30 scalar_type global_function_simple::val
31 (
const fem_interpolation_context &c)
const {
32 base_node pt = c.xreal();
33 GMM_ASSERT1(pt.size() == dim_,
"Point of wrong size (" << pt.size() <<
") "
34 <<
"passed to a global function of dim = "<< dim_ <<
".");
38 void global_function_simple::grad
39 (
const fem_interpolation_context &c, base_small_vector &g)
const {
40 base_node pt = c.xreal();
41 GMM_ASSERT1(pt.size() == dim_,
"Point of wrong size (" << pt.size() <<
") "
42 <<
"passed to a global function of dim = "<< dim_ <<
".");
46 void global_function_simple::hess
47 (
const fem_interpolation_context &c, base_matrix &h)
const {
48 base_node pt = c.xreal();
49 GMM_ASSERT1(pt.size() == dim_,
"Point of wrong size (" << pt.size() <<
") "
50 <<
"passed to a global function of dim = "<< dim_ <<
".");
56 scalar_type global_function_parser::val(
const base_node &pt)
const {
57 const bgeot::base_tensor &t = tensor_val(pt);
58 GMM_ASSERT1(t.size() == 1,
"Wrong size of expression result "
59 << f_val.expression());
63 const base_tensor &global_function_parser::tensor_val(
const base_node &pt)
const {
68 void global_function_parser::grad(
const base_node &pt, base_small_vector &g)
const {
71 const bgeot::base_tensor &t = f_grad.eval();
72 GMM_ASSERT1(t.size() == dim_,
"Wrong size of expression result "
73 << f_grad.expression());
78 void global_function_parser::hess(
const base_node &pt, base_matrix &h)
const {
81 const bgeot::base_tensor &t = f_hess.eval();
82 GMM_ASSERT1(t.size() ==
size_type(dim_*dim_),
83 "Wrong size of expression result " << f_hess.expression());
87 global_function_parser::global_function_parser(dim_type dim__,
88 const std::string &sval,
89 const std::string &sgrad,
90 const std::string &shess)
91 : global_function_simple(dim__),
92 f_val(gw, sval), f_grad(gw, sgrad), f_hess(gw, shess) {
97 gw.add_fixed_size_variable(
"X", gmm::sub_interval(0, N), pt_);
98 if (N >= 1) gw.add_macro(
"x",
"X(1)");
99 if (N >= 2) gw.add_macro(
"y",
"X(2)");
100 if (N >= 3) gw.add_macro(
"z",
"X(3)");
101 if (N >= 4) gw.add_macro(
"w",
"X(4)");
110 scalar_type global_function_sum::val
111 (
const fem_interpolation_context &c)
const {
113 for (
const auto &f : functions)
118 void global_function_sum::grad
119 (
const fem_interpolation_context &c, base_small_vector &g)
const {
122 base_small_vector gg(dim_);
123 for (
const auto &f : functions) {
129 void global_function_sum::hess
130 (
const fem_interpolation_context &c, base_matrix &h)
const {
131 h.resize(dim_, dim_);
133 base_matrix hh(dim_, dim_);
134 for (
const auto &f : functions) {
136 gmm::add(hh.as_vector(), h.as_vector());
140 bool global_function_sum::is_in_support(
const base_node &p)
const {
141 for (
const auto &f : functions)
142 if (f->is_in_support(p))
return true;
146 void global_function_sum::bounding_box
147 (base_node &bmin_, base_node &bmax_)
const {
148 if (functions.size() > 0)
149 functions[0]->bounding_box(bmin_, bmax_);
150 base_node bmin0(dim()), bmax0(dim());
151 for (
const auto &f : functions) {
152 f->bounding_box(bmin0, bmax0);
154 if (bmin0[i] < bmin_[i]) bmin_[i] = bmin0[i];
155 if (bmax0[i] > bmax_[i]) bmax_[i] = bmax0[i];
160 global_function_sum::global_function_sum(
const std::vector<pglobal_function> &funcs)
161 : global_function((funcs.size() > 0) ? funcs[0]->dim() : 0), functions(funcs) {
162 for (
const auto &f : functions)
163 GMM_ASSERT1(f->dim() == dim(),
"Incompatible dimensions among the provided"
164 " global functions");
167 global_function_sum::global_function_sum(pglobal_function f1, pglobal_function f2)
168 : global_function(f1->dim()), functions(2) {
171 GMM_ASSERT1(f1->dim() == dim() && f2->dim() == dim(),
172 "Incompatible dimensions between the provided global functions");
175 global_function_sum::global_function_sum(pglobal_function f1, pglobal_function f2,
177 : global_function(f1->dim()), functions(3) {
181 GMM_ASSERT1(f1->dim() == dim() && f2->dim() == dim() && f3->dim() == dim(),
182 "Incompatible dimensions between the provided global functions");
185 global_function_sum::global_function_sum(pglobal_function f1, pglobal_function f2,
186 pglobal_function f3, pglobal_function f4)
187 : global_function(f1->dim()), functions(4) {
192 GMM_ASSERT1(f1->dim() == dim() && f2->dim() == dim() && f3->dim() == dim(),
193 "Incompatible dimensions between the provided global functions");
199 scalar_type global_function_product::val
200 (
const fem_interpolation_context &c)
const {
201 return f1->val(c) * f2->val(c);
204 void global_function_product::grad
205 (
const fem_interpolation_context &c, base_small_vector &g)
const {
207 base_small_vector gg(dim_);
209 gmm::copy(gmm::scaled(gg, f2->val(c)), g);
211 gmm::add(gmm::scaled(gg, f1->val(c)), g);
214 void global_function_product::hess
215 (
const fem_interpolation_context &c, base_matrix &h)
const {
216 h.resize(dim_, dim_);
218 base_matrix hh(dim_, dim_);
220 gmm::copy(gmm::scaled(hh, f2->val(c)), h);
222 gmm::add(gmm::scaled(hh, f1->val(c)), h);
223 base_small_vector g1(dim_), g2(dim_);
226 gmm::rank_one_update(h, g1, g2);
227 gmm::rank_one_update(h, g2, g1);
230 bool global_function_product::is_in_support(
const base_node &p)
const {
231 return f1->is_in_support(p) && f2->is_in_support(p);
234 void global_function_product::bounding_box
235 (base_node &bmin_, base_node &bmax_)
const {
236 base_node bmin0(dim()), bmax0(dim());
237 f1->bounding_box(bmin0, bmax0);
238 f2->bounding_box(bmin_, bmax_);
240 if (bmin0[i] > bmin_[i]) bmin_[i] = bmin0[i];
241 if (bmax0[i] < bmax_[i]) bmax_[i] = bmax0[i];
242 if (bmin_[i] > bmax_[i])
243 GMM_WARNING1(
"Global function product with vanishing basis function");
247 global_function_product::global_function_product(pglobal_function f1_, pglobal_function f2_)
248 : global_function(f1_->dim()), f1(f1_), f2(f2_) {
249 GMM_ASSERT1(f2->dim() == dim(),
"Incompatible dimensions between the provided"
250 " global functions");
256 bool global_function_bounded::is_in_support(
const base_node &pt)
const {
259 const bgeot::base_tensor &t = f_val.eval();
260 GMM_ASSERT1(t.size() == 1,
"Wrong size of expression result "
261 << f_val.expression());
262 return (t[0] > scalar_type(0));
267 global_function_bounded::global_function_bounded(pglobal_function f_,
268 const base_node &bmin_,
269 const base_node &bmax_,
270 const std::string &is_in_expr)
271 : global_function(f_->dim()), f(f_), bmin(bmin_), bmax(bmax_),
272 f_val(gw, is_in_expr) {
274 has_expr = !is_in_expr.empty();
279 gw.add_fixed_size_variable(
"X", gmm::sub_interval(0, N), pt_);
280 if (N >= 1) gw.add_macro(
"x",
"X(1)");
281 if (N >= 2) gw.add_macro(
"y",
"X(2)");
282 if (N >= 3) gw.add_macro(
"z",
"X(3)");
283 if (N >= 4) gw.add_macro(
"w",
"X(4)");
290 parser_xy_function::parser_xy_function(
const std::string &sval,
291 const std::string &sgrad,
292 const std::string &shess)
293 : f_val(gw, sval), f_grad(gw, sgrad), f_hess(gw, shess),
294 ptx(1), pty(1), ptr(1), ptt(1) {
296 gw.add_fixed_size_constant(
"x", ptx);
297 gw.add_fixed_size_constant(
"y", pty);
298 gw.add_fixed_size_constant(
"r", ptr);
299 gw.add_fixed_size_constant(
"theta", ptt);
307 parser_xy_function::val(scalar_type x, scalar_type y)
const {
310 ptr[0] = double(sqrt(fabs(x*x+y*y)));
311 ptt[0] = double(atan2(y,x));
313 const bgeot::base_tensor &t = f_val.eval();
314 GMM_ASSERT1(t.size() == 1,
"Wrong size of expression result "
315 << f_val.expression());
320 parser_xy_function::grad(scalar_type x, scalar_type y)
const {
323 ptr[0] = double(sqrt(fabs(x*x+y*y)));
324 ptt[0] = double(atan2(y,x));
326 base_small_vector res(2);
327 const bgeot::base_tensor &t = f_grad.eval();
328 GMM_ASSERT1(t.size() == 2,
"Wrong size of expression result "
329 << f_grad.expression());
335 parser_xy_function::hess(scalar_type x, scalar_type y)
const {
338 ptr[0] = double(sqrt(fabs(x*x+y*y)));
339 ptt[0] = double(atan2(y,x));
341 base_matrix res(2,2);
342 const bgeot::base_tensor &t = f_hess.eval();
343 GMM_ASSERT1(t.size() == 4,
"Wrong size of expression result "
344 << f_hess.expression());
345 gmm::copy(t.as_vector(), res.as_vector());
351 crack_singular_xy_function::val(scalar_type x, scalar_type y)
const {
352 scalar_type sgny = (y < 0 ? -1.0 : 1.0);
353 scalar_type r = sqrt(x*x + y*y);
354 if (r < 1e-10)
return 0;
359 scalar_type sin2 = sqrt(gmm::abs(.5-x/(2*r))) * sgny;
360 scalar_type cos2 = sqrt(gmm::abs(.5+x/(2*r)));
367 case 0 : res = sqrt(r)*sin2;
break;
368 case 1 : res = sqrt(r)*cos2;
break;
369 case 2 : res = sin2*y/sqrt(r);
break;
370 case 3 : res = cos2*y/sqrt(r);
break;
374 case 4 : res = sqrt(r)*r*sin2;
break;
375 case 5 : res = sqrt(r)*r*cos2;
break;
376 case 6 : res = sin2*cos2*cos2*r*sqrt(r);
break;
377 case 7 : res = cos2*cos2*cos2*r*sqrt(r);
break;
381 case 8 : res = -sin2/sqrt(r);
break;
382 case 9 : res = cos2/sqrt(r);
break;
386 case 10 : res = sin2*sqrt(r);
break;
387 case 11 : res = cos2*sqrt(r);
break;
391 case 12 : res = r*sin2*sin2;
break;
392 case 13 : res = sqrt(r)*sin2;
break;
396 case 14 : res = sin2/r;
break;
397 case 15 : res = cos2/r;
break;
399 default: GMM_ASSERT2(
false,
"arg");
406 crack_singular_xy_function::grad(scalar_type x, scalar_type y)
const {
407 scalar_type sgny = (y < 0 ? -1.0 : 1.0);
408 scalar_type r = sqrt(x*x + y*y);
411 GMM_WARNING0(
"Warning, point close to the singularity (r=" << r <<
")");
417 scalar_type sin2 = sqrt(gmm::abs(.5-x/(2*r))) * sgny;
418 scalar_type cos2 = sqrt(gmm::abs(.5+x/(2*r)));
420 base_small_vector res(2);
424 res[0] = -sin2/(2*sqrt(r));
425 res[1] = cos2/(2*sqrt(r));
428 res[0] = cos2/(2*sqrt(r));
429 res[1] = sin2/(2*sqrt(r));
432 res[0] = cos2*((-5*cos2*cos2) + 1. + 4*(cos2*cos2*cos2*cos2))/sqrt(r);
433 res[1] = sin2*((-3*cos2*cos2) + 1. + 4*(cos2*cos2*cos2*cos2))/sqrt(r);
436 res[0] = -cos2*cos2*sin2*((4*cos2*cos2) - 3.)/sqrt(r);
437 res[1] = cos2*((4*cos2*cos2*cos2*cos2) + 2. - (5*cos2*cos2))/sqrt(r);
442 res[0] = sin2 *((4*cos2*cos2)-3.)*sqrt(r)/2.;
443 res[1] = cos2*(5. - (4*cos2*cos2))*sqrt(r)/2. ;
446 res[0] = cos2*((4*cos2*cos2)-1.)*sqrt(r)/2.;
447 res[1] = sin2*((4*cos2*cos2)+1.)*sqrt(r)/2. ;
451 res[0] = sin2*cos2*cos2*sqrt(r)/2.;
452 res[1] = cos2*(2. - (cos2*cos2))*sqrt(r)/2.;
455 res[0] = 3*cos2*cos2*cos2*sqrt(r)/2.;
456 res[1] = 3*sin2*cos2*cos2*sqrt(r)/2.;
462 res[0] =sin2*((4*cos2*cos2)-1.)/(2*sqrt(r)*r);
463 res[1] =-cos2*((4*cos2*cos2)-3.)/(2*sqrt(r)*r);
466 res[0] =-cos2*((4*cos2*cos2) - 3.)/(2*sqrt(r)*r);
467 res[1] =-sin2*((4*cos2*cos2)-1.)/(2*sqrt(r)*r);
472 res[0] = -sin2/(2*sqrt(r));
473 res[1] = cos2/(2*sqrt(r));
476 res[0] = cos2/(2*sqrt(r));
477 res[1] = sin2/(2*sqrt(r));
487 res[0] = -sin2/(2*sqrt(r));
488 res[1] = cos2/(2*sqrt(r));
495 res[0] = -sin2*((3*cos2*cos2) - 1.)/(r*r);
496 res[1] = cos2*((6*cos2*cos2) - 5.)/(2*r*r);
499 res[0] = -cos2*((3*cos2*cos2) - 2.)/(r*r);
500 res[1] = -sin2*((6*cos2*cos2) - 1.)/(2*r*r);
504 default: GMM_ASSERT2(
false,
"oups");
510 crack_singular_xy_function::hess(scalar_type x, scalar_type y)
const {
511 scalar_type sgny = (y < 0 ? -1.0 : 1.0);
512 scalar_type r = sqrt(x*x + y*y);
515 GMM_WARNING0(
"Warning, point close to the singularity (r=" << r <<
")");
521 scalar_type sin2 = sqrt(gmm::abs(.5-x/(2*r))) * sgny;
522 scalar_type cos2 = sqrt(gmm::abs(.5+x/(2*r)));
524 base_matrix res(2,2);
527 res(0,0) = (-sin2*x*x + 2.0*cos2*x*y + sin2*y*y) / (4*pow(r, 3.5));
528 res(0,1) = (-cos2*x*x - 2.0*sin2*x*y + cos2*y*y) / (4*pow(r, 3.5));
529 res(1,0) = res(0, 1);
530 res(1,1) = (sin2*x*x - 2.0*cos2*x*y - sin2*y*y) / (4*pow(r, 3.5));
533 res(0,0) = (-cos2*x*x - 2.0*sin2*x*y + cos2*y*y) / (4*pow(r, 3.5));
534 res(0,1) = (sin2*x*x - 2.0*cos2*x*y - sin2*y*y) / (4*pow(r, 3.5));
535 res(1,0) = res(0, 1);
536 res(1,1) = (cos2*x*x + 2.0*sin2*x*y - cos2*y*y) / (4*pow(r, 3.5));
539 res(0,0) = 3.0*y*(sin2*x*x + 2.0*cos2*x*y - sin2*y*y) / (4*pow(r, 4.5));
540 res(0,1) = (-2.0*sin2*x*x*x - 5.0*cos2*y*x*x + 4.0*sin2*y*y*x + cos2*y*y*y)
542 res(1,0) = res(0, 1);
543 res(1,1) = (4.0*cos2*x*x*x - 7.0*sin2*y*x*x - 2.0*cos2*y*y*x - sin2*y*y*y)
547 res(0,0) = 3.0*y*(cos2*x*x - 2.0*sin2*x*y - cos2*y*y) / (4*pow(r, 4.5));
548 res(0,1) = (-2.0*cos2*x*x*x + 5.0*sin2*y*x*x + 4.0*cos2*y*y*x - sin2*y*y*y)
550 res(1,0) = res(0, 1);
551 res(1,1) = (-4.0*sin2*x*x*x - 7.0*cos2*y*x*x + 2.0*sin2*y*y*x - cos2*y*y*y)
555 res(0,0) = (sin2*(-4*cos2*cos2*cos2*cos2 + 3*cos2*cos2 + 0.75))/sqrt(r);
556 res(0,1) = (cos2*(4*cos2*cos2*cos2*cos2 - 5*cos2*cos2 + 1.25))/sqrt(r);
557 res(1,1) = (sin2*(4*cos2*cos2*cos2*cos2 - 3*cos2*cos2 + 1.25))/sqrt(r);
561 res(0,0) = (cos2*(-4*cos2*cos2*cos2*cos2 + 5*cos2*cos2 - 0.25))/sqrt(r);
562 res(0,1) = (sin2*(-4*cos2*cos2*cos2*cos2 + 3*cos2*cos2 - 0.25))/sqrt(r);
563 res(1,1) = (cos2*(4*cos2*cos2*cos2*cos2 - 5*cos2*cos2 + 2.25))/sqrt(r);
567 res(0,0) = (cos2*cos2*sin2*(0.75 - cos2*cos2))/sqrt(r);
568 res(0,1) = (cos2*(cos2*cos2*cos2*cos2 - 1.25*cos2*cos2 + 0.5))/sqrt(r);
569 res(1,1) = (sin2*(cos2*cos2*cos2*cos2 - 0.75*cos2*cos2 + 0.5))/sqrt(r);
573 res(0,0) = (3*cos2*cos2*cos2*(1.25 - cos2*cos2))/sqrt(r);
574 res(0,1) = (3*cos2*cos2*sin2*(0.75 - cos2*cos2))/sqrt(r);
575 res(1,1) = (3*cos2*(cos2*cos2*cos2*cos2 - 1.25*cos2*cos2 + 0.5))/sqrt(r);
579 res(0,0) = (3*sin2*(-4*cos2*cos2*cos2*cos2 + 3*cos2*cos2 - 0.25))/(r*r*sqrt(r));
580 res(0,1) = (3*cos2*(4*cos2*cos2*cos2*cos2 - 5*cos2*cos2 + 1.25))/(r*r*sqrt(r));
581 res(1,1) = (3*sin2*(4*cos2*cos2*cos2*cos2 - 3*cos2*cos2 + 0.25))/(r*r*sqrt(r));
585 res(0,0) = (3*cos2*(4*cos2*cos2*cos2*cos2 - 5*cos2*cos2 + 1.25))/(r*r*sqrt(r));
586 res(0,1) = (3*sin2*(4*cos2*cos2*cos2*cos2 - 3*cos2*cos2 + 0.25))/(r*r*sqrt(r));
587 res(1,1) = (3*cos2*(-4*cos2*cos2*cos2*cos2 + 5*cos2*cos2 - 1.25))/(r*r*sqrt(r));
591 res(0,0) = (sin2*(cos2*cos2 - 0.25))/(r*sqrt(r));
592 res(0,1) = (cos2*(0.75 - cos2*cos2))/(r*sqrt(r));
593 res(1,1) = (sin2*(0.25 - cos2*cos2))/(r*sqrt(r));
597 res(0,0) = (cos2*(0.75 - cos2*cos2))/(r*sqrt(r));
598 res(0,1) = (sin2*(0.25 - cos2*cos2))/(r*sqrt(r));
599 res(1,1) = (cos2*(cos2*cos2 - 0.75))/(r*sqrt(r));
603 res(0,0) = (2*cos2*cos2*(1 - cos2*cos2))/r;
604 res(0,1) = (cos2*sin2*(1 - 2*cos2*cos2))/r;
605 res(1,1) = (2*cos2*cos2*cos2*cos2 - 2*cos2*cos2 + 0.5)/r;
609 res(0,0) = (sin2*(cos2*cos2 - 0.25))/(r*sqrt(r));
610 res(0,1) = (cos2*(0.75 - cos2*cos2))/(r*sqrt(r));
611 res(1,1) = (sin2*(0.25 - cos2*cos2))/(r*sqrt(r));
615 res(0,0) = (sin2*(21*cos2*cos2*cos2*cos2 - 17*cos2*cos2 + 2))/(r*r*r);
616 res(0,1) = (cos2*(-21*cos2*cos2*cos2*cos2 + 27.5*cos2*cos2 - 7.5))/(r*r*r);
617 res(1,1) = (sin2*(-21*cos2*cos2*cos2*cos2 + 17*cos2*cos2 - 1.25))/(r*r*r);
621 res(0,0) = (cos2*(21*cos2*cos2*cos2*cos2 - 25*cos2*cos2 + 6))/(r*r*r);
622 res(0,1) = (sin2*(21*cos2*cos2*cos2*cos2 - 14.5*cos2*cos2 + 1))/(r*r*r);
623 res(1,1) = (cos2*(-21*cos2*cos2*cos2*cos2 + 25*cos2*cos2 - 5.25))/(r*r*r);
626 default: GMM_ASSERT2(
false,
"oups");
632 cutoff_xy_function::val(scalar_type x, scalar_type y)
const {
635 case EXPONENTIAL_CUTOFF: {
636 res = (a4>0) ? exp(-a4 * gmm::sqr(x*x+y*y)) : 1;
639 case POLYNOMIAL_CUTOFF: {
641 scalar_type r = gmm::sqrt(x*x+y*y);
643 if (r <= r1) res = 1;
644 else if (r >= r0) res = 0;
650 scalar_type c = 1./pow(r0-r1,3.0);
651 res = c*(r*(r*(2.0*r-3.0*(r0+r1))+6.0*r1*r0) + r0*r0*(r0-3.0*r1));
655 case POLYNOMIAL2_CUTOFF: {
657 scalar_type r = gmm::sqrt(x*x+y*y);
658 if (r <= r1) res = scalar_type(1);
659 else if (r >= r0) res = scalar_type(0);
671 res = (r*(r*(r*(r*(-6.0*r + 15.0*(r0+r1))
672 - 10.0*(r0*r0 + 4.0*r1*r0 + r1*r1))
673 + 30.0 * r0*r1*(r0+r1)) - 30.0*r1*r1*r0*r0)
674 + r0*r0*r0*(r0*r0-5.0*r1*r0+10*r1*r1)) / pow(r0-r1, 5.0);
684 cutoff_xy_function::grad(scalar_type x, scalar_type y)
const {
685 base_small_vector res(2);
687 case EXPONENTIAL_CUTOFF: {
688 scalar_type r2 = x*x+y*y, ratio = -4.*exp(-a4*r2*r2)*a4*r2;
693 case POLYNOMIAL_CUTOFF: {
694 scalar_type r = gmm::sqrt(x*x+y*y);
695 scalar_type ratio = 0;
697 if ( r > r1 && r < r0 ) {
700 ratio = 6.*(r - r0)*(r - r1)/pow(r0-r1, 3.);
706 case POLYNOMIAL2_CUTOFF: {
707 scalar_type r = gmm::sqrt(x*x+y*y);
708 scalar_type ratio = 0;
709 if (r > r1 && r < r0) {
715 ratio = -30.0*gmm::sqr(r-r0)*gmm::sqr(r-r1) / pow(r0-r1, 5.0);
729 cutoff_xy_function::hess(scalar_type x, scalar_type y)
const {
730 base_matrix res(2,2);
732 case EXPONENTIAL_CUTOFF: {
733 scalar_type r2 = x*x+y*y, r4 = r2*r2;
734 res(0,0) = 4.0*a4*(-3.0*x*x - y*y + 4.0*a4*x*x*r4)*exp(-a4*r4);
735 res(1,0) = 8.0*a4*x*y*(-1.0 + 2.0*a4*r4)*exp(-a4*r4);
737 res(1,1) = 4.0*a4*(-3.0*y*y - x*x + 4.0*a4*y*y*r4)*exp(-a4*r4);
740 case POLYNOMIAL_CUTOFF: {
741 scalar_type r2 = x*x+y*y, r = gmm::sqrt(r2), c=6./(pow(r0-r1,3.)*r*r2);
742 if ( r > r1 && r < r0 ) {
743 res(0,0) = c*(x*x*r2 + r1*r0*y*y - r*r2*(r0+r1) + r2*r2);
744 res(1,0) = c*x*y*(r2 - r1*r0);
746 res(1,1) = c*(y*y*r2 + r1*r0*x*x - r*r2*(r0+r1) + r2*r2);
750 case POLYNOMIAL2_CUTOFF: {
751 scalar_type r2 = x*x+y*y, r = gmm::sqrt(r2), r3 = r*r2;
752 if (r > r1 && r < r0) {
753 scalar_type dp = -30.0*(r1-r)*(r1-r)*(r0-r)*(r0-r) / pow(r0-r1, 5.0);
754 scalar_type ddp = 60.0*(r1-r)*(r0-r)*(r0+r1-2.0*r) / pow(r0-r1, 5.0);
755 scalar_type rx= x/r, ry= y/r, rxx= y*y/r3, rxy= -x*y/r3, ryy= x*x/r3;
756 res(0,0) = ddp*rx*rx + dp*rxx;
757 res(1,0) = ddp*rx*ry + dp*rxy;
759 res(1,1) = ddp*ry*ry + dp*ryy;
767 cutoff_xy_function::cutoff_xy_function(
int fun_num, scalar_type r,
768 scalar_type r1_, scalar_type r0_)
773 if (r > 0) a4 = pow(2.7/r,4.);
777 struct global_function_on_levelsets_2D_ :
778 public global_function,
public context_dependencies {
779 const std::vector<level_set> dummy_lsets;
780 const std::vector<level_set> &lsets;
782 mutable pmesher_signed_distance mls_x, mls_y;
790 if (lsets.size() == 0) {
791 mls_x = ls.mls_of_convex(cv, 1);
792 mls_y = ls.mls_of_convex(cv, 0);
795 scalar_type d = scalar_type(-2);
796 for (
const level_set &ls_ : lsets) {
797 pmesher_signed_distance mls_xx, mls_yy;
798 mls_xx = ls_.mls_of_convex(cv, 1);
799 mls_yy = ls_.mls_of_convex(cv, 0);
800 scalar_type x = (*mls_xx)(pt), y = (*mls_yy)(pt);
801 scalar_type d2 = gmm::sqr(x) + gmm::sqr(y);
802 if (d < scalar_type(-1) || d2 < d) {
812 virtual scalar_type val(
const fem_interpolation_context& c)
const {
813 update_mls(c.convex_num(), c.xref().size());
814 scalar_type x = (*mls_x)(c.xref());
815 scalar_type y = (*mls_y)(c.xref());
816 if (c.xfem_side() > 0 && y <= 1E-13) y = 1E-13;
817 if (c.xfem_side() < 0 && y >= -1E-13) y = -1E-13;
820 virtual void grad(
const fem_interpolation_context& c,
821 base_small_vector &g)
const {
823 base_small_vector dx(P), dy(P), dfr(2);
825 update_mls(c.convex_num(), P);
826 scalar_type x = mls_x->grad(c.xref(), dx);
827 scalar_type y = mls_y->grad(c.xref(), dy);
828 if (c.xfem_side() > 0 && y <= 0) y = 1E-13;
829 if (c.xfem_side() < 0 && y >= 0) y = -1E-13;
831 base_small_vector gfn = fn->grad(x,y);
832 gmm::mult(c.B(), gfn[0]*dx + gfn[1]*dy, g);
834 virtual void hess(
const fem_interpolation_context&c,
835 base_matrix &h)
const {
836 size_type P = c.xref().size(), N = c.N();
837 base_small_vector dx(P), dy(P), dfr(2), dx_real(N), dy_real(N);
839 update_mls(c.convex_num(), P);
840 scalar_type x = mls_x->grad(c.xref(), dx);
841 scalar_type y = mls_y->grad(c.xref(), dy);
842 if (c.xfem_side() > 0 && y <= 0) y = 1E-13;
843 if (c.xfem_side() < 0 && y >= 0) y = -1E-13;
845 base_small_vector gfn = fn->grad(x,y);
846 base_matrix hfn = fn->hess(x,y);
848 base_matrix hx, hy, hx_real(N*N, 1), hy_real(N*N, 1);
849 mls_x->hess(c.xref(), hx);
850 mls_y->hess(c.xref(), hy);
856 gmm::mult_add(c.B32(), gmm::scaled(dx, -1.0), gmm::mat_col(hx_real, 0));
858 gmm::mult_add(c.B32(), gmm::scaled(dy, -1.0), gmm::mat_col(hy_real, 0));
864 h(i, j) = hfn(0,0) * dx_real[i] * dx_real[j]
865 + hfn(0,1) * dx_real[i] * dy_real[j]
866 + hfn(1,0) * dy_real[i] * dx_real[j]
867 + hfn(1,1) * dy_real[i] * dy_real[j]
868 + gfn[0] * hx_real(i * N + j, 0) + gfn[1] * hy_real(i*N+j,0);
872 void update_from_context()
const { cv =
size_type(-1); }
874 global_function_on_levelsets_2D_(
const std::vector<level_set> &lsets_,
875 const pxy_function &fn_)
876 : global_function(lsets_.size() ? lsets_[0].linked_mesh().dim() : 2),
877 dummy_lsets(0, dummy_level_set()),
878 lsets(lsets_), ls(dummy_level_set()), fn(fn_) {
879 GMM_ASSERT1(lsets.size() > 0,
"The list of level sets should"
880 " contain at least one level set.");
882 for (
const level_set &ls_ : lsets)
886 global_function_on_levelsets_2D_(
const level_set &ls_,
887 const pxy_function &fn_)
888 : global_function(ls_.linked_mesh().dim()),
889 dummy_lsets(0, dummy_level_set()),
890 lsets(dummy_lsets), ls(ls_), fn(fn_) {
898 global_function_on_level_sets(
const std::vector<level_set> &lsets,
899 const pxy_function &fn) {
900 return std::make_shared<global_function_on_levelsets_2D_>(lsets, fn);
904 global_function_on_level_set(
const level_set &ls,
905 const pxy_function &fn) {
906 return std::make_shared<global_function_on_levelsets_2D_>(ls, fn);
913 const scalar_type eps(1e-12);
916 scalar_type bsp3_01(scalar_type t) {
917 return (t >= -eps && t < 1) ? pow(1.-t,2)
920 scalar_type bsp3_01_der(scalar_type t) {
921 return (t >= -eps && t < 1) ? 2.*t-2.
924 scalar_type bsp3_01_der2(scalar_type t) {
925 return (t >= eps && t <= 1.-eps) ? 2.
928 scalar_type bsp3_01_der2_with_hint(scalar_type t, scalar_type t_hint) {
929 return (t > -eps && t < 1.+eps && t_hint > 0 && t_hint < 1) ? 2.
932 scalar_type bsp3_02(scalar_type t) {
935 return (-1.5*t+2.)*t;
937 return 0.5*pow(2.-t,2);
941 scalar_type bsp3_02_der(scalar_type t) {
950 scalar_type bsp3_02_der2(scalar_type t) {
956 else if (t <= 2.-eps)
961 scalar_type bsp3_03(scalar_type t) {
975 scalar_type bsp3_03_der(scalar_type t) {
988 scalar_type bsp3_03_der2(scalar_type t) {
992 else if (t <= 1.-eps)
996 else if (t <= 2.-eps)
1000 else if (t <= 3.-eps)
1002 else if (t < 3.+eps)
1009 scalar_type bsp4_01(scalar_type t) {
1010 return (t >= -eps && t < 1) ? pow(1.-t,3)
1013 scalar_type bsp4_01_der(scalar_type t) {
1014 return (t >= -eps && t < 1) ? -3*pow(1.-t,2)
1017 scalar_type bsp4_01_der2(scalar_type t) {
1018 return (t >= -eps && t < 1) ? 6*(1.-t)
1021 scalar_type bsp4_02(scalar_type t) {
1024 return ((7./4.*t-9./2.)*t+3.)*t;
1026 return 1./4.*pow(2.-t,3);
1031 scalar_type bsp4_02_der(scalar_type t) {
1034 return (21./4.*t-9.)*t+3.;
1036 return -3./4.*pow(2.-t,2);
1041 scalar_type bsp4_02_der2(scalar_type t) {
1046 return 3./2.*(2.-t);
1051 scalar_type bsp4_03(scalar_type t) {
1054 return (-11./12.*t+3./2.)*t*t;
1057 return ((7./12.*t-5./4.)*t+1./4.)*t+7./12.;
1059 return 1./6.*pow(3.-t,3);
1064 scalar_type bsp4_03_der(scalar_type t) {
1067 return (-11./4.*t+3.)*t;
1070 return (7./4.*t-5./2.)*t+1./4.;
1072 return -1./2.*pow(3.-t,2);
1077 scalar_type bsp4_03_der2(scalar_type t) {
1080 return -11./2.*t+3.;
1083 return 7./2.*t-5./2.;
1090 scalar_type bsp4_04(scalar_type t) {
1096 return 1./6.*pow(t,3);
1097 }
else if (t <= 2) {
1099 return ((-1./2.*t+1./2.)*t+1./2.)*t+1./6.;
1104 scalar_type bsp4_04_der(scalar_type t) {
1112 return 1./2.*pow(t,2)*sgn;
1115 return ((-3./2.*t+1.)*t+1./2.)*sgn;
1120 scalar_type bsp4_04_der2(scalar_type t) {
1137 scalar_type bsp5_01(scalar_type t) {
1138 return (t >= -eps && t < 1) ? pow(1.-t,4)
1141 scalar_type bsp5_01_der(scalar_type t) {
1142 return (t >= -eps && t < 1) ? -4.*pow(1.-t,3)
1145 scalar_type bsp5_01_der2(scalar_type t) {
1146 return (t >= -eps && t < 1) ? 12.*pow(1.-t,2)
1149 scalar_type bsp5_02(scalar_type t) {
1152 return (((-15./8.*t+7.)*t-9.)*t+4.)*t;
1154 return 1./8.*pow(2.-t,4);
1159 scalar_type bsp5_02_der(scalar_type t) {
1162 return ((-15./2.*t+21.)*t-18.)*t+4.;
1164 return -1./2.*pow(2.-t,3);
1169 scalar_type bsp5_02_der2(scalar_type t) {
1172 return (-45./2.*t+42.)*t-18.;
1174 return 3./2.*pow(2.-t,2);
1179 scalar_type bsp5_03(scalar_type t) {
1182 return ((85./72.*t-11./3.)*t+3.)*t*t;
1185 return (((-23./72*t+2./9.)*t+1./3.)*t+2./9.)*t+1./18.;
1187 return 1./18.*pow(3.-t,4);
1192 scalar_type bsp5_03_der(scalar_type t) {
1195 return ((85./18.*t-11.)*t+6.)*t;
1198 return -(((-23./18*t+2./3.)*t+2./3.)*t+2./9.);
1200 return -2./9.*pow(3.-t,3);
1205 scalar_type bsp5_03_der2(scalar_type t) {
1208 return (85./6.*t-22.)*t+6.;
1211 return (-23./6*t+4./3.)*t+2./3.;
1213 return 2./3.*pow(3.-t,2);
1218 scalar_type bsp5_04(scalar_type t) {
1221 return (-25./72.*t+2./3.)*t*t*t;
1224 return (((23./72.*t-5./9.)*t-1./3.)*t+4./9.)*t+4./9.;
1227 return (((-13./72.*t+5./9.)*t-1./3.)*t-4./9.)*t+4./9.;
1229 return 1./24.*pow(4.-t,4);
1234 scalar_type bsp5_04_der(scalar_type t) {
1237 return (-25./18.*t+2.)*t*t;
1240 return -(((23./18.*t-5./3.)*t-2./3.)*t+4./9.);
1243 return ((-13./18.*t+5./3.)*t-2./3.)*t-4./9.;
1245 return -1./6.*pow(4.-t,3);
1250 scalar_type bsp5_04_der2(scalar_type t) {
1253 return (-25./6.*t+4.)*t;
1256 return (23./6.*t-10./3.)*t-2./3.;
1259 return (-13./6.*t+10./3.)*t-2./3.;
1261 return 1./2.*pow(4.-t,2);
1266 scalar_type bsp5_05(scalar_type t) {
1267 if (t > scalar_type(2.5)) {
1272 return 1./24.*pow(t,4);
1275 return (((-1./6.*t+1./6.)*t+1./4.)*t+1./6.)*t+1./24.;
1278 return (1./4.*t-5./8.)*t+115./192.;
1283 scalar_type bsp5_05_der(scalar_type t) {
1285 if (t > scalar_type(2.5)) {
1291 return 1./6.*pow(t,3)*sgn;
1294 return (((-2./3.*t+1./2.)*t+1./2)*t+1./6.)*sgn;
1297 return (t*t-5./4.)*t*sgn;
1302 scalar_type bsp5_05_der2(scalar_type t) {
1303 if (t > scalar_type(2.5)) {
1308 return 1./2.*pow(t,2);
1311 return (-2.*t+1.)*t+1./2;
1322 class global_function_x_bspline_
1323 :
public global_function_simple,
public context_dependencies {
1324 scalar_type xmin, xmax, xscale;
1325 std::function<scalar_type(scalar_type)> fx, fx_der, fx_der2;
1327 void update_from_context()
const {}
1329 virtual scalar_type val(
const base_node &pt)
const
1331 return fx(xscale*(pt[0]-xmin));
1333 virtual void grad(
const base_node &pt, base_small_vector &g)
const
1335 scalar_type dx = xscale*(pt[0]-xmin);
1337 g[0] = xscale * fx_der(dx);
1339 virtual void hess(
const base_node &pt, base_matrix &h)
const
1341 scalar_type dx = xscale*(pt[0]-xmin);
1342 h.resize(dim_, dim_);
1344 h(0,0) = xscale*xscale * fx_der2(dx);
1347 virtual bool is_in_support(
const base_node &pt)
const {
1348 scalar_type dx = pt[0]-(xmin+xmax)/2;
1349 return (gmm::abs(dx)+1e-9 < gmm::abs(xmax-xmin)/2);
1352 virtual void bounding_box(base_node &bmin, base_node &bmax)
const {
1353 GMM_ASSERT1(bmin.size() == dim_ && bmax.size() == dim_,
1354 "Wrong dimensions");
1355 bmin[0] = std::min(xmin,xmax);
1356 bmax[0] = std::max(xmin,xmax);
1359 global_function_x_bspline_(
const scalar_type &xmin_,
const scalar_type &xmax_,
1361 : global_function_simple(1), xmin(xmin_), xmax(xmax_),
1362 xscale(scalar_type(xtype)/(xmax-xmin))
1364 GMM_ASSERT1(order >= 3 && order <= 5,
"Only orders 3 to 5 are supported");
1365 GMM_ASSERT1(xtype >= 1 && xtype <= order,
"Wrong input");
1368 fx = bsp3_01; fx_der = bsp3_01_der; fx_der2 = bsp3_01_der2;
1369 }
else if (xtype == 2) {
1370 fx = bsp3_02; fx_der = bsp3_02_der; fx_der2 = bsp3_02_der2;
1371 }
else if (xtype == 3) {
1372 fx = bsp3_03; fx_der = bsp3_03_der; fx_der2 = bsp3_03_der2;
1374 }
else if (order == 4) {
1376 fx = bsp4_01; fx_der = bsp4_01_der; fx_der2 = bsp4_01_der2;
1377 }
else if (xtype == 2) {
1378 fx = bsp4_02; fx_der = bsp4_02_der; fx_der2 = bsp4_02_der2;
1379 }
else if (xtype == 3) {
1380 fx = bsp4_03; fx_der = bsp4_03_der; fx_der2 = bsp4_03_der2;
1381 }
else if (xtype == 4) {
1382 fx = bsp4_04; fx_der = bsp4_04_der; fx_der2 = bsp4_04_der2;
1384 }
else if (order == 5) {
1386 fx = bsp5_01; fx_der = bsp5_01_der; fx_der2 = bsp5_01_der2;
1387 }
else if (xtype == 2) {
1388 fx = bsp5_02; fx_der = bsp5_02_der; fx_der2 = bsp5_02_der2;
1389 }
else if (xtype == 3) {
1390 fx = bsp5_03; fx_der = bsp5_03_der; fx_der2 = bsp5_03_der2;
1391 }
else if (xtype == 4) {
1392 fx = bsp5_04; fx_der = bsp5_04_der; fx_der2 = bsp5_04_der2;
1393 }
else if (xtype == 5) {
1394 fx = bsp5_05; fx_der = bsp5_05_der; fx_der2 = bsp5_05_der2;
1399 virtual ~global_function_x_bspline_()
1400 { DAL_STORED_OBJECT_DEBUG_DESTROYED(
this,
"Global function x bspline"); }
1405 class global_function_xy_bspline_
1406 :
public global_function_simple,
public context_dependencies {
1407 scalar_type xmin, ymin, xmax, ymax, xscale, yscale;
1408 std::function<scalar_type(scalar_type)>
1409 fx, fy, fx_der, fy_der, fx_der2, fy_der2;
1411 void update_from_context()
const {}
1413 virtual scalar_type val(
const base_node &pt)
const
1415 return fx(xscale*(pt[0]-xmin))
1416 * fy(yscale*(pt[1]-ymin));
1418 virtual void grad(
const base_node &pt, base_small_vector &g)
const
1420 scalar_type dx = xscale*(pt[0]-xmin),
1421 dy = yscale*(pt[1]-ymin);
1423 g[0] = xscale * fx_der(dx) * fy(dy);
1424 g[1] = fx(dx) * yscale * fy_der(dy);
1426 virtual void hess(
const base_node &pt, base_matrix &h)
const
1428 scalar_type dx = xscale*(pt[0]-xmin),
1429 dy = yscale*(pt[1]-ymin);
1430 h.resize(dim_, dim_);
1432 h(0,0) = xscale*xscale * fx_der2(dx) * fy(dy);
1433 h(0,1) = h(1,0) = xscale * fx_der(dx) * yscale * fy_der(dy);
1434 h(1,1) = fx(dx) * yscale*yscale * fy_der2(dy);
1437 virtual bool is_in_support(
const base_node &pt)
const {
1438 scalar_type dx = pt[0]-(xmin+xmax)/2,
1439 dy = pt[1]-(ymin+ymax)/2;
1440 return (gmm::abs(dx)+1e-9 < gmm::abs(xmax-xmin)/2) &&
1441 (gmm::abs(dy)+1e-9 < gmm::abs(ymax-ymin)/2);
1444 virtual void bounding_box(base_node &bmin, base_node &bmax)
const {
1445 GMM_ASSERT1(bmin.size() == dim_ && bmax.size() == dim_,
1446 "Wrong dimensions");
1447 bmin[0] = std::min(xmin,xmax);
1448 bmin[1] = std::min(ymin,ymax);
1449 bmax[0] = std::max(xmin,xmax);
1450 bmax[1] = std::max(ymin,ymax);
1453 global_function_xy_bspline_(
const scalar_type &xmin_,
const scalar_type &xmax_,
1454 const scalar_type &ymin_,
const scalar_type &ymax_,
1457 : global_function_simple(2), xmin(xmin_), ymin(ymin_), xmax(xmax_), ymax(ymax_),
1458 xscale(scalar_type(xtype)/(xmax-xmin)), yscale(scalar_type(ytype)/(ymax-ymin))
1460 GMM_ASSERT1(order >= 3 && order <= 5,
"Wrong input");
1461 GMM_ASSERT1(xtype >= 1 && xtype <= order &&
1462 ytype >= 1 && ytype <= order,
"Wrong input");
1465 fx = bsp3_01; fx_der = bsp3_01_der; fx_der2 = bsp3_01_der2;
1466 }
else if (xtype == 2) {
1467 fx = bsp3_02; fx_der = bsp3_02_der; fx_der2 = bsp3_02_der2;
1468 }
else if (xtype == 3) {
1469 fx = bsp3_03; fx_der = bsp3_03_der; fx_der2 = bsp3_03_der2;
1473 fy = bsp3_01; fy_der = bsp3_01_der; fy_der2 = bsp3_01_der2;
1474 }
else if (ytype == 2) {
1475 fy = bsp3_02; fy_der = bsp3_02_der; fy_der2 = bsp3_02_der2;
1476 }
else if (ytype == 3) {
1477 fy = bsp3_03; fy_der = bsp3_03_der; fy_der2 = bsp3_03_der2;
1479 }
else if (order == 4) {
1481 fx = bsp4_01; fx_der = bsp4_01_der; fx_der2 = bsp4_01_der2;
1482 }
else if (xtype == 2) {
1483 fx = bsp4_02; fx_der = bsp4_02_der; fx_der2 = bsp4_02_der2;
1484 }
else if (xtype == 3) {
1485 fx = bsp4_03; fx_der = bsp4_03_der; fx_der2 = bsp4_03_der2;
1486 }
else if (xtype == 4) {
1487 fx = bsp4_04; fx_der = bsp4_04_der; fx_der2 = bsp4_04_der2;
1491 fy = bsp4_01; fy_der = bsp4_01_der; fy_der2 = bsp4_01_der2;
1492 }
else if (ytype == 2) {
1493 fy = bsp4_02; fy_der = bsp4_02_der; fy_der2 = bsp4_02_der2;
1494 }
else if (ytype == 3) {
1495 fy = bsp4_03; fy_der = bsp4_03_der; fy_der2 = bsp4_03_der2;
1496 }
else if (ytype == 4) {
1497 fy = bsp4_04; fy_der = bsp4_04_der; fy_der2 = bsp4_04_der2;
1500 }
else if (order == 5) {
1502 fx = bsp5_01; fx_der = bsp5_01_der; fx_der2 = bsp5_01_der2;
1503 }
else if (xtype == 2) {
1504 fx = bsp5_02; fx_der = bsp5_02_der; fx_der2 = bsp5_02_der2;
1505 }
else if (xtype == 3) {
1506 fx = bsp5_03; fx_der = bsp5_03_der; fx_der2 = bsp5_03_der2;
1507 }
else if (xtype == 4) {
1508 fx = bsp5_04; fx_der = bsp5_04_der; fx_der2 = bsp5_04_der2;
1509 }
else if (xtype == 5) {
1510 fx = bsp5_05; fx_der = bsp5_05_der; fx_der2 = bsp5_05_der2;
1514 fy = bsp5_01; fy_der = bsp5_01_der; fy_der2 = bsp5_01_der2;
1515 }
else if (ytype == 2) {
1516 fy = bsp5_02; fy_der = bsp5_02_der; fy_der2 = bsp5_02_der2;
1517 }
else if (ytype == 3) {
1518 fy = bsp5_03; fy_der = bsp5_03_der; fy_der2 = bsp5_03_der2;
1519 }
else if (ytype == 4) {
1520 fy = bsp5_04; fy_der = bsp5_04_der; fy_der2 = bsp5_04_der2;
1521 }
else if (ytype == 5) {
1522 fy = bsp5_05; fy_der = bsp5_05_der; fy_der2 = bsp5_05_der2;
1527 virtual ~global_function_xy_bspline_()
1528 { DAL_STORED_OBJECT_DEBUG_DESTROYED(
this,
"Global function xy bspline"); }
1532 class global_function_xyz_bspline_
1533 :
public global_function_simple,
public context_dependencies {
1534 scalar_type xmin, ymin, zmin, xmax, ymax, zmax, xscale, yscale, zscale;
1535 std::function<scalar_type(scalar_type)>
1536 fx, fy, fz, fx_der, fy_der, fz_der, fx_der2, fy_der2, fz_der2;
1538 void update_from_context()
const {}
1540 virtual scalar_type val(
const base_node &pt)
const
1542 return fx(xscale*(pt[0]-xmin))
1543 * fy(yscale*(pt[1]-ymin))
1544 * fz(zscale*(pt[2]-zmin));
1546 virtual void grad(
const base_node &pt, base_small_vector &g)
const
1548 scalar_type dx = xscale*(pt[0]-xmin),
1549 dy = yscale*(pt[1]-ymin),
1550 dz = zscale*(pt[2]-zmin);
1552 g[0] = xscale * fx_der(dx) * fy(dy) * fz(dz);
1553 g[1] = fx(dx) * yscale * fy_der(dy) * fz(dz);
1554 g[2] = fx(dx) * fy(dy) * zscale * fz_der(dz);
1556 virtual void hess(
const base_node &pt, base_matrix &h)
const
1558 scalar_type dx = xscale*(pt[0]-xmin),
1559 dy = yscale*(pt[1]-ymin),
1560 dz = zscale*(pt[2]-zmin);
1561 h.resize(dim_, dim_);
1563 h(0,0) = xscale*xscale * fx_der2(dx) * fy(dy) * fz(dz);
1564 h(1,1) = fx(dx) * yscale*yscale * fy_der2(dy) * fz(dz);
1565 h(2,2) = fx(dx) * fy(dy) * zscale*zscale * fz_der2(dz);
1566 h(0,1) = h(1,0) = xscale * fx_der(dx) * yscale * fy_der(dy) * fz(dz);
1567 h(0,2) = h(2,0) = xscale * fx_der(dx) * fy(dy) * zscale * fz_der(dz);
1568 h(1,2) = h(2,1) = fx(dx) * yscale * fy_der(dy) * zscale * fz_der(dz);
1571 virtual bool is_in_support(
const base_node &pt)
const {
1572 scalar_type dx = pt[0]-(xmin+xmax)/2,
1573 dy = pt[1]-(ymin+ymax)/2,
1574 dz = pt[2]-(zmin+zmax)/2;
1575 return (gmm::abs(dx)+1e-9 < gmm::abs(xmax-xmin)/2) &&
1576 (gmm::abs(dy)+1e-9 < gmm::abs(ymax-ymin)/2) &&
1577 (gmm::abs(dz)+1e-9 < gmm::abs(zmax-zmin)/2);
1580 virtual void bounding_box(base_node &bmin, base_node &bmax)
const {
1581 GMM_ASSERT1(bmin.size() == dim_ && bmax.size() == dim_,
1582 "Wrong dimensions");
1583 bmin[0] = std::min(xmin,xmax);
1584 bmin[1] = std::min(ymin,ymax);
1585 bmin[2] = std::min(zmin,zmax);
1586 bmax[0] = std::max(xmin,xmax);
1587 bmax[1] = std::max(ymin,ymax);
1588 bmax[2] = std::max(zmin,zmax);
1591 global_function_xyz_bspline_(
const scalar_type &xmin_,
const scalar_type &xmax_,
1592 const scalar_type &ymin_,
const scalar_type &ymax_,
1593 const scalar_type &zmin_,
const scalar_type &zmax_,
1598 : global_function_simple(3), xmin(xmin_), ymin(ymin_), zmin(zmin_),
1599 xmax(xmax_), ymax(ymax_), zmax(zmax_),
1600 xscale(scalar_type(xtype)/(xmax-xmin)),
1601 yscale(scalar_type(ytype)/(ymax-ymin)),
1602 zscale(scalar_type(ztype)/(zmax-zmin))
1604 GMM_ASSERT1(order >= 3 && order <= 5,
"Wrong input");
1605 GMM_ASSERT1(xtype >= 1 && xtype <= order &&
1606 ytype >= 1 && ytype <= order &&
1607 ztype >= 1 && ztype <= order,
"Wrong input");
1611 fx = bsp3_01; fx_der = bsp3_01_der; fx_der2 = bsp3_01_der2;
1612 }
else if (xtype == 2) {
1613 fx = bsp3_02; fx_der = bsp3_02_der; fx_der2 = bsp3_02_der2;
1614 }
else if (xtype == 3) {
1615 fx = bsp3_03; fx_der = bsp3_03_der; fx_der2 = bsp3_03_der2;
1619 fy = bsp3_01; fy_der = bsp3_01_der; fy_der2 = bsp3_01_der2;
1620 }
else if (ytype == 2) {
1621 fy = bsp3_02; fy_der = bsp3_02_der; fy_der2 = bsp3_02_der2;
1622 }
else if (ytype == 3) {
1623 fy = bsp3_03; fy_der = bsp3_03_der; fy_der2 = bsp3_03_der2;
1627 fz = bsp3_01; fz_der = bsp3_01_der; fz_der2 = bsp3_01_der2;
1628 }
else if (ztype == 2) {
1629 fz = bsp3_02; fz_der = bsp3_02_der; fz_der2 = bsp3_02_der2;
1630 }
else if (ztype == 3) {
1631 fz = bsp3_03; fz_der = bsp3_03_der; fz_der2 = bsp3_03_der2;
1634 }
else if (order == 4) {
1637 fx = bsp4_01; fx_der = bsp4_01_der; fx_der2 = bsp4_01_der2;
1638 }
else if (xtype == 2) {
1639 fx = bsp4_02; fx_der = bsp4_02_der; fx_der2 = bsp4_02_der2;
1640 }
else if (xtype == 3) {
1641 fx = bsp4_03; fx_der = bsp4_03_der; fx_der2 = bsp4_03_der2;
1642 }
else if (xtype == 4) {
1643 fx = bsp4_04; fx_der = bsp4_04_der; fx_der2 = bsp4_04_der2;
1647 fy = bsp4_01; fy_der = bsp4_01_der; fy_der2 = bsp4_01_der2;
1648 }
else if (ytype == 2) {
1649 fy = bsp4_02; fy_der = bsp4_02_der; fy_der2 = bsp4_02_der2;
1650 }
else if (ytype == 3) {
1651 fy = bsp4_03; fy_der = bsp4_03_der; fy_der2 = bsp4_03_der2;
1652 }
else if (ytype == 4) {
1653 fy = bsp4_04; fy_der = bsp4_04_der; fy_der2 = bsp4_04_der2;
1657 fz = bsp4_01; fz_der = bsp4_01_der; fz_der2 = bsp4_01_der2;
1658 }
else if (ztype == 2) {
1659 fz = bsp4_02; fz_der = bsp4_02_der; fz_der2 = bsp4_02_der2;
1660 }
else if (ztype == 3) {
1661 fz = bsp4_03; fz_der = bsp4_03_der; fz_der2 = bsp4_03_der2;
1662 }
else if (ztype == 4) {
1663 fz = bsp4_04; fz_der = bsp4_04_der; fz_der2 = bsp4_04_der2;
1666 }
else if (order == 5) {
1669 fx = bsp5_01; fx_der = bsp5_01_der; fx_der2 = bsp5_01_der2;
1670 }
else if (xtype == 2) {
1671 fx = bsp5_02; fx_der = bsp5_02_der; fx_der2 = bsp5_02_der2;
1672 }
else if (xtype == 3) {
1673 fx = bsp5_03; fx_der = bsp5_03_der; fx_der2 = bsp5_03_der2;
1674 }
else if (xtype == 4) {
1675 fx = bsp5_04; fx_der = bsp5_04_der; fx_der2 = bsp5_04_der2;
1676 }
else if (xtype == 5) {
1677 fx = bsp5_05; fx_der = bsp5_05_der; fx_der2 = bsp5_05_der2;
1681 fy = bsp5_01; fy_der = bsp5_01_der; fy_der2 = bsp5_01_der2;
1682 }
else if (ytype == 2) {
1683 fy = bsp5_02; fy_der = bsp5_02_der; fy_der2 = bsp5_02_der2;
1684 }
else if (ytype == 3) {
1685 fy = bsp5_03; fy_der = bsp5_03_der; fy_der2 = bsp5_03_der2;
1686 }
else if (ytype == 4) {
1687 fy = bsp5_04; fy_der = bsp5_04_der; fy_der2 = bsp5_04_der2;
1688 }
else if (ytype == 5) {
1689 fy = bsp5_05; fy_der = bsp5_05_der; fy_der2 = bsp5_05_der2;
1693 fz = bsp5_01; fz_der = bsp5_01_der; fz_der2 = bsp5_01_der2;
1694 }
else if (ztype == 2) {
1695 fz = bsp5_02; fz_der = bsp5_02_der; fz_der2 = bsp5_02_der2;
1696 }
else if (ztype == 3) {
1697 fz = bsp5_03; fz_der = bsp5_03_der; fz_der2 = bsp5_03_der2;
1698 }
else if (ztype == 4) {
1699 fz = bsp5_04; fz_der = bsp5_04_der; fz_der2 = bsp5_04_der2;
1700 }
else if (ztype == 5) {
1701 fz = bsp5_05; fz_der = bsp5_05_der; fz_der2 = bsp5_05_der2;
1707 virtual ~global_function_xyz_bspline_()
1708 { DAL_STORED_OBJECT_DEBUG_DESTROYED(
this,
"Global function xyz bspline"); }
1713 global_function_bspline(
const scalar_type xmin,
const scalar_type xmax,
1715 return std::make_shared<global_function_x_bspline_>
1716 (xmin, xmax, order, xtype);
1720 global_function_bspline(
const scalar_type xmin,
const scalar_type xmax,
1721 const scalar_type ymin,
const scalar_type ymax,
1724 return std::make_shared<global_function_xy_bspline_>
1725 (xmin, xmax, ymin, ymax, order, xtype, ytype);
1729 global_function_bspline(
const scalar_type xmin,
const scalar_type xmax,
1730 const scalar_type ymin,
const scalar_type ymax,
1731 const scalar_type zmin,
const scalar_type zmax,
1736 return std::make_shared<global_function_xyz_bspline_>
1737 (xmin, xmax, ymin, ymax, zmin, zmax, order,
1738 xtype, ytype, ztype);
1745 interpolator_on_mesh_fem::interpolator_on_mesh_fem
1746 (
const mesh_fem &mf_,
const std::vector<scalar_type> &U_)
1749 if (mf.is_reduced()) {
1751 gmm::mult(mf.extension_matrix(), U_, U);
1753 base_node bmin, bmax;
1754 scalar_type EPS=1E-13;
1757 for (dal::bv_visitor cv(mf.convex_index()); !cv.finished(); ++cv) {
1758 bounding_box(bmin, bmax, mf.linked_mesh().points_of_convex(cv),
1759 mf.linked_mesh().trans_of_convex(cv));
1760 for (
auto&& val : bmin) val -= EPS;
1761 for (
auto&& val : bmax) val += EPS;
1762 boxtree.add_box(bmin, bmax, cv);
1764 boxtree.build_tree();
1767 bool interpolator_on_mesh_fem::find_a_point(
const base_node &pt,
1771 if (cv_stored !=
size_type(-1) && gic.invert(pt, ptr, gt_invertible)) {
1777 boxtree.find_boxes_at_point(pt, boxlst);
1778 for (
const auto &box : boxlst) {
1780 (mf.linked_mesh().convex(box->id),
1781 mf.linked_mesh().trans_of_convex(box->id));
1782 cv_stored = box->id;
1783 if (gic.invert(pt, ptr, gt_invertible)) {
1791 bool interpolator_on_mesh_fem::eval(
const base_node &pt, base_vector &val,
1792 base_matrix &grad)
const {
1796 dim_type q = mf.get_qdim(), N = mf.linked_mesh().dim();
1797 if (find_a_point(pt, ptref, cv)) {
1798 pfem pf = mf.fem_of_element(cv);
1800 mf.linked_mesh().trans_of_convex(cv);
1802 vectors_to_base_matrix(G, mf.linked_mesh().points_of_convex(cv));
1803 fem_interpolation_context fic(pgt, pf, ptref, G, cv,
short_type(-1));
1809 pf->interpolation(fic, coeff, val, q);
1811 pf->interpolation_grad(fic, coeff, grad, q);
does the inversion of the geometric transformation for a given convex
Definition of global functions to be used as base or enrichment functions in fem.
void mult_add(const L1 &l1, const L2 &l2, L3 &l3)
*/
void reshape(M &v, size_type m, size_type n)
*/
void copy(const L1 &l1, L2 &l2)
*/
void fill(L &l, typename gmm::linalg_traits< L >::value_type x)
*/
void clear(L &l)
clear (fill with zeros) a vector or matrix.
void resize(V &v, size_type n)
*/
void mult(const L1 &l1, const L2 &l2, L3 &l3)
*/
void add(const L1 &l1, L2 &l2)
*/
std::shared_ptr< const getfem::virtual_fem > pfem
type of pointer on a fem description
gmm::uint16_type short_type
used as the common short type integer in the library
size_t size_type
used as the common size type in the library
std::shared_ptr< const bgeot::geometric_trans > pgeometric_trans
pointer type for a geometric transformation
void add_dependency(pstatic_stored_object o1, pstatic_stored_object o2)
Add a dependency, object o1 will depend on object o2.
GEneric Tool for Finite Element Methods.
void slice_vector_on_basic_dof_of_element(const mesh_fem &mf, const VEC1 &vec, size_type cv, VEC2 &coeff, size_type qmult1=size_type(-1), size_type qmult2=size_type(-1))
Given a mesh_fem.