My Project
Loading...
Searching...
No Matches
CpGridVanguard.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*/
27#ifndef OPM_CPGRID_VANGUARD_HPP
28#define OPM_CPGRID_VANGUARD_HPP
29
30#include <opm/common/TimingMacros.hpp>
31
34
39
40#include <array>
41#include <functional>
42#include <memory>
43#include <stdexcept>
44#include <tuple>
45#include <vector>
46
47namespace Opm {
48template <class TypeTag>
49class CpGridVanguard;
50}
51
52namespace Opm::Properties {
53
54namespace TTag {
56 using InheritsFrom = std::tuple<FlowBaseVanguard>;
57};
58}
59
60// declare the properties
61template<class TypeTag>
62struct Vanguard<TypeTag, TTag::CpGridVanguard> {
64};
65template<class TypeTag>
66struct Grid<TypeTag, TTag::CpGridVanguard> {
67 using type = Dune::CpGrid;
68};
69template<class TypeTag>
70struct EquilGrid<TypeTag, TTag::CpGridVanguard> {
72};
73
74} // namespace Opm::Properties
75
76namespace Opm {
77
85template <class TypeTag>
86class CpGridVanguard : public FlowBaseVanguard<TypeTag>
87 , public GenericCpGridVanguard<GetPropType<TypeTag, Properties::ElementMapper>,
88 GetPropType<TypeTag, Properties::GridView>,
89 GetPropType<TypeTag, Properties::Scalar>>
90{
91 friend class FlowBaseVanguard<TypeTag>;
93
97
98public:
104 static constexpr int dimensionworld = Grid::dimensionworld;
106 static constexpr bool waterEnabled = Indices::waterEnabled;
107 static constexpr bool gasEnabled = Indices::gasEnabled;
108 static constexpr bool oilEnabled = Indices::oilEnabled;
109private:
110 using Element = typename GridView::template Codim<0>::Entity;
111
112public:
113 CpGridVanguard(Simulator& simulator)
114 : FlowBaseVanguard<TypeTag>(simulator)
115 {
116 this->checkConsistency();
117 this->callImplementationInit();
118 }
119
124 {
125 const auto& runspec = this->eclState().runspec();
126 const auto& config = this->eclState().getSimulationConfig();
127 const auto& phases = runspec.phases();
128
129 // check for correct module setup
130 if (config.isThermal()) {
132 throw std::runtime_error("Input specifies energy while simulator has disabled it, try xxx_energy");
133 }
134 } else {
136 throw std::runtime_error("Input specifies no energy while simulator has energy, try run without _energy");
137 }
138 }
139
140 if (config.isDiffusive()) {
142 throw std::runtime_error("Input specifies diffusion while simulator has disabled it, try xxx_diffusion");
143 }
144 }
145
146 if (runspec.micp()) {
148 throw std::runtime_error("Input specifies MICP while simulator has it disabled");
149 }
150 }
151
152 if (phases.active(Phase::BRINE)) {
154 throw std::runtime_error("Input specifies Brine while simulator has it disabled");
155 }
156 }
157
158 if (phases.active(Phase::POLYMER)) {
160 throw std::runtime_error("Input specifies Polymer while simulator has it disabled");
161 }
162 }
163
164 // checking for correct phases is more difficult TODO!
165 if (phases.active(Phase::ZFRACTION)) {
167 throw std::runtime_error("Input specifies ExBo while simulator has it disabled");
168 }
169 }
170 if (phases.active(Phase::FOAM)) {
172 throw std::runtime_error("Input specifies Foam while simulator has it disabled");
173 }
174 }
175
176 if (phases.active(Phase::SOLVENT)) {
178 throw std::runtime_error("Input specifies Solvent while simulator has it disabled");
179 }
180 }
181 if(phases.active(Phase::WATER)){
182 if(waterEnabled == false){
183 throw std::runtime_error("Input specifies water while simulator has it disabled");
184 }
185 }
186 if(phases.active(Phase::GAS)){
187 if(gasEnabled == false){
188 throw std::runtime_error("Input specifies gas while simulator has it disabled");
189 }
190 }
191 if(phases.active(Phase::OIL)){
192 if(oilEnabled == false){
193 throw std::runtime_error("Input specifies oil while simulator has it disabled");
194 }
195 }
196
197 }
198
205 {
206 globalTrans_.reset();
207 }
208
209 const TransmissibilityType& globalTransmissibility() const
210 {
211 assert( globalTrans_ != nullptr );
212 return *globalTrans_;
213 }
214
221 {
222#if HAVE_MPI
223 if (const auto& extPFile = this->externalPartitionFile();
224 !extPFile.empty() && (extPFile != "none"))
225 {
226 this->setExternalLoadBalancer(details::MPIPartitionFromFile { extPFile });
227 }
228
229 this->doLoadBalance_(this->edgeWeightsMethod(), this->ownersFirst(),
230 this->partitionMethod(), this->serialPartitioning(),
231 this->enableDistributedWells(), this->imbalanceTol(),
232 this->gridView(), this->schedule(),
233 this->eclState(), this->parallelWells_,
234 this->numJacobiBlocks());
235#endif
236
237 this->updateGridView_();
238 this->updateCartesianToCompressedMapping_();
239 this->updateCellDepths_();
240 this->updateCellThickness_();
241
242#if HAVE_MPI
243 this->distributeFieldProps_(this->eclState());
244#endif
245 }
246
247 unsigned int gridEquilIdxToGridIdx(unsigned int elemIndex) const {
248 return elemIndex;
249 }
250
251 unsigned int gridIdxToEquilGridIdx(unsigned int elemIndex) const {
252 return elemIndex;
253 }
261 std::function<std::array<double,dimensionworld>(int)>
263 {
264 return this->cellCentroids_(this->cartesianIndexMapper(), true);
265 }
266
267 const std::vector<int>& globalCell()
268 {
269 return this->grid().globalCell();
270 }
271
272protected:
273 void createGrids_()
274 {
275 this->doCreateGrids_(this->eclState());
276 }
277
278 void allocTrans() override
279 {
281 globalTrans_.reset(new TransmissibilityType(this->eclState(),
282 this->gridView(),
283 this->cartesianIndexMapper(),
284 this->grid(),
285 this->cellCentroids(),
289 globalTrans_->update(false, TransmissibilityType::TransUpdateQuantities::Trans);
290 }
291
292 double getTransmissibility(unsigned I, unsigned J) const override
293 {
294 return globalTrans_->transmissibility(I,J);
295 }
296
297#if HAVE_MPI
298 const std::string& zoltanParams() const override
299 {
300 return this->zoltanParams_;
301 }
302 const std::string& metisParams() const override
303 {
304 return this->metisParams_;
305 }
306#endif
307
308 // removing some connection located in inactive grid cells
309 void filterConnections_()
310 {
311 this->doFilterConnections_(this->schedule());
312 }
313
314 // \Note: this globalTrans_ is used for domain decomposition and INIT file output.
315 // It only contains trans_ due to permeability and does not contain thermalHalfTrans_,
316 // diffusivity_ abd dispersivity_. The main reason is to reduce the memory usage for rank 0
317 // during parallel running.
318 std::unique_ptr<TransmissibilityType> globalTrans_;
319};
320
321} // namespace Opm
322
323#endif // OPM_CPGRID_VANGUARD_HPP
This file ensures that flow can be compiled in the presence of dune-fem.
Helper class for grid instantiation of ECL file-format using problems.
Helper class for grid instantiation of ECL file-format using problems.
Declares the properties required by the black oil model.
Definition CollectDataOnIORank.hpp:51
const GridView & gridView() const
Returns a reference to the grid view to be used.
Definition basevanguard.hh:69
Helper class for grid instantiation of ECL file-format using problems.
Definition CpGridVanguard.hpp:90
void releaseGlobalTransmissibilities()
Free the memory occupied by the global transmissibility object.
Definition CpGridVanguard.hpp:204
void checkConsistency()
Checking consistency of simulator.
Definition CpGridVanguard.hpp:123
std::function< std::array< double, dimensionworld >(int)> cellCentroids() const
Get function to query cell centroids for a distributed grid.
Definition CpGridVanguard.hpp:262
void loadBalance()
Distribute the simulation grid over multiple processes.
Definition CpGridVanguard.hpp:220
Helper class for grid instantiation of ECL file-format using problems.
Definition FlowBaseVanguard.hpp:83
std::function< std::array< double, dimensionworld >(int)> cellCentroids_(const CartMapper &cartMapper, const bool &isCpGrid) const
Get function to query cell centroids for a distributed grid.
Definition FlowBaseVanguard.hpp:318
int numJacobiBlocks() const
Number of blocks in the Block-Jacobi preconditioner.
Definition FlowGenericVanguard.hpp:239
const Schedule & schedule() const
Return a reference to the object that managages the ECL schedule.
Definition FlowGenericVanguard.hpp:168
ParallelWellStruct parallelWells_
Information about wells in parallel.
Definition FlowGenericVanguard.hpp:391
bool enableDistributedWells() const
Whether perforations of a well might be distributed.
Definition FlowGenericVanguard.hpp:289
const EclipseState & eclState() const
Return a reference to the internalized ECL deck.
Definition FlowGenericVanguard.hpp:159
bool ownersFirst() const
Parameter that decide if cells owned by rank are ordered before ghost cells.
Definition FlowGenericVanguard.hpp:251
Dune::EdgeWeightMethod edgeWeightsMethod() const
Parameter deciding the edge-weight strategy of the load balancer.
Definition FlowGenericVanguard.hpp:233
Definition GenericCpGridVanguard.hpp:78
const CartesianIndexMapper & cartesianIndexMapper() const
Returns the object which maps a global element index of the simulation grid to the corresponding elem...
Definition GenericCpGridVanguard.cpp:568
static void setExternalLoadBalancer(const std::function< std::vector< int >(const Dune::CpGrid &)> &loadBalancer)
Sets a function that returns external load balancing information when passed the grid.
Definition GenericCpGridVanguard.hpp:123
Definition Transmissibility.hpp:54
Defines the common properties required by the porous medium multi-phase models.
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilboundaryratevector.hh:37
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242
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:235
Definition FlowBaseVanguard.hpp:69
The type of the DUNE grid.
Definition basicproperties.hh:100
Definition CpGridVanguard.hpp:55
Property which provides a Vanguard (manages grids)
Definition basicproperties.hh:96