32 #ifndef CORE_BASIS_LOCATE_H
33 #define CORE_BASIS_LOCATE_H 1
49 const T a=p[0], b=p[1], c=p[2];
50 const T d=p[3], e=p[4], f=p[5];
51 const T g=p[6], h=p[7], i=p[8];
53 const T detp=a*e*i-c*e*g+b*f*g+c*d*h-a*f*h-b*d*i;
54 const T detinvp=(detp ? 1.0/detp : 0);
56 q[0]=(e*i-f*h)*detinvp;
57 q[1]=(c*h-b*i)*detinvp;
58 q[2]=(b*f-c*e)*detinvp;
59 q[3]=(f*g-d*i)*detinvp;
60 q[4]=(a*i-c*g)*detinvp;
61 q[5]=(c*d-a*f)*detinvp;
62 q[6]=(d*h-e*g)*detinvp;
63 q[7]=(b*g-a*h)*detinvp;
64 q[8]=(a*e-b*d)*detinvp;
71 template <
class Po
intVector>
74 const double a=p[0].x(), b=p[0].y(), c=p[0].z();
75 const double d=p[1].x(), e=p[1].y(), f=p[1].z();
76 const double g=p[2].x(), h=p[2].y(), i=p[2].z();
78 const double detp=a*e*i-c*e*g+b*f*g+c*d*h-a*f*h-b*d*i;
79 const double detinvp=(detp ? 1.0/detp : 0);
81 q[0]=(e*i-f*h)*detinvp;
82 q[1]=(c*h-b*i)*detinvp;
83 q[2]=(b*f-c*e)*detinvp;
84 q[3]=(f*g-d*i)*detinvp;
85 q[4]=(a*i-c*g)*detinvp;
86 q[5]=(c*d-a*f)*detinvp;
87 q[6]=(d*h-e*g)*detinvp;
88 q[7]=(b*g-a*h)*detinvp;
89 q[8]=(a*e-b*d)*detinvp;
97 const T a=p[0], b=p[1], c=p[2];
98 const T d=p[3], e=p[4], f=p[5];
99 const T g=p[6], h=p[7], i=p[8];
101 const T detp=a*e*i-c*e*g+b*f*g+c*d*h-a*f*h-b*d*i;
108 const T a=p[0], b=p[1], c=p[2];
109 const T d=p[3], e=p[4], f=p[5];
110 const T g=p[6], h=p[7], i=p[8];
112 const T detp=a*e*i-c*e*g+b*f*g+c*d*h-a*f*h-b*d*i;
113 const T s = sqrt((a*a+b*b+c*c)*(d*d+e*e+f*f)*(g*g+h*h+i*i));
119 template <
class VectorOfPo
ints>
122 const double a=p[0].x(), b=p[0].y(), c=p[0].z();
123 const double d=p[1].x(), e=p[1].y(), f=p[1].z();
124 const double g=p[2].x(), h=p[2].y(), i=p[2].z();
126 const double detp=a*e*i-c*e*g+b*f*g+c*d*h-a*f*h-b*d*i;
131 template <
class VectorOfPo
ints>
134 const double a=p[0].x(), b=p[0].y(), c=p[0].z();
135 const double d=p[1].x(), e=p[1].y(), f=p[1].z();
136 const double g=p[2].x(), h=p[2].y(), i=p[2].z();
138 const double detp=a*e*i-c*e*g+b*f*g+c*d*h-a*f*h-b*d*i;
139 const double s = std::sqrt((a*a+b*b+c*c)*(d*d+e*e+f*f)*(g*g+h*h+i*i));
147 template <
class VECTOR,
class T>
154 template<
class VECTOR>
172 template <
class VECTOR>
175 return(
d_volume_type(derivs,static_cast<typename VECTOR::value_type*>(0)));
178 template <
class ElemBasis,
class ElemData>
185 for(
int i=0; i<ElemBasis::GaussianNum; i++)
187 coords[0]=ElemBasis::GaussianPoints[i][0];
188 coords[1]=ElemBasis::GaussianPoints[i][1];
189 coords[2]=ElemBasis::GaussianPoints[i][2];
192 pEB->derivate(coords, cd, derivs);
193 volume+=ElemBasis::GaussianWeights[i]*
d_volume(derivs);
195 return volume*pEB->volume();
199 template <
class VECTOR1,
class VECTOR2>
202 const unsigned int dvsize = derivs.size();
208 for(
unsigned int i = 0; i<dvsize; i++) {
210 Jdv1+=dv1[i]*Geometry::Vector(derivs[i].x(), derivs[i].y(), derivs[i].z());
217 template<
class VECTOR1,
class VECTOR2>
218 inline double d_area(
const VECTOR1& derivs,
const VECTOR2& dv0,
const VECTOR2& dv1)
220 return(
d_area_type(derivs,dv0,dv1,static_cast<typename VECTOR1::value_type*>(0)));
225 template <
class NumApprox,
class ElemBasis,
class ElemData>
226 double get_area2(
const ElemBasis *pEB,
const unsigned face,
229 const double *v0 = pEB->unit_vertices[pEB->unit_faces[face][0]];
230 const double *v1 = pEB->unit_vertices[pEB->unit_faces[face][1]];
231 const double *v2 = pEB->unit_vertices[pEB->unit_faces[face][2]];
243 for(
int i=0; i<NumApprox::GaussianNum; i++) {
244 coords[0]=v0[0]+NumApprox::GaussianPoints[i][0]*d0[0]+NumApprox::GaussianPoints[i][1]*d1[0];
245 coords[1]=v0[1]+NumApprox::GaussianPoints[i][0]*d0[1]+NumApprox::GaussianPoints[i][1]*d1[1];
248 pEB->derivate(coords, cd, derivs);
249 area+=NumApprox::GaussianWeights[i]*
d_area(derivs, d0, d1);
251 return (area*pEB->area(face));
256 template <
class NumApprox,
class ElemBasis,
class ElemData>
257 double get_area3(
const ElemBasis *pEB,
const unsigned face,
260 const double *v0 = pEB->unit_vertices[pEB->unit_faces[face][0]];
261 const double *v1 = pEB->unit_vertices[pEB->unit_faces[face][1]];
262 const double *v2 = pEB->unit_vertices[pEB->unit_faces[face][2]];
275 for(
int i=0; i<NumApprox::GaussianNum; i++) {
276 coords[0]=v0[0]+NumApprox::GaussianPoints[i][0]*d0[0]+NumApprox::GaussianPoints[i][1]*d1[0];
277 coords[1]=v0[1]+NumApprox::GaussianPoints[i][0]*d0[1]+NumApprox::GaussianPoints[i][1]*d1[1];
278 coords[2]=v0[2]+NumApprox::GaussianPoints[i][0]*d0[2]+NumApprox::GaussianPoints[i][1]*d1[2];
281 pEB->derivate(coords, cd, derivs);
283 area+=NumApprox::GaussianWeights[i]*
d_area(derivs, d0, d1);
285 return (area*pEB->area(face));
289 template <
class VECTOR1,
class VECTOR2>
292 const unsigned int dvsize = dv.size();
297 Jdv[0] = Jdv[1] = Jdv[2] = 0.;
298 for(
unsigned int i = 0; i<dvsize; i++) {
299 Jdv[0]+=dv[i]*derivs[i].x();
300 Jdv[1]+=dv[i]*derivs[i].y();
301 Jdv[2]+=dv[i]*derivs[i].z();
304 return sqrt(Jdv[0]*Jdv[0]+Jdv[1]*Jdv[1]+Jdv[2]*Jdv[2]);
308 template <
class VECTOR1,
class VECTOR2>
311 return(d_arc_length_type(derivs,dv,static_cast<typename VECTOR1::value_type*>(0)));
315 template <
class NumApprox,
class ElemBasis,
class ElemData>
319 const double *v0 = pEB->unit_vertices[pEB->unit_edges[edge][0]];
320 const double *v1 = pEB->unit_vertices[pEB->unit_edges[edge][1]];
323 double arc_length=0.;
326 for(
int i=0; i<NumApprox::GaussianNum; i++) {
327 coords[0]=v0[0]+NumApprox::GaussianPoints[i][0]*dv[0];
329 pEB->derivate(coords, cd, derivs);
331 arc_length+=NumApprox::GaussianWeights[i]*
d_arc_length(derivs, dv);
337 template <
class NumApprox,
class ElemBasis,
class ElemData>
341 const double *v0 = pEB->unit_vertices[pEB->unit_edges[edge][0]];
342 const double *v1 = pEB->unit_vertices[pEB->unit_edges[edge][1]];
346 double arc_length=0.;
349 for(
int i=0; i<NumApprox::GaussianNum; i++) {
350 coords[0]=v0[0]+NumApprox::GaussianPoints[i][0]*dv[0];
351 coords[1]=v0[1]+NumApprox::GaussianPoints[i][0]*dv[1];
353 pEB->derivate(coords, cd, derivs);
354 arc_length+=NumApprox::GaussianWeights[i]*
d_arc_length(derivs, dv);
360 template <
class NumApprox,
class ElemBasis,
class ElemData>
364 const double *v0 = pEB->unit_vertices[pEB->unit_edges[edge][0]];
365 const double *v1 = pEB->unit_vertices[pEB->unit_edges[edge][1]];
370 double arc_length=0.;
373 for(
int i=0; i<NumApprox::GaussianNum; i++) {
374 coords[0]=v0[0]+NumApprox::GaussianPoints[i][0]*dv[0];
375 coords[1]=v0[1]+NumApprox::GaussianPoints[i][0]*dv[1];
376 coords[2]=v0[2]+NumApprox::GaussianPoints[i][0]*dv[2];
378 pEB->derivate(coords, cd, derivs);
379 arc_length+=NumApprox::GaussianWeights[i]*
d_arc_length(derivs, dv);
389 return interp - value;
395 return (interp - value).point();
399 template <
class VECTOR1,
class VECTOR2,
class T>
401 const T& y,
const VECTOR2& yd)
414 template <
class VECTOR1,
class VECTOR2>
420 const double dx = ((yd0.
x() ? y.
x()/yd0.
x() : 0)+(yd0.
y() ? y.
y()/yd0.
y() : 0)+(yd0.
z() ? y.
z()/yd0.
z() : 0))/3.0;
427 template <
class VECTOR1,
class VECTOR2,
class T>
429 const T& y,
const VECTOR2& yd)
446 return sqrt(dx*dx+dy*dy);
449 template <
class VECTOR1,
class VECTOR2>
453 const double J00=yd[0].x();
454 const double J10=yd[0].y();
455 const double J20=yd[0].z();
456 const double J01=yd[1].x();
457 const double J11=yd[1].y();
458 const double J21=yd[1].z();
459 const double detJ=-J10*J01+J10*J21-J00*J21-J11*J20+J11*J00+J01*J20;
460 const double F1=y.
x();
461 const double F2=y.
y();
462 const double F3=y.
z();
465 double dx=(F2*J01-F2*J21+J21*F1-J11*F1+F3*J11-J01*F3)/detJ;
466 double dy=-(-J20*F2+J20*F1+J00*F2+F3*J10-F3*J00-F1*J10)/detJ;
470 return sqrt(dx*dx+dy*dy);
477 template <
class VECTOR1,
class VECTOR2,
class T>
479 const T& y,
const VECTOR2& yd)
503 return sqrt(dx*dx+dy*dy+dz*dz);
507 template <
class VECTOR1,
class VECTOR2>
511 double J[9], JInv[9];
525 const double dx= JInv[0]*y.
x()+JInv[1]*y.
y()+JInv[2]*y.
z();
526 const double dy= JInv[3]*y.
x()+JInv[4]*y.
y()+JInv[5]*y.
z();
527 const double dz= JInv[6]*y.
x()+JInv[7]*y.
y()+JInv[8]*y.
z();
533 return sqrt(dx*dx+dy*dy+dz*dz);
546 template <
class ElemBasis>
549 typedef typename ElemBasis::value_type
T;
558 template <
class ElemData,
class VECTOR>
560 const T& value,
const ElemData &cd)
const
563 for (
int steps=0; steps<
maxsteps; steps++)
566 pEB->derivate(x, cd, yd);
575 template<
class ElemBasis>
577 template<
class ElemBasis>
579 template<
class ElemBasis>
584 template <
class ElemBasis>
587 typedef typename ElemBasis::value_type
T;
596 template <
class ElemData,
class VECTOR>
598 const T& value,
const ElemData &cd)
const
601 for (
int steps=0; steps<
maxsteps; steps++)
604 pEB->derivate(x, cd, yd);
613 template<
class ElemBasis>
615 template<
class ElemBasis>
618 template<
class ElemBasis>
624 template <
class ElemBasis>
628 typedef typename ElemBasis::value_type
T;
637 template <
class ElemData,
class VECTOR>
639 const T& value,
const ElemData &cd)
const
643 for (
int steps=0; steps<
maxsteps; steps++)
645 T y =
difference(pElem->interpolate(x, cd), value);
646 pElem->derivate(x, cd, yd);
655 template<
class ElemBasis>
657 template<
class ElemBasis>
659 template<
class ElemBasis>
668 double &cur_d,
double dist)
670 double dv = interp - val;
676 double &cur_d,
double dist)
683 template <
class VECTOR,
class T>
686 typename VECTOR::const_iterator iter = val.begin();
687 while(iter != val.end())
690 if (fabs(v)>epsilon)
return false;
695 template <
class VECTOR>
698 typename VECTOR::const_iterator iter = val.begin();
699 while(iter != val.end())
702 if (fabs(v.
x())>epsilon || fabs(v.
y())>epsilon || fabs(v.
z())>epsilon)
708 template <
class VECTOR>
709 inline double check_zero(
const VECTOR& derivs,
double epsilon = 1e-7)
711 return(
check_zero_type(derivs,static_cast<typename VECTOR::value_type*>(0),epsilon));
virtual ~Dim2Locate()
Definition: Locate.h:593
Interface to statically allocated std::vector class.
double getnextx1(VECTOR1 &x, const T &y, const VECTOR2 &yd)
Definition: Locate.h:400
double d_area(const VECTOR1 &derivs, const VECTOR2 &dv0, const VECTOR2 &dv1)
General template for any type of combination of containers.
Definition: Locate.h:218
static const int maxsteps
maximal steps for Newton search
Definition: Locate.h:631
double check_zero(const VECTOR &derivs, double epsilon=1e-7)
Definition: Locate.h:709
static const int maxsteps
maximal steps for Newton search
Definition: Locate.h:590
double get_arc1d_length(const ElemBasis *pEB, const unsigned edge, const ElemData &cd)
Definition: Locate.h:316
double get_area2(const ElemBasis *pEB, const unsigned face, const ElemData &cd)
Definition: Locate.h:226
double InverseMatrix3P(const PointVector &p, double *q)
Inline templated inverse matrix.
Definition: Locate.h:72
void y(const double)
Definition: Point.h:135
double d_arc_length(const VECTOR1 &derivs, const VECTOR2 &dv, Geometry::Point *type)
arc length calculation on points
Definition: Locate.h:290
bool check_zero_type(const VECTOR &val, T *, double epsilon)
Definition: Locate.h:684
double getnextx2(VECTOR1 &x, const T &y, const VECTOR2 &yd)
Definition: Locate.h:428
static const double thresholdDist
Thresholds for coordinates checks.
Definition: Locate.h:550
T difference(const T &interp, const T &value)
Definition: Locate.h:387
ElemBasis::value_type T
Definition: Locate.h:549
static const double thresholdDist
Thresholds for coordinates checks.
Definition: Locate.h:629
ElemBasis::value_type T
Definition: Locate.h:587
Dim2Locate()
Definition: Locate.h:592
double DetMatrix3P(const VectorOfPoints &p)
Inline templated determinant of matrix.
Definition: Locate.h:120
void z(const double)
Definition: Point.h:145
virtual ~Dim3Locate()
Definition: Locate.h:555
static const int maxsteps
maximal steps for Newton search
Definition: Locate.h:552
T DetMatrix3x3(const T *p)
Definition: Locate.h:95
double d_volume(const VECTOR &derivs)
calculate volume
Definition: Locate.h:173
void x(const double)
Definition: Point.h:125
virtual ~Dim1Locate()
Definition: Locate.h:634
double get_area3(const ElemBasis *pEB, const unsigned face, const ElemData &cd)
Definition: Locate.h:257
Vector Cross(const Vector &v1, const Vector &v2)
Definition: Vector.h:378
static const double thresholdDist
Thresholds for coordinates checks.
Definition: Locate.h:588
double ScaledDetMatrix3P(const VectorOfPoints &p)
Inline templated determinant of matrix.
Definition: Locate.h:132
double d_volume_type(const VECTOR &, T *)
default case for volume calculation - currently not needed
Definition: Locate.h:148
double get_arc2d_length(const ElemBasis *pEB, const unsigned edge, const ElemData &cd)
Definition: Locate.h:338
v
Definition: readAllFields.py:42
#define ENSURE_DIMENSIONS_MATCH(var1, var2, message)
Definition: Exception.h:93
Dim1Locate()
Definition: Locate.h:633
bool compare_distance(const T &interp, const T &val, double &cur_d, double dist)
Definition: Locate.h:667
double length() const
Definition: Vector.h:365
bool get_iterative(const ElemBasis *pElem, VECTOR &x, const T &value, const ElemData &cd) const
find value in interpolation for given value
Definition: Locate.h:638
T ScaledDetMatrix3x3(const T *p)
Definition: Locate.h:106
static const double thresholdDist1
1+thresholdDist
Definition: Locate.h:551
double getnextx3(VECTOR1 &x, const T &y, const VECTOR2 &yd)
Definition: Locate.h:478
static const double thresholdDist1
1+thresholdDist
Definition: Locate.h:589
bool get_iterative(const ElemBasis *pEB, VECTOR &x, const T &value, const ElemData &cd) const
find value in interpolation for given value
Definition: Locate.h:597
T InverseMatrix3x3(const T *p, T *q)
Definition: Locate.h:47
bool get_iterative(const ElemBasis *pEB, VECTOR &x, const T &value, const ElemData &cd) const
find value in interpolation for given value
Definition: Locate.h:559
static const double thresholdDist1
1+thresholdDist
Definition: Locate.h:630
double get_volume3(const ElemBasis *pEB, const ElemData &cd)
Definition: Locate.h:179
double get_arc3d_length(const ElemBasis *pEB, const unsigned edge, const ElemData &cd)
Definition: Locate.h:361
Dim3Locate()
Definition: Locate.h:554
double d_area_type(const VECTOR1 &derivs, const VECTOR2 &dv0, const VECTOR2 &dv1, Geometry::Point *type)
area calculation on points
Definition: Locate.h:200
ElemBasis::value_type T
Definition: Locate.h:628