initialize.hh
Go to the documentation of this file.
1 #include <dune/common/version.hh>
2 #include<dune/geometry/referenceelements.hh>
3 #include "transportproblem2.hh"
4 
6 template<class G, class M, class V>
7 void 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 #if DUNE_VERSION_NEWER(DUNE_GRID, 2, 3)
34  local = Dune :: ReferenceElements<ct,dim >::general(gt).position(0,0);
35 #else
36  local = Dune :: GenericReferenceElements<ct,dim >::general(gt).position(0,0);
37 #endif
38 
39  // get global coordinate of cell center
40  Dune::FieldVector<ct,dimworld> global =
41  it->geometry().global(local);
42  // Dune::FieldVector<ct, dimworld> global = it->geometry().position();
43 
44 #if DUNE_VERSION_NEWER(DUNE_GRID, 2, 4)
45  // initialize cell concentration
46  c[mapper.index(*it)] = c0(global);
47 #else
48  // initialize cell concentration
49  c[mapper.map(*it)] = c0(global);
50 #endif
51  }
52 }
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