move allocation of compositional data into CompositionalContainer

This commit is contained in:
Arne Morten Kvarving 2025-02-11 14:58:09 +01:00
parent 4bfadcd80d
commit 686f110a34
3 changed files with 67 additions and 20 deletions

View File

@ -23,7 +23,63 @@
#include <config.h>
#include <opm/simulators/flow/CompositionalContainer.hpp>
#include <opm/material/fluidsystems/BlackOilDefaultIndexTraits.hpp>
#include <opm/material/fluidsystems/BlackOilFluidSystem.hpp>
#include <opm/material/fluidsystems/GenericOilGasFluidSystem.hpp>
namespace Opm {
template<class FluidSystem>
void CompositionalContainer<FluidSystem>::
allocate(const unsigned bufferSize,
std::map<std::string, int>& rstKeywords)
{
if (auto& zmf = rstKeywords["ZMF"]; zmf > 0) {
zmf = 0;
this->allocated_ = true;
for (int i = 0; i < numComponents; ++i) {
moleFractions_[i].resize(bufferSize, 0.0);
}
}
if (auto& xmf = rstKeywords["XMF"]; xmf > 0 && FluidSystem::phaseIsActive(oilPhaseIdx)) {
this->allocated_ = true;
xmf = 0;
for (int i = 0; i < numComponents; ++i) {
phaseMoleFractions_[oilPhaseIdx][i].resize(bufferSize, 0.0);
}
}
if (auto& ymf = rstKeywords["YMF"]; ymf > 0 && FluidSystem::phaseIsActive(gasPhaseIdx)) {
this->allocated_ = true;
ymf = 0;
for (int i = 0; i < numComponents; ++i) {
phaseMoleFractions_[gasPhaseIdx][i].resize(bufferSize, 0.0);
}
}
}
template<class T> using FS = BlackOilFluidSystem<T,BlackOilDefaultIndexTraits>;
#define INSTANTIATE_TYPE(T) \
template class CompositionalContainer<FS<T>>;
INSTANTIATE_TYPE(double)
#if FLOW_INSTANTIATE_FLOAT
INSTANTIATE_TYPE(float)
#endif
#define INSTANTIATE_COMP(NUM) \
template<class T> using FS##NUM = GenericOilGasFluidSystem<T, NUM>; \
template class CompositionalContainer<FS##NUM<double>>;
INSTANTIATE_COMP(0)
INSTANTIATE_COMP(2)
INSTANTIATE_COMP(3)
INSTANTIATE_COMP(4)
INSTANTIATE_COMP(5)
INSTANTIATE_COMP(6)
INSTANTIATE_COMP(7)
} // namespace Opm

View File

@ -27,6 +27,8 @@
#define OPM_COMPOSITIONAL_CONTAINER_HPP
#include <array>
#include <map>
#include <string>
#include <vector>
namespace Opm {
@ -38,9 +40,17 @@ class CompositionalContainer
using ScalarBuffer = std::vector<Scalar>;
static constexpr int numComponents = FluidSystem::numComponents;
static constexpr int numPhases = FluidSystem::numPhases;
static constexpr int gasPhaseIdx = FluidSystem::gasPhaseIdx;
static constexpr int oilPhaseIdx = FluidSystem::oilPhaseIdx;
static constexpr int waterPhaseIdx = FluidSystem::waterPhaseIdx;
public:
void allocate(const unsigned bufferSize,
std::map<std::string, int>& rstKeywords);
bool allocated_ = false;
// total mole fractions for each component
std::array<ScalarBuffer, numComponents> moleFractions_;
// mole fractions for each component in each phase

View File

@ -1294,26 +1294,7 @@ doAllocBuffers(const unsigned bufferSize,
}
if (this->isCompositional_) {
if (rstKeywords["ZMF"] > 0) {
rstKeywords["ZMF"] = 0;
for (int i = 0; i < numComponents; ++i) {
compC_.moleFractions_[i].resize(bufferSize, 0.0);
}
}
if (rstKeywords["XMF"] > 0 && FluidSystem::phaseIsActive(oilPhaseIdx)) {
rstKeywords["XMF"] = 0;
for (int i = 0; i < numComponents; ++i) {
compC_.phaseMoleFractions_[oilPhaseIdx][i].resize(bufferSize, 0.0);
}
}
if (rstKeywords["YMF"] > 0 && FluidSystem::phaseIsActive(gasPhaseIdx)) {
rstKeywords["YMF"] = 0;
for (int i = 0; i < numComponents; ++i) {
compC_.phaseMoleFractions_[gasPhaseIdx][i].resize(bufferSize, 0.0);
}
}
this->compC_.allocate(bufferSize, rstKeywords);
}