MFEM  v4.5.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
adios2datacollection.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 //
12 // Created on: Jan 7, 2020
13 // Author: William F Godoy godoywf@ornl.gov
14 // adios2: Adaptable Input/Output System https://github.com/ornladios/ADIOS2
15 
16 #include "adios2datacollection.hpp"
17 
18 #ifdef MFEM_USE_ADIOS2
19 
20 namespace mfem
21 {
22 
23 #ifdef MFEM_USE_MPI
25  const std::string& collection_name, Mesh* mesh,
26  const std::string engine_type) : DataCollection(collection_name, mesh),
27  stream( new adios2stream(name, adios2stream::openmode::out, comm, engine_type) )
28 {
29  SetMesh(mesh);
30 }
31 #else
33  const std::string& collection_name, Mesh* mesh,
34  const std::string engine_type): DataCollection(collection_name, mesh),
35  stream( new adios2stream(name, adios2stream::openmode::out, engine_type) )
36 {
37  SetMesh(mesh);
38 }
39 #endif
40 
42 {
43  stream->Close();
44 }
45 
47 {
48  stream->BeginStep();
49 
50  // only save mesh once (moving mesh, not yet supported)
51  if (stream->CurrentStep() == 0)
52  {
53  if (mesh == nullptr)
54  {
55  const std::string error_message =
56  "MFEM ADIOS2DataCollection Save error: Mesh is null. Please call SetMesh before Save\n";
57  mfem_error(error_message.c_str());
58  }
59  stream->Print(*mesh);
60  }
61 
62  // reduce footprint
63  if (myid == 0)
64  {
65  stream->SetTime(time);
66  stream->SetCycle(cycle);
67  }
68 
69  for (const auto& field : field_map)
70  {
71  const std::string& variable_name = field.first;
72  field.second->Save(*stream.get(), variable_name);
73  }
74 
75  stream->EndStep();
76 }
77 
78 void ADIOS2DataCollection::SetParameter(const std::string key,
79  const std::string value) noexcept
80 {
81  stream->SetParameter(key, value);
82 }
83 
84 void ADIOS2DataCollection::SetLevelsOfDetail(const int levels_of_detail)
85 noexcept
86 {
87  stream->SetRefinementLevel(levels_of_detail);
88 }
89 
90 } // namespace mfem
91 
92 #endif // MFEM_USE_ADIOS2
double time
Physical time (for time-dependent simulations)
Mesh * mesh
The (common) mesh for the collected fields.
int cycle
Time cycle; for time-dependent simulations cycle >= 0, otherwise = -1.
void mfem_error(const char *msg)
Function called when an error is encountered. Used by the macros MFEM_ABORT, MFEM_ASSERT, MFEM_VERIFY.
Definition: error.cpp:154
void SetParameter(const std::string key, const std::string value) noexcept
int myid
MPI rank (in parallel)
void SetLevelsOfDetail(const int levels_of_detail) noexcept
virtual void SetMesh(Mesh *new_mesh)
Set/change the mesh associated with the collection.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
Definition: globals.hpp:66
ADIOS2DataCollection(MPI_Comm comm, const std::string &collection_name, Mesh *mesh=nullptr, const std::string engine_type="BPFile")