opm-simulators
GenericTracerModel.hpp
Go to the documentation of this file.
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=4 sw=4 sts=4:
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 2 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  Consult the COPYING file in the top-level source directory of this
20  module for the precise wording of the license and the list of
21  copyright holders.
22 */
28 #ifndef OPM_GENERIC_TRACER_MODEL_HPP
29 #define OPM_GENERIC_TRACER_MODEL_HPP
30 
31 #include <dune/istl/bcrsmatrix.hh>
32 
33 #include <opm/grid/common/CartesianIndexMapper.hpp>
34 
35 #include <opm/input/eclipse/EclipseState/Phase.hpp>
36 
38 
39 #include <opm/simulators/linalg/matrixblock.hh>
40 #include <opm/simulators/wells/WellTracerRate.hpp>
41 
42 #include <array>
43 #include <cstddef>
44 #include <functional>
45 #include <memory>
46 #include <string>
47 #include <unordered_map>
48 #include <vector>
49 
50 namespace Opm {
51 
52 class EclipseState;
53 class Well;
54 
55 template<class Grid, class GridView, class DofMapper, class Stencil, class FluidSystem, class Scalar>
57 public:
58  using TracerVectorSingle = Dune::BlockVector<Dune::FieldVector<Scalar, 1>>;
59  using TracerMatrix = Dune::BCRSMatrix<Opm::MatrixBlock<Scalar, 2, 2>>;
60  using TracerVector = Dune::BlockVector<Dune::FieldVector<Scalar, 2>>;
62  static constexpr int dimWorld = Grid::dimensionworld;
66  int numTracers() const;
67 
71  const std::string& name(int tracerIdx) const;
72  std::string fname(int tracerIdx) const;
73  std::string sname(int tracerIdx) const;
74  std::string wellfname(int tracerIdx) const;
75  std::string wellsname(int tracerIdx) const;
76 
77  Phase phase(int tracerIdx) const;
78  const std::vector<bool>& enableSolTracers() const;
79 
83  Scalar freeTracerConcentration(int tracerIdx, int globalDofIdx) const;
84  Scalar solTracerConcentration(int tracerIdx, int globalDofIdx) const;
85  void setFreeTracerConcentration(int tracerIdx, int globalDofIdx, Scalar value);
86  void setSolTracerConcentration(int tracerIdx, int globalDofIdx, Scalar value);
87  void setEnableSolTracers(int tracerIdx, bool enableSolTracer);
88 
92  const std::unordered_map<int, std::vector<WellTracerRate<Scalar>>>&
94  { return wellTracerRate_; }
95 
96  const std::unordered_map<int, std::vector<WellTracerRate<Scalar>>>&
97  getWellFreeTracerRates() const
98  { return wellFreeTracerRate_; }
99 
100  const std::unordered_map<int, std::vector<WellTracerRate<Scalar>>>&
101  getWellSolTracerRates() const
102  { return wellSolTracerRate_; }
103 
104  const std::unordered_map<int, std::vector<MSWellTracerRate<Scalar>>>&
105  getMswTracerRates() const {return mSwTracerRate_;}
106 
107  template<class Serializer>
108  void serializeOp(Serializer& serializer)
109  {
110  serializer(tracerConcentration_);
111  serializer(freeTracerConcentration_);
112  serializer(solTracerConcentration_);
113  serializer(wellTracerRate_);
114  serializer(wellFreeTracerRate_);
115  serializer(wellSolTracerRate_);
116  serializer(mSwTracerRate_);
117  }
118 
119 protected:
120  GenericTracerModel(const GridView& gridView,
121  const EclipseState& eclState,
122  const CartesianIndexMapper& cartMapper,
123  const DofMapper& dofMapper,
124  const std::function<std::array<double,dimWorld>(int)> centroids);
125 
129  void doInit(bool rst,
130  std::size_t numGridDof,
131  std::size_t gasPhaseIdx,
132  std::size_t oilPhaseIdx,
133  std::size_t waterPhaseIdx);
134 
135  bool linearSolve_(const TracerMatrix& M, TracerVector& x, TracerVector& b);
136 
137  bool linearSolveBatchwise_(const TracerMatrix& M,
138  std::vector<TracerVector>& x,
139  std::vector<TracerVector>& b);
140 
141  Scalar currentConcentration_(const Well& eclWell,
142  const std::string& trName,
143  const SummaryState& summaryState) const;
144 
147  Free = 0,
148  Solution = 1,
149  };
150 
151  const GridView& gridView_;
152  const EclipseState& eclState_;
153  const CartesianIndexMapper& cartMapper_;
154  const DofMapper& dofMapper_;
155 
156  std::vector<int> tracerPhaseIdx_;
157  std::vector<bool> enableSolTracers_;
158  std::vector<TracerVector> tracerConcentration_;
159  std::unique_ptr<TracerMatrix> tracerMatrix_;
160  std::vector<TracerVectorSingle> freeTracerConcentration_;
161  std::vector<TracerVectorSingle> solTracerConcentration_;
162 
163  // well_index -> tracer rates
164  std::unordered_map<int, std::vector<WellTracerRate<Scalar>>> wellTracerRate_;
165  std::unordered_map<int, std::vector<WellTracerRate<Scalar>>> wellFreeTracerRate_;
166  std::unordered_map<int, std::vector<WellTracerRate<Scalar>>> wellSolTracerRate_;
167 
168  std::unordered_map<int, std::vector<MSWellTracerRate<Scalar>>> mSwTracerRate_;
169 
171  std::function<std::array<double,dimWorld>(int)> centroids_;
172 };
173 
174 } // namespace Opm
175 
176 #endif // OPM_GENERIC_TRACER_MODEL_HPP
void doInit(bool rst, std::size_t numGridDof, std::size_t gasPhaseIdx, std::size_t oilPhaseIdx, std::size_t waterPhaseIdx)
Initialize all internal data structures needed by the tracer module.
Definition: GenericTracerModel_impl.hpp:227
Definition: GenericTracerModel.hpp:56
int numTracers() const
Return the number of tracers considered by the tracerModel.
Definition: GenericTracerModel_impl.hpp:162
Scalar freeTracerConcentration(int tracerIdx, int globalDofIdx) const
Return the tracer concentration for tracer index and global DofIdx.
Definition: GenericTracerModel_impl.hpp:117
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
A fully-implicit black-oil flow model.
std::function< std::array< double, dimWorld >int)> centroids_
Function returning the cell centers.
Definition: GenericTracerModel.hpp:171
const std::unordered_map< int, std::vector< WellTracerRate< Scalar > > > & getWellTracerRates() const
Return well tracer rates.
Definition: GenericTracerModel.hpp:93
const std::string & name(int tracerIdx) const
Return the tracer name.
Definition: GenericTracerModel_impl.hpp:220
Definition: CollectDataOnIORank.hpp:49