-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataTypes.h
148 lines (121 loc) · 4.48 KB
/
DataTypes.h
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* data_types.h
*
* Created on: Feb 14, 2015
* Author: viktor
*/
#ifndef DATA_TYPES_H_
#define DATA_TYPES_H_
#include "DiscretizationData.h"
#include <deal.II/lac/vector.h> // numerical vector of data --> Vector<double>
#include <deal.II/lac/sparse_matrix.h> // sparse matrix denoted by a SparsityPattern --> SparseMatrix<double>
#include <deal.II/numerics/vector_tools.h>
#include <deal.II/numerics/error_estimator.h> // Kelly error estimator --> solution type
using namespace MonteCarlo;
/*---------------------------------------------------------------------------*/
/* Auxiliary solution type class */
/*---------------------------------------------------------------------------*/
template< int dim >
class solution_type
{
public:
solution_type() {};
solution_type( int l ) : level(l),
vector(DiscretizationData<dim>::dof_handlers_ptr[level]->n_dofs()) {};
virtual ~solution_type() {};
void reinit( int l )
{
level = l;
vector.reinit( DiscretizationData<dim>::dof_handlers_ptr[level]->n_dofs() );
vector = 0.0;
};
void interpolate_from( solution_type &input_vector )
{
if ( DiscretizationData<dim>::intergrid_maps_ptr.size() != 0 )
VectorTools::interpolate_to_different_mesh( *(DiscretizationData<dim>::intergrid_maps_ptr[input_vector.level][level]), input_vector.vector,
*(DiscretizationData<dim>::hanging_nodes_constraints_ptr[level]), vector);
else
vector = 0.0;
};
void add( solution_type &input_vector, double multiplier = 1.0 )
{
solution_type<dim> tmp_vector(level);
tmp_vector.interpolate_from(input_vector);
tmp_vector.vector *= multiplier;
vector += tmp_vector.vector;
};
void subtract( solution_type &input_vector )
{
solution_type<dim> tmp_vector(level);
tmp_vector.interpolate_from(input_vector);
vector -= tmp_vector.vector;
};
double L1_norm()
{
Vector<double> local_errors ( DiscretizationData<dim>::dof_handlers_ptr[level]->get_tria().n_active_cells() );
VectorTools::integrate_difference ( *(DiscretizationData<dim>::dof_handlers_ptr[level]),
vector,
ZeroFunction<dim>(),
local_errors,
*(DiscretizationData<dim>::quadrature_formula),
VectorTools::NormType::L1_norm);
return local_errors.l1_norm();
};
double L2_norm()
{
Vector<double> local_errors ( DiscretizationData<dim>::dof_handlers_ptr[level]->get_tria().n_active_cells() );
VectorTools::integrate_difference ( *(DiscretizationData<dim>::dof_handlers_ptr[level]),
vector,
ZeroFunction<dim>(),
local_errors,
*(DiscretizationData<dim>::quadrature_formula),
VectorTools::NormType::L2_norm);
return local_errors.l2_norm();
};
double Linfty_norm()
{
Vector<double> local_errors ( DiscretizationData<dim>::dof_handlers_ptr[level]->get_tria().n_active_cells() );
VectorTools::integrate_difference ( *(DiscretizationData<dim>::dof_handlers_ptr[level]),
vector,
ZeroFunction<dim>(),
local_errors,
*(DiscretizationData<dim>::quadrature_formula),
VectorTools::NormType::Linfty_norm);
return local_errors.linfty_norm();
};
float estimate_posterior_error()
{
Vector<float> estimated_error_per_cell ( DiscretizationData<dim>::triangulations_ptr[level]->n_active_cells() );
KellyErrorEstimator<dim>::estimate( *(DiscretizationData<dim>::dof_handlers_ptr[level]),
QGauss<dim-1>(2),
typename FunctionMap<dim>::type(),
vector,
estimated_error_per_cell );
return estimated_error_per_cell.l2_norm();
}
int sample;
public:
int level;
Vector<double> vector;
};
/*---------------------------------------------------------------------------*/
/* Auxiliary matrix type class */
/*---------------------------------------------------------------------------*/
template< int dim >
class matrix_type
{
public:
matrix_type() {};
matrix_type( int l ) : level(l),
matrix( *(DiscretizationData<dim>::sparsity_patterns_ptr[level]) ) {};
virtual ~matrix_type() {};
void reinit( int l )
{
level = l;
matrix.reinit (*(DiscretizationData<dim>::sparsity_patterns_ptr[level]));
};
public:
int level;
SparseMatrix<double> matrix;
};
#endif /* DATA_TYPES_H_ */