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
/
integration.cc
93 lines (76 loc) · 2.49 KB
/
integration.cc
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// Dune includes
#include <config.h> // file generated by CMake
#include <iomanip>
#include <iostream>
#include <dune/grid/yaspgrid.hh> // load yaspgrid definition
#include <dune/common/parallel/mpihelper.hh> // include mpi helper class
#include "functors.hh"
#include "integrateentity.hh"
//! uniform refinement test
template<class Grid>
void uniformintegration (Grid& grid)
{
// function to integrate
Exp<typename Grid::ctype,Grid::dimension> f;
// get GridView on leaf grid - type
typedef typename Grid :: LeafGridView GridView;
// get GridView instance
GridView gridView = grid.leafGridView();
// get iterator type
typedef typename GridView :: template Codim<0> :: Iterator LeafIterator;
// loop over grid sequence
double oldvalue=1E100;
for (int k=0; k<10; k++)
{
// compute integral with some order
double value = 0.0;
LeafIterator eendit = gridView.template end<0>();
for (LeafIterator it = gridView.template begin<0>(); it!=eendit; ++it)
value += integrateEntity(*it,f,1); /*@\label{ic:call}@*/
// print result and error estimate
std::cout << "elements="
<< std::setw(8) << std::right
<< grid.size(0)
<< " integral="
<< std::scientific << std::setprecision(12)
<< value
<< " error=" << std::abs(value-oldvalue)
<< std::endl;
// save value of integral
oldvalue=value;
// refine all elements
grid.globalRefine(1);
}
}
int main(int argc, char **argv)
{
// initialize MPI, finalize is done automatically on exit
Dune::MPIHelper::instance(argc,argv);
// start try/catch block to get error messages from dune
try {
using namespace Dune;
// the GridSelector :: GridType is defined in gridtype.hh and is
// set during compilation
typedef GridSelector :: GridType Grid;
// use unitcube from grids
std::stringstream dgfFileName;
dgfFileName << DUNE_GRID_HOWTO_EXAMPLE_GRIDS_PATH
<< "unitcube" << Grid::dimension << ".dgf";
// create grid pointer
GridPtr<Grid> gridPtr( dgfFileName.str() );
// integrate and compute error with extrapolation
uniformintegration( *gridPtr );
}
catch (std::exception & e) {
std::cout << "ERROR: " << e.what() << std::endl;
return 1;
}
catch (...) {
std::cout << "Unknown ERROR" << std::endl;
return 1;
}
// done
return 0;
}