vtkblackoilpolymermodule: 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 18ddfc8fb2
commit 3733e548bb
4 changed files with 225 additions and 139 deletions

View File

@@ -64,6 +64,7 @@ list (APPEND MAIN_SOURCE_FILES
opm/models/blackoil/blackoilsolventparams.cpp opm/models/blackoil/blackoilsolventparams.cpp
opm/models/io/vtkblackoilenergyparams.cpp opm/models/io/vtkblackoilenergyparams.cpp
opm/models/io/vtkblackoilmicpparams.cpp opm/models/io/vtkblackoilmicpparams.cpp
opm/models/io/vtkblackoilpolymerparams.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
@@ -659,6 +660,7 @@ list (APPEND PUBLIC_HEADER_FILES
opm/models/io/vtkblackoilmodule.hpp opm/models/io/vtkblackoilmodule.hpp
opm/models/io/vtkblackoilparams.hpp opm/models/io/vtkblackoilparams.hpp
opm/models/io/vtkblackoilpolymermodule.hpp opm/models/io/vtkblackoilpolymermodule.hpp
opm/models/io/vtkblackoilpolymerparams.hpp
opm/models/io/vtkblackoilsolventmodule.hh opm/models/io/vtkblackoilsolventmodule.hh
opm/models/io/vtkcompositionmodule.hh opm/models/io/vtkcompositionmodule.hh
opm/models/io/vtkdiffusionmodule.hh opm/models/io/vtkdiffusionmodule.hh

View File

@@ -36,6 +36,7 @@
#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/vtkblackoilpolymerparams.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>
@@ -48,18 +49,6 @@ struct VtkBlackOilPolymer {};
} // namespace Opm::Properties::TTag } // namespace Opm::Properties::TTag
namespace Opm::Parameters {
// set default values for what quantities to output
struct VtkWritePolymerConcentration { static constexpr bool value = true; };
struct VtkWritePolymerDeadPoreVolume { static constexpr bool value = true; };
struct VtkWritePolymerViscosityCorrection { static constexpr bool value = true; };
struct VtkWriteWaterViscosityCorrection { static constexpr bool value = true; };
struct VtkWritePolymerRockDensity { static constexpr bool value = true; };
struct VtkWritePolymerAdsorption { static constexpr bool value = true; };
} // namespace Opm::Parameters
namespace Opm { namespace Opm {
/*! /*!
@@ -88,7 +77,11 @@ class VtkBlackOilPolymerModule : public BaseOutputModule<TypeTag>
public: public:
VtkBlackOilPolymerModule(const Simulator& simulator) VtkBlackOilPolymerModule(const Simulator& simulator)
: ParentType(simulator) : ParentType(simulator)
{ } {
if constexpr (enablePolymer) {
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
@@ -96,27 +89,9 @@ public:
*/ */
static void registerParameters() static void registerParameters()
{ {
if (!enablePolymer) if constexpr (enablePolymer) {
return; VtkBlackoilPolymerParams::registerParameters();
}
Parameters::Register<Parameters::VtkWritePolymerConcentration>
("Include the concentration of the polymer component in the water phase "
"in the VTK output files");
Parameters::Register<Parameters::VtkWritePolymerDeadPoreVolume>
("Include the fraction of the \"dead\" pore volume "
"in the VTK output files");
Parameters::Register<Parameters::VtkWritePolymerRockDensity>
("Include the amount of already adsorbed polymer component"
"in the VTK output files");
Parameters::Register<Parameters::VtkWritePolymerAdsorption>
("Include the adsorption rate of the polymer component"
"in the VTK output files");
Parameters::Register<Parameters::VtkWritePolymerViscosityCorrection>
("Include the viscosity correction of the polymer component "
"in the VTK output files");
Parameters::Register<Parameters::VtkWriteWaterViscosityCorrection>
("Include the viscosity correction of the water component "
"due to polymers in the VTK output files");
} }
/*! /*!
@@ -125,26 +100,31 @@ public:
*/ */
void allocBuffers() void allocBuffers()
{ {
if constexpr (enablePolymer) {
if (!Parameters::Get<Parameters::EnableVtkOutput>()) { if (!Parameters::Get<Parameters::EnableVtkOutput>()) {
return; return;
} }
if (!enablePolymer) if (params_.polymerConcentrationOutput_) {
return;
if (polymerConcentrationOutput_())
this->resizeScalarBuffer_(polymerConcentration_); this->resizeScalarBuffer_(polymerConcentration_);
if (polymerDeadPoreVolumeOutput_()) }
if (params_.polymerDeadPoreVolumeOutput_) {
this->resizeScalarBuffer_(polymerDeadPoreVolume_); this->resizeScalarBuffer_(polymerDeadPoreVolume_);
if (polymerRockDensityOutput_()) }
if (params_.polymerRockDensityOutput_) {
this->resizeScalarBuffer_(polymerRockDensity_); this->resizeScalarBuffer_(polymerRockDensity_);
if (polymerAdsorptionOutput_()) }
if (params_.polymerAdsorptionOutput_) {
this->resizeScalarBuffer_(polymerAdsorption_); this->resizeScalarBuffer_(polymerAdsorption_);
if (polymerViscosityCorrectionOutput_()) }
if (params_.polymerViscosityCorrectionOutput_) {
this->resizeScalarBuffer_(polymerViscosityCorrection_); this->resizeScalarBuffer_(polymerViscosityCorrection_);
if (waterViscosityCorrectionOutput_()) }
if (params_.waterViscosityCorrectionOutput_) {
this->resizeScalarBuffer_(waterViscosityCorrection_); this->resizeScalarBuffer_(waterViscosityCorrection_);
} }
}
}
/*! /*!
* \brief Modify the internal buffers according to the intensive quantities relevant for * \brief Modify the internal buffers according to the intensive quantities relevant for
@@ -152,117 +132,93 @@ public:
*/ */
void processElement(const ElementContext& elemCtx) void processElement(const ElementContext& elemCtx)
{ {
if constexpr (enablePolymer) {
if (!Parameters::Get<Parameters::EnableVtkOutput>()) { if (!Parameters::Get<Parameters::EnableVtkOutput>()) {
return; return;
} }
if (!enablePolymer)
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 (polymerConcentrationOutput_()) if (params_.polymerConcentrationOutput_) {
polymerConcentration_[globalDofIdx] = polymerConcentration_[globalDofIdx] =
scalarValue(intQuants.polymerConcentration()); scalarValue(intQuants.polymerConcentration());
}
if (polymerDeadPoreVolumeOutput_()) if (params_.polymerDeadPoreVolumeOutput_) {
polymerDeadPoreVolume_[globalDofIdx] = polymerDeadPoreVolume_[globalDofIdx] =
scalarValue(intQuants.polymerDeadPoreVolume()); scalarValue(intQuants.polymerDeadPoreVolume());
}
if (polymerRockDensityOutput_()) if (params_.polymerRockDensityOutput_) {
polymerRockDensity_[globalDofIdx] = polymerRockDensity_[globalDofIdx] =
scalarValue(intQuants.polymerRockDensity()); scalarValue(intQuants.polymerRockDensity());
}
if (polymerAdsorptionOutput_()) if (params_.polymerAdsorptionOutput_) {
polymerAdsorption_[globalDofIdx] = polymerAdsorption_[globalDofIdx] =
scalarValue(intQuants.polymerAdsorption()); scalarValue(intQuants.polymerAdsorption());
}
if (polymerViscosityCorrectionOutput_()) if (params_.polymerViscosityCorrectionOutput_) {
polymerViscosityCorrection_[globalDofIdx] = polymerViscosityCorrection_[globalDofIdx] =
scalarValue(intQuants.polymerViscosityCorrection()); scalarValue(intQuants.polymerViscosityCorrection());
}
if (waterViscosityCorrectionOutput_()) if (params_.waterViscosityCorrectionOutput_) {
waterViscosityCorrection_[globalDofIdx] = waterViscosityCorrection_[globalDofIdx] =
scalarValue(intQuants.waterViscosityCorrection()); scalarValue(intQuants.waterViscosityCorrection());
} }
} }
}
}
/*! /*!
* \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)
{ {
if constexpr (enablePolymer) {
VtkMultiWriter* vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter); VtkMultiWriter* vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
if (!vtkWriter) if (!vtkWriter) {
return; return;
}
if (!enablePolymer) if (params_.polymerConcentrationOutput_) {
return;
if (polymerConcentrationOutput_())
this->commitScalarBuffer_(baseWriter, "polymer concentration", polymerConcentration_); this->commitScalarBuffer_(baseWriter, "polymer concentration", polymerConcentration_);
}
if (polymerDeadPoreVolumeOutput_()) if (params_.polymerDeadPoreVolumeOutput_) {
this->commitScalarBuffer_(baseWriter, "dead pore volume fraction", polymerDeadPoreVolume_); this->commitScalarBuffer_(baseWriter, "dead pore volume fraction", polymerDeadPoreVolume_);
}
if (polymerRockDensityOutput_()) if (params_.polymerRockDensityOutput_) {
this->commitScalarBuffer_(baseWriter, "polymer rock density", polymerRockDensity_); this->commitScalarBuffer_(baseWriter, "polymer rock density", polymerRockDensity_);
}
if (polymerAdsorptionOutput_()) if (params_.polymerAdsorptionOutput_) {
this->commitScalarBuffer_(baseWriter, "polymer adsorption", polymerAdsorption_); this->commitScalarBuffer_(baseWriter, "polymer adsorption", polymerAdsorption_);
}
if (polymerViscosityCorrectionOutput_()) if (params_.polymerViscosityCorrectionOutput_) {
this->commitScalarBuffer_(baseWriter, "polymer viscosity correction", polymerViscosityCorrection_); this->commitScalarBuffer_(baseWriter, "polymer viscosity correction", polymerViscosityCorrection_);
}
if (waterViscosityCorrectionOutput_()) if (params_.waterViscosityCorrectionOutput_) {
this->commitScalarBuffer_(baseWriter, "water viscosity correction", waterViscosityCorrection_); this->commitScalarBuffer_(baseWriter, "water viscosity correction", waterViscosityCorrection_);
} }
}
}
private: private:
static bool polymerConcentrationOutput_() VtkBlackoilPolymerParams params_{};
{ ScalarBuffer polymerConcentration_{};
static bool val = Parameters::Get<Parameters::VtkWritePolymerConcentration>(); ScalarBuffer polymerDeadPoreVolume_{};
return val; ScalarBuffer polymerRockDensity_{};
} ScalarBuffer polymerAdsorption_{};
ScalarBuffer polymerViscosityCorrection_{};
static bool polymerDeadPoreVolumeOutput_() ScalarBuffer waterViscosityCorrection_{};
{
static bool val = Parameters::Get<Parameters::VtkWritePolymerDeadPoreVolume>();
return val;
}
static bool polymerRockDensityOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWritePolymerRockDensity>();
return val;
}
static bool polymerAdsorptionOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWritePolymerAdsorption>();
return val;
}
static bool polymerViscosityCorrectionOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWritePolymerViscosityCorrection>();
return val;
}
static bool waterViscosityCorrectionOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWritePolymerViscosityCorrection>();
return val;
}
ScalarBuffer polymerConcentration_;
ScalarBuffer polymerDeadPoreVolume_;
ScalarBuffer polymerRockDensity_;
ScalarBuffer polymerAdsorption_;
ScalarBuffer polymerViscosityCorrection_;
ScalarBuffer waterViscosityCorrection_;
}; };
} // namespace Opm } // namespace Opm

View File

@@ -0,0 +1,63 @@
// -*- 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/vtkblackoilpolymerparams.hpp>
#include <opm/models/utils/parametersystem.hpp>
namespace Opm {
void VtkBlackoilPolymerParams::registerParameters()
{
Parameters::Register<Parameters::VtkWritePolymerConcentration>
("Include the concentration of the polymer component in the water phase "
"in the VTK output files");
Parameters::Register<Parameters::VtkWritePolymerDeadPoreVolume>
("Include the fraction of the \"dead\" pore volume "
"in the VTK output files");
Parameters::Register<Parameters::VtkWritePolymerRockDensity>
("Include the amount of already adsorbed polymer component"
"in the VTK output files");
Parameters::Register<Parameters::VtkWritePolymerAdsorption>
("Include the adsorption rate of the polymer component"
"in the VTK output files");
Parameters::Register<Parameters::VtkWritePolymerViscosityCorrection>
("Include the viscosity correction of the polymer component "
"in the VTK output files");
Parameters::Register<Parameters::VtkWriteWaterViscosityCorrection>
("Include the viscosity correction of the water component "
"due to polymers in the VTK output files");
}
void VtkBlackoilPolymerParams::read()
{
polymerConcentrationOutput_ = Parameters::Get<Parameters::VtkWritePolymerConcentration>();
polymerDeadPoreVolumeOutput_ = Parameters::Get<Parameters::VtkWritePolymerDeadPoreVolume>();
polymerRockDensityOutput_ = Parameters::Get<Parameters::VtkWritePolymerRockDensity>();
polymerAdsorptionOutput_ = Parameters::Get<Parameters::VtkWritePolymerAdsorption>();
polymerViscosityCorrectionOutput_ = Parameters::Get<Parameters::VtkWritePolymerViscosityCorrection>();
waterViscosityCorrectionOutput_ = Parameters::Get<Parameters::VtkWritePolymerViscosityCorrection>();
}
} // namespace Opm

View File

@@ -0,0 +1,65 @@
// -*- 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::VtkBlackOilPolymerModule
*/
#ifndef OPM_VTK_BLACK_OIL_POLYMER_PARAMS_HPP
#define OPM_VTK_BLACK_OIL_POLYMER_PARAMS_HPP
namespace Opm::Parameters {
// set default values for what quantities to output
struct VtkWritePolymerConcentration { static constexpr bool value = true; };
struct VtkWritePolymerDeadPoreVolume { static constexpr bool value = true; };
struct VtkWritePolymerViscosityCorrection { static constexpr bool value = true; };
struct VtkWriteWaterViscosityCorrection { static constexpr bool value = true; };
struct VtkWritePolymerRockDensity { static constexpr bool value = true; };
struct VtkWritePolymerAdsorption { static constexpr bool value = true; };
} // namespace Opm::Parameters
namespace Opm {
/*!
* \brief Struct holding the parameters for VtkBlackoilPolymerModule.
*/
struct VtkBlackoilPolymerParams
{
//! \brief Registers the parameters in parameter system.
static void registerParameters();
//! \brief Reads the parameter values from the parameter system.
void read();
bool polymerConcentrationOutput_;
bool polymerDeadPoreVolumeOutput_;
bool polymerRockDensityOutput_;
bool polymerAdsorptionOutput_;
bool polymerViscosityCorrectionOutput_;
bool waterViscosityCorrectionOutput_;
};
} // namespace Opm
#endif // OPM_VTK_BLACK_OIL_POLYMER_MODULE_HPP