Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
iwr
dune-vtk
Commits
6b0d1620
Commit
6b0d1620
authored
Aug 11, 2020
by
Stenger, Florian
Browse files
namespace Vtk engulfs all
parent
c66bd4cd
Changes
76
Hide whitespace changes
Inline
Side-by-side
dune/vtk/CMakeLists.txt
View file @
6b0d1620
dune_add_library
(
"vtktypes"
OBJECT
vtk
types.cc
)
types.cc
)
#install headers
install
(
FILES
...
...
@@ -8,20 +8,22 @@ install(FILES
defaultvtkfunction.hh
filereader.hh
filewriter.hh
forward.hh
gridcreatorinterface.hh
legacyvtkfunction.hh
pvdwriter.hh
pvdwriter.impl.hh
vtk
function.hh
vtk
localfunction.hh
vtk
localfunctioninterface.hh
vtk
reader.hh
vtk
reader.impl.hh
vtk
timeserieswriter.hh
vtk
timeserieswriter.impl.hh
vtk
types.hh
vtk
writer.hh
vtk
writerinterface.hh
vtk
writerinterface.impl.hh
function.hh
localfunction.hh
localfunctioninterface.hh
reader.hh
reader.impl.hh
timeserieswriter.hh
timeserieswriter.impl.hh
types.hh
writer.hh
writerinterface.hh
writerinterface.impl.hh
DESTINATION
${
CMAKE_INSTALL_INCLUDEDIR
}
/dune/vtkwriter
)
add_subdirectory
(
datacollectors
)
...
...
dune/vtk/datacollectorinterface.hh
View file @
6b0d1620
...
...
@@ -5,130 +5,135 @@
namespace
Dune
{
/// Base class for data collectors in a CRTP style.
/**
* \tparam GridViewType Model of Dune::GridView
* \tparam Derived Implementation of a concrete DataCollector.
* \tparam Partition Dune::PartitionType [Partitions::InteriorBorder]
**/
template
<
class
GridViewType
,
class
Derived
,
class
Partition
>
class
DataCollectorInterface
{
public:
/// The partitionset to collect data from
static
constexpr
auto
partition
=
Partition
{};
using
GridView
=
GridViewType
;
/// The dimension of the grid
enum
{
dim
=
GridView
::
dimension
};
/// The dimension of the world
enum
{
dow
=
GridView
::
dimensionworld
};
public:
/// Store a copy of the GridView
DataCollectorInterface
(
GridView
const
&
gridView
)
:
gridView_
(
gridView
)
{}
/// Update the DataCollector on the current GridView
void
update
()
{
asDerived
().
updateImpl
();
}
/// Return the number of ghost elements
int
ghostLevel
()
const
{
return
asDerived
().
ghostLevelImpl
();
}
/// Return the number of cells in (this partition of the) grid
std
::
uint64_t
numCells
()
const
{
return
asDerived
().
numCellsImpl
();
}
/// Return the number of points in (this partition of the) grid
std
::
uint64_t
numPoints
()
const
{
return
asDerived
().
numPointsImpl
();
}
/// \brief Return a flat vector of point coordinates
/**
* All coordinates are extended to 3 components and concatenated.
* [p0_x, p0_y, p0_z, p1_x, p1_y, p1_z, ...]
* If the GridView::dimensionworld < 3, the remaining components are
* set to 0
**/
template
<
class
T
>
std
::
vector
<
T
>
points
()
const
{
return
asDerived
().
template
pointsImpl
<
T
>();
}
namespace
Vtk
{
///
\brief Return a flat vector of function values evaluated at the points
.
///
Base class for data collectors in a CRTP style
.
/**
* In case of a vector valued function, flat the vector entries:
* [fct(p0)_0, fct(p0)_1, fct(p0)_2, fct(p1)_0, ...]
* where the vector dimension must be 3 (possible extended by 0s)
* In case of tensor valued function, flat the tensor row-wise:
* [fct(p0)_00, fct(p0)_01, fct(p0)_02, fct(p0)_10, fct(p0)_11, fct(p0)_12, fct(p0)_20...]
* where the tensor dimension must be 3x3 (possible extended by 0s)
* \tparam GridViewType Model of Dune::GridView
* \tparam Derived Implementation of a concrete DataCollector.
* \tparam Partition Dune::PartitionType [Partitions::InteriorBorder]
**/
template
<
class
T
,
class
VtkFunc
tion
>
std
::
vector
<
T
>
pointData
(
VtkFunction
const
&
fct
)
const
template
<
class
GridViewType
,
class
Derived
,
class
Parti
tion
>
class
DataCollectorInterface
{
return
asDerived
().
template
pointDataImpl
<
T
>(
fct
);
}
/// \brief Return a flat vector of function values evaluated at the cells in the order of traversal.
/**
* \see pointData.
* Note: Cells might be described explicitly by connectivity, offsets, and types, e.g. in
* an UnstructuredGrid, or might be described implicitly by the grid type, e.g. in
* StructuredGrid.
*/
template
<
class
T
,
class
VtkFunction
>
std
::
vector
<
T
>
cellData
(
VtkFunction
const
&
fct
)
const
{
return
asDerived
().
template
cellDataImpl
<
T
>(
fct
);
}
protected:
// cast to derived type
Derived
&
asDerived
()
{
return
static_cast
<
Derived
&>
(
*
this
);
}
const
Derived
&
asDerived
()
const
{
return
static_cast
<
const
Derived
&>
(
*
this
);
}
public:
// default implementations
void
updateImpl
()
{
/* do nothing */
}
int
ghostLevelImpl
()
const
{
return
gridView_
.
overlapSize
(
0
);
}
// Evaluate `fct` in center of cell.
template
<
class
T
,
class
VtkFunction
>
std
::
vector
<
T
>
cellDataImpl
(
VtkFunction
const
&
fct
)
const
;
protected:
GridView
gridView_
;
};
public:
/// The partitionset to collect data from
static
constexpr
auto
partition
=
Partition
{};
using
GridView
=
GridViewType
;
/// The dimension of the grid
enum
{
dim
=
GridView
::
dimension
};
/// The dimension of the world
enum
{
dow
=
GridView
::
dimensionworld
};
public:
/// Store a copy of the GridView
DataCollectorInterface
(
GridView
const
&
gridView
)
:
gridView_
(
gridView
)
{}
/// Update the DataCollector on the current GridView
void
update
()
{
asDerived
().
updateImpl
();
}
/// Return the number of ghost elements
int
ghostLevel
()
const
{
return
asDerived
().
ghostLevelImpl
();
}
/// Return the number of cells in (this partition of the) grid
std
::
uint64_t
numCells
()
const
{
return
asDerived
().
numCellsImpl
();
}
/// Return the number of points in (this partition of the) grid
std
::
uint64_t
numPoints
()
const
{
return
asDerived
().
numPointsImpl
();
}
/// \brief Return a flat vector of point coordinates
/**
* All coordinates are extended to 3 components and concatenated.
* [p0_x, p0_y, p0_z, p1_x, p1_y, p1_z, ...]
* If the GridView::dimensionworld < 3, the remaining components are
* set to 0
**/
template
<
class
T
>
std
::
vector
<
T
>
points
()
const
{
return
asDerived
().
template
pointsImpl
<
T
>();
}
/// \brief Return a flat vector of function values evaluated at the points.
/**
* In case of a vector valued function, flat the vector entries:
* [fct(p0)_0, fct(p0)_1, fct(p0)_2, fct(p1)_0, ...]
* where the vector dimension must be 3 (possible extended by 0s)
* In case of tensor valued function, flat the tensor row-wise:
* [fct(p0)_00, fct(p0)_01, fct(p0)_02, fct(p0)_10, fct(p0)_11, fct(p0)_12, fct(p0)_20...]
* where the tensor dimension must be 3x3 (possible extended by 0s)
**/
template
<
class
T
,
class
VtkFunction
>
std
::
vector
<
T
>
pointData
(
VtkFunction
const
&
fct
)
const
{
return
asDerived
().
template
pointDataImpl
<
T
>(
fct
);
}
/// \brief Return a flat vector of function values evaluated at the cells in the order of traversal.
/**
* \see pointData.
* Note: Cells might be described explicitly by connectivity, offsets, and types, e.g. in
* an UnstructuredGrid, or might be described implicitly by the grid type, e.g. in
* StructuredGrid.
*/
template
<
class
T
,
class
VtkFunction
>
std
::
vector
<
T
>
cellData
(
VtkFunction
const
&
fct
)
const
{
return
asDerived
().
template
cellDataImpl
<
T
>(
fct
);
}
protected:
// cast to derived type
Derived
&
asDerived
()
{
return
static_cast
<
Derived
&>
(
*
this
);
}
const
Derived
&
asDerived
()
const
{
return
static_cast
<
const
Derived
&>
(
*
this
);
}
public:
// default implementations
void
updateImpl
()
{
/* do nothing */
}
int
ghostLevelImpl
()
const
{
return
gridView_
.
overlapSize
(
0
);
}
// Evaluate `fct` in center of cell.
template
<
class
T
,
class
VtkFunction
>
std
::
vector
<
T
>
cellDataImpl
(
VtkFunction
const
&
fct
)
const
;
protected:
GridView
gridView_
;
};
}
// end namespace Vtk
}
// end namespace Dune
#include
"datacollectorinterface.impl.hh"
dune/vtk/datacollectorinterface.impl.hh
View file @
6b0d1620
...
...
@@ -2,25 +2,30 @@
#include
<dune/geometry/referenceelements.hh>
namespace
Dune
{
template
<
class
GV
,
class
D
,
class
P
>
template
<
class
T
,
class
VtkFunction
>
std
::
vector
<
T
>
DataCollectorInterface
<
GV
,
D
,
P
>
::
cellDataImpl
(
VtkFunction
const
&
fct
)
const
namespace
Dune
{
std
::
vector
<
T
>
data
;
data
.
reserve
(
this
->
numCells
()
*
fct
.
ncomps
());
auto
localFct
=
localFunction
(
fct
);
for
(
auto
const
&
e
:
elements
(
gridView_
,
partition
))
{
localFct
.
bind
(
e
);
auto
refElem
=
referenceElement
<
T
,
dim
>
(
e
.
type
());
for
(
int
comp
=
0
;
comp
<
fct
.
ncomps
();
++
comp
)
data
.
emplace_back
(
localFct
.
evaluate
(
comp
,
refElem
.
position
(
0
,
0
)));
localFct
.
unbind
();
}
return
data
;
}
namespace
Vtk
{
template
<
class
GV
,
class
D
,
class
P
>
template
<
class
T
,
class
VtkFunction
>
std
::
vector
<
T
>
DataCollectorInterface
<
GV
,
D
,
P
>
::
cellDataImpl
(
VtkFunction
const
&
fct
)
const
{
std
::
vector
<
T
>
data
;
data
.
reserve
(
this
->
numCells
()
*
fct
.
ncomps
());
auto
localFct
=
localFunction
(
fct
);
for
(
auto
const
&
e
:
elements
(
gridView_
,
partition
))
{
localFct
.
bind
(
e
);
auto
refElem
=
referenceElement
<
T
,
dim
>
(
e
.
type
());
for
(
int
comp
=
0
;
comp
<
fct
.
ncomps
();
++
comp
)
data
.
emplace_back
(
localFct
.
evaluate
(
comp
,
refElem
.
position
(
0
,
0
)));
localFct
.
unbind
();
}
return
data
;
}
}
// end namespace Vtk
}
// end namespace Dune
dune/vtk/datacollectors/continuousdatacollector.hh
View file @
6b0d1620
...
...
@@ -7,140 +7,144 @@
#include
<dune/grid/utility/globalindexset.hh>
#include
<dune/vtk/forward.hh>
#include
<dune/vtk/
vtk
types.hh>
#include
<dune/vtk/types.hh>
#include
"unstructureddatacollector.hh"
namespace
Dune
{
/// Implementation of \ref DataCollector for linear cells, with continuous data.
template
<
class
GridView
,
class
Partition
>
class
ContinuousDataCollector
:
public
UnstructuredDataCollectorInterface
<
GridView
,
ContinuousDataCollector
<
GridView
,
Partition
>
,
Partition
>
{
using
Self
=
ContinuousDataCollector
;
using
Super
=
UnstructuredDataCollectorInterface
<
GridView
,
Self
,
Partition
>
;
namespace
Vtk
{
public:
using
Super
::
dim
;
using
Super
::
partition
;
/// Implementation of \ref DataCollector for linear cells, with continuous data.
template
<
class
GridView
,
class
Partition
>
class
ContinuousDataCollector
:
public
UnstructuredDataCollectorInterface
<
GridView
,
ContinuousDataCollector
<
GridView
,
Partition
>
,
Partition
>
{
using
Self
=
ContinuousDataCollector
;
using
Super
=
UnstructuredDataCollectorInterface
<
GridView
,
Self
,
Partition
>
;
public:
using
Super
::
dim
;
using
Super
::
partition
;
public:
ContinuousDataCollector
(
GridView
const
&
gridView
)
:
Super
(
gridView
)
{}
/// Collect the vertex indices
void
updateImpl
()
{
numPoints_
=
0
;
indexMap_
.
resize
(
gridView_
.
size
(
dim
));
auto
const
&
indexSet
=
gridView_
.
indexSet
();
for
(
auto
const
&
vertex
:
vertices
(
gridView_
,
partition
))
indexMap_
[
indexSet
.
index
(
vertex
)]
=
std
::
int64_t
(
numPoints_
++
);
if
(
gridView_
.
comm
().
size
()
>
1
)
{
auto
&&
e
=
elements
(
gridView_
,
partition
);
numCells_
=
std
::
distance
(
std
::
begin
(
e
),
std
::
end
(
e
));
}
else
{
numCells_
=
gridView_
.
size
(
0
);
}
}
public:
ContinuousDataCollector
(
GridView
const
&
gridView
)
:
Super
(
gridView
)
{}
/// Return number of grid vertices
std
::
uint64_t
numPointsImpl
()
const
{
return
numPoints_
;
}
/// Collect the vertex indices
void
updateImpl
()
{
numPoints_
=
0
;
indexMap_
.
resize
(
gridView_
.
size
(
dim
));
auto
const
&
indexSet
=
gridView_
.
indexSet
();
for
(
auto
const
&
vertex
:
vertices
(
gridView_
,
partition
))
indexMap_
[
indexSet
.
index
(
vertex
)]
=
std
::
int64_t
(
numPoints_
++
);
if
(
gridView_
.
comm
().
size
()
>
1
)
{
auto
&&
e
=
elements
(
gridView_
,
partition
);
numCells_
=
std
::
distance
(
std
::
begin
(
e
),
std
::
end
(
e
));
}
else
{
numCells_
=
gridView_
.
size
(
0
);
}
}
/// Return number of grid vertices
std
::
uint64_t
numPointsImpl
()
const
{
return
numPoints_
;
}
/// Return the coordinates of all grid vertices in the order given by the indexSet
template
<
class
T
>
std
::
vector
<
T
>
pointsImpl
()
const
{
std
::
vector
<
T
>
data
;
data
.
reserve
(
numPoints_
*
3
);
for
(
auto
const
&
vertex
:
vertices
(
gridView_
,
partition
))
{
auto
v
=
vertex
.
geometry
().
center
();
for
(
std
::
size_t
j
=
0
;
j
<
v
.
size
();
++
j
)
data
.
emplace_back
(
v
[
j
]);
for
(
std
::
size_t
j
=
v
.
size
();
j
<
3u
;
++
j
)
data
.
emplace_back
(
0
);
}
return
data
;
}
/// Return the coordinates of all grid vertices in the order given by the indexSet
template
<
class
T
>
std
::
vector
<
T
>
pointsImpl
()
const
{
std
::
vector
<
T
>
data
;
data
.
reserve
(
numPoints_
*
3
);
for
(
auto
const
&
vertex
:
vertices
(
gridView_
,
partition
))
{
auto
v
=
vertex
.
geometry
().
center
();
for
(
std
::
size_t
j
=
0
;
j
<
v
.
size
();
++
j
)
data
.
emplace_back
(
v
[
j
]);
for
(
std
::
size_t
j
=
v
.
size
();
j
<
3u
;
++
j
)
data
.
emplace_back
(
0
);
}
return
data
;
}
/// Return a vector of global unique ids of the points
std
::
vector
<
std
::
uint64_t
>
pointIdsImpl
()
const
{
std
::
vector
<
std
::
uint64_t
>
data
;
data
.
reserve
(
numPoints_
);
GlobalIndexSet
<
GridView
>
globalIndexSet
(
gridView_
,
dim
);
for
(
auto
const
&
vertex
:
vertices
(
gridView_
,
partition
))
{
data
.
emplace_back
(
globalIndexSet
.
index
(
vertex
));
}
return
data
;
}
/// Return number of grid cells
std
::
uint64_t
numCellsImpl
()
const
{
return
numCells_
;
}
/// Return a vector of global unique ids of the points
std
::
vector
<
std
::
uint64_t
>
pointIdsImpl
()
const
{
std
::
vector
<
std
::
uint64_t
>
data
;
data
.
reserve
(
numPoints_
);
GlobalIndexSet
<
GridView
>
globalIndexSet
(
gridView_
,
dim
);
for
(
auto
const
&
vertex
:
vertices
(
gridView_
,
partition
))
{
data
.
emplace_back
(
globalIndexSet
.
index
(
vertex
));
}
return
data
;
}
/// Return the types, offsets and connectivity of the cells, using the same connectivity as
/// given by the grid.
Cells
cellsImpl
()
const
{
auto
const
&
indexSet
=
gridView_
.
indexSet
();
auto
types
=
indexSet
.
types
(
0
);
int
maxVertices
=
std
::
accumulate
(
types
.
begin
(),
types
.
end
(),
1
,
[](
int
m
,
GeometryType
t
)
{
auto
refElem
=
referenceElement
<
double
,
dim
>
(
t
);
return
std
::
max
(
m
,
refElem
.
size
(
dim
));
});
Cells
cells
;
cells
.
connectivity
.
reserve
(
numCells_
*
maxVertices
);
cells
.
offsets
.
reserve
(
numCells_
);
cells
.
types
.
reserve
(
numCells_
);
std
::
int64_t
old_o
=
0
;
for
(
auto
const
&
c
:
elements
(
gridView_
,
partition
))
{
Vtk
::
CellType
cellType
(
c
.
type
());
for
(
unsigned
int
j
=
0
;
j
<
c
.
subEntities
(
dim
);
++
j
)
cells
.
connectivity
.
emplace_back
(
indexMap_
[
indexSet
.
subIndex
(
c
,
cellType
.
permutation
(
j
),
dim
)]);
cells
.
offsets
.
push_back
(
old_o
+=
c
.
subEntities
(
dim
));
cells
.
types
.
push_back
(
cellType
.
type
());
}
return
cells
;
}
/// Evaluate the `fct` at the corners of the elements
template
<
class
T
,
class
GlobalFunction
>
std
::
vector
<
T
>
pointDataImpl
(
GlobalFunction
const
&
fct
)
const
{
std
::
vector
<
T
>
data
(
numPoints_
*
fct
.
ncomps
());
auto
const
&
indexSet
=
gridView_
.
indexSet
();
auto
localFct
=
localFunction
(
fct
);
for
(
auto
const
&
e
:
elements
(
gridView_
,
partition
))
{
localFct
.
bind
(
e
);
Vtk
::
CellType
cellType
{
e
.
type
()};
auto
refElem
=
referenceElement
(
e
.
geometry
());
for
(
unsigned
int
j
=
0
;
j
<
e
.
subEntities
(
dim
);
++
j
)
{
std
::
size_t
idx
=
fct
.
ncomps
()
*
indexMap_
[
indexSet
.
subIndex
(
e
,
cellType
.
permutation
(
j
),
dim
)];
for
(
int
comp
=
0
;
comp
<
fct
.
ncomps
();
++
comp
)
data
[
idx
+
comp
]
=
T
(
localFct
.
evaluate
(
comp
,
refElem
.
position
(
cellType
.
permutation
(
j
),
dim
)));
/// Return number of grid cells
std
::
uint64_t
numCellsImpl
()
const
{
return
numCells_
;
}
localFct
.
unbind
();
}
return
data
;
}
protected:
using
Super
::
gridView_
;
std
::
uint64_t
numPoints_
=
0
;
std
::
uint64_t
numCells_
=
0
;
std
::
vector
<
std
::
int64_t
>
indexMap_
;
};
/// Return the types, offsets and connectivity of the cells, using the same connectivity as
/// given by the grid.
Cells
cellsImpl
()
const
{
auto
const
&
indexSet
=
gridView_
.
indexSet
();
auto
types
=
indexSet
.
types
(
0
);
int
maxVertices
=
std
::
accumulate
(
types
.
begin
(),
types
.
end
(),
1
,
[](
int
m
,
GeometryType
t
)
{
auto
refElem
=
referenceElement
<
double
,
dim
>
(
t
);
return
std
::
max
(
m
,
refElem
.
size
(
dim
));
});
Cells
cells
;
cells
.
connectivity
.
reserve
(
numCells_
*
maxVertices
);
cells
.
offsets
.
reserve
(
numCells_
);
cells
.
types
.
reserve
(
numCells_
);
std
::
int64_t
old_o
=
0
;
for
(
auto
const
&
c
:
elements
(
gridView_
,
partition
))
{
Vtk
::
CellType
cellType
(
c
.
type
());
for
(
unsigned
int
j
=
0
;
j
<
c
.
subEntities
(
dim
);
++
j
)
cells
.
connectivity
.
emplace_back
(
indexMap_
[
indexSet
.
subIndex
(
c
,
cellType
.
permutation
(
j
),
dim
)]);
cells
.
offsets
.
push_back
(
old_o
+=
c
.
subEntities
(
dim
));
cells
.
types
.
push_back
(
cellType
.
type
());
}
return
cells
;
}
/// Evaluate the `fct` at the corners of the elements
template
<
class
T
,
class
GlobalFunction
>
std
::
vector
<
T
>
pointDataImpl
(
GlobalFunction
const
&
fct
)
const
{
std
::
vector
<
T
>
data
(
numPoints_
*
fct
.
ncomps
());
auto
const
&
indexSet
=
gridView_
.
indexSet
();
auto
localFct
=
localFunction
(
fct
);
for
(
auto
const
&
e
:
elements
(
gridView_
,
partition
))
{
localFct
.
bind
(
e
);
Vtk
::
CellType
cellType
{
e
.
type
()};
auto
refElem
=
referenceElement
(
e
.
geometry
());
for
(
unsigned
int
j
=
0
;
j
<
e
.
subEntities
(
dim
);
++
j
)
{
std
::
size_t
idx
=
fct
.
ncomps
()
*
indexMap_
[
indexSet
.
subIndex
(
e
,
cellType
.
permutation
(
j
),
dim
)];
for
(
int
comp
=
0
;
comp
<
fct
.
ncomps
();
++
comp
)
data
[
idx
+
comp
]
=
T
(
localFct
.
evaluate
(
comp
,
refElem
.
position
(
cellType
.
permutation
(
j
),
dim
)));
}
localFct
.
unbind
();
}