16 #ifndef __H2D_INTEGRALS_H1_H
17 #define __H2D_INTEGRALS_H1_H
19 #include "../quadrature/limit_order.h"
21 #include "../function/function.h"
27 template<
typename Real>
28 Real int_v(
int n,
double *wt, Func<Real> *v)
30 Real result = Real(0);
31 for (
int i = 0; i < n; i++)
32 result += wt[i] * v->val[i];
36 template<
typename Real,
typename Geom>
37 Real int_x_v(
int n,
double *wt, Func<Real> *v, Geom *e)
39 Real result = Real(0);
40 for (
int i = 0; i < n; i++)
41 result += wt[i] * e->x[i] * v->val[i];
45 template<
typename Real,
typename Geom>
46 Real int_y_v(
int n,
double *wt, Func<Real> *v, Geom *e)
48 Real result = Real(0);
49 for (
int i = 0; i < n; i++)
50 result += wt[i] * e->y[i] * v->val[i];
54 template<
typename Real,
typename Scalar>
55 Scalar int_u_v(
int n,
double *wt, Func<Real> *u, Func<Real> *v)
57 Scalar result = Scalar(0);
58 for (
int i = 0; i < n; i++)
59 result += wt[i] * u->val[i] * v->val[i];
64 template<
typename Real,
typename Scalar>
65 Scalar int_u_ext_v(
int n,
double *wt, Func<Scalar> *u_ext, Func<Real> *v)
67 Scalar result = Scalar(0);
68 for (
int i = 0; i < n; i++)
69 result += wt[i] * u_ext->val[i] * v->val[i];
73 template<
typename Real,
typename Scalar,
typename Geom>
74 Scalar int_x_u_v(
int n,
double *wt, Func<Real> *u, Func<Real> *v, Geom *e)
76 Scalar result = Scalar(0);
77 for (
int i = 0; i < n; i++)
78 result += wt[i] * e->x[i] * u->val[i] * v->val[i];
83 template<
typename Real,
typename Scalar,
typename Geom>
84 Scalar int_x_u_ext_v(
int n,
double *wt, Func<Scalar> *u_ext, Func<Real> *v, Geom *e)
86 Scalar result = Scalar(0);
87 for (
int i = 0; i < n; i++)
88 result += wt[i] * e->x[i] * u_ext->val[i] * v->val[i];
92 template<
typename Real,
typename Scalar,
typename Geom>
93 Scalar int_y_u_v(
int n,
double *wt, Func<Real> *u, Func<Real> *v, Geom *e)
95 Scalar result = Scalar(0);
96 for (
int i = 0; i < n; i++)
97 result += wt[i] * e->y[i] * u->val[i] * v->val[i];
102 template<
typename Real,
typename Scalar,
typename Geom>
103 Scalar int_y_u_ext_v(
int n,
double *wt, Func<Scalar> *u_ext, Func<Real> *v, Geom *e)
105 Scalar result = Scalar(0);
106 for (
int i = 0; i < n; i++)
107 result += wt[i] * e->y[i] * u_ext->val[i] * v->val[i];
111 template<
typename Real,
typename Scalar,
typename Geom>
112 Scalar int_F_v(
int n,
double *wt, Real(*F)(Real x, Real y), Func<Real> *v, Geom *e)
114 Scalar result = Scalar(0);
115 for (
int i = 0; i < n; i++)
116 result += wt[i] * ((*F)(e->x[i], e->y[i]) * v->val[i]);
120 template<
typename Real,
typename Scalar>
121 Scalar int_grad_u_grad_v(
int n,
double *wt, Func<Real> *u, Func<Real> *v)
123 Scalar result = Scalar(0);
124 for (
int i = 0; i < n; i++)
125 result += wt[i] * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]);
130 template<
typename Real,
typename Scalar>
131 Scalar int_grad_u_ext_grad_v(
int n,
double *wt, Func<Scalar> *u_ext, Func<Real> *v)
133 Scalar result = Scalar(0);
134 for (
int i = 0; i < n; i++)
135 result += wt[i] * (u_ext->dx[i] * v->dx[i] + u_ext->dy[i] * v->dy[i]);
139 template<
typename Real,
typename Scalar,
typename Geom>
140 Scalar int_x_grad_u_grad_v(
int n,
double *wt, Func<Real> *u, Func<Real> *v, Geom *e)
142 Scalar result = Scalar(0);
143 for (
int i = 0; i < n; i++)
144 result += wt[i] * e->x[i] * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]);
149 template<
typename Real,
typename Scalar,
typename Geom>
150 Scalar int_x_grad_u_ext_grad_v(
int n,
double *wt, Func<Scalar> *u_ext, Func<Real> *v, Geom *e)
152 Scalar result = Scalar(0);
153 for (
int i = 0; i < n; i++)
154 result += wt[i] * e->x[i] * (u_ext->dx[i] * v->dx[i] + u_ext->dy[i] * v->dy[i]);
158 template<
typename Real,
typename Scalar,
typename Geom>
159 Scalar int_y_grad_u_grad_v(
int n,
double *wt, Func<Real> *u, Func<Real> *v, Geom *e)
161 Scalar result = Scalar(0);
162 for (
int i = 0; i < n; i++)
163 result += wt[i] * e->y[i] * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]);
168 template<
typename Real,
typename Scalar,
typename Geom>
169 Scalar int_y_grad_u_ext_grad_v(
int n,
double *wt, Func<Scalar> *u_ext, Func<Real> *v, Geom *e)
171 Scalar result = Scalar(0);
172 for (
int i = 0; i < n; i++)
173 result += wt[i] * e->y[i] * (u_ext->dx[i] * v->dx[i] + u_ext->dy[i] * v->dy[i]);
177 template<
typename Real,
typename Scalar>
178 Scalar int_dudx_v(
int n,
double *wt, Func<Real> *u, Func<Real> *v)
180 Scalar result = Scalar(0);
181 for (
int i = 0; i < n; i++)
182 result += wt[i] * (u->dx[i] * v->val[i]);
186 template<
typename Real,
typename Scalar>
187 Scalar int_dudy_v(
int n,
double *wt, Func<Real> *u, Func<Real> *v)
189 Scalar result = Scalar(0);
190 for (
int i = 0; i < n; i++)
191 result += wt[i] * (u->dy[i] * v->val[i]);
195 template<
typename Real,
typename Scalar>
196 Scalar int_u_dvdx(
int n,
double *wt, Func<Real> *u, Func<Real> *v)
198 Scalar result = Scalar(0);
199 for (
int i = 0; i < n; i++)
200 result += wt[i] * u->val[i] * v->dx[i];
204 template<
typename Real,
typename Scalar,
typename Geom>
205 Scalar int_u_dvdx_over_x(
int n,
double *wt, Func<Real> *u, Func<Real> *v, Geom *e)
207 Scalar result = Scalar(0);
208 for (
int i = 0; i < n; i++)
209 result += wt[i] * ((e->x[i] > 0) ? u->val[i] * v->dx[i] / e->x[i] : 0.0);
214 template<
typename Real,
typename Scalar,
typename Geom>
215 Scalar int_u_ext_dvdx_over_x(
int n,
double *wt, Func<Scalar> *u_ext, Func<Real> *v, Geom *e)
217 Scalar result = Scalar(0);
218 for (
int i = 0; i < n; i++)
219 result += wt[i] * u_ext->val[i] * v->dx[i] / e->x[i];
223 template<
typename Real,
typename Scalar>
224 Scalar int_u_dvdy(
int n,
double *wt, Func<Real> *u, Func<Real> *v)
226 Scalar result = Scalar(0);
227 for (
int i = 0; i < n; i++)
228 result += wt[i] * u->val[i] * v->dy[i];
232 template<
typename Real,
typename Scalar,
typename Geom>
233 Scalar int_u_dvdy_over_y(
int n,
double *wt, Func<Real> *u, Func<Real> *v, Geom *e)
235 Scalar result = Scalar(0);
236 for (
int i = 0; i < n; i++)
237 result += wt[i] * ((e->y[i] > 0) ? u->val[i] * v->dy[i] / e->y[i] : 0.0);
242 template<
typename Real,
typename Scalar,
typename Geom>
243 Scalar int_u_ext_dvdy_over_y(
int n,
double *wt, Func<Scalar> *u_ext, Func<Real> *v, Geom *e)
245 Scalar result = Scalar(0);
246 for (
int i = 0; i < n; i++)
247 result += wt[i] * u_ext->val[i] * v->dy[i] / e->y[i];
251 template<
typename Real,
typename Scalar>
252 Scalar int_dudx_dvdx(
int n,
double *wt, Func<Real> *u, Func<Real> *v)
254 Scalar result = Scalar(0);
255 for (
int i = 0; i < n; i++)
256 result += wt[i] * (u->dx[i] * v->dx[i]);
260 template<
typename Real,
typename Scalar>
261 Scalar int_dudy_dvdy(
int n,
double *wt, Func<Real> *u, Func<Real> *v)
263 Scalar result = Scalar(0);
264 for (
int i = 0; i < n; i++)
265 result += wt[i] * (u->dy[i] * v->dy[i]);
269 template<
typename Real,
typename Scalar>
270 Scalar int_dudx_dvdy(
int n,
double *wt, Func<Real> *u, Func<Real> *v)
272 Scalar result = Scalar(0);
273 for (
int i = 0; i < n; i++)
274 result += wt[i] * (u->dx[i] * v->dy[i]);
278 template<
typename Real,
typename Scalar>
279 Scalar int_dudy_dvdx(
int n,
double *wt, Func<Real> *u, Func<Real> *v)
281 Scalar result = Scalar(0);
282 for (
int i = 0; i < n; i++)
283 result += wt[i] * (v->dx[i] * u->dy[i]);
287 template<
typename Real,
typename Scalar>
288 Scalar int_w_nabla_u_v(
int n,
double *wt, Func<Real> *w1, Func<Real> *w2,
289 Func<Real> *u, Func<Real> *v)
291 Scalar result = Scalar(0);
292 for (
int i = 0; i < n; i++)
293 result += wt[i] * (w1->val[i] * u->dx[i] + w2->val[i] * u->dy[i]) * v->val[i];
302 #define h1_integrate_expression(exp) \
303 {double3* pt = quad->get_points(o, ru->get_active_element()->get_mode()); \
304 unsigned char np = quad->get_num_points(o, ru->get_active_element()->get_mode()); \
305 if (ru->is_jacobian_const()){ \
306 for (int i = 0; i < np; i++) \
307 result += pt[i][2] * (exp); \
308 result *= ru->get_const_jacobian(); \
311 double* jac = ru->get_jacobian(o); \
312 for (int i = 0; i < np; i++) \
313 result += pt[i][2] * jac[i] * (exp); \
318 template<
typename Scalar>
319 inline double int_h1_error(Function<Scalar>* fu, Function<Scalar>* fv, RefMap* ru, RefMap* rv)
321 Quad2D* quad = fu->get_quad_2d();
322 assert(quad == fv->get_quad_2d());
324 int o = std::max(2 * fu->get_fn_order(), 2 * fv->get_fn_order()) + ru->get_inv_ref_order();
325 limit_order(o, ru->get_active_element()->get_mode());
326 fu->set_quad_order(o);
327 fv->set_quad_order(o);
329 Scalar* fnu = fu->get_fn_values();
330 Scalar* fnv = fv->get_fn_values();
332 Scalar *dudx, *dudy, *dvdx, *dvdy;
333 fu->get_dx_dy_values(dudx, dudy);
334 fv->get_dx_dy_values(dvdx, dvdy);
337 h1_integrate_expression(sqr(fnu[i] - fnv[i]) + sqr(dudx[i] - dvdx[i]) + sqr(dudy[i] - dvdy[i]));
341 template<
typename Scalar>
342 inline double int_h1_semi_error(Function<Scalar>* fu, Function<Scalar>* fv, RefMap* ru, RefMap* rv)
344 Quad2D* quad = fu->get_quad_2d();
345 assert(quad == fv->get_quad_2d());
347 int o = std::max(2 * fu->get_fn_order(), 2 * fv->get_fn_order()) + ru->get_inv_ref_order();
348 limit_order(o, ru->get_active_element()->get_mode());
349 fu->set_quad_order(o);
350 fv->set_quad_order(o);
352 Scalar* fnu = fu->get_fn_values();
353 Scalar* fnv = fv->get_fn_values();
355 Scalar *dudx, *dudy, *dvdx, *dvdy;
356 fu->get_dx_dy_values(dudx, dudy);
357 fv->get_dx_dy_values(dvdx, dvdy);
360 h1_integrate_expression(sqr(dudx[i] - dvdx[i]) + sqr(dudy[i] - dvdy[i]));
364 template<
typename Scalar>
365 inline double int_l2_error(Function<Scalar>* fu, Function<Scalar>* fv, RefMap* ru, RefMap* rv)
367 Quad2D* quad = fu->get_quad_2d();
368 assert(quad == fv->get_quad_2d());
370 int o = std::max(2 * fu->get_fn_order(), 2 * fv->get_fn_order()) + ru->get_inv_ref_order();
371 limit_order(o, ru->get_active_element()->get_mode());
375 Scalar* fnu = fu->get_fn_values();
376 Scalar* fnv = fv->get_fn_values();
379 h1_integrate_expression(sqr(fnu[i] - fnv[i]));
383 template<
typename Scalar>
384 inline double int_dx_error(Function<Scalar>* fu, Function<Scalar>* fv, RefMap* ru, RefMap* rv)
386 Quad2D* quad = fu->get_quad_2d();
387 assert(quad == fv->get_quad_2d());
389 int o = std::max(2 * fu->get_fn_order(), 2 * fv->get_fn_order()) + ru->get_inv_ref_order();
390 limit_order(o, ru->get_active_element()->get_mode());
391 fu->set_quad_order(o);
392 fv->set_quad_order(o);
394 Scalar *dudx, *dudy, *dvdx, *dvdy;
395 fu->get_dx_dy_values(dudx, dudy);
396 fv->get_dx_dy_values(dvdx, dvdy);
399 h1_integrate_expression(sqr(dudx[i] - dvdx[i]));
403 template<
typename Scalar>
404 inline double int_dy_error(Function<Scalar>* fu, Function<Scalar>* fv, RefMap* ru, RefMap* rv)
406 Quad2D* quad = fu->get_quad_2d();
407 assert(quad == fv->get_quad_2d());
409 int o = std::max(2 * fu->get_fn_order(), 2 * fv->get_fn_order()) + ru->get_inv_ref_order();
410 limit_order(o, ru->get_active_element()->get_mode());
411 fu->set_quad_order(o);
412 fv->set_quad_order(o);
414 Scalar *dudx, *dudy, *dvdx, *dvdy;
415 fu->get_dx_dy_values(dudx, dudy);
416 fv->get_dx_dy_values(dvdx, dvdy);
419 h1_integrate_expression(sqr(dudy[i] - dvdy[i]));
423 template<
typename Scalar>
424 inline double int_h1_norm(Function<Scalar>* fu, RefMap* ru)
426 Quad2D* quad = fu->get_quad_2d();
428 int o = 2 * fu->get_fn_order() + ru->get_inv_ref_order();
429 limit_order(o, ru->get_active_element()->get_mode());
430 fu->set_quad_order(o);
432 Scalar* fnu = fu->get_fn_values();
434 fu->get_dx_dy_values(dudx, dudy);
437 h1_integrate_expression(sqr(fnu[i]) + sqr(dudx[i]) + sqr(dudy[i]));
441 template<
typename Scalar>
442 inline double int_h1_seminorm(Function<Scalar>* fu, RefMap* ru)
444 Quad2D* quad = fu->get_quad_2d();
446 int o = 2 * fu->get_fn_order() + ru->get_inv_ref_order();
447 limit_order(o, ru->get_active_element()->get_mode());
448 fu->set_quad_order(o);
450 Scalar* fnu = fu->get_fn_values();
452 fu->get_dx_dy_values(dudx, dudy);
455 h1_integrate_expression(sqr(dudx[i]) + sqr(dudy[i]));
459 template<
typename Scalar>
460 inline double int_l2_norm(Function<Scalar>* fu, RefMap* ru)
462 Quad2D* quad = fu->get_quad_2d();
464 int o = 2 * fu->get_fn_order() + ru->get_inv_ref_order();
465 limit_order(o, ru->get_active_element()->get_mode());
468 Scalar* fnu = fu->get_fn_values();
471 h1_integrate_expression(sqr(fnu[i]));
const int H2D_FN_VAL
Both components are usually requested together...