vtkenergymodule: 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 85bbba93fa
commit 924da68d02
4 changed files with 151 additions and 63 deletions

View File

@ -70,6 +70,7 @@ list (APPEND MAIN_SOURCE_FILES
opm/models/io/vtkcompositionparams.cpp
opm/models/io/vtkdiffusionparams.cpp
opm/models/io/vtkdiscretefractureparams.cpp
opm/models/io/vtkenergyparams.cpp
opm/models/io/restart.cpp
opm/models/parallel/mpiutil.cpp
opm/models/parallel/tasklets.cpp
@ -674,6 +675,7 @@ list (APPEND PUBLIC_HEADER_FILES
opm/models/io/vtkdiscretefracturemodule.hpp
opm/models/io/vtkdiscretefractureparams.hpp
opm/models/io/vtkenergymodule.hpp
opm/models/io/vtkenergyparams.hpp
opm/models/io/vtkmultiphasemodule.hh
opm/models/io/vtkmultiwriter.hh
opm/models/io/vtkphasepresencemodule.hh

View File

@ -30,6 +30,7 @@
#include <opm/material/common/MathToolbox.hpp>
#include <opm/models/io/baseoutputmodule.hh>
#include <opm/models/io/vtkenergyparams.hpp>
#include <opm/models/io/vtkmultiwriter.hh>
#include <opm/models/discretization/common/fvbaseparameters.hh>
@ -37,16 +38,6 @@
#include <opm/models/utils/parametersystem.hpp>
#include <opm/models/utils/propertysystem.hh>
namespace Opm::Parameters {
// set default values for what quantities to output
struct VtkWriteSolidInternalEnergy { static constexpr bool value = false; };
struct VtkWriteThermalConductivity { static constexpr bool value = false; };
struct VtkWriteInternalEnergies { static constexpr bool value = false; };
struct VtkWriteEnthalpies { static constexpr bool value = false; };
} // namespace Opm::Parameters
namespace Opm {
/*!
@ -86,6 +77,7 @@ public:
VtkEnergyModule(const Simulator& simulator)
: ParentType(simulator)
{
params_.read();
}
/*!
@ -93,18 +85,7 @@ public:
*/
static void registerParameters()
{
Parameters::Register<Parameters::VtkWriteSolidInternalEnergy>
("Include the volumetric internal energy of solid"
"matrix in the VTK output files");
Parameters::Register<Parameters::VtkWriteThermalConductivity>
("Include the total thermal conductivity of the"
"medium in the VTK output files");
Parameters::Register<Parameters::VtkWriteEnthalpies>
("Include the specific enthalpy of the phases in "
"the VTK output files");
Parameters::Register<Parameters::VtkWriteInternalEnergies>
("Include the specific internal energy of the "
"phases in the VTK output files");
VtkEnergyParams::registerParameters();
}
/*!
@ -113,15 +94,19 @@ public:
*/
void allocBuffers()
{
if (enthalpyOutput_())
if (params_.enthalpyOutput_) {
this->resizePhaseBuffer_(enthalpy_);
if (internalEnergyOutput_())
}
if (params_.internalEnergyOutput_) {
this->resizePhaseBuffer_(internalEnergy_);
}
if (solidInternalEnergyOutput_())
if (params_.solidInternalEnergyOutput_) {
this->resizeScalarBuffer_(solidInternalEnergy_);
if (thermalConductivityOutput_())
}
if (params_.thermalConductivityOutput_) {
this->resizeScalarBuffer_(thermalConductivity_);
}
}
/*!
@ -139,16 +124,20 @@ public:
const auto& intQuants = elemCtx.intensiveQuantities(i, /*timeIdx=*/0);
const auto& fs = intQuants.fluidState();
if (solidInternalEnergyOutput_())
if (params_.solidInternalEnergyOutput_) {
solidInternalEnergy_[I] = Toolbox::value(intQuants.solidInternalEnergy());
if (thermalConductivityOutput_())
}
if (params_.thermalConductivityOutput_) {
thermalConductivity_[I] = Toolbox::value(intQuants.thermalConductivity());
}
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
if (enthalpyOutput_())
if (params_.enthalpyOutput_) {
enthalpy_[phaseIdx][I] = Toolbox::value(fs.enthalpy(phaseIdx));
if (internalEnergyOutput_())
}
if (params_.internalEnergyOutput_) {
internalEnergy_[phaseIdx][I] = Toolbox::value(fs.internalEnergy(phaseIdx));
}
}
}
}
@ -158,52 +147,33 @@ public:
*/
void commitBuffers(BaseOutputWriter& baseWriter)
{
VtkMultiWriter *vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
VtkMultiWriter* vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
if (!vtkWriter) {
return;
}
if (solidInternalEnergyOutput_())
if (params_.solidInternalEnergyOutput_) {
this->commitScalarBuffer_(baseWriter, "internalEnergySolid", solidInternalEnergy_);
if (thermalConductivityOutput_())
}
if (params_.thermalConductivityOutput_) {
this->commitScalarBuffer_(baseWriter, "thermalConductivity", thermalConductivity_);
}
if (enthalpyOutput_())
if (params_.enthalpyOutput_) {
this->commitPhaseBuffer_(baseWriter, "enthalpy_%s", enthalpy_);
if (internalEnergyOutput_())
}
if (params_.internalEnergyOutput_) {
this->commitPhaseBuffer_(baseWriter, "internalEnergy_%s", internalEnergy_);
}
}
private:
static bool solidInternalEnergyOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWriteSolidInternalEnergy>();
return val;
}
VtkEnergyParams params_{};
PhaseBuffer enthalpy_{};
PhaseBuffer internalEnergy_{};
static bool thermalConductivityOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWriteThermalConductivity>();
return val;
}
static bool enthalpyOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWriteEnthalpies>();
return val;
}
static bool internalEnergyOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWriteInternalEnergies>();
return val;
}
PhaseBuffer enthalpy_;
PhaseBuffer internalEnergy_;
ScalarBuffer thermalConductivity_;
ScalarBuffer solidInternalEnergy_;
ScalarBuffer thermalConductivity_{};
ScalarBuffer solidInternalEnergy_{};
};
} // namespace Opm

