From a0ec0fca7266c0f0db7e5e4051bb645bda6c0bc2 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 14 Aug 2024 14:46:53 +0200 Subject: [PATCH] NonlinearSolver: move parameter registration to translation unit --- opm/simulators/flow/NonlinearSolver.cpp | 40 +++++++++++++++++-------- opm/simulators/flow/NonlinearSolver.hpp | 14 +++------ 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/opm/simulators/flow/NonlinearSolver.cpp b/opm/simulators/flow/NonlinearSolver.cpp index 721199167..0cc63d2ff 100644 --- a/opm/simulators/flow/NonlinearSolver.cpp +++ b/opm/simulators/flow/NonlinearSolver.cpp @@ -28,8 +28,7 @@ #include #include -namespace Opm { -namespace detail { +namespace Opm::detail { template void detectOscillations(const std::vector>& residualHistory, @@ -106,25 +105,40 @@ void stabilizeNonlinearUpdate(BVector& dx, BVector& dxOld, return; } +template +void registerNonlinearParameters() +{ + Parameters::Register> + ("The maximum relaxation factor of a Newton iteration"); + Parameters::Register + ("The maximum number of Newton iterations per time step"); + Parameters::Register + ("The minimum number of Newton iterations per time step"); + Parameters::Register + ("The type of relaxation used by Newton method"); + + Parameters::SetDefault(20); +} + template using BV = Dune::BlockVector>; -#define INSTANCE(T,Size) \ +#define INSTANTIATE(T,Size) \ template void stabilizeNonlinearUpdate,T>(BV&, BV&, \ const T, NonlinearRelaxType); -#define INSTANCE_TYPE(T) \ +#define INSTANTIATE_TYPE(T) \ template void detectOscillations(const std::vector>&, \ const int, const int, const T, const int, \ bool&, bool&); \ - INSTANCE(T,1) \ - INSTANCE(T,2) \ - INSTANCE(T,3) \ - INSTANCE(T,4) \ - INSTANCE(T,5) \ - INSTANCE(T,6) + template void registerNonlinearParameters(); \ + INSTANTIATE(T,1) \ + INSTANTIATE(T,2) \ + INSTANTIATE(T,3) \ + INSTANTIATE(T,4) \ + INSTANTIATE(T,5) \ + INSTANTIATE(T,6) -INSTANCE_TYPE(double) +INSTANTIATE_TYPE(double) -} // namespace detail -} // namespace Opm +} // namespace Opm::detail diff --git a/opm/simulators/flow/NonlinearSolver.hpp b/opm/simulators/flow/NonlinearSolver.hpp index 731a05ccb..b59441ac9 100644 --- a/opm/simulators/flow/NonlinearSolver.hpp +++ b/opm/simulators/flow/NonlinearSolver.hpp @@ -72,6 +72,9 @@ template void stabilizeNonlinearUpdate(BVector& dx, BVector& dxOld, const Scalar omega, NonlinearRelaxType relaxType); +template +void registerNonlinearParameters(); + } /// A nonlinear solver class suitable for general fully-implicit models, @@ -115,16 +118,7 @@ void stabilizeNonlinearUpdate(BVector& dx, BVector& dxOld, static void registerParameters() { - Parameters::Register> - ("The maximum relaxation factor of a Newton iteration"); - Parameters::Register - ("The maximum number of Newton iterations per time step"); - Parameters::Register - ("The minimum number of Newton iterations per time step"); - Parameters::Register - ("The type of relaxation used by Newton method"); - - Parameters::SetDefault(20); + detail::registerNonlinearParameters(); } void reset()