grid.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=2 sw=2 sts=2:
3#ifndef DUNE_POLYHEDRALGRID_GRID_HH
4#define DUNE_POLYHEDRALGRID_GRID_HH
5
6#include <set>
7#include <vector>
8
9// Warning suppression for Dune includes.
11
12//- dune-common includes
13#include <dune/common/version.hh>
14#include <dune/common/parallel/mpihelper.hh>
15
16//- dune-grid includes
17#include <dune/grid/common/grid.hh>
18
19#include <dune/common/parallel/communication.hh>
20
21//- polyhedralgrid includes
29
30// Re-enable warnings.
32
34
36#include <opm/grid/cart_grid.h>
41
42#include <opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp>
43
44namespace Dune
45{
46
47
48 // PolyhedralGridFamily
49 // ------------
50
51 template< int dim, int dimworld, typename coord_t >
53 {
54 struct Traits
55 {
57
58 typedef coord_t ctype;
59
60 // type of data passed to entities, intersections, and iterators
61 // for PolyhedralGrid this is just an empty place holder
62 typedef const Grid* ExtraData;
63
64 typedef int Index ;
65
66 static const int dimension = dim;
67 static const int dimensionworld = dimworld;
68
69 typedef Dune::FieldVector< ctype, dimensionworld > GlobalCoordinate ;
70
75
76 typedef Dune::Intersection< const Grid, LeafIntersectionImpl > LeafIntersection;
77 typedef Dune::Intersection< const Grid, LevelIntersectionImpl > LevelIntersection;
78
79 typedef Dune::IntersectionIterator< const Grid, LeafIntersectionIteratorImpl, LeafIntersectionImpl > LeafIntersectionIterator;
80 typedef Dune::IntersectionIterator< const Grid, LevelIntersectionIteratorImpl, LevelIntersectionImpl > LevelIntersectionIterator;
81
83 typedef Dune::EntityIterator< 0, const Grid, HierarchicIteratorImpl > HierarchicIterator;
84
85 template< int codim >
86 struct Codim
87 {
89 typedef Dune::Geometry< dimension-codim, dimensionworld, const Grid, PolyhedralGridGeometry > Geometry;
90
92 typedef Dune::Geometry< dimension-codim, dimensionworld, const Grid, PolyhedralGridLocalGeometry > LocalGeometry;
93
95 typedef Dune::Entity< codim, dimension, const Grid, PolyhedralGridEntity > Entity;
96
99
100 //typedef Dune::EntitySeed< const Grid, PolyhedralGridEntitySeed< codim, const Grid > > EntitySeed;
102
103 template< PartitionIteratorType pitype >
105 {
107 typedef Dune::EntityIterator< codim, const Grid, LeafIteratorImpl > LeafIterator;
108
110 };
111
114 };
115
118
121
122 typedef Dune::MPIHelper::MPICommunicator MPICommunicator;
123 using Communication = Dune::Communication<MPICommunicator>;
124 using CollectiveCommunication = Dune::Communication<MPICommunicator>;
125
126 template< PartitionIteratorType pitype >
128 {
129 typedef Dune::GridView< PolyhedralGridViewTraits< dim, dimworld, ctype, pitype > > LeafGridView;
130 typedef Dune::GridView< PolyhedralGridViewTraits< dim, dimworld, ctype, pitype > > LevelGridView;
131 };
132
135 };
136 };
137
138
139
140 // PolyhedralGrid
141 // --------------
142
151 template < int dim, int dimworld, typename coord_t >
154 : public GridDefaultImplementation
155 < dim, dimworld, coord_t, PolyhedralGridFamily< dim, dimworld, coord_t > >
157 {
159
160 typedef GridDefaultImplementation
161 < dim, dimworld, coord_t, PolyhedralGridFamily< dim, dimworld, coord_t > > Base;
162
163 public:
165
166 protected:
168 {
169 inline void operator () ( UnstructuredGridType* grdPtr )
170 {
171 destroy_grid( grdPtr );
172 }
173 };
174
175 public:
176 typedef std::unique_ptr< UnstructuredGridType, UnstructuredGridDeleter > UnstructuredGridPtr;
177
179 allocateGrid ( std::size_t nCells, std::size_t nFaces, std::size_t nFaceNodes, std::size_t nCellFaces, std::size_t nNodes )
180 {
181 // Note that we here assign a grid of dimension dimworld in order to obtain global coordinates in the correct dimension
182 UnstructuredGridType *grid = allocate_grid( dimworld, nCells, nFaces, nFaceNodes, nCellFaces, nNodes );
183 if( !grid )
184 DUNE_THROW( GridError, "Unable to allocate grid" );
185 return UnstructuredGridPtr( grid );
186 }
187
188 static void
190 {
191 // get C pointer to UnstructuredGrid
192 UnstructuredGrid* ugPtr = ug.operator ->();
193
194 // compute geometric quantities like cell volume and face normals
195 compute_geometry( ugPtr );
196 }
197
206 typedef typename GridFamily::Traits Traits;
207
214 template< int codim >
215 struct Codim;
216
223 typedef typename Traits::HierarchicIterator HierarchicIterator;
225 typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator;
227 typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator;
228
235 template< PartitionIteratorType pitype >
237 {
238 typedef typename GridFamily::Traits::template Partition< pitype >::LevelGridView LevelGridView;
239 typedef typename GridFamily::Traits::template Partition< pitype >::LeafGridView LeafGridView;
240 };
241
245
259 typedef typename Traits::LeafIndexSet LeafIndexSet;
260
269 typedef typename Traits::LevelIndexSet LevelIndexSet;
270
281 typedef typename Traits::GlobalIdSet GlobalIdSet;
282
298 typedef typename Traits::LocalIdSet LocalIdSet;
299
306 typedef typename Traits::ctype ctype;
307
309 using Communication = typename Traits::Communication;
311
312 typedef typename Traits :: GlobalCoordinate GlobalCoordinate;
313
324 explicit PolyhedralGrid (const Opm::EclipseGrid& inputGrid,
325 const std::vector<double>& poreVolumes = std::vector<double>{},
326 const bool edge_conformal = false)
327 : gridPtr_ { createGrid(inputGrid, poreVolumes, static_cast<int>(edge_conformal)) }
328 , grid_ { *gridPtr_ }
329 , comm_ { MPIHelper::getCommunicator() }
330 , leafIndexSet_ { *this }
331 , globalIdSet_ { *this }
332 , localIdSet_ { *this }
333 , nBndSegments_ { 0 }
334 {
335 init();
336 }
337
343 explicit PolyhedralGrid ( const std::vector< int >& n,
344 const std::vector< double >& dx )
345 : gridPtr_( createGrid( n, dx ) ),
346 grid_( *gridPtr_ ),
347 comm_( MPIHelper::getCommunicator()),
348 leafIndexSet_( *this ),
349 globalIdSet_( *this ),
350 localIdSet_( *this ),
351 nBndSegments_( 0 )
352 {
353 init();
354 }
355
362 explicit PolyhedralGrid ( UnstructuredGridPtr &&gridPtr )
363 : gridPtr_( std::move( gridPtr ) ),
364 grid_( *gridPtr_ ),
365 comm_( MPIHelper::getCommunicator() ),
366 leafIndexSet_( *this ),
367 globalIdSet_( *this ),
368 localIdSet_( *this ),
369 nBndSegments_( 0 )
370 {
371 init();
372 }
373
381 explicit PolyhedralGrid ( const UnstructuredGridType& grid )
382 : gridPtr_(),
383 grid_( grid ),
384 comm_( MPIHelper::getCommunicator() ),
385 leafIndexSet_( *this ),
386 globalIdSet_( *this ),
387 localIdSet_( *this ),
388 nBndSegments_( 0 )
389 {
390 init();
391 }
392
397 operator const UnstructuredGridType& () const { return grid_; }
398
411 int maxLevel () const
412 {
413 return 0;
414 }
415
424 int size ( int /* level */, int codim ) const
425 {
426 return size( codim );
427 }
428
435 int size ( int codim ) const
436 {
437 if( codim == 0 )
438 {
439 return grid_.number_of_cells;
440 }
441 else if ( codim == 1 )
442 {
443 return grid_.number_of_faces;
444 }
445 else if ( codim == dim )
446 {
447 return grid_.number_of_nodes;
448 }
449 else
450 {
451 std::cerr << "Warning: codimension " << codim << " not available in PolyhedralGrid" << std::endl;
452 return 0;
453 }
454 }
455
464 int size ( int /* level */, GeometryType type ) const
465 {
466 return size( dim - type.dim() );
467 }
468
473 int size ( GeometryType type ) const
474 {
475 return size( dim - type.dim() );
476 }
477
484 size_t numBoundarySegments () const
485 {
486 return nBndSegments_;
487 }
490 template< int codim >
492 {
493 return leafbegin< codim, All_Partition >();
494 }
495
496 template< int codim >
498 {
499 return leafend< codim, All_Partition >();
500 }
501
502 template< int codim, PartitionIteratorType pitype >
503 typename Codim< codim >::template Partition< pitype >::LeafIterator
504 leafbegin () const
505 {
506 typedef typename Traits::template Codim< codim >::template Partition< pitype >::LeafIteratorImpl Impl;
507 return Impl( extraData(), true );
508 }
509
510 template< int codim, PartitionIteratorType pitype >
511 typename Codim< codim >::template Partition< pitype >::LeafIterator
512 leafend () const
513 {
514 typedef typename Traits::template Codim< codim >::template Partition< pitype >::LeafIteratorImpl Impl;
515 return Impl( extraData(), false );
516 }
517
518 template< int codim >
519 typename Codim< codim >::LevelIterator lbegin ( const int /* level */ ) const
520 {
521 return leafbegin< codim, All_Partition >();
522 }
523
524 template< int codim >
525 typename Codim< codim >::LevelIterator lend ( const int /* level */ ) const
526 {
527 return leafend< codim, All_Partition >();
528 }
529
530 template< int codim, PartitionIteratorType pitype >
531 typename Codim< codim >::template Partition< pitype >::LevelIterator
532 lbegin ( const int /* level */ ) const
533 {
534 return leafbegin< codim, pitype > ();
535 }
536
537 template< int codim, PartitionIteratorType pitype >
538 typename Codim< codim >::template Partition< pitype >::LevelIterator
539 lend ( const int /* level */ ) const
540 {
541 return leafend< codim, pitype > ();
542 }
543
544 const GlobalIdSet &globalIdSet () const
545 {
546 return globalIdSet_;
547 }
548
549 const LocalIdSet &localIdSet () const
550 {
551 return localIdSet_;
552 }
553
554 const LevelIndexSet &levelIndexSet ( int /* level */ ) const
555 {
556 return leafIndexSet();
557 }
558
560 {
561 return leafIndexSet_;
562 }
563
564 void globalRefine ( int /* refCount */ )
565 {
566 }
567
568 bool mark ( int /* refCount */, const typename Codim< 0 >::Entity& /* entity */ )
569 {
570 return false;
571 }
572
573 int getMark ( const typename Codim< 0 >::Entity& /* entity */) const
574 {
575 return false;
576 }
577
579 bool preAdapt ()
580 {
581 return false;
582 }
583
585 bool adapt ()
586 {
587 return false ;
588 }
589
594 template< class DataHandle >
595 bool adapt ( DataHandle & )
596 {
597 return false;
598 }
599
601 void postAdapt ()
602 {
603 }
604
612 int overlapSize ( int /* codim */) const
613 {
614 return 0;
615 }
616
621 int ghostSize( int codim ) const
622 {
623 return (codim == 0 ) ? 1 : 0;
624 }
625
631 int overlapSize ( int /* level */, int /* codim */ ) const
632 {
633 return 0;
634 }
635
641 int ghostSize ( int /* level */, int codim ) const
642 {
643 return ghostSize( codim );
644 }
645
659 template< class DataHandle>
660 void communicate ( DataHandle& /* dataHandle */,
661 InterfaceType /* interface */,
662 CommunicationDirection /* direction */,
663 int /* level */ ) const
664 {
665 OPM_THROW(std::runtime_error, "communicate not implemented for polyhedreal grid!");
666 }
667
680 template< class DataHandle>
681 void communicate ( DataHandle& /* dataHandle */,
682 InterfaceType /* interface */,
683 CommunicationDirection /* direction */ ) const
684 {
685 OPM_THROW(std::runtime_error, "communicate not implemented for polyhedreal grid!");
686 }
687
690 {
691 OPM_THROW(std::runtime_error, "switch to global view not implemented for polyhedreal grid!");
692 }
693
696 {
697 OPM_THROW(std::runtime_error, "switch to distributed view not implemented for polyhedreal grid!");
698 }
699
708 const CommunicationType &comm () const
709 {
710 return comm_;
711 }
712
713 // data handle interface different between geo and interface
714
725 {
726 return false ;
727 }
728
744 template< class DataHandle, class Data >
745 bool loadBalance ( CommDataHandleIF< DataHandle, Data >& /* datahandle */ )
746 {
747 return false;
748 }
749
764 template< class DofManager >
765 bool loadBalance ( DofManager& /* dofManager */ )
766 {
767 return false;
768 }
769
771 template< PartitionIteratorType pitype >
772 typename Partition< pitype >::LevelGridView levelGridView ( int /* level */ ) const
773 {
774 typedef typename Partition< pitype >::LevelGridView View;
775 typedef typename View::GridViewImp ViewImp;
776 return View( ViewImp( *this ) );
777 }
778
780 template< PartitionIteratorType pitype >
782 {
783 typedef typename Traits::template Partition< pitype >::LeafGridView View;
784 typedef typename View::GridViewImp ViewImp;
785 return View( ViewImp( *this ) );
786 }
787
789 LevelGridView levelGridView ( int /* level */ ) const
790 {
791 typedef typename LevelGridView::GridViewImp ViewImp;
792 return LevelGridView( ViewImp( *this ) );
793 }
794
797 {
798 typedef typename LeafGridView::GridViewImp ViewImp;
799 return LeafGridView( ViewImp( *this ) );
800 }
801
803 template< class EntitySeed >
805 entityPointer ( const EntitySeed &seed ) const
806 {
807 typedef typename Traits::template Codim< EntitySeed::codimension >::EntityPointer EntityPointer;
808 typedef typename Traits::template Codim< EntitySeed::codimension >::EntityPointerImpl EntityPointerImpl;
809 typedef typename Traits::template Codim< EntitySeed::codimension >::EntityImpl EntityImpl;
810 return EntityPointer( EntityPointerImpl( EntityImpl( extraData(), seed ) ) );
811 }
812
814 template< class EntitySeed >
815 typename Traits::template Codim< EntitySeed::codimension >::Entity
816 entity ( const EntitySeed &seed ) const
817 {
818 typedef typename Traits::template Codim< EntitySeed::codimension >::EntityImpl EntityImpl;
819 return EntityImpl( extraData(), seed );
820 }
821
835 void update ()
836 {
837 }
838
841 const std::array<int, 3>& logicalCartesianSize() const
842 {
843 return cartDims_;
844 }
845
846 const int* globalCell() const
847 {
848 assert( grid_.global_cell != 0 );
849 return grid_.global_cell;
850 }
851
852 const int* globalCellPtr() const
853 {
854 return grid_.global_cell;
855 }
856
857 void getIJK(const int c, std::array<int,3>& ijk) const
858 {
859 int gc = globalCell()[c];
860 ijk[0] = gc % logicalCartesianSize()[0]; gc /= logicalCartesianSize()[0];
861 ijk[1] = gc % logicalCartesianSize()[1];
862 ijk[2] = gc / logicalCartesianSize()[1];
863 }
864
869
870
879 template<class DataHandle>
880 void scatterData([[maybe_unused]] DataHandle& handle) const
881 {
882 OPM_THROW(std::runtime_error, "ScatterData not implemented for polyhedral grid!");
883 }
884
885 protected:
887 createGrid(const Opm::EclipseGrid& inputGrid,
888 const std::vector<double>& poreVolumes,
889 const bool edge_conformal) const
890 {
891 grdecl g{};
892
893 g.dims[0] = inputGrid.getNX();
894 g.dims[1] = inputGrid.getNY();
895 g.dims[2] = inputGrid.getNZ();
896
897 std::vector<double> coord = inputGrid.getCOORD( );
898 std::vector<double> zcorn = inputGrid.getZCORN( );
899 std::vector<int> actnum = inputGrid.getACTNUM( );
900
901 g.coord = coord.data();
902 g.zcorn = zcorn.data();
903 g.actnum = actnum.data();
904
905 const double z_tolerance = inputGrid.isPinchActive() ? inputGrid.getPinchThresholdThickness() : 0.0;
906
907 if (!poreVolumes.empty() && (inputGrid.getMinpvMode() != Opm::MinpvMode::Inactive))
908 {
909 Opm::MinpvProcessor mp(g.dims[0], g.dims[1], g.dims[2]);
910 const std::vector<double>& minpvv = inputGrid.getMinpvVector();
911 // Currently the pinchProcessor is not used and only opmfil is supported
912 // The polyhedralgrid only only supports the opmfil option
913 //bool opmfil = inputGrid.getMinpvMode() == Opm::MinpvMode::OpmFIL;
914 bool opmfil = true;
915 const size_t cartGridSize = g.dims[0] * g.dims[1] * g.dims[2];
916 std::vector<double> thickness(cartGridSize);
917 for (size_t i = 0; i < cartGridSize; ++i) {
918 thickness[i] = inputGrid.getCellThickness(i);
919 }
920 mp.process(thickness, z_tolerance, inputGrid.getPinchMaxEmptyGap() , poreVolumes,
921 minpvv, actnum, opmfil, zcorn.data());
922 }
923
924 /*
925 if (!poreVolumes.empty() && (inputGrid.getMinpvMode() != Opm::MinpvMode::Inactive)) {
926 Opm::MinpvProcessor mp(g.dims[0], g.dims[1], g.dims[2]);
927 const double minpv_value = inputGrid.getMinpvValue();
928 // Currently the pinchProcessor is not used and only opmfil is supported
929 //bool opmfil = inputGrid.getMinpvMode() == Opm::MinpvMode::OpmFIL;
930 bool opmfil = true;
931 mp.process(poreVolumes, minpv_value, actnum, opmfil, zcorn.data());
932 }
933 */
934
936 (&g, z_tolerance, static_cast<int>(edge_conformal));
937
938 if (cgrid == nullptr) {
939 OPM_THROW(std::runtime_error, "Failed to construct grid.");
940 }
941
942 return cgrid;
943 }
944
945 UnstructuredGridType* createGrid( const std::vector< int >& n, const std::vector< double >& dx ) const
946 {
947 UnstructuredGridType* cgrid = nullptr ;
948 assert( int(n.size()) == dim );
949 if( dim == 2 )
950 {
951 cgrid = create_grid_cart2d( n[ 0 ], n[ 1 ], dx[ 0 ], dx[ 1 ] );
952 }
953 else if ( dim == 3 )
954 {
955 cgrid = create_grid_hexa3d( n[ 0 ], n[ 1 ], n[ 2 ], dx[ 0 ], dx[ 1 ], dx[ 2 ] );
956 }
957
958 //print_grid( cgrid );
959 if (!cgrid) {
960 OPM_THROW(std::runtime_error, "Failed to construct grid.");
961 }
962 return cgrid;
963 }
964
965 public:
966 typedef typename Traits :: ExtraData ExtraData;
967 ExtraData extraData () const { return this; }
968
969 template <class EntitySeed>
970 int corners( const EntitySeed& seed ) const
971 {
972 const int codim = EntitySeed :: codimension;
973 const int index = seed.index();
974 if (codim==0)
975 return cellVertices_[ index ].size();
976 if (codim==1)
977 return grid_.face_nodepos[ index+1 ] - grid_.face_nodepos[ index ];
978 if (codim==dim)
979 return 1;
980 return 0;
981 }
982
983 template <class EntitySeed>
985 corner ( const EntitySeed& seed, const int i ) const
986 {
987 const int codim = EntitySeed :: codimension;
988 if (codim==0)
989 {
990 const int coordIndex = GlobalCoordinate :: dimension * cellVertices_[ seed.index() ][ i ];
991 return copyToGlobalCoordinate( grid_.node_coordinates + coordIndex );
992 }
993 if (codim==1)
994 {
995 // for faces we need to swap vertices in 3d since in UnstructuredGrid
996 // those are ordered counter clockwise, for 2d this does not matter
997 // TODO: Improve this for performance reasons
998 const int crners = corners( seed );
999 const int crner = (crners == 4 && EntitySeed :: dimension == 3 && i > 1 ) ? 5 - i : i;
1000 const int faceVertex = grid_.face_nodes[ grid_.face_nodepos[seed.index() ] + crner ];
1001 return copyToGlobalCoordinate( grid_.node_coordinates + GlobalCoordinate :: dimension * faceVertex );
1002 }
1003 if (codim==dim)
1004 {
1005 const int coordIndex = GlobalCoordinate :: dimension * seed.index();
1006 return copyToGlobalCoordinate( grid_.node_coordinates + coordIndex );
1007 }
1008 return GlobalCoordinate( 0 );
1009 }
1010
1011 template <class EntitySeed>
1012 int subEntities( const EntitySeed& seed, const int codim ) const
1013 {
1014 const int index = seed.index();
1015 if( seed.codimension == 0 )
1016 {
1017 if (codim==0)
1018 return 1;
1019 if (codim==1)
1020 return grid_.cell_facepos[ index+1 ] - grid_.cell_facepos[ index ];
1021 if (codim==dim)
1022 return cellVertices_[ index ].size();
1023 }
1024 else if( seed.codimension == 1 )
1025 {
1026 if (codim==1)
1027 return 1;
1028 if (codim==dim)
1029 return grid_.face_nodepos[ index+1 ] - grid_.face_nodepos[ index ];
1030 }
1031 else if ( seed.codimension == dim )
1032 {
1033 return 1 ;
1034 }
1035
1036 return 0;
1037 }
1038
1039 template <int codim, class EntitySeedArg >
1040 typename Codim<codim>::EntitySeed
1041 subEntitySeed( const EntitySeedArg& baseSeed, const int i ) const
1042 {
1043 assert( codim >= EntitySeedArg::codimension );
1044 assert( i>= 0 && i<subEntities( baseSeed, codim ) );
1045 typedef typename Codim<codim>::EntitySeed EntitySeed;
1046
1047 // if codim equals entity seed codim just return same entity seed.
1048 if( codim == EntitySeedArg::codimension )
1049 {
1050 return EntitySeed( baseSeed.index() );
1051 }
1052
1053 if( EntitySeedArg::codimension == 0 )
1054 {
1055 if ( codim == 1 )
1056 {
1057 return EntitySeed( grid_.cell_faces[ grid_.cell_facepos[ baseSeed.index() ] + i ] );
1058 }
1059 else if ( codim == dim )
1060 {
1061 return EntitySeed( cellVertices_[ baseSeed.index() ][ i ] );
1062 }
1063 }
1064 else if ( EntitySeedArg::codimension == 1 && codim == dim )
1065 {
1066 return EntitySeed( grid_.face_nodes[ grid_.face_nodepos[ baseSeed.index() + i ] ]);
1067 }
1068
1069 DUNE_THROW(NotImplemented,"codimension not available");
1070 return EntitySeed();
1071 }
1072
1073 template <int codim>
1074 typename Codim<codim>::EntitySeed
1075 subEntitySeed( const typename Codim<1>::EntitySeed& faceSeed, const int i ) const
1076 {
1077 assert( i>= 0 && i<subEntities( faceSeed, codim ) );
1078 typedef typename Codim<codim>::EntitySeed EntitySeed;
1079 if ( codim == 1 )
1080 {
1081 return EntitySeed( faceSeed.index() );
1082 }
1083 else if ( codim == dim )
1084 {
1085 return EntitySeed( grid_.face_nodes[ grid_.face_nodepos[ faceSeed.index() ] + i ] );
1086 }
1087 else
1088 {
1089 DUNE_THROW(NotImplemented,"codimension not available");
1090 }
1091 }
1092
1093 bool hasBoundaryIntersections(const typename Codim<0>::EntitySeed& seed ) const
1094 {
1095 const int faces = subEntities( seed, 1 );
1096 for( int f=0; f<faces; ++f )
1097 {
1098 const auto faceSeed = this->template subEntitySeed<1>( seed, f );
1099 if( isBoundaryFace( faceSeed ) )
1100 return true;
1101 }
1102 return false;
1103 }
1104
1105 bool isBoundaryFace(const int face ) const
1106 {
1107 assert( face >= 0 && face < grid_.number_of_faces );
1108 const int facePos = 2 * face;
1109 return ((grid_.face_cells[ facePos ] < 0) || (grid_.face_cells[ facePos+1 ] < 0));
1110 }
1111
1112 bool isBoundaryFace(const typename Codim<1>::EntitySeed& faceSeed ) const
1113 {
1114 assert( faceSeed.isValid() );
1115 return isBoundaryFace( faceSeed.index() );
1116 }
1117
1118 int boundarySegmentIndex(const typename Codim<0>::EntitySeed& seed, const int face ) const
1119 {
1120 const auto faceSeed = this->template subEntitySeed<1>( seed, face );
1121 assert( faceSeed.isValid() );
1122 const int facePos = 2 * faceSeed.index();
1123 const int idx = std::min( grid_.face_cells[ facePos ], grid_.face_cells[ facePos+1 ]);
1124 // check that this is actually the boundary
1125 assert( idx < 0 );
1126 return -(idx+1); // +1 to include 0 boundary segment index
1127 }
1128
1129 const std::vector< GeometryType > &geomTypes ( const unsigned int codim ) const
1130 {
1131 static std::vector< GeometryType > emptyDummy;
1132 if (codim < geomTypes_.size())
1133 {
1134 return geomTypes_[codim];
1135 }
1136
1137 return emptyDummy;
1138 }
1139
1140 template < class Seed >
1141 GeometryType geometryType( const Seed& seed ) const
1142 {
1143 if( Seed::codimension == 0 )
1144 {
1145 assert(!geomTypes( Seed::codimension ).empty());
1146 return geomTypes( Seed::codimension )[ 0 ];
1147 }
1148 else
1149 {
1150 // 3d faces
1151 if( dim == 3 && Seed::codimension == 1 )
1152 {
1153 GeometryType face;
1154 const int nVx = corners( seed );
1155 if( nVx == 4 ) // quad face
1156 face = Dune::GeometryTypes::cube(2);
1157 else if( nVx == 3 ) // triangle face
1158 face = Dune::GeometryTypes::simplex(2);
1159 else // polygonal face
1160 face = Dune::GeometryTypes::none(2);
1161 return face;
1162 }
1163
1164 // for codim 2 and codim 3 there is only one option
1165 assert(!geomTypes( Seed::codimension ).empty());
1166 return geomTypes( Seed::codimension )[ 0 ];
1167 }
1168 }
1169
1170 int indexInInside( const typename Codim<0>::EntitySeed& seed, const int i ) const
1171 {
1172 return ( grid_.cell_facetag ) ? cartesianIndexInInside( seed, i ) : i;
1173 }
1174
1175 int cartesianIndexInInside( const typename Codim<0>::EntitySeed& seed, const int i ) const
1176 {
1177 assert( i>= 0 && i<subEntities( seed, 1 ) );
1178 return grid_.cell_facetag[ grid_.cell_facepos[ seed.index() ] + i ] ;
1179 }
1180
1181 typename Codim<0>::EntitySeed
1182 neighbor( const typename Codim<0>::EntitySeed& seed, const int i ) const
1183 {
1184 const int face = this->template subEntitySeed<1>( seed, i ).index();
1185 int nb = grid_.face_cells[ 2 * face ];
1186 if( nb == seed.index() )
1187 {
1188 nb = grid_.face_cells[ 2 * face + 1 ];
1189 }
1190
1191 typedef typename Codim<0>::EntitySeed EntitySeed;
1192 return EntitySeed( nb );
1193 }
1194
1195 int
1196 indexInOutside( const typename Codim<0>::EntitySeed& seed, const int i ) const
1197 {
1198 if( grid_.cell_facetag )
1199 {
1200 // if cell_facetag is present we assume pseudo Cartesian corner point case
1201 const int in_inside = cartesianIndexInInside( seed, i );
1202 return in_inside + ((in_inside % 2) ? -1 : 1);
1203 }
1204 else
1205 {
1206 typedef typename Codim<0>::EntitySeed EntitySeed;
1207 EntitySeed nb = neighbor( seed, i );
1208 const int faces = subEntities( seed, 1 );
1209 for( int face = 0; face<faces; ++ face )
1210 {
1211 if( neighbor( nb, face ).equals(seed) )
1212 {
1213 return indexInInside( nb, face );
1214 }
1215 }
1216 DUNE_THROW(InvalidStateException,"inverse intersection not found");
1217 return -1;
1218 }
1219 }
1220
1221 template <class EntitySeed>
1223 outerNormal( const EntitySeed& seed, const int i ) const
1224 {
1225 const int face = this->template subEntitySeed<1>( seed, i ).index();
1226 const int normalIdx = face * GlobalCoordinate :: dimension ;
1228 const int nb = grid_.face_cells[ 2*face ];
1229 if( nb != seed.index() )
1230 {
1231 normal *= -1.0;
1232 }
1233 return normal;
1234 }
1235
1236 template <class EntitySeed>
1238 unitOuterNormal( const EntitySeed& seed, const int i ) const
1239 {
1240 const int face = this->template subEntitySeed<1>( seed, i ).index();
1241 if( seed.index() == grid_.face_cells[ 2*face ] )
1242 {
1243 return unitOuterNormals_[ face ];
1244 }
1245 else
1246 {
1247 GlobalCoordinate normal = unitOuterNormals_[ face ];
1248 normal *= -1.0;
1249 return normal;
1250 }
1251 }
1252
1253 template <class EntitySeed>
1254 GlobalCoordinate centroids( const EntitySeed& seed ) const
1255 {
1256 if( ! seed.isValid() )
1257 return GlobalCoordinate( 0 );
1258
1259 const int index = GlobalCoordinate :: dimension * seed.index();
1260 const int codim = EntitySeed::codimension;
1261 assert( index >= 0 && index < size( codim ) * GlobalCoordinate :: dimension );
1262
1263 if( codim == 0 )
1264 {
1266 }
1267 else if ( codim == 1 )
1268 {
1270 }
1271 else if( codim == dim )
1272 {
1274 }
1275 else
1276 {
1277 DUNE_THROW(InvalidStateException,"codimension not implemented");
1278 return GlobalCoordinate( 0 );
1279 }
1280 }
1281
1282 GlobalCoordinate copyToGlobalCoordinate( const double* coords ) const
1283 {
1284 GlobalCoordinate coordinate;
1285 for( int i=0; i<GlobalCoordinate::dimension; ++i )
1286 {
1287 coordinate[ i ] = coords[ i ];
1288 }
1289 return coordinate;
1290 }
1291
1292 template <class EntitySeed>
1293 double volumes( const EntitySeed& seed ) const
1294 {
1295 static const int codim = EntitySeed::codimension;
1296 if( codim == dim || ! seed.isValid() )
1297 {
1298 return 1.0;
1299 }
1300 else
1301 {
1302 assert( seed.isValid() );
1303
1304 if( codim == 0 )
1305 {
1306 return grid_.cell_volumes[ seed.index() ];
1307 }
1308 else if ( codim == 1 )
1309 {
1310 return grid_.face_areas[ seed.index() ];
1311 }
1312 else
1313 {
1314 DUNE_THROW(InvalidStateException,"codimension not implemented");
1315 return 0.0;
1316 }
1317 }
1318 }
1319
1320 protected:
1321 void init ()
1322 {
1323 // copy Cartesian dimensions
1324 for( int i=0; i<3; ++i )
1325 {
1326 cartDims_[ i ] = grid_.cartdims[ i ];
1327 }
1328
1329 // setup list of cell vertices
1330 const int numCells = size( 0 );
1331
1332 cellVertices_.resize( numCells );
1333
1334 // sort vertices such that they comply with the dune reference cube
1335 if( grid_.cell_facetag )
1336 {
1337 typedef std::array<int, 3> KeyType;
1338 std::map< const KeyType, const int > vertexFaceTags;
1339 const int vertexFacePattern [8][3] = {
1340 { 0, 2, 4 }, // vertex 0
1341 { 1, 2, 4 }, // vertex 1
1342 { 0, 3, 4 }, // vertex 2
1343 { 1, 3, 4 }, // vertex 3
1344 { 0, 2, 5 }, // vertex 4
1345 { 1, 2, 5 }, // vertex 5
1346 { 0, 3, 5 }, // vertex 6
1347 { 1, 3, 5 } // vertex 7
1348 };
1349
1350 for( int i=0; i<8; ++i )
1351 {
1352 KeyType key; key.fill( 4 ); // default is 4 which is the first z coord (for the 2d case)
1353 for( int j=0; j<dim; ++j )
1354 {
1355 key[ j ] = vertexFacePattern[ i ][ j ];
1356 }
1357
1358 vertexFaceTags.insert( std::make_pair( key, i ) );
1359 }
1360
1361 for (int c = 0; c < numCells; ++c)
1362 {
1363 if( dim == 2 )
1364 {
1365 // for 2d Cartesian grids the face ordering is wrong
1366 int f = grid_.cell_facepos[ c ];
1367 std::swap( grid_.cell_faces[ f+1 ], grid_.cell_faces[ f+2 ] );
1368 std::swap( grid_.cell_facetag[ f+1 ], grid_.cell_facetag[ f+2 ] );
1369 }
1370
1371 typedef std::map<int,int> vertexmap_t;
1372 typedef typename vertexmap_t :: iterator iterator;
1373
1374 std::vector< vertexmap_t > cell_pts( dim*2 );
1375
1376 for (unsigned hf = grid_.cell_facepos[ c ]; hf < grid_.cell_facepos[c+1]; ++hf)
1377 {
1378 const int f = grid_.cell_faces[ hf ];
1379 const int faceTag = grid_.cell_facetag[ hf ];
1380
1381 for (unsigned nodepos = grid_.face_nodepos[f]; nodepos < grid_.face_nodepos[f+1]; ++nodepos )
1382 {
1383 const int node = grid_.face_nodes[ nodepos ];
1384 iterator it = cell_pts[ faceTag ].find( node );
1385 if( it == cell_pts[ faceTag ].end() )
1386 {
1387 cell_pts[ faceTag ].insert( std::make_pair( node, 1 ) );
1388 }
1389 else
1390 {
1391 // increase vertex reference counter
1392 (*it).second++;
1393 }
1394 }
1395 }
1396
1397 typedef std::map< int, std::set<int> > vertexlist_t;
1398 vertexlist_t vertexList;
1399
1400 for( int faceTag = 0; faceTag<dim*2; ++faceTag )
1401 {
1402 for( iterator it = cell_pts[ faceTag ].begin(),
1403 end = cell_pts[ faceTag ].end(); it != end; ++it )
1404 {
1405
1406 // only consider vertices with one appearance
1407 if( (*it).second == 1 )
1408 {
1409 vertexList[ (*it).first ].insert( faceTag );
1410 }
1411 }
1412 }
1413
1414 assert( int(vertexList.size()) == ( dim == 2 ? 4 : 8) );
1415
1416 cellVertices_[ c ].resize( vertexList.size() );
1417 for( auto it = vertexList.begin(), end = vertexList.end(); it != end; ++it )
1418 {
1419 assert( (*it).second.size() == dim );
1420 KeyType key; key.fill( 4 ); // fill with 4 which is the first z coord
1421
1422 std::ranges::copy(it->second, key.begin());
1423 auto vx = vertexFaceTags.find( key );
1424 assert( vx != vertexFaceTags.end() );
1425 if( vx != vertexFaceTags.end() )
1426 {
1427 if( (*vx).second >= int(cellVertices_[ c ].size()) )
1428 cellVertices_[ c ].resize( (*vx).second+1 );
1429 // store node number on correct local position
1430 cellVertices_[ c ][ (*vx).second ] = (*it).first ;
1431 }
1432 }
1433 }
1434
1435 // if face_tag is available we assume that the elements follow a cube-like structure
1436 geomTypes_.resize(dim + 1);
1437 GeometryType tmp;
1438 for (int codim = 0; codim <= dim; ++codim)
1439 {
1440 tmp = Dune::GeometryTypes::cube(dim - codim);
1441 geomTypes_[codim].push_back(tmp);
1442 }
1443 }
1444 else // if ( grid_.cell_facetag )
1445 {
1446 int maxVx = 0 ;
1447 int minVx = std::numeric_limits<int>::max();
1448
1449 for (int c = 0; c < numCells; ++c)
1450 {
1451 std::set<int> cell_pts;
1452 for (unsigned hf = grid_.cell_facepos[ c ]; hf < grid_.cell_facepos[c+1]; ++hf)
1453 {
1454 int f = grid_.cell_faces[ hf ];
1455 const int* fnbeg = grid_.face_nodes + grid_.face_nodepos[f];
1456 const int* fnend = grid_.face_nodes + grid_.face_nodepos[f+1];
1457 cell_pts.insert(fnbeg, fnend);
1458 }
1459
1460 cellVertices_[ c ].resize( cell_pts.size() );
1461 std::ranges::copy(cell_pts, cellVertices_[c].begin());
1462 maxVx = std::max( maxVx, int( cell_pts.size() ) );
1463 minVx = std::min( minVx, int( cell_pts.size() ) );
1464 }
1465
1466 if( minVx == maxVx && maxVx == 4 )
1467 {
1468 for (int c = 0; c < numCells; ++c)
1469 {
1470 assert( cellVertices_[ c ].size() == 4 );
1471 GlobalCoordinate center( 0 );
1472 GlobalCoordinate p[ dim+1 ];
1473 for( int i=0; i<dim+1; ++i )
1474 {
1475 const int vertex = cellVertices_[ c ][ i ];
1476
1477 for( int d=0; d<dim; ++d )
1478 {
1479 center[ d ] += grid_.node_coordinates[ vertex*dim + d ];
1480 p[ i ][ d ] = grid_.node_coordinates[ vertex*dim + d ];
1481 }
1482 }
1483 center *= 0.25;
1484 for( int d=0; d<dim; ++d )
1485 {
1486 grid_.cell_centroids[ c*dim + d ] = center[ d ];
1487 }
1488
1489 Dune::GeometryType simplex;
1490 simplex = Dune::GeometryTypes::simplex(dim);
1491
1492 typedef Dune::AffineGeometry< ctype, dim, dimworld> AffineGeometryType;
1493 AffineGeometryType geometry( simplex, p );
1494 grid_.cell_volumes[ c ] = geometry.volume();
1495 }
1496 }
1497
1498 // check face normals
1499 {
1500 const int faces = grid_.number_of_faces;
1501 for( int face = 0 ; face < faces; ++face )
1502 {
1503 const int a = grid_.face_cells[ 2*face ];
1504 const int b = grid_.face_cells[ 2*face + 1 ];
1505
1506 assert( a >=0 || b >=0 );
1507
1508 if( grid_.face_areas[ face ] < 0 )
1509 std::abort();
1510
1511 GlobalCoordinate centerDiff( 0 );
1512 if( b >= 0 )
1513 {
1514 for( int d=0; d<dimworld; ++d )
1515 {
1516 centerDiff[ d ] = grid_.cell_centroids[ b*dimworld + d ];
1517 }
1518 }
1519 else
1520 {
1521 for( int d=0; d<dimworld; ++d )
1522 {
1523 centerDiff[ d ] = grid_.face_centroids[ face*dimworld + d ];
1524 }
1525 }
1526
1527 if( a >= 0 )
1528 {
1529 for( int d=0; d<dimworld; ++d )
1530 {
1531 centerDiff[ d ] -= grid_.cell_centroids[ a*dimworld + d ];
1532 }
1533 }
1534 else
1535 {
1536 for( int d=0; d<dimworld; ++d )
1537 {
1538 centerDiff[ d ] -= grid_.face_centroids[ face*dimworld + d ];
1539 }
1540 }
1541
1542 GlobalCoordinate normal( 0 );
1543 for( int d=0; d<dimworld; ++d )
1544 {
1545 normal[ d ] = grid_.face_normals[ face*dimworld + d ];
1546 }
1547
1548 if( centerDiff.two_norm() < 1e-10 )
1549 std::abort();
1550
1551 // if diff and normal point in different direction, flip faces
1552 if( centerDiff * normal < 0 )
1553 {
1554 grid_.face_cells[ 2*face ] = b;
1555 grid_.face_cells[ 2*face + 1 ] = a;
1556 }
1557 }
1558 }
1559
1560 bool allSimplex = true ;
1561 bool allCube = true ;
1562
1563 for (int c = 0; c < numCells; ++c)
1564 {
1565 const int nVx = cellVertices_[ c ].size();
1566 if( nVx != 4 )
1567 {
1568 allSimplex = false;
1569 }
1570
1571 if( nVx != 8 )
1572 {
1573 allCube = false;
1574 }
1575 }
1576 // Propogate the cell geometry type to all codimensions
1577 geomTypes_.resize(dim + 1);
1578 GeometryType tmp;
1579 for (int codim = 0; codim <= dim; ++codim)
1580 {
1581 if( allSimplex )
1582 {
1583 tmp = Dune::GeometryTypes::simplex(dim - codim);
1584 geomTypes_[ codim ].push_back( tmp );
1585 }
1586 else if ( allCube )
1587 {
1588 tmp = Dune::GeometryTypes::cube(dim - codim);
1589 geomTypes_[ codim ].push_back( tmp );
1590 }
1591 else
1592 {
1593 tmp = Dune::GeometryTypes::none(dim - codim);
1594 geomTypes_[ codim ].push_back( tmp );
1595 }
1596 }
1597
1598 } // end else of ( grid_.cell_facetag )
1599
1600 nBndSegments_ = 0;
1602 for( int face = 0; face < grid_.number_of_faces; ++face )
1603 {
1604 const int normalIdx = face * GlobalCoordinate :: dimension ;
1606 normal /= normal.two_norm();
1607 unitOuterNormals_[ face ] = normal;
1608
1609 if( isBoundaryFace( face ) )
1610 {
1611 // increase number if boundary segments
1612 ++nBndSegments_;
1613 const int facePos = 2 * face ;
1614 // store negative number to indicate boundary
1615 // the abstract value is the segment index
1616 if( grid_.face_cells[ facePos ] < 0 )
1617 {
1618 grid_.face_cells[ facePos ] = -nBndSegments_;
1619 }
1620 else if ( grid_.face_cells[ facePos+1 ] < 0 )
1621 {
1622 grid_.face_cells[ facePos+1 ] = -nBndSegments_;
1623 }
1624 }
1625 }
1626 }
1627
1628 void print( std::ostream& out, const UnstructuredGridType& grid ) const
1629 {
1630 const int numCells = grid.number_of_cells;
1631 for( int c=0; c<numCells; ++c )
1632 {
1633 out << "cell " << c << " : faces = " << std::endl;
1634 for (int hf=grid.cell_facepos[ c ]; hf < grid.cell_facepos[c+1]; ++hf)
1635 {
1636 int f = grid_.cell_faces[ hf ];
1637 const int* fnbeg = grid_.face_nodes + grid_.face_nodepos[f];
1638 const int* fnend = grid_.face_nodes + grid_.face_nodepos[f+1];
1639 out << f << " vx = " ;
1640 while( fnbeg != fnend )
1641 {
1642 out << *fnbeg << " ";
1643 ++fnbeg;
1644 }
1645 out << std::endl;
1646 }
1647 out << std::endl;
1648
1649 const auto& vx = cellVertices_[ c ];
1650 out << "cell " << c << " : vertices = ";
1651 for( size_t i=0; i<vx.size(); ++i )
1652 out << vx[ i ] << " ";
1653 out << std::endl;
1654 }
1655
1656 }
1657
1658 protected:
1661
1663 std::array< int, 3 > cartDims_;
1664 std::vector< std::vector< GeometryType > > geomTypes_;
1665 std::vector< std::vector< int > > cellVertices_;
1666
1667 std::vector< GlobalCoordinate > unitOuterNormals_;
1668
1672
1674
1675 private:
1676 // no copying
1677 PolyhedralGrid ( const PolyhedralGrid& );
1678 };
1679
1680
1681
1682 // PolyhedralGrid::Codim
1683 // -------------
1684
1685 template< int dim, int dimworld, typename coord_t >
1686 template< int codim >
1688 : public Base::template Codim< codim >
1689 {
1698 typedef typename Traits::template Codim< codim >::Entity Entity;
1699
1704 typedef typename Traits::template Codim< codim >::EntityPointer EntityPointer;
1705
1719 typedef typename Traits::template Codim< codim >::Geometry Geometry;
1720
1729 typedef typename Traits::template Codim< codim >::LocalGeometry LocalGeometry;
1730
1736 template< PartitionIteratorType pitype >
1738 {
1739 typedef typename Traits::template Codim< codim >
1742 typedef typename Traits::template Codim< codim >
1745 };
1746
1755
1764
1766 };
1767
1768} // namespace Dune
1769
1773
1774#endif // #ifndef DUNE_POLYHEDRALGRID_GRID_HH
void destroy_grid(struct UnstructuredGrid *g)
struct UnstructuredGrid * allocate_grid(size_t ndims, size_t ncells, size_t nfaces, size_t nfacenodes, size_t ncellfaces, size_t nnodes)
struct UnstructuredGrid * create_grid_cart2d(int nx, int ny, double dx, double dy)
struct UnstructuredGrid * create_grid_hexa3d(int nx, int ny, int nz, double dx, double dy, double dz)
Definition: entity.hh:152
Definition: entityseed.hh:16
Definition: geometry.hh:245
Definition: idset.hh:18
Definition: indexset.hh:25
Definition: intersectioniterator.hh:16
Definition: intersection.hh:22
Definition: iterator.hh:21
Definition: geometry.hh:264
identical grid wrapper
Definition: grid.hh:157
void postAdapt()
Definition: grid.hh:601
Traits::ctype ctype
type of vector coordinates (e.g., double)
Definition: grid.hh:306
int ghostSize(int, int codim) const
obtain size of ghost region for a grid level
Definition: grid.hh:641
bool loadBalance(CommDataHandleIF< DataHandle, Data > &)
rebalance the load each process has to handle
Definition: grid.hh:745
Partition< All_Partition >::LevelGridView LevelGridView
View types for All_Partition.
Definition: grid.hh:243
Traits::template Codim< EntitySeed::codimension >::EntityPointer entityPointer(const EntitySeed &seed) const
obtain EntityPointer from EntitySeed.
Definition: grid.hh:805
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
obtain EntityPointer from EntitySeed.
Definition: grid.hh:816
static void computeGeometry(UnstructuredGridPtr &ug)
Definition: grid.hh:189
bool preAdapt()
Definition: grid.hh:579
std::vector< std::vector< int > > cellVertices_
Definition: grid.hh:1665
GlobalCoordinate outerNormal(const EntitySeed &seed, const int i) const
Definition: grid.hh:1223
int ghostSize(int codim) const
obtain size of ghost region for the leaf grid
Definition: grid.hh:621
bool loadBalance(DofManager &)
rebalance the load each process has to handle
Definition: grid.hh:765
Traits::GlobalIdSet GlobalIdSet
type of global id set
Definition: grid.hh:281
int maxLevel() const
obtain maximal grid level
Definition: grid.hh:411
Codim< codim >::template Partition< pitype >::LeafIterator leafend() const
Definition: grid.hh:512
Codim< codim >::LevelIterator lbegin(const int) const
Definition: grid.hh:519
std::array< int, 3 > cartDims_
Definition: grid.hh:1663
const LeafIndexSet & leafIndexSet() const
Definition: grid.hh:559
const int * globalCellPtr() const
Definition: grid.hh:852
Traits::LevelIndexSet LevelIndexSet
type of level index set
Definition: grid.hh:269
LevelGridView levelGridView(int) const
View for a grid level for All_Partition.
Definition: grid.hh:789
std::unique_ptr< UnstructuredGridType, UnstructuredGridDeleter > UnstructuredGridPtr
Definition: grid.hh:176
PolyhedralGrid(const std::vector< int > &n, const std::vector< double > &dx)
constructor
Definition: grid.hh:343
bool isBoundaryFace(const typename Codim< 1 >::EntitySeed &faceSeed) const
Definition: grid.hh:1112
static UnstructuredGridPtr allocateGrid(std::size_t nCells, std::size_t nFaces, std::size_t nFaceNodes, std::size_t nCellFaces, std::size_t nNodes)
Definition: grid.hh:179
size_t nBndSegments_
Definition: grid.hh:1673
Codim< codim >::LeafIterator leafbegin() const
Definition: grid.hh:491
Codim< codim >::LevelIterator lend(const int) const
Definition: grid.hh:525
ExtraData extraData() const
Definition: grid.hh:967
Partition< pitype >::LeafGridView leafGridView() const
View for the leaf grid.
Definition: grid.hh:781
void print(std::ostream &out, const UnstructuredGridType &grid) const
Definition: grid.hh:1628
int getMark(const typename Codim< 0 >::Entity &) const
Definition: grid.hh:573
Traits::HierarchicIterator HierarchicIterator
iterator over the grid hierarchy
Definition: grid.hh:223
Codim< 0 >::EntitySeed neighbor(const typename Codim< 0 >::EntitySeed &seed, const int i) const
Definition: grid.hh:1182
CommunicationType comm_
Definition: grid.hh:1662
Codim< codim >::LeafIterator leafend() const
Definition: grid.hh:497
int size(int, int codim) const
obtain number of entites on a level
Definition: grid.hh:424
Partition< pitype >::LevelGridView levelGridView(int) const
View for a grid level.
Definition: grid.hh:772
PolyhedralGrid(const Opm::EclipseGrid &inputGrid, const std::vector< double > &poreVolumes=std::vector< double >{}, const bool edge_conformal=false)
constructor
Definition: grid.hh:324
GlobalCoordinate copyToGlobalCoordinate(const double *coords) const
Definition: grid.hh:1282
void update()
update grid caches
Definition: grid.hh:835
void getIJK(const int c, std::array< int, 3 > &ijk) const
Definition: grid.hh:857
Partition< All_Partition >::LeafGridView LeafGridView
Definition: grid.hh:244
void switchToDistributedView()
Switch to the distributed view.
Definition: grid.hh:695
int overlapSize(int, int) const
obtain size of overlap region for a grid level
Definition: grid.hh:631
int indexInOutside(const typename Codim< 0 >::EntitySeed &seed, const int i) const
Definition: grid.hh:1196
std::vector< std::vector< GeometryType > > geomTypes_
Definition: grid.hh:1664
int size(int codim) const
obtain number of leaf entities
Definition: grid.hh:435
void scatterData(DataHandle &handle) const
Moves data from the global (all data on process) view to the distributed view.
Definition: grid.hh:880
LeafIndexSet leafIndexSet_
Definition: grid.hh:1669
int indexInInside(const typename Codim< 0 >::EntitySeed &seed, const int i) const
Definition: grid.hh:1170
Codim< codim >::EntitySeed subEntitySeed(const EntitySeedArg &baseSeed, const int i) const
Definition: grid.hh:1041
Traits::LocalIdSet LocalIdSet
type of local id set
Definition: grid.hh:298
int corners(const EntitySeed &seed) const
Definition: grid.hh:970
const GlobalIdSet & globalIdSet() const
Definition: grid.hh:544
typename Traits::Communication Communication
communicator with all other processes having some part of the grid
Definition: grid.hh:309
std::vector< GlobalCoordinate > unitOuterNormals_
Definition: grid.hh:1667
Codim< codim >::template Partition< pitype >::LeafIterator leafbegin() const
Definition: grid.hh:504
int subEntities(const EntitySeed &seed, const int codim) const
Definition: grid.hh:1012
UnstructuredGridType * createGrid(const std::vector< int > &n, const std::vector< double > &dx) const
Definition: grid.hh:945
const CommunicationType & comm() const
obtain CollectiveCommunication object
Definition: grid.hh:708
int overlapSize(int) const
obtain size of overlap region for the leaf grid
Definition: grid.hh:612
const std::vector< GeometryType > & geomTypes(const unsigned int codim) const
Definition: grid.hh:1129
Traits::LevelIntersectionIterator LevelIntersectionIterator
iterator over intersections with other entities on the same level
Definition: grid.hh:227
Communication CommunicationType
Definition: grid.hh:310
GridFamily::Traits Traits
type of the grid traits
Definition: grid.hh:206
PolyhedralGrid(UnstructuredGridPtr &&gridPtr)
constructor
Definition: grid.hh:362
Codim< codim >::EntitySeed subEntitySeed(const typename Codim< 1 >::EntitySeed &faceSeed, const int i) const
Definition: grid.hh:1075
Traits::LeafIntersectionIterator LeafIntersectionIterator
iterator over intersections with other entities on the leaf level
Definition: grid.hh:225
bool adapt(DataHandle &)
Definition: grid.hh:595
Codim< codim >::template Partition< pitype >::LevelIterator lend(const int) const
Definition: grid.hh:539
UnstructuredGrid UnstructuredGridType
Definition: grid.hh:164
bool hasBoundaryIntersections(const typename Codim< 0 >::EntitySeed &seed) const
Definition: grid.hh:1093
double volumes(const EntitySeed &seed) const
Definition: grid.hh:1293
int size(int, GeometryType type) const
obtain number of entites on a level
Definition: grid.hh:464
void communicate(DataHandle &, InterfaceType, CommunicationDirection) const
communicate information on leaf entities
Definition: grid.hh:681
Codim< codim >::template Partition< pitype >::LevelIterator lbegin(const int) const
Definition: grid.hh:532
UnstructuredGridPtr gridPtr_
Definition: grid.hh:1659
const LocalIdSet & localIdSet() const
Definition: grid.hh:549
GlobalIdSet globalIdSet_
Definition: grid.hh:1670
size_t numBoundarySegments() const
obtain number of leaf entities
Definition: grid.hh:484
void switchToGlobalView()
Switch to the global view.
Definition: grid.hh:689
GeometryType geometryType(const Seed &seed) const
Definition: grid.hh:1141
const std::array< int, 3 > & logicalCartesianSize() const
Definition: grid.hh:841
bool loadBalance()
rebalance the load each process has to handle
Definition: grid.hh:724
PolyhedralGrid(const UnstructuredGridType &grid)
constructor
Definition: grid.hh:381
LeafGridView leafGridView() const
View for the leaf grid for All_Partition.
Definition: grid.hh:796
int boundarySegmentIndex(const typename Codim< 0 >::EntitySeed &seed, const int face) const
Definition: grid.hh:1118
bool isBoundaryFace(const int face) const
Definition: grid.hh:1105
int size(GeometryType type) const
returns the number of boundary segments within the macro grid
Definition: grid.hh:473
int cartesianIndexInInside(const typename Codim< 0 >::EntitySeed &seed, const int i) const
Definition: grid.hh:1175
bool mark(int, const typename Codim< 0 >::Entity &)
Definition: grid.hh:568
Traits::GlobalCoordinate GlobalCoordinate
Definition: grid.hh:312
const LevelIndexSet & levelIndexSet(int) const
Definition: grid.hh:554
void communicate(DataHandle &, InterfaceType, CommunicationDirection, int) const
communicate information on a grid level
Definition: grid.hh:660
bool adapt()
Definition: grid.hh:585
Traits::ExtraData ExtraData
Definition: grid.hh:966
const int * globalCell() const
Definition: grid.hh:846
const UnstructuredGridType & grid_
Definition: grid.hh:1660
GlobalCoordinate unitOuterNormal(const EntitySeed &seed, const int i) const
Definition: grid.hh:1238
GlobalCoordinate centroids(const EntitySeed &seed) const
Definition: grid.hh:1254
LocalIdSet localIdSet_
Definition: grid.hh:1671
Traits::LeafIndexSet LeafIndexSet
type of leaf index set
Definition: grid.hh:259
void globalRefine(int)
Definition: grid.hh:564
void init()
Definition: grid.hh:1321
GlobalCoordinate corner(const EntitySeed &seed, const int i) const
Definition: grid.hh:985
UnstructuredGridType * createGrid(const Opm::EclipseGrid &inputGrid, const std::vector< double > &poreVolumes, const bool edge_conformal) const
Definition: grid.hh:887
Transform a corner-point grid ZCORN field to account for MINPV processing.
Definition: MinpvProcessor.hpp:35
Result process(const std::vector< double > &thickness, const double z_tolerance, const double max_gap, const std::vector< double > &pv, const std::vector< double > &minpvv, const std::vector< int > &actnum, const bool mergeMinPVCells, double *zcorn, const bool pinchNOGAP=false, const bool pinchOption4ALL=false, const std::vector< double > &permz={}, const std::function< double(int)> &multZ=[](int){ return 0;}, const double tolerance_unique_points=0) const
void compute_geometry(struct UnstructuredGrid *g)
struct UnstructuredGrid * create_grid_cornerpoint(const struct grdecl *in, double tol, int edge_conformal)
The namespace Dune is the main namespace for all Dune code.
Definition: common/CartesianIndexMapper.hpp:10
int faceTag(const Dune::CpGrid &grid, const Dune::cpgrid::Cell2FacesRow::iterator &cell_face)
Get Eclipse Cartesian tag of a face.
int numCells(const Dune::CpGrid &grid)
Get the number of cells of a grid.
STL namespace.
Traits::template Codim< codim >::template Partition< pitype >::LeafIterator LeafIterator
Definition: grid.hh:1741
Traits::template Codim< codim >::template Partition< pitype >::LevelIterator LevelIterator
Definition: grid.hh:1744
traits structure containing types for a codimension
Definition: grid.hh:1689
Partition< All_Partition >::LeafIterator LeafIterator
type of level iterator
Definition: grid.hh:1754
Traits::template Codim< codim >::Entity Entity
type of entity
Definition: grid.hh:1698
Traits::template Codim< codim >::EntityPointer EntityPointer
type of entity pointer
Definition: grid.hh:1704
Traits::template Codim< codim >::LocalGeometry LocalGeometry
type of local geometry
Definition: grid.hh:1729
Partition< All_Partition >::LevelIterator LevelIterator
type of leaf iterator
Definition: grid.hh:1763
Traits::template Codim< codim >::Geometry Geometry
type of world geometry
Definition: grid.hh:1719
Types for GridView.
Definition: grid.hh:237
GridFamily::Traits::template Partition< pitype >::LeafGridView LeafGridView
Definition: grid.hh:239
GridFamily::Traits::template Partition< pitype >::LevelGridView LevelGridView
Definition: grid.hh:238
void operator()(UnstructuredGridType *grdPtr)
Definition: grid.hh:169
PolyhedralGridIterator< codim, const Grid, pitype > LeafIteratorImpl
Definition: grid.hh:106
Dune::EntityIterator< codim, const Grid, LeafIteratorImpl > LeafIterator
Definition: grid.hh:107
LeafIterator LevelIterator
Definition: grid.hh:109
Dune::Geometry< dimension-codim, dimensionworld, const Grid, PolyhedralGridLocalGeometry > LocalGeometry
Definition: grid.hh:92
Entity EntityPointer
Definition: grid.hh:98
PolyhedralGridGeometry< dimension-codim, dimensionworld, const Grid > GeometryImpl
Definition: grid.hh:88
Dune::Geometry< dimension-codim, dimensionworld, const Grid, PolyhedralGridGeometry > Geometry
Definition: grid.hh:89
Partition< All_Partition >::LeafIterator LeafIterator
Definition: grid.hh:112
EntityImpl EntityPointerImpl
Definition: grid.hh:97
PolyhedralGridEntitySeed< codim, const Grid > EntitySeed
Definition: grid.hh:101
Dune::Entity< codim, dimension, const Grid, PolyhedralGridEntity > Entity
Definition: grid.hh:95
PolyhedralGridLocalGeometry< dimension-codim, dimensionworld, const Grid > LocalGeometryImpl
Definition: grid.hh:91
Partition< All_Partition >::LevelIterator LevelIterator
Definition: grid.hh:113
PolyhedralGridEntity< codim, dimension, const Grid > EntityImpl
Definition: grid.hh:94
Dune::GridView< PolyhedralGridViewTraits< dim, dimworld, ctype, pitype > > LeafGridView
Definition: grid.hh:129
Dune::GridView< PolyhedralGridViewTraits< dim, dimworld, ctype, pitype > > LevelGridView
Definition: grid.hh:130
PolyhedralGridIterator< 0, const Grid, All_Partition > HierarchicIteratorImpl
Definition: grid.hh:82
Dune::EntityIterator< 0, const Grid, HierarchicIteratorImpl > HierarchicIterator
Definition: grid.hh:83
Dune::IntersectionIterator< const Grid, LevelIntersectionIteratorImpl, LevelIntersectionImpl > LevelIntersectionIterator
Definition: grid.hh:80
GlobalIdSet LocalIdSet
Definition: grid.hh:120
PolyhedralGridIndexSet< dim, dimworld, ctype > LeafIndexSet
Definition: grid.hh:116
Dune::Communication< MPICommunicator > Communication
Definition: grid.hh:123
Dune::IntersectionIterator< const Grid, LeafIntersectionIteratorImpl, LeafIntersectionImpl > LeafIntersectionIterator
Definition: grid.hh:79
PolyhedralGridIntersection< const Grid > LevelIntersectionImpl
Definition: grid.hh:72
PolyhedralGridIntersectionIterator< const Grid > LeafIntersectionIteratorImpl
Definition: grid.hh:73
Dune::Intersection< const Grid, LeafIntersectionImpl > LeafIntersection
Definition: grid.hh:76
PolyhedralGridIntersectionIterator< const Grid > LevelIntersectionIteratorImpl
Definition: grid.hh:74
static const int dimension
Definition: grid.hh:66
const Grid * ExtraData
Definition: grid.hh:62
int Index
Definition: grid.hh:64
Partition< All_Partition >::LevelGridView LevelGridView
Definition: grid.hh:134
Partition< All_Partition >::LeafGridView LeafGridView
Definition: grid.hh:133
PolyhedralGrid< dim, dimworld, coord_t > Grid
Definition: grid.hh:56
PolyhedralGridIdSet< dim, dimworld, ctype > GlobalIdSet
Definition: grid.hh:119
Dune::FieldVector< ctype, dimensionworld > GlobalCoordinate
Definition: grid.hh:69
Dune::Communication< MPICommunicator > CollectiveCommunication
Definition: grid.hh:124
static const int dimensionworld
Definition: grid.hh:67
PolyhedralGridIntersection< const Grid > LeafIntersectionImpl
Definition: grid.hh:71
Dune::MPIHelper::MPICommunicator MPICommunicator
Definition: grid.hh:122
coord_t ctype
Definition: grid.hh:58
Dune::Intersection< const Grid, LevelIntersectionImpl > LevelIntersection
Definition: grid.hh:77
PolyhedralGridIndexSet< dim, dimworld, ctype > LevelIndexSet
Definition: grid.hh:117
Definition: grid.hh:53
Definition: UnstructuredGrid.h:101
int * face_nodes
Definition: UnstructuredGrid.h:123
grid_size_t * face_nodepos
Definition: UnstructuredGrid.h:129
int number_of_cells
Definition: UnstructuredGrid.h:111
double * face_areas
Definition: UnstructuredGrid.h:175
int * cell_faces
Definition: UnstructuredGrid.h:148
int number_of_faces
Definition: UnstructuredGrid.h:113
double * cell_centroids
Definition: UnstructuredGrid.h:194
int * cell_facetag
Definition: UnstructuredGrid.h:246
double * cell_volumes
Definition: UnstructuredGrid.h:199
int * face_cells
Definition: UnstructuredGrid.h:140
grid_size_t * cell_facepos
Definition: UnstructuredGrid.h:154
double * face_centroids
Definition: UnstructuredGrid.h:170
int number_of_nodes
Definition: UnstructuredGrid.h:115
int cartdims[3]
Definition: UnstructuredGrid.h:229
int * global_cell
Definition: UnstructuredGrid.h:216
double * face_normals
Definition: UnstructuredGrid.h:186
double * node_coordinates
Definition: UnstructuredGrid.h:162
Definition: preprocess.h:56
int dims[3]
Definition: preprocess.h:57
double b(const Dune::FieldVector< ct, dimworld > &, double)
Definition: transportproblem2.hh:25