add mpi serialization for UDQASTNode

This commit is contained in:
Arne Morten Kvarving 2019-12-11 15:50:41 +01:00
parent 5873b56025
commit 7d825cea82
3 changed files with 69 additions and 0 deletions

View File

@ -36,6 +36,7 @@
#include <opm/parser/eclipse/EclipseState/Schedule/MSW/Valve.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/OilVaporizationProperties.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunction.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/VFPInjTable.hpp>
@ -1293,6 +1294,18 @@ std::size_t packSize(const UDQFunctionTable& data,
packSize(data.functionMap(), comm);
}
std::size_t packSize(const UDQASTNode& data,
Dune::MPIHelper::MPICommunicator comm)
{
return packSize(data.var_type, comm) +
packSize(data.getType(), comm) +
packSize(data.stringValue(), comm) +
packSize(data.scalarValue(), comm) +
packSize(data.getSelectors(), comm) +
packSize(data.getLeft(), comm) +
packSize(data.getRight(), comm);
}
////// pack routines
template<class T>
@ -2602,6 +2615,19 @@ void pack(const UDQFunctionTable& data,
pack(data.functionMap(), buffer, position, comm);
}
void pack(const UDQASTNode& data,
std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
pack(data.var_type, buffer, position, comm);
pack(data.getType(), buffer, position, comm);
pack(data.stringValue(), buffer, position, comm);
pack(data.scalarValue(), buffer, position, comm);
pack(data.getSelectors(), buffer, position, comm);
pack(data.getLeft(), buffer, position, comm);
pack(data.getRight(), buffer, position, comm);
}
/// unpack routines
template<class T>
@ -4448,6 +4474,28 @@ void unpack(UDQFunctionTable& data,
data = UDQFunctionTable(params, map);
}
void unpack(UDQASTNode& data,
std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
UDQVarType var_type;
UDQTokenType type;
std::string stringValue;
double scalarValue;
std::vector<std::string> selectors;
std::shared_ptr<UDQASTNode> left;
std::shared_ptr<UDQASTNode> right;
unpack(var_type, buffer, position, comm);
unpack(type, buffer, position, comm);
unpack(stringValue, buffer, position, comm);
unpack(scalarValue, buffer, position, comm);
unpack(selectors, buffer, position, comm);
unpack(left, buffer, position, comm);
unpack(right, buffer, position, comm);
data = UDQASTNode(var_type, type, stringValue, scalarValue, selectors, left, right);
}
#define INSTANTIATE_PACK_VECTOR(T) \
template std::size_t packSize(const std::vector<T>& data, \
Dune::MPIHelper::MPICommunicator comm); \

View File

@ -112,6 +112,7 @@ class TableManager;
class TableSchema;
class ThresholdPressure;
class UDAValue;
class UDQASTNode;
class UDQFunction;
class UDQFunctionTable;
class UDQParams;
@ -629,6 +630,7 @@ ADD_PACK_PROTOTYPES(ThresholdPressure)
ADD_PACK_PROTOTYPES(TimeMap)
ADD_PACK_PROTOTYPES(TimeMap::StepData)
ADD_PACK_PROTOTYPES(UDAValue)
ADD_PACK_PROTOTYPES(UDQASTNode)
ADD_PACK_PROTOTYPES(UDQFunction)
ADD_PACK_PROTOTYPES(UDQFunctionTable)
ADD_PACK_PROTOTYPES(UDQParams)

View File

@ -43,6 +43,7 @@
#include <opm/parser/eclipse/EclipseState/Schedule/MSW/Valve.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/OilVaporizationProperties.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunction.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/VFPInjTable.hpp>
@ -1690,6 +1691,24 @@ BOOST_AUTO_TEST_CASE(UDQFunctionTable)
}
BOOST_AUTO_TEST_CASE(UDQASTNode)
{
#ifdef HAVE_MPI
std::shared_ptr<Opm::UDQASTNode> n0;
std::shared_ptr<Opm::UDQASTNode> n1(new Opm::UDQASTNode(Opm::UDQVarType::NONE,
Opm::UDQTokenType::error,
"test1", 1.0, {"test2"},
n0, n0));
Opm::UDQASTNode val1(Opm::UDQVarType::NONE,
Opm::UDQTokenType::error,
"test", 1.0, {"test3"}, n1, n1);
auto val2 = PackUnpack(val1);
BOOST_CHECK(std::get<1>(val2) == std::get<2>(val2));
BOOST_CHECK(val1 == std::get<0>(val2));
#endif
}
bool init_unit_test_func()
{
return true;