mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Also copy flags, and helper function with test.
This commit is contained in:
@@ -263,6 +263,7 @@ list (APPEND TEST_SOURCE_FILES
|
|||||||
tests/test_parallelwellinfo.cpp
|
tests/test_parallelwellinfo.cpp
|
||||||
tests/test_partitionCells.cpp
|
tests/test_partitionCells.cpp
|
||||||
tests/test_preconditionerfactory.cpp
|
tests/test_preconditionerfactory.cpp
|
||||||
|
tests/test_privarspacking.cpp
|
||||||
tests/test_relpermdiagnostics.cpp
|
tests/test_relpermdiagnostics.cpp
|
||||||
tests/test_RestartSerialization.cpp
|
tests/test_RestartSerialization.cpp
|
||||||
tests/test_stoppedwells.cpp
|
tests/test_stoppedwells.cpp
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include <opm/simulators/aquifers/AquiferGridUtils.hpp>
|
#include <opm/simulators/aquifers/AquiferGridUtils.hpp>
|
||||||
|
|
||||||
#include <opm/simulators/flow/partitionCells.hpp>
|
#include <opm/simulators/flow/partitionCells.hpp>
|
||||||
|
#include <opm/simulators/flow/priVarsPacking.hpp>
|
||||||
#include <opm/simulators/flow/SubDomain.hpp>
|
#include <opm/simulators/flow/SubDomain.hpp>
|
||||||
|
|
||||||
#include <opm/simulators/linalg/extractMatrix.hpp>
|
#include <opm/simulators/linalg/extractMatrix.hpp>
|
||||||
@@ -266,7 +267,22 @@ public:
|
|||||||
const auto& comm = model_.ebosSimulator().vanguard().grid().comm();
|
const auto& comm = model_.ebosSimulator().vanguard().grid().comm();
|
||||||
if (comm.size() > 1) {
|
if (comm.size() > 1) {
|
||||||
const auto& ccomm = model_.ebosSimulator().model().newtonMethod().linearSolver().comm();
|
const auto& ccomm = model_.ebosSimulator().model().newtonMethod().linearSolver().comm();
|
||||||
|
|
||||||
|
// Copy numerical values from primary vars.
|
||||||
ccomm->copyOwnerToAll(solution, solution);
|
ccomm->copyOwnerToAll(solution, solution);
|
||||||
|
|
||||||
|
// Copy flags from primary vars.
|
||||||
|
const std::size_t num = solution.size();
|
||||||
|
Dune::BlockVector<std::size_t> allmeanings(num);
|
||||||
|
for (std::size_t ii = 0; ii < num; ++ii) {
|
||||||
|
allmeanings[ii] = PVUtil::pack(solution[ii]);
|
||||||
|
}
|
||||||
|
ccomm->copyOwnerToAll(allmeanings, allmeanings);
|
||||||
|
for (std::size_t ii = 0; ii < num; ++ii) {
|
||||||
|
PVUtil::unPack(solution[ii], allmeanings[ii]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update intensive quantities for our overlap values.
|
||||||
model_.ebosSimulator().model().invalidateAndUpdateIntensiveQuantitiesOverlap(/*timeIdx=*/0);
|
model_.ebosSimulator().model().invalidateAndUpdateIntensiveQuantitiesOverlap(/*timeIdx=*/0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
54
opm/simulators/flow/priVarsPacking.hpp
Normal file
54
opm/simulators/flow/priVarsPacking.hpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2023 Total SE
|
||||||
|
|
||||||
|
This file is part of the Open Porous Media project (OPM).
|
||||||
|
|
||||||
|
OPM is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OPM is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OPM_PRIVARSPACKING_HEADER_INCLUDED
|
||||||
|
#define OPM_PRIVARSPACKING_HEADER_INCLUDED
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
namespace Opm {
|
||||||
|
|
||||||
|
namespace PVUtil {
|
||||||
|
constexpr int fbits = 4;
|
||||||
|
|
||||||
|
template <class PV>
|
||||||
|
std::size_t pack(const PV& privar) {
|
||||||
|
std::size_t m1 = static_cast<std::size_t>(privar.primaryVarsMeaningWater());
|
||||||
|
std::size_t m2 = static_cast<std::size_t>(privar.primaryVarsMeaningPressure());
|
||||||
|
std::size_t m3 = static_cast<std::size_t>(privar.primaryVarsMeaningGas());
|
||||||
|
std::size_t m4 = static_cast<std::size_t>(privar.primaryVarsMeaningBrine());
|
||||||
|
return m1 + (m2 << fbits*1) + (m3 << fbits*2) + (m4 << fbits*3);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class PV>
|
||||||
|
void unPack(PV& privar, const std::size_t meanings) {
|
||||||
|
const std::size_t filter = ((1 << fbits) - 1);
|
||||||
|
std::size_t m1 = (meanings >> fbits*0) & filter;
|
||||||
|
std::size_t m2 = (meanings >> fbits*1) & filter;
|
||||||
|
std::size_t m3 = (meanings >> fbits*2) & filter;
|
||||||
|
std::size_t m4 = (meanings >> fbits*3) & filter;
|
||||||
|
privar.setPrimaryVarsMeaningWater(typename PV::WaterMeaning(m1));
|
||||||
|
privar.setPrimaryVarsMeaningPressure(typename PV::PressureMeaning(m2));
|
||||||
|
privar.setPrimaryVarsMeaningGas(typename PV::GasMeaning(m3));
|
||||||
|
privar.setPrimaryVarsMeaningBrine(typename PV::BrineMeaning(m4));
|
||||||
|
}
|
||||||
|
} // namespace PVMeanings
|
||||||
|
} // namespace Opm
|
||||||
|
|
||||||
|
#endif // OPM_PRIVARSPACKING_HEADER_INCLUDED
|
||||||
118
tests/test_privarspacking.cpp
Normal file
118
tests/test_privarspacking.cpp
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2023 SINTEF.
|
||||||
|
|
||||||
|
This file is part of the Open Porous Media project (OPM).
|
||||||
|
|
||||||
|
OPM is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OPM is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <opm/simulators/flow/priVarsPacking.hpp>
|
||||||
|
|
||||||
|
#define BOOST_TEST_MODULE priVarsPacking
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
// Must define a class for testing, using extracts from BlackoilPrimaryVariables,
|
||||||
|
// but without the typetags.
|
||||||
|
class PriVarMeaning
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum class WaterMeaning {
|
||||||
|
Sw, // water saturation
|
||||||
|
Rvw, // vaporized water
|
||||||
|
Rsw, // dissolved gas in water
|
||||||
|
Disabled, // The primary variable is not used
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class PressureMeaning {
|
||||||
|
Po, // oil pressure
|
||||||
|
Pg, // gas pressure
|
||||||
|
Pw, // water pressure
|
||||||
|
};
|
||||||
|
enum class GasMeaning {
|
||||||
|
Sg, // gas saturation
|
||||||
|
Rs, // dissolved gas in oil
|
||||||
|
Rv, // vapporized oil
|
||||||
|
Disabled, // The primary variable is not used
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class BrineMeaning {
|
||||||
|
Cs, // salt concentration
|
||||||
|
Sp, // (precipitated) salt saturation
|
||||||
|
Disabled, // The primary variable is not used
|
||||||
|
};
|
||||||
|
|
||||||
|
WaterMeaning primaryVarsMeaningWater() const
|
||||||
|
{ return primaryVarsMeaningWater_; }
|
||||||
|
void setPrimaryVarsMeaningWater(WaterMeaning newMeaning)
|
||||||
|
{ primaryVarsMeaningWater_ = newMeaning; }
|
||||||
|
|
||||||
|
PressureMeaning primaryVarsMeaningPressure() const
|
||||||
|
{ return primaryVarsMeaningPressure_; }
|
||||||
|
void setPrimaryVarsMeaningPressure(PressureMeaning newMeaning)
|
||||||
|
{ primaryVarsMeaningPressure_ = newMeaning; }
|
||||||
|
|
||||||
|
GasMeaning primaryVarsMeaningGas() const
|
||||||
|
{ return primaryVarsMeaningGas_; }
|
||||||
|
void setPrimaryVarsMeaningGas(GasMeaning newMeaning)
|
||||||
|
{ primaryVarsMeaningGas_ = newMeaning; }
|
||||||
|
|
||||||
|
BrineMeaning primaryVarsMeaningBrine() const
|
||||||
|
{ return primaryVarsMeaningBrine_; }
|
||||||
|
void setPrimaryVarsMeaningBrine(BrineMeaning newMeaning)
|
||||||
|
{ primaryVarsMeaningBrine_ = newMeaning; }
|
||||||
|
|
||||||
|
bool operator==(const PriVarMeaning& other) const
|
||||||
|
{
|
||||||
|
return primaryVarsMeaningWater_ == other.primaryVarsMeaningWater_
|
||||||
|
&& primaryVarsMeaningPressure_ == other.primaryVarsMeaningPressure_
|
||||||
|
&& primaryVarsMeaningGas_ == other.primaryVarsMeaningGas_
|
||||||
|
&& primaryVarsMeaningBrine_ == other.primaryVarsMeaningBrine_;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
WaterMeaning primaryVarsMeaningWater_ = WaterMeaning::Disabled;
|
||||||
|
PressureMeaning primaryVarsMeaningPressure_ = PressureMeaning::Pw;
|
||||||
|
GasMeaning primaryVarsMeaningGas_ = GasMeaning::Disabled;
|
||||||
|
BrineMeaning primaryVarsMeaningBrine_ = BrineMeaning::Disabled;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(meanings)
|
||||||
|
{
|
||||||
|
// Test default meanings.
|
||||||
|
{
|
||||||
|
PriVarMeaning pv1, pv2;
|
||||||
|
std::size_t p = Opm::PVUtil::pack(pv1);
|
||||||
|
Opm::PVUtil::unPack(pv2, p);
|
||||||
|
BOOST_CHECK(pv1 == pv2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test explicitly set meanings.
|
||||||
|
{
|
||||||
|
PriVarMeaning pv1, pv2, pv3;
|
||||||
|
pv1.setPrimaryVarsMeaningPressure(PriVarMeaning::PressureMeaning::Pw);
|
||||||
|
pv1.setPrimaryVarsMeaningWater(PriVarMeaning::WaterMeaning::Rvw);
|
||||||
|
pv1.setPrimaryVarsMeaningGas(PriVarMeaning::GasMeaning::Disabled);
|
||||||
|
pv1.setPrimaryVarsMeaningBrine(PriVarMeaning::BrineMeaning::Cs);
|
||||||
|
std::size_t p = Opm::PVUtil::pack(pv1);
|
||||||
|
Opm::PVUtil::unPack(pv2, p);
|
||||||
|
BOOST_CHECK(pv1 == pv2);
|
||||||
|
BOOST_CHECK(!(pv1 == pv3));
|
||||||
|
BOOST_CHECK(!(pv2 == pv3));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user