Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ADIOS2 engine as option #2636

Merged
merged 13 commits into from
Apr 22, 2023
7 changes: 4 additions & 3 deletions cpp/demo/interpolation-io/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void interpolate_scalar(std::shared_ptr<mesh::Mesh<U>> mesh,
#ifdef HAS_ADIOS2
// Write the function to a VTX file for visualisation, e.g. using
// ParaView
io::VTXWriter<U> outfile(mesh->comm(), filename.replace_extension("bp"), {u});
io::VTXWriter<U> outfile(mesh->comm(), filename.replace_extension("bp"), {u},
"BP4");
outfile.write(0.0);
outfile.close();
#endif
Expand Down Expand Up @@ -167,7 +168,7 @@ void interpolate_nedelec(std::shared_ptr<mesh::Mesh<U>> mesh,
// between cells).
#ifdef HAS_ADIOS2
io::VTXWriter<U> outfile(mesh->comm(), filename.replace_extension("bp"),
{u_l});
{u_l}, "BP4");
outfile.write(0.0);
outfile.close();
#endif
Expand Down Expand Up @@ -212,7 +213,7 @@ int main(int argc, char* argv[])
interpolate_nedelec<float>(mesh0, "u_nedelec32");
interpolate_nedelec<double>(mesh1, "u_nedelec64");
interpolate_nedelec<std::complex<float>>(mesh0, "u_nedelec_complex64");
interpolate_nedelec<std::complex<double>>(mesh1, "u_nedelec_complex12");
interpolate_nedelec<std::complex<double>>(mesh1, "u_nedelec_complex128");
}

MPI_Finalize();
Expand Down
53 changes: 51 additions & 2 deletions cpp/dolfinx/io/ADIOS2Writers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
using namespace dolfinx;
using namespace dolfinx::io;

//-----------------------------------------------------------------------------
std::string impl_fides::to_fides_cell(mesh::CellType type)
namespace
{
/// Convert DOLFINx CellType to Fides CellType
/// https://gitlab.kitware.com/vtk/vtk-m/-/blob/master/vtkm/CellShape.h#L30-53
/// @param[in] type The DOLFInx cell
/// @return The Fides cell string
std::string to_fides_cell(mesh::CellType type)
{
switch (type)
{
Expand All @@ -40,6 +45,50 @@ std::string impl_fides::to_fides_cell(mesh::CellType type)
throw std::runtime_error("Unknown cell type.");
}
}

} // namespace

//-----------------------------------------------------------------------------
ADIOS2Writer::ADIOS2Writer(MPI_Comm comm, const std::filesystem::path& filename,
std::string tag, std::string engine)
: _adios(std::make_unique<adios2::ADIOS>(comm)),
_io(std::make_unique<adios2::IO>(_adios->DeclareIO(tag)))
{
_io->SetEngine(engine);
_engine = std::make_unique<adios2::Engine>(
_io->Open(filename, adios2::Mode::Write));
}
//-----------------------------------------------------------------------------
ADIOS2Writer::~ADIOS2Writer() { close(); }
//-----------------------------------------------------------------------------
void ADIOS2Writer::close()
{
assert(_engine);
// The reason this looks odd is that ADIOS2 uses `operator bool()`
// to test if the engine is open
if (*_engine)
_engine->Close();
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void impl_fides::initialize_mesh_attributes(adios2::IO& io, mesh::CellType type)
{
// NOTE: If we start using mixed element types, we can change
// data-model to "unstructured"
impl_adios2::define_attribute<std::string>(io, "Fides_Data_Model",
"unstructured_single");

// Define Fides attributes pointing to ADIOS2 Variables for geometry
// and topology
impl_adios2::define_attribute<std::string>(io, "Fides_Coordinates_Variable",
"points");
impl_adios2::define_attribute<std::string>(io, "Fides_Connectivity_Variable",
"connectivity");
impl_adios2::define_attribute<std::string>(io, "Fides_Cell_Type",
to_fides_cell(type));

impl_adios2::define_attribute<std::string>(io, "Fides_Time_Variable", "step");
}
//-----------------------------------------------------------------------------
std::stringstream
io::impl_vtx::create_vtk_schema(const std::vector<std::string>& point_data,
Expand Down
Loading