My Project
Loading...
Searching...
No Matches
CpGrid.hpp
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>
46#include <opm/grid/cpgrid/CpGridDataTraits.hpp>
47#include <opm/grid/cpgrid/OrientedEntityTable.hpp>
49#include <opm/grid/utility/platform_dependent/reenable_warnings.h> // Not really needed it seems, but alas.
50#include "common/GridEnums.hpp"
51#include <opm/grid/utility/OpmWellType.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
89void noNNC_check(Dune::CpGrid&,
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
103void disjointPatches_check(Dune::CpGrid&,
104 const std::vector<std::array<int,3>>&,
105 const std::vector<std::array<int,3>>&);
106
107void lookup_check(const Dune::CpGrid&);
108
109void refine_and_check(const Dune::cpgrid::Geometry<3, 3>&,
110 const std::array<int, 3>&,
111 bool);
112
113void refinePatch_and_check(Dune::CpGrid&,
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
123void check_global_refine(const Dune::CpGrid&,
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>
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
214 using Communication = cpgrid::CpGridDataTraits::Communication;
215 using CollectiveCommunication = cpgrid::CpGridDataTraits::CollectiveCommunication;
216 };
217
219 //
220 // CpGridFamily
221 //
223
225 {
226 typedef CpGridTraits Traits;
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);
248 friend void ::noNNC_check(Dune::CpGrid&,
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);
260 friend void ::disjointPatches_check(Dune::CpGrid&,
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
265 void ::refine_and_check(const Dune::cpgrid::Geometry<3,3>&,
266 const std::array<int,3>&,
267 bool);
268 friend
269 void ::refinePatch_and_check(Dune::CpGrid&,
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
279 void ::check_global_refine(const Dune::CpGrid&,
280 const Dune::CpGrid&);
281
282 public:
283
284 // --- Typedefs ---
285
286
289
290
291 // --- Methods ---
292
293
295 CpGrid();
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
556 Dune::cpgrid::Intersection getParentIntersectionFromLgrBoundaryFace(const Dune::cpgrid::Intersection& intersection) const;
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 {
728 scatterData(data);
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 {
776 scatterData(data);
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 {
814 scatterData(data);
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 {
836 scatterData(data);
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 {
883 scatterData(data);
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 }
1058 void increment()
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 }
1069 void decrement()
1070 {
1071 --iter_;
1072 }
1073 int distanceTo(const CentroidIterator& o)
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
1086 CentroidIterator<0> beginCellCentroids() const;
1087
1089 CentroidIterator<1> beginFaceCentroids() const;
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
1137 using InterfaceMap = cpgrid::CpGridDataTraits::InterfaceMap;
1138
1168
1172
1174 void switchToGlobalView();
1175
1179
1180#if HAVE_MPI
1182 using ParallelIndexSet = cpgrid::CpGridDataTraits::ParallelIndexSet;
1184 using RemoteIndices = cpgrid::CpGridDataTraits::RemoteIndices;
1185
1187 using CommunicationType = cpgrid::CpGridDataTraits::CommunicationType;
1188
1192 const CommunicationType& cellCommunication() const;
1193
1194 ParallelIndexSet& getCellIndexSet();
1195
1196 RemoteIndices& getCellRemoteIndices();
1197
1198 const ParallelIndexSet& getCellIndexSet() const;
1199
1200 const RemoteIndices& getCellRemoteIndices() const;
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
1283#include <opm/grid/cpgrid/Entity.hpp>
1284#include <opm/grid/cpgrid/Iterators.hpp>
1285#include <opm/grid/cpgrid/CpGridData.hpp>
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>
1420 cpgrid::Entity<dim> createEntity(const CpGrid&, int, bool);
1421
1422} // namespace Dune
1423
1424#include <opm/grid/cpgrid/PersistentContainer.hpp>
1425#include <opm/grid/cpgrid/CartesianIndexMapper.hpp>
1426#include "cpgrid/Intersection.hpp"
1427#include "cpgrid/Geometry.hpp"
1428#include "cpgrid/Indexsets.hpp"
1429
1430#endif // OPM_CPGRID_HEADER
An iterator over the centroids of the geometry of the entities.
Definition CpGrid.hpp:1043
CentroidIterator(GeometryIterator iter)
Constructs a new iterator from an iterator over the geometries.
Definition CpGrid.hpp:1050
std::vector< cpgrid::Geometry< 3-codim, 3 > >::const_iterator GeometryIterator
The type of the iterator over the codim geometries.
Definition CpGrid.hpp:1047
[ provides Dune::Grid ]
Definition CpGrid.hpp:238
std::string name() const
Get the grid name.
Definition CpGrid.cpp:636
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.
Definition CpGrid.cpp:1361
void readSintefLegacyFormat(const std::string &grid_prefix)
Read the Sintef legacy grid format ('topogeom').
Definition CpGrid.cpp:1403
unsigned int numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition CpGrid.cpp:976
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...
Definition CpGrid.cpp:1475
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
void globalRefine(int)
global refinement
Definition CpGrid.cpp:933
const Traits::LocalIdSet & localIdSet() const
Access to the LocalIdSet.
Definition CpGrid.cpp:916
CentroidIterator< 0 > beginCellCentroids() const
Get an iterator over the cell centroids positioned at the first one.
Definition CpGrid.cpp:1295
const Traits::GlobalIdSet & globalIdSet() const
Access to the GlobalIdSet.
Definition CpGrid.cpp:911
int faceTag(const Cell2FacesRowIterator &cell_face) const
Get the cartesian tag associated with a face tag.
Definition CpGrid.hpp:1365
void setUniqueBoundaryIds(bool uids)
Set whether we want to have unique boundary ids.
Definition CpGrid.cpp:631
void createCartesian(const std::array< int, 3 > &dims, const std::array< double, 3 > &cellsize, const std::array< int, 3 > &shift={0, 0, 0})
Create a cartesian grid.
Definition CpGrid.cpp:534
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)
Read the Eclipse grid format ('grdecl').
Definition CpGrid.cpp:1448
unsigned int overlapSize(int) const
Size of the overlap on the leaf level.
Definition CpGrid.cpp:954
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
const Vector & faceNormal(int face) const
Get the unit normal of a face.
Definition CpGrid.cpp:1280
int numCellFaces() const
Get the sum of all faces attached to all cells.
Definition CpGrid.cpp:1073
const std::vector< int > & globalCell() const
Retrieve mapping from internal ("compressed") active grid cells to external ("uncompressed") cells.
Definition CpGrid.cpp:614
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 Vector & cellCentroid(int cell) const
Get the coordinates of the center of a cell.
Definition CpGrid.cpp:1290
int maxLevel() const
Return maximum level defined in this grid. Levels are 0 and 1, maxlevel = 1 (not counting leafview),...
Definition CpGrid.cpp:641
const CpGridTraits::Communication & comm() const
Get the collective communication object.
Definition CpGrid.cpp:1001
double faceArea(int face) const
Get the area of a face.
Definition CpGrid.cpp:1270
const Vector & faceCentroid(int face) const
Get the coordinates of the center of a face.
Definition CpGrid.cpp:1275
const Traits::LevelIndexSet & levelIndexSet(int level) const
Access to the LevelIndexSets.
Definition CpGrid.cpp:921
int size(int level, int codim) const
Number of grid entities per level and codim.
Definition CpGrid.cpp:887
const std::array< int, 3 > & logicalCartesianSize() const
The logical cartesian size of the global grid.
Definition CpGrid.cpp:597
int faceVertex(int face, int local_index) const
Get the index identifying a vertex of a face.
Definition CpGrid.cpp:1083
bool loadBalance(int overlapLayers=1, bool useZoltan=true)
Distributes this grid over the available nodes in a distributed machine.
Definition CpGrid.hpp:629
int numVertices() const
Get The number of vertices.
Definition CpGrid.cpp:1022
void getIJK(const int c, std::array< int, 3 > &ijk) const
Extract Cartesian index triplet (i,j,k) of an active cell.
Definition CpGrid.cpp:621
int cellFace(int cell, int local_index) const
Get a specific face of a cell.
Definition CpGrid.cpp:1032
bool uniqueBoundaryIds() const
Is the grid currently using unique boundary ids?
Definition CpGrid.cpp:626
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...
Definition CpGrid.cpp:1482
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
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.
Definition CpGrid.cpp:187
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
int faceCell(int face, int local_index) const
Get the index identifying a cell attached to a face.
Definition CpGrid.cpp:1042
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim and PartitionIteratorType.
void writeSintefLegacyFormat(const std::string &grid_prefix) const
Write the Sintef legacy grid format ('topogeom').
Definition CpGrid.cpp:1413
unsigned int ghostSize(int) const
Size of the ghost cell layer on the leaf level.
Definition CpGrid.cpp:960
cpgrid::Entity< codim > entity(const cpgrid::Entity< codim > &seed) const
given an EntitySeed (or EntityPointer) return an entity object
Definition CpGrid.cpp:944
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 Traits::LeafIndexSet & leafIndexSet() const
Access to the LeafIndexSet.
Definition CpGrid.cpp:928
const std::vector< std::shared_ptr< Dune::cpgrid::CpGridData > > & chooseData() const
Returns either data_ or distributed_data_(if non empty).
Definition CpGrid.cpp:604
Traits::template Codim< codim >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
const InterfaceMap & pointScatterGatherInterface() const
Get an interface for gathering/scattering data attached to points with communication.
Definition CpGrid.cpp:1356
CpGrid()
Default constructor.
Definition CpGrid.cpp:160
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::vector< int > & sortedNumAquiferCells() const
Get sorted active cell indices of numerical aquifer.
Definition CpGrid.cpp:1305
void switchToDistributedView()
Switch to the distributed view.
Definition CpGrid.cpp:1366
CentroidIterator< 1 > beginFaceCentroids() const
Get an iterator over the face centroids positioned at the first one.
Definition CpGrid.cpp:1300
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 cpgrid::OrientedEntityTable< 0, 1 >::row_type cellFaceRow(int cell) const
Get a list of indices identifying all faces of a cell.
Definition CpGrid.cpp:1037
int numCells() const
Get the number of cells.
Definition CpGrid.cpp:1012
const InterfaceMap & cellScatterGatherInterface() const
Get an interface for gathering/scattering data attached to cells with communication.
Definition CpGrid.cpp:1351
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 numFaces() const
Get the number of faces.
Definition CpGrid.cpp:1017
const Vector & vertexPosition(int vertex) const
Get the Position of a vertex.
Definition CpGrid.cpp:1265
double cellCenterDepth(int cell_index) const
Get vertical position of cell center ("zcorn" average).
Definition CpGrid.cpp:1123
void communicate(DataHandle &data, InterfaceType iftype, CommunicationDirection dir, int) const
The new communication interface.
Definition CpGrid.hpp:907
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.
Definition CpGrid.cpp:1285
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
Definition Entity.hpp:65
This class encapsulates geometry for vertices, intersections, and cells.
Definition Geometry.hpp:75
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
Iterator intended to be used as LeafIterator and LevelIterator (no difference due to no adaptivity) f...
Definition Iterators.hpp:60
A class used as a row type for OrientedEntityTable.
Definition OrientedEntityTable.hpp:55
LookUpCartesianData - To search field properties of leaf grid view elements via CartesianIndex (carte...
Definition LookUpData.hh:173
LookUpData class - To search field properties of leaf grid view elements via element/elementIndex.
Definition LookUpData.hh:63
Copyright 2019 Equinor AS.
Definition CartesianIndexMapper.hpp:10
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.cpp:68
Low-level corner-point processing routines and supporting data structures.
face_tag
Connection taxonomy.
Definition preprocess.h:66
@ K_FACE
Connection topologically normal to I-J plane.
Definition preprocess.h:69
@ J_FACE
Connection topologically normal to I-K plane.
Definition preprocess.h:68
@ NNC_FACE
Arbitrary non-neighbouring connection.
Definition preprocess.h:70
@ I_FACE
Connection topologically normal to J-K plane.
Definition preprocess.h:67
Definition CpGrid.hpp:225
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.
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
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
Raw corner-point specification of a particular geological model.
Definition preprocess.h:56