27 Func<T>::Func(
int num_gip,
int num_comps) : num_gip(num_gip), nc(num_comps)
48 throw Hermes::Exceptions::Exception(
"Unable to subtract a function due to a different number of integration points (this: %d, other: %d)", num_gip, func->
num_gip);
50 throw Hermes::Exceptions::Exception(
"Unable to subtract a function due to a different number of components (this: %d, other: %d)", nc, func->
nc);
52 subtract(this->val, func->
val);
53 subtract(this->dx, func->dx);
54 subtract(this->dy, func->
dy);
56 #ifdef H2D_USE_SECOND_DERIVATIVES
57 subtract(this->laplace, func->
laplace);
62 subtract(this->val0, func->val0);
63 subtract(this->val1, func->
val1);
64 subtract(this->dx0, func->dx0);
65 subtract(this->dx1, func->
dx1);
66 subtract(this->dy0, func->dy0);
67 subtract(this->dy1, func->
dy1);
68 subtract(this->curl, func->
curl);
69 subtract(this->div, func->
div);
74 int Func<T>::get_num_gip()
const
82 if(attribute != NULL && other_attribute != NULL)
84 for(
int i = 0; i < num_gip; i++)
85 attribute[i] -= other_attribute[i];
93 throw Hermes::Exceptions::Exception(
"Unable to add a function due to a different number of integration points (this: %d, other: %d)", num_gip, func->
num_gip);
95 throw Hermes::Exceptions::Exception(
"Unable to add a function due to a different number of components (this: %d, other: %d)", nc, func->
nc);
97 add(this->val, func->
val);
98 add(this->dx, func->dx);
99 add(this->dy, func->
dy);
101 #ifdef H2D_USE_SECOND_DERIVATIVES
102 add(this->laplace, func->
laplace);
107 add(this->val0, func->val0);
108 add(this->val1, func->
val1);
109 add(this->dx0, func->dx0);
110 add(this->dx1, func->
dx1);
111 add(this->dy0, func->dy0);
112 add(this->dy1, func->
dy1);
113 add(this->curl, func->
curl);
114 add(this->div, func->
div);
121 if(attribute != NULL && other_attribute != NULL)
123 if(other_attribute == NULL)
124 throw Hermes::Exceptions::Exception(
"Unable to add a function expansion, the desired attribute is NULL in the other function.");
125 for(
int i = 0; i < num_gip; i++)
126 attribute[i] += other_attribute[i];
154 delete [] val; val = NULL;
155 delete [] dx; dx = NULL;
156 delete [] dy; dy = NULL;
158 #ifdef H2D_USE_SECOND_DERIVATIVES
165 delete [] val0;
delete [] val1; val0 = val1 = NULL;
166 delete [] dx0;
delete [] dx1; dx0 = dx1 = NULL;
167 delete [] dy0;
delete [] dy1; dy0 = dy1 = NULL;
168 delete [] curl; curl = NULL;
169 delete [] div; div = NULL;
175 Func<T>(fn->num_gip, fn->nc),
178 reverse_neighbor_side(reverse)
181 throw Hermes::Exceptions::Exception(
"Invalid arguments to DiscontinuousFunc constructor.");
182 if(support_on_neighbor)
190 Func<T>(fn_c->num_gip, fn_c->nc),
193 reverse_neighbor_side(reverse)
196 throw Hermes::Exceptions::NullException(0);
198 throw Hermes::Exceptions::NullException(1);
200 throw Hermes::Exceptions::Exception(
"DiscontinuousFunc must be formed by two Func's with same number of integration points and components.");
235 if(fn_central != NULL && func.
fn_central != NULL)
237 if(fn_neighbor != NULL && func.
fn_neighbor != NULL)
242 void DiscontinuousFunc<T>::free_fn()
244 if(fn_central != NULL)
246 fn_central->free_fn();
250 if(fn_neighbor != NULL)
252 fn_neighbor->free_fn();
259 void DiscontinuousFunc<T>::free_ord()
261 if(fn_central != NULL)
263 fn_central->free_ord();
267 if(fn_neighbor != NULL)
269 fn_neighbor->free_ord();
290 delete [] x;
delete [] y;
291 delete [] tx;
delete [] ty;
292 delete [] nx;
delete [] ny;
297 Geom<T>(), neighb_marker(n_marker), neighb_id(n_id), neighb_diam(n_diam)
313 this->wrapped_geom = geom;
317 void InterfaceGeom<T>::free()
319 wrapped_geom->
free();
324 void InterfaceGeom<T>::free_ord()
332 return neighb_marker;
350 static Hermes::Ord x[] = { Hermes::Ord(1) };
351 static Hermes::Ord y[] = { Hermes::Ord(1) };
353 static Hermes::Ord nx[] = { Hermes::Ord(1) };
354 static Hermes::Ord ny[] = { Hermes::Ord(1) };
356 static Hermes::Ord tx[] = { Hermes::Ord(1) };
357 static Hermes::Ord ty[] = { Hermes::Ord(1) };
359 static Hermes::Ord diam = Hermes::Ord(1);
362 e->nx = nx; e->
ny = ny;
363 e->tx = tx; e->
ty = ty;
378 e->x =
new double[np];
379 e->
y =
new double[np];
382 for (
int i = 0; i < np; i++)
406 e->x =
new double[np];
407 e->
y =
new double[np];
408 e->tx =
new double[np];
409 e->
ty =
new double[np];
410 e->nx =
new double[np];
411 e->
ny =
new double[np];
412 for (
int i = 0; i < np; i++)
416 e->tx[i] = tan[i][0]; e->
ty[i] = tan[i][1];
417 e->nx[i] = tan[i][1]; e->
ny[i] = - tan[i][0];
425 Hermes::Ord *d =
new Hermes::Ord(order);
426 Hermes::Ord *d1 =
new Hermes::Ord(order > 1 ? order - 1 : order);
432 #ifdef H2D_USE_SECOND_DERIVATIVES
435 f->val0 = f->
val1 = d;
436 f->dx0 = f->
dx1 = d1;
437 f->dy0 = f->
dy1 = d1;
449 #ifdef H2D_USE_SECOND_DERIVATIVES
450 if(space_type == HERMES_H1_SPACE || space_type == HERMES_L2_SPACE)
463 if(space_type == HERMES_H1_SPACE || space_type == HERMES_L2_SPACE)
465 u->
val =
new double[np];
466 u->dx =
new double[np];
467 u->
dy =
new double[np];
469 #ifdef H2D_USE_SECOND_DERIVATIVES
481 #ifdef H2D_USE_SECOND_DERIVATIVES
490 m =
new double2x2[np];
491 double2x2 const_inv_ref_map;
498 for(
int i = 0; i < np; i++)
500 m[i][0][0] = const_inv_ref_map[0][0];
501 m[i][0][1] = const_inv_ref_map[0][1];
502 m[i][1][0] = const_inv_ref_map[1][0];
503 m[i][1][1] = const_inv_ref_map[1][1];
509 #ifdef H2D_USE_SECOND_DERIVATIVES
511 mm = rm->get_second_ref_map(order);
512 for (
int i = 0; i < np; i++, m++, mm++)
515 u->dx[i] = (dx[i] * (*m)[0][0] + dy[i] * (*m)[0][1]);
516 u->
dy[i] = (dx[i] * (*m)[1][0] + dy[i] * (*m)[1][1]);
518 double axx = (Hermes::sqr((*m)[0][0]) + Hermes::sqr((*m)[1][0]));
519 double ayy = (Hermes::sqr((*m)[0][1]) + Hermes::sqr((*m)[1][1]));
520 double axy = 2.0 * ((*m)[0][0]*(*m)[0][1] + (*m)[1][0]*(*m)[1][1]);
521 double ax = (*mm)[0][0] + (*mm)[2][0];
522 double ay = (*mm)[0][1] + (*mm)[2][1];
523 u->
laplace[i] = ( dx[i] * ax + dy[i] * ay + dxx[i] * axx + dxy[i] * axy + dyy[i] * ayy );
526 for (
int i = 0; i < np; i++, m++)
529 u->dx[i] = (dx[i] * (*m)[0][0] + dy[i] * (*m)[0][1]);
530 u->
dy[i] = (dx[i] * (*m)[1][0] + dy[i] * (*m)[1][1]);
539 else if(space_type == HERMES_HCURL_SPACE)
541 u->val0 =
new double[np];
542 u->
val1 =
new double[np];
543 u->
curl =
new double[np];
552 m =
new double2x2[np];
553 double2x2 const_inv_ref_map;
560 for(
int i = 0; i < np; i++)
562 m[i][0][0] = const_inv_ref_map[0][0];
563 m[i][0][1] = const_inv_ref_map[0][1];
564 m[i][1][0] = const_inv_ref_map[1][0];
565 m[i][1][1] = const_inv_ref_map[1][1];
570 for (
int i = 0; i < np; i++, m++)
572 u->val0[i] = (fn0[i] * (*m)[0][0] + fn1[i] * (*m)[0][1]);
573 u->
val1[i] = (fn0[i] * (*m)[1][0] + fn1[i] * (*m)[1][1]);
574 u->
curl[i] = ((*m)[0][0] * (*m)[1][1] - (*m)[1][0] * (*m)[0][1]) * (dx1[i] - dy0[i]);
582 else if(space_type == HERMES_HDIV_SPACE)
584 u->val0 =
new double[np];
585 u->
val1 =
new double[np];
594 m =
new double2x2[np];
595 double2x2 const_inv_ref_map;
602 for(
int i = 0; i < np; i++)
604 m[i][0][0] = const_inv_ref_map[0][0];
605 m[i][0][1] = const_inv_ref_map[0][1];
606 m[i][1][0] = const_inv_ref_map[1][0];
607 m[i][1][1] = const_inv_ref_map[1][1];
612 for (
int i = 0; i < np; i++, m++)
614 u->val0[i] = ( fn0[i] * (*m)[1][1] - fn1[i] * (*m)[1][0]);
615 u->
val1[i] = (- fn0[i] * (*m)[0][1] + fn1[i] * (*m)[0][0]);
616 u->
div[i] = ((*m)[0][0] * (*m)[1][1] - (*m)[1][0] * (*m)[0][1]) * (dx0[i] + dy1[i]);
623 throw Hermes::Exceptions::Exception(
"Wrong space type - space has to be either H1, Hcurl, Hdiv or L2");
628 template<
typename Scalar>
632 if(fu == NULL)
throw Hermes::Exceptions::Exception(
"NULL MeshFunction in Func<Scalar>*::init_fn().");
633 if(fu->get_mesh() == NULL)
throw Hermes::Exceptions::Exception(
"Uninitialized MeshFunction used.");
644 u->
val =
new Scalar[np];
645 u->dx =
new Scalar[np];
646 u->
dy =
new Scalar[np];
653 u->val0 =
new Scalar[np];
654 u->
val1 =
new Scalar[np];
655 u->
curl =
new Scalar[np];
656 u->
div =
new Scalar[np];
663 for (
int i = 0; i < np; i++) u->
curl[i] = dx1[i] - dy0[i];
667 for (
int i = 0; i < np; i++) u->
div[i] = dx0[i] + dy1[i];
672 template<
typename Scalar>
676 if(fu == NULL)
throw Hermes::Exceptions::Exception(
"NULL MeshFunction in Func<Scalar>*::init_fn().");
677 if(fu->get_mesh() == NULL)
throw Hermes::Exceptions::Exception(
"Uninitialized MeshFunction used.");
679 SpaceType space_type = fu->get_space_type();
680 SolutionType sln_type = fu->
get_type();
684 #ifdef H2D_USE_SECOND_DERIVATIVES
685 if(space_type == HERMES_H1_SPACE && sln_type != HERMES_EXACT)
698 u->
val =
new Scalar[np];
699 u->dx =
new Scalar[np];
700 u->
dy =
new Scalar[np];
702 #ifdef H2D_USE_SECOND_DERIVATIVES
703 if(space_type == HERMES_H1_SPACE && sln_type != HERMES_EXACT)
711 #ifdef H2D_USE_SECOND_DERIVATIVES
712 if(space_type == HERMES_H1_SPACE && sln_type != HERMES_EXACT)
716 for (
int i = 0; i < np; i++)
717 u->
laplace[i] = dxx[i] + dyy[i];
723 u->val0 =
new Scalar[np];
724 u->
val1 =
new Scalar[np];
725 u->
curl =
new Scalar[np];
726 u->
div =
new Scalar[np];
733 for (
int i = 0; i < np; i++)
734 u->
curl[i] = dx1[i] - dy0[i];
738 for (
int i = 0; i < np; i++)
739 u->
div[i] = dx0[i] + dy1[i];
744 template Func<double>*
init_fn(MeshFunction<double>*fu,
const int order);
745 template Func<std::complex<double> >*
init_fn(MeshFunction<std::complex<double> >*fu,
const int order);
747 template HERMES_API Func<double>*
init_fn(Solution<double>*fu,
const int order);
748 template HERMES_API Func<std::complex<double> >*
init_fn(Solution<std::complex<double> >*fu,
const int order);
750 template class HERMES_API Func<Hermes::Ord>;
751 template class HERMES_API Func<double>;
752 template class HERMES_API Func<std::complex<double> >;
753 template class HERMES_API DiscontinuousFunc<Hermes::Ord>;
754 template class HERMES_API DiscontinuousFunc<double>;
755 template class HERMES_API DiscontinuousFunc<std::complex<double> >;
756 template class HERMES_API Geom<Hermes::Ord>;
757 template class HERMES_API Geom<double>;
758 template class HERMES_API InterfaceGeom<Hermes::Ord>;
759 template class HERMES_API InterfaceGeom<double>;