This source file includes following definitions.
- interpolate
- evaluate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 #include <stdexcept>
17 #include <cmath>
18 #include <config.h>
19 #include <dune/fem/operator/lagrangeinterpolation.hh>
20 #include "secOrd_op_initData_w.h"
21 #include "grid.h"
22
23 #ifdef DEBUG
24 #include <iostream>
25 #endif
26
27 class Initial_data_w
28 : public Dune::Fem::Function<Esfem::Grid::Grid_and_time::Function_space,
29 Initial_data_w>
30 {
31 public:
32 using Base = Esfem::Grid::Grid_and_time::Function_space;
33 using Domain = Base::DomainType;
34 using Range = Base::RangeType;
35
36 explicit Initial_data_w(const Dune::Fem::TimeProviderBase&);
37 Initial_data_w(const Initial_data_w&) = delete;
38 Initial_data_w& operator=(const Initial_data_w&) = delete;
39
40 void evaluate(const Domain&, Range&) const;
41 private:
42 const Dune::Fem::TimeProviderBase& tp;
43 };
44
45
46
47
48 struct Esfem::SecOrd_op::Init_data_w::Data{
49 Initial_data_w u0;
50 Data(const Grid::Grid_and_time& gt)
51 : u0 {gt.time_provider()}
52 {}
53 };
54
55 Esfem::SecOrd_op::Init_data_w::Init_data_w(const Grid::Grid_and_time& gt){
56 try{
57 d_ptr = new Data {gt};
58 }
59 catch(const std::exception&){
60 std::throw_with_nested(std::logic_error{"Error in constructor of Init_data_w."});
61 }
62 catch(...){
63 throw std::logic_error{"Unknown error in constructor of Init_data_w."};
64 }
65 }
66 Esfem::SecOrd_op::Init_data_w::~Init_data_w(){
67 delete d_ptr;
68 d_ptr = nullptr;
69 #ifdef DEBUG
70 std::cerr << "~Init_data_w(): delete d_ptr.\n";
71 #endif
72 }
73 void Esfem::SecOrd_op::Init_data_w::interpolate(Grid::Scal_FEfun& fef) const{
74 using FE_function = Esfem::Grid::Scal_FEfun::Dune_FEfun;
75 Dune::LagrangeInterpolation<FE_function>::interpolateFunction(d_ptr -> u0, fef);
76 }
77
78
79
80
81 Initial_data_w::Initial_data_w(const Dune::Fem::TimeProviderBase& tpb)
82 : tp {tpb}
83 {}
84 void Initial_data_w::evaluate(const Domain& d, Range& r) const{
85 static_assert(Domain::dimension == 3, "Bad domain dimension.");
86 static_assert(Range::dimension == 1, "Bad range dimension.");
87 const double y = d[1];
88 const double z = d[2];
89 const double t = tp.time();
90 r = std::exp(-6.*t)*y*z;
91 }
92
93
94