vtktemperaturemodule: 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 e093101d1c
commit e0af58a7cf
4 changed files with 114 additions and 21 deletions

View File

@ -75,6 +75,7 @@ list (APPEND MAIN_SOURCE_FILES
opm/models/io/vtkphasepresenceparams.cpp
opm/models/io/vtkprimaryvarsparams.cpp
opm/models/io/vtkptflashparams.cpp
opm/models/io/vtktemperatureparams.cpp
opm/models/io/restart.cpp
opm/models/parallel/mpiutil.cpp
opm/models/parallel/tasklets.cpp
@ -691,6 +692,7 @@ list (APPEND PUBLIC_HEADER_FILES
opm/models/io/vtkptflashparams.hpp
opm/models/io/vtkscalarfunction.hh
opm/models/io/vtktemperaturemodule.hpp
opm/models/io/vtktemperatureparams.hpp
opm/models/io/vtktensorfunction.hh
opm/models/io/vtkvectorfunction.hh
opm/models/ncp/ncpboundaryratevector.hh

View File

@ -33,17 +33,11 @@
#include <opm/models/io/baseoutputmodule.hh>
#include <opm/models/io/vtkmultiwriter.hh>
#include <opm/models/io/vtktemperatureparams.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 VtkWriteTemperature { static constexpr bool value = true; };
} // namespace Opm::Parameters
namespace Opm {
/*!
@ -71,15 +65,16 @@ class VtkTemperatureModule : public BaseOutputModule<TypeTag>
public:
VtkTemperatureModule(const Simulator& simulator)
: ParentType(simulator)
{}
{
params_.read();
}
/*!
* \brief Register all run-time parameters for the Vtk output module.
*/
static void registerParameters()
{
Parameters::Register<Parameters::VtkWriteTemperature>
("Include the temperature in the VTK output files");
VtkTemperatureParams::registerParameters();
}
/*!
@ -88,7 +83,9 @@ public:
*/
void allocBuffers()
{
if (temperatureOutput_()) this->resizeScalarBuffer_(temperature_);
if (params_.temperatureOutput_) {
this->resizeScalarBuffer_(temperature_);
}
}
/*!
@ -108,8 +105,9 @@ public:
const auto& intQuants = elemCtx.intensiveQuantities(i, /*timeIdx=*/0);
const auto& fs = intQuants.fluidState();
if (temperatureOutput_())
if (params_.temperatureOutput_) {
temperature_[I] = Toolbox::value(fs.temperature(/*phaseIdx=*/0));
}
}
}
@ -118,23 +116,19 @@ public:
*/
void commitBuffers(BaseOutputWriter& baseWriter)
{
VtkMultiWriter *vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
VtkMultiWriter* vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
if (!vtkWriter) {
return;
}
if (temperatureOutput_())
if (params_.temperatureOutput_) {
this->commitScalarBuffer_(baseWriter, "temperature", temperature_);
}
}
private:
static bool temperatureOutput_()
{
static bool val = Parameters::Get<Parameters::VtkWriteTemperature>();
return val;
}
ScalarBuffer temperature_;
VtkTemperatureParams params_{};
ScalarBuffer temperature_{};
};
} // namespace Opm

View File

@ -0,0 +1,42 @@
// -*- 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/vtktemperatureparams.hpp>
#include <opm/models/utils/parametersystem.hpp>
namespace Opm {
void VtkTemperatureParams::registerParameters()
{
Parameters::Register<Parameters::VtkWriteTemperature>
("Include the temperature in the VTK output files");
}
void VtkTemperatureParams::read()
{
temperatureOutput_ = Parameters::Get<Parameters::VtkWriteTemperature>();
}
} // 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.
*/
/*!
* \file
* \copydoc Opm::VtkTemperatureModule
*/
#ifndef OPM_VTK_TEMPERATURE_PARAMS_HPP
#define OPM_VTK_TEMPERATURE_PARAMS_HPP
namespace Opm::Parameters {
// set default values for what quantities to output
struct VtkWriteTemperature { static constexpr bool value = true; };
} // namespace Opm::Parameters
namespace Opm {
/*!
* \brief Struct holding the parameters for VtkTemperatureModule.
*/
struct VtkTemperatureParams
{
//! \brief Registers the parameters in parameter system.
static void registerParameters();
//! \brief Reads the parameter values from the parameter system.
void read();
bool temperatureOutput_;
};
} // namespace Opm
#endif // OPM_VTK_TEMPERATURE_PARAMS_HPP