vtkblackoilenergymodule: 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 e50cd2fb82
commit 7a92006ffe
4 changed files with 191 additions and 102 deletions

View File

@@ -62,6 +62,7 @@ list (APPEND MAIN_SOURCE_FILES
opm/models/blackoil/blackoilnewtonmethodparams.cpp opm/models/blackoil/blackoilnewtonmethodparams.cpp
opm/models/blackoil/blackoilpolymerparams.cpp opm/models/blackoil/blackoilpolymerparams.cpp
opm/models/blackoil/blackoilsolventparams.cpp opm/models/blackoil/blackoilsolventparams.cpp
opm/models/io/vtkblackoilenergyparams.cpp
opm/models/io/vtkblackoilparams.cpp opm/models/io/vtkblackoilparams.cpp
opm/models/io/restart.cpp opm/models/io/restart.cpp
opm/models/parallel/mpiutil.cpp opm/models/parallel/mpiutil.cpp
@@ -651,6 +652,7 @@ list (APPEND PUBLIC_HEADER_FILES
opm/models/io/structuredgridvanguard.hh opm/models/io/structuredgridvanguard.hh
opm/models/io/unstructuredgridvanguard.hh opm/models/io/unstructuredgridvanguard.hh
opm/models/io/vtkblackoilenergymodule.hpp opm/models/io/vtkblackoilenergymodule.hpp
opm/models/io/vtkblackoilenergyparams.hpp
opm/models/io/vtkblackoilmicpmodule.hh opm/models/io/vtkblackoilmicpmodule.hh
opm/models/io/vtkblackoilmodule.hpp opm/models/io/vtkblackoilmodule.hpp
opm/models/io/vtkblackoilparams.hpp opm/models/io/vtkblackoilparams.hpp

View File

@@ -36,21 +36,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/vtkblackoilenergyparams.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 VtkWriteRockInternalEnergy { static constexpr bool value = true; };
struct VtkWriteTotalThermalConductivity { static constexpr bool value = true; };
struct VtkWriteFluidInternalEnergies { static constexpr bool value = true; };
struct VtkWriteFluidEnthalpies { static constexpr bool value = true; };
} // namespace Opm::Parameters
namespace Opm { namespace Opm {
/*! /*!
@@ -82,7 +73,11 @@ class VtkBlackOilEnergyModule : public BaseOutputModule<TypeTag>
public: public:
VtkBlackOilEnergyModule(const Simulator& simulator) VtkBlackOilEnergyModule(const Simulator& simulator)
: ParentType(simulator) : ParentType(simulator)
{ } {
if constexpr (enableEnergy) {
params_.read();
}
}
/*! /*!
* \brief Register all run-time parameters for the multi-phase VTK output * \brief Register all run-time parameters for the multi-phase VTK output
@@ -90,19 +85,9 @@ public:
*/ */
static void registerParameters() static void registerParameters()
{ {
if (!enableEnergy) if constexpr (enableEnergy) {
return; VtkBlackoilEnergyParams::registerParameters();
}
Parameters::Register<Parameters::VtkWriteRockInternalEnergy>
("Include the volumetric internal energy of rock "
"in the VTK output files");
Parameters::Register<Parameters::VtkWriteTotalThermalConductivity>
("Include the total thermal conductivity of the medium and the fluids "
"in the VTK output files");
Parameters::Register<Parameters::VtkWriteFluidInternalEnergies>
("Include the internal energies of the fluids in the VTK output files");
Parameters::Register<Parameters::VtkWriteFluidEnthalpies>
("Include the enthalpies of the fluids in the VTK output files");
} }
/*! /*!
@@ -111,22 +96,25 @@ public:
*/ */
void allocBuffers() void allocBuffers()
{ {
if constexpr (enableEnergy) {
if (!Parameters::Get<Parameters::EnableVtkOutput>()) { if (!Parameters::Get<Parameters::EnableVtkOutput>()) {
return; return;
} }
if (!enableEnergy) if (params_.rockInternalEnergyOutput_) {
return;
if (rockInternalEnergyOutput_())
this->resizeScalarBuffer_(rockInternalEnergy_); this->resizeScalarBuffer_(rockInternalEnergy_);
if (totalThermalConductivityOutput_()) }
if (params_.totalThermalConductivityOutput_) {
this->resizeScalarBuffer_(totalThermalConductivity_); this->resizeScalarBuffer_(totalThermalConductivity_);
if (fluidInternalEnergiesOutput_()) }
if (params_.fluidInternalEnergiesOutput_) {
this->resizePhaseBuffer_(fluidInternalEnergies_); this->resizePhaseBuffer_(fluidInternalEnergies_);
if (fluidEnthalpiesOutput_()) }
if (params_.fluidEnthalpiesOutput_) {
this->resizePhaseBuffer_(fluidEnthalpies_); this->resizePhaseBuffer_(fluidEnthalpies_);
} }
}
}
/*! /*!
* \brief Modify the internal buffers according to the intensive quantities relevant for * \brief Modify the internal buffers according to the intensive quantities relevant for
@@ -134,93 +122,78 @@ public:
*/ */
void processElement(const ElementContext& elemCtx) void processElement(const ElementContext& elemCtx)
{ {
if constexpr (enableEnergy) {
if (!Parameters::Get<Parameters::EnableVtkOutput>()) { if (!Parameters::Get<Parameters::EnableVtkOutput>()) {
return; return;
} }
if (!enableEnergy)
return;
for (unsigned dofIdx = 0; dofIdx < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++dofIdx) { for (unsigned dofIdx = 0; dofIdx < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++dofIdx) {
const auto& intQuants = elemCtx.intensiveQuantities(dofIdx, /*timeIdx=*/0); const auto& intQuants = elemCtx.intensiveQuantities(dofIdx, /*timeIdx=*/0);
unsigned globalDofIdx = elemCtx.globalSpaceIndex(dofIdx, /*timeIdx=*/0); unsigned globalDofIdx = elemCtx.globalSpaceIndex(dofIdx, /*timeIdx=*/0);
if (rockInternalEnergyOutput_()) if (params_.rockInternalEnergyOutput_) {
rockInternalEnergy_[globalDofIdx] = rockInternalEnergy_[globalDofIdx] =
scalarValue(intQuants.rockInternalEnergy()); scalarValue(intQuants.rockInternalEnergy());
}
if (totalThermalConductivityOutput_()) if (params_.totalThermalConductivityOutput_) {
totalThermalConductivity_[globalDofIdx] = totalThermalConductivity_[globalDofIdx] =
scalarValue(intQuants.totalThermalConductivity()); scalarValue(intQuants.totalThermalConductivity());
}
for (int phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx) { for (int phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx) {
if (FluidSystem::phaseIsActive(phaseIdx)) { if (FluidSystem::phaseIsActive(phaseIdx)) {
if (fluidInternalEnergiesOutput_()) if (params_.fluidInternalEnergiesOutput_) {
fluidInternalEnergies_[phaseIdx][globalDofIdx] = fluidInternalEnergies_[phaseIdx][globalDofIdx] =
scalarValue(intQuants.fluidState().internalEnergy(phaseIdx)); scalarValue(intQuants.fluidState().internalEnergy(phaseIdx));
}
if (fluidEnthalpiesOutput_()) if (params_.fluidEnthalpiesOutput_) {
fluidEnthalpies_[phaseIdx][globalDofIdx] = fluidEnthalpies_[phaseIdx][globalDofIdx] =
scalarValue(intQuants.fluidState().enthalpy(phaseIdx)); scalarValue(intQuants.fluidState().enthalpy(phaseIdx));
} }
} }
} }
} }
}
}
/*! /*!
* \brief Add all buffers to the VTK output writer. * \brief Add all buffers to the VTK output writer.
*/ */
void commitBuffers(BaseOutputWriter& baseWriter) void commitBuffers(BaseOutputWriter& baseWriter)
{ {
VtkMultiWriter *vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter); if constexpr (enableEnergy) {
if (!vtkWriter) VtkMultiWriter* vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
if (!vtkWriter) {
return; return;
}
if (!enableEnergy) if (params_.rockInternalEnergyOutput_) {
return;
if (rockInternalEnergyOutput_())
this->commitScalarBuffer_(baseWriter, "volumetric internal energy rock", rockInternalEnergy_); this->commitScalarBuffer_(baseWriter, "volumetric internal energy rock", rockInternalEnergy_);
}
if (totalThermalConductivityOutput_()) if (params_.totalThermalConductivityOutput_) {
this->commitScalarBuffer_(baseWriter, "total thermal conductivity", totalThermalConductivity_); this->commitScalarBuffer_(baseWriter, "total thermal conductivity", totalThermalConductivity_);
}
if (fluidInternalEnergiesOutput_()) if (params_.fluidInternalEnergiesOutput_) {
this->commitPhaseBuffer_(baseWriter, "internal energy_%s", fluidInternalEnergies_); this->commitPhaseBuffer_(baseWriter, "internal energy_%s", fluidInternalEnergies_);
}
if (fluidEnthalpiesOutput_()) if (params_.fluidEnthalpiesOutput_) {
this->commitPhaseBuffer_(baseWriter, "enthalpy_%s", fluidEnthalpies_); this->commitPhaseBuffer_(baseWriter, "enthalpy_%s", fluidEnthalpies_);
} }
}
}
private: private:
static bool rockInternalEnergyOutput_() VtkBlackoilEnergyParams params_{};
{
static bool val = Parameters::Get<Parameters::VtkWriteRockInternalEnergy>();
return val;
}
static bool totalThermalConductivityOutput_() ScalarBuffer rockInternalEnergy_{};
{ ScalarBuffer totalThermalConductivity_{};
static bool val = Parameters::Get<Parameters::VtkWriteTotalThermalConductivity>(); PhaseBuffer fluidInternalEnergies_{};
return val; PhaseBuffer fluidEnthalpies_{};
}
static bool fluidInternalEnergiesOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWriteFluidInternalEnergies>();
return val;
}
static bool fluidEnthalpiesOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWriteFluidEnthalpies>();
return val;
}
ScalarBuffer rockInternalEnergy_;
ScalarBuffer totalThermalConductivity_;
PhaseBuffer fluidInternalEnergies_;
PhaseBuffer fluidEnthalpies_;
}; };
} // namespace Opm } // namespace Opm

