initialize.hh
Go to the documentation of this file.
1#include <dune/common/version.hh>
2#include<dune/geometry/referenceelements.hh>
4
6template<class G, class M, class V>
7void initialize(const G& grid, const M& mapper, V& c)
8{
9 // first we extract the dimensions of the grid
10 const int dim = G::dimension;
11 const int dimworld = G::dimensionworld;
12
13 // type used for coordinates in the grid
14 typedef typename G::ctype ct;
15
16 // type of grid view on leaf part
17 typedef typename G::LeafGridView GridView;
18
19 // leaf iterator type
20 typedef typename GridView::template Codim<0>::Iterator LeafIterator;
21
22 // get grid view on leaf part
23 GridView gridView = grid.leafGridView();
24
25 // iterate through leaf grid an evaluate c0 at cell center
26 LeafIterator endit = gridView.template end<0>();
27 for (LeafIterator it = gridView.template begin<0>(); it!=endit; ++it) {
28 // get geometry type
29 Dune::GeometryType gt = it->type();
30
31 // get cell center in reference element
32 const Dune::FieldVector<ct,dim>&
33 local = Dune :: ReferenceElements<ct,dim >::general(gt).position(0,0);
34
35 // get global coordinate of cell center
36 Dune::FieldVector<ct,dimworld> global =
37 it->geometry().global(local);
38 // Dune::FieldVector<ct, dimworld> global = it->geometry().position();
39
40 // initialize cell concentration
41 c[mapper.index(*it)] = c0(global);
42 }
43}
void initialize(const G &grid, const M &mapper, V &c)
initialize the vector of unknowns with initial value
Definition: initialize.hh:7
double c0(const Dune::FieldVector< ct, dimworld > &x)
Definition: transportproblem2.hh:15