-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFunctions.cc
86 lines (71 loc) · 1.96 KB
/
Functions.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
// @sect3{Functions.cc}
// In this file we keep right hand side function, Dirichlet boundary
// conditions and solution to our Poisson equation problem. Since
// these classes and functions have been discussed extensively in
// the deal.ii tutorials we won't discuss them any further.
#include <deal.II/base/function.h>
#include <deal.II/base/tensor_function.h>
#include <deal.II/lac/vector.h>
#include <cmath>
using namespace dealii;
template <int dim>
class RightHandSide : public Function<dim>
{
public:
RightHandSide() : Function<dim>(1)
{}
virtual double value(const Point<dim> &p,
const unsigned int component = 0 ) const;
};
template <int dim>
class DirichletBoundaryValues : public Function<dim>
{
public:
DirichletBoundaryValues() : Function<dim>(1)
{}
virtual double value(const Point<dim> &p,
const unsigned int component = 0 ) const;
};
template<int dim>
class TrueSolution : public Function<dim>
{
public:
TrueSolution() : Function<dim>(dim+1)
{}
virtual void vector_value(const Point<dim> & p,
Vector<double> &valuess) const;
};
template <int dim>
double
RightHandSide<dim>::
value(const Point<dim> &p,
const unsigned int ) const
{
const double x = p[0];
const double y = p[1];
return 4*M_PI*M_PI*(cos(2*M_PI*y) - sin(2*M_PI*x));
}
template <int dim>
double
DirichletBoundaryValues<dim>::
value(const Point<dim> &p,
const unsigned int ) const
{
const double x = p[0];
const double y = p[1];
return cos(2*M_PI*y) -sin(2*M_PI*x) - x;
}
template <int dim>
void
TrueSolution<dim>::
vector_value(const Point<dim> &p,
Vector<double> &values) const
{
Assert(values.size() == dim+1,
ExcDimensionMismatch(values.size(), dim+1) );
double x = p[0];
double y = p[1];
values(0) = 1 + 2*M_PI*cos(2*M_PI*x);
values(1) = 2*M_PI*sin(2*M_PI*y);
values(2) = cos(2*M_PI*y) - sin(2*M_PI*x) - x;
}