dune-grid 2.12-git
Loading...
Searching...
No Matches
gridptr.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5#ifndef DUNE_DGF_GRIDPTR_HH
6#define DUNE_DGF_GRIDPTR_HH
7
8#include <cassert>
9#include <cctype>
10
11#include <array>
12#include <iostream>
13#include <map>
14#include <memory>
15#include <string>
16#include <type_traits>
17#include <vector>
18
19//- Dune includes
22
28
32
34
35namespace Dune
36{
37
38 // External Forward Declarations
39 // -----------------------------
40
41 template < class G >
42 struct DGFGridFactory;
43
44 template< class GridImp, class IntersectionImp >
45 class Intersection;
46
47
48
49 // GridPtr
50 // -------
51
64 template< class GridType >
65 struct GridPtr
66 {
67 class mygrid_ptr : public std::shared_ptr< GridType >
68 {
70 // empty deleter to avoid deletion on release
72
73 void removeObj()
74 {
75 // if use count is only 1 delete object
76 if( use_count() == 1 )
77 {
78 // delete point here, since we use the empty deleter
79 GridType* grd = release();
80 if( grd ) delete grd ;
81 }
82 }
83
84 void assignObj( const mygrid_ptr& other )
85 {
86 removeObj();
87 base_t :: operator = ( other );
88 }
89 public:
90 using base_t :: get ;
91 using base_t :: swap ;
92 using base_t :: use_count ;
93
94 // default constructor
95 mygrid_ptr() : base_t( ( GridType * ) 0, emptydeleter_t() ) {}
96 // copy constructor
97 mygrid_ptr( const mygrid_ptr& other ) : base_t(nullptr) { assignObj( other ); }
98 // constructor taking pointer
99 explicit mygrid_ptr( GridType* grd ) : base_t( grd, emptydeleter_t() ) {}
100
101 // destructor
102 ~mygrid_ptr() { removeObj(); }
103
104 // assignment operator
106 {
107 assignObj( other );
108 return *this;
109 }
110
111 // release pointer
112 GridType* release()
113 {
114 GridType* grd = this->get();
115 base_t ptr(( GridType * ) 0, emptydeleter_t() );
116 this->swap( ptr );
117 return grd ;
118 }
119 };
120
121 protected:
122 std::string getFileExtension( const std::string& filename ) const
123 {
124 // extract file extension
125 auto extpos = filename.find_last_of(".");
126 std::string ext;
127 if( extpos != std::string::npos)
128 ext = filename.substr( extpos + 1 );
129
130 // convert all letters to lower case
131 for( auto& item : ext )
132 item = std::tolower( item );
133 return ext;
134 }
135
136 // read gmsh file if dimension world <= 3
138 {
139 GridFactory<GridType> gridFactory;
140 std::vector<int> boundaryIDs;
141 std::vector<int> elementsIDs;
142 GmshReader<GridType>::read(gridFactory,filename,boundaryIDs,elementsIDs);
143 initialize( gridFactory, boundaryIDs,elementsIDs);
144 }
145
146 // if dimension world > 3 throw GridError
148 {
149 DUNE_THROW(GridError, "GmshReader requires dimWorld <= 3." );
150 }
151
152 public:
153
155 static const int dimension = GridType::dimension;
156
158 explicit GridPtr ( const std::string &filename,
160 : gridPtr_(),
161 elParam_(),
162 vtxParam_(),
163 bndParam_(),
164 bndId_(),
165 emptyParam_(),
166 nofElParam_( 0 ),
167 nofVtxParam_( 0 ),
168 haveBndParam_( false )
169 {
170 std::string fileExt = getFileExtension( filename );
171
172 if( fileExt == "dgf" )
173 {
174 DGFGridFactory< GridType > dgfFactory( filename, comm );
175 initialize( dgfFactory );
176 }
177 else if( fileExt == "msh" )
178 {
179 // Gmsh reader only compiles for dimworld <= 3
180 readGmsh( filename, std::integral_constant< bool, GridType::dimensionworld <= 3 > () );
181 }
182 else if( fileExt == "amc" || fileExt == "2d" || fileExt == "3d" )
183 {
184 // TODO: AlbertaReader
185 DUNE_THROW( NotImplemented, "GridPtr: file format '" << fileExt << "' not supported yet!" );
186 }
187 else if( fileExt == "vtu" )
188 {
189 // TODO: vtu/vtk reader
190 DUNE_THROW( NotImplemented, "GridPtr: file format '" << fileExt << "' not supported yet!" );
191 }
192 else
193 {
194 DUNE_THROW( NotImplemented, "GridPtr: file format '" << fileExt << "' not supported yet!" );
195 }
196 }
197
199 explicit GridPtr ( std::istream &input,
201 : gridPtr_(),
202 elParam_(),
203 vtxParam_(),
204 bndParam_(),
205 bndId_(),
206 emptyParam_(),
207 nofElParam_( 0 ),
208 nofVtxParam_( 0 ),
209 haveBndParam_( false )
210 {
211 // input stream only works for DGF format right now
212 DGFGridFactory< GridType > dgfFactory( input, comm );
213 initialize( dgfFactory );
214 }
215
218 : gridPtr_(),
219 elParam_(),
220 vtxParam_(),
221 bndParam_(),
222 bndId_(),
223 emptyParam_(),
224 nofElParam_(0),
225 nofVtxParam_(0),
226 haveBndParam_( false )
227 {}
228
230 explicit GridPtr( GridType *grd )
231 : gridPtr_(grd),
232 elParam_(),
233 vtxParam_(),
234 bndParam_(),
235 bndId_(),
236 emptyParam_(),
237 nofElParam_(0),
238 nofVtxParam_(0),
239 haveBndParam_( false )
240 {}
241
243 GridPtr( const GridPtr &org ) = default;
244
247 {
248 gridPtr_ = org.gridPtr_;
249 elParam_ = org.elParam_;
250 vtxParam_ = org.vtxParam_;
251 bndParam_ = org.bndParam_;
252 bndId_ = org.bndId_;
254
258 return *this;
259 }
260
262 GridPtr& operator = (GridType * grd)
263 {
264 gridPtr_ = mygrid_ptr( grd );
265 elParam_.resize(0);
266 vtxParam_.resize(0);
267 bndParam_.resize(0);
268 bndId_.resize(0);
270
271 nofVtxParam_ = 0;
272 nofElParam_ = 0;
273 haveBndParam_ = false;
274 return *this;
275 }
276
278 GridType& operator*() {
279 return *gridPtr_;
280 }
281
283 GridType* operator->() {
284 return gridPtr_.operator -> ();
285 }
286
288 const GridType& operator*() const {
289 return *gridPtr_;
290 }
291
293 const GridType* operator->() const {
294 return gridPtr_.operator -> ();
295 }
296
298 GridType* release () { return gridPtr_.release(); }
299
301 int nofParameters(int cdim) const {
302 switch (cdim) {
303 case 0 : return nofElParam_; break;
304 case GridType::dimension : return nofVtxParam_; break;
305 }
306 return 0;
307 }
308
310 template <class Entity>
311 int nofParameters ( const Entity & ) const
312 {
313 return nofParameters( (int) Entity::codimension );
314 }
315
317 template< class GridImp, class IntersectionImp >
319 {
320 return parameters( intersection ).size();
321 }
322
324 template <class Entity>
325 const std::vector< double > &parameters ( const Entity &entity ) const
326 {
327 typedef typename GridType::LevelGridView GridView;
328 GridView gridView = gridPtr_->levelGridView( 0 );
329 switch( (int)Entity::codimension )
330 {
331 case 0 :
332 if( nofElParam_ > 0 )
333 {
334 assert( (unsigned int)gridView.indexSet().index( entity ) < elParam_.size() );
335 return elParam_[ gridView.indexSet().index( entity ) ];
336 }
337 break;
338 case GridType::dimension :
339 if( nofVtxParam_ > 0 )
340 {
341 assert( (unsigned int)gridView.indexSet().index( entity ) < vtxParam_.size() );
342 return vtxParam_[ gridView.indexSet().index( entity ) ];
343 }
344 break;
345 }
346 return emptyParam_;
347 }
348
350 template< class GridImp, class IntersectionImp >
352 {
353 // if no parameters given return empty vector
354 if ( !haveBndParam_ )
356
357 return bndParam_[ intersection.boundarySegmentIndex() ];
358 }
359
361 {
362 if( gridPtr_->comm().size() > 1 )
363 {
364 DataHandle dh(*this);
365 gridPtr_->levelGridView( 0 ).communicate( dh.interface(), InteriorBorder_All_Interface,ForwardCommunication );
366 }
367 }
368
370 {
371 if( gridPtr_->comm().size() > 1 )
372 {
373 DataHandle dh(*this);
374 gridPtr_->loadBalance( dh.interface() );
375 gridPtr_->levelGridView( 0 ).communicate( dh.interface(), InteriorBorder_All_Interface,ForwardCommunication );
376 }
377 }
378
379 protected:
380 template< class Range >
381 static bool isEmpty ( Range &&range )
382 {
383 return range.begin() == range.end();
384 }
385
387 {
388 gridPtr_ = mygrid_ptr( dgfFactory.grid() );
389
390 const auto gridView = gridPtr_->levelGridView( 0 );
391
392 nofElParam_ = dgfFactory.template numParameters< 0 >();
393 nofVtxParam_ = dgfFactory.template numParameters< dimension >();
395
396 std::array< int, 3 > nofParams = {{ nofElParam_, nofVtxParam_, static_cast< int >( haveBndParam_ ) }};
397 gridView.comm().max( nofParams.data(), nofParams.size() );
398
399 // empty grids have no parameters associated
400 if( isEmpty( elements( gridView, Partitions::interiorBorder ) ) )
401 {
402 nofElParam_ = nofParams[ 0 ];
403 nofVtxParam_ = nofParams[ 1 ];
404 }
405
406 // boundary parameters may be empty
407 haveBndParam_ = static_cast< bool >( nofParams[ 2 ] );
408
409 if( (nofElParam_ != nofParams[ 0 ]) || (nofVtxParam_ != nofParams[ 1 ]) )
410 DUNE_THROW( DGFException, "Number of parameters differs between processes" );
411
412 if( nofElParam_ > 0 )
413 elParam_.resize( gridView.indexSet().size( 0 ) );
414
415 if( nofVtxParam_ > 0 )
416 vtxParam_.resize( gridView.indexSet().size( dimension ) );
417
418 if( haveBndParam_ )
419 {
420 bndId_.resize( gridView.indexSet().size( 1 ) );
421 bndParam_.resize( gridPtr_->numBoundarySegments() );
422 }
423
424 for( const auto &element : elements( gridView, Partitions::interiorBorder ) )
425 {
426 if( nofElParam_ > 0 )
427 {
428 const auto &indexSet = gridView.indexSet();
429 std::swap( elParam_[ indexSet.index( element ) ], dgfFactory.parameter( element ) );
430 assert( elParam_[ indexSet.index( element ) ].size() == static_cast< std::size_t >( nofElParam_ ) );
431 }
432
433 if( nofVtxParam_ > 0 )
434 {
435 const auto &indexSet = gridView.indexSet();
436 for( unsigned int v = 0, n = element.subEntities( dimension ); v < n; ++v )
437 {
438 const auto index = indexSet.subIndex( element, v, dimension );
439 if( vtxParam_[ index ].empty() )
440 std::swap( vtxParam_[ index ], dgfFactory.parameter( element.template subEntity< dimension >( v ) ) );
441 assert( vtxParam_[ index ].size() == static_cast< std::size_t >( nofVtxParam_ ) );
442 }
443 }
444
445 if( haveBndParam_ && element.hasBoundaryIntersections() )
446 {
447 const auto &indexSet = gridView.indexSet();
448 for( const auto &intersection : intersections( gridView, element ) )
449 {
450 // dirty hack: check for "none" to make corner point grid work
451 if( !intersection.boundary() || intersection.type().isNone() )
452 continue;
453
454 const auto k = indexSet.subIndex( element, intersection.indexInInside(), 1 );
455 bndId_[ k ] = dgfFactory.boundaryId( intersection );
456 if( haveBndParam_ )
457 bndParam_[ intersection.boundarySegmentIndex() ] = dgfFactory.boundaryParameter( intersection );
458 }
459 }
460 }
461 }
462
464 std::vector<int>& boundaryIds,
465 std::vector<int>& elementIds )
466 {
467 gridPtr_ = mygrid_ptr( factory.createGrid().release() );
468
469 const auto& gridView = gridPtr_->leafGridView();
470 const auto& indexSet = gridView.indexSet();
471
472 nofElParam_ = elementIds.empty() ? 0 : 1 ;
473 nofVtxParam_ = 0;
474 haveBndParam_ = boundaryIds.empty() ? 0 : 1 ;
475
476 std::array< int, 3 > nofParams = {{ nofElParam_, nofVtxParam_, static_cast< int >( haveBndParam_ ) }};
477 gridView.comm().max( nofParams.data(), nofParams.size() );
478
479 // empty grids have no parameters associated
480 if( isEmpty( elements( gridView, Partitions::interiorBorder ) ) )
481 {
482 nofElParam_ = nofParams[ 0 ];
483 }
484
485 // boundary parameters may be empty
486 haveBndParam_ = static_cast< bool >( nofParams[ 2 ] );
487
488 // Reorder boundary IDs according to the insertion index
489 if(!boundaryIds.empty() || !elementIds.empty() )
490 {
491 bndParam_.resize( boundaryIds.size() );
492 elParam_.resize( elementIds.size(), std::vector<double>(1) );
493 for(const auto& entity : elements( gridView ))
494 {
495 elParam_[ indexSet.index( entity ) ][ 0 ] = elementIds[ factory.insertionIndex( entity ) ];
496 if( haveBndParam_ )
497 {
498 for(const auto& intersection : intersections( gridView,entity) )
499 {
500 if(intersection.boundary())
501 {
502 // DGFBoundaryParameter::type is of type string.
503 bndParam_[intersection.boundarySegmentIndex()] = std::to_string(boundaryIds[factory.insertionIndex(intersection)]);
504 }
505 }
506 }
507 }
508 }
509 }
510
511 template <class Entity>
513 {
514 const auto gridView = gridPtr_->levelGridView( 0 );
515 switch( (int)Entity::codimension )
516 {
517 case 0 :
518 if( nofElParam_ > 0 ) {
519 if ( gridView.indexSet().index( entity ) >= elParam_.size() )
520 elParam_.resize( gridView.indexSet().index( entity ) );
521 return elParam_[ gridView.indexSet().index( entity ) ];
522 }
523 break;
524 case GridType::dimension :
525 if( nofVtxParam_ > 0 ) {
526 if ( gridView.indexSet().index( entity ) >= vtxParam_.size() )
527 vtxParam_.resize( gridView.indexSet().index( entity ) );
528 return vtxParam_[ gridView.indexSet().index( entity ) ];
529 }
530 break;
531 }
532 return emptyParam_;
533 }
534
535 void setNofParams( int cdim, int nofP )
536 {
537 switch (cdim) {
538 case 0 : nofElParam_ = nofP; break;
539 case GridType::dimension : nofVtxParam_ = nofP; break;
540 }
541 }
542
544 : public CommDataHandleIF< DataHandle, char >
545 {
546 explicit DataHandle ( GridPtr &gridPtr )
547 : gridPtr_( gridPtr ), idSet_( gridPtr->localIdSet() )
548 {
549 const auto gridView = gridPtr_->levelGridView( 0 );
550
551 if( gridPtr_.nofElParam_ > 0 || gridPtr_.nofVtxParam_ > 0 || gridPtr_.haveBndParam_ )
552 {
553 const auto &indexSet = gridView.indexSet();
554 for( const auto &element : elements( gridView, Partitions::interiorBorder ) )
555 {
556 if( gridPtr_.nofElParam_ > 0 )
557 std::swap( gridPtr_.elParam_[ indexSet.index( element ) ], elData_[ idSet_.id( element ) ] );
558
559 if( gridPtr_.nofVtxParam_ > 0 )
560 {
561 for( unsigned int v = 0, n = element.subEntities( dimension ); v < n; ++v )
562 {
563 const auto index = indexSet.subIndex( element, v, dimension );
564 if ( !gridPtr_.vtxParam_[ index ].empty() )
565 std::swap( gridPtr_.vtxParam_[ index ], vtxData_[ idSet_.subId( element, v, dimension ) ] );
566 }
567 }
568
569 if( gridPtr_.haveBndParam_ && element.hasBoundaryIntersections() )
570 {
571 for( const auto &intersection : intersections( gridView, element ) )
572 {
573 // dirty hack: check for "none" to make corner point grid work
574 if( !intersection.boundary() || intersection.type().isNone() )
575 continue;
576
577 const int i = intersection.indexInInside();
578 auto &bndData = bndData_[ idSet_.subId( element, i, 1 ) ];
579 bndData.first = gridPtr_.bndId_[ indexSet.subIndex( element, i, 1 ) ];
580 if( gridPtr_.haveBndParam_ )
581 std::swap( bndData.second, gridPtr_.bndParam_[ intersection.boundarySegmentIndex() ] );
582 }
583 }
584 }
585 }
586 }
587
588 DataHandle ( const DataHandle & ) = delete;
589 DataHandle ( DataHandle && ) = delete;
590
592 {
593 const auto gridView = gridPtr_->levelGridView( 0 );
594
595
596 if( gridPtr_.nofElParam_ > 0 || gridPtr_.nofVtxParam_ > 0 || gridPtr_.haveBndParam_ )
597 {
598 const auto &indexSet = gridView.indexSet();
599
600 if( gridPtr_.nofElParam_ > 0 )
601 gridPtr_.elParam_.resize( indexSet.size( 0 ) );
602 if( gridPtr_.nofVtxParam_ > 0 )
603 gridPtr_.vtxParam_.resize( indexSet.size( dimension ) );
604 if( gridPtr_.haveBndParam_ )
605 {
606 gridPtr_.bndId_.resize( indexSet.size( 1 ) );
607 gridPtr_.bndParam_.resize( gridPtr_->numBoundarySegments() );
608 }
609
610 for( const auto &element : elements( gridView, Partitions::all ) )
611 {
612 if( gridPtr_.nofElParam_ > 0 )
613 {
614 std::swap( gridPtr_.elParam_[ indexSet.index( element ) ], elData_[ idSet_.id( element ) ] );
615 assert( gridPtr_.elParam_[ indexSet.index( element ) ].size() == static_cast< std::size_t >( gridPtr_.nofElParam_ ) );
616 }
617
618 if( gridPtr_.nofVtxParam_ > 0 )
619 {
620 for( unsigned int v = 0; v < element.subEntities( dimension ); ++v )
621 {
622 const auto index = indexSet.subIndex( element, v, dimension );
623 if( gridPtr_.vtxParam_[ index ].empty() )
624 std::swap( gridPtr_.vtxParam_[ index ], vtxData_[ idSet_.subId( element, v, dimension ) ] );
625 assert( gridPtr_.vtxParam_[ index ].size() == static_cast< std::size_t >( gridPtr_.nofVtxParam_ ) );
626 }
627 }
628
629 if( gridPtr_.haveBndParam_ && element.hasBoundaryIntersections() )
630 {
631 for( const auto &intersection : intersections( gridView, element ) )
632 {
633 // dirty hack: check for "none" to make corner point grid work
634 if( !intersection.boundary() || intersection.type().isNone() )
635 continue;
636
637 const int i = intersection.indexInInside();
638 auto &bndData = bndData_[ idSet_.subId( element, i, 1 ) ];
639 gridPtr_.bndId_[ indexSet.subIndex( element, i, 1 ) ] = bndData.first;
640 if( gridPtr_.haveBndParam_ )
641 std::swap( bndData.second, gridPtr_.bndParam_[ intersection.boundarySegmentIndex() ] );
642 }
643 }
644 }
645 }
646 }
647
649
650 bool contains ( int dim, int codim ) const
651 {
652 assert( dim == dimension );
653 // do not use a switch statement, because dimension == 1 is possible
654 return (codim == 1) || ((codim == dimension) && (gridPtr_.nofVtxParam_ > 0)) || ((codim == 0) && (gridPtr_.nofElParam_ > 0));
655 }
656
657 bool fixedSize (int /* dim */, int /* codim */) const { return false; }
658
659 template< class Entity >
660 std::size_t size ( const Entity &entity ) const
661 {
662 std::size_t totalSize = 0;
663
664 // do not use a switch statement, because dimension == 1 is possible
665 if( (Entity::codimension == 0) && (gridPtr_.nofElParam_ > 0) )
666 {
667 assert( elData_[ idSet_.id( entity ) ].size() == static_cast< std::size_t >( gridPtr_.nofElParam_ ) );
668 for( double &v : elData_[ idSet_.id( entity ) ] )
669 totalSize += dataSize( v );
670 }
671
672 if( (Entity::codimension == dimension) && (gridPtr_.nofVtxParam_ > 0) )
673 {
674 assert( vtxData_[ idSet_.id( entity ) ].size() == static_cast< std::size_t >( gridPtr_.nofVtxParam_ ) );
675 for( double &v : vtxData_[ idSet_.id( entity ) ] )
676 totalSize += dataSize( v );
677 }
678
679 if( Entity::codimension == 1 )
680 {
681 const auto bndData = bndData_.find( idSet_.id( entity ) );
682 if( bndData != bndData_.end() )
683 totalSize += dataSize( bndData->second.first ) + dataSize( bndData->second.second );
684 }
685
686 return totalSize;
687 }
688
689 template< class Buffer, class Entity >
690 void gather ( Buffer &buffer, const Entity &entity ) const
691 {
692 // do not use a switch statement, because dimension == 1 is possible
693 if( (Entity::codimension == 0) && (gridPtr_.nofElParam_ > 0) )
694 {
695 assert( elData_[ idSet_.id( entity ) ].size() == static_cast< std::size_t >( gridPtr_.nofElParam_ ) );
696 for( double &v : elData_[ idSet_.id( entity ) ] )
697 write( buffer, v );
698 }
699
700 if( (Entity::codimension == dimension) && (gridPtr_.nofVtxParam_ > 0) )
701 {
702 assert( vtxData_[ idSet_.id( entity ) ].size() == static_cast< std::size_t >( gridPtr_.nofVtxParam_ ) );
703 for( double &v : vtxData_[ idSet_.id( entity ) ] )
704 write( buffer, v );
705 }
706
707 if( Entity::codimension == 1 )
708 {
709 const auto bndData = bndData_.find( idSet_.id( entity ) );
710 if( bndData != bndData_.end() )
711 {
712 write( buffer, bndData->second.first );
713 write( buffer, bndData->second.second );
714 }
715 }
716 }
717
718 template< class Buffer, class Entity >
719 void scatter ( Buffer &buffer, const Entity &entity, std::size_t n )
720 {
721 // do not use a switch statement, because dimension == 1 is possible
722 if( (Entity::codimension == 0) && (gridPtr_.nofElParam_ > 0) )
723 {
724 auto &p = elData_[ idSet_.id( entity ) ];
725 p.resize( gridPtr_.nofElParam_ );
726 for( double &v : p )
727 read( buffer, v, n );
728 }
729
730 if( (Entity::codimension == dimension) && (gridPtr_.nofVtxParam_ > 0) )
731 {
732 auto &p = vtxData_[ idSet_.id( entity ) ];
733 p.resize( gridPtr_.nofVtxParam_ );
734 for( double &v : p )
735 read( buffer, v, n );
736 }
737
738 if( (Entity::codimension == 1) && (n > 0) )
739 {
740 auto &bndData = bndData_[ idSet_.id( entity ) ];
741 read( buffer, bndData.first, n );
742 read( buffer, bndData.second, n );
743 }
744
745 assert( n == 0 );
746 }
747
748 private:
749 template< class T >
750 static std::enable_if_t< std::is_trivially_copyable< T >::value, std::size_t > dataSize ( const T & /* value */ )
751 {
752 return sizeof( T );
753 }
754
755 static std::size_t dataSize ( const std::string &s )
756 {
757 return dataSize( s.size() ) + s.size();
758 }
759
760 template< class Buffer, class T >
761 static std::enable_if_t< std::is_trivially_copyable< T >::value > write ( Buffer &buffer, const T &value )
762 {
763 std::array< char, sizeof( T ) > bytes;
764 std::memcpy( bytes.data(), &value, sizeof( T ) );
765 for( char &b : bytes )
766 buffer.write( b );
767 }
768
769 template< class Buffer >
770 static void write ( Buffer &buffer, const std::string &s )
771 {
772 write( buffer, s.size() );
773 for( const char &c : s )
774 buffer.write( c );
775 }
776
777 template< class Buffer, class T >
778 static std::enable_if_t< std::is_trivially_copyable< T >::value > read ( Buffer &buffer, T &value, std::size_t &n )
779 {
780 assert( n >= sizeof( T ) );
781 n -= sizeof( T );
782
783 std::array< char, sizeof( T ) > bytes;
784 for( char &b : bytes )
785 buffer.read( b );
786 std::memcpy( &value, bytes.data(), sizeof( T ) );
787 }
788
789 template< class Buffer >
790 static void read ( Buffer &buffer, std::string &s, std::size_t &n )
791 {
793 read( buffer, size, n );
794 s.resize( size );
795
796 assert( n >= size );
797 n -= size;
798
799 for( char &c : s )
800 buffer.read( c );
801 }
802
803 GridPtr &gridPtr_;
804 const typename GridType::LocalIdSet &idSet_;
807 };
808
809 // grid auto pointer
811 // element and vertex parameters
817
821 }; // end of class GridPtr
822
823} // end namespace Dune
824
825#endif
Describes the parallel communication interface class for MessageBuffers and DataHandles.
int size() const
bool empty() const
static constexpr IntegralRange< T > range(T from, T to) noexcept
size_type dim() const
std::ptrdiff_t index() const
#define DUNE_THROW(E,...)
@ ForwardCommunication
communicate as given in InterfaceType
Definition gridenums.hh:171
@ InteriorBorder_All_Interface
send interior and border, receive all entities
Definition gridenums.hh:88
const IndexSet & indexSet() const
obtain the index set
Definition common/gridview.hh:177
constexpr All all
PartitionSet for all partitions.
Definition partitionset.hh:295
constexpr InteriorBorder interiorBorder
PartitionSet for the interior and border partitions.
Definition partitionset.hh:286
Include standard header files.
MPI_Comm MPICommunicator
static MPICommunicator getCommunicator()
Definition dgfgridfactory.hh:38
const DGFBoundaryParameter::type & boundaryParameter(const Intersection< GG, II > &) const
Definition dgfgridfactory.hh:158
int boundaryId(const Intersection &intersection) const
Definition dgfgridfactory.hh:102
Grid * grid()
Definition dgfgridfactory.hh:90
std::vector< double > & parameter(const Element &element)
Definition dgfgridfactory.hh:124
bool haveBoundaryParameters() const
Definition dgfgridfactory.hh:151
Intersection of a mesh entity of codimension 0 ("element") with a "neighboring" element or with the d...
Definition common/intersection.hh:164
size_t boundarySegmentIndex() const
index of the boundary segment within the macro grid
Definition common/intersection.hh:236
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition datahandleif.hh:78
Wrapper class for entities.
Definition common/entity.hh:66
static constexpr int codimension
Know your own codimension.
Definition common/entity.hh:106
Base class for exceptions in Dune grid modules.
Definition exceptions.hh:20
virtual unsigned int insertionIndex(const typename Codim< 0 >::Entity &entity) const
obtain an element's insertion index
Definition common/gridfactory.hh:181
Provide a generic factory class for unstructured grids.
Definition common/gridfactory.hh:275
virtual std::unique_ptr< GridType > createGrid()
Finalize grid creation and hand over the grid.
Definition common/gridfactory.hh:333
Grid view abstract base class.
Definition common/gridview.hh:66
exception class for IO errors in the DGF parser
Definition dgfexception.hh:16
Class for constructing grids from DGF files.
Definition gridptr.hh:66
GridPtr(std::istream &input, MPICommunicatorType comm=MPIHelper::getCommunicator())
constructor given a std::istream
Definition gridptr.hh:199
const std::vector< double > & parameters(const Entity &entity) const
get parameters defined for each codim 0 und dim entity on the grid through the grid file
Definition gridptr.hh:325
GridPtr()
Default constructor, creating empty GridPtr.
Definition gridptr.hh:217
const GridType & operator*() const
return const reference to GridType instance
Definition gridptr.hh:288
bool haveBndParam_
Definition gridptr.hh:820
static const int dimension
Definition gridptr.hh:155
std::vector< int > bndId_
Definition gridptr.hh:815
void setNofParams(int cdim, int nofP)
Definition gridptr.hh:535
void loadBalance()
Definition gridptr.hh:369
std::vector< DGFBoundaryParameter::type > bndParam_
Definition gridptr.hh:814
void initialize(GridFactory< GridType > &factory, std::vector< int > &boundaryIds, std::vector< int > &elementIds)
Definition gridptr.hh:463
GridPtr(GridType *grd)
Constructor storing given pointer to internal auto pointer.
Definition gridptr.hh:230
int nofElParam_
Definition gridptr.hh:818
const DGFBoundaryParameter::type & parameters(const Intersection< GridImp, IntersectionImp > &intersection) const
get parameters for intersection
Definition gridptr.hh:351
GridType & operator*()
return reference to GridType instance
Definition gridptr.hh:278
static bool isEmpty(Range &&range)
Definition gridptr.hh:381
int nofParameters(const Entity &) const
get parameters defined for given entity
Definition gridptr.hh:311
GridPtr(const std::string &filename, MPICommunicatorType comm=MPIHelper::getCommunicator())
constructor given the name of a DGF file
Definition gridptr.hh:158
std::vector< std::vector< double > > elParam_
Definition gridptr.hh:812
MPIHelper::MPICommunicator MPICommunicatorType
Definition gridptr.hh:154
GridPtr & operator=(const GridPtr &org)
assignment of grid pointer
Definition gridptr.hh:246
int nofParameters(int cdim) const
get number of parameters defined for a given codimension
Definition gridptr.hh:301
int nofParameters(const Intersection< GridImp, IntersectionImp > &intersection) const
get number of parameters defined for a given intersection
Definition gridptr.hh:318
std::vector< double > emptyParam_
Definition gridptr.hh:816
mygrid_ptr gridPtr_
Definition gridptr.hh:810
void readGmsh(const std::string &, std::integral_constant< bool, false >)
Definition gridptr.hh:147
void readGmsh(const std::string &filename, std::integral_constant< bool, true >)
Definition gridptr.hh:137
std::vector< double > & params(const Entity &entity)
Definition gridptr.hh:512
void initialize(DGFGridFactory< GridType > &dgfFactory)
Definition gridptr.hh:386
GridPtr(const GridPtr &org)=default
Copy constructor, copies internal auto pointer.
std::string getFileExtension(const std::string &filename) const
Definition gridptr.hh:122
const GridType * operator->() const
return const pointer to GridType instance
Definition gridptr.hh:293
GridType * release()
release pointer from internal ownership
Definition gridptr.hh:298
void communicate()
Definition gridptr.hh:360
std::vector< std::vector< double > > vtxParam_
Definition gridptr.hh:813
GridType * operator->()
return pointer to GridType instance
Definition gridptr.hh:283
int nofVtxParam_
Definition gridptr.hh:819
Definition gridptr.hh:68
mygrid_ptr(GridType *grd)
Definition gridptr.hh:99
~mygrid_ptr()
Definition gridptr.hh:102
GridType * release()
Definition gridptr.hh:112
mygrid_ptr(const mygrid_ptr &other)
Definition gridptr.hh:97
mygrid_ptr & operator=(const mygrid_ptr &other)
Definition gridptr.hh:105
mygrid_ptr()
Definition gridptr.hh:95
Definition gridptr.hh:545
CommDataHandleIF< DataHandle, char > & interface()
Definition gridptr.hh:648
DataHandle(const DataHandle &)=delete
~DataHandle()
Definition gridptr.hh:591
DataHandle(GridPtr &gridPtr)
Definition gridptr.hh:546
void gather(Buffer &buffer, const Entity &entity) const
Definition gridptr.hh:690
bool fixedSize(int, int) const
Definition gridptr.hh:657
std::size_t size(const Entity &entity) const
Definition gridptr.hh:660
DataHandle(DataHandle &&)=delete
void scatter(Buffer &buffer, const Entity &entity, std::size_t n)
Definition gridptr.hh:719
bool contains(int dim, int codim) const
Definition gridptr.hh:650
static const type & defaultValue()
default constructor
Definition parser.hh:28
static std::unique_ptr< Grid > read(const std::string &fileName, bool verbose=true, bool insertBoundarySegments=true)
Definition gmshreader.hh:203
T data(T... args)
T empty(T... args)
T find_last_of(T... args)
GridType get(GridType ... args)
T memcpy(T... args)
T resize(T... args)
T size(T... args)
T substr(T... args)
GridType swap(GridType ... args)
T to_string(T... args)
GridType use_count(GridType ... args)