vtkptflashmodule: 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 29f2a35694
commit 4eb70830cf
4 changed files with 125 additions and 34 deletions

View File

@@ -74,6 +74,7 @@ list (APPEND MAIN_SOURCE_FILES
opm/models/io/vtkmultiphaseparams.cpp
opm/models/io/vtkphasepresenceparams.cpp
opm/models/io/vtkprimaryvarsparams.cpp
opm/models/io/vtkptflashparams.cpp
opm/models/io/restart.cpp
opm/models/parallel/mpiutil.cpp
opm/models/parallel/tasklets.cpp
@@ -687,6 +688,7 @@ list (APPEND PUBLIC_HEADER_FILES
opm/models/io/vtkprimaryvarsmodule.hpp
opm/models/io/vtkprimaryvarsparams.hpp
opm/models/io/vtkptflashmodule.hpp
opm/models/io/vtkptflashparams.hpp
opm/models/io/vtkscalarfunction.hh
opm/models/io/vtktemperaturemodule.hh
opm/models/io/vtktensorfunction.hh

View File

@@ -33,18 +33,11 @@
#include <opm/models/io/baseoutputmodule.hh>
#include <opm/models/io/vtkmultiwriter.hh>
#include <opm/models/io/vtkptflashparams.hpp>
#include <opm/models/utils/parametersystem.hpp>
#include <opm/models/utils/propertysystem.hh>
namespace Opm::Parameters {
// set default values for what quantities to output
struct VtkWriteLiquidMoleFractions { static constexpr bool value = false; };
struct VtkWriteEquilibriumConstants { static constexpr bool value = false; };
} // namespace Opm::Parameters
namespace Opm {
/*!
@@ -79,17 +72,16 @@ class VtkPTFlashModule: public BaseOutputModule<TypeTag>
public:
explicit VtkPTFlashModule(const Simulator& simulator)
: ParentType(simulator)
{ }
{
params_.read();
}
/*!
* \brief Register all run-time parameters for the Vtk output module.
*/
static void registerParameters()
{
Parameters::Register<Parameters::VtkWriteLiquidMoleFractions>
("Include liquid mole fractions (L) in the VTK output files");
Parameters::Register<Parameters::VtkWriteEquilibriumConstants>
("Include equilibrium constants (K) in the VTK output files");
VtkPtFlashParams::registerParameters();
}
/*!
@@ -98,10 +90,12 @@ public:
*/
void allocBuffers()
{
if (LOutput_())
if (params_.LOutput_) {
this->resizeScalarBuffer_(L_);
if (equilConstOutput_())
}
if (params_.equilConstOutput_) {
this->resizeComponentBuffer_(K_);
}
}
/*!
@@ -121,12 +115,14 @@ public:
const auto& intQuants = elemCtx.intensiveQuantities(i, /*timeIdx=*/0);
const auto& fs = intQuants.fluidState();
if (LOutput_())
if (params_.LOutput_) {
L_[I] = Toolbox::value(fs.L());
}
for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
if (equilConstOutput_())
if (params_.equilConstOutput_) {
K_[compIdx][I] = Toolbox::value(fs.K(compIdx));
}
}
}
}
@@ -136,32 +132,23 @@ public:
*/
void commitBuffers(BaseOutputWriter& baseWriter)
{
auto *vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
auto* vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
if (!vtkWriter) {
return;
}
if (equilConstOutput_())
if (params_.equilConstOutput_) {
this->commitComponentBuffer_(baseWriter, "K^%s", K_);
if (LOutput_())
}
if (params_.LOutput_) {
this->commitScalarBuffer_(baseWriter, "L", L_);
}
}
private:
static bool LOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWriteLiquidMoleFractions>();
return val;
}
static bool equilConstOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWriteEquilibriumConstants>();
return val;
}
ComponentBuffer K_;
ScalarBuffer L_;
VtkPtFlashParams params_{};
ComponentBuffer K_{};
ScalarBuffer L_{};
};
} // namespace Opm

View File

@@ -0,0 +1,45 @@
// -*- 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/vtkptflashparams.hpp>
#include <opm/models/utils/parametersystem.hpp>
namespace Opm {
void VtkPtFlashParams::registerParameters()
{
Parameters::Register<Parameters::VtkWriteLiquidMoleFractions>
("Include liquid mole fractions (L) in the VTK output files");
Parameters::Register<Parameters::VtkWriteEquilibriumConstants>
("Include equilibrium constants (K) in the VTK output files");
}
void VtkPtFlashParams::read()
{
LOutput_ = Parameters::Get<Parameters::VtkWriteLiquidMoleFractions>();
equilConstOutput_ = Parameters::Get<Parameters::VtkWriteEquilibriumConstants>();
}
} // namespace Opm

View File

@@ -0,0 +1,57 @@
// -*- 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::VtkPTFlashModule
*/
#ifndef OPM_VTK_PTFLASH_PARAMS_HPP
#define OPM_VTK_PTFLASH_PARAMS_HPP
namespace Opm::Parameters {
// set default values for what quantities to output
struct VtkWriteLiquidMoleFractions { static constexpr bool value = false; };
struct VtkWriteEquilibriumConstants { static constexpr bool value = false; };
} // namespace Opm::Parameters
namespace Opm {
/*!
* \brief Struct holding the parameters for VtkPtFlashModule.
*/
struct VtkPtFlashParams
{
//! \brief Registers the parameters in parameter system.
static void registerParameters();
//! \brief Reads the parameter values from the parameter system.
void read();
bool LOutput_;
bool equilConstOutput_;
};
} // namespace Opm
#endif // OPM_VTK_PTFLASH_MODULE_HPP