CpGrid.hpp
Go to the documentation of this file.
1//===========================================================================
2//
3// File: CpGrid.hpp
4//
5// Created: Fri May 29 20:26:36 2009
6//
7// Author(s): Atgeirr F Rasmussen <atgeirr@sintef.no>
8// B�rd Skaflestad <bard.skaflestad@sintef.no>
9// Antonella Ritorto <antonella.ritorto@opm-op.com>
10//
11// $Date$
12//
13// $Revision$
14//
15//===========================================================================
16
17/*
18 Copyright 2009, 2010 SINTEF ICT, Applied Mathematics.
19 Copyright 2009, 2010, 2014, 2022-2023 Equinor ASA.
20 Copyright 2014, 2015 Dr. Blatt - HPC-Simulartion-Software & Services
21 Copyright 2015 NTNU
22
23 This file is part of The Open Porous Media project (OPM).
24
25 OPM is free software: you can redistribute it and/or modify
26 it under the terms of the GNU General Public License as published by
27 the Free Software Foundation, either version 3 of the License, or
28 (at your option) any later version.
29
30 OPM is distributed in the hope that it will be useful,
31 but WITHOUT ANY WARRANTY; without even the implied warranty of
32 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 GNU General Public License for more details.
34
35 You should have received a copy of the GNU General Public License
36 along with OPM. If not, see <http://www.gnu.org/licenses/>.
37*/
38
39#ifndef OPM_CPGRID_HEADER
40#define OPM_CPGRID_HEADER
41
42// Warning suppression for Dune includes.
43#include <opm/grid/utility/platform_dependent/disable_warnings.h> // Not really needed it seems, but alas.
44
45#include <dune/grid/common/grid.hh>
49#include <opm/grid/utility/platform_dependent/reenable_warnings.h> // Not really needed it seems, but alas.
50#include "common/GridEnums.hpp"
52
53#include <iostream>
54#if ! HAVE_MPI
55#include <list>
56#endif
57
58namespace Opm
59{
60class EclipseGrid;
61class EclipseState;
62template<typename Grid, typename GridView> class LookUpData;
63template<typename Grid, typename GridView> class LookUpCartesianData;
64class NNC;
65}
66
67namespace Dune
68{
69 class CpGrid;
70
71 namespace cpgrid
72 {
73 class CpGridData;
74 template <int> class Entity;
75 template<int,int> class Geometry;
76 class HierarchicIterator;
77 class IntersectionIterator;
78 template<int, PartitionIteratorType> class Iterator;
79 class LevelGlobalIdSet;
80 class GlobalIdSet;
81 class Intersection;
82 class IntersectionIterator;
83 class IndexSet;
84 class IdSet;
85
86 }
87}
88
90 const std::vector<std::array<int,3>>&,
91 const std::vector<std::array<int,3>>&,
92 const std::vector<std::array<int,3>>&,
93 const std::vector<std::string>&);
94
95void testCase(const std::string&,
96 const Opm::NNC&,
97 const std::vector<std::array<int,3>>&,
98 const std::vector<std::array<int,3>>&,
99 const std::vector<std::array<int,3>>&,
100 const std::vector<std::string>&,
101 bool);
102
104 const std::vector<std::array<int,3>>&,
105 const std::vector<std::array<int,3>>&);
106
108
110 const std::array<int, 3>&,
111 bool);
112
114 const std::vector<std::array<int,3>>&,
115 const std::vector<std::array<int,3>>&,
116 const std::vector<std::array<int,3>>&,
117 const std::vector<std::string>&);
118
119void refinePatch_and_check(const std::array<int,3>&,
120 const std::array<int,3>&,
121 const std::array<int,3>&);
122
124 const Dune::CpGrid&);
125namespace Dune
126{
127
129 //
130 // CpGridTraits
131 //
133
135 {
137 typedef CpGrid Grid;
138
147
150
153 template <int cd>
154 struct Codim
155 {
158 typedef cpgrid::Geometry<3-cd, 3> Geometry;
159 //typedef Dune::Geometry<3-cd, 3, CpGrid, cpgrid::Geometry> Geometry;
162 //typedef Dune::Geometry<3-cd, 3, CpGrid, cpgrid::Geometry> LocalGeometry;
165
168
171
174
177 template <PartitionIteratorType pitype>
179 {
184 };
185 };
186
189 template <PartitionIteratorType pitype>
191 {
193 typedef Dune::GridView<DefaultLevelGridViewTraits<CpGrid> > LevelGridView;
195 typedef Dune::GridView<DefaultLeafGridViewTraits<CpGrid> > LeafGridView;
196
197 };
198
200 typedef Dune::GridView<DefaultLevelGridViewTraits<CpGrid>> LevelGridView;
202 typedef Dune::GridView<DefaultLeafGridViewTraits<CpGrid>> LeafGridView;
203
212
216 };
217
219 //
220 // CpGridFamily
221 //
223
225 {
227 };
228
230 //
231 // CpGrid
232 //
234
236 class CpGrid
237 : public GridDefaultImplementation<3, 3, double, CpGridFamily>
238 {
239 friend class cpgrid::CpGridData;
240 friend class cpgrid::Entity<0>;
241 friend class cpgrid::Entity<1>;
242 friend class cpgrid::Entity<2>;
243 friend class cpgrid::Entity<3>;
244 template<typename Grid, typename GridView> friend class Opm::LookUpData;
245 template<typename Grid, typename GridView> friend class Opm::LookUpCartesianData;
246 template<int dim>
247 friend cpgrid::Entity<dim> createEntity(const CpGrid&,int,bool);
249 const std::vector<std::array<int,3>>&,
250 const std::vector<std::array<int,3>>&,
251 const std::vector<std::array<int,3>>&,
252 const std::vector<std::string>&);
253 friend void ::testCase(const std::string&,
254 const Opm::NNC&,
255 const std::vector<std::array<int,3>>&,
256 const std::vector<std::array<int,3>>&,
257 const std::vector<std::array<int,3>>&,
258 const std::vector<std::string>&,
259 bool);
261 const std::vector<std::array<int,3>>&,
262 const std::vector<std::array<int,3>>&);
263 friend void ::lookup_check(const Dune::CpGrid&);
264 friend
266 const std::array<int,3>&,
267 bool);
268 friend
270 const std::vector<std::array<int,3>>&,
271 const std::vector<std::array<int,3>>&,
272 const std::vector<std::array<int,3>>&,
273 const std::vector<std::string>&);
274 friend
275 void ::refinePatch_and_check(const std::array<int,3>&,
276 const std::array<int,3>&,
277 const std::array<int,3>&);
278 friend
280 const Dune::CpGrid&);
281
282 public:
283
284 // --- Typedefs ---
285
286
289
290
291 // --- Methods ---
292
293
296
297 CpGrid(MPIHelper::MPICommunicator comm);
298
300
301
304 void readSintefLegacyFormat(const std::string& grid_prefix);
305
306
310 void writeSintefLegacyFormat(const std::string& grid_prefix) const;
311
312
313#if HAVE_ECL_INPUT
332 std::vector<std::size_t> processEclipseFormat(const Opm::EclipseGrid* ecl_grid,
333 Opm::EclipseState* ecl_state,
334 bool periodic_extension, bool turn_normals, bool clip_z,
335 bool pinchActive);
336
356 std::vector<std::size_t> processEclipseFormat(const Opm::EclipseGrid* ecl_grid,
357 Opm::EclipseState* ecl_state,
358 bool periodic_extension, bool turn_normals = false, bool clip_z = false);
359
360#endif
361
365 void processEclipseFormat(const grdecl& input_data, bool remove_ij_boundary, bool turn_normals = false);
366
368
374
375
382 void createCartesian(const std::array<int, 3>& dims,
383 const std::array<double, 3>& cellsize,
384 const std::array<int, 3>& shift = {0,0,0});
385
389 const std::array<int, 3>& logicalCartesianSize() const;
390
398 const std::vector<int>& globalCell() const;
399
401 const std::vector<std::shared_ptr<Dune::cpgrid::CpGridData>>& chooseData() const;
402
410 void getIJK(const int c, std::array<int,3>& ijk) const;
412
416 bool uniqueBoundaryIds() const;
417
420 void setUniqueBoundaryIds(bool uids);
421
422
423 // --- Dune interface below ---
424
426 // \@{
431 std::string name() const;
432
434 int maxLevel() const;
435
437 template<int codim>
438 typename Traits::template Codim<codim>::LevelIterator lbegin (int level) const;
440 template<int codim>
441 typename Traits::template Codim<codim>::LevelIterator lend (int level) const;
442
444 template<int codim, PartitionIteratorType PiType>
445 typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const;
447 template<int codim, PartitionIteratorType PiType>
448 typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lend (int level) const;
449
451 template<int codim>
452 typename Traits::template Codim<codim>::LeafIterator leafbegin() const;
454 template<int codim>
455 typename Traits::template Codim<codim>::LeafIterator leafend() const;
456
458 template<int codim, PartitionIteratorType PiType>
459 typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafbegin() const;
461 template<int codim, PartitionIteratorType PiType>
462 typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafend() const;
463
465 int size (int level, int codim) const;
466
468 int size (int codim) const;
469
471 int size (int level, GeometryType type) const;
472
474 int size (GeometryType type) const;
475
477 const Traits::GlobalIdSet& globalIdSet() const;
478
480 const Traits::LocalIdSet& localIdSet() const;
481
483 const Traits::LevelIndexSet& levelIndexSet(int level) const;
484
486 const Traits::LeafIndexSet& leafIndexSet() const;
487
489 void globalRefine (int);
490
491 const std::vector<Dune::GeometryType>& geomTypes(const int) const;
492
494 template <int codim>
496
510 void addLgrUpdateLeafView(const std::array<int,3>& cells_per_dim, const std::array<int,3>& startIJK,
511 const std::array<int,3>& endIJK, const std::string& lgr_name);
512
529 void addLgrsUpdateLeafView(const std::vector<std::array<int,3>>& cells_per_dim_vec,
530 const std::vector<std::array<int,3>>& startIJK_vec,
531 const std::vector<std::array<int,3>>& endIJK_vec,
532 const std::vector<std::string>& lgr_name_vec);
533
534 // @brief TO BE DONE
535 const std::map<std::string,int>& getLgrNameToLevel() const;
536
537 // @breif Compute center of an entity/element/cell in the Eclipse way:
538 // - Average of the 4 corners of the bottom face.
539 // - Average of the 4 corners of the top face.
540 // Return average of the previous computations.
541 // @param [in] int Index of a cell.
542 // @return 'eclipse centroid'
543 std::array<double,3> getEclCentroid(const int& idx) const;
544
545 // @breif Compute center of an entity/element/cell in the Eclipse way:
546 // - Average of the 4 corners of the bottom face.
547 // - Average of the 4 corners of the top face.
548 // Return average of the previous computations.
549 // @param [in] Entity<0> Entity
550 // @return 'eclipse centroid'
551 std::array<double,3> getEclCentroid(const cpgrid::Entity<0>& elem) const;
552
553 // @brief Return parent (coarse) intersection (face) of a refined face on the leaf grid view, whose neighboring cells
554 // are two: one coarse cell (equivalent to its origin cell from level 0), and one refined cell
555 // from certain LGR
557
558 /* No refinement implemented. GridDefaultImplementation's methods will be used.
559
569
570 bool mark(int refCount, const typename Traits::template Codim<0>::EntityPointer & e)
571 {
572 return hostgrid_->mark(refCount, getHostEntity<0>(*e));
573 }
574
578
579 int getMark(const typename Traits::template Codim<0>::EntityPointer & e) const
580 {
581 return hostgrid_->getMark(getHostEntity<0>(*e));
582 }
583
585 bool preAdapt() {
586 return hostgrid_->preAdapt();
587 }
588
589
591 bool adapt()
592 {
593 return hostgrid_->adapt();
594 }
595
597 void postAdapt() {
598 return hostgrid_->postAdapt();
599 }
600
601 end of refinement section */
602
604 unsigned int overlapSize(int) const;
605
606
608 unsigned int ghostSize(int) const;
609
611 unsigned int overlapSize(int, int) const;
612
614 unsigned int ghostSize(int, int) const;
615
617 unsigned int numBoundarySegments() const;
618
619 void setZoltanParams(const std::map<std::string,std::string>& params);
620
621
622 // loadbalance is not part of the grid interface therefore we skip it.
623
629 bool loadBalance(int overlapLayers=1, bool useZoltan=true)
630 {
631 using std::get;
632 return get<0>(scatterGrid(defaultTransEdgeWgt, false, nullptr, false, nullptr, true, overlapLayers, useZoltan ));
633 }
634
635 // loadbalance is not part of the grid interface therefore we skip it.
636
656 std::pair<bool,std::vector<std::pair<std::string,bool>>>
657 loadBalance(const std::vector<cpgrid::OpmWellType> * wells,
658 const double* transmissibilities = nullptr,
659 int overlapLayers=1, bool useZoltan=true)
660 {
661 return scatterGrid(defaultTransEdgeWgt, false, wells, false, transmissibilities, false, overlapLayers, useZoltan);
662 }
663
664 // loadbalance is not part of the grid interface therefore we skip it.
665
689 std::pair<bool,std::vector<std::pair<std::string,bool>>>
690 loadBalance(EdgeWeightMethod method, const std::vector<cpgrid::OpmWellType> * wells,
691 const double* transmissibilities = nullptr, bool ownersFirst=false,
692 bool addCornerCells=false, int overlapLayers=1,
693 bool useZoltan = true)
694 {
695 return scatterGrid(method, ownersFirst, wells, false, transmissibilities, addCornerCells, overlapLayers, useZoltan);
696 }
697
717 template<class DataHandle>
718 std::pair<bool, std::vector<std::pair<std::string,bool> > >
719 loadBalance(DataHandle& data,
720 const std::vector<cpgrid::OpmWellType> * wells,
721 const double* transmissibilities = nullptr,
722 int overlapLayers=1, bool useZoltan = true)
723 {
724 auto ret = loadBalance(wells, transmissibilities, overlapLayers, useZoltan);
725 using std::get;
726 if (get<0>(ret))
727 {
729 }
730 return ret;
731 }
732
761 template<class DataHandle>
762 std::pair<bool, std::vector<std::pair<std::string,bool> > >
763 loadBalance(DataHandle& data, EdgeWeightMethod method,
764 const std::vector<cpgrid::OpmWellType> * wells,
765 bool serialPartitioning,
766 const double* transmissibilities = nullptr, bool ownersFirst=false,
767 bool addCornerCells=false, int overlapLayers=1, bool useZoltan = true,
768 double zoltanImbalanceTol = 1.1,
769 bool allowDistributedWells = false)
770 {
771 auto ret = scatterGrid(method, ownersFirst, wells, serialPartitioning, transmissibilities,
772 addCornerCells, overlapLayers, useZoltan, zoltanImbalanceTol, allowDistributedWells);
773 using std::get;
774 if (get<0>(ret))
775 {
777 }
778 return ret;
779 }
780
797 template<class DataHandle>
798 std::pair<bool, std::vector<std::pair<std::string,bool> > >
799 loadBalance(DataHandle& data, const std::vector<int>& parts,
800 const std::vector<cpgrid::OpmWellType> * wells,
801 bool ownersFirst=false,
802 bool addCornerCells=false, int overlapLayers=1)
803 {
804 using std::get;
805 auto ret = scatterGrid(defaultTransEdgeWgt, ownersFirst, wells,
806 /* serialPartitioning = */ false,
807 /* transmissibilities = */ {},
808 addCornerCells, overlapLayers, /* useZoltan =*/ false,
809 /* zoltanImbalanceTol (ignored) = */ 0.0,
810 /* allowDistributedWells = */ true, parts);
811 using std::get;
812 if (get<0>(ret))
813 {
815 }
816 return ret;
817 }
818
827 template<class DataHandle>
828 bool loadBalance(DataHandle& data,
829 decltype(data.fixedSize(0,0)) overlapLayers=1, bool useZoltan = true)
830 {
831 // decltype usage needed to tell the compiler not to use this function if first
832 // argument is std::vector but rather loadbalance by parts
833 bool ret = loadBalance(overlapLayers, useZoltan);
834 if (ret)
835 {
837 }
838 return ret;
839 }
840
852 bool loadBalance(const std::vector<int>& parts, bool ownersFirst=false,
853 bool addCornerCells=false, int overlapLayers=1)
854 {
855 using std::get;
856 return get<0>(scatterGrid(defaultTransEdgeWgt, ownersFirst, /* wells = */ {},
857 /* serialPartitioning = */ false,
858 /* trabsmissibilities = */ {},
859 addCornerCells, overlapLayers, /* useZoltan =*/ false,
860 /* zoltanImbalanceTol (ignored) = */ 0.0,
861 /* allowDistributedWells = */ true, parts));
862 }
863
876 template<class DataHandle>
877 bool loadBalance(DataHandle& data, const std::vector<int>& parts, bool ownersFirst=false,
878 bool addCornerCells=false, int overlapLayers=1)
879 {
880 bool ret = loadBalance(parts, ownersFirst, addCornerCells, overlapLayers);
881 if (ret)
882 {
884 }
885 return ret;
886 }
887
893 std::vector<int>
894 zoltanPartitionWithoutScatter(const std::vector<cpgrid::OpmWellType>* wells,
895 const double* transmissibilities,
896 const int numParts,
897 const double zoltanImbalanceTol) const;
898
906 template<class DataHandle>
907 void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int /*level*/) const
908 {
909 communicate(data, iftype, dir);
910 }
911
919 template<class DataHandle>
920 void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const;
921
923 const typename CpGridTraits::Communication& comm () const;
925
926 // ------------ End of Dune interface, start of simplified interface --------------
927
933
934 // enum { dimension = 3 }; // already defined
935
936 typedef Dune::FieldVector<double, 3> Vector;
937
938
939 const std::vector<double>& zcornData() const;
940
941
942 // Topology
944 int numCells() const;
945
947 int numFaces() const;
948
950 int numVertices() const;
951
952
959 int numCellFaces(int cell) const;
960
965 int cellFace(int cell, int local_index) const;
966
970
981 int faceCell(int face, int local_index) const;
982
989 int numCellFaces() const;
990
991 int numFaceVertices(int face) const;
992
997 int faceVertex(int face, int local_index) const;
998
1001 double cellCenterDepth(int cell_index) const;
1002
1003
1004 const Vector faceCenterEcl(int cell_index, int face, const Dune::cpgrid::Intersection& intersection) const;
1005
1006 const Vector faceAreaNormalEcl(int face) const;
1007
1008
1009 // Geometry
1013 const Vector& vertexPosition(int vertex) const;
1014
1017 double faceArea(int face) const;
1018
1021 const Vector& faceCentroid(int face) const;
1022
1026 const Vector& faceNormal(int face) const;
1027
1030 double cellVolume(int cell) const;
1031
1034 const Vector& cellCentroid(int cell) const;
1035
1038 template<int codim>
1040 : public RandomAccessIteratorFacade<CentroidIterator<codim>,
1041 FieldVector<double, 3>,
1042 const FieldVector<double, 3>&, int>
1043 {
1044 public:
1046 typedef typename std::vector<cpgrid::Geometry<3-codim, 3> >::const_iterator
1051 : iter_(iter)
1052 {}
1053
1054 const FieldVector<double,3>& dereference() const
1055 {
1056 return iter_->center();
1057 }
1059 {
1060 ++iter_;
1061 }
1062 const FieldVector<double,3>& elementAt(int n)
1063 {
1064 return iter_[n]->center();
1065 }
1066 void advance(int n){
1067 iter_+=n;
1068 }
1070 {
1071 --iter_;
1072 }
1074 {
1075 return o-iter_;
1076 }
1077 bool equals(const CentroidIterator& o) const{
1078 return o==iter_;
1079 }
1080 private:
1082 GeometryIterator iter_;
1083 };
1084
1087
1090
1091 // Extra
1092 int boundaryId(int face) const;
1093
1100 template<class Cell2FacesRowIterator>
1101 int
1102 faceTag(const Cell2FacesRowIterator& cell_face) const;
1103
1105
1106 // ------------ End of simplified interface --------------
1107
1108 //------------- methods not in the DUNE grid interface.
1109
1114
1115
1124 template<class DataHandle>
1125 void scatterData(DataHandle& handle) const;
1126
1133 template<class DataHandle>
1134 void gatherData(DataHandle& handle) const;
1135
1138
1168
1172
1175
1179
1180#if HAVE_MPI
1185
1188
1193
1195
1197
1199
1201#endif
1202
1204 const std::vector<int>& sortedNumAquiferCells() const;
1205
1206 private:
1232 std::pair<bool, std::vector<std::pair<std::string,bool> > >
1233 scatterGrid(EdgeWeightMethod method,
1234 bool ownersFirst,
1235 const std::vector<cpgrid::OpmWellType> * wells,
1236 bool serialPartitioning,
1237 const double* transmissibilities,
1238 bool addCornerCells,
1239 int overlapLayers,
1240 bool useZoltan = true,
1241 double zoltanImbalanceTol = 1.1,
1242 bool allowDistributedWells = true,
1243 const std::vector<int>& input_cell_part = {});
1244
1249 std::vector<std::shared_ptr<cpgrid::CpGridData>> data_;
1251 cpgrid::CpGridData* current_view_data_;
1253 std::vector<std::shared_ptr<cpgrid::CpGridData>> distributed_data_;
1255 std::map<std::string,int> lgr_names_ = {{"GLOBAL", 0}};
1261 std::shared_ptr<InterfaceMap> cell_scatter_gather_interfaces_;
1262 /*
1263 * @brief Interface for scattering and gathering point data.
1264 *
1265 * @warning Will only update owner cells
1266 */
1267 std::shared_ptr<InterfaceMap> point_scatter_gather_interfaces_;
1271 std::shared_ptr<cpgrid::GlobalIdSet> global_id_set_ptr_;
1272
1273
1277 std::map<std::string,std::string> zoltanParams;
1278
1279 }; // end Class CpGrid
1280
1281} // end namespace Dune
1282
1286
1287
1288namespace Dune
1289{
1290
1291 namespace Capabilities
1292 {
1294 template <>
1295 struct hasEntity<CpGrid, 0>
1296 {
1297 static const bool v = true;
1298 };
1299
1301 template <>
1302 struct hasEntity<CpGrid, 3>
1303 {
1304 static const bool v = true;
1305 };
1306
1307 template<>
1308 struct canCommunicate<CpGrid,0>
1309 {
1310 static const bool v = true;
1311 };
1312
1313 template<>
1314 struct canCommunicate<CpGrid,3>
1315 {
1316 static const bool v = true;
1317 };
1318
1320 template <>
1321 struct hasBackupRestoreFacilities<CpGrid>
1322 {
1323 static const bool v = false;
1324 };
1325
1326 }
1327
1328 template<class DataHandle>
1329 void CpGrid::communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const
1330 {
1331 current_view_data_->communicate(data, iftype, dir);
1332 }
1333
1334
1335 template<class DataHandle>
1336 void CpGrid::scatterData(DataHandle& handle) const
1337 {
1338#if HAVE_MPI
1339 if(distributed_data_.empty())
1340 OPM_THROW(std::runtime_error, "Moving Data only allowed with a load balanced grid!");
1341 distributed_data_[0]->scatterData(handle, data_[0].get(), distributed_data_[0].get(), cellScatterGatherInterface(),
1343#else
1344 // Suppress warnings for unused argument.
1345 (void) handle;
1346#endif
1347 }
1348
1349 template<class DataHandle>
1350 void CpGrid::gatherData(DataHandle& handle) const
1351 {
1352#if HAVE_MPI
1353 if(distributed_data_.empty())
1354 OPM_THROW(std::runtime_error, "Moving Data only allowed with a load balance grid!");
1355 distributed_data_[0]->gatherData(handle, data_[0].get(), distributed_data_[0].get());
1356#else
1357 // Suppress warnings for unused argument.
1358 (void) handle;
1359#endif
1360 }
1361
1362
1363 template<class Cell2FacesRowIterator>
1364 int
1365 CpGrid::faceTag(const Cell2FacesRowIterator& cell_face) const
1366 {
1367 // Note that this relies on the following implementation detail:
1368 // The grid is always constructed such that the interior faces constructed
1369 // with orientation set to true are
1370 // oriented along the positive IJK direction. Oriented means that
1371 // the first cell attached to face has the lower index.
1372 // For faces along the boundary (only one cell, always attached at index 0)
1373 // the orientation has to be determined by the orientation of the cell.
1374 // If it is true then in UnstructuredGrid it would be stored at index 0,
1375 // otherwise at index 1.
1376 const int cell = cell_face.getCellIndex();
1377 const int face = *cell_face;
1378 assert (0 <= cell); assert (cell < numCells());
1379 assert (0 <= face); assert (face < numFaces());
1380
1382
1383 const cpgrid::EntityRep<1> f(face, true);
1384 const F2C& f2c = current_view_data_->face_to_cell_[f];
1385 const face_tag tag = current_view_data_->face_tag_[f];
1386
1387 assert ((f2c.size() == 1) || (f2c.size() == 2));
1388
1389 int inside_cell = 0;
1390
1391 if ( f2c.size() == 2 ) // Two cells => interior
1392 {
1393 if ( f2c[1].index() == cell )
1394 {
1395 inside_cell = 1;
1396 }
1397 }
1398 const bool normal_is_in = ! f2c[inside_cell].orientation();
1399
1400 switch (tag) {
1401 case I_FACE:
1402 // LEFT : RIGHT
1403 return normal_is_in ? 0 : 1; // min(I) : max(I)
1404 case J_FACE:
1405 // BACK : FRONT
1406 return normal_is_in ? 2 : 3; // min(J) : max(J)
1407 case K_FACE:
1408 // Note: TOP at min(K) as 'z' measures *depth*.
1409 // TOP : BOTTOM
1410 return normal_is_in ? 4 : 5; // min(K) : max(K)
1411 case NNC_FACE:
1412 // For nnc faces we return the otherwise unused value -1.
1413 return -1;
1414 default:
1415 OPM_THROW(std::logic_error, "Unhandled face tag. This should never happen!");
1416 }
1417 }
1418
1419 template<int dim>
1421
1422} // namespace Dune
1423
1426#include "cpgrid/Intersection.hpp"
1427#include "cpgrid/Geometry.hpp"
1428#include "cpgrid/Indexsets.hpp"
1429
1430#endif // OPM_CPGRID_HEADER
void refinePatch_and_check(Dune::CpGrid &, const std::vector< std::array< int, 3 > > &, const std::vector< std::array< int, 3 > > &, const std::vector< std::array< int, 3 > > &, const std::vector< std::string > &)
void testCase(const std::string &, const Opm::NNC &, const std::vector< std::array< int, 3 > > &, const std::vector< std::array< int, 3 > > &, const std::vector< std::array< int, 3 > > &, const std::vector< std::string > &, bool)
void check_global_refine(const Dune::CpGrid &, const Dune::CpGrid &)
void noNNC_check(Dune::CpGrid &, const std::vector< std::array< int, 3 > > &, const std::vector< std::array< int, 3 > > &, const std::vector< std::array< int, 3 > > &, const std::vector< std::string > &)
void disjointPatches_check(Dune::CpGrid &, const std::vector< std::array< int, 3 > > &, const std::vector< std::array< int, 3 > > &)
void refine_and_check(const Dune::cpgrid::Geometry< 3, 3 > &, const std::array< int, 3 > &, bool)
void lookup_check(const Dune::CpGrid &)
DataHandle & data
Definition: CpGridData.hpp:1085
An iterator over the centroids of the geometry of the entities.
Definition: CpGrid.hpp:1043
void increment()
Definition: CpGrid.hpp:1058
CentroidIterator(GeometryIterator iter)
Constructs a new iterator from an iterator over the geometries.
Definition: CpGrid.hpp:1050
const FieldVector< double, 3 > & dereference() const
Definition: CpGrid.hpp:1054
int distanceTo(const CentroidIterator &o)
Definition: CpGrid.hpp:1073
void decrement()
Definition: CpGrid.hpp:1069
void advance(int n)
Definition: CpGrid.hpp:1066
std::vector< cpgrid::Geometry< 3-codim, 3 > >::const_iterator GeometryIterator
The type of the iterator over the codim geometries.
Definition: CpGrid.hpp:1047
bool equals(const CentroidIterator &o) const
Definition: CpGrid.hpp:1077
const FieldVector< double, 3 > & elementAt(int n)
Definition: CpGrid.hpp:1062
[ provides Dune::Grid ]
Definition: CpGrid.hpp:238
std::string name() const
Get the grid name.
CentroidIterator< 0 > beginCellCentroids() const
Get an iterator over the cell centroids positioned at the first one.
std::pair< bool, std::vector< std::pair< std::string, bool > > > loadBalance(EdgeWeightMethod method, const std::vector< cpgrid::OpmWellType > *wells, const double *transmissibilities=nullptr, bool ownersFirst=false, bool addCornerCells=false, int overlapLayers=1, bool useZoltan=true)
Distributes this grid over the available nodes in a distributed machine.
Definition: CpGrid.hpp:690
void switchToGlobalView()
Switch to the global view.
const Vector faceCenterEcl(int cell_index, int face, const Dune::cpgrid::Intersection &intersection) const
void readSintefLegacyFormat(const std::string &grid_prefix)
int numFaceVertices(int face) const
unsigned int numBoundarySegments() const
returns the number of boundary segments within the macro grid
void addLgrUpdateLeafView(const std::array< int, 3 > &cells_per_dim, const std::array< int, 3 > &startIJK, const std::array< int, 3 > &endIJK, const std::string &lgr_name)
Create a grid out of a coarse one and a refinement(LGR) of a selected block-shaped patch of cells fro...
CpGridFamily GridFamily
Family typedef, why is this not defined by Grid<>?
Definition: CpGrid.hpp:288
Traits::template Codim< codim >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
void gatherData(DataHandle &handle) const
Moves data from the distributed view to the global (all data on process) view.
Definition: CpGrid.hpp:1350
CentroidIterator< 1 > beginFaceCentroids() const
Get an iterator over the face centroids positioned at the first one.
void globalRefine(int)
global refinement
void setZoltanParams(const std::map< std::string, std::string > &params)
int size(GeometryType type) const
number of leaf entities per geometry type in this process
cpgrid::CpGridDataTraits::ParallelIndexSet ParallelIndexSet
The type of the parallel index set.
Definition: CpGrid.hpp:1182
int faceTag(const Cell2FacesRowIterator &cell_face) const
Get the cartesian tag associated with a face tag.
Definition: CpGrid.hpp:1365
const std::vector< double > & zcornData() const
ParallelIndexSet & getCellIndexSet()
void setUniqueBoundaryIds(bool uids)
std::array< double, 3 > getEclCentroid(const cpgrid::Entity< 0 > &elem) const
void createCartesian(const std::array< int, 3 > &dims, const std::array< double, 3 > &cellsize, const std::array< int, 3 > &shift={0, 0, 0})
Traits::template Codim< codim >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
void processEclipseFormat(const grdecl &input_data, bool remove_ij_boundary, bool turn_normals=false)
unsigned int overlapSize(int) const
Size of the overlap on the leaf level.
cpgrid::CpGridDataTraits::InterfaceMap InterfaceMap
The type of the map describing communication interfaces.
Definition: CpGrid.hpp:1137
Traits::template Codim< codim >::LevelIterator lend(int level) const
one past the end on this level
int numCellFaces() const
Get the sum of all faces attached to all cells.
const std::vector< int > & globalCell() const
std::pair< bool, std::vector< std::pair< std::string, bool > > > loadBalance(DataHandle &data, const std::vector< int > &parts, const std::vector< cpgrid::OpmWellType > *wells, bool ownersFirst=false, bool addCornerCells=false, int overlapLayers=1)
Distributes this grid over the available nodes in a distributed machine.
Definition: CpGrid.hpp:799
const Traits::LocalIdSet & localIdSet() const
Access to the LocalIdSet.
int maxLevel() const
Return maximum level defined in this grid. Levels are 0 and 1, maxlevel = 1 (not counting leafview),...
const CpGridTraits::Communication & comm() const
Get the collective communication object.
double faceArea(int face) const
Get the area of a face.
const std::vector< Dune::GeometryType > & geomTypes(const int) const
const Vector & vertexPosition(int vertex) const
Get the Position of a vertex.
int size(int level, int codim) const
Number of grid entities per level and codim.
const std::array< int, 3 > & logicalCartesianSize() const
int faceVertex(int face, int local_index) const
Get the index identifying a vertex of a face.
bool loadBalance(int overlapLayers=1, bool useZoltan=true)
Distributes this grid over the available nodes in a distributed machine.
Definition: CpGrid.hpp:629
const Vector & faceCentroid(int face) const
Get the coordinates of the center of a face.
unsigned int ghostSize(int, int) const
Size of the ghost cell layer on a given level.
cpgrid::CpGridDataTraits::RemoteIndices RemoteIndices
The type of the remote indices information.
Definition: CpGrid.hpp:1184
const InterfaceMap & cellScatterGatherInterface() const
Get an interface for gathering/scattering data attached to cells with communication.
int numVertices() const
Get The number of vertices.
Dune::cpgrid::Intersection getParentIntersectionFromLgrBoundaryFace(const Dune::cpgrid::Intersection &intersection) const
void getIJK(const int c, std::array< int, 3 > &ijk) const
Extract Cartesian index triplet (i,j,k) of an active cell.
int cellFace(int cell, int local_index) const
Get a specific face of a cell.
bool uniqueBoundaryIds() const
std::pair< bool, std::vector< std::pair< std::string, bool > > > loadBalance(const std::vector< cpgrid::OpmWellType > *wells, const double *transmissibilities=nullptr, int overlapLayers=1, bool useZoltan=true)
Distributes this grid over the available nodes in a distributed machine.
Definition: CpGrid.hpp:657
void addLgrsUpdateLeafView(const std::vector< std::array< int, 3 > > &cells_per_dim_vec, const std::vector< std::array< int, 3 > > &startIJK_vec, const std::vector< std::array< int, 3 > > &endIJK_vec, const std::vector< std::string > &lgr_name_vec)
Create a grid out of a coarse one and (at most) 2 refinements(LGRs) of selected block-shaped disjoint...
Traits::template Codim< codim >::template Partition< PiType >::LevelIterator lend(int level) const
one past the end on this level
std::pair< bool, std::vector< std::pair< std::string, bool > > > loadBalance(DataHandle &data, EdgeWeightMethod method, const std::vector< cpgrid::OpmWellType > *wells, bool serialPartitioning, const double *transmissibilities=nullptr, bool ownersFirst=false, bool addCornerCells=false, int overlapLayers=1, bool useZoltan=true, double zoltanImbalanceTol=1.1, bool allowDistributedWells=false)
Distributes this grid over the available nodes in a distributed machine.
Definition: CpGrid.hpp:763
const Traits::GlobalIdSet & globalIdSet() const
Access to the GlobalIdSet.
CpGrid(MPIHelper::MPICommunicator comm)
std::vector< int > zoltanPartitionWithoutScatter(const std::vector< cpgrid::OpmWellType > *wells, const double *transmissibilities, const int numParts, const double zoltanImbalanceTol) const
Partitions the grid using Zoltan without decomposing and distributing it among processes.
const ParallelIndexSet & getCellIndexSet() const
bool loadBalance(DataHandle &data, decltype(data.fixedSize(0, 0)) overlapLayers=1, bool useZoltan=true)
Distributes this grid and data over the available nodes in a distributed machine.
Definition: CpGrid.hpp:828
cpgrid::Entity< codim > entity(const cpgrid::Entity< codim > &seed) const
given an EntitySeed (or EntityPointer) return an entity object
int faceCell(int face, int local_index) const
Get the index identifying a cell attached to a face.
int numCellFaces(int cell) const
Get the number of faces of a cell.
int boundaryId(int face) const
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim and PartitionIteratorType.
unsigned int overlapSize(int, int) const
Size of the overlap on a given level.
void writeSintefLegacyFormat(const std::string &grid_prefix) const
unsigned int ghostSize(int) const
Size of the ghost cell layer on the leaf level.
friend cpgrid::Entity< dim > createEntity(const CpGrid &, int, bool)
const Vector & cellCentroid(int cell) const
Get the coordinates of the center of a cell.
std::pair< bool, std::vector< std::pair< std::string, bool > > > loadBalance(DataHandle &data, const std::vector< cpgrid::OpmWellType > *wells, const double *transmissibilities=nullptr, int overlapLayers=1, bool useZoltan=true)
Distributes this grid and data over the available nodes in a distributed machine.
Definition: CpGrid.hpp:719
const std::vector< std::shared_ptr< Dune::cpgrid::CpGridData > > & chooseData() const
Returns either data_ or distributed_data_(if non empty).
Traits::template Codim< codim >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
const Vector & faceNormal(int face) const
Get the unit normal of a face.
Dune::FieldVector< double, 3 > Vector
Definition: CpGrid.hpp:936
CpGrid()
Default constructor.
Traits::template Codim< codim >::template Partition< PiType >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level and PartitionIteratorType.
const std::map< std::string, int > & getLgrNameToLevel() const
const std::vector< int > & sortedNumAquiferCells() const
Get sorted active cell indices of numerical aquifer.
void switchToDistributedView()
Switch to the distributed view.
const RemoteIndices & getCellRemoteIndices() const
const Vector faceAreaNormalEcl(int face) const
bool loadBalance(DataHandle &data, const std::vector< int > &parts, bool ownersFirst=false, bool addCornerCells=false, int overlapLayers=1)
Distributes this grid and data over the available nodes in a distributed machine.
Definition: CpGrid.hpp:877
const Traits::LeafIndexSet & leafIndexSet() const
Access to the LeafIndexSet.
const cpgrid::OrientedEntityTable< 0, 1 >::row_type cellFaceRow(int cell) const
Get a list of indices identifying all faces of a cell.
int numCells() const
Get the number of cells.
bool loadBalance(const std::vector< int > &parts, bool ownersFirst=false, bool addCornerCells=false, int overlapLayers=1)
Distributes this grid over the available nodes in a distributed machine.
Definition: CpGrid.hpp:852
int size(int level, GeometryType type) const
number of entities per level and geometry type in this process
int numFaces() const
Get the number of faces.
std::array< double, 3 > getEclCentroid(const int &idx) const
double cellCenterDepth(int cell_index) const
Get vertical position of cell center ("zcorn" average).
void communicate(DataHandle &data, InterfaceType iftype, CommunicationDirection dir, int) const
communicate objects for all codims on a given level
Definition: CpGrid.hpp:907
const Traits::LevelIndexSet & levelIndexSet(int level) const
Access to the LevelIndexSets.
RemoteIndices & getCellRemoteIndices()
cpgrid::CpGridDataTraits::CommunicationType CommunicationType
The type of the owner-overlap-copy communication.
Definition: CpGrid.hpp:1187
int size(int codim) const
number of leaf entities per codim in this process
const InterfaceMap & pointScatterGatherInterface() const
Get an interface for gathering/scattering data attached to points with communication.
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
double cellVolume(int cell) const
Get the volume of the cell.
const CommunicationType & cellCommunication() const
Get the owner-overlap-copy communication for cells.
void scatterData(DataHandle &handle) const
Moves data from the global (all data on process) view to the distributed view.
Definition: CpGrid.hpp:1336
Struct that hods all the data needed to represent a Cpgrid.
Definition: CpGridData.hpp:131
void communicate(DataHandle &data, InterfaceType iftype, CommunicationDirection dir)
communicate objects for all codims on a given level
Definition: CpGridData.hpp:863
Represents an entity of a given codim, with positive or negative orientation.
Definition: EntityRep.hpp:99
The global id set for Dune.
Definition: Indexsets.hpp:304
Only needs to provide interface for doing nothing.
Definition: Iterators.hpp:108
Definition: Indexsets.hpp:55
Definition: Intersection.hpp:278
Definition: Intersection.hpp:66
Definition: Iterators.hpp:60
A class used as a row type for OrientedEntityTable.
Definition: OrientedEntityTable.hpp:55
Definition: LookUpData.hh:173
Definition: LookUpData.hh:63
The namespace Dune is the main namespace for all Dune code.
Definition: common/CartesianIndexMapper.hpp:10
cpgrid::Entity< dim > createEntity(const CpGrid &, int, bool)
EdgeWeightMethod
enum for choosing Methods for weighting graph-edges correspoding to cell interfaces in Zoltan's graph...
Definition: GridEnums.hpp:34
@ defaultTransEdgeWgt
Use the transmissibilities as edge weights.
Definition: GridEnums.hpp:38
Holds the implementation of the CpGrid as a pimple.
Definition: CellQuadrature.hpp:26
face_tag
Definition: preprocess.h:66
@ K_FACE
Definition: preprocess.h:69
@ J_FACE
Definition: preprocess.h:68
@ NNC_FACE
Definition: preprocess.h:70
@ I_FACE
Definition: preprocess.h:67
Definition: CpGrid.hpp:225
CpGridTraits Traits
Definition: CpGrid.hpp:226
Traits associated with a specific grid partition type.
Definition: CpGrid.hpp:179
cpgrid::Iterator< cd, pitype > LevelIterator
The type of the iterator over the level entities of this codim on this partition.
Definition: CpGrid.hpp:181
cpgrid::Iterator< cd, pitype > LeafIterator
The type of the iterator over the leaf entities of this codim on this partition.
Definition: CpGrid.hpp:183
Traits associated with a specific codim.
Definition: CpGrid.hpp:155
cpgrid::Entity< cd > Entity
The type of the entity.
Definition: CpGrid.hpp:164
cpgrid::Geometry< 3-cd, 3 > Geometry
The type of the geometry associated with the entity. IMPORTANT: Codim<codim>::Geometry == Geometry<di...
Definition: CpGrid.hpp:158
cpgrid::Geometry< 3-cd, 3 > LocalGeometry
The type of the local geometry associated with the entity.
Definition: CpGrid.hpp:161
cpgrid::Iterator< cd, All_Partition > LeafIterator
The type of the iterator over all leaf entities of this codim.
Definition: CpGrid.hpp:170
cpgrid::Iterator< cd, All_Partition > LevelIterator
The type of the iterator over all level entities of this codim.
Definition: CpGrid.hpp:167
cpgrid::Entity< cd > EntitySeed
The type of the entity pointer for entities of this codim.
Definition: CpGrid.hpp:173
Traits associated with a specific grid partition type.
Definition: CpGrid.hpp:191
Dune::GridView< DefaultLeafGridViewTraits< CpGrid > > LeafGridView
The type of the leaf grid view associated with this partition type.
Definition: CpGrid.hpp:195
Dune::GridView< DefaultLevelGridViewTraits< CpGrid > > LevelGridView
The type of the level grid view associated with this partition type.
Definition: CpGrid.hpp:193
Definition: CpGrid.hpp:135
cpgrid::IndexSet LevelIndexSet
The type of the level index set.
Definition: CpGrid.hpp:205
cpgrid::IntersectionIterator LeafIntersectionIterator
The type of the intersection iterator at the leafs of the grid.
Definition: CpGrid.hpp:144
Dune::GridView< DefaultLeafGridViewTraits< CpGrid > > LeafGridView
The type of the leaf grid view associated with this partition type.
Definition: CpGrid.hpp:202
Dune::GridView< DefaultLevelGridViewTraits< CpGrid > > LevelGridView
The type of the level grid view associated with this partition type.
Definition: CpGrid.hpp:200
cpgrid::GlobalIdSet GlobalIdSet
The type of the global id set.
Definition: CpGrid.hpp:209
cpgrid::IntersectionIterator LevelIntersectionIterator
The type of the intersection iterator at the levels of the grid.
Definition: CpGrid.hpp:146
cpgrid::IndexSet LeafIndexSet
The type of the leaf index set.
Definition: CpGrid.hpp:207
cpgrid::CpGridDataTraits::CollectiveCommunication CollectiveCommunication
Definition: CpGrid.hpp:215
GlobalIdSet LocalIdSet
The type of the local id set.
Definition: CpGrid.hpp:211
cpgrid::CpGridDataTraits::Communication Communication
The type of the collective communication.
Definition: CpGrid.hpp:214
cpgrid::HierarchicIterator HierarchicIterator
The type of the hierarchic iterator.
Definition: CpGrid.hpp:149
cpgrid::Intersection LevelIntersection
The type of the intersection at the levels of the grid.
Definition: CpGrid.hpp:142
cpgrid::Intersection LeafIntersection
The type of the intersection at the leafs of the grid.
Definition: CpGrid.hpp:140
CpGrid Grid
The type that implements the grid.
Definition: CpGrid.hpp:137
Dune::RemoteIndices< ParallelIndexSet > RemoteIndices
The type of the remote indices information.
Definition: CpGridDataTraits.hpp:82
typename CommunicationType::ParallelIndexSet ParallelIndexSet
The type of the parallel index set.
Definition: CpGridDataTraits.hpp:79
Dune::Communication< MPICommunicator > CollectiveCommunication
Definition: CpGridDataTraits.hpp:58
Dune::OwnerOverlapCopyCommunication< int, int > CommunicationType
type of OwnerOverlap communication for cells
Definition: CpGridDataTraits.hpp:76
Dune::Communication< MPICommunicator > Communication
Definition: CpGridDataTraits.hpp:57
Communicator::InterfaceMap InterfaceMap
The type of the map describing communication interfaces.
Definition: CpGridDataTraits.hpp:73
Definition: preprocess.h:56