LoAdSG
integratorRHS.h
1/**********************************************************************************
2* Author: Christoph Pflaum, Riccarda Scherner-Griesshammer, Tim Rheinfels
3 * Department Informatik Lehrstuhl 10 - Systemsimulation
4 * Friedrich-Alexander Universität Erlangen-Nürnberg
5 *
6*********************************************/
7#ifndef INTERATORRHS_H
8#define INTERATORRHS_H
9
10#include <functional>
11#include <limits>
12
13#include "integral.hpp"
14#include "../interfaceMatrices.h"
15
24template <typename F, size_t N>
26{
27
28 private:
29
33 class TermRHS
34 {
35
36 private:
37
38 std::array<double,N> h_u;
39 std::array<double,N> h_v;
40 std::array<double,N> p_u;
41 std::array<double,N> p_v;
42 std::array<int,N> d_u;
43 std::array<int,N> d_v;
45 double m_gamma;
46
47
48 public:
49
60 inline TermRHS( const std::array<double, N>& h_u_, const std::array<double, N>& h_v_, const std::array<double, N>& p_u_, const std::array<double, N>& p_v_,const std::array<int, N>& d_u_, const std::array<int, N>& d_v_, const F& variable_coefficient, double gamma )
61 : h_u(h_u_),
62 h_v(h_v_),
63 p_u(p_u_),
64 p_v(p_v_),
65 d_u(d_u_),
66 d_v(d_v_),
67 m_variable_coefficient(variable_coefficient),
68 m_gamma(gamma)
69 {
70
71 }
72
80 inline double operator() (std::array<double, N>& x ) const
81 {
82
83
84
85 double value = 1.0;
86
87 for( size_t i = 0; i < N; i++ )
88 {
89 // Multiply by the first base function
90
91 if(d_u[i]!=0){
92 double suppleft=p_u[i]-h_u[i];
93 double suppright=p_u[i]+h_u[i];
94
95 if(suppleft <= x[i] && x[i] <= suppright){
96 double slope = 1.0/h_u[i];
97 if(x[i]<p_u[i]){
98 double c = -(p_u[i]-h_u[i])/h_u[i];
99 value *= (slope*x[i]+c);
100 } else{
101 double c = + (p_u[i]+h_u[i])/h_u[i];
102 value *= (-1.0*slope*x[i]+c);
103 }
104 }else{
105 value = 0.0;
106 }
107 }else{
108 if(p_u[i]==0.0)
109 value *= -x[i]+1.0;
110 if(p_u[i]==1.0)
111 value *= x[i];
112 }
113 if(d_v[i]!=0) {
114 double suppleft = p_v[i] - h_v[i];
115 double suppright = p_v[i] + h_v[i];
116 if (suppleft <= x[i] && x[i] <= suppright) {
117 double slope = 1.0 / h_v[i];
118 if (x[i] < p_v[i]) {
119
120 double c = -(p_v[i] - h_v[i]) / h_v[i];
121 value *= (slope * x[i] + c);
122 } else {
123
124 double c = +(p_v[i] + h_v[i]) / h_v[i];
125 value *= (-1.0 * slope * x[i] + c);
126 }
127 } else {
128 value = 0.0;
129 }
130 }else{
131
132 if(p_v[i]==0.0){
133 value *= -x[i]+1.0;
134 }
135
136 if(p_v[i]==1.0){
137 value *= x[i];
138 }
139
140 }
141
142 }
143
144
145
146 // Evaluate the variable coefficient replacing floating point inf by gamma
147 double c_eval = m_variable_coefficient(x);
148
149 if( (std::abs(c_eval) > m_gamma) || (std::fpclassify(c_eval) == FP_INFINITE) )
150 {
151 c_eval = (std::signbit(c_eval) ? (-m_gamma) : m_gamma);
152 }
153
154 // Mulitply by the variable coefficient
155 value *= c_eval;
156
157 // Return Helmholtz function with variable coefficient evaluated at x
158 return value;
159
160 }
161
162 };
163
164
166 double m_epsilon;
167 size_t m_depth_min;
168 size_t m_depth_max;
169 double m_gamma;
170
171
172 public:
173
183 IntegratorRHS( const F& c, double epsilon, size_t depth_min = 0, size_t depth_max = std::numeric_limits<size_t>::max(), double gamma = std::numeric_limits<double>::max() )
185 m_epsilon(epsilon),
186 m_depth_min(depth_min),
187 m_depth_max(depth_max),
188 m_gamma(gamma)
189 {
190
191 /* Nothing to do here... */
192
193 }
194
205 double integration(std::array<double, N> l_b, std::array<double, N> r_b, std::array<double, N> p_u, std::array<double, N> p_v, std::array<double, N> h_u, std::array<double, N> h_v,
206 array<int, N> d_u, std::array<int, N> d_v) const
207 {
208
209 TermRHS ht(h_u, h_v, p_u,p_v,d_u,d_v,m_variable_coefficient, m_gamma );
210
211
212
213
214
215 // Integrate
216 return integral<double, TermRHS, N>( ht, l_b, r_b, m_epsilon, m_depth_min, m_depth_max, m_gamma );
217
218 }
219
220 double stencil_integration(double p_left[N], double p_right[N],
221 BasisFunctionType u[N], BasisFunctionType v[N]) const {return 0;};
222
223
224
225};
226
227#endif
Class for describing a Helmholtz term.
Definition integratorRHS.h:34
std::array< double, N > h_u
Meshwidth of Base function u.
Definition integratorRHS.h:38
std::array< double, N > p_u
Position of Base function u;.
Definition integratorRHS.h:40
F m_variable_coefficient
Functor providing the variable coefficient.
Definition integratorRHS.h:44
std::array< int, N > d_v
Depth of Base function v;.
Definition integratorRHS.h:43
std::array< int, N > d_u
Depth of Base function u;.
Definition integratorRHS.h:42
std::array< double, N > h_v
Meshwidth of Base function v.
Definition integratorRHS.h:39
TermRHS(const std::array< double, N > &h_u_, const std::array< double, N > &h_v_, const std::array< double, N > &p_u_, const std::array< double, N > &p_v_, const std::array< int, N > &d_u_, const std::array< int, N > &d_v_, const F &variable_coefficient, double gamma)
Constructor.
Definition integratorRHS.h:60
std::array< double, N > p_v
Position of Base function v;.
Definition integratorRHS.h:41
double operator()(std::array< double, N > &x) const
Evaluation operator.
Definition integratorRHS.h:80
double m_gamma
Cutoff parameter for singularities.
Definition integratorRHS.h:45
Integrator for the Helmholtz operator with variable coefficients.
Definition integratorRHS.h:26
IntegratorRHS(const F &c, double epsilon, size_t depth_min=0, size_t depth_max=std::numeric_limits< size_t >::max(), double gamma=std::numeric_limits< double >::max())
Constructor.
Definition integratorRHS.h:183
double m_gamma
Value to replace infinte values with.
Definition integratorRHS.h:169
size_t m_depth_max
Maximum recursion depth.
Definition integratorRHS.h:168
double integration(std::array< double, N > l_b, std::array< double, N > r_b, std::array< double, N > p_u, std::array< double, N > p_v, std::array< double, N > h_u, std::array< double, N > h_v, array< int, N > d_u, std::array< int, N > d_v) const
Performs the integration of the FEM function defined by p_left, p_right, u and u with the additional ...
Definition integratorRHS.h:205
F m_variable_coefficient
The variable coefficient.
Definition integratorRHS.h:165
double m_epsilon
Refinement criterion on the hierarchical surplus.
Definition integratorRHS.h:166
size_t m_depth_min
Minimum recursion depth.
Definition integratorRHS.h:167
Definition interfaceMatrices.h:21