AquiferInterface.hpp
Go to the documentation of this file.
1/*
2 Copyright 2017 SINTEF Digital, Mathematics and Cybernetics.
3 Copyright 2017 Statoil ASA.
4 Copyright 2017 IRIS
5
6 This file is part of the Open Porous Media project (OPM).
7
8 OPM is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 OPM is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with OPM. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#ifndef OPM_AQUIFERINTERFACE_HEADER_INCLUDED
23#define OPM_AQUIFERINTERFACE_HEADER_INCLUDED
24
25#include <opm/common/ErrorMacros.hpp>
26
29
30#include <opm/output/data/Aquifer.hpp>
31
32#include <fmt/format.h>
33
34#include <stdexcept>
35
36namespace Opm
37{
38
39template <typename TypeTag>
41{
42public:
47
48 // Constructor
50 const Simulator& simulator)
51 : aquiferID_(aqID)
52 , simulator_(simulator)
53 , activeCompIdx_(resolveActiveCompIdx_())
54 {
55 }
56
57 // Destructor
58 virtual ~AquiferInterface() = default;
59
60 virtual void initFromRestart(const data::Aquifers& aquiferSoln) = 0;
61
62 virtual void initialSolutionApplied() = 0;
63
64 virtual void beginTimeStep() = 0;
65 virtual void endTimeStep() = 0;
66
67 virtual data::AquiferData aquiferData() const = 0;
68
69 virtual void computeFaceAreaFraction(const std::vector<Scalar>& total_face_area) = 0;
70 virtual Scalar totalFaceArea() const = 0;
71
72 template <class Context>
74 const Context& context,
75 const unsigned spaceIdx,
76 const unsigned timeIdx)
77 {
78 const unsigned cellIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
79 addToSource(rates, cellIdx, timeIdx);
80 }
81
82 virtual void addToSource(RateVector& rates,
83 const unsigned cellIdx,
84 const unsigned timeIdx) = 0;
85
88 virtual Scalar cachedConnectionInfluxRate([[maybe_unused]] unsigned cellIdx) const
89 {
90 return Scalar{0};
91 }
92
93 int aquiferID() const { return this->aquiferID_; }
94
95protected:
97 {
98 const auto& rspec = simulator_.vanguard().eclState().runspec();
99 return rspec.co2Storage() || rspec.h2Storage();
100 }
101
102 // Brine properties come from the internal brine model rather than PVTW/DENSITY
104 {
105 const auto& rspec = simulator_.vanguard().eclState().runspec();
106 return rspec.co2Storage() || rspec.h2Storage() || rspec.co2Sol() || rspec.h2Sol();
107 }
108
109 int phaseIdx_() const
110 {
111 // If OIL is used to model brine the aquifer should do the same
112 if (co2store_or_h2store_() && FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx))
113 return FluidSystem::oilPhaseIdx;
114
115 return FluidSystem::waterPhaseIdx;
116 }
117
118 const int aquiferID_{};
120
121 // Active component index of the aquifer's phase, for offsetting conti0EqIdx.
122 const int activeCompIdx_{};
123
124private:
125 int resolveActiveCompIdx_() const
126 {
127 const auto phaseIdx = this->phaseIdx_();
128
129 if (! FluidSystem::phaseIsActive(phaseIdx)) {
130 OPM_THROW(std::logic_error,
131 fmt::format("Aquifer {} needs an active {} phase",
132 this->aquiferID_,
133 FluidSystem::phaseName(phaseIdx)));
134 }
135
136 return FluidSystem::canonicalToActiveCompIdx(
137 FluidSystem::solventComponentIndex(phaseIdx));
138 }
139};
140
141} // namespace Opm
142
143#endif
Definition: AquiferInterface.hpp:41
const int aquiferID_
Definition: AquiferInterface.hpp:118
const Simulator & simulator_
Definition: AquiferInterface.hpp:119
virtual void beginTimeStep()=0
virtual void computeFaceAreaFraction(const std::vector< Scalar > &total_face_area)=0
virtual void initialSolutionApplied()=0
virtual void initFromRestart(const data::Aquifers &aquiferSoln)=0
AquiferInterface(int aqID, const Simulator &simulator)
Definition: AquiferInterface.hpp:49
const int activeCompIdx_
Definition: AquiferInterface.hpp:122
virtual Scalar totalFaceArea() const =0
virtual data::AquiferData aquiferData() const =0
void addToSource(RateVector &rates, const Context &context, const unsigned spaceIdx, const unsigned timeIdx)
Definition: AquiferInterface.hpp:73
virtual ~AquiferInterface()=default
int phaseIdx_() const
Definition: AquiferInterface.hpp:109
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: AquiferInterface.hpp:46
bool internal_brine_model_() const
Definition: AquiferInterface.hpp:103
virtual void endTimeStep()=0
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: AquiferInterface.hpp:45
virtual Scalar cachedConnectionInfluxRate(unsigned cellIdx) const
Definition: AquiferInterface.hpp:88
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: AquiferInterface.hpp:43
bool co2store_or_h2store_() const
Definition: AquiferInterface.hpp:96
virtual void addToSource(RateVector &rates, const unsigned cellIdx, const unsigned timeIdx)=0
int aquiferID() const
Definition: AquiferInterface.hpp:93
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: AquiferInterface.hpp:44
Declare the properties used by the infrastructure code of the finite volume discretizations.
Defines the common properties required by the porous medium multi-phase models.
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