GenericCpGridVanguard.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_GENERIC_CPGRID_VANGUARD_HPP
28#define OPM_GENERIC_CPGRID_VANGUARD_HPP
29
30#include <opm/grid/CpGrid.hpp>
31#include <opm/grid/cpgrid/LevelCartesianIndexMapper.hpp>
32
34
35#include <functional>
36#include <memory>
37#include <optional>
38#include <vector>
39
40#if HAVE_MPI
41#include <filesystem>
42#endif
43
44namespace Opm {
45 class EclipseState;
46 class Schedule;
47 class Well;
48 class ParallelEclipseState;
49 class LgrCollection;
50}
51
52namespace Opm {
53
54#if HAVE_MPI
55namespace details {
57{
58public:
59 explicit MPIPartitionFromFile(const std::filesystem::path& partitionFile)
60 : partitionFile_(partitionFile)
61 {}
62
63 std::vector<int> operator()(const Dune::CpGrid& grid) const;
64
65private:
66 std::filesystem::path partitionFile_{};
67};
68
69} // namespace Opm::details
70#endif // HAVE_MPI
71
72
76extern std::optional<std::function<std::vector<int> (const Dune::CpGrid&)>> externalLoadBalancer;
77
78template<class ElementMapper, class GridView, class Scalar>
80protected:
83 using Element = typename GridView::template Codim<0>::Entity;
84
85public:
87
88 virtual ~GenericCpGridVanguard() = default;
89
93 Dune::CpGrid& grid()
94 { return *grid_; }
95
99 const Dune::CpGrid& grid() const
100 { return *grid_; }
101
111 const Dune::CpGrid& equilGrid() const;
112
121
125 static void setExternalLoadBalancer(const std::function<std::vector<int> (const Dune::CpGrid&)>& loadBalancer)
126 {
127 externalLoadBalancer = loadBalancer;
128 }
129
135
141
146
147 const std::vector<int>& cellPartition() const
148 {
149 return this->cell_part_;
150 }
151
152protected:
158#if HAVE_MPI
159 void doLoadBalance_(const Dune::EdgeWeightMethod edgeWeightsMethod,
160 const bool ownersFirst,
161 const bool addCorners,
162 const int numOverlap,
163 const Dune::PartitionMethod partitionMethod,
164 const bool serialPartitioning,
165 const bool enableDistributedWells,
166 const bool allowSplittingInactiveWells,
167 const double imbalanceTol,
168 const GridView& gridView,
169 const Schedule& schedule,
170 EclipseState& eclState,
172 const int numJacobiBlocks,
173 const bool enableEclOutput);
174
175 void distributeFieldProps_(EclipseState& eclState);
176
177private:
178 std::vector<double> extractFaceTrans(const GridView& gridView) const;
179
180 void distributeGrid(const Dune::EdgeWeightMethod edgeWeightsMethod,
181 const bool ownersFirst,
182 const bool addCorners,
183 const int numOverlap,
184 const Dune::PartitionMethod partitionMethod,
185 const bool serialPartitioning,
186 const bool enableDistributedWells,
187 const double imbalanceTol,
188 const bool loadBalancerSet,
189 const bool useTransToFilterOverlap,
190 const std::vector<double>& faceTrans,
191 const std::vector<Well>& wells,
192 const std::unordered_map<std::string, std::set<int>>& possibleFutureConnections,
193 EclipseState& eclState,
195
196 void distributeGrid(const Dune::EdgeWeightMethod edgeWeightsMethod,
197 const bool ownersFirst,
198 const bool addCorners,
199 const int numOverlap,
200 const Dune::PartitionMethod partitionMethod,
201 const bool serialPartitioning,
202 const bool enableDistributedWells,
203 const double imbalanceTol,
204 const bool loadBalancerSet,
205 const bool useTransToFilterOverlap,
206 const std::vector<double>& faceTrans,
207 const std::vector<Well>& wells,
208 const std::unordered_map<std::string, std::set<int>>& possibleFutureConnections,
209 ParallelEclipseState* eclState,
211
212protected:
213 virtual const std::string& zoltanParams() const = 0;
214 virtual double zoltanPhgEdgeSizeThreshold() const = 0;
215 virtual const std::string& metisParams() const = 0;
216
217#endif // HAVE_MPI
218
220
221 void doCreateGrids_(bool edge_conformal, EclipseState& eclState);
222 void addLgrsUpdateLeafView(const LgrCollection& lgrCollection,
223 const int lgrsSize,
224 Dune::CpGrid& grid);
225
226 virtual void allocTrans() = 0;
227 virtual double getTransmissibility(unsigned I, unsigned J) const = 0;
228
229 Scalar computeCellThickness(const Element& element) const;
230
231 std::unique_ptr<Dune::CpGrid> grid_;
232 std::unique_ptr<Dune::CpGrid> equilGrid_;
233 std::unique_ptr<CartesianIndexMapper> cartesianIndexMapper_;
234 std::unique_ptr<CartesianIndexMapper> equilCartesianIndexMapper_;
235 std::unique_ptr<LevelCartesianIndexMapper> levelCartesianIndexMapper_;
236
238 std::vector<int> cell_part_{};
239};
240
241} // namespace Opm
242
243#endif // OPM_GENERIC_CPGRID_VANGUARD_HPP
Definition: CollectDataOnIORank.hpp:50
std::vector< std::pair< std::string, bool > > ParallelWellStruct
Definition: FlowGenericVanguard.hpp:110
Definition: GenericCpGridVanguard.hpp:79
const CartesianIndexMapper & cartesianIndexMapper() const
Returns the object which maps a global element index of the simulation grid to the corresponding elem...
void releaseEquilGrid()
Indicates that the initial condition has been computed and the memory used by the EQUIL grid can be r...
const Dune::CpGrid & equilGrid() const
Returns a refefence to the grid which should be used by the EQUIL initialization code.
virtual double zoltanPhgEdgeSizeThreshold() const =0
const LevelCartesianIndexMapper levelCartesianIndexMapper() const
Returns the object which maps a global element index of the simulation grid to the corresponding elem...
std::unique_ptr< Dune::CpGrid > equilGrid_
Definition: GenericCpGridVanguard.hpp:232
virtual double getTransmissibility(unsigned I, unsigned J) const =0
const CartesianIndexMapper & equilCartesianIndexMapper() const
Returns mapper from compressed to cartesian indices for the EQUIL grid.
std::vector< int > cell_part_
Definition: GenericCpGridVanguard.hpp:238
virtual void allocTrans()=0
int mpiRank
Definition: GenericCpGridVanguard.hpp:237
void doLoadBalance_(const Dune::EdgeWeightMethod edgeWeightsMethod, const bool ownersFirst, const bool addCorners, const int numOverlap, const Dune::PartitionMethod partitionMethod, const bool serialPartitioning, const bool enableDistributedWells, const bool allowSplittingInactiveWells, const double imbalanceTol, const GridView &gridView, const Schedule &schedule, EclipseState &eclState, FlowGenericVanguard::ParallelWellStruct &parallelWells, const int numJacobiBlocks, const bool enableEclOutput)
Distribute the simulation grid over multiple processes.
const std::vector< int > & cellPartition() const
Definition: GenericCpGridVanguard.hpp:147
const Dune::CpGrid & grid() const
Return a reference to the simulation grid.
Definition: GenericCpGridVanguard.hpp:99
void distributeFieldProps_(EclipseState &eclState)
std::unique_ptr< CartesianIndexMapper > equilCartesianIndexMapper_
Definition: GenericCpGridVanguard.hpp:234
std::unique_ptr< LevelCartesianIndexMapper > levelCartesianIndexMapper_
Definition: GenericCpGridVanguard.hpp:235
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:125
virtual const std::string & metisParams() const =0
Dune::CpGrid & grid()
Return a reference to the simulation grid.
Definition: GenericCpGridVanguard.hpp:93
typename GridView::template Codim< 0 >::Entity Element
Definition: GenericCpGridVanguard.hpp:83
virtual const std::string & zoltanParams() const =0
void doCreateGrids_(bool edge_conformal, EclipseState &eclState)
std::unique_ptr< Dune::CpGrid > grid_
Definition: GenericCpGridVanguard.hpp:231
std::unique_ptr< CartesianIndexMapper > cartesianIndexMapper_
Definition: GenericCpGridVanguard.hpp:233
Scalar computeCellThickness(const Element &element) const
void addLgrsUpdateLeafView(const LgrCollection &lgrCollection, const int lgrsSize, Dune::CpGrid &grid)
virtual ~GenericCpGridVanguard()=default
Definition: EclGenericWriter.hpp:52
Parallel frontend to the EclipseState.
Definition: ParallelEclipseState.hpp:153
Definition: GenericCpGridVanguard.hpp:57
MPIPartitionFromFile(const std::filesystem::path &partitionFile)
Definition: GenericCpGridVanguard.hpp:59
std::vector< int > operator()(const Dune::CpGrid &grid) const
Definition: blackoilbioeffectsmodules.hh:45
std::optional< std::function< std::vector< int >(const Dune::CpGrid &)> > externalLoadBalancer
optional functor returning external load balancing information