| 1 |
// Copyright(C) 1999-2020, 2024 National Technology & Engineering Solutions |
| 2 |
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 3 |
// NTESS, the U.S. Government retains certain rights in this software. |
| 4 |
// |
| 5 |
// See packages/seacas/LICENSE for details |
| 6 |
|
| 7 |
#ifndef IOSS_Ioad_AdiosWrapper_hpp |
| 8 |
#define IOSS_Ioad_AdiosWrapper_hpp |
| 9 |
|
| 10 |
#include "Ioss_Utils.h" // for Utils, IOSS_ERROR, etc |
| 11 |
#include "adios/AdiosWrapper.h" |
| 12 |
|
| 13 |
namespace Ioad { |
| 14 |
|
| 15 |
template <typename T> |
| 16 |
void AdiosWrapper::DefineVariable(const std::string &name, const adios2::Dims &shape, |
| 17 |
const adios2::Dims &start, const adios2::Dims &count, |
| 18 |
const bool /*constantDims*/) |
| 19 |
{ |
| 20 |
adios2::Variable<T> var = this->IO::InquireVariable<T>(name); |
| 21 |
if (!var) { |
| 22 |
this->IO::DefineVariable<T>(name, shape, start, count); |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
template <typename T> |
| 27 |
T AdiosWrapper::GetAttribute(const std::string &attribute_name, bool ignore_missing, |
| 28 |
T default_value) |
| 29 |
{ |
| 30 |
adios2::Attribute<T> attribute = this->IO::InquireAttribute<T>(attribute_name); |
| 31 |
if (!attribute) { |
| 32 |
if (ignore_missing) { |
| 33 |
return default_value; |
| 34 |
} |
| 35 |
else { |
| 36 |
std::ostringstream errmsg; |
| 37 |
errmsg << "ERROR: " << attribute_name << " not found.\n"; |
| 38 |
IOSS_ERROR(errmsg); |
| 39 |
} |
| 40 |
} |
| 41 |
return attribute.Data()[0]; |
| 42 |
} |
| 43 |
|
| 44 |
template <typename T> void AdiosWrapper::GetSync(adios2::Variable<T> var, T *data) |
| 45 |
{ |
| 46 |
this->Engine::Get(var, data, adios2::Mode::Sync); |
| 47 |
} |
| 48 |
|
| 49 |
template <typename T> void AdiosWrapper::GetSync(adios2::Variable<T> var, T &data) |
| 50 |
{ |
| 51 |
this->Engine::Get(var, data, adios2::Mode::Sync); |
| 52 |
} |
| 53 |
|
| 54 |
template <typename T> void AdiosWrapper::GetSync(std::string var_name, T *data) |
| 55 |
{ |
| 56 |
this->Engine::Get(var_name, data, adios2::Mode::Sync); |
| 57 |
} |
| 58 |
|
| 59 |
template <typename T> void AdiosWrapper::GetSync(std::string var_name, T &data) |
| 60 |
{ |
| 61 |
this->Engine::Get(var_name, data, adios2::Mode::Sync); |
| 62 |
} |
| 63 |
|
| 64 |
template <typename T> void AdiosWrapper::InquireAndPut(const std::string &name, const T *value) |
| 65 |
{ |
| 66 |
adios2::Variable<T> var = this->IO::InquireVariable<T>(name); |
| 67 |
if (var) { |
| 68 |
this->Engine::Put<T>(name, value, |
| 69 |
adios2::Mode::Sync); // If not Sync, variables are not saved correctly. |
| 70 |
} |
| 71 |
else { |
| 72 |
std::ostringstream errmsg; |
| 73 |
errmsg << "ERROR: Could not find variable '" << name << "'\n"; |
| 74 |
IOSS_ERROR(errmsg); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
template <typename T> void AdiosWrapper::DefineAttribute(const std::string &name, const T &value) |
| 79 |
{ |
| 80 |
adios2::Attribute<T> attr = this->IO::InquireAttribute<T>(name); |
| 81 |
if (!attr) { |
| 82 |
this->IO::DefineAttribute<T>(name, value); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
template <typename T> |
| 87 |
void AdiosWrapper::DefineMetaVariable(const std::string &meta_name, |
| 88 |
const std::string &variable_name) |
| 89 |
{ |
| 90 |
std::string encoded_name = EncodeMetaVariable(meta_name, variable_name); |
| 91 |
adios2::Variable<T> var = this->IO::InquireVariable<T>(encoded_name); |
| 92 |
if (!var) { |
| 93 |
this->IO::DefineVariable<T>(encoded_name); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
template <typename T> |
| 98 |
void AdiosWrapper::PutMetaVariable(const std::string &meta_name, T value, |
| 99 |
const std::string &variable_name) |
| 100 |
{ |
| 101 |
std::string name = EncodeMetaVariable(meta_name, variable_name); |
| 102 |
adios2::Variable<T> var = this->IO::InquireVariable<T>(name); |
| 103 |
if (var) { |
| 104 |
this->Engine::Put<T>(var, &value, |
| 105 |
adios2::Mode::Sync); // If not Sync, variables are not saved correctly. |
| 106 |
} |
| 107 |
else { |
| 108 |
std::ostringstream errmsg; |
| 109 |
errmsg << "ERROR: " << name << " variable not defined.\n"; |
| 110 |
IOSS_ERROR(errmsg); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
template <typename T> |
| 115 |
T AdiosWrapper::GetMetaVariable(const std::string &meta_name, const std::string &variable_name) |
| 116 |
{ |
| 117 |
T variable; |
| 118 |
this->Engine::Get<T>(EncodeMetaVariable(meta_name, variable_name), variable, |
| 119 |
adios2::Mode::Sync); // If not Sync, variables are not saved correctly. |
| 120 |
return variable; |
| 121 |
} |
| 122 |
|
| 123 |
} // end of namespace Ioad |
| 124 |
|
| 125 |
#endif |