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
49 "Constant-flux aquifers need the black-oil components");
50
51 static constexpr int numEq = BlackoilIndices::numEq;
53 AquiferConstantFlux(const std::vector<Aquancon::AquancCell>& connections,
54 const Simulator& simulator,
55 const SingleAquiferFlux& aquifer)
56 : AquiferInterface<TypeTag>(aquifer.id, simulator)
57 , connections_ (connections)
58 , aquifer_data_ (aquifer)
59 , connection_flux_ (connections_.size(), Eval{0})
60 {
61 this->total_face_area_ = this->initializeConnections();
62 }
63
65 {
66 AquiferConstantFlux<TypeTag> result({}, simulator, {});
67 result.cumulative_flux_ = 1.0;
68
69 return result;
70 }
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 + this->activeCompIdx_]
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 // Active component index of the aquifer's phase, for offsetting conti0EqIdx.
165 const int activeCompIdx_{FluidSystem::canonicalToActiveCompIdx(
166 FluidSystem::solventComponentIndex(this->phaseIdx_()))};
167
168 SingleAquiferFlux aquifer_data_;
169 std::vector<Eval> connection_flux_{};
170 std::vector<int> cellToConnectionIdx_{};
171 Scalar flux_rate_{};
172 Scalar cumulative_flux_{};
173 Scalar total_face_area_{0.0};
174 Scalar area_fraction_{1.0};
175
176 Scalar initializeConnections()
177 {
178 auto connected_face_area = 0.0;
179
180 this->cellToConnectionIdx_
181 .resize(this->simulator_.gridView().size(/*codim=*/0), -1);
182
183 for (std::size_t idx = 0; idx < this->connections_.size(); ++idx) {
184 const auto global_index = this->connections_[idx].global_index;
185 const int cell_index = this->simulator_.vanguard()
186 .compressedIndexForInterior(global_index);
187
188 if (cell_index < 0) {
189 continue;
190 }
191
192 this->cellToConnectionIdx_[cell_index] = idx;
193
194 connected_face_area += this->connections_[idx].effective_facearea;
195 }
196
197 // TODO: At the moment, we are using the effective_facearea from the
198 // parser. Should we update the facearea here if the grid changed
199 // during the preprocessing?
200
201 return connected_face_area;
202 }
203
204 Scalar computeFaceAreaFraction(const Scalar connected_face_area) const
205 {
206 const auto tot_face_area = this->simulator_.vanguard()
207 .grid().comm().sum(connected_face_area);
208
209 return (tot_face_area > 0.0)
210 ? connected_face_area / tot_face_area
211 : 0.0;
212 }
213
214 Scalar totalFluxRate() const
215 {
216 return std::accumulate(this->connection_flux_.begin(),
217 this->connection_flux_.end(), 0.0,
218 [](const Scalar rate, const auto& q)
219 {
220 return rate + getValue(q);
221 });
222 }
223};
224
225} // namespace Opm
226
227#endif //OPM_AQUIFERCONSTANTFLUX_HPP
Definition: AquiferConstantFlux.hpp:39
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:53
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:51
bool operator==(const AquiferConstantFlux &rhs) const
Definition: AquiferConstantFlux.hpp:156
GetPropType< TypeTag, Properties::Evaluation > Eval
Definition: AquiferConstantFlux.hpp:52
void addToSource(RateVector &rates, const unsigned cellIdx, const unsigned timeIdx) override
Definition: AquiferConstantFlux.hpp:131
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:64
void initialSolutionApplied() override
Definition: AquiferConstantFlux.hpp:100
void serializeOp(Serializer &serializer)
Definition: AquiferConstantFlux.hpp:151
Definition: AquiferInterface.hpp:53
const Simulator & simulator_
Definition: AquiferInterface.hpp:138
int phaseIdx_() const
Definition: AquiferInterface.hpp:128
int aquiferID() const
Definition: AquiferInterface.hpp:112
Definition: AquiferInterface.hpp:42
Definition: blackoilbioeffectsmodules.hh:45
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