Merge pull request #3549 from joakim-hove/serialize-set

Add serializer support for set - closely modelled after map
This commit is contained in:
Joakim Hove 2021-09-27 13:47:15 +02:00 committed by GitHub
commit edb2c4abb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 0 deletions

View File

@ -291,6 +291,44 @@ public:
} }
} }
template<class Set, bool complexType = true>
void set(Set& data)
{
using Data = typename Set::value_type;
auto handle = [&](auto& d)
{
if constexpr (is_vector<Data>::value)
this->template vector<typename Data::value_type,complexType>(d);
else if constexpr (is_ptr<Data>::value)
ptr(d);
else if constexpr (complexType)
d.serializeOp(*this);
else
(*this)(d);
};
if (m_op == Operation::PACKSIZE) {
m_packSize += Mpi::packSize(data.size(), m_comm);
for (auto& it : data) {
handle(it);
}
} else if (m_op == Operation::PACK) {
Mpi::pack(data.size(), m_buffer, m_position, m_comm);
for (auto& it : data) {
handle(it);
}
} else if (m_op == Operation::UNPACK) {
size_t size;
Mpi::unpack(size, m_buffer, m_position, m_comm);
for (size_t i = 0; i < size; ++i) {
Data entry;
handle(entry);
data.insert(entry);
}
}
}
//! \brief Call this to serialize data. //! \brief Call this to serialize data.
//! \tparam T Type of class to serialize //! \tparam T Type of class to serialize
//! \param data Class to serialize //! \param data Class to serialize

View File

@ -50,6 +50,8 @@
#include <opm/parser/eclipse/EclipseState/InitConfig/InitConfig.hpp> #include <opm/parser/eclipse/EclipseState/InitConfig/InitConfig.hpp>
#include <opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp> #include <opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/RSTConfig.hpp> #include <opm/parser/eclipse/EclipseState/Schedule/RSTConfig.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionResult.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/State.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionAST.hpp> #include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionAST.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.hpp> #include <opm/parser/eclipse/EclipseState/Schedule/Action/PyAction.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/Actions.hpp> #include <opm/parser/eclipse/EclipseState/Schedule/Action/Actions.hpp>
@ -79,6 +81,7 @@
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunction.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/UDQ/UDQFunctionTable.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.hpp> #include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/VFPInjTable.hpp> #include <opm/parser/eclipse/EclipseState/Schedule/VFPInjTable.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.hpp> #include <opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well/PAvg.hpp> #include <opm/parser/eclipse/EclipseState/Schedule/Well/PAvg.hpp>
@ -566,6 +569,7 @@ TEST_FOR_TYPE2(Action, Actions)
TEST_FOR_TYPE2(Action, ActionX) TEST_FOR_TYPE2(Action, ActionX)
TEST_FOR_TYPE2(Action, AST) TEST_FOR_TYPE2(Action, AST)
TEST_FOR_TYPE2(Action, ASTNode) TEST_FOR_TYPE2(Action, ASTNode)
TEST_FOR_TYPE2(Action, State)
TEST_FOR_TYPE(BCConfig) TEST_FOR_TYPE(BCConfig)
TEST_FOR_TYPE(BrineDensityTable) TEST_FOR_TYPE(BrineDensityTable)
TEST_FOR_TYPE(ColumnSchema) TEST_FOR_TYPE(ColumnSchema)
@ -652,6 +656,7 @@ TEST_FOR_TYPE(UDQConfig)
TEST_FOR_TYPE(UDQDefine) TEST_FOR_TYPE(UDQDefine)
TEST_FOR_TYPE(UDQIndex) TEST_FOR_TYPE(UDQIndex)
TEST_FOR_TYPE(UDQParams) TEST_FOR_TYPE(UDQParams)
TEST_FOR_TYPE(UDQState)
TEST_FOR_TYPE(UnitSystem) TEST_FOR_TYPE(UnitSystem)
TEST_FOR_TYPE(Valve) TEST_FOR_TYPE(Valve)
TEST_FOR_TYPE(VFPInjTable) TEST_FOR_TYPE(VFPInjTable)