Skip to content

Commit

Permalink
Merge pull request dealii#14056 from tjhei/xdmf_ref_cell
Browse files Browse the repository at this point in the history
  • Loading branch information
masterleinad committed Jul 6, 2022
2 parents b8b79cf + c479d5c commit cd49222
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 40 deletions.
4 changes: 0 additions & 4 deletions doc/news/changes/incompatibilities/20220627Arndt-1

This file was deleted.

64 changes: 60 additions & 4 deletions include/deal.II/base/data_out_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -3322,15 +3322,28 @@ class XDMFEntry
* cases where <code>solution_filename == mesh_filename</code>, and
* <code>dim==spacedim</code>.
*/
XDMFEntry(const std::string & filename,
const double time,
const std::uint64_t nodes,
const std::uint64_t cells,
const unsigned int dim,
const ReferenceCell &cell_type);

/**
* Deprecated constructor.
*
* @deprecated Use the constructor that additionally takes a ReferenceCell.
*/
XDMFEntry(const std::string & filename,
const double time,
const std::uint64_t nodes,
const std::uint64_t cells,
const unsigned int dim);

/**
* Simplified constructor that calls the complete constructor for
* cases where <code>dim==spacedim</code>.
* Deprecated constructor.
*
* @deprecated Use the constructor that additionally takes a ReferenceCell.
*/
XDMFEntry(const std::string & mesh_filename,
const std::string & solution_filename,
Expand All @@ -3340,8 +3353,23 @@ class XDMFEntry
const unsigned int dim);

/**
* Constructor that sets all members to provided parameters.
* Simplified constructor that calls the complete constructor for
* cases where <code>dim==spacedim</code>.
*/
XDMFEntry(const std::string & mesh_filename,
const std::string & solution_filename,
const double time,
const std::uint64_t nodes,
const std::uint64_t cells,
const unsigned int dim,
const ReferenceCell &cell_type);

/**
* Deprecated constructor.
*
* @deprecated Use the constructor that additionally takes a ReferenceCell.
*/
DEAL_II_DEPRECATED
XDMFEntry(const std::string & mesh_filename,
const std::string & solution_filename,
const double time,
Expand All @@ -3350,6 +3378,18 @@ class XDMFEntry
const unsigned int dim,
const unsigned int spacedim);

/**
* Constructor that sets all members to provided parameters.
*/
XDMFEntry(const std::string & mesh_filename,
const std::string & solution_filename,
const double time,
const std::uint64_t nodes,
const std::uint64_t cells,
const unsigned int dim,
const unsigned int spacedim,
const ReferenceCell &cell_type);

/**
* Record an attribute and associated dimensionality.
*/
Expand All @@ -3366,14 +3406,24 @@ class XDMFEntry
serialize(Archive &ar, const unsigned int /*version*/)
{
ar &valid &h5_sol_filename &h5_mesh_filename &entry_time &num_nodes
&num_cells &dimension &space_dimension &attribute_dims;
&num_cells &dimension &space_dimension &cell_type &attribute_dims;
}

/**
* Get the XDMF content associated with this entry.
* If the entry is not valid, this returns an empty string.
*/
std::string
get_xdmf_content(const unsigned int indent_level) const;

/**
* Get the XDMF content associated with this entry.
* If the entry is not valid, this returns an empty string.
*
* @deprecated Use the other function instead.
*/
DEAL_II_DEPRECATED
std::string
get_xdmf_content(const unsigned int indent_level,
const ReferenceCell &reference_cell) const;

Expand Down Expand Up @@ -3419,6 +3469,12 @@ class XDMFEntry
*/
unsigned int space_dimension;

/**
* The type of cell in deal.II language. We currently only support
* xdmf entries where all cells have the same type.
*/
ReferenceCell cell_type;

