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:
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 void computeFaceAreaFraction(const std::vector<Scalar>& total_face_area) override
71 {
72 assert (total_face_area.size() >= static_cast<typename std::vector<Scalar>::size_type>(this->aquiferID()));
73
74 this->area_fraction_ = this->totalFaceArea()
75 / total_face_area[this->aquiferID() - 1];
76 }
77
78 Scalar totalFaceArea() const override
79 {
80 return this->total_face_area_;
81 }
82
83 void updateAquifer(const SingleAquiferFlux& aquifer)
84 {
85 aquifer_data_ = aquifer;
86 }
87
88 void initFromRestart(const data::Aquifers& aquiferSoln) override
89 {
90 auto xaqPos = aquiferSoln.find(this->aquiferID());
91 if (xaqPos == aquiferSoln.end()) {
92 return;
93 }
94
95 this->cumulative_flux_ = this->area_fraction_ * xaqPos->second.volume;
96 }
97
98 void initialSolutionApplied() override
99 {}
100
101 void beginTimeStep() override
102 {}
103
104 void endTimeStep() override
105 {
106 this->flux_rate_ = this->totalFluxRate();
107 this->cumulative_flux_ +=
108 this->flux_rate_ * this->simulator_.timeStepSize();
109 }
110
111 data::AquiferData aquiferData() const override
112 {
113 data::AquiferData data;
114
115 data.aquiferID = this->aquifer_data_.id;
116
117 // Pressure for constant flux aquifer is 0
118 data.pressure = 0.0;
119 data.fluxRate = this->totalFluxRate();
120
121 data.volume = this->cumulative_flux_;
122
123 // not totally sure whether initPressure matters
124 data.initPressure = 0.0;
125
126 return data;
127 }
128
130 const unsigned cellIdx,
131 [[maybe_unused]] const unsigned timeIdx) override
132 {
133 const int idx = this->cellToConnectionIdx_[cellIdx];
134 if (idx < 0) {
135 return;
136 }
137
138 const auto& model = this->simulator_.model();
139
140 const auto fw = this->aquifer_data_.flux;
141
142 this->connection_flux_[idx] = fw * this->connections_[idx].effective_facearea;
143
144 rates[BlackoilIndices::conti0EqIdx + compIdx_()]
145 += this->connection_flux_[idx] / model.dofTotalVolume(cellIdx);
146 }
147
148 template<class Serializer>
149 void serializeOp(Serializer& serializer)
150 {
151 serializer(cumulative_flux_);
152 }
153
154 bool operator==(const AquiferConstantFlux& rhs) const
155 {
156 return this->cumulative_flux_ == rhs.cumulative_flux_;
157 }
158
159private:
160 const std::vector<Aquancon::AquancCell>& connections_;
161
162 SingleAquiferFlux aquifer_data_;
163 std::vector<Eval> connection_flux_{};
164 std::vector<int> cellToConnectionIdx_{};
165 Scalar flux_rate_{};
166 Scalar cumulative_flux_{};
167 Scalar total_face_area_{0.0};
168 Scalar area_fraction_{1.0};
169
170 Scalar initializeConnections()
171 {
172 auto connected_face_area = 0.0;
173
174 this->cellToConnectionIdx_
175 .resize(this->simulator_.gridView().size(/*codim=*/0), -1);
176
177 for (std::size_t idx = 0; idx < this->connections_.size(); ++idx) {
178 const auto global_index = this->connections_[idx].global_index;
179 const int cell_index = this->simulator_.vanguard()
180 .compressedIndexForInterior(global_index);
181
182 if (cell_index < 0) {
183 continue;
184 }
185
186 this->cellToConnectionIdx_[cell_index] = idx;
187
188 connected_face_area += this->connections_[idx].effective_facearea;
189 }
190
191 // TODO: At the moment, we are using the effective_facearea from the
192 // parser. Should we update the facearea here if the grid changed
193 // during the preprocessing?
194
195 return connected_face_area;
196 }
197
198 Scalar computeFaceAreaFraction(const Scalar connected_face_area) const
199 {
200 const auto tot_face_area = this->simulator_.vanguard()
201 .grid().comm().sum(connected_face_area);
202
203 return (tot_face_area > 0.0)
204 ? connected_face_area / tot_face_area
205 : 0.0;
206 }
207
208 // TODO: this is a function from AquiferAnalytical
209 int compIdx_() const
210 {
211 if (this->co2store_or_h2store_())
212 return FluidSystem::oilCompIdx;
213
214 return FluidSystem::waterCompIdx;
215 }
216
217 Scalar totalFluxRate() const
218 {
219 return std::accumulate(this->connection_flux_.begin(),
220 this->connection_flux_.end(), 0.0,
221 [](const Scalar rate, const auto& q)
222 {
223 return rate + getValue(q);
224 });
225 }
226};
227
228} // namespace Opm
229
230#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:88
void endTimeStep() override
Definition: AquiferConstantFlux.hpp:104
void computeFaceAreaFraction(const std::vector< Scalar > &total_face_area) override
Definition: AquiferConstantFlux.hpp:70
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:78
data::AquiferData aquiferData() const override
Definition: AquiferConstantFlux.hpp:111
GetPropType< TypeTag, Properties::ElementMapper > ElementMapper
Definition: AquiferConstantFlux.hpp:43
void updateAquifer(const SingleAquiferFlux &aquifer)
Definition: AquiferConstantFlux.hpp:83
static constexpr int numEq
Definition: AquiferConstantFlux.hpp:48
bool operator==(const AquiferConstantFlux &rhs) const
Definition: AquiferConstantFlux.hpp:154
void addToSource(RateVector &rates, const unsigned cellIdx, const unsigned timeIdx) override
Definition: AquiferConstantFlux.hpp:129
void beginTimeStep() override
Definition: AquiferConstantFlux.hpp:101
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:98
void serializeOp(Serializer &serializer)
Definition: AquiferConstantFlux.hpp:149
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: blackoilboundaryratevector.hh:39
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