From 08d8fa91b605ede52c2b9d06a55d23c3f1c9d64f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Wed, 1 Oct 2025 14:13:21 +0200 Subject: [PATCH] Make blackoil_nohyst available in flow, not just standalone. --- CMakeLists.txt | 13 +----- flow/flow_blackoil_nohyst.cpp | 47 ++++++++++++++++----- flow/flow_blackoil_nohyst.hpp | 44 +++++++++++++++++++ flow/flow_blackoil_nohyst_main.cpp | 27 ++++++++++++ opm/simulators/flow/MainDispatchDynamic.cpp | 9 +++- 5 files changed, 116 insertions(+), 24 deletions(-) create mode 100644 flow/flow_blackoil_nohyst.hpp create mode 100644 flow/flow_blackoil_nohyst_main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index c091e1377f..866f552c25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -577,7 +577,8 @@ set(FLOW_MODELS blackoil brine energy extbo foam gasoil gaswater gasoil_energy brine_saltprecipitation gaswater_saltprec_vapwat gaswater_saltprec_energy brine_precsalt_vapwat blackoil_legacyassembly gasoildiffuse gaswater_dissolution - gaswater_dissolution_diffuse gaswater_energy gaswater_solvent biofilm) + gaswater_dissolution_diffuse gaswater_energy gaswater_solvent biofilm + blackoil_nohyst) set(FLOW_VARIANT_MODELS brine_energy onephase onephase_energy) set(FLOW_TGTS) @@ -641,16 +642,6 @@ opm_add_test(flow_blackoil_polyhedralgrid flow/flow_blackoil_polyhedralgrid.cpp $) -opm_add_test(flow_blackoil_nohyst - ONLY_COMPILE - ALWAYS_ENABLE - DEFAULT_ENABLE_IF ${FLOW_POLY_ONLY_DEFAULT_ENABLE_IF} - DEPENDS opmsimulators - LIBRARIES opmsimulators - SOURCES - flow/flow_blackoil_nohyst.cpp - $) - opm_add_test(flow_distribute_z ONLY_COMPILE ALWAYS_ENABLE diff --git a/flow/flow_blackoil_nohyst.cpp b/flow/flow_blackoil_nohyst.cpp index 48be5b672c..457cbaeaeb 100644 --- a/flow/flow_blackoil_nohyst.cpp +++ b/flow/flow_blackoil_nohyst.cpp @@ -1,4 +1,6 @@ /* + Copyright 2025 Equinor ASA. + This file is part of the Open Porous Media project (OPM). OPM is free software: you can redistribute it and/or modify @@ -30,38 +32,61 @@ namespace Opm { namespace Properties { namespace TTag { - struct FlowProblemNoHystNoEps { + struct FlowProblemNohyst { using InheritsFrom = std::tuple; }; } template - struct Linearizer { using type = TpfaLinearizer; }; + struct Linearizer { using type = TpfaLinearizer; }; template - struct LocalResidual { using type = BlackOilLocalResidualTPFA; }; + struct LocalResidual { using type = BlackOilLocalResidualTPFA; }; template - struct EnableDiffusion { static constexpr bool value = false; }; + struct EnableDiffusion { static constexpr bool value = false; }; template - struct EnableHysteresis { static constexpr bool value = false; }; + struct EnableHysteresis { static constexpr bool value = false; }; template - struct EnableEndpointScaling { static constexpr bool value = true; }; + struct EnableEndpointScaling { static constexpr bool value = true; }; template - struct AvoidElementContext { static constexpr bool value = true; }; + struct AvoidElementContext { static constexpr bool value = true; }; } -} // namespace Opm - -int main(int argc, char** argv) +std::unique_ptr> +flowBlackoilTpfaNohystMainInit(int argc, char** argv, bool outputCout, bool outputFiles) { - using TypeTag = Opm::Properties::TTag::FlowProblemNoHystNoEps; + // we always want to use the default locale, and thus spare us the trouble + // with incorrect locale settings. + resetLocale(); + + return std::make_unique>( + argc, argv, outputCout, outputFiles); +} + +// ----------------- Main program ----------------- +int flowBlackoilTpfaNohystMain(int argc, char** argv, bool outputCout, bool outputFiles) +{ + // we always want to use the default locale, and thus spare us the trouble + // with incorrect locale settings. + resetLocale(); + + FlowMain + mainfunc {argc, argv, outputCout, outputFiles}; + return mainfunc.execute(); +} + +int flowBlackoilTpfaNohystMainStandalone(int argc, char** argv) +{ + using TypeTag = Opm::Properties::TTag::FlowProblemNohyst; auto mainObject = std::make_unique(argc, argv); auto ret = mainObject->runStatic(); // Destruct mainObject as the destructor calls MPI_Finalize! mainObject.reset(); return ret; } + +} // namespace Opm diff --git a/flow/flow_blackoil_nohyst.hpp b/flow/flow_blackoil_nohyst.hpp new file mode 100644 index 0000000000..02b5d823e6 --- /dev/null +++ b/flow/flow_blackoil_nohyst.hpp @@ -0,0 +1,44 @@ +/* + Copyright 2025 Equinor ASA. + + 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 3 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 . +*/ +#ifndef FLOW_BLACKOIL_NOHYST_HPP +#define FLOW_BLACKOIL_NOHYST_HPP + +#include + +#include + +namespace Opm { + +namespace Properties { namespace TTag { struct FlowProblemNohyst; } } + +//! \brief Main function used in flow binary. +int flowBlackoilTpfaNohystMain(int argc, char** argv, bool outputCout, bool outputFiles); + +template class FlowMain; + +//! \brief Initialization function used in flow binary and python simulator. +std::unique_ptr> +flowBlackoilTpfaNohystMainInit(int argc, char** argv, bool outputCout, bool outputFiles); + +//! \brief Main function used in flow_brine binary. +int flowBlackoilTpfaNohystMainStandalone(int argc, char** argv); + +} + +#endif // FLOW_BLACKOIL_NOHYST_HPP diff --git a/flow/flow_blackoil_nohyst_main.cpp b/flow/flow_blackoil_nohyst_main.cpp new file mode 100644 index 0000000000..15f21fb705 --- /dev/null +++ b/flow/flow_blackoil_nohyst_main.cpp @@ -0,0 +1,27 @@ +/* + Copyright 2025 Equinor ASA. + + 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 3 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 . +*/ + +#include "config.h" + +#include + +int main(int argc, char** argv) +{ + return Opm::flowBlackoilTpfaNohystMainStandalone(argc, argv); +} diff --git a/opm/simulators/flow/MainDispatchDynamic.cpp b/opm/simulators/flow/MainDispatchDynamic.cpp index ece545659c..4318d1f509 100644 --- a/opm/simulators/flow/MainDispatchDynamic.cpp +++ b/opm/simulators/flow/MainDispatchDynamic.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -423,6 +424,10 @@ int Opm::Main::runBlackOil() // support the diffusion module yet. return flowBlackoilMain(argc_, argv_, outputCout_, outputFiles_); } - - return flowBlackoilTpfaMain(argc_, argv_, outputCout_, outputFiles_); + if (this->eclipseState_->runspec().hysterPar().active()) { + return flowBlackoilTpfaMain(argc_, argv_, outputCout_, outputFiles_); + } else { + // Use variant without hysteresis support to save memory. + return flowBlackoilTpfaNohystMain(argc_, argv_, outputCout_, outputFiles_); + } }