41 Grid*
convert(
const FromGrid& grid, Vector& cellData, std::vector<unsigned int>& ordering )
45 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
49 GridFactory< Grid > factory;
54 typedef typename FromGrid :: LeafGridView GridView ;
55 typedef typename GridView :: IndexSet IndexSet ;
56 typedef typename IndexSet :: IndexType IndexType ;
57 typedef typename GridView :: template Codim< 0 > :: Iterator ElementIterator ;
58 typedef typename ElementIterator::Entity Entity ;
59 typedef typename GridView :: IntersectionIterator IntersectionIterator ;
60 typedef typename IntersectionIterator :: Intersection Intersection ;
62 GridView gridView = grid.leafGridView();
63 const IndexSet &indexSet = gridView.indexSet();
66 std::map< IndexType, unsigned int > vtxMap;
68 const int numVertices = (1 << dim);
69 std::vector< unsigned int > vertices( numVertices );
70 typedef std::pair< Dune::GeometryType, std::vector< unsigned int > > ElementPair;
71 std::vector< ElementPair > elements;
72 if( ! ordering.empty() )
73 elements.resize( ordering.size() );
75 int nextElementIndex = 0;
76 const ElementIterator end = gridView.template end< 0 >();
77 for( ElementIterator it = gridView.template begin< 0 >(); it != end; ++it )
79 const Entity &entity = *it;
82 const typename Entity::Geometry geo = entity.geometry();
84 for(
int i = 0; i < numVertices; ++i )
86 const IndexType vtxId = indexSet.subIndex( entity, i, dim );
87 std::pair< typename std::map< IndexType, unsigned int >::iterator,
bool > result
88 = vtxMap.insert( std::make_pair( vtxId, vtxMap.size() ) );
90 factory.insertVertex( geo.corner( i ), vtxId );
91 vertices[ i ] = result.first->second;
93 if( ordering.empty() )
95 factory.insertElement( entity.type(), vertices );
100 elements[ ordering[ nextElementIndex++ ] ] = ElementPair( entity.type(), vertices ) ;
104 if( ! ordering.empty() )
107 for(
auto it = elements.begin(), end = elements.end(); it != end; ++it )
109 factory.insertElement( (*it).first, (*it).second );
113 nextElementIndex = 0;
114 for( ElementIterator it = gridView.template begin< 0 >(); it != end; ++it )
116 const Entity &entity = *it;
118 const int elementIndex = ordering.empty() ? nextElementIndex++ : ordering[ nextElementIndex++ ];
119 const IntersectionIterator iend = gridView.iend( entity );
120 for( IntersectionIterator iit = gridView.ibegin( entity ); iit != iend; ++iit )
122 const Intersection &intersection = *iit;
123 const int faceNumber = intersection.indexInInside();
125 if( intersection.boundary() )
126 factory.insertBoundary( elementIndex, faceNumber );
129#if DUNE_VERSION_NEWER(DUNE_GRID,3,0)
130 const double isParallel =
true;
132 const double isParallel = Capabilities::isParallel< FromGrid > :: v;
135 intersection.neighbor() &&
136 intersection.outside().partitionType() != InteriorEntity )
139 factory.insertProcessBorder( elementIndex, faceNumber );
146 Grid* newgrid = factory.createGrid(
true,
true, std::string(
"FromToGrid") );
148 if( ! cellData.empty() )
150 Vector oldCellData( cellData );
151 auto macroView = newgrid->levelGridView( 0 );
153 for(
auto it = macroView.template begin<0>(), end = macroView.template end<0>();
154 it != end; ++it, ++idx )
156 const int insertionIndex = ordering.empty() ?
157 factory.insertionIndex( *it ) : ordering[ factory.insertionIndex( *it ) ]; ;
158 cellData[ idx ] = oldCellData[ insertionIndex ] ;
163 if( ordering.empty() )
164 ordering = factory.ordering();
167 MPI_Barrier( MPI_COMM_WORLD );