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

View File

@@ -32,24 +32,12 @@
#include <opm/models/discretization/common/fvbaseparameters.hh> #include <opm/models/discretization/common/fvbaseparameters.hh>
#include <opm/models/io/baseoutputmodule.hh> #include <opm/models/io/baseoutputmodule.hh>
#include <opm/models/io/vtkcompositionparams.hpp>
#include <opm/models/io/vtkmultiwriter.hh> #include <opm/models/io/vtkmultiwriter.hh>
#include <opm/models/utils/parametersystem.hpp> #include <opm/models/utils/parametersystem.hpp>
#include <opm/models/utils/propertysystem.hh> #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 { namespace Opm {
/*! /*!
@@ -88,27 +76,16 @@ class VtkCompositionModule : public BaseOutputModule<TypeTag>
public: public:
VtkCompositionModule(const Simulator& simulator) VtkCompositionModule(const Simulator& simulator)
: ParentType(simulator) : ParentType(simulator)
{ } {
params_.read();
}
/*! /*!
* \brief Register all run-time parameters for the Vtk output module. * \brief Register all run-time parameters for the Vtk output module.
*/ */
static void registerParameters() static void registerParameters()
{ {
Parameters::Register<Parameters::VtkWriteMassFractions> VtkCompositionParams::registerParameters();
("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");
} }
/*! /*!
@@ -117,21 +94,28 @@ public:
*/ */
void allocBuffers() void allocBuffers()
{ {
if (moleFracOutput_()) if (params_.moleFracOutput_) {
this->resizePhaseComponentBuffer_(moleFrac_); this->resizePhaseComponentBuffer_(moleFrac_);
if (massFracOutput_()) }
if (params_.massFracOutput_) {
this->resizePhaseComponentBuffer_(massFrac_); this->resizePhaseComponentBuffer_(massFrac_);
if (totalMassFracOutput_()) }
if (params_.totalMassFracOutput_) {
this->resizeComponentBuffer_(totalMassFrac_); this->resizeComponentBuffer_(totalMassFrac_);
if (totalMoleFracOutput_()) }
if (params_.totalMoleFracOutput_) {
this->resizeComponentBuffer_(totalMoleFrac_); this->resizeComponentBuffer_(totalMoleFrac_);
if (molarityOutput_()) }
if (params_.molarityOutput_) {
this->resizePhaseComponentBuffer_(molarity_); this->resizePhaseComponentBuffer_(molarity_);
}
if (fugacityOutput_()) if (params_.fugacityOutput_) {
this->resizeComponentBuffer_(fugacity_); this->resizeComponentBuffer_(fugacity_);
if (fugacityCoeffOutput_()) }
if (params_.fugacityCoeffOutput_) {
this->resizePhaseComponentBuffer_(fugacityCoeff_); this->resizePhaseComponentBuffer_(fugacityCoeff_);
}
} }
/*! /*!
@@ -153,21 +137,25 @@ public:
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) { for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) { for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
if (moleFracOutput_()) if (params_.moleFracOutput_) {
moleFrac_[phaseIdx][compIdx][I] = Toolbox::value(fs.moleFraction(phaseIdx, compIdx)); 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)); 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)); molarity_[phaseIdx][compIdx][I] = Toolbox::value(fs.molarity(phaseIdx, compIdx));
}
if (fugacityCoeffOutput_()) if (params_.fugacityCoeffOutput_) {
fugacityCoeff_[phaseIdx][compIdx][I] = fugacityCoeff_[phaseIdx][compIdx][I] =
Toolbox::value(fs.fugacityCoefficient(phaseIdx, compIdx)); Toolbox::value(fs.fugacityCoefficient(phaseIdx, compIdx));
}
} }
} }
for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) { for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
if (totalMassFracOutput_()) { if (params_.totalMassFracOutput_) {
Scalar compMass = 0; Scalar compMass = 0;
Scalar totalMass = 0; Scalar totalMass = 0;
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) { for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
@@ -179,7 +167,7 @@ public:
} }
totalMassFrac_[compIdx][I] = compMass / totalMass; totalMassFrac_[compIdx][I] = compMass / totalMass;
} }
if (totalMoleFracOutput_()) { if (params_.totalMoleFracOutput_) {
Scalar compMoles = 0; Scalar compMoles = 0;
Scalar totalMoles = 0; Scalar totalMoles = 0;
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) { for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
@@ -193,8 +181,9 @@ public:
} }
totalMoleFrac_[compIdx][I] = compMoles / totalMoles; totalMoleFrac_[compIdx][I] = compMoles / totalMoles;
} }
if (fugacityOutput_()) if (params_.fugacityOutput_) {
fugacity_[compIdx][I] = Toolbox::value(intQuants.fluidState().fugacity(/*phaseIdx=*/0, compIdx)); fugacity_[compIdx][I] = Toolbox::value(intQuants.fluidState().fugacity(/*phaseIdx=*/0, compIdx));
}
} }
} }
} }
@@ -204,79 +193,45 @@ public:
*/ */
void commitBuffers(BaseOutputWriter& baseWriter) void commitBuffers(BaseOutputWriter& baseWriter)
{ {
VtkMultiWriter *vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter); VtkMultiWriter* vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
if (!vtkWriter) { if (!vtkWriter) {
return; return;
} }
if (moleFracOutput_()) if (params_.moleFracOutput_) {
this->commitPhaseComponentBuffer_(baseWriter, "moleFrac_%s^%s", moleFrac_); this->commitPhaseComponentBuffer_(baseWriter, "moleFrac_%s^%s", moleFrac_);
if (massFracOutput_()) }
if (params_.massFracOutput_) {
this->commitPhaseComponentBuffer_(baseWriter, "massFrac_%s^%s", massFrac_); this->commitPhaseComponentBuffer_(baseWriter, "massFrac_%s^%s", massFrac_);
if (molarityOutput_()) }
if (params_.molarityOutput_) {
this->commitPhaseComponentBuffer_(baseWriter, "molarity_%s^%s", molarity_); this->commitPhaseComponentBuffer_(baseWriter, "molarity_%s^%s", molarity_);
if (totalMassFracOutput_()) }
if (params_.totalMassFracOutput_) {
this->commitComponentBuffer_(baseWriter, "totalMassFrac^%s", totalMassFrac_); this->commitComponentBuffer_(baseWriter, "totalMassFrac^%s", totalMassFrac_);
if (totalMoleFracOutput_()) }
if (params_.totalMoleFracOutput_) {
this->commitComponentBuffer_(baseWriter, "totalMoleFrac^%s", totalMoleFrac_); this->commitComponentBuffer_(baseWriter, "totalMoleFrac^%s", totalMoleFrac_);
}
if (fugacityOutput_()) if (params_.fugacityOutput_) {
this->commitComponentBuffer_(baseWriter, "fugacity^%s", fugacity_); this->commitComponentBuffer_(baseWriter, "fugacity^%s", fugacity_);
if (fugacityCoeffOutput_()) }
if (params_.fugacityCoeffOutput_) {
this->commitPhaseComponentBuffer_(baseWriter, "fugacityCoeff_%s^%s", fugacityCoeff_); this->commitPhaseComponentBuffer_(baseWriter, "fugacityCoeff_%s^%s", fugacityCoeff_);
}
} }
private: private:
static bool massFracOutput_() VtkCompositionParams params_{};
{ PhaseComponentBuffer moleFrac_{};
static bool val = Parameters::Get<Parameters::VtkWriteMassFractions>(); PhaseComponentBuffer massFrac_{};
return val; PhaseComponentBuffer molarity_{};
} ComponentBuffer totalMassFrac_{};
ComponentBuffer totalMoleFrac_{};
static bool moleFracOutput_() ComponentBuffer fugacity_{};
{ PhaseComponentBuffer fugacityCoeff_{};
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_;
}; };
} // namespace Opm } // 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