Merge pull request #5987 from akva2/tracer_container

Add TracerContainer, a container for tracer data output
This commit is contained in:
Bård Skaflestad 2025-02-14 10:54:12 +01:00 committed by GitHub
commit ee6d34f4a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 239 additions and 77 deletions

View File

@ -120,6 +120,7 @@ list (APPEND MAIN_SOURCE_FILES
opm/simulators/flow/SimulatorReportBanners.cpp
opm/simulators/flow/SimulatorSerializer.cpp
opm/simulators/flow/SolutionContainers.cpp
opm/simulators/flow/TracerContainer.cpp
opm/simulators/flow/Transmissibility.cpp
opm/simulators/flow/ValidationFunctions.cpp
opm/simulators/flow/equil/EquilibrationHelpers.cpp
@ -880,6 +881,7 @@ list (APPEND PUBLIC_HEADER_FILES
opm/simulators/flow/SolutionContainers.hpp
opm/simulators/flow/SubDomain.hpp
opm/simulators/flow/TTagFlowProblemTPFA.hpp
opm/simulators/flow/TracerContainer.hpp
opm/simulators/flow/TracerModel.hpp
opm/simulators/flow/Transmissibility.hpp
opm/simulators/flow/Transmissibility_impl.hpp

View File

@ -123,6 +123,7 @@ GenericOutputBlackoilModule(const EclipseState& eclState,
, enableSaltPrecipitation_(enableSaltPrecipitation)
, enableExtbo_(enableExtbo)
, enableMICP_(enableMICP)
, tracerC_(eclState_)
, local_data_valid_(false)
{
const auto& fp = eclState_.fieldProps();
@ -631,41 +632,7 @@ assignToSolution(data::Solution& sol)
this->fipC_.outputRestart(sol);
// Tracers
if (! this->freeTracerConcentrations_.empty()) {
const auto& tracers = this->eclState_.tracer();
for (auto tracerIdx = 0*tracers.size();
tracerIdx < tracers.size(); ++tracerIdx)
{
sol.insert(tracers[tracerIdx].fname(),
UnitSystem::measure::identity,
std::move(freeTracerConcentrations_[tracerIdx]),
data::TargetType::RESTART_TRACER_SOLUTION);
}
// Put freeTracerConcentrations container into a valid state. Otherwise
// we'll move from vectors that have already been moved from if we
// get here and it's not a restart step.
this->freeTracerConcentrations_.clear();
}
if (! this->solTracerConcentrations_.empty()) {
const auto& tracers = this->eclState_.tracer();
for (auto tracerIdx = 0*tracers.size();
tracerIdx < tracers.size(); ++tracerIdx)
{
if (solTracerConcentrations_[tracerIdx].empty())
continue;
sol.insert(tracers[tracerIdx].sname(),
UnitSystem::measure::identity,
std::move(solTracerConcentrations_[tracerIdx]),
data::TargetType::RESTART_TRACER_SOLUTION);
}
// Put solTracerConcentrations container into a valid state. Otherwise
// we'll move from vectors that have already been moved from if we
// get here and it's not a restart step.
this->solTracerConcentrations_.clear();
}
this->tracerC_.outputRestart(sol);
}
template<class FluidSystem>
@ -789,8 +756,6 @@ doAllocBuffers(const unsigned bufferSize,
const bool enablePCHysteresis,
const bool enableNonWettingHysteresis,
const bool enableWettingHysteresis,
const unsigned numTracers,
const std::vector<bool>& enableSolTracers,
const unsigned numOutputNnc,
std::map<std::string, int> rstKeywords)
{
@ -1220,19 +1185,7 @@ doAllocBuffers(const unsigned bufferSize,
}
// tracers
if (numTracers > 0) {
freeTracerConcentrations_.resize(numTracers);
for (unsigned tracerIdx = 0; tracerIdx < numTracers; ++tracerIdx)
{
freeTracerConcentrations_[tracerIdx].resize(bufferSize, 0.0);
}
solTracerConcentrations_.resize(numTracers);
for (unsigned tracerIdx = 0; tracerIdx < numTracers; ++tracerIdx)
{
if (enableSolTracers[tracerIdx])
solTracerConcentrations_[tracerIdx].resize(bufferSize, 0.0);
}
}
this->tracerC_.allocate(bufferSize);
if (rstKeywords["RESIDUAL"] > 0) {
rstKeywords["RESIDUAL"] = 0;

View File

@ -40,6 +40,7 @@
#include <opm/simulators/flow/MechContainer.hpp>
#include <opm/simulators/flow/MICPContainer.hpp>
#include <opm/simulators/flow/RegionPhasePVAverage.hpp>
#include <opm/simulators/flow/TracerContainer.hpp>
#include <opm/simulators/utils/ParallelCommunication.hpp>
@ -330,8 +331,6 @@ protected:
const bool enablePCHysteresis = false,
const bool enableNonWettingHysteresis = false,
const bool enableWettingHysteresis = false,
unsigned numTracers = 0,
const std::vector<bool>& enableSolTracers = {},
unsigned numOutputNnc = 0,
std::map<std::string, int> rstKeywords = {});
@ -467,8 +466,7 @@ protected:
std::array<ScalarBuffer, numPhases> viscosity_;
std::array<ScalarBuffer, numPhases> relativePermeability_;
std::vector<ScalarBuffer> freeTracerConcentrations_;
std::vector<ScalarBuffer> solTracerConcentrations_;
TracerContainer<FluidSystem> tracerC_;
std::array<ScalarBuffer, numPhases> residual_;

View File

@ -188,8 +188,6 @@ public:
problem.materialLawManager()->enablePCHysteresis(),
problem.materialLawManager()->enableNonWettingHysteresis(),
problem.materialLawManager()->enableWettingHysteresis(),
problem.tracerModel().numTracers(),
problem.tracerModel().enableSolTracers(),
problem.eclWriter()->getOutputNnc().size());
}
@ -647,25 +645,14 @@ public:
// tracers
const auto& tracerModel = simulator_.problem().tracerModel();
if (! this->freeTracerConcentrations_.empty()) {
for (int tracerIdx = 0; tracerIdx < tracerModel.numTracers(); ++tracerIdx) {
if (this->freeTracerConcentrations_[tracerIdx].empty()) {
continue;
}
this->freeTracerConcentrations_[tracerIdx][globalDofIdx] =
tracerModel.freeTracerConcentration(tracerIdx, globalDofIdx);
}
}
if (! this->solTracerConcentrations_.empty()) {
for (int tracerIdx = 0; tracerIdx < tracerModel.numTracers(); ++tracerIdx) {
if (this->solTracerConcentrations_[tracerIdx].empty()) {
continue;
}
this->solTracerConcentrations_[tracerIdx][globalDofIdx] =
tracerModel.solTracerConcentration(tracerIdx, globalDofIdx);
}
}
this->tracerC_.assignFreeConcentrations(globalDofIdx,
[globalDofIdx, &tracerModel](const unsigned tracerIdx)
{ return tracerModel.freeTracerConcentration(tracerIdx,
globalDofIdx); });
this->tracerC_.assignSolConcentrations(globalDofIdx,
[globalDofIdx, &tracerModel](const unsigned tracerIdx)
{ return tracerModel.solTracerConcentration(tracerIdx,
globalDofIdx); });
// output residual
for ( int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx )

View File

@ -166,8 +166,6 @@ public:
/* enablePCHysteresis = */ false,
/* enableNonWettingHysteresis =*/ false,
/* enableWettingHysteresis =*/ false,
/* numTracers = */ 0,
/* enableSoltracers =*/ {},
/* numOutputNnc =*/ 0,
std::move(rstKeywords));
}

