Skip to content
GitLab
Menu
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
3612f5f1
Commit
3612f5f1
authored
Dec 17, 2020
by
Praetorius, Simon
Browse files
Merge branch 'feature/export_types' into 'master'
Export some types and data See merge request extensions/dune-vtk!14
parents
bab2cc12
4ac2e5bc
Changes
7
Hide whitespace changes
Inline
Side-by-side
dune/vtk/vtkreader.hh
View file @
3612f5f1
...
...
@@ -26,14 +26,14 @@ namespace Dune
*
* NOTE: Assumption on the file structure: Each XML tag must be on a separate line.
*
* \tparam Grid
The type of the grid to construct.
* \tparam GridCreator
P
olicy type to control what to pass to a grid factory with
*
data given from the file. [ContinuousGridCreator]
* \tparam FieldType
Type of the components of the data to extract from the file [default: double]
* \tparam Grid The type of the grid to construct.
* \tparam
GC
GridCreator
p
olicy type to control what to pass to a grid factory with
* data given from the file. [ContinuousGridCreator]
* \tparam FieldType Type of the components of the data to extract from the file [default: double]
**/
template
<
class
Grid
,
class
G
ridCreator
=
Vtk
::
ContinuousGridCreator
<
Grid
>,
class
FieldType
=
double
>
template
<
class
Grid
,
class
G
C
=
Vtk
::
ContinuousGridCreator
<
Grid
>,
class
FieldType
=
double
>
class
VtkReader
:
public
Vtk
::
FileReader
<
Grid
,
VtkReader
<
Grid
,
G
ridCreator
>>
:
public
Vtk
::
FileReader
<
Grid
,
VtkReader
<
Grid
,
G
C
>>
{
// Sections visited during the xml parsing
enum
Sections
{
...
...
@@ -52,17 +52,32 @@ namespace Dune
};
// Type of global world coordinates
using
GlobalCoordinate
=
typename
G
ridCreator
::
GlobalCoordinate
;
using
GlobalCoordinate
=
typename
G
C
::
GlobalCoordinate
;
// Template representing a grid-function that is created in getPointData() and getCellData()
// with Context either Vtk::PointContext or Vek::CellContext, respectively.
// To each GridCreat
e
a GridFunction is associated, see, e.g. Vtk::ContinuousGridFunction
// To each GridCreat
or
a GridFunction is associated, see, e.g. Vtk::ContinuousGridFunction
// or Vtk::LagrangeGridFunction.
template
<
class
Context
>
using
GridFunction
=
typename
Vtk
::
AssociatedGridFunction
<
GridCreator
,
FieldType
,
Context
>::
type
;
using
GridFunction
=
typename
Vtk
::
AssociatedGridFunction
<
GC
,
FieldType
,
Context
>::
type
;
public:
using
GridCreator
=
GC
;
/// GridFunction representing the data stored on the points in the file
using
PointGridFunction
=
GridFunction
<
Vtk
::
PointContext
>
;
/// GridFunction representing the data stored on the cells in the file
using
CellGridFunction
=
GridFunction
<
Vtk
::
CellContext
>
;
public:
/// Constructor. Creates a new GridCreator with the passed factory
/**
* \param args... Either pass a GridFactory by reference or shared_ptr, or a list of arguments
* passed to the constructor of a Dune::GridFactory (typically and empty parameter
* list). See the constructor of \ref GridCreatorInterface and the GridCreator
* passed to this reader.
**/
template
<
class
...
Args
,
std
::
enable_if_t
<
std
::
is_constructible
<
GridCreator
,
Args
...>
::
value
,
int
>
=
0
>
explicit
VtkReader
(
Args
&&
...
args
)
...
...
@@ -97,36 +112,66 @@ namespace Dune
}
/// Construct the actual grid using the GridCreator
///
NOTE: requires an aforegoing call to \ref read()
///
[[expects: read_ == true]]
std
::
unique_ptr
<
Grid
>
createGrid
()
const
{
return
creator_
->
createGrid
();
}
/// Construct a grid-function representing the point-data with the given name
///
NOTE: requires an aforegoing call to \ref read()
///
[[expects: read_ == true]]
GridFunction
<
Vtk
::
PointContext
>
getPointData
(
std
::
string
const
&
name
)
const
{
auto
const
&
data
=
dataArray_
.
at
(
"PointData."
+
name
);
VTK_ASSERT_MSG
(
data
.
section
==
POINT_DATA
,
"The data to extract is not point-data. Use `getCellData()` instead!"
);
auto
data_it
=
dataArray_
.
find
(
"PointData."
+
name
);
auto
point_it
=
pointData_
.
find
(
"PointData."
+
name
);
VTK_ASSERT_MSG
(
data_it
!=
dataArray_
.
end
()
&&
point_it
!=
pointData_
.
end
(),
"The data to extract is not found in point-data. Try `getCellData()` instead!"
);
VTK_ASSERT
(
data_it
->
second
.
section
==
POINT_DATA
);
return
{
*
creator_
,
point
Data_
.
at
(
"PointData."
+
name
),
data
.
components
,
return
{
*
creator_
,
point
_it
->
second
,
data_it
->
second
.
components
,
vec_types
,
vec_offsets
,
vec_connectivity
};
}
/// Return a vector of DataArrayAttributes for all POINT_DATA blocks
/// [[expects: read_ == true]]
std
::
vector
<
DataArrayAttributes
>
getPointDataAttributes
()
const
{
std
::
vector
<
DataArrayAttributes
>
attributes
;
attributes
.
reserve
(
pointData_
.
size
());
for
(
auto
const
&
da
:
dataArray_
)
{
if
(
da
.
second
.
section
==
POINT_DATA
);
attributes
.
push_back
(
da
.
second
);
}
return
attributes
;
}
/// Construct a grid-function representing the cell-data with the given name
///
NOTE: requires an aforegoing call to \ref read()
///
[[expects: read_ == true]]
GridFunction
<
Vtk
::
CellContext
>
getCellData
(
std
::
string
const
&
name
)
const
{
auto
const
&
data
=
dataArray_
.
at
(
"CellData."
+
name
);
VTK_ASSERT_MSG
(
data
.
section
==
CELL_DATA
,
"The data to extract is not cell-data. Use `getPointData()` instead!"
);
auto
data_it
=
dataArray_
.
find
(
"CellData."
+
name
);
auto
cell_it
=
cellData_
.
find
(
"CellData."
+
name
);
VTK_ASSERT_MSG
(
data_it
!=
dataArray_
.
end
()
&&
cell_it
!=
cellData_
.
end
(),
"The data to extract is not found in cell-data. Try `getPointData()` instead!"
);
VTK_ASSERT
(
data_it
->
second
.
section
==
CELL_DATA
);
return
{
*
creator_
,
cell
Data_
.
at
(
"CellData."
+
name
),
data
.
components
,
return
{
*
creator_
,
cell
_it
->
second
,
data_it
->
second
.
components
,
vec_types
,
vec_offsets
,
vec_connectivity
};
}
/// Return a vector of DataArrayAttributes for all CELL_DATA blocks
/// [[expects: read_ == true]]
std
::
vector
<
DataArrayAttributes
>
getCellDataAttributes
()
const
{
std
::
vector
<
DataArrayAttributes
>
attributes
;
attributes
.
reserve
(
cellData_
.
size
());
for
(
auto
const
&
da
:
dataArray_
)
{
if
(
da
.
second
.
section
==
CELL_DATA
);
attributes
.
push_back
(
da
.
second
);
}
return
attributes
;
}
/// Advanced read methods
/// @{
...
...
@@ -258,6 +303,8 @@ namespace Dune
/// Offset of beginning of appended data
std
::
uint64_t
offset0_
=
0
;
bool
read_
=
false
;
};
// deduction guides
...
...
dune/vtk/vtkreader.impl.hh
View file @
3612f5f1
...
...
@@ -35,6 +35,7 @@ void VtkReader<Grid,Creator,Field>::read (std::string const& filename, bool fill
}
else
{
DUNE_THROW
(
Dune
::
VtkError
,
"File has unknown file-extension '"
<<
ext
<<
"'. Allowed are only '.vtu' and '.pvtu'."
);
}
read_
=
true
;
}
...
...
@@ -807,6 +808,7 @@ void VtkReader<Grid,Creator,Field>::clear ()
numberOfCells_
=
0
;
numberOfPoints_
=
0
;
offset0_
=
0
;
read_
=
false
;
}
}
// end namespace Dune
dune/vtk/vtkwriterinterface.hh
View file @
3612f5f1
...
...
@@ -16,21 +16,22 @@ namespace Dune
{
/// Interface for file writers for the Vtk XML file formats
/**
* \tparam G
ridView
Model of Dune::GridView
* \tparam D
ataCollector
Model of \ref DataCollectorInterface
* \tparam G
V
Model of Dune::GridView
* \tparam D
C
Model of \ref DataCollectorInterface
**/
template
<
class
G
ridView
,
class
D
ataCollector
>
template
<
class
G
V
,
class
D
C
>
class
VtkWriterInterface
:
public
Vtk
::
FileWriter
{
template
<
class
>
friend
class
TimeseriesWriter
;
template
<
class
>
friend
class
PvdWriter
;
protected:
static
constexpr
int
dimension
=
GridView
::
dimension
;
public:
using
GridView
=
GV
;
using
DataCollector
=
DC
;
protected:
using
VtkFunction
=
Dune
::
Vtk
::
Function
<
GridView
>
;
using
Communicator
=
CollectiveCommunication
<
typename
MPIHelper
::
MPICommunicator
>
;
using
pos_type
=
typename
std
::
ostream
::
pos_type
;
enum
PositionTypes
{
...
...
dune/vtk/writers/vtkimagedatawriter.hh
View file @
3612f5f1
...
...
@@ -22,8 +22,6 @@ namespace Dune
class
VtkImageDataWriter
:
public
VtkWriterInterface
<
GridView
,
DataCollector
>
{
static
constexpr
int
dimension
=
GridView
::
dimension
;
using
Super
=
VtkWriterInterface
<
GridView
,
DataCollector
>
;
using
pos_type
=
typename
Super
::
pos_type
;
...
...
dune/vtk/writers/vtkrectilineargridwriter.hh
View file @
3612f5f1
...
...
@@ -22,8 +22,6 @@ namespace Dune
class
VtkRectilinearGridWriter
:
public
VtkWriterInterface
<
GridView
,
DataCollector
>
{
static
constexpr
int
dimension
=
GridView
::
dimension
;
using
Super
=
VtkWriterInterface
<
GridView
,
DataCollector
>
;
using
pos_type
=
typename
Super
::
pos_type
;
...
...
dune/vtk/writers/vtkstructuredgridwriter.hh
View file @
3612f5f1
...
...
@@ -22,8 +22,6 @@ namespace Dune
class
VtkStructuredGridWriter
:
public
VtkWriterInterface
<
GridView
,
DataCollector
>
{
static
constexpr
int
dimension
=
GridView
::
dimension
;
using
Super
=
VtkWriterInterface
<
GridView
,
DataCollector
>
;
using
pos_type
=
typename
Super
::
pos_type
;
...
...
dune/vtk/writers/vtkunstructuredgridwriter.hh
View file @
3612f5f1
...
...
@@ -24,8 +24,6 @@ namespace Dune
{
template
<
class
>
friend
class
VtkTimeseriesWriter
;
static
constexpr
int
dimension
=
GridView
::
dimension
;
using
Super
=
VtkWriterInterface
<
GridView
,
DataCollector
>
;
using
pos_type
=
typename
Super
::
pos_type
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment