vtkcompositionmodule: move parameters to dedicated struct with a translation unit

This commit is contained in:
Arne Morten Kvarving
2024-09-16 08:43:09 +02:00
parent c7c15fbe23
commit 2d000835a7
4 changed files with 183 additions and 99 deletions

View File

@@ -67,6 +67,7 @@ list (APPEND MAIN_SOURCE_FILES
opm/models/io/vtkblackoilpolymerparams.cpp
opm/models/io/vtkblackoilparams.cpp
opm/models/io/vtkblackoilsolventparams.cpp
opm/models/io/vtkcompositionparams.cpp
opm/models/io/restart.cpp
opm/models/parallel/mpiutil.cpp
opm/models/parallel/tasklets.cpp
@@ -665,6 +666,7 @@ list (APPEND PUBLIC_HEADER_FILES
opm/models/io/vtkblackoilsolventmodule.hpp
opm/models/io/vtkblackoilsolventparams.hpp
opm/models/io/vtkcompositionmodule.hpp
opm/models/io/vtkcompositionparams.hpp
opm/models/io/vtkdiffusionmodule.hh
opm/models/io/vtkdiscretefracturemodule.hh
opm/models/io/vtkenergymodule.hh

View File

@@ -32,24 +32,12 @@
#include <opm/models/discretization/common/fvbaseparameters.hh>
#include <opm/models/io/baseoutputmodule.hh>
#include <opm/models/io/vtkcompositionparams.hpp>
#include <opm/models/io/vtkmultiwriter.hh>
#include <opm/models/utils/parametersystem.hpp>
#include <opm/models/utils/propertysystem.hh>
namespace Opm::Parameters {
// set default values for what quantities to output
struct VtkWriteMassFractions { static constexpr bool value = false; };
struct VtkWriteMoleFractions { static constexpr bool value = true; };
struct VtkWriteTotalMassFractions { static constexpr bool value = false; };
struct VtkWriteTotalMoleFractions { static constexpr bool value = false; };
struct VtkWriteMolarities { static constexpr bool value = false; };
struct VtkWriteFugacities { static constexpr bool value = false; };
struct VtkWriteFugacityCoeffs { static constexpr bool value = false; };
} // namespace Opm::Properties
namespace Opm {
/*!
@@ -88,27 +76,16 @@ class VtkCompositionModule : public BaseOutputModule<TypeTag>
public:
VtkCompositionModule(const Simulator& simulator)
: ParentType(simulator)
{ }
{
params_.read();
}
/*!
* \brief Register all run-time parameters for the Vtk output module.
*/
static void registerParameters()
{
Parameters::Register<Parameters::VtkWriteMassFractions>
("Include mass fractions in the VTK output files");
Parameters::Register<Parameters::VtkWriteMoleFractions>
("Include mole fractions in the VTK output files");
Parameters::Register<Parameters::VtkWriteTotalMassFractions>
("Include total mass fractions in the VTK output files");
Parameters::Register<Parameters::VtkWriteTotalMoleFractions>
("Include total mole fractions in the VTK output files");
Parameters::Register<Parameters::VtkWriteMolarities>
("Include component molarities in the VTK output files");
Parameters::Register<Parameters::VtkWriteFugacities>
("Include component fugacities in the VTK output files");
Parameters::Register<Parameters::VtkWriteFugacityCoeffs>
("Include component fugacity coefficients in the VTK output files");
VtkCompositionParams::registerParameters();
}
/*!
@@ -117,22 +94,29 @@ public:
*/
void allocBuffers()
{
if (moleFracOutput_())
if (params_.moleFracOutput_) {
this->resizePhaseComponentBuffer_(moleFrac_);
if (massFracOutput_())
}
if (params_.massFracOutput_) {
this->resizePhaseComponentBuffer_(massFrac_);
if (totalMassFracOutput_())
}
if (params_.totalMassFracOutput_) {
this->resizeComponentBuffer_(totalMassFrac_);
if (totalMoleFracOutput_())
}
if (params_.totalMoleFracOutput_) {
this->resizeComponentBuffer_(totalMoleFrac_);
if (molarityOutput_())
}
if (params_.molarityOutput_) {
this->resizePhaseComponentBuffer_(molarity_);
}
if (fugacityOutput_())
if (params_.fugacityOutput_) {
this->resizeComponentBuffer_(fugacity_);
if (fugacityCoeffOutput_())
}
if (params_.fugacityCoeffOutput_) {
this->resizePhaseComponentBuffer_(fugacityCoeff_);
}
}
/*!
* \brief Modify the internal buffers according to the intensive quantities relevant
@@ -153,21 +137,25 @@ public:
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
if (moleFracOutput_())
if (params_.moleFracOutput_) {
moleFrac_[phaseIdx][compIdx][I] = Toolbox::value(fs.moleFraction(phaseIdx, compIdx));
if (massFracOutput_())
}
if (params_.massFracOutput_) {
massFrac_[phaseIdx][compIdx][I] = Toolbox::value(fs.massFraction(phaseIdx, compIdx));
if (molarityOutput_())
}
if (params_.molarityOutput_) {
molarity_[phaseIdx][compIdx][I] = Toolbox::value(fs.molarity(phaseIdx, compIdx));
}
if (fugacityCoeffOutput_())
if (params_.fugacityCoeffOutput_) {
fugacityCoeff_[phaseIdx][compIdx][I] =
Toolbox::value(fs.fugacityCoefficient(phaseIdx, compIdx));
}
}
}
for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
if (totalMassFracOutput_()) {
if (params_.totalMassFracOutput_) {
Scalar compMass = 0;
Scalar totalMass = 0;
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
@@ -179,7 +167,7 @@ public:
}
totalMassFrac_[compIdx][I] = compMass / totalMass;
}
if (totalMoleFracOutput_()) {
if (params_.totalMoleFracOutput_) {
Scalar compMoles = 0;
Scalar totalMoles = 0;
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
@@ -193,90 +181,57 @@ public:
}
totalMoleFrac_[compIdx][I] = compMoles / totalMoles;
}
if (fugacityOutput_())
if (params_.fugacityOutput_) {
fugacity_[compIdx][I] = Toolbox::value(intQuants.fluidState().fugacity(/*phaseIdx=*/0, compIdx));
}
}
}
}
/*!
* \brief Add all buffers to the VTK output writer.
*/
void commitBuffers(BaseOutputWriter& baseWriter)
{
VtkMultiWriter *vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
VtkMultiWriter* vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
if (!vtkWriter) {
return;
}
if (moleFracOutput_())
if (params_.moleFracOutput_) {
this->commitPhaseComponentBuffer_(baseWriter, "moleFrac_%s^%s", moleFrac_);
if (massFracOutput_())
}
if (params_.massFracOutput_) {
this->commitPhaseComponentBuffer_(baseWriter, "massFrac_%s^%s", massFrac_);
if (molarityOutput_())
}
if (params_.molarityOutput_) {
this->commitPhaseComponentBuffer_(baseWriter, "molarity_%s^%s", molarity_);
if (totalMassFracOutput_())
}
if (params_.totalMassFracOutput_) {
this->commitComponentBuffer_(baseWriter, "totalMassFrac^%s", totalMassFrac_);
if (totalMoleFracOutput_())
}
if (params_.totalMoleFracOutput_) {
this->commitComponentBuffer_(baseWriter, "totalMoleFrac^%s", totalMoleFrac_);
}
if (fugacityOutput_())
if (params_.fugacityOutput_) {
this->commitComponentBuffer_(baseWriter, "fugacity^%s", fugacity_);
if (fugacityCoeffOutput_())
}
if (params_.fugacityCoeffOutput_) {
this->commitPhaseComponentBuffer_(baseWriter, "fugacityCoeff_%s^%s", fugacityCoeff_);
}
}
private:
static bool massFracOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWriteMassFractions>();
return val;
}
VtkCompositionParams params_{};
PhaseComponentBuffer moleFrac_{};
PhaseComponentBuffer massFrac_{};
PhaseComponentBuffer molarity_{};
ComponentBuffer totalMassFrac_{};
ComponentBuffer totalMoleFrac_{};
static bool moleFracOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWriteMoleFractions>();
return val;
}
static bool totalMassFracOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWriteTotalMassFractions>();
return val;
}
static bool totalMoleFracOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWriteTotalMoleFractions>();
return val;
}
static bool molarityOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWriteMolarities>();
return val;
}
static bool fugacityOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWriteFugacities>();
return val;
}
static bool fugacityCoeffOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWriteFugacityCoeffs>();
return val;
}
PhaseComponentBuffer moleFrac_;
PhaseComponentBuffer massFrac_;
PhaseComponentBuffer molarity_;
ComponentBuffer totalMassFrac_;
ComponentBuffer totalMoleFrac_;
ComponentBuffer fugacity_;
PhaseComponentBuffer fugacityCoeff_;
ComponentBuffer fugacity_{};
PhaseComponentBuffer fugacityCoeff_{};
};
} // namespace Opm

View File

@@ -0,0 +1,60 @@
// -*- 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/models/io/vtkcompositionparams.hpp>
#include <opm/models/utils/parametersystem.hpp>
namespace Opm {
void VtkCompositionParams::registerParameters()
{
Parameters::Register<Parameters::VtkWriteMassFractions>
("Include mass fractions in the VTK output files");
Parameters::Register<Parameters::VtkWriteMoleFractions>
("Include mole fractions in the VTK output files");
Parameters::Register<Parameters::VtkWriteTotalMassFractions>
("Include total mass fractions in the VTK output files");
Parameters::Register<Parameters::VtkWriteTotalMoleFractions>
("Include total mole fractions in the VTK output files");
Parameters::Register<Parameters::VtkWriteMolarities>
("Include component molarities in the VTK output files");
Parameters::Register<Parameters::VtkWriteFugacities>
("Include component fugacities in the VTK output files");
Parameters::Register<Parameters::VtkWriteFugacityCoeffs>
("Include component fugacity coefficients in the VTK output files");
}
void VtkCompositionParams::read()
{
massFracOutput_ = Parameters::Get<Parameters::VtkWriteMassFractions>();
moleFracOutput_ = Parameters::Get<Parameters::VtkWriteMoleFractions>();
totalMassFracOutput_ = Parameters::Get<Parameters::VtkWriteTotalMassFractions>();
totalMoleFracOutput_ = Parameters::Get<Parameters::VtkWriteTotalMoleFractions>();
molarityOutput_ = Parameters::Get<Parameters::VtkWriteMolarities>();
fugacityOutput_ = Parameters::Get<Parameters::VtkWriteFugacities>();
fugacityCoeffOutput_ = Parameters::Get<Parameters::VtkWriteFugacityCoeffs>();
}
} // namespace Opm

View File

@@ -0,0 +1,67 @@
// -*- 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::VtkCompositionModule
*/
#ifndef OPM_VTK_COMPOSITION_PARAMS_HPP
#define OPM_VTK_COMPOSITION_PARAMS_HPP
namespace Opm::Parameters {
// set default values for what quantities to output
struct VtkWriteMassFractions { static constexpr bool value = false; };
struct VtkWriteMoleFractions { static constexpr bool value = true; };
struct VtkWriteTotalMassFractions { static constexpr bool value = false; };
struct VtkWriteTotalMoleFractions { static constexpr bool value = false; };
struct VtkWriteMolarities { static constexpr bool value = false; };
struct VtkWriteFugacities { static constexpr bool value = false; };
struct VtkWriteFugacityCoeffs { static constexpr bool value = false; };
} // namespace Opm::Properties
namespace Opm {
/*!
* \brief Struct holding the parameters for VtkCompositionModule.
*/
struct VtkCompositionParams
{
//! \brief Registers the parameters in parameter system.
static void registerParameters();
//! \brief Reads the parameter values from the parameter system.
void read();
bool massFracOutput_;
bool moleFracOutput_;
bool totalMassFracOutput_;
bool totalMoleFracOutput_;
bool molarityOutput_;
bool fugacityOutput_;
bool fugacityCoeffOutput_;
};
} // namespace Opm
#endif // OPM_VTK_COMPOSITION_PARAMS_HPP