opm-simulators
NonlinearSystemCompositional.hpp
1 /*
2  Copyright 2026, SINTEF Digital
3 
4  This file is part of the Open Porous Media project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef OPM_NONLINEAR_SYSTEM_COMPOSITIONAL_HEADER_INCLUDED
21 #define OPM_NONLINEAR_SYSTEM_COMPOSITIONAL_HEADER_INCLUDED
22 
23 #include <dune/common/fvector.hh>
24 #include <dune/istl/bvector.hh>
25 
26 #include <opm/simulators/flow/BlackoilModelParameters.hpp>
27 #include <opm/simulators/flow/NonlinearSystem.hpp>
28 
29 #include <opm/simulators/timestepping/ConvergenceReport.hpp>
30 #include <opm/simulators/timestepping/SimulatorReport.hpp>
31 #include <opm/simulators/timestepping/SimulatorTimer.hpp>
32 
33 #include <flowexperimental/comp/wells/CompWellModel.hpp>
34 
35 #include <filesystem>
36 #include <vector>
37 
38 namespace Opm {
39 
40 template <class TypeTag>
42 {
43 public:
45  using Simulator = typename ParentType::Simulator;
46  using Grid = typename ParentType::Grid;
47  using FluidSystem = typename ParentType::FluidSystem;
48  using Indices = typename ParentType::Indices;
49  using Scalar = typename ParentType::Scalar;
53 
54  static constexpr int numEq = Indices::numEq;
55 
56  using VectorBlockType = Dune::FieldVector<Scalar, numEq>;
57  using BVector = Dune::BlockVector<VectorBlockType>;
58 
59  NonlinearSystemCompositional(Simulator& simulator,
60  const ModelParameters& param,
61  CompWellModel<TypeTag>& wellModel,
62  bool terminalOutput);
63 
64  SimulatorReportSingle prepareStep(const SimulatorTimerInterface& timer);
65 
66  void initialLinearization(SimulatorReportSingle& report,
67  int minIter,
68  int maxIter,
69  const SimulatorTimerInterface& timer) override;
70 
71  template <class NonlinearSolverType>
72  SimulatorReportSingle nonlinearIteration(const SimulatorTimerInterface& timer,
73  NonlinearSolverType& nonlinearSolver);
74 
75  template <class NonlinearSolverType>
76  SimulatorReportSingle nonlinearIterationNewton(const SimulatorTimerInterface& timer,
77  NonlinearSolverType& nonlinearSolver);
78 
79  Scalar relativeChange() const;
80 
81  int linearIterationsLastSolve() const
82  { return this->simulator_.model().newtonMethod().linearSolver().iterations(); }
83 
84  void solveJacobianSystem(BVector& x);
85 
86  bool hasNlddSolver() const
87  { return false; }
88 
89  const SimulatorReport& localAccumulatedReports() const
90  {
91  static const SimulatorReport emptyReport{};
92  return emptyReport;
93  }
94 
95  const std::vector<SimulatorReport>& domainAccumulatedReports() const
96  {
97  static const std::vector<SimulatorReport> emptyReports{};
98  return emptyReports;
99  }
100 
101  void writeNonlinearIterationsPerCell(const std::filesystem::path&) const {}
102 
103  template<class T>
104  std::vector<std::vector<Scalar>> computeFluidInPlace(const T&, const std::vector<int>& fipnum) const
105  { return computeFluidInPlace(fipnum); }
106 
107  std::vector<std::vector<Scalar>> computeFluidInPlace(const std::vector<int>&) const
108  { return {}; }
109 
110  void writePartitions(const std::filesystem::path&) const {}
111 
112 private:
113  std::vector<Scalar> reservoirResidualMetrics() const;
114 
115  double linear_solve_setup_time_ = 0.0;
116 };
117 
118 } // namespace Opm
119 
120 #include <opm/simulators/flow/NonlinearSystemCompositional_impl.hpp>
121 
122 #endif // OPM_NONLINEAR_SYSTEM_COMPOSITIONAL_HEADER_INCLUDED
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(...))
Definition: propertysystem.hh:233
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Solver parameters for the NonlinearSystemBlackOilReservoir.
Definition: BlackoilModelParameters.hpp:200
Definition: NonlinearSystemCompositional.hpp:41
A struct for returning timing data from a simulator to its caller.
Definition: SimulatorReport.hpp:33
Interface class for SimulatorTimer objects, to be improved.
Definition: SimulatorTimerInterface.hpp:33
Definition: SimulatorReport.hpp:121
Definition: CompWellModel.hpp:51
Definition: NonlinearSystem.hpp:43
Definition: ComponentName.hpp:33