From 3733e548bb4c38e0c76c5c40524356898969241d Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Mon, 16 Sep 2024 08:43:09 +0200 Subject: [PATCH] vtkblackoilpolymermodule: move parameters to dedicated struct with a translation unit --- CMakeLists_files.cmake | 2 + opm/models/io/vtkblackoilpolymermodule.hpp | 234 +++++++++------------ opm/models/io/vtkblackoilpolymerparams.cpp | 63 ++++++ opm/models/io/vtkblackoilpolymerparams.hpp | 65 ++++++ 4 files changed, 225 insertions(+), 139 deletions(-) create mode 100644 opm/models/io/vtkblackoilpolymerparams.cpp create mode 100644 opm/models/io/vtkblackoilpolymerparams.hpp diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 99ceda1d8..f76b65c75 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -64,6 +64,7 @@ list (APPEND MAIN_SOURCE_FILES opm/models/blackoil/blackoilsolventparams.cpp opm/models/io/vtkblackoilenergyparams.cpp opm/models/io/vtkblackoilmicpparams.cpp + opm/models/io/vtkblackoilpolymerparams.cpp opm/models/io/vtkblackoilparams.cpp opm/models/io/restart.cpp opm/models/parallel/mpiutil.cpp @@ -659,6 +660,7 @@ list (APPEND PUBLIC_HEADER_FILES opm/models/io/vtkblackoilmodule.hpp opm/models/io/vtkblackoilparams.hpp opm/models/io/vtkblackoilpolymermodule.hpp + opm/models/io/vtkblackoilpolymerparams.hpp opm/models/io/vtkblackoilsolventmodule.hh opm/models/io/vtkcompositionmodule.hh opm/models/io/vtkdiffusionmodule.hh diff --git a/opm/models/io/vtkblackoilpolymermodule.hpp b/opm/models/io/vtkblackoilpolymermodule.hpp index ab23d7f2a..ac6d9f43e 100644 --- a/opm/models/io/vtkblackoilpolymermodule.hpp +++ b/opm/models/io/vtkblackoilpolymermodule.hpp @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -48,18 +49,6 @@ struct VtkBlackOilPolymer {}; } // 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 { /*! @@ -88,7 +77,11 @@ class VtkBlackOilPolymerModule : public BaseOutputModule public: VtkBlackOilPolymerModule(const Simulator& simulator) : ParentType(simulator) - { } + { + if constexpr (enablePolymer) { + params_.read(); + } + } /*! * \brief Register all run-time parameters for the multi-phase VTK output @@ -96,27 +89,9 @@ public: */ static void registerParameters() { - if (!enablePolymer) - return; - - Parameters::Register - ("Include the concentration of the polymer component in the water phase " - "in the VTK output files"); - Parameters::Register - ("Include the fraction of the \"dead\" pore volume " - "in the VTK output files"); - Parameters::Register - ("Include the amount of already adsorbed polymer component" - "in the VTK output files"); - Parameters::Register - ("Include the adsorption rate of the polymer component" - "in the VTK output files"); - Parameters::Register - ("Include the viscosity correction of the polymer component " - "in the VTK output files"); - Parameters::Register - ("Include the viscosity correction of the water component " - "due to polymers in the VTK output files"); + if constexpr (enablePolymer) { + VtkBlackoilPolymerParams::registerParameters(); + } } /*! @@ -125,25 +100,30 @@ public: */ void allocBuffers() { - if (!Parameters::Get()) { - return; + if constexpr (enablePolymer) { + if (!Parameters::Get()) { + return; + } + + if (params_.polymerConcentrationOutput_) { + this->resizeScalarBuffer_(polymerConcentration_); + } + if (params_.polymerDeadPoreVolumeOutput_) { + this->resizeScalarBuffer_(polymerDeadPoreVolume_); + } + if (params_.polymerRockDensityOutput_) { + this->resizeScalarBuffer_(polymerRockDensity_); + } + if (params_.polymerAdsorptionOutput_) { + this->resizeScalarBuffer_(polymerAdsorption_); + } + if (params_.polymerViscosityCorrectionOutput_) { + this->resizeScalarBuffer_(polymerViscosityCorrection_); + } + if (params_.waterViscosityCorrectionOutput_) { + this->resizeScalarBuffer_(waterViscosityCorrection_); + } } - - if (!enablePolymer) - return; - - if (polymerConcentrationOutput_()) - this->resizeScalarBuffer_(polymerConcentration_); - if (polymerDeadPoreVolumeOutput_()) - this->resizeScalarBuffer_(polymerDeadPoreVolume_); - if (polymerRockDensityOutput_()) - this->resizeScalarBuffer_(polymerRockDensity_); - if (polymerAdsorptionOutput_()) - this->resizeScalarBuffer_(polymerAdsorption_); - if (polymerViscosityCorrectionOutput_()) - this->resizeScalarBuffer_(polymerViscosityCorrection_); - if (waterViscosityCorrectionOutput_()) - this->resizeScalarBuffer_(waterViscosityCorrection_); } /*! @@ -152,40 +132,45 @@ public: */ void processElement(const ElementContext& elemCtx) { - if (!Parameters::Get()) { - return; - } + if constexpr (enablePolymer) { + if (!Parameters::Get()) { + return; + } - if (!enablePolymer) - return; + for (unsigned dofIdx = 0; dofIdx < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++dofIdx) { + const auto& intQuants = elemCtx.intensiveQuantities(dofIdx, /*timeIdx=*/0); + unsigned globalDofIdx = elemCtx.globalSpaceIndex(dofIdx, /*timeIdx=*/0); - for (unsigned dofIdx = 0; dofIdx < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++dofIdx) { - const auto& intQuants = elemCtx.intensiveQuantities(dofIdx, /*timeIdx=*/0); - unsigned globalDofIdx = elemCtx.globalSpaceIndex(dofIdx, /*timeIdx=*/0); + if (params_.polymerConcentrationOutput_) { + polymerConcentration_[globalDofIdx] = + scalarValue(intQuants.polymerConcentration()); + } - if (polymerConcentrationOutput_()) - polymerConcentration_[globalDofIdx] = - scalarValue(intQuants.polymerConcentration()); + if (params_.polymerDeadPoreVolumeOutput_) { + polymerDeadPoreVolume_[globalDofIdx] = + scalarValue(intQuants.polymerDeadPoreVolume()); + } - if (polymerDeadPoreVolumeOutput_()) - polymerDeadPoreVolume_[globalDofIdx] = - scalarValue(intQuants.polymerDeadPoreVolume()); + if (params_.polymerRockDensityOutput_) { + polymerRockDensity_[globalDofIdx] = + scalarValue(intQuants.polymerRockDensity()); + } - if (polymerRockDensityOutput_()) - polymerRockDensity_[globalDofIdx] = - scalarValue(intQuants.polymerRockDensity()); + if (params_.polymerAdsorptionOutput_) { + polymerAdsorption_[globalDofIdx] = + scalarValue(intQuants.polymerAdsorption()); + } - if (polymerAdsorptionOutput_()) - polymerAdsorption_[globalDofIdx] = - scalarValue(intQuants.polymerAdsorption()); + if (params_.polymerViscosityCorrectionOutput_) { + polymerViscosityCorrection_[globalDofIdx] = + scalarValue(intQuants.polymerViscosityCorrection()); + } - if (polymerViscosityCorrectionOutput_()) - polymerViscosityCorrection_[globalDofIdx] = - scalarValue(intQuants.polymerViscosityCorrection()); - - if (waterViscosityCorrectionOutput_()) - waterViscosityCorrection_[globalDofIdx] = - scalarValue(intQuants.waterViscosityCorrection()); + if (params_.waterViscosityCorrectionOutput_) { + waterViscosityCorrection_[globalDofIdx] = + scalarValue(intQuants.waterViscosityCorrection()); + } + } } } @@ -194,75 +179,46 @@ public: */ void commitBuffers(BaseOutputWriter& baseWriter) { - VtkMultiWriter *vtkWriter = dynamic_cast(&baseWriter); - if (!vtkWriter) - return; + if constexpr (enablePolymer) { + VtkMultiWriter* vtkWriter = dynamic_cast(&baseWriter); + if (!vtkWriter) { + return; + } - if (!enablePolymer) - return; + if (params_.polymerConcentrationOutput_) { + this->commitScalarBuffer_(baseWriter, "polymer concentration", polymerConcentration_); + } - if (polymerConcentrationOutput_()) - this->commitScalarBuffer_(baseWriter, "polymer concentration", polymerConcentration_); + if (params_.polymerDeadPoreVolumeOutput_) { + this->commitScalarBuffer_(baseWriter, "dead pore volume fraction", polymerDeadPoreVolume_); + } - if (polymerDeadPoreVolumeOutput_()) - this->commitScalarBuffer_(baseWriter, "dead pore volume fraction", polymerDeadPoreVolume_); + if (params_.polymerRockDensityOutput_) { + this->commitScalarBuffer_(baseWriter, "polymer rock density", polymerRockDensity_); + } - if (polymerRockDensityOutput_()) - this->commitScalarBuffer_(baseWriter, "polymer rock density", polymerRockDensity_); + if (params_.polymerAdsorptionOutput_) { + this->commitScalarBuffer_(baseWriter, "polymer adsorption", polymerAdsorption_); + } - if (polymerAdsorptionOutput_()) - this->commitScalarBuffer_(baseWriter, "polymer adsorption", polymerAdsorption_); + if (params_.polymerViscosityCorrectionOutput_) { + this->commitScalarBuffer_(baseWriter, "polymer viscosity correction", polymerViscosityCorrection_); + } - if (polymerViscosityCorrectionOutput_()) - this->commitScalarBuffer_(baseWriter, "polymer viscosity correction", polymerViscosityCorrection_); - - if (waterViscosityCorrectionOutput_()) - this->commitScalarBuffer_(baseWriter, "water viscosity correction", waterViscosityCorrection_); + if (params_.waterViscosityCorrectionOutput_) { + this->commitScalarBuffer_(baseWriter, "water viscosity correction", waterViscosityCorrection_); + } + } } private: - static bool polymerConcentrationOutput_() - { - static bool val = Parameters::Get(); - return val; - } - - static bool polymerDeadPoreVolumeOutput_() - { - static bool val = Parameters::Get(); - return val; - } - - static bool polymerRockDensityOutput_() - { - static bool val = Parameters::Get(); - return val; - } - - static bool polymerAdsorptionOutput_() - { - static bool val = Parameters::Get(); - return val; - } - - static bool polymerViscosityCorrectionOutput_() - { - static bool val = Parameters::Get(); - return val; - } - - static bool waterViscosityCorrectionOutput_() - { - static bool val = Parameters::Get(); - return val; - } - - ScalarBuffer polymerConcentration_; - ScalarBuffer polymerDeadPoreVolume_; - ScalarBuffer polymerRockDensity_; - ScalarBuffer polymerAdsorption_; - ScalarBuffer polymerViscosityCorrection_; - ScalarBuffer waterViscosityCorrection_; + VtkBlackoilPolymerParams params_{}; + ScalarBuffer polymerConcentration_{}; + ScalarBuffer polymerDeadPoreVolume_{}; + ScalarBuffer polymerRockDensity_{}; + ScalarBuffer polymerAdsorption_{}; + ScalarBuffer polymerViscosityCorrection_{}; + ScalarBuffer waterViscosityCorrection_{}; }; } // namespace Opm diff --git a/opm/models/io/vtkblackoilpolymerparams.cpp b/opm/models/io/vtkblackoilpolymerparams.cpp new file mode 100644 index 000000000..f33830e97 --- /dev/null +++ b/opm/models/io/vtkblackoilpolymerparams.cpp @@ -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 . + + 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 +#include + +#include + +namespace Opm { + +void VtkBlackoilPolymerParams::registerParameters() +{ + Parameters::Register + ("Include the concentration of the polymer component in the water phase " + "in the VTK output files"); + Parameters::Register + ("Include the fraction of the \"dead\" pore volume " + "in the VTK output files"); + Parameters::Register + ("Include the amount of already adsorbed polymer component" + "in the VTK output files"); + Parameters::Register + ("Include the adsorption rate of the polymer component" + "in the VTK output files"); + Parameters::Register + ("Include the viscosity correction of the polymer component " + "in the VTK output files"); + Parameters::Register + ("Include the viscosity correction of the water component " + "due to polymers in the VTK output files"); +} + +void VtkBlackoilPolymerParams::read() +{ + polymerConcentrationOutput_ = Parameters::Get(); + polymerDeadPoreVolumeOutput_ = Parameters::Get(); + polymerRockDensityOutput_ = Parameters::Get(); + polymerAdsorptionOutput_ = Parameters::Get(); + polymerViscosityCorrectionOutput_ = Parameters::Get(); + waterViscosityCorrectionOutput_ = Parameters::Get(); +} + +} // namespace Opm diff --git a/opm/models/io/vtkblackoilpolymerparams.hpp b/opm/models/io/vtkblackoilpolymerparams.hpp new file mode 100644 index 000000000..df866b29a --- /dev/null +++ b/opm/models/io/vtkblackoilpolymerparams.hpp @@ -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 . + + 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