View File

@ -0,0 +1,55 @@
// -*- 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/vtkenergyparams.hpp>
#include <opm/models/utils/parametersystem.hpp>
namespace Opm {
void VtkEnergyParams::registerParameters()
{
Parameters::Register<Parameters::VtkWriteSolidInternalEnergy>
("Include the volumetric internal energy of solid"
"matrix in the VTK output files");
Parameters::Register<Parameters::VtkWriteThermalConductivity>
("Include the total thermal conductivity of the"
"medium in the VTK output files");
Parameters::Register<Parameters::VtkWriteEnthalpies>
("Include the specific enthalpy of the phases in "
"the VTK output files");
Parameters::Register<Parameters::VtkWriteInternalEnergies>
("Include the specific internal energy of the "
"phases in the VTK output files");
}
void VtkEnergyParams::read()
{
solidInternalEnergyOutput_ = Parameters::Get<Parameters::VtkWriteSolidInternalEnergy>();
thermalConductivityOutput_ = Parameters::Get<Parameters::VtkWriteThermalConductivity>();
enthalpyOutput_ = Parameters::Get<Parameters::VtkWriteEnthalpies>();
internalEnergyOutput_ = Parameters::Get<Parameters::VtkWriteInternalEnergies>();
}
} // namespace Opm

View File

@ -0,0 +1,61 @@
// -*- 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::VtkEnergyModule
*/
#ifndef OPM_VTK_ENERGY_PARAMS_HPP
#define OPM_VTK_ENERGY_PARAMS_HPP
namespace Opm::Parameters {
// set default values for what quantities to output
struct VtkWriteSolidInternalEnergy { static constexpr bool value = false; };
struct VtkWriteThermalConductivity { static constexpr bool value = false; };
struct VtkWriteInternalEnergies { static constexpr bool value = false; };
struct VtkWriteEnthalpies { static constexpr bool value = false; };
} // namespace Opm::Parameters
namespace Opm {
/*!
* \brief Struct holding the parameters for VtkEnergyModule.
*/
struct VtkEnergyParams
{
//! \brief Registers the parameters in parameter system.
static void registerParameters();
//! \brief Reads the parameter values from the parameter system.
void read();
bool solidInternalEnergyOutput_;
bool thermalConductivityOutput_;
bool enthalpyOutput_;
bool internalEnergyOutput_;
};
} // namespace Opm
#endif // OPM_VTK_ENERGY_PARAMS_HPP