View File

@ -0,0 +1,154 @@
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
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 2 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/>.
Consult the COPYING file in the top-level source directory of this
module for the precise wording of the license and the list of
copyright holders.
*/
#include <config.h>
#include <opm/simulators/flow/TracerContainer.hpp>
#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
#include <opm/material/fluidsystems/BlackOilDefaultIndexTraits.hpp>
#include <opm/material/fluidsystems/BlackOilFluidSystem.hpp>
#include <opm/material/fluidsystems/GenericOilGasWaterFluidSystem.hpp>
#include <opm/output/data/Solution.hpp>
#include <algorithm>
#include <utility>
namespace Opm {
template<class FluidSystem>
void TracerContainer<FluidSystem>::
allocate(const unsigned bufferSize)
{
const auto& tracers = eclState_.tracer();
if (!tracers.empty()) {
allocated_ = true;
freeConcentrations_.resize(tracers.size());
solConcentrations_.resize(tracers.size());
std::for_each(tracers.begin(), tracers.end(),
[idx = 0, bufferSize, this](const auto& tracer) mutable
{
freeConcentrations_[idx].resize(bufferSize, 0.0);
if (((tracer.phase == Phase::GAS && FluidSystem::enableDissolvedGas()) ||
(tracer.phase == Phase::OIL && FluidSystem::enableVaporizedOil())) &&
(tracer.solution_concentration.has_value() ||
tracer.solution_tvdp.has_value()))
{
solConcentrations_[idx].resize(bufferSize, 0.0);
}
++idx;
});
}
}
template<class FluidSystem>
void TracerContainer<FluidSystem>::
assignFreeConcentrations(const unsigned globalDofIdx,
const AssignFunction& concentration)
{
std::for_each(freeConcentrations_.begin(), freeConcentrations_.end(),
[globalDofIdx, idx = 0, &concentration](auto& tracer) mutable
{
if (!tracer.empty()) {
tracer[globalDofIdx] = concentration(idx);
}
++idx;
});
}
template<class FluidSystem>
void TracerContainer<FluidSystem>::
assignSolConcentrations(const unsigned globalDofIdx,
const AssignFunction& concentration)
{
std::for_each(solConcentrations_.begin(), solConcentrations_.end(),
[globalDofIdx, idx = 0, &concentration](auto& tracer) mutable
{
if (!tracer.empty()) {
tracer[globalDofIdx] = concentration(idx);
}
++idx;
});
}
template<class FluidSystem>
void TracerContainer<FluidSystem>::
outputRestart(data::Solution& sol)
{
if (!this->allocated_) {
return;
}
const auto& tracers = this->eclState_.tracer();
std::for_each(tracers.begin(), tracers.end(),
[idx = 0, &sol, this](const auto& tracer) mutable
{
sol.insert(tracer.fname(),
UnitSystem::measure::identity,
std::move(freeConcentrations_[idx]),
data::TargetType::RESTART_TRACER_SOLUTION);
if (!solConcentrations_[idx].empty()) {
sol.insert(tracer.sname(),
UnitSystem::measure::identity,
std::move(solConcentrations_[idx]),
data::TargetType::RESTART_TRACER_SOLUTION);
}
++idx;
});
this->allocated_ = false;
}
template<class T> using FS = BlackOilFluidSystem<T,BlackOilDefaultIndexTraits>;
#define INSTANTIATE_TYPE(T) \
template class TracerContainer<FS<T>>;
INSTANTIATE_TYPE(double)
#if FLOW_INSTANTIATE_FLOAT
INSTANTIATE_TYPE(float)
#endif
#define INSTANTIATE_COMP_THREEPHASE(NUM) \
template<class T> using FS##NUM = GenericOilGasWaterFluidSystem<T, NUM, true>; \
template class TracerContainer<FS##NUM<double>>;
#define INSTANTIATE_COMP_TWOPHASE(NUM) \
template<class T> using GFS##NUM = GenericOilGasWaterFluidSystem<T, NUM, false>; \
template class TracerContainer<GFS##NUM<double>>;
#define INSTANTIATE_COMP(NUM) \
INSTANTIATE_COMP_THREEPHASE(NUM) \
INSTANTIATE_COMP_TWOPHASE(NUM)
INSTANTIATE_COMP_THREEPHASE(0) // \Note: to register the parameter ForceDisableFluidInPlaceOutput
INSTANTIATE_COMP(2)
INSTANTIATE_COMP(3)
INSTANTIATE_COMP(4)
INSTANTIATE_COMP(5)
INSTANTIATE_COMP(6)
INSTANTIATE_COMP(7)
} // namespace Opm