/**
* The attributes associated with this entry and their dimension.
*/
Expand Down
148 changes: 125 additions & 23 deletions source/base/data_out_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7985,13 +7985,24 @@ DataOutInterface<dim, spacedim>::create_xdmf_entry(
// Output the XDMF file only on the root process
if (myrank == 0)
{
const auto &patches = get_patches();
Assert(patches.size() > 0, DataOutBase::ExcNoPatches());
// We currently don't support writing mixed meshes:
#ifdef DEBUG
for (const auto &patch : patches)
Assert(patch.reference_cell == patches[0].reference_cell,
ExcNotImplemented());
#endif


XDMFEntry entry(h5_mesh_filename,
h5_solution_filename,
cur_time,
global_node_cell_count[0],
global_node_cell_count[1],
dim,
spacedim);
spacedim,
patches[0].reference_cell);
unsigned int n_data_sets = data_filter.n_data_sets();

// The vector names generated here must match those generated in the HDF5
Expand Down Expand Up @@ -8037,20 +8048,9 @@ DataOutInterface<dim, spacedim>::write_xdmf_file(
xdmf_file
<< " <Grid Name=\"CellTime\" GridType=\"Collection\" CollectionType=\"Temporal\">\n";

// Write out all the entries indented
const auto &patches = get_patches();
Assert(patches.size() > 0, DataOutBase::ExcNoPatches());

// We currently don't support writing mixed meshes:
#ifdef DEBUG
for (const auto &patch : patches)
Assert(patch.reference_cell == patches[0].reference_cell,
ExcNotImplemented());
#endif

for (const auto &entry : entries)
{
xdmf_file << entry.get_xdmf_content(3, patches[0].reference_cell);
xdmf_file << entry.get_xdmf_content(3);
}

xdmf_file << " </Grid>\n";
Expand Down Expand Up @@ -9177,6 +9177,7 @@ XDMFEntry::XDMFEntry()
, num_cells(numbers::invalid_unsigned_int)
, dimension(numbers::invalid_unsigned_int)
, space_dimension(numbers::invalid_unsigned_int)
, cell_type()
{}


Expand All @@ -9186,7 +9187,16 @@ XDMFEntry::XDMFEntry(const std::string & filename,
const std::uint64_t nodes,
const std::uint64_t cells,
const unsigned int dim)
: XDMFEntry(filename, filename, time, nodes, cells, dim, dim)
: XDMFEntry(filename, filename, time, nodes, cells, dim, dim, ReferenceCell())
{}

XDMFEntry::XDMFEntry(const std::string & filename,
const double time,
const std::uint64_t nodes,
const std::uint64_t cells,
const unsigned int dim,
const ReferenceCell &cell_type)
: XDMFEntry(filename, filename, time, nodes, cells, dim, dim, cell_type)
{}


Expand All @@ -9197,7 +9207,33 @@ XDMFEntry::XDMFEntry(const std::string & mesh_filename,
const std::uint64_t nodes,
const std::uint64_t cells,
const unsigned int dim)
: XDMFEntry(mesh_filename, solution_filename, time, nodes, cells, dim, dim)
: XDMFEntry(mesh_filename,
solution_filename,
time,
nodes,
cells,
dim,
dim,
ReferenceCell())
{}



XDMFEntry::XDMFEntry(const std::string & mesh_filename,
const std::string & solution_filename,
const double time,
const std::uint64_t nodes,
const std::uint64_t cells,
const unsigned int dim,
const ReferenceCell &cell_type)
: XDMFEntry(mesh_filename,
solution_filename,
time,
nodes,
cells,
dim,
dim,
cell_type)
{}


Expand All @@ -9209,6 +9245,59 @@ XDMFEntry::XDMFEntry(const std::string & mesh_filename,
const std::uint64_t cells,
const unsigned int dim,
const unsigned int spacedim)
: XDMFEntry(mesh_filename,
solution_filename,
time,
nodes,
cells,
dim,
spacedim,
ReferenceCell())
{}



namespace
{
/**
* Deprecated XDMFEntry constructors do not fill the cell_type, so we use this
* little helper to convert it to the appropriate hex cell.
*/
ReferenceCell
cell_type_hex_if_invalid(const ReferenceCell &cell_type,
const unsigned int dimension)
{
if (cell_type == ReferenceCells::Invalid)
{
switch (dimension)
{
case 0:
return ReferenceCells::get_hypercube<0>();
case 1:
return ReferenceCells::get_hypercube<1>();
case 2:
return ReferenceCells::get_hypercube<2>();
case 3:
return ReferenceCells::get_hypercube<3>();
default:
AssertThrow(false, ExcMessage("Invalid dimension"));
}
}
else
return cell_type;
}
} // namespace



XDMFEntry::XDMFEntry(const std::string & mesh_filename,
const std::string & solution_filename,
const double time,
const std::uint64_t nodes,
const std::uint64_t cells,
const unsigned int dim,
const unsigned int spacedim,
const ReferenceCell &cell_type_)
: valid(true)
, h5_sol_filename(solution_filename)
, h5_mesh_filename(mesh_filename)
Expand All @@ -9217,6 +9306,7 @@ XDMFEntry::XDMFEntry(const std::string & mesh_filename,
, num_cells(cells)
, dimension(dim)
, space_dimension(spacedim)
, cell_type(cell_type_hex_if_invalid(cell_type_, dim))
{}


Expand Down Expand Up @@ -9250,6 +9340,18 @@ namespace
std::string
XDMFEntry::get_xdmf_content(const unsigned int indent_level,
const ReferenceCell &reference_cell) const
{
// We now store the type of cell in the XDMFEntry:
(void)reference_cell;
Assert(cell_type == reference_cell,
ExcMessage("Incorrect ReferenceCell type passed in."));
return get_xdmf_content(indent_level);
}



std::string
XDMFEntry::get_xdmf_content(const unsigned int indent_level) const
{
if (!valid)
return "";
Expand Down Expand Up @@ -9282,26 +9384,26 @@ XDMFEntry::get_xdmf_content(const unsigned int indent_level,
}
else if (dimension == 2)
{
Assert(reference_cell == ReferenceCells::Quadrilateral ||
reference_cell == ReferenceCells::Triangle,
Assert(cell_type == ReferenceCells::Quadrilateral ||
cell_type == ReferenceCells::Triangle,
ExcNotImplemented());

if (reference_cell == ReferenceCells::Quadrilateral)
if (cell_type == ReferenceCells::Quadrilateral)
{
ss << "Quadrilateral";
}
else // if (reference_cell == ReferenceCells::Triangle)
else // if (cell_type == ReferenceCells::Triangle)
{
ss << "Triangle";
}
}
else if (dimension == 3)
{
Assert(reference_cell == ReferenceCells::Hexahedron ||
reference_cell == ReferenceCells::Tetrahedron,
Assert(cell_type == ReferenceCells::Hexahedron ||
cell_type == ReferenceCells::Tetrahedron,
ExcNotImplemented());

if (reference_cell == ReferenceCells::Hexahedron)
if (cell_type == ReferenceCells::Hexahedron)
{
ss << "Hexahedron";
}
Expand All @@ -9321,7 +9423,7 @@ XDMFEntry::get_xdmf_content(const unsigned int indent_level,
ss << "\">\n";

ss << indent(indent_level + 2) << "<DataItem Dimensions=\"" << num_cells
<< " " << reference_cell.n_vertices()
<< " " << cell_type.n_vertices()
<< "\" NumberType=\"UInt\" Format=\"HDF\">\n";

ss << indent(indent_level + 3) << h5_mesh_filename << ":/cells\n";
Expand Down
2 changes: 1 addition & 1 deletion tests/data_out/data_out_hdf5_02.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ check()
<< " <Grid Name=\"CellTime\" GridType=\"Collection\" CollectionType=\"Temporal\">\n";

// Write out the entry
xdmf_file << entry.get_xdmf_content(3, ReferenceCells::get_hypercube<dim>());
xdmf_file << entry.get_xdmf_content(3);

xdmf_file << " </Grid>\n";
xdmf_file << " </Domain>\n";
Expand Down
2 changes: 1 addition & 1 deletion tests/mpi/data_out_hdf5_02.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ check()
<< " <Grid Name=\"CellTime\" GridType=\"Collection\" CollectionType=\"Temporal\">\n";

// Write out the entry
xdmf_file << entry.get_xdmf_content(3, ReferenceCells::get_hypercube<dim>());
xdmf_file << entry.get_xdmf_content(3);

xdmf_file << " </Grid>\n";
xdmf_file << " </Domain>\n";
Expand Down
7 changes: 2 additions & 5 deletions tests/serialization/xdmf_entry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ test()
oa << entry1;
// archive and stream closed when destructors are called
}
deallog << oss.str() << std::endl;

// verify correctness of the serialization
{
Expand All @@ -54,13 +53,11 @@ test()

deallog << "XDMFEntry before serialization: " << std::endl
<< std::endl
<< entry1.get_xdmf_content(0, ReferenceCells::get_hypercube<dim>())
<< std::endl;
<< entry1.get_xdmf_content(0) << std::endl;

deallog << "XDMFEntry after de-serialization: " << std::endl
<< std::endl
<< entry2.get_xdmf_content(0, ReferenceCells::get_hypercube<dim>())
<< std::endl;
<< entry2.get_xdmf_content(0) << std::endl;
}


Expand Down

0 comments on commit cd49222

Please sign in to comment.