proteus  1.8.1
C/C++/Fortran libraries
equivalent_polynomials_utils.h
Go to the documentation of this file.
1 #ifndef EQUIVALENT_POYNOMIALS_UTILS
2 #define EQUIVALENT_POYNOMIALS_UTILS
4 {
5  template<int nSpace>
6  inline void _calculate_normal(double* phys_nodes_cut, double* level_set_normal);
7 
8  template<>
9  inline void _calculate_normal<1>(double* phys_nodes_cut, double* level_set_normal)
10  {
11  const unsigned int nSpace(1);
12  level_set_normal[0] = 1.0;
13  }
14 
15  template<>
16  inline void _calculate_normal<2>(double* phys_nodes_cut, double* level_set_normal)
17  {
18  const unsigned int nSpace(2);
19  double level_set_tangent[2];
20  for(unsigned int I=0; I < nSpace; I++)
21  {
22  level_set_tangent[I] = phys_nodes_cut[3+I] - phys_nodes_cut[I];//nodes always 3D
23  }
24  level_set_normal[0] = level_set_tangent[1];
25  level_set_normal[1] = - level_set_tangent[0];
26  double norm = std::sqrt(level_set_normal[0]*level_set_normal[0] +
27  level_set_normal[1]*level_set_normal[1]);
28  if (norm > 0.0)
29  for(unsigned int I=0; I < nSpace; I++)
30  level_set_normal[I] /= norm;
31  else
32  {
33  for(unsigned int I=0; I < nSpace; I++)
34  level_set_normal[I] =0.0;
35  level_set_normal[1] = 1.0;
36  }
37  }
38 
39  template<>
40  inline void _calculate_normal<3>(double* phys_nodes_cut, double* level_set_normal)
41  {
42  const unsigned int nSpace(3);
43  double level_set_tangent_a[3], level_set_tangent_b[3];
44  for(unsigned int I=0; I < nSpace; I++)
45  {
46  level_set_tangent_a[I] = phys_nodes_cut[3+I] - phys_nodes_cut[I];
47  level_set_tangent_b[I] = phys_nodes_cut[6+I] - phys_nodes_cut[I];
48  }
49  level_set_normal[0] = level_set_tangent_a[1]*level_set_tangent_b[2]
50  - level_set_tangent_a[2]*level_set_tangent_b[1];
51  level_set_normal[1] = - level_set_tangent_a[0]*level_set_tangent_b[2]
52  + level_set_tangent_a[2]*level_set_tangent_b[0];
53  level_set_normal[2] = level_set_tangent_a[0]*level_set_tangent_b[1]
54  - level_set_tangent_a[1]*level_set_tangent_b[0];
55  double norm = std::sqrt(level_set_normal[0]*level_set_normal[0] +
56  level_set_normal[1]*level_set_normal[1] +
57  level_set_normal[2]*level_set_normal[2]);
58  if (norm > 0.0)
59  for(unsigned int I=0; I < nSpace; I++)
60  level_set_normal[I] /= norm;
61  else
62  {
63  for(unsigned int I=0; I < nSpace; I++)
64  level_set_normal[I] =0.0;
65  level_set_normal[2] =1.0;
66  }
67  assert(std::fabs(1.0-level_set_normal[0]*level_set_normal[0] - level_set_normal[1]*level_set_normal[1] - level_set_normal[2]*level_set_normal[2]) < 1.0e-8);
68  }
69 
70  inline void _calculate_normal_quad(double* phys_nodes_cut_quad_01,
71  double* phys_nodes_cut_quad_02,
72  double* phys_nodes_cut_quad_31,
73  double* phys_nodes_cut_quad_32,
74  double* level_set_normal)
75  {
76  const unsigned int nSpace(3);
77  double level_set_tangent_a[3], level_set_tangent_b[3], level_set_tangent_c[3], level_set_normal_2[3];
78  for(unsigned int I=0; I < nSpace; I++)
79  {
80  level_set_tangent_a[I] = phys_nodes_cut_quad_02[I] - phys_nodes_cut_quad_01[I];
81  level_set_tangent_b[I] = phys_nodes_cut_quad_32[I] - phys_nodes_cut_quad_01[I];
82  level_set_tangent_c[I] = phys_nodes_cut_quad_31[I] - phys_nodes_cut_quad_01[I];
83  }
84  level_set_normal[0] = level_set_tangent_a[1]*level_set_tangent_b[2] - level_set_tangent_a[2]*level_set_tangent_b[1];
85  level_set_normal[1] = - level_set_tangent_a[0]*level_set_tangent_b[2] + level_set_tangent_a[2]*level_set_tangent_b[0];
86  level_set_normal[2] = level_set_tangent_a[0]*level_set_tangent_b[1] - level_set_tangent_a[1]*level_set_tangent_b[0];
87  double norm = std::sqrt(level_set_normal[0]*level_set_normal[0] +
88  level_set_normal[1]*level_set_normal[1] +
89  level_set_normal[2]*level_set_normal[2]);
90  if (norm > 0.0)
91  {
92  for(unsigned int I=0; I < nSpace; I++)
93  level_set_normal[I] = level_set_normal[I] / norm;
94  }
95  else
96  {
97  for(unsigned int I=0; I < nSpace; I++)
98  level_set_normal[I] =0.0;
99  level_set_normal[2] = 1.0;
100  }
101  assert(std::fabs(1.0-level_set_normal[0]*level_set_normal[0] - level_set_normal[1]*level_set_normal[1] - level_set_normal[2]*level_set_normal[2]) < 1.0e-8);
102  }
103 
104  template<int nP>
105  inline void _calculate_polynomial_1D(double* xi, double* C_H, double* C_ImH, double* C_D, double& _H, double& _ImH, double& _D)
106  {
107  _H = 0.0;
108  _ImH = 0.0;
109  _D = 0.0;
110  unsigned int iDOF = 0;
111  register double x_pow_i=1.0;
112  for(unsigned int i=0; i < nP+1; i++, iDOF++)
113  {
114  register double psi=x_pow_i;
115  _H += C_H[iDOF]*psi;
116  _ImH += C_ImH[iDOF]*psi;
117  _D += C_D[iDOF]*psi;
118  x_pow_i *= xi[0];
119  }
120  }
121 
122  template<int nP>
123  inline void _calculate_polynomial_2D(double* xi, double* C_H, double* C_ImH, double* C_D, double& _H, double& _ImH, double& _D)
124  {
125  _H = 0.0;
126  _ImH = 0.0;
127  _D = 0.0;
128  unsigned int iDOF = 0;
129  register double x_pow_i=1.0;
130  for(unsigned int i=0; i < nP+1; i++)
131  {
132  register double y_pow_j=1.0;
133  for(unsigned int j=0; j < nP+1-i; j++, iDOF++)
134  {
135  register double psi=x_pow_i*y_pow_j;
136  _H += C_H[iDOF]*psi;
137  _ImH += C_ImH[iDOF]*psi;
138  _D += C_D[iDOF]*psi;
139  y_pow_j *= xi[1];
140  }
141  x_pow_i *= xi[0];
142  }
143  }
144 
145  template<int nP>
146  inline void _calculate_polynomial_3D(double* xi, double* C_H, double* C_ImH, double* C_D, double& _H, double& _ImH, double& _D)
147  {
148  _H = 0.0;
149  _ImH = 0.0;
150  _D = 0.0;
151  unsigned int iDOF = 0;
152  register double x_pow_i=1.0;
153  for(unsigned int i=0; i < nP+1; i++)
154  {
155  register double y_pow_j=1.0;
156  for(unsigned int j=0; j < nP+1-i; j++)
157  {
158  register double x_pow_i_y_pow_j=x_pow_i*y_pow_j, z_pow_k=1.0;
159  for(unsigned int k=0; k < nP+1-i-j; k++, iDOF++)
160  {
161  register double psi=x_pow_i_y_pow_j*z_pow_k;
162  _H += C_H[iDOF]*psi;
163  _ImH += C_ImH[iDOF]*psi;
164  _D += C_D[iDOF]*psi;
165  z_pow_k *= xi[2];
166  }
167  y_pow_j *= xi[1];
168  }
169  x_pow_i *= xi[0];
170  }
171  }
172 
173  const int XX(0),XY(1),XZ(2),YX(3),YY(4),YZ(5),ZX(6),ZY(7),ZZ(8);
174 
175  template<int nSpace>
176  inline double det(const double* A);
177 
178  template<>
179  inline double det<1>(const double* A)
180  {
181  return A[0];
182  }
183 
184  template<>
185  inline double det<2>(const double* A)
186  {
187  return A[0]*A[3] - A[1]*A[2];
188  }
189 
190  template<>
191  inline double det<3>(const double* A)
192  {
193  return A[XX]*(A[YY]*A[ZZ] - A[YZ]*A[ZY]) -
194  A[XY]*(A[YX]*A[ZZ] - A[YZ]*A[ZX]) +
195  A[XZ]*(A[YX]*A[ZY] - A[YY]*A[ZX]);
196  }
197 
198  template<int nSpace>
199  inline void inv(const double* A, double* Ainv);
200 
201  template<>
202  inline void inv<1>(const double* A, double* Ainv)
203  {
204  Ainv[0] = 1.0/A[0];
205  }
206 
207  template<>
208  inline void inv<2>(const double* A, double* Ainv)
209  {
210  double oneOverDet = 1.0/det<2>(A);
211  Ainv[0] = oneOverDet*A[3];
212  Ainv[1] = -oneOverDet*A[1];
213  Ainv[2] = -oneOverDet*A[2];
214  Ainv[3] = oneOverDet*A[0];
215  }
216 
217  template<>
218  inline void inv<3>(const double* A, double* Ainv)
219  {
220  double oneOverDet = 1.0/det<3>(A);
221  Ainv[XX] = oneOverDet*(A[YY]*A[ZZ] - A[YZ]*A[ZY]);
222  Ainv[YX] = oneOverDet*(A[YZ]*A[ZX] - A[YX]*A[ZZ]);
223  Ainv[ZX] = oneOverDet*(A[YX]*A[ZY] - A[YY]*A[ZX]);
224  Ainv[XY] = oneOverDet*(A[ZY]*A[XZ] - A[ZZ]*A[XY]);
225  Ainv[YY] = oneOverDet*(A[ZZ]*A[XX] - A[ZX]*A[XZ]);
226  Ainv[ZY] = oneOverDet*(A[ZX]*A[XY] - A[ZY]*A[XX]);
227  Ainv[XZ] = oneOverDet*(A[XY]*A[YZ] - A[XZ]*A[YY]);
228  Ainv[YZ] = oneOverDet*(A[XZ]*A[YX] - A[XX]*A[YZ]);
229  Ainv[ZZ] = oneOverDet*(A[XX]*A[YY] - A[XY]*A[YX]);
230  }
231 }//equivalent_polynomials
232 #endif
equivalent_polynomials::XY
const int XY(1)
equivalent_polynomials::inv< 2 >
void inv< 2 >(const double *A, double *Ainv)
Definition: equivalent_polynomials_utils.h:208
equivalent_polynomials::YY
const int YY(4)
equivalent_polynomials::inv
void inv(const double *A, double *Ainv)
equivalent_polynomials::XX
const int XX(0)
equivalent_polynomials::ZZ
const int ZZ(8)
equivalent_polynomials::_calculate_polynomial_3D
void _calculate_polynomial_3D(double *xi, double *C_H, double *C_ImH, double *C_D, double &_H, double &_ImH, double &_D)
Definition: equivalent_polynomials_utils.h:146
equivalent_polynomials::_calculate_normal< 3 >
void _calculate_normal< 3 >(double *phys_nodes_cut, double *level_set_normal)
Definition: equivalent_polynomials_utils.h:40
equivalent_polynomials::_calculate_polynomial_2D
void _calculate_polynomial_2D(double *xi, double *C_H, double *C_ImH, double *C_D, double &_H, double &_ImH, double &_D)
Definition: equivalent_polynomials_utils.h:123
equivalent_polynomials::det< 1 >
double det< 1 >(const double *A)
Definition: equivalent_polynomials_utils.h:179
equivalent_polynomials::det< 2 >
double det< 2 >(const double *A)
Definition: equivalent_polynomials_utils.h:185
equivalent_polynomials::_calculate_normal
void _calculate_normal(double *phys_nodes_cut, double *level_set_normal)
equivalent_polynomials::_calculate_normal_quad
void _calculate_normal_quad(double *phys_nodes_cut_quad_01, double *phys_nodes_cut_quad_02, double *phys_nodes_cut_quad_31, double *phys_nodes_cut_quad_32, double *level_set_normal)
Definition: equivalent_polynomials_utils.h:70
equivalent_polynomials
Definition: equivalent_polynomials.h:12
equivalent_polynomials::_calculate_normal< 2 >
void _calculate_normal< 2 >(double *phys_nodes_cut, double *level_set_normal)
Definition: equivalent_polynomials_utils.h:16
equivalent_polynomials::YZ
const int YZ(5)
equivalent_polynomials::det
double det(const double *A)
equivalent_polynomials::_calculate_normal< 1 >
void _calculate_normal< 1 >(double *phys_nodes_cut, double *level_set_normal)
Definition: equivalent_polynomials_utils.h:9
equivalent_polynomials::XZ
const int XZ(2)
equivalent_polynomials::inv< 1 >
void inv< 1 >(const double *A, double *Ainv)
Definition: equivalent_polynomials_utils.h:202
equivalent_polynomials::ZX
const int ZX(6)
equivalent_polynomials::det< 3 >
double det< 3 >(const double *A)
Definition: equivalent_polynomials_utils.h:191
equivalent_polynomials::_calculate_polynomial_1D
void _calculate_polynomial_1D(double *xi, double *C_H, double *C_ImH, double *C_D, double &_H, double &_ImH, double &_D)
Definition: equivalent_polynomials_utils.h:105
psi
Double psi
Definition: Headers.h:78
equivalent_polynomials::inv< 3 >
void inv< 3 >(const double *A, double *Ainv)
Definition: equivalent_polynomials_utils.h:218
equivalent_polynomials::YX
const int YX(3)
equivalent_polynomials::ZY
const int ZY(7)