View File

@ -0,0 +1,70 @@
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
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 2 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/>.
Consult the COPYING file in the top-level source directory of this
module for the precise wording of the license and the list of
copyright holders.
*/
/*!
* \file
* \copydoc Opm::OutputBlackOilModule
*/
#ifndef OPM_TRACER_CONTAINER_HPP
#define OPM_TRACER_CONTAINER_HPP
#include <functional>
#include <vector>
namespace Opm {
namespace data { class Solution; }
class EclipseState;
template<class FluidSystem>
class TracerContainer
{
using Scalar = typename FluidSystem::Scalar;
using ScalarBuffer = std::vector<Scalar>;
public:
TracerContainer(const EclipseState& eclState)
: eclState_(eclState)
{}
void allocate(const unsigned bufferSize);
using AssignFunction = std::function<Scalar(const unsigned)>;
void assignFreeConcentrations(const unsigned globalDofIdx,
const AssignFunction& concentration);
void assignSolConcentrations(const unsigned globalDofIdx,
const AssignFunction& concentration);
void outputRestart(data::Solution& sol);
private:
const EclipseState& eclState_;
std::vector<ScalarBuffer> freeConcentrations_{};
std::vector<ScalarBuffer> solConcentrations_{};
bool allocated_{false};
};
} // namespace Opm
#endif // OPM_TRACER_CONTAINER_HPP