dune-fem school 2016 - universität stuttgart · dune-fem school 2016 dune-fem school 2016 the...
TRANSCRIPT
Dune-Fem School 2016
DUNE-FEM School 2016The Dune-Grid Interface Classes
Claus-Justus Heine, Robert Klöfkorn,Andreas Dedner, Martin Nolte, Christoph Gersbacher
September 26-30, 2016Stuttgart, Germany
Institute for Applied Analysis andNumerical Simulation
University of Stuttgart
www.ians.uni-stuttgart.de
International Research
Institute of Stavanger
www.iris.no
An Overview of DUNE-GRID
Outline
1 An Overview of DUNE-GRID
2 Hierarchical Grids
3 Grid Parts
4 The DUNE Interface for Hierarchical Grids
5 Construction of Hierarchical Grids
6 The DUNE Grid File (DGF) Format
7 The ”Hello Grid” Program
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 2 / 51
An Overview of DUNE-GRID
Why DUNE-GRID?
Numerical methods for solving PDEs are often grid-based, e.g.,• Finite Volume methods,• Finite Element methods,• Discontinuous Galerkin methods.
Often, grids from complex software toolboxes are used, e.g.,ALBERTA Adaptive, hierarchical Finite Element toolbox based a
simplicial grid using bisection refinement.UG Toolbox for the parallel solution of PDEs on unstructured
grids using multigrid methods.
Problems: What if my toolbox does not implement a desired feature?
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 3 / 51
An Overview of DUNE-GRID
What is DUNE-GRID?
The DUNE-GRID module defines a slim interface for• adaptive,• hierarchically nested,• possibly nonconforming,• parallel,• multi element type,• ...
grids in arbitrary space dimensions.
A (hierarchical) grid is seen as a parallel container of entities (points,lines, faces, elements, ...) endowed with a hierarchy.
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 4 / 51
Notes
Notes
Notes
Notes
An Overview of DUNE-GRID
Grid Implementations
List of grid implementations shipped with DUNE-GRID:AlbertaGrid Unstructured simplex grid based using ALBERTA
(1–3d, bisection refinement)GeometryGrid Meta grid exchanging the host grid’s geometry
OneDGrid Locally adaptive grid of an interval (1d)SGrid Cartesian grid (1–3d, global refinement)
YaspGrid Parallel, Cartesian grid (1–3d, global refinement)
Important other grid modules DUNE-ALUGRID and DUNE-UGGRID :ALUGrid Parallel, unstructured grid based on ALUGrid library
(2–3d, simplices or cubes, red refinement andbisection, dynamic load balancing)
UGGrid Parallel, unstructured grid based using UG (2–3d,multi element type, red-green refinement, dynamicload balancing)
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 5 / 51
An Overview of DUNE-GRID
Grid Implementations
List of grid implementations shipped with DUNE-GRID:AlbertaGrid Unstructured simplex grid based using ALBERTA
(1–3d, bisection refinement)GeometryGrid Meta grid exchanging the host grid’s geometry
OneDGrid Locally adaptive grid of an interval (1d)SGrid Cartesian grid (1–3d, global refinement)
YaspGrid Parallel, Cartesian grid (1–3d, global refinement)Important other grid modules DUNE-ALUGRID and DUNE-UGGRID :
ALUGrid Parallel, unstructured grid based on ALUGrid library(2–3d, simplices or cubes, red refinement andbisection, dynamic load balancing)
UGGrid Parallel, unstructured grid based using UG (2–3d,multi element type, red-green refinement, dynamicload balancing)
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 5 / 51
An Overview of DUNE-GRID
Futher Grid Implementations
List of implementations written outside of DUNE-GRID:FoamGrid Unstructured grid supporting non-manifold
topologies (2d)MultiDomainGrid Meta grid dividing the host grid into several
subdomains (treated as separate grids)NetworkGrid Unstructured 1d interval network in R3
ParallelSimplexGrid Unstructured, parallel simplex grid (nd)PrismGrid Meta grid adding an additional dimension
using prismatic elementsSPGrid Very efficient parallel, Cartesian Grid (nd,
global refinement)SubGrid Meta grid allowing to select of a subset of
the grid hierarchyMore grid implementations on www.dune-project.org.
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 6 / 51
Hierarchical Grids
Outline
1 An Overview of DUNE-GRID
2 Hierarchical Grids
3 Grid Parts
4 The DUNE Interface for Hierarchical Grids
5 Construction of Hierarchical Grids
6 The DUNE Grid File (DGF) Format
7 The ”Hello Grid” Program
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 7 / 51
Notes
Notes
Notes
Notes
Hierarchical Grids
Example of a Hierarchical Grid
Example of a macro grid for an interval (a,b):
G0
Possible hierarchy (created through successive refinement):
Gleaf
G0
G1
G2
G3
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 8 / 51
Hierarchical Grids
Entities
Entities model the elements, faces, edges, and vertices of a(hierarchical) grid.
Each entity e is assigned• a codimension c
(w.r.t. the grid dimension),• a level in the hierarchy,• a reference element Re,• a geometric realization,• a partition type
(in parallel computations).
c = 3
c = 1
c = 2
Subentities of a prism (c = 0)
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 9 / 51
Hierarchical Grids
Elements (Entities of Codimension 0)
Elements (i.e., entities of codimension 0) additionally provide• access to their subentities,• their father (if they have one),• their geometric relation to their father,• an iterator over their children.
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 10 / 51
Hierarchical Grids
Geometric Realization of Entities
Let e be an entity with reference element Re.
Its geometric realization is Fe(Re), where Fe : Re → Rw is a givenreference mapping. w is called the world dimension.
Fe(Re)
Re
Fe
Assumptions:• Fe is a C1-Diffeomorphism between Re and Fe(Re).• Consistency of the geometric realization of subentities.
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 11 / 51
Notes
Notes
Notes
Notes
Hierarchical Grids
DUNE Reference Elements
DUNE provides a predefined set of reference elements Rd for eachdimension d ≥ 0.
They are defined recursively over d :d = 0: We set R0 := P.d 7→ d + 1 : For R ∈ Rd we define:
R: the pyramid over R,R|: the prism over R.We set Rd+1 := R,R| |R ∈ Rd.
Notice: P = P| for d = 1.
2(1,1,0)
1(1,0,0)
0(0,0,0)
4(0,0,1)
5(0,1,1)
1(1,0,0)
0(0,0,0)
3(0,0,1)
4(1,0,1)
10(0,0,0)
3(0,0,1)
3(1,1,0)
6(0,1,1)
7(1,1,1)
1(1,0,0)
0(0,0,0)
4(0,0,1)
Set of 3d reference elements
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 12 / 51
Hierarchical Grids
Hierarchical Grids
Example:Hierarchical Grid:
G = G0, . . . ,G3, Gl = E0l , E
1l .
E0l set of intervals in Gl
E1l set of vertices in Gl Gleaf
G0
G1
G2
G3
Some Definitions:
• We say that e ∈ Ecl has codimension c and level l .
• Every element e ∈ E0l+1 has been created from an element f ∈ E0
l ,which we call its father. Conversely, we say that e is a child of f .
• The leaf grid Gleaf consists of all elements e ∈⋃
l E0l that have no
children and their subentities.
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 13 / 51
Grid Parts
Outline
1 An Overview of DUNE-GRID
2 Hierarchical Grids
3 Grid Parts
4 The DUNE Interface for Hierarchical Grids
5 Construction of Hierarchical Grids
6 The DUNE Grid File (DGF) Format
7 The ”Hello Grid” Program
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 14 / 51
Grid Parts
DUNE-FEM Grid Parts
A grid part is a non-overlapping set of entities, such as• a grid level (LevelGridPart),• the leaf grid (LeafGridPart),• meta grid parts, i.e., grid parts implemented through another grid
part (e.g., FilteredGridPart).
It provides ...• ... iterators over entities of a given codimension.• ... access to intersections between neighboring elements or
between elements and the domain boundary.• ... a set of indices allowing to relate data to specific entities.• ... data exchange for entities shared between processes (in
parallel computations).
In DUNE-GRID, a similar concept, the grid view, exists:auto gridView = static_cast< typename GridPart::GridView > (gridPart);
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 15 / 51
Notes
Notes
Notes
Notes
Grid Parts
Grid parts: Intersections
Grid parts provide access to intersections of an element (inside) with• neighboring elements (outside),• the domain boundary.
Intersections provide access to• the adjacent elements (inside / outside),• the normal n (to the inside element).
n
intersection inside
outside
• the geometric realization of the intersection,• its relative position within the reference elements of inside and
outside,• boundary information (for boundary intersections),
Note: Intersections depend on element where intersection iterator wasinitiated.
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 16 / 51
Grid Parts
Index Sets
Observations:• Numerical algorithms need to attach DoFs to entities.• For linear algebra, DoFs must often be numbered consecutively.
For a set E of indices, we seek a bijective index mapping
IE : E → 0, . . . ,nE − 1.
We say that ...• ... the number i = IE (e) is the index of the entity e ∈ E .• ... the set IE (E ) is a set of indices.• ... the size of IE (E ) is nE .
A grid part G provides such a mapping for each set of entities ER ∈ Gwith a commen reference element R.
Note: There is no efficient way to obtain the entity from its index.DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 17 / 51
Grid Parts
Grid parts: Iterators (traditional way)Entities are accessed through iterators on the grid part.
STL-like interface:
static const int c = 0; // ElementsgridPart.template begin<c>() // first entity of codim cgridPart.template end<c>() // behind the last entity of codim c
Example: Loop over all entities of codimendion c:
typedef typename GridPartType::template Codim<c>::IteratorTypeIteratorType;
typedef typename GridPartType::template Codim<c>::EntityTypeEntityType;
const IteratorType end = gridPart.template end<c>();for( IteratorType it = gridPart.template begin<c>(); it != end; ++it )const EntityType &entity = *it;// code to obtain some typesconst typename EntityType::Geometry Geometry;// code to be performed on the entityconst Geometry geometry = entity.geometry();
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 18 / 51
Grid Parts
Grid parts: Iterators (using auto)
Entities are accessed through iterators on the grid part.
STL-like interface:
static const int c = 0; // ElementsgridPart.template begin<c>() // first entity of codim cgridPart.template end<c>() // behind the last entity of codim c
Example: Loop over all entities of codimendion c using auto
const auto end = gridPart.template end<c>();for( auto it = gridPart.template begin<c>(); it != end; ++it )// dereference iterator for performance reasonsconst auto entity = *it;// code to be performed on the entityconst auto geometry = entity.geometry();
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 19 / 51
Notes
Notes
Notes
Notes
Grid Parts
Grid parts: construction 1/2
Almost all parts of DUNE-FEM are based on a given grid part.In general grid parts are constructed given a hierarchical DUNE grid:AdaptiveLeafGridPart<HGridType> gridPart(grid);
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 20 / 51
Grid Parts
Grid parts: construction 2/2
In addition some meta grid parts are available in DUNE-FEM. These use a host grid part.Example: filtered grid part:
typedef Adapt iveLeafGr idPar t <HGridType> HostGridPartType ;HostGridPartType hos tGr idPar t ( g r i d ) ;
typedef R a d i a l F i l t e r < HostGridPartType > F i l t e r T y p e ;
/ / cons t ruc t f i l t e rtypename F i l t e r T y p e : : GlobalCoordinateType center ( 0 ) ;const double rad ius = 0 .15 ;F i l t e r T y p e f i l t e r ( hostGr idPar t , center , rad ius ) ;
/ / cons t ruc t f i l t e r e d g r i d pa r ttypedef Dune : : Fem : : F i l t e r e d G r i d P a r t < HostGridPartType , F i l t e r T y p e >
GridPartType ;GridPartType g r i d P a r t ( hostGr idPar t , f i l t e r ) ;
The filter has a method
bool conta ins ( const E n t i t y &e n t i t y ) const
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 21 / 51
Grid Parts
Grid Parts: Index Set Interface
Index sets export the IndexType and provide the following methods(incomplete list):// check whether an entity is contained in the index settemplate< class Entity >bool contains ( const Entity &e ) const;
// map an entity e to an indextemplate< class Entity >IndexType index ( const Entity &e ) const;
// map subentity (i,c) of an entity e to an indextemplate< class Entity >IndexType subIndex ( const Entity &e,
int i, unsigned int c ) const;
// obtain number of entities for type of reference elementIndexType size ( GeometryType type ) const;// obtain number of entities for a codimensionIndexType size ( int codim ) const;
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 22 / 51
Grid Parts
Grid Parts: Index Sets Example
Example:const typename GridPartType::IndexSetType &indexSet= gridPart.indexSet();
assert( indexSet.contains( entity ) );
typedef typename EntityType::template Codim<c>::Entity SubEntityType;
const SubEntityType subEntity= entity.template subEntity<c>( 0 );
// the right hand side may be more efficientassert( indexSet.index( subEntity )
== indexSet.subIndex( entity, 0, c ) );
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 23 / 51
Notes
Notes
Notes
Notes
The DUNE Interface for Hierarchical Grids
Outline
1 An Overview of DUNE-GRID
2 Hierarchical Grids
3 Grid Parts
4 The DUNE Interface for Hierarchical Grids
5 Construction of Hierarchical Grids
6 The DUNE Grid File (DGF) Format
7 The ”Hello Grid” Program
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 24 / 51
The DUNE Interface for Hierarchical Grids
The Entity Interface
View Concept:An entity is a read-only object, i.e., it cannot be modified and it shouldonly be stored locally.
Warning: The entity is returned by value, i.e., each call results in anew copy. Avoid performance bottleneck by storing a local copy.
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 25 / 51
The DUNE Interface for Hierarchical Grids
The Entity Interface
class Entity// ...
public:static const int codimension;static const int mydimension;
int level () const;
Dune::GeometryType type () const;
Geometry geometry () const;
// obtain partition type (in parallel computations)Dune::PartitionType partitionType () const;
// return minimal information to create this entity (for storage)EntitySeed seed () const;
// ...;
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 26 / 51
The DUNE Interface for Hierarchical Grids
Codim 0: Extended Entity Interface
Entities of codimension 0 (elements) provide additional methods totraverse the grid hierarchy:class Entity// ...
public:bool hasFather () const;Entity father () const;
int subEntities( int codim ) const;template <int cd>typename Codim< cd >::Entity subEntity( int i ) const;
LocalGeometry geometryInFather () const;
bool isLeaf () const;
HierarchicIterator hbegin ( int maxlevel ) const;HierarchicIterator hend ( int maxlevel ) const;// ...
;
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 27 / 51
Notes
Notes
Notes
Notes
The DUNE Interface for Hierarchical Grids
The Geometry Interface
Let e be an entity with reference element Re. The class Geometry
represents the reference mapping Fe : Re → Rw .
The class exports two types:LocalCoordinate for x ∈ Re,GlobalCoordinate for
x ∈ Fe(Re) ⊂ Rw .
Fe(Re)
Re
Fe
The geometry is obtained from the Entity by:const Geometry geometry = entity.geometry();
Warning: The geometry is returned by value, i.e., each call results in anew copy.
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 28 / 51
The DUNE Interface for Hierarchical Grids
DUNE Geometry Interface
The following methods describe the geometric realization Fe(Re):class Geometry// ...
public:int corners () const;GlobalCoordinate corner ( int i ) const;
GlobalCoordinate center () const;
ctype volume () const;
// ...;
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 29 / 51
The DUNE Interface for Hierarchical Grids
DUNE Geometry Interface
The folloing methods describe the reference mapping Fe:class Geometry// ...
public:bool affine () const;
GlobalCoordinate global ( const LocalCoordinate &local ) const;
LocalCoordinate local ( const GlobalCoordinate &global ) const;
const JacobianTransposed &jacobianTransposed ( const LocalCoordinate &local ) const;
const JacobianInverseTransposed &jacobianInverseTransposed ( const LocalCoordinate &local ) const;
// ...;
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 30 / 51
The DUNE Interface for Hierarchical Grids
The Geometry Type
Some grid objects (Entity, Geometry, Intersection) have anassociated reference element.
Each provides a methodDune::GeometryType type () const;
The return value uniquely identifies the associated type of referenceelement.
Information about the actual reference element is collected in the classtemplate Dune::ReferenceElement.
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 31 / 51
Notes
Notes
Notes
Notes
The DUNE Interface for Hierarchical Grids
Obtaining Types
The type of all parameters in a class’s methods are exported by theclass.
Types can be obtained in many different ways, e.g.,typename GridView::template Codim< 0 >::Iterator;typename Iterator::Entity Entity;typename Entity::Geometry;
typename GridView::template Codim< 0 >::Iterator;typename GridView::template Codim< 0 >::Entity;typename GridView::template Codim< 0 >::Geometry;
The Codim structure contains most types.
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 32 / 51
The DUNE Interface for Hierarchical Grids
Capabilities
A DUNE grid is not required to model all entities. You can test for themthrough a capability:const bool Dune::Capabilities::hasEntity< Grid, codim >::v;
For codimension 0 and d , this capability must be true.
You can also check whether a grid has only a single element type:const bool Dune::Capabilities::hasSingleGeometryType< Grid >::v;
An additional value tells you the corresponding type of referenceelement:const unsigned int id= Dune::Capabilities::hasSingleGeometryType< Grid >::topologyId;Dune::GeometryType gt( id, Grid::dimension );
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 33 / 51
The DUNE Interface for Hierarchical Grids
Further Capabilities
Here’s a complete list of DUNE-GRID capabilities:const bool Dune::Capabilities::isCartesian< Grid >::v;
const bool Dune::Capabilities::hasEntity< Grid, codim >::v;
const bool Dune::Capabilities::isParallel< Grid >::v;
const bool Dune::Capabilities::canCommunicate< Grid, codim >::v;
const bool Dune::Capabilities::hasBackupRestoreFacilities< Grid >::v;
const bool Dune::Capabilities::hasSingleGeometryType< Grid >::v;
const bool Dune::Capabilities::isLeafwiseConforming< Grid >::v;
const bool Dune::Capabilities::isLevelwiseConforming< Grid >::v;
const bool Dune::Capabilities::threadSafe< Grid >::v;
const bool Dune::Capabilities::viewThreadSafe< Grid >::v;
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 34 / 51
Construction of Hierarchical Grids
Outline
1 An Overview of DUNE-GRID
2 Hierarchical Grids
3 Grid Parts
4 The DUNE Interface for Hierarchical Grids
5 Construction of Hierarchical Grids
6 The DUNE Grid File (DGF) Format
7 The ”Hello Grid” Program
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 35 / 51
Notes
Notes
Notes
Notes
Construction of Hierarchical Grids
Unified Grid Construction?
Problem: Each grid implementation has its own• constructor,• native file format.
Questions: Can I ...• ... use different grid implementations without rewriting my code?• ... import macro grids into different grid implementations without
special file conversion utitilities?
Answers:• In general, this is not possible.• However, large classes of macro grids can be used to construct
many different grid implementations.
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 36 / 51
Construction of Hierarchical Grids
Common Grid Construction Mechanisms
Common mechanisms for grid construction:• For each “unstructured grid”, there is a GridFactory. It allows
construction of macro grids from vertex coordinates and elements.• A StructuredGridFactory can be used to construct Cartesian
macro grids (possibly split into simplices).• A simple, text-based file format, the DUNE Grid File (DGF) Format,
has been designed for the construction of any grid implementation(as long as it can represent the macro grid).
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 37 / 51
Construction of Hierarchical Grids
Common File Readers
Based on the GridFactory some file readers for unstructured gridshave been implemented:• The AlbertaReader reads native ALBERTA mesh files (into any
unstructured grid).• The AmiraMeshReader reads files in AmiraMesh format.• The GmshReader reads files in Gmsh1 format.
Adding another reader for some interesting file format only requires anunderstanding of the GridFactory.
1 http://geuz.org/gmsh/.
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 38 / 51
The DUNE Grid File (DGF) Format
Outline
1 An Overview of DUNE-GRID
2 Hierarchical Grids
3 Grid Parts
4 The DUNE Interface for Hierarchical Grids
5 Construction of Hierarchical Grids
6 The DUNE Grid File (DGF) Format
7 The ”Hello Grid” Program
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 39 / 51
Notes
Notes
Notes
Notes
The DUNE Grid File (DGF) Format
The DUNE Grid File (DGF) Format
Goals: DGF shall . . .• . . . allow simple description of macro grids,• . . . work for every DUNE grid implementation (structured and
unstructured),• . . . be as independent as possible from the grid implementation,• . . . be extendable to special grid functionalities,• . . . easy to extend to new grids.
Structure: A DGF file consists of blocks (at least one):
INTERVAL SIMPLEX SIMPLEXGENERATOR PROJECTION
VERTEX CUBE GRIDPARAMETER . . .
Warning: The generated macro grid strongly depends on the gridimplementation.
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 40 / 51
The DUNE Grid File (DGF) Format
DGF Interval Block Example
A DGF file consisting of a single INTERVAL block will result in ad-dimensional axis-aligned cube in Rd .
An INTERVAL block always consists of• two d-dimensional coordinates (lower left and upper right corner),• the number of cells in each direction.
Example: The Unit Square
DGFINTERVAL0 0 % first corner1 1 % second corner4 8 % 4 / 8 cells
#
Result depends on grid implementation
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 41 / 51
The DUNE Grid File (DGF) Format
DGF: Vertex and Simplex Blocks
General simplicial grids can be constructed from a VERTEX block and aSIMPLEX block.DGFVERTEX-1.0 -1.0 % vertex 0-0.2 -1.0 % vertex 11.0 -1.0 % vertex 21.0 -0.6 % vertex 31.0 1.0 % vertex 4-1.0 1.0 % vertex 50.2 -0.2 % vertex 6
#SIMPLEX0 1 5 % triangle 0, vertices 0,1,51 3 6 % triangle 1, vertices 1,3,61 2 3 % triangle 2, vertices 1,2,36 3 4 % triangle 3, vertices 6,3,46 4 5 % triangle 4, vertices 6,4,56 5 1 % triangle 5, vertices 6,5,1
#
Result (simplex grid)
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 42 / 51
The DUNE Grid File (DGF) Format
DGF: Vertex and Cube Blocks
Similar to the SIMPLEX block there is a CUBE block.
DGFVERTEX-1.0 -1.0 % vertex 0-0.2 -1.0 % vertex 11.0 -1.0 % vertex 21.0 -0.6 % vertex 31.0 1.0 % vertex 4-1.0 1.0 % vertex 50.2 -0.2 % vertex 6
#CUBE0 1 5 6 % cube 0, vertices 0,1,5,61 2 6 3 % cube 1, vertices 1,2,6,36 3 5 4 % cube 2, vertices 6,3,5,4
#
Result (cube grid)
Result (simplex grid)DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 43 / 51
Notes
Notes
Notes
Notes
The DUNE Grid File (DGF) Format
DGF: Using Triangle or TetGen
DGFSIMPLEXGENERATOR% path to TetGen / Trianglepath $HOME/bin% read information from filefile BBEETH1M.d_cut mesh% dimension of grid to generatedimension 3#
Result (simplex grid)
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 44 / 51
The DUNE Grid File (DGF) Format
Grid Construction Through DGF
The DGF parser is automatically invoked when calling one of thefollowing constructors:Dune::GridPtr< Grid >( const std::string &filename );Dune::GridPtr< Grid >( std::istream &stream );
The Dune::GridPtr behaves like a std::shared_ptr, so the gridis (usually) deleted automatically.
Example:As details in the DGF file can depend on the grid dimension (and onthe world dimension), one can construct the grid as follows:std::stringstream name;name << basename << "_" << Grid::dimension << "d.dgf";Dune::GridPtr< Grid > gridPtr( name.str() );Grid& grid = *gridPtr;
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 45 / 51
The DUNE Grid File (DGF) Format
The Grid SelectorObservations:
• Many applications require only a single grid.
• Exchanging the grid implementation by hand is tedious.
Solution:The preprocessor can automatically define the typeDune::GridSelector::GridType
based on code snipets added to config.h.
This requires -DALLOW_CXXFLAGS_OVERWRITE=ON set during cmake run toallow changing the actual type during the make procedure, e.g.,make cleanmake GRIDTYPE=ALUGRID_SIMPLEX GRIDDIM=3
Standard values for GRIDTYPE:ALBERTAGRID ALUGRID_CUBE ONEDGRID UGGRID
ALUGRID_CONFORM ALUGRID_SIMPLEX YASPGRID
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 46 / 51
The ”Hello Grid” Program
Outline
1 An Overview of DUNE-GRID
2 Hierarchical Grids
3 Grid Parts
4 The DUNE Interface for Hierarchical Grids
5 Construction of Hierarchical Grids
6 The DUNE Grid File (DGF) Format
7 The ”Hello Grid” Program
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 47 / 51
Notes
Notes
Notes
Notes
The ”Hello Grid” Program
Structure of all Exercises
Source directory and build directory:source code is contained in dune-fem-school/01.intro-1/
build the executables are contained indune-fem-school/build-cmake/01.intro-1/
In every lesson folder you will find the following sub-folders:source Contains the exercise for each lesson. Incomplete source
code, search for TODO to find the places where to insertcode.
solution Contains a reference implementation for the exercise.data Contains input parameter files and input grids.
output Folder that holds simulation output (after simulation isfinished).
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 48 / 51
The ”Hello Grid” Program
Structure: 01.intro-1
main function• First some setup is performed:
initializing MPI in the case of a parallel run• Read run time parameters from command line and../data/parameter (class Dune::Fem::Parameterexplained later)
• Read the macro grid from a dgf file given as run time parameter(e.g., ../data/grid.dgf)
• We want to compute something on a series of refined gridsthe computation is done in the method algorithm
algorithm function• Given a DUNE grid we first construct a grid part• After solving our problem we output the result and compute an
error - the VTK output is described in a later lectureDUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 49 / 51
The ”Hello Grid” Program
TODO: 01.intro-1
1 You can directly type make in 01.intro-1/source and execute./exercise-01.intro-1
2 The results are in 01.intro-1/output and can be viewed withparaview
TODO During the make process change the type of the grid for example from YASPGRID toALUGRID_SIMPLEX or the grid dimension GRIDDIM from 2 to 3. You can even computeon a surface by using ALUGRID_SIMPLEX, GRIDDIM=2, and WOLRDDIM=3. Rememberto change the parameter file so that you use a macro grid file that works with the grid,e.g. sphere.dgf.
TODO Implement some different functions (e.g. with different smoothness)
TODO To compute something on a disc of a given radius around the origin we can either
• use a grid that can perform boundary adaptation (e.g., AluGrid and use a dgffile providing the correct projection for boundary vertices (e.g., disc.dgf). Thiscan be changed directly in the parameter file.
• use a FilteredGridPart. This will work with any grid, e.g., YaspGrid.
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 50 / 51
The ”Hello Grid” Program
TODO: 01.intro-1
TODO Compute the area of the domain |Ω| =∑
E∈G |E | by iterating over theelements in the GridPart.Compute the error between the computed value and the exact size ofΩ.Note: The EOC will be zero unless you have implemented one of thetwo options of the previous TODO.For the dim-dimensional disc or radius r you can useconst double exactTotalVolume= std::pow(r*r*M_PI, dim/2.0) / tgamma(dim/2.0+1.0);
TODO Change the parameters to perform a few eoc computations for thedomain size error.
TODO Compute ∑K∈G
|K |u(ωK ) ≈∫
Ω
u(x) dx
(here ωK is the barycenter of the element K .You can of course also use a higher order quadrature.
DUNE Group (IANS & IRIS) DUNE-FEM School 2016 September 26-30, 2016 51 / 51
Notes
Notes
Notes
Notes