View File

@@ -0,0 +1,53 @@
// -*- 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/vtkblackoilenergyparams.hpp>
#include <opm/models/utils/parametersystem.hpp>
namespace Opm {
void VtkBlackoilEnergyParams::registerParameters()
{
Parameters::Register<Parameters::VtkWriteRockInternalEnergy>
("Include the volumetric internal energy of rock "
"in the VTK output files");
Parameters::Register<Parameters::VtkWriteTotalThermalConductivity>
("Include the total thermal conductivity of the medium and the fluids "
"in the VTK output files");
Parameters::Register<Parameters::VtkWriteFluidInternalEnergies>
("Include the internal energies of the fluids in the VTK output files");
Parameters::Register<Parameters::VtkWriteFluidEnthalpies>
("Include the enthalpies of the fluids in the VTK output files");
}
void VtkBlackoilEnergyParams::read()
{
rockInternalEnergyOutput_ = Parameters::Get<Parameters::VtkWriteRockInternalEnergy>();
totalThermalConductivityOutput_ = Parameters::Get<Parameters::VtkWriteTotalThermalConductivity>();
fluidInternalEnergiesOutput_ = Parameters::Get<Parameters::VtkWriteFluidInternalEnergies>();
fluidEnthalpiesOutput_ = Parameters::Get<Parameters::VtkWriteFluidEnthalpies>();
}
} // 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::VtkBlackOilEnergyModule
*/
#ifndef OPM_VTK_BLACK_OIL_ENERGY_PARAMS_HPP
#define OPM_VTK_BLACK_OIL_ENERGY_PARAMS_HPP
namespace Opm::Parameters {
// set default values for what quantities to output
struct VtkWriteRockInternalEnergy { static constexpr bool value = true; };
struct VtkWriteTotalThermalConductivity { static constexpr bool value = true; };
struct VtkWriteFluidInternalEnergies { static constexpr bool value = true; };
struct VtkWriteFluidEnthalpies { static constexpr bool value = true; };
} // namespace Opm::Parameters
namespace Opm {
/*!
* \brief Struct holding the parameters for VtkBlackoilEnergyOutputModule.
*/
struct VtkBlackoilEnergyParams
{
//! \brief Registers the parameters in parameter system.
static void registerParameters();
//! \brief Reads the parameter values from the parameter system.
void read();
bool rockInternalEnergyOutput_;
bool totalThermalConductivityOutput_;
bool fluidInternalEnergiesOutput_;
bool fluidEnthalpiesOutput_;
};
} // namespace Opm
#endif // OPM_VTK_BLACKOIL_ENERGY_PARAMS_HPP