From 72d3395e510824e02c93c841b76522c489ff2267 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Mon, 16 Sep 2024 08:43:09 +0200 Subject: [PATCH] vtkblackoilsolventmodule: move parameters to dedicated struct with a translation unit --- CMakeLists_files.cmake | 2 + opm/models/io/vtkblackoilsolventmodule.hpp | 207 +++++++++------------ opm/models/io/vtkblackoilsolventparams.cpp | 59 ++++++ opm/models/io/vtkblackoilsolventparams.hpp | 63 +++++++ 4 files changed, 209 insertions(+), 122 deletions(-) create mode 100644 opm/models/io/vtkblackoilsolventparams.cpp create mode 100644 opm/models/io/vtkblackoilsolventparams.hpp diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 712d988f7..22b7a0bcb 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -66,6 +66,7 @@ list (APPEND MAIN_SOURCE_FILES opm/models/io/vtkblackoilmicpparams.cpp opm/models/io/vtkblackoilpolymerparams.cpp opm/models/io/vtkblackoilparams.cpp + opm/models/io/vtkblackoilsolventparams.cpp opm/models/io/restart.cpp opm/models/parallel/mpiutil.cpp opm/models/parallel/tasklets.cpp @@ -662,6 +663,7 @@ list (APPEND PUBLIC_HEADER_FILES opm/models/io/vtkblackoilpolymermodule.hpp opm/models/io/vtkblackoilpolymerparams.hpp opm/models/io/vtkblackoilsolventmodule.hpp + opm/models/io/vtkblackoilsolventparams.hpp opm/models/io/vtkcompositionmodule.hh opm/models/io/vtkdiffusionmodule.hh opm/models/io/vtkdiscretefracturemodule.hh diff --git a/opm/models/io/vtkblackoilsolventmodule.hpp b/opm/models/io/vtkblackoilsolventmodule.hpp index 084ecf8d5..0fdb69a7c 100644 --- a/opm/models/io/vtkblackoilsolventmodule.hpp +++ b/opm/models/io/vtkblackoilsolventmodule.hpp @@ -36,22 +36,12 @@ #include #include +#include #include #include #include -namespace Opm::Parameters { - -// set default values for what quantities to output -struct VtkWriteSolventSaturation { static constexpr bool value = true; }; -struct VtkWriteSolventRsw { static constexpr bool value = true; }; -struct VtkWriteSolventDensity { static constexpr bool value = true; }; -struct VtkWriteSolventViscosity { static constexpr bool value = true; }; -struct VtkWriteSolventMobility { static constexpr bool value = true; }; - -} // namespace Opm::Properties - namespace Opm { /*! @@ -80,7 +70,11 @@ class VtkBlackOilSolventModule : public BaseOutputModule public: VtkBlackOilSolventModule(const Simulator& simulator) : ParentType(simulator) - { } + { + if constexpr (enableSolvent) { + params_.read(); + } + } /*! * \brief Register all run-time parameters for the multi-phase VTK output @@ -88,24 +82,9 @@ public: */ static void registerParameters() { - if (!enableSolvent) - return; - - Parameters::Register - ("Include the \"saturation\" of the solvent component " - "in the VTK output files"); - Parameters::Register - ("Include the \"dissolved volume in water\" of the solvent component " - "in the VTK output files"); - Parameters::Register - ("Include the \"density\" of the solvent component " - "in the VTK output files"); - Parameters::Register - ("Include the \"viscosity\" of the solvent component " - "in the VTK output files"); - Parameters::Register - ("Include the \"mobility\" of the solvent component " - "in the VTK output files"); + if constexpr (enableSolvent) { + VtkBlackOilSolventParams::registerParameters(); + } } /*! @@ -114,23 +93,27 @@ public: */ void allocBuffers() { - if (!Parameters::Get()) { - return; + if constexpr (enableSolvent) { + if (!Parameters::Get()) { + return; + } + + if (params_.solventSaturationOutput_) { + this->resizeScalarBuffer_(solventSaturation_); + } + if (params_.solventRswOutput_) { + this->resizeScalarBuffer_(solventRsw_); + } + if (params_.solventDensityOutput_) { + this->resizeScalarBuffer_(solventDensity_); + } + if (params_.solventViscosityOutput_) { + this->resizeScalarBuffer_(solventViscosity_); + } + if (params_.solventMobilityOutput_) { + this->resizeScalarBuffer_(solventMobility_); + } } - - if (!enableSolvent) - return; - - if (solventSaturationOutput_()) - this->resizeScalarBuffer_(solventSaturation_); - if (solventRswOutput_()) - this->resizeScalarBuffer_(solventRsw_); - if (solventDensityOutput_()) - this->resizeScalarBuffer_(solventDensity_); - if (solventViscosityOutput_()) - this->resizeScalarBuffer_(solventViscosity_); - if (solventMobilityOutput_()) - this->resizeScalarBuffer_(solventMobility_); } /*! @@ -139,37 +122,41 @@ public: */ void processElement(const ElementContext& elemCtx) { - if (!Parameters::Get()) { - return; - } + if constexpr (enableSolvent) { + if (!Parameters::Get()) { + return; + } - if (!enableSolvent) - return; + using Toolbox = MathToolbox; + 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); - using Toolbox = MathToolbox; - 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_.solventSaturationOutput_) { + solventSaturation_[globalDofIdx] = + Toolbox::scalarValue(intQuants.solventSaturation()); + } - if (solventSaturationOutput_()) - solventSaturation_[globalDofIdx] = - Toolbox::scalarValue(intQuants.solventSaturation()); + if (params_.solventRswOutput_) { + solventRsw_[globalDofIdx] = + Toolbox::scalarValue(intQuants.rsSolw()); + } - if (solventRswOutput_()) - solventRsw_[globalDofIdx] = - Toolbox::scalarValue(intQuants.rsSolw()); + if (params_.solventDensityOutput_) { + solventDensity_[globalDofIdx] = + Toolbox::scalarValue(intQuants.solventDensity()); + } - if (solventDensityOutput_()) - solventDensity_[globalDofIdx] = - Toolbox::scalarValue(intQuants.solventDensity()); + if (params_.solventViscosityOutput_) { + solventViscosity_[globalDofIdx] = + Toolbox::scalarValue(intQuants.solventViscosity()); + } - if (solventViscosityOutput_()) - solventViscosity_[globalDofIdx] = - Toolbox::scalarValue(intQuants.solventViscosity()); - - if (solventMobilityOutput_()) - solventMobility_[globalDofIdx] = - Toolbox::scalarValue(intQuants.solventMobility()); + if (params_.solventMobilityOutput_) { + solventMobility_[globalDofIdx] = + Toolbox::scalarValue(intQuants.solventMobility()); + } + } } } @@ -178,65 +165,41 @@ public: */ void commitBuffers(BaseOutputWriter& baseWriter) { - VtkMultiWriter *vtkWriter = dynamic_cast(&baseWriter); - if (!vtkWriter) - return; + if constexpr (enableSolvent) { + VtkMultiWriter* vtkWriter = dynamic_cast(&baseWriter); + if (!vtkWriter) { + return; + } - if (!enableSolvent) - return; + if (params_.solventSaturationOutput_) { + this->commitScalarBuffer_(baseWriter, "saturation_solvent", solventSaturation_); + } - if (solventSaturationOutput_()) - this->commitScalarBuffer_(baseWriter, "saturation_solvent", solventSaturation_); + if (params_.solventRswOutput_) { + this->commitScalarBuffer_(baseWriter, "dissolved_solvent", solventRsw_); + } - if (solventRswOutput_()) - this->commitScalarBuffer_(baseWriter, "dissolved_solvent", solventRsw_); + if (params_.solventDensityOutput_) { + this->commitScalarBuffer_(baseWriter, "density_solvent", solventDensity_); + } - if (solventDensityOutput_()) - this->commitScalarBuffer_(baseWriter, "density_solvent", solventDensity_); + if (params_.solventViscosityOutput_) { + this->commitScalarBuffer_(baseWriter, "viscosity_solvent", solventViscosity_); + } - if (solventViscosityOutput_()) - this->commitScalarBuffer_(baseWriter, "viscosity_solvent", solventViscosity_); - - if (solventMobilityOutput_()) - this->commitScalarBuffer_(baseWriter, "mobility_solvent", solventMobility_); + if (params_.solventMobilityOutput_) { + this->commitScalarBuffer_(baseWriter, "mobility_solvent", solventMobility_); + } + } } private: - static bool solventSaturationOutput_() - { - static bool val = Parameters::Get(); - return val; - } - - static bool solventRswOutput_() - { - static bool val = Parameters::Get(); - return val; - } - - static bool solventDensityOutput_() - { - static bool val = Parameters::Get(); - return val; - } - - static bool solventViscosityOutput_() - { - static bool val = Parameters::Get(); - return val; - } - - static bool solventMobilityOutput_() - { - static bool val = Parameters::Get(); - return val; - } - - ScalarBuffer solventSaturation_; - ScalarBuffer solventRsw_; - ScalarBuffer solventDensity_; - ScalarBuffer solventViscosity_; - ScalarBuffer solventMobility_; + VtkBlackOilSolventParams params_{}; + ScalarBuffer solventSaturation_{}; + ScalarBuffer solventRsw_{}; + ScalarBuffer solventDensity_{}; + ScalarBuffer solventViscosity_{}; + ScalarBuffer solventMobility_{}; }; } // namespace Opm diff --git a/opm/models/io/vtkblackoilsolventparams.cpp b/opm/models/io/vtkblackoilsolventparams.cpp new file mode 100644 index 000000000..a3ef8cd82 --- /dev/null +++ b/opm/models/io/vtkblackoilsolventparams.cpp @@ -0,0 +1,59 @@ +// -*- 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 VtkBlackOilSolventParams::registerParameters() +{ + Parameters::Register + ("Include the \"saturation\" of the solvent component " + "in the VTK output files"); + Parameters::Register + ("Include the \"dissolved volume in water\" of the solvent component " + "in the VTK output files"); + Parameters::Register + ("Include the \"density\" of the solvent component " + "in the VTK output files"); + Parameters::Register + ("Include the \"viscosity\" of the solvent component " + "in the VTK output files"); + Parameters::Register + ("Include the \"mobility\" of the solvent component " + "in the VTK output files"); +} + +void VtkBlackOilSolventParams::read() +{ + solventSaturationOutput_ = Parameters::Get(); + solventRswOutput_ = Parameters::Get(); + solventDensityOutput_ = Parameters::Get(); + solventViscosityOutput_ = Parameters::Get(); + solventMobilityOutput_ = Parameters::Get(); +} + +} // namespace Opm diff --git a/opm/models/io/vtkblackoilsolventparams.hpp b/opm/models/io/vtkblackoilsolventparams.hpp new file mode 100644 index 000000000..7637e546c --- /dev/null +++ b/opm/models/io/vtkblackoilsolventparams.hpp @@ -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. +*/ +/*! + * \file + * \copydoc Opm::VtkBlackOilSolventModule + */ +#ifndef OPM_VTK_BLACK_OIL_SOLVENT_PARAMS_HPP +#define OPM_VTK_BLACK_OIL_SOLVENT_PARAMS_HPP + +namespace Opm::Parameters { + +// set default values for what quantities to output +struct VtkWriteSolventSaturation { static constexpr bool value = true; }; +struct VtkWriteSolventRsw { static constexpr bool value = true; }; +struct VtkWriteSolventDensity { static constexpr bool value = true; }; +struct VtkWriteSolventViscosity { static constexpr bool value = true; }; +struct VtkWriteSolventMobility { static constexpr bool value = true; }; + +} // namespace Opm::Parameters + +namespace Opm { + +/*! + * \brief Struct holding the parameters for VtkBlackoilPolymerModule. + */ +struct VtkBlackOilSolventParams +{ + //! \brief Registers the parameters in parameter system. + static void registerParameters(); + + //! \brief Reads the parameter values from the parameter system. + void read(); + + bool solventSaturationOutput_; + bool solventRswOutput_; + bool solventDensityOutput_; + bool solventViscosityOutput_; + bool solventMobilityOutput_; +}; + +} // namespace Opm + +#endif // OPM_VTK_BLACK_OIL_SOLVENT_PARAMS_HPP