From 2d000835a78f76aeb734c3d027cf7a085e5b3d8e Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Mon, 16 Sep 2024 08:43:09 +0200 Subject: [PATCH] vtkcompositionmodule: move parameters to dedicated struct with a translation unit --- CMakeLists_files.cmake | 2 + opm/models/io/vtkcompositionmodule.hpp | 153 +++++++++---------------- opm/models/io/vtkcompositionparams.cpp | 60 ++++++++++ opm/models/io/vtkcompositionparams.hpp | 67 +++++++++++ 4 files changed, 183 insertions(+), 99 deletions(-) create mode 100644 opm/models/io/vtkcompositionparams.cpp create mode 100644 opm/models/io/vtkcompositionparams.hpp diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index fb60511a6..43245d150 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -67,6 +67,7 @@ list (APPEND MAIN_SOURCE_FILES opm/models/io/vtkblackoilpolymerparams.cpp opm/models/io/vtkblackoilparams.cpp opm/models/io/vtkblackoilsolventparams.cpp + opm/models/io/vtkcompositionparams.cpp opm/models/io/restart.cpp opm/models/parallel/mpiutil.cpp opm/models/parallel/tasklets.cpp @@ -665,6 +666,7 @@ list (APPEND PUBLIC_HEADER_FILES opm/models/io/vtkblackoilsolventmodule.hpp opm/models/io/vtkblackoilsolventparams.hpp opm/models/io/vtkcompositionmodule.hpp + opm/models/io/vtkcompositionparams.hpp opm/models/io/vtkdiffusionmodule.hh opm/models/io/vtkdiscretefracturemodule.hh opm/models/io/vtkenergymodule.hh diff --git a/opm/models/io/vtkcompositionmodule.hpp b/opm/models/io/vtkcompositionmodule.hpp index 3487e6251..962bfdb7c 100644 --- a/opm/models/io/vtkcompositionmodule.hpp +++ b/opm/models/io/vtkcompositionmodule.hpp @@ -32,24 +32,12 @@ #include #include +#include #include #include #include -namespace Opm::Parameters { - -// set default values for what quantities to output -struct VtkWriteMassFractions { static constexpr bool value = false; }; -struct VtkWriteMoleFractions { static constexpr bool value = true; }; -struct VtkWriteTotalMassFractions { static constexpr bool value = false; }; -struct VtkWriteTotalMoleFractions { static constexpr bool value = false; }; -struct VtkWriteMolarities { static constexpr bool value = false; }; -struct VtkWriteFugacities { static constexpr bool value = false; }; -struct VtkWriteFugacityCoeffs { static constexpr bool value = false; }; - -} // namespace Opm::Properties - namespace Opm { /*! @@ -88,27 +76,16 @@ class VtkCompositionModule : public BaseOutputModule public: VtkCompositionModule(const Simulator& simulator) : ParentType(simulator) - { } + { + params_.read(); + } /*! * \brief Register all run-time parameters for the Vtk output module. */ static void registerParameters() { - Parameters::Register - ("Include mass fractions in the VTK output files"); - Parameters::Register - ("Include mole fractions in the VTK output files"); - Parameters::Register - ("Include total mass fractions in the VTK output files"); - Parameters::Register - ("Include total mole fractions in the VTK output files"); - Parameters::Register - ("Include component molarities in the VTK output files"); - Parameters::Register - ("Include component fugacities in the VTK output files"); - Parameters::Register - ("Include component fugacity coefficients in the VTK output files"); + VtkCompositionParams::registerParameters(); } /*! @@ -117,21 +94,28 @@ public: */ void allocBuffers() { - if (moleFracOutput_()) + if (params_.moleFracOutput_) { this->resizePhaseComponentBuffer_(moleFrac_); - if (massFracOutput_()) + } + if (params_.massFracOutput_) { this->resizePhaseComponentBuffer_(massFrac_); - if (totalMassFracOutput_()) + } + if (params_.totalMassFracOutput_) { this->resizeComponentBuffer_(totalMassFrac_); - if (totalMoleFracOutput_()) + } + if (params_.totalMoleFracOutput_) { this->resizeComponentBuffer_(totalMoleFrac_); - if (molarityOutput_()) + } + if (params_.molarityOutput_) { this->resizePhaseComponentBuffer_(molarity_); + } - if (fugacityOutput_()) + if (params_.fugacityOutput_) { this->resizeComponentBuffer_(fugacity_); - if (fugacityCoeffOutput_()) + } + if (params_.fugacityCoeffOutput_) { this->resizePhaseComponentBuffer_(fugacityCoeff_); + } } /*! @@ -153,21 +137,25 @@ public: for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) { for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) { - if (moleFracOutput_()) + if (params_.moleFracOutput_) { moleFrac_[phaseIdx][compIdx][I] = Toolbox::value(fs.moleFraction(phaseIdx, compIdx)); - if (massFracOutput_()) + } + if (params_.massFracOutput_) { massFrac_[phaseIdx][compIdx][I] = Toolbox::value(fs.massFraction(phaseIdx, compIdx)); - if (molarityOutput_()) + } + if (params_.molarityOutput_) { molarity_[phaseIdx][compIdx][I] = Toolbox::value(fs.molarity(phaseIdx, compIdx)); + } - if (fugacityCoeffOutput_()) + if (params_.fugacityCoeffOutput_) { fugacityCoeff_[phaseIdx][compIdx][I] = Toolbox::value(fs.fugacityCoefficient(phaseIdx, compIdx)); + } } } for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) { - if (totalMassFracOutput_()) { + if (params_.totalMassFracOutput_) { Scalar compMass = 0; Scalar totalMass = 0; for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) { @@ -179,7 +167,7 @@ public: } totalMassFrac_[compIdx][I] = compMass / totalMass; } - if (totalMoleFracOutput_()) { + if (params_.totalMoleFracOutput_) { Scalar compMoles = 0; Scalar totalMoles = 0; for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) { @@ -193,8 +181,9 @@ public: } totalMoleFrac_[compIdx][I] = compMoles / totalMoles; } - if (fugacityOutput_()) + if (params_.fugacityOutput_) { fugacity_[compIdx][I] = Toolbox::value(intQuants.fluidState().fugacity(/*phaseIdx=*/0, compIdx)); + } } } } @@ -204,79 +193,45 @@ public: */ void commitBuffers(BaseOutputWriter& baseWriter) { - VtkMultiWriter *vtkWriter = dynamic_cast(&baseWriter); + VtkMultiWriter* vtkWriter = dynamic_cast(&baseWriter); if (!vtkWriter) { return; } - if (moleFracOutput_()) + if (params_.moleFracOutput_) { this->commitPhaseComponentBuffer_(baseWriter, "moleFrac_%s^%s", moleFrac_); - if (massFracOutput_()) + } + if (params_.massFracOutput_) { this->commitPhaseComponentBuffer_(baseWriter, "massFrac_%s^%s", massFrac_); - if (molarityOutput_()) + } + if (params_.molarityOutput_) { this->commitPhaseComponentBuffer_(baseWriter, "molarity_%s^%s", molarity_); - if (totalMassFracOutput_()) + } + if (params_.totalMassFracOutput_) { this->commitComponentBuffer_(baseWriter, "totalMassFrac^%s", totalMassFrac_); - if (totalMoleFracOutput_()) + } + if (params_.totalMoleFracOutput_) { this->commitComponentBuffer_(baseWriter, "totalMoleFrac^%s", totalMoleFrac_); + } - if (fugacityOutput_()) + if (params_.fugacityOutput_) { this->commitComponentBuffer_(baseWriter, "fugacity^%s", fugacity_); - if (fugacityCoeffOutput_()) + } + if (params_.fugacityCoeffOutput_) { this->commitPhaseComponentBuffer_(baseWriter, "fugacityCoeff_%s^%s", fugacityCoeff_); + } } private: - static bool massFracOutput_() - { - static bool val = Parameters::Get(); - return val; - } + VtkCompositionParams params_{}; + PhaseComponentBuffer moleFrac_{}; + PhaseComponentBuffer massFrac_{}; + PhaseComponentBuffer molarity_{}; + ComponentBuffer totalMassFrac_{}; + ComponentBuffer totalMoleFrac_{}; - static bool moleFracOutput_() - { - static bool val = Parameters::Get(); - return val; - } - - static bool totalMassFracOutput_() - { - static bool val = Parameters::Get(); - return val; - } - - static bool totalMoleFracOutput_() - { - static bool val = Parameters::Get(); - return val; - } - - static bool molarityOutput_() - { - static bool val = Parameters::Get(); - return val; - } - - static bool fugacityOutput_() - { - static bool val = Parameters::Get(); - return val; - } - - static bool fugacityCoeffOutput_() - { - static bool val = Parameters::Get(); - return val; - } - - PhaseComponentBuffer moleFrac_; - PhaseComponentBuffer massFrac_; - PhaseComponentBuffer molarity_; - ComponentBuffer totalMassFrac_; - ComponentBuffer totalMoleFrac_; - - ComponentBuffer fugacity_; - PhaseComponentBuffer fugacityCoeff_; + ComponentBuffer fugacity_{}; + PhaseComponentBuffer fugacityCoeff_{}; }; } // namespace Opm diff --git a/opm/models/io/vtkcompositionparams.cpp b/opm/models/io/vtkcompositionparams.cpp new file mode 100644 index 000000000..0da6dc51f --- /dev/null +++ b/opm/models/io/vtkcompositionparams.cpp @@ -0,0 +1,60 @@ +// -*- 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 VtkCompositionParams::registerParameters() +{ + Parameters::Register + ("Include mass fractions in the VTK output files"); + Parameters::Register + ("Include mole fractions in the VTK output files"); + Parameters::Register + ("Include total mass fractions in the VTK output files"); + Parameters::Register + ("Include total mole fractions in the VTK output files"); + Parameters::Register + ("Include component molarities in the VTK output files"); + Parameters::Register + ("Include component fugacities in the VTK output files"); + Parameters::Register + ("Include component fugacity coefficients in the VTK output files"); +} + +void VtkCompositionParams::read() +{ + massFracOutput_ = Parameters::Get(); + moleFracOutput_ = Parameters::Get(); + totalMassFracOutput_ = Parameters::Get(); + totalMoleFracOutput_ = Parameters::Get(); + molarityOutput_ = Parameters::Get(); + fugacityOutput_ = Parameters::Get(); + fugacityCoeffOutput_ = Parameters::Get(); +} + +} // namespace Opm diff --git a/opm/models/io/vtkcompositionparams.hpp b/opm/models/io/vtkcompositionparams.hpp new file mode 100644 index 000000000..c16b23fdb --- /dev/null +++ b/opm/models/io/vtkcompositionparams.hpp @@ -0,0 +1,67 @@ +// -*- 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::VtkCompositionModule + */ +#ifndef OPM_VTK_COMPOSITION_PARAMS_HPP +#define OPM_VTK_COMPOSITION_PARAMS_HPP + +namespace Opm::Parameters { + +// set default values for what quantities to output +struct VtkWriteMassFractions { static constexpr bool value = false; }; +struct VtkWriteMoleFractions { static constexpr bool value = true; }; +struct VtkWriteTotalMassFractions { static constexpr bool value = false; }; +struct VtkWriteTotalMoleFractions { static constexpr bool value = false; }; +struct VtkWriteMolarities { static constexpr bool value = false; }; +struct VtkWriteFugacities { static constexpr bool value = false; }; +struct VtkWriteFugacityCoeffs { static constexpr bool value = false; }; + +} // namespace Opm::Properties + +namespace Opm { + +/*! + * \brief Struct holding the parameters for VtkCompositionModule. + */ +struct VtkCompositionParams +{ + //! \brief Registers the parameters in parameter system. + static void registerParameters(); + + //! \brief Reads the parameter values from the parameter system. + void read(); + + bool massFracOutput_; + bool moleFracOutput_; + bool totalMassFracOutput_; + bool totalMoleFracOutput_; + bool molarityOutput_; + bool fugacityOutput_; + bool fugacityCoeffOutput_; +}; + +} // namespace Opm + +#endif // OPM_VTK_COMPOSITION_PARAMS_HPP