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