rheolef  6.3
space_constant.cc
Go to the documentation of this file.
1 
2 #include "rheolef/space_constant.h"
3 
4 namespace rheolef { namespace space_constant {
5 
6 static
7 const std::string
9  "scalar",
10  "vector",
11  "tensor",
12  "unsymmetric_tensor",
13  "tensor4",
14  "mixed"
15 };
16 const std::string&
18 {
19  if (valued_tag < last_valued) return valued_id [valued_tag];
20  error_macro ("invalid valued tag = " << valued_tag);
21  return valued_id [0]; // not reached
22 }
24 valued_tag (const std::string& name)
25 {
26  for (size_t valued_tag = 0; valued_tag < last_valued; valued_tag++) {
27  if (valued_id[valued_tag] == name) return valued_type(valued_tag);
28  }
29  error_macro ("invalid valued `" << name << "'");
30  return scalar; // not reached
31 }
32 static
33 const char*const
35  "cartesian",
36  "rz",
37  "zr"
38 };
39 std::string
41 {
42  assert_macro (i < last_coord_sys, "invalid coordinate_type " << i);
43  return coord_sys_table [i];
44 }
46 coordinate_system (std::string sys_coord)
47 {
48  for (size_type i = 0; i < last_coord_sys; i++)
49  if (sys_coord == coord_sys_table[i]) return coordinate_type(i);
50  error_macro ("unexpected coordinate system `" << sys_coord << "'");
51  return last_coord_sys;
52 }
53 void
55 {
56  assert_macro (i < last_coord_sys, "invalid coordinate_type " << i);
57  check_macro (!((i == axisymmetric_rz || i == axisymmetric_zr) && d > 2),
58  "inconsistent `" << coord_sys_table[i]
59  << "' coordinate system for " << d << "D geometry");
60 }
61 static
62 const size_type
64  { 0, 1, 3},
65  { 1, 2, 4},
66  { 3, 4, 5}
67 };
68 static
69 const char*const
71  "00",
72  "01",
73  "11",
74  "02",
75  "12",
76  "22"
77 };
78 static
79 const
82  { 0, 1, 4},
83  { 2, 3, 5},
84  { 6, 7, 8}
85 };
86 static
87 const char*const
89  "00",
90  "01",
91  "10",
92  "11",
93  "02",
94  "12",
95  "20",
96  "21",
97  "22"
98 };
99 #ifdef _RHEOLEF_HAVE_CONSTANT_BRACES_INITIALIZER
100 static
101 const
102 std::pair<size_type,size_type>
104  {0,0},
105  {0,1},
106  {1,1},
107  {0,2},
108  {1,2},
109  {2,2}
110 };
111 static
112 const
113 std::pair<size_type,size_type>
115  {0,0},
116  {0,1},
117  {1,0},
118  {1,1},
119  {0,2},
120  {1,2},
121  {2,0},
122  {2,1},
123  {2,2}
124 };
125 #else // ! _RHEOLEF_HAVE_CONSTANT_BRACES_INITIALIZER
126 static std::pair<size_type,size_type> symmetric_tensor_subscript [6];
127 static std::pair<size_type,size_type> unsymmetric_tensor_subscript [9];
128 #endif // _RHEOLEF_HAVE_CONSTANT_BRACES_INITIALIZER
129 
130 size_type
133  size_type d,
134  coordinate_type sys_coord)
135 {
136  switch (valued_tag) {
137  case vector: return d;
138  case scalar: return 0;
139  case tensor4: { // A_ijkl with A_ijkl=A_jikl, A_ijkl=A_ijlk and A_ijkl=A_klij
140  if ((sys_coord == axisymmetric_rz)||(sys_coord == axisymmetric_zr)) {
141  return 10; // add all the theta,theta components
142  }
143  switch (d) {
144  case 1: return 1;
145  case 2: return 6;
146  default: return 21;
147  }
148  }
149  case tensor: {
150  if ((sys_coord == axisymmetric_rz)||(sys_coord == axisymmetric_zr)) {
151  return 4; // add the \tau_{\theta,\theta}" component
152  }
153  return d*(d+1)/2;
154  }
155  case unsymmetric_tensor: {
156  if ((sys_coord == axisymmetric_rz)||(sys_coord == axisymmetric_zr)) {
157  return 5;
158  }
159  return d*d;
160  }
161  default: {
162  error_macro ("unsupported valued space `" << valued_name(valued_tag) << "'");
163  return 0; // not reached
164  }
165  }
166 }
167 size_type
169  const std::string& valued,
170  size_type d,
171  coordinate_type sys_coord)
172 {
173  return n_component (valued_tag(valued), d, sys_coord);
174 }
175 size_type
178  coordinate_type sys_coord,
179  size_type i,
180  size_type j)
181 {
182  if (valued_tag == unsymmetric_tensor) {
183  if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
184  && i == 2 && j == 2)
185  return 4;
186  return unsymmetric_tensor_index [i][j];
187  } else {
188  if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
189  && i == 2 && j == 2)
190  return 3;
191  return symmetric_tensor_index [i][j];
192  }
193 }
194 size_type
196  std::string valued,
197  std::string sys_coord,
198  size_type i,
199  size_type j)
200 {
201  return tensor_index (valued_tag(valued), coordinate_system(sys_coord), i, j);
202 }
203 std::pair<size_type,size_type>
206  coordinate_type sys_coord,
207  size_type i_comp)
208 {
209  if (valued_tag == unsymmetric_tensor) {
210  if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
211  && i_comp == 4)
212  return std::pair<size_type,size_type>(2,2);
213  return unsymmetric_tensor_subscript [i_comp];
214  } else {
215  if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
216  && i_comp == 3)
217  return std::pair<size_type,size_type>(2,2);
218  return symmetric_tensor_subscript [i_comp];
219  }
220 }
221 std::string
224  coordinate_type sys_coord,
225  size_type i_comp)
226 {
227  if (valued_tag == unsymmetric_tensor) {
228  if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
229  && i_comp == 4)
230  return "22";
231  return unsymmetric_tensor_subscript_name [i_comp];
232  } else {
233  if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
234  && i_comp == 3)
235  return "22";
236  return symmetric_tensor_subscript_name [i_comp];
237  }
238 }
239 std::pair<size_type,size_type>
241  std::string valued,
242  std::string sys_coord,
243  size_type i_comp)
244 {
245  return tensor_subscript (valued_tag(valued),
246  coordinate_system(sys_coord), i_comp);
247 }
248 std::string
250  std::string valued,
251  std::string sys_coord,
252  size_type i_comp)
253 {
254  return tensor_subscript_name (valued_tag(valued),
255  coordinate_system(sys_coord), i_comp);
256 }
257 // => 6 components in 2d, 21 in 3d and 10 in 2d-axisymmetric(rz)
258 static
259 const
260 size_type
262  { 0, 1, 3, 6, 10, 15},
263  { 1, 2, 4, 7, 11, 16},
264  { 3, 4, 5, 8, 12, 17},
265  { 6, 7, 8, 9, 13, 18},
266  { 10, 11, 12, 13, 14, 19},
267  { 15, 16, 17, 18, 19, 20}
268 };
269 #ifdef _RHEOLEF_HAVE_CONSTANT_BRACES_INITIALIZER
270 static
271 const
272 std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
274  {{0,0}, {0,0}},
275  {{0,0}, {0,1}},
276  {{0,1}, {0,1}},
277  {{0,0}, {1,1}},
278  {{0,1}, {1,1}},
279  {{1,1}, {1,1}},
280  {{0,0}, {0,2}},
281  {{0,1}, {0,2}},
282  {{1,1}, {0,2}},
283  {{0,2}, {0,2}},
284  {{0,0}, {1,2}},
285  {{0,1}, {1,2}},
286  {{1,1}, {1,2}},
287  {{0,2}, {1,2}},
288  {{1,2}, {1,2}},
289  {{0,0}, {2,2}},
290  {{0,1}, {2,2}},
291  {{1,1}, {2,2}},
292  {{0,2}, {2,2}},
293  {{1,2}, {2,2}},
294  {{2,2}, {2,2}} };
295 #else // ! _RHEOLEF_HAVE_CONSTANT_BRACES_INITIALIZER
296 static
297 std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
299 
300 #endif // ! _RHEOLEF_HAVE_CONSTANT_BRACES_INITIALIZER
301 
302 static
303 const char* const
305  "00_00",
306  "00_01",
307  "01_01",
308  "00_11",
309  "01_11",
310  "11_11",
311  "00_02",
312  "01_02",
313  "11_02",
314  "02_02",
315  "00_12",
316  "01_12",
317  "11_12",
318  "02_12",
319  "12_12",
320  "00_22",
321  "01_22",
322  "11_22",
323  "02_22",
324  "12_22",
325  "22_22" };
326 
327 #ifdef _RHEOLEF_HAVE_CONSTANT_BRACES_INITIALIZER
328 static
329 const
330 std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
332  {{0,0}, {0,0}},
333  {{0,0}, {0,1}},
334  {{0,1}, {0,1}},
335  {{0,0}, {1,1}},
336  {{0,1}, {1,1}},
337  {{1,1}, {1,1}},
338  {{0,0}, {2,2}},
339  {{0,1}, {2,2}},
340  {{1,1}, {2,2}},
341  {{2,2}, {2,2}} };
342 #else // _RHEOLEF_HAVE_CONSTANT_BRACES_INITIALIZER
343 static
344 std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
346 #endif // _RHEOLEF_HAVE_CONSTANT_BRACES_INITIALIZER
347 
348 static
349 const char* const
351  "00_00",
352  "00_01",
353  "01_01",
354  "00_11",
355  "01_11",
356  "11_11",
357  "00_22",
358  "01_22",
359  "11_22",
360  "22_22" };
361 
362 size_type
364  valued_type valued,
365  coordinate_type sys_coord,
366  size_type i,
367  size_type j,
368  size_type k,
369  size_type l)
370 {
371  size_type ij = tensor_index (tensor, sys_coord, i, j);
372  size_type kl = tensor_index (tensor, sys_coord, k, l);
373  return symmetric_tensor4_index[ij][kl];
374 }
375 size_type
377  std::string valued,
378  std::string sys_coord,
379  size_type i,
380  size_type j,
381  size_type k,
382  size_type l)
383 {
384  return tensor4_index (valued_tag(valued), coordinate_system(sys_coord), i, j, k, l);
385 }
386 std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
388  valued_type valued,
389  coordinate_type sys_coord,
390  size_type i_comp)
391 {
392  if (sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr) {
393  return symmetric_tensor4_subscript_rz [i_comp];
394  } else {
395  return symmetric_tensor4_subscript [i_comp];
396  }
397 }
398 std::string
400  valued_type valued,
401  coordinate_type sys_coord,
402  size_type i_comp)
403 {
404  if (sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr) {
405  return symmetric_tensor4_subscript_rz_name [i_comp];
406  } else {
407  return symmetric_tensor4_subscript_name [i_comp];
408  }
409 }
410 std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
412  std::string valued,
413  std::string sys_coord,
414  size_type i_comp)
415 {
416  return tensor4_subscript (valued_tag(valued),
417  coordinate_system(sys_coord), i_comp);
418 }
419 std::string
421  std::string valued,
422  std::string sys_coord,
423  size_type i_comp)
424 {
425  return tensor4_subscript_name (valued_tag(valued),
426  coordinate_system(sys_coord), i_comp);
427 }
429  {scalar, vector, tensor},
430  {vector, last_valued, last_valued}, // v*v undef: see dot(v,v)->s or otimes(v,v)->t
431  {scalar, vector, tensor} // v*t undef: see trans(v)*t
432 };
434  {scalar, last_valued, last_valued},
435  {vector, last_valued, last_valued},
436  {tensor, last_valued, last_valued}
437 };
440 {
441  if (tag1 > tensor || tag2 > tensor) return last_valued;
442  return multiplies_result_tag_table [tag1][tag2];
443 }
446 {
447  if (tag1 > tensor || tag2 > tensor) return last_valued;
448  return divides_result_tag_table [tag1][tag2];
449 }
450 #ifndef _RHEOLEF_HAVE_CONSTANT_BRACES_INITIALIZER
453 };
455  typedef std::pair<size_type,size_type> p;
456  symmetric_tensor_subscript[0] = p(0,0);
457  symmetric_tensor_subscript[1] = p(0,1);
458  symmetric_tensor_subscript[2] = p(1,1);
459  symmetric_tensor_subscript[3] = p(0,2);
460  symmetric_tensor_subscript[4] = p(1,2);
461  symmetric_tensor_subscript[5] = p(2,2);
462 
463  unsymmetric_tensor_subscript[0] = p(0,0);
464  unsymmetric_tensor_subscript[1] = p(0,1);
465  unsymmetric_tensor_subscript[2] = p(1,0);
466  unsymmetric_tensor_subscript[3] = p(1,1);
467  unsymmetric_tensor_subscript[4] = p(0,2);
468  unsymmetric_tensor_subscript[5] = p(1,2);
469  unsymmetric_tensor_subscript[6] = p(2,0);
470  unsymmetric_tensor_subscript[7] = p(2,1);
471  unsymmetric_tensor_subscript[8] = p(2,2);
472 
473  typedef std::pair<p,p> pp;
474  symmetric_tensor4_subscript [ 0] = pp(p(0,0), p(0,0));
475  symmetric_tensor4_subscript [ 1] = pp(p(0,0), p(0,1));
476  symmetric_tensor4_subscript [ 2] = pp(p(0,1), p(0,1));
477  symmetric_tensor4_subscript [ 3] = pp(p(0,0), p(1,1));
478  symmetric_tensor4_subscript [ 4] = pp(p(0,1), p(1,1));
479  symmetric_tensor4_subscript [ 5] = pp(p(1,1), p(1,1));
480  symmetric_tensor4_subscript [ 6] = pp(p(0,0), p(0,2));
481  symmetric_tensor4_subscript [ 7] = pp(p(0,1), p(0,2));
482  symmetric_tensor4_subscript [ 8] = pp(p(1,1), p(0,2));
483  symmetric_tensor4_subscript [ 9] = pp(p(0,2), p(0,2));
484  symmetric_tensor4_subscript [10] = pp(p(0,0), p(1,2));
485  symmetric_tensor4_subscript [11] = pp(p(0,1), p(1,2));
486  symmetric_tensor4_subscript [12] = pp(p(1,1), p(1,2));
487  symmetric_tensor4_subscript [13] = pp(p(0,2), p(1,2));
488  symmetric_tensor4_subscript [14] = pp(p(1,2), p(1,2));
489  symmetric_tensor4_subscript [15] = pp(p(0,0), p(2,2));
490  symmetric_tensor4_subscript [16] = pp(p(0,1), p(2,2));
491  symmetric_tensor4_subscript [17] = pp(p(1,1), p(2,2));
492  symmetric_tensor4_subscript [18] = pp(p(0,2), p(2,2));
493  symmetric_tensor4_subscript [19] = pp(p(1,2), p(2,2));
494  symmetric_tensor4_subscript [20] = pp(p(2,2), p(2,2));
495 
496  symmetric_tensor4_subscript_rz [0] = pp(p(0,0), p(0,0));
497  symmetric_tensor4_subscript_rz [0] = pp(p(0,0), p(0,1));
498  symmetric_tensor4_subscript_rz [0] = pp(p(0,1), p(0,1));
499  symmetric_tensor4_subscript_rz [0] = pp(p(0,0), p(1,1));
500  symmetric_tensor4_subscript_rz [0] = pp(p(0,1), p(1,1));
501  symmetric_tensor4_subscript_rz [0] = pp(p(1,1), p(1,1));
502  symmetric_tensor4_subscript_rz [0] = pp(p(0,0), p(2,2));
503  symmetric_tensor4_subscript_rz [0] = pp(p(0,1), p(2,2));
504  symmetric_tensor4_subscript_rz [0] = pp(p(1,1), p(2,2));
505  symmetric_tensor4_subscript_rz [0] = pp(p(2,2), p(2,2));
506 }
508 
509 #endif // _RHEOLEF_HAVE_CONSTANT_BRACES_INITIALIZER
510 
511 }} // namespace rheolef::space_constant
512