This repository has been archived by the owner on Jan 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvertexdata.hh
61 lines (53 loc) · 2.08 KB
/
vertexdata.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef __DUNE_GRID_HOWTO_VERTEXDATA_HH__
#define __DUNE_GRID_HOWTO_VERTEXDATA_HH__
#include <dune/grid/common/mcmgmapper.hh>
#include <dune/grid/io/file/vtk/vtkwriter.hh>
#if HAVE_GRAPE
#include <dune/grid/io/visual/grapedatadisplay.hh>
#endif
// demonstrate attaching data to elements
template<class G, class F>
void vertexdata (const G& grid, const F& f)
{
// get dimension from Grid
const int dim = G::dimension;
typedef typename G::LeafGridView GridView;
// determine type of LeafIterator for codimension = dimension
typedef typename GridView::template Codim<dim>::Iterator VertexLeafIterator;
// get grid view on the leaf part
GridView gridView = grid.leafGridView();
// make a mapper for codim 0 entities in the leaf grid
Dune::LeafMultipleCodimMultipleGeomTypeMapper<G>
mapper(grid, Dune::mcmgVertexLayout());
// allocate a vector for the data
std::vector<double> c(mapper.size());
// iterate through all entities of codim 0 at the leaves
for (VertexLeafIterator it = gridView.template begin<dim>();
it!=gridView.template end<dim>(); ++it)
{
// evaluate functor and store value
c[mapper.index(*it)] = f(it->geometry().corner(0));
}
// generate a VTK file
Dune::VTKWriter<typename G::LeafGridView> vtkwriter(grid.leafGridView());
vtkwriter.addVertexData(c,"data");
vtkwriter.write( "vertexdata", Dune::VTK::appendedraw );
// online visualization with Grape
#if HAVE_GRAPE
{
const int polynomialOrder = 1; // we piecewise linear data
const int dimRange = 1; // we have scalar data here
// create instance of data display
Dune::GrapeDataDisplay<G> grape(grid);
// display data
grape.displayVector("concentration", // name of data that appears in grape
c, // data vector
gridView.indexSet(), // used index set
polynomialOrder, // polynomial order of data
dimRange); // dimRange of data
}
#endif
}
#endif // __DUNE_GRID_HOWTO_VERTEXDATA_HH__