Rheolef  7.1
an efficient C++ finite element environment
space_constant.cc
Go to the documentation of this file.
1 // constants
22 
23 #include "rheolef/space_constant.h"
24 
25 namespace rheolef { namespace space_constant {
26 
27 // ---------------------------------------------------------------------------
28 // valued: for multi-component field support
29 // ---------------------------------------------------------------------------
30 static
31 const std::string
32 valued_id [last_valued+1] = {
33  "scalar",
34  "vector",
35  "tensor",
36  "unsymmetric_tensor",
37  "tensor3",
38  "tensor4",
39  "mixed",
40  "undefined"
41 };
42 const std::string&
44 {
45  if (valued_tag <= last_valued) return valued_id [valued_tag];
46  error_macro ("invalid valued tag = " << valued_tag);
47  return valued_id [last_valued]; // not reached
48 }
50 valued_tag (const std::string& name)
51 {
52  for (size_t valued_tag = 0; valued_tag < last_valued; valued_tag++) {
53  if (valued_id[valued_tag] == name) return valued_type(valued_tag);
54  }
55  error_macro ("invalid valued `" << name << "'");
56  return scalar; // not reached
57 }
58 // ---------------------------------------------------------------------------
59 // coordinate system helper
60 // ---------------------------------------------------------------------------
61 static
62 const char*const
63 coord_sys_table [last_coord_sys] = {
64  "cartesian",
65  "rz",
66  "zr"
67 };
68 std::string
70 {
71  assert_macro (i < last_coord_sys, "invalid coordinate_type " << i);
72  return coord_sys_table [i];
73 }
76 {
77  for (size_type i = 0; i < last_coord_sys; i++)
78  if (sys_coord == coord_sys_table[i]) return coordinate_type(i);
79  error_macro ("unexpected coordinate system `" << sys_coord << "'");
80  return last_coord_sys;
81 }
82 void
84 {
85  assert_macro (i < last_coord_sys, "invalid coordinate_type " << i);
86  check_macro (!((i == axisymmetric_rz || i == axisymmetric_zr) && d > 2),
87  "inconsistent `" << coord_sys_table[i]
88  << "' coordinate system for " << d << "D geometry");
89 }
90 // ---------------------------------------------------------------------------------
91 // symmetric & unsymmetric 2-tensors field-valued support
92 // ---------------------------------------------------------------------------------
93 static
94 const size_type
95 symmetric_tensor_index [3][3] = {
96  { 0, 1, 3},
97  { 1, 2, 4},
98  { 3, 4, 5}
99 };
100 static
101 const char*const
102 symmetric_tensor_subscript_name [6] = {
103  "00",
104  "01",
105  "11",
106  "02",
107  "12",
108  "22"
109 };
110 static
111 const
112 size_type
113 unsymmetric_tensor_index [3][3] = {
114  { 0, 1, 4},
115  { 2, 3, 5},
116  { 6, 7, 8}
117 };
118 static
119 const char*const
120 unsymmetric_tensor_subscript_name [9] = {
121  "00",
122  "01",
123  "10",
124  "11",
125  "02",
126  "12",
127  "20",
128  "21",
129  "22"
130 };
131 // intel C++ v12 cannot support class initializers:
132 static std::pair<size_type,size_type> symmetric_tensor_subscript [6];
133 static std::pair<size_type,size_type> unsymmetric_tensor_subscript [9];
134 
135 size_type
138  size_type d,
140 {
141  switch (valued_tag) {
142  case vector: return d;
143  case scalar: return 0;
144  case tensor4: { // A_ijkl with A_ijkl=A_jikl, A_ijkl=A_ijlk and A_ijkl=A_klij
146  return 10; // add all the theta,theta components
147  }
148  switch (d) {
149  case 1: return 1;
150  case 2: return 6;
151  default: return 21;
152  }
153  }
154  case tensor: {
156  return 4; // add the \tau_{\theta,\theta}" component
157  }
158  return d*(d+1)/2;
159  }
160  case unsymmetric_tensor: {
162  return 5;
163  }
164  return d*d;
165  }
166  default: {
167  error_macro ("unsupported valued space `" << valued_name(valued_tag) << "'");
168  return 0; // not reached
169  }
170  }
171 }
172 size_type
174  const std::string& valued,
175  size_type d,
177 {
178  return n_component (valued_tag(valued), d, sys_coord);
179 }
180 size_type
184  size_type i,
185  size_type j)
186 {
189  && i == 2 && j == 2)
190  return 4;
191  return unsymmetric_tensor_index [i][j];
192  } else {
194  && i == 2 && j == 2)
195  return 3;
196  return symmetric_tensor_index [i][j];
197  }
198 }
199 size_type
201  std::string valued,
202  std::string sys_coord,
203  size_type i,
204  size_type j)
205 {
206  return tensor_index (valued_tag(valued), coordinate_system(sys_coord), i, j);
207 }
208 std::pair<size_type,size_type>
212  size_type i_comp)
213 {
216  && i_comp == 4)
217  return std::pair<size_type,size_type>(2,2);
218  return unsymmetric_tensor_subscript [i_comp];
219  } else {
221  && i_comp == 3)
222  return std::pair<size_type,size_type>(2,2);
223  return symmetric_tensor_subscript [i_comp];
224  }
225 }
226 std::string
230  size_type i_comp)
231 {
234  && i_comp == 4)
235  return "22";
236  return unsymmetric_tensor_subscript_name [i_comp];
237  } else {
239  && i_comp == 3)
240  return "22";
241  return symmetric_tensor_subscript_name [i_comp];
242  }
243 }
244 std::pair<size_type,size_type>
246  std::string valued,
247  std::string sys_coord,
248  size_type i_comp)
249 {
250  return tensor_subscript (valued_tag(valued),
251  coordinate_system(sys_coord), i_comp);
252 }
253 std::string
255  std::string valued,
256  std::string sys_coord,
257  size_type i_comp)
258 {
259  return tensor_subscript_name (valued_tag(valued),
260  coordinate_system(sys_coord), i_comp);
261 }
262 // =================================================================================
263 // symmetric 4-tensors
264 // Note: 3 symmetries for 4-order tensors
265 // A_ijkl=A_ijlk, A_ijkl=A_jikl & A_ijkl=Aklij
266 // => 6 components in 2d, 21 in 3d and 10 in 2d-axisymmetric(rz)
267 // =================================================================================
268 static
269 const
270 size_type
271 symmetric_tensor4_index [6][6] = {
272  { 0, 1, 3, 6, 10, 15},
273  { 1, 2, 4, 7, 11, 16},
274  { 3, 4, 5, 8, 12, 17},
275  { 6, 7, 8, 9, 13, 18},
276  { 10, 11, 12, 13, 14, 19},
277  { 15, 16, 17, 18, 19, 20}
278 };
279 // intel C++ v12 cannot support class initializers:
280 static
281 std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
282 symmetric_tensor4_subscript [21];
283 
284 static
285 const char* const
286 symmetric_tensor4_subscript_name [21] = {
287  "00_00",
288  "00_01",
289  "01_01",
290  "00_11",
291  "01_11",
292  "11_11",
293  "00_02",
294  "01_02",
295  "11_02",
296  "02_02",
297  "00_12",
298  "01_12",
299  "11_12",
300  "02_12",
301  "12_12",
302  "00_22",
303  "01_22",
304  "11_22",
305  "02_22",
306  "12_22",
307  "22_22" };
308 
309 // special axisymmetic case
310 // intel C++ v12 cannot support class initializers:
311 static
312 std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
313 symmetric_tensor4_subscript_rz [10];
314 
315 static
316 const char* const
317 symmetric_tensor4_subscript_rz_name [10] = {
318  "00_00",
319  "00_01",
320  "01_01",
321  "00_11",
322  "01_11",
323  "11_11",
324  "00_22",
325  "01_22",
326  "11_22",
327  "22_22" };
328 
329 // -----------------------------------------------------------------------
330 // 4-tensor interface
331 // -----------------------------------------------------------------------
332 size_type
334  valued_type valued,
336  size_type i,
337  size_type j,
338  size_type k,
339  size_type l)
340 {
341  size_type ij = tensor_index (tensor, sys_coord, i, j);
342  size_type kl = tensor_index (tensor, sys_coord, k, l);
343  return symmetric_tensor4_index[ij][kl];
344 }
345 size_type
347  std::string valued,
348  std::string sys_coord,
349  size_type i,
350  size_type j,
351  size_type k,
352  size_type l)
353 {
354  return tensor4_index (valued_tag(valued), coordinate_system(sys_coord), i, j, k, l);
355 }
356 std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
358  valued_type valued,
360  size_type i_comp)
361 {
363  return symmetric_tensor4_subscript_rz [i_comp];
364  } else {
365  return symmetric_tensor4_subscript [i_comp];
366  }
367 }
368 std::string
370  valued_type valued,
372  size_type i_comp)
373 {
375  return symmetric_tensor4_subscript_rz_name [i_comp];
376  } else {
377  return symmetric_tensor4_subscript_name [i_comp];
378  }
379 }
380 std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
382  std::string valued,
383  std::string sys_coord,
384  size_type i_comp)
385 {
386  return tensor4_subscript (valued_tag(valued),
387  coordinate_system(sys_coord), i_comp);
388 }
389 std::string
391  std::string valued,
392  std::string sys_coord,
393  size_type i_comp)
394 {
395  return tensor4_subscript_name (valued_tag(valued),
396  coordinate_system(sys_coord), i_comp);
397 }
398 // -----------------------------------------------------------------------
399 // field*field : compute the value_type result at run time
400 // -----------------------------------------------------------------------
401 // TODO: move it in operators.cc
402 static const valued_type multiplies_result_tag_table [tensor3+1][tensor3+1] = {
408 };
411 {
412  if (tag1 > tensor3 || tag2 > tensor3) return last_valued;
413  return multiplies_result_tag_table [tag1][tag2];
414 }
415 static const valued_type divides_result_tag_table [tensor+1][tensor+1] = {
419 };
422 {
423  if (tag1 > tensor || tag2 > tensor) return last_valued;
424  return divides_result_tag_table [tag1][tag2];
425 }
426 // ---------------------------------------------------------------------------
427 // init arrays of pairs:
428 // ---------------------------------------------------------------------------
429 // intel C++ v12 cannot support class initializers:
430 struct static_initializer_t {
431  static_initializer_t();
432 };
433 static_initializer_t::static_initializer_t() {
434  typedef std::pair<size_type,size_type> p;
435  symmetric_tensor_subscript[0] = p(0,0);
436  symmetric_tensor_subscript[1] = p(0,1);
437  symmetric_tensor_subscript[2] = p(1,1);
438  symmetric_tensor_subscript[3] = p(0,2);
439  symmetric_tensor_subscript[4] = p(1,2);
440  symmetric_tensor_subscript[5] = p(2,2);
441 
442  unsymmetric_tensor_subscript[0] = p(0,0);
443  unsymmetric_tensor_subscript[1] = p(0,1);
444  unsymmetric_tensor_subscript[2] = p(1,0);
445  unsymmetric_tensor_subscript[3] = p(1,1);
446  unsymmetric_tensor_subscript[4] = p(0,2);
447  unsymmetric_tensor_subscript[5] = p(1,2);
448  unsymmetric_tensor_subscript[6] = p(2,0);
449  unsymmetric_tensor_subscript[7] = p(2,1);
450  unsymmetric_tensor_subscript[8] = p(2,2);
451 
452  typedef std::pair<p,p> pp;
453  symmetric_tensor4_subscript [ 0] = pp(p(0,0), p(0,0));
454  symmetric_tensor4_subscript [ 1] = pp(p(0,0), p(0,1));
455  symmetric_tensor4_subscript [ 2] = pp(p(0,1), p(0,1));
456  symmetric_tensor4_subscript [ 3] = pp(p(0,0), p(1,1));
457  symmetric_tensor4_subscript [ 4] = pp(p(0,1), p(1,1));
458  symmetric_tensor4_subscript [ 5] = pp(p(1,1), p(1,1));
459  symmetric_tensor4_subscript [ 6] = pp(p(0,0), p(0,2));
460  symmetric_tensor4_subscript [ 7] = pp(p(0,1), p(0,2));
461  symmetric_tensor4_subscript [ 8] = pp(p(1,1), p(0,2));
462  symmetric_tensor4_subscript [ 9] = pp(p(0,2), p(0,2));
463  symmetric_tensor4_subscript [10] = pp(p(0,0), p(1,2));
464  symmetric_tensor4_subscript [11] = pp(p(0,1), p(1,2));
465  symmetric_tensor4_subscript [12] = pp(p(1,1), p(1,2));
466  symmetric_tensor4_subscript [13] = pp(p(0,2), p(1,2));
467  symmetric_tensor4_subscript [14] = pp(p(1,2), p(1,2));
468  symmetric_tensor4_subscript [15] = pp(p(0,0), p(2,2));
469  symmetric_tensor4_subscript [16] = pp(p(0,1), p(2,2));
470  symmetric_tensor4_subscript [17] = pp(p(1,1), p(2,2));
471  symmetric_tensor4_subscript [18] = pp(p(0,2), p(2,2));
472  symmetric_tensor4_subscript [19] = pp(p(1,2), p(2,2));
473  symmetric_tensor4_subscript [20] = pp(p(2,2), p(2,2));
474 
475  symmetric_tensor4_subscript_rz [0] = pp(p(0,0), p(0,0));
476  symmetric_tensor4_subscript_rz [0] = pp(p(0,0), p(0,1));
477  symmetric_tensor4_subscript_rz [0] = pp(p(0,1), p(0,1));
478  symmetric_tensor4_subscript_rz [0] = pp(p(0,0), p(1,1));
479  symmetric_tensor4_subscript_rz [0] = pp(p(0,1), p(1,1));
480  symmetric_tensor4_subscript_rz [0] = pp(p(1,1), p(1,1));
481  symmetric_tensor4_subscript_rz [0] = pp(p(0,0), p(2,2));
482  symmetric_tensor4_subscript_rz [0] = pp(p(0,1), p(2,2));
483  symmetric_tensor4_subscript_rz [0] = pp(p(1,1), p(2,2));
484  symmetric_tensor4_subscript_rz [0] = pp(p(2,2), p(2,2));
485 }
486 static static_initializer_t dummy;
487 
488 }} // namespace rheolef::space_constant
field::size_type size_type
Definition: branch.cc:425
tensor3_basic< Float > tensor3
Definition: tensor3.h:121
tensor_basic< Float > tensor
Definition: tensor.h:181
tensor4_basic< Float > tensor4
Definition: tensor4.h:133
static iorheo::force_initialization dummy
Definition: iorheo.cc:147
see the tensor3 page for the full documentation
see the tensor page for the full documentation
#define assert_macro(ok_condition, message)
Definition: dis_macros.h:113
#define error_macro(message)
Definition: dis_macros.h:49
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
string sys_coord
Definition: mkgeo_grid.sh:171
void check_coord_sys_and_dimension(coordinate_type i, size_type d)
coordinate_type coordinate_system(std::string sys_coord)
std::string coordinate_system_name(coordinate_type i)
valued_type multiplies_result_tag(space_constant::valued_type tag1, space_constant::valued_type tag2)
size_type tensor4_index(valued_type valued, coordinate_type sys_coord, size_type i, size_type j, size_type k, size_type l)
std::string tensor_subscript_name(valued_type valued_tag, coordinate_type sys_coord, size_type i_comp)
size_type tensor_index(valued_type valued_tag, coordinate_type sys_coord, size_type i, size_type j)
valued_type divides_result_tag(space_constant::valued_type tag1, space_constant::valued_type tag2)
std::pair< std::pair< size_type, size_type >, std::pair< size_type, size_type > > tensor4_subscript(valued_type valued, coordinate_type sys_coord, size_type i_comp)
std::string tensor4_subscript_name(valued_type valued, coordinate_type sys_coord, size_type i_comp)
const std::string & valued_name(valued_type valued_tag)
valued_type valued_tag(const std::string &name)
size_type n_component(valued_type valued_tag, size_type d, coordinate_type sys_coord)
std::pair< size_type, size_type > tensor_subscript(valued_type valued_tag, coordinate_type sys_coord, size_type i_comp)
This file is part of Rheolef.
Definition: sphere.icc:25