AquiferConstantFlux.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2023 Equinor
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_AQUIFERCONSTANTFLUX_HPP
21#define OPM_AQUIFERCONSTANTFLUX_HPP
22
24
25#include <opm/input/eclipse/EclipseState/Aquifer/Aquancon.hpp>
26#include <opm/input/eclipse/EclipseState/Aquifer/AquiferFlux.hpp>
27
28#include <opm/material/common/MathToolbox.hpp>
29#include <opm/material/densead/Evaluation.hpp>
30
31#include <cassert>
32#include <numeric>
33#include <vector>
34
35namespace Opm {
36
37template<typename TypeTag>
39{
40public:
41 using RateVector = GetPropType<TypeTag, Properties::RateVector>;
42 using Simulator = GetPropType<TypeTag, Properties::Simulator>;
43 using ElementMapper = GetPropType<TypeTag, Properties::ElementMapper>;
44 using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
45 using BlackoilIndices = GetPropType<TypeTag, Properties::Indices>;
46 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
47
48 static constexpr int numEq = BlackoilIndices::numEq;
49 using Eval = DenseAd::Evaluation<Scalar, /*size=*/numEq>;
50
51 AquiferConstantFlux(const std::vector<Aquancon::AquancCell>& connections,
52 const Simulator& simulator,
53 const SingleAquiferFlux& aquifer)
54 : AquiferInterface<TypeTag>(aquifer.id, simulator)
55 , connections_ (connections)
56 , aquifer_data_ (aquifer)
57 , connection_flux_ (connections_.size(), Eval{0})
58 {
59 this->total_face_area_ = this->initializeConnections();
60 }
61
63 {
64 AquiferConstantFlux<TypeTag> result({}, simulator, {});
65 result.cumulative_flux_ = 1.0;
66
67 return result;
68 }
69
70 virtual ~AquiferConstantFlux() = default;
71
72 void computeFaceAreaFraction(const std::vector<Scalar>& total_face_area) override
73 {
74 assert (total_face_area.size() >= static_cast<typename std::vector<Scalar>::size_type>(this->aquiferID()));
75
76 this->area_fraction_ = this->totalFaceArea()
77 / total_face_area[this->aquiferID() - 1];
78 }
79
80 Scalar totalFaceArea() const override
81 {
82 return this->total_face_area_;
83 }
84
85 void updateAquifer(const SingleAquiferFlux& aquifer)
86 {
87 aquifer_data_ = aquifer;
88 }
89
90 void initFromRestart(const data::Aquifers& aquiferSoln) override
91 {
92 auto xaqPos = aquiferSoln.find(this->aquiferID());
93 if (xaqPos == aquiferSoln.end()) {
94 return;
95 }
96
97 this->cumulative_flux_ = this->area_fraction_ * xaqPos->second.volume;
98 }
99
101 {}
102
103 void beginTimeStep() override
104 {}
105
106 void endTimeStep() override
107 {
108 this->flux_rate_ = this->totalFluxRate();
109 this->cumulative_flux_ +=
110 this->flux_rate_ * this->simulator_.timeStepSize();
111 }
112
113 data::AquiferData aquiferData() const override
114 {
115 data::AquiferData data;
116
117 data.aquiferID = this->aquifer_data_.id;
118
119 // Pressure for constant flux aquifer is 0
120 data.pressure = 0.0;
121 data.fluxRate = this->totalFluxRate();
122
123 data.volume = this->cumulative_flux_;
124
125 // not totally sure whether initPressure matters
126 data.initPressure = 0.0;
127
128 return data;
129 }
130
132 const unsigned cellIdx,
133 [[maybe_unused]] const unsigned timeIdx) override
134 {
135 const int idx = this->cellToConnectionIdx_[cellIdx];
136 if (idx < 0) {
137 return;
138 }
139
140 const auto& model = this->simulator_.model();
141
142 const auto fw = this->aquifer_data_.flux;
143
144 this->connection_flux_[idx] = fw * this->connections_[idx].effective_facearea;
145
146 rates[BlackoilIndices::conti0EqIdx + compIdx_()]
147 += this->connection_flux_[idx] / model.dofTotalVolume(cellIdx);
148 }
149
150 template<class Serializer>
151 void serializeOp(Serializer& serializer)
152 {
153 serializer(cumulative_flux_);
154 }
155
156 bool operator==(const AquiferConstantFlux& rhs) const
157 {
158 return this->cumulative_flux_ == rhs.cumulative_flux_;
159 }
160
161private:
162 const std::vector<Aquancon::AquancCell>& connections_;
163
164 SingleAquiferFlux aquifer_data_;
165 std::vector<Eval> connection_flux_{};
166 std::vector<int> cellToConnectionIdx_{};
167 Scalar flux_rate_{};
168 Scalar cumulative_flux_{};
169 Scalar total_face_area_{0.0};
170 Scalar area_fraction_{1.0};
171
172 Scalar initializeConnections()
173 {
174 auto connected_face_area = 0.0;
175
176 this->cellToConnectionIdx_
177 .resize(this->simulator_.gridView().size(/*codim=*/0), -1);
178
179 for (std::size_t idx = 0; idx < this->connections_.size(); ++idx) {
180 const auto global_index = this->connections_[idx].global_index;
181 const int cell_index = this->simulator_.vanguard()
182 .compressedIndexForInterior(global_index);
183
184 if (cell_index < 0) {
185 continue;
186 }
187
188 this->cellToConnectionIdx_[cell_index] = idx;
189
190 connected_face_area += this->connections_[idx].effective_facearea;
191 }
192
193 // TODO: At the moment, we are using the effective_facearea from the
194 // parser. Should we update the facearea here if the grid changed
195 // during the preprocessing?
196
197 return connected_face_area;
198 }
199
200 Scalar computeFaceAreaFraction(const Scalar connected_face_area) const
201 {
202 const auto tot_face_area = this->simulator_.vanguard()
203 .grid().comm().sum(connected_face_area);
204
205 return (tot_face_area > 0.0)
206 ? connected_face_area / tot_face_area
207 : 0.0;
208 }
209
210 // TODO: this is a function from AquiferAnalytical
211 int compIdx_() const
212 {
213 if (this->co2store_or_h2store_())
214 return FluidSystem::oilCompIdx;
215
216 return FluidSystem::waterCompIdx;
217 }
218
219 Scalar totalFluxRate() const
220 {
221 return std::accumulate(this->connection_flux_.begin(),
222 this->connection_flux_.end(), 0.0,
223 [](const Scalar rate, const auto& q)
224 {
225 return rate + getValue(q);
226 });
227 }
228};
229
230} // namespace Opm
231
232#endif //OPM_AQUIFERCONSTANTFLUX_HPP
Definition: AquiferConstantFlux.hpp:39
DenseAd::Evaluation< Scalar, numEq > Eval
Definition: AquiferConstantFlux.hpp:49
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: AquiferConstantFlux.hpp:41
void initFromRestart(const data::Aquifers &aquiferSoln) override
Definition: AquiferConstantFlux.hpp:90
void endTimeStep() override
Definition: AquiferConstantFlux.hpp:106
void computeFaceAreaFraction(const std::vector< Scalar > &total_face_area) override
Definition: AquiferConstantFlux.hpp:72
AquiferConstantFlux(const std::vector< Aquancon::AquancCell > &connections, const Simulator &simulator, const SingleAquiferFlux &aquifer)
Definition: AquiferConstantFlux.hpp:51
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: AquiferConstantFlux.hpp:44
GetPropType< TypeTag, Properties::Indices > BlackoilIndices
Definition: AquiferConstantFlux.hpp:45
Scalar totalFaceArea() const override
Definition: AquiferConstantFlux.hpp:80
data::AquiferData aquiferData() const override
Definition: AquiferConstantFlux.hpp:113
GetPropType< TypeTag, Properties::ElementMapper > ElementMapper
Definition: AquiferConstantFlux.hpp:43
void updateAquifer(const SingleAquiferFlux &aquifer)
Definition: AquiferConstantFlux.hpp:85
static constexpr int numEq
Definition: AquiferConstantFlux.hpp:48
bool operator==(const AquiferConstantFlux &rhs) const
Definition: AquiferConstantFlux.hpp:156
void addToSource(RateVector &rates, const unsigned cellIdx, const unsigned timeIdx) override
Definition: AquiferConstantFlux.hpp:131
virtual ~AquiferConstantFlux()=default
void beginTimeStep() override
Definition: AquiferConstantFlux.hpp:103
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: AquiferConstantFlux.hpp:46
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: AquiferConstantFlux.hpp:42
static AquiferConstantFlux serializationTestObject(const Simulator &simulator)
Definition: AquiferConstantFlux.hpp:62
void initialSolutionApplied() override
Definition: AquiferConstantFlux.hpp:100
void serializeOp(Serializer &serializer)
Definition: AquiferConstantFlux.hpp:151
Definition: AquiferInterface.hpp:35
const Simulator & simulator_
Definition: AquiferInterface.hpp:98
bool co2store_or_h2store_() const
Definition: AquiferInterface.hpp:82
int aquiferID() const
Definition: AquiferInterface.hpp:79
Definition: BlackoilPhases.hpp:27