Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
space_constant.cc
Go to the documentation of this file.
1
21// constants
22
23#include "rheolef/space_constant.h"
24
25namespace rheolef { namespace space_constant {
26
27// ---------------------------------------------------------------------------
28// valued: for multi-component field support
29// ---------------------------------------------------------------------------
30static
31const std::string
32valued_id [last_valued+1] = {
33 "scalar",
34 "vector",
35 "tensor",
36 "unsymmetric_tensor",
37 "tensor3",
38 "tensor4",
39 "mixed",
40 "undefined"
41};
42const 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}
50valued_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// ---------------------------------------------------------------------------
61static
62const char*const
63coord_sys_table [last_coord_sys] = {
64 "cartesian",
65 "rz",
66 "zr"
67};
68std::string
70{
71 assert_macro (i < last_coord_sys, "invalid coordinate_type " << i);
72 return coord_sys_table [i];
73}
75coordinate_system (std::string sys_coord)
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}
82void
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// ---------------------------------------------------------------------------------
93static
94const size_type
95symmetric_tensor_index [3][3] = {
96 { 0, 1, 3},
97 { 1, 2, 4},
98 { 3, 4, 5}
99};
100static
101const char*const
102symmetric_tensor_subscript_name [6] = {
103 "00",
104 "01",
105 "11",
106 "02",
107 "12",
108 "22"
109};
110static
111const
113unsymmetric_tensor_index [3][3] = {
114 { 0, 1, 4},
115 { 2, 3, 5},
116 { 6, 7, 8}
117};
118static
119const char*const
120unsymmetric_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:
132static std::pair<size_type,size_type> symmetric_tensor_subscript [6];
133static std::pair<size_type,size_type> unsymmetric_tensor_subscript [9];
134
138 size_type d,
139 coordinate_type sys_coord)
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
145 if ((sys_coord == axisymmetric_rz)||(sys_coord == axisymmetric_zr)) {
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: {
155 if ((sys_coord == axisymmetric_rz)||(sys_coord == axisymmetric_zr)) {
156 return 4; // add the \tau_{\theta,\theta}" component
157 }
158 return d*(d+1)/2;
159 }
160 case unsymmetric_tensor: {
161 if ((sys_coord == axisymmetric_rz)||(sys_coord == axisymmetric_zr)) {
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}
174 const std::string& valued,
175 size_type d,
176 coordinate_type sys_coord)
177{
178 return n_component (valued_tag(valued), d, sys_coord);
179}
183 coordinate_type sys_coord,
184 size_type i,
185 size_type j)
186{
188 if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
189 && i == 2 && j == 2)
190 return 4;
191 return unsymmetric_tensor_index [i][j];
192 } else {
193 if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
194 && i == 2 && j == 2)
195 return 3;
196 return symmetric_tensor_index [i][j];
197 }
198}
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}
208std::pair<size_type,size_type>
211 coordinate_type sys_coord,
213{
215 if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
216 && i_comp == 4)
217 return std::pair<size_type,size_type>(2,2);
218 return unsymmetric_tensor_subscript [i_comp];
219 } else {
220 if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
221 && i_comp == 3)
222 return std::pair<size_type,size_type>(2,2);
223 return symmetric_tensor_subscript [i_comp];
224 }
225}
226std::string
229 coordinate_type sys_coord,
231{
233 if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
234 && i_comp == 4)
235 return "22";
236 return unsymmetric_tensor_subscript_name [i_comp];
237 } else {
238 if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
239 && i_comp == 3)
240 return "22";
241 return symmetric_tensor_subscript_name [i_comp];
242 }
243}
244std::pair<size_type,size_type>
246 std::string valued,
247 std::string sys_coord,
249{
250 return tensor_subscript (valued_tag(valued),
251 coordinate_system(sys_coord), i_comp);
252}
253std::string
255 std::string valued,
256 std::string sys_coord,
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// =================================================================================
268static
269const
271symmetric_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:
280static
281std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
282symmetric_tensor4_subscript [21];
283
284static
285const char* const
286symmetric_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:
311static
312std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
313symmetric_tensor4_subscript_rz [10];
314
315static
316const char* const
317symmetric_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// -----------------------------------------------------------------------
334 valued_type valued,
335 coordinate_type sys_coord,
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}
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}
356std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
358 valued_type valued,
359 coordinate_type sys_coord,
361{
362 if (sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr) {
363 return symmetric_tensor4_subscript_rz [i_comp];
364 } else {
365 return symmetric_tensor4_subscript [i_comp];
366 }
367}
368std::string
370 valued_type valued,
371 coordinate_type sys_coord,
373{
374 if (sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr) {
375 return symmetric_tensor4_subscript_rz_name [i_comp];
376 } else {
377 return symmetric_tensor4_subscript_name [i_comp];
378 }
379}
380std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
382 std::string valued,
383 std::string sys_coord,
385{
386 return tensor4_subscript (valued_tag(valued),
387 coordinate_system(sys_coord), i_comp);
388}
389std::string
391 std::string valued,
392 std::string sys_coord,
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
402static 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}
415static 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:
430struct static_initializer_t {
431 static_initializer_t();
432};
433static_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}
486static static_initializer_t dummy;
487
488}} // namespace rheolef::space_constant
field::size_type size_type
Definition branch.cc:430
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)")
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)
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.
space_constant::valued_type valued_tag() const
Definition sphere.icc:25