~ubuntu-branches/ubuntu/trusty/rheolef/trusty

« back to all changes in this revision

Viewing changes to nfem/plib/space_constant.cc

  • Committer: Package Import Robot
  • Author(s): Pierre Saramito
  • Date: 2012-04-06 09:12:21 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120406091221-m58me99p1nxqui49
Tags: 6.0-1
* New upstream release 6.0 (major changes):
  - massively distributed and parallel support
  - full FEM characteristic method (Lagrange-Gakerkin method) support
  - enhanced users documentation 
  - source code supports g++-4.7 (closes: #667356)
* debian/control: dependencies for MPI distributed solvers added
* debian/rules: build commands simplified
* debian/librheolef-dev.install: man1/* to man9/* added
* debian/changelog: package description rewritted (closes: #661689)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
///
 
2
/// This file is part of Rheolef.
 
3
///
 
4
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
 
5
///
 
6
/// Rheolef is free software; you can redistribute it and/or modify
 
7
/// it under the terms of the GNU General Public License as published by
 
8
/// the Free Software Foundation; either version 2 of the License, or
 
9
/// (at your option) any later version.
 
10
///
 
11
/// Rheolef is distributed in the hope that it will be useful,
 
12
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
/// GNU General Public License for more details.
 
15
///
 
16
/// You should have received a copy of the GNU General Public License
 
17
/// along with Rheolef; if not, write to the Free Software
 
18
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
/// 
 
20
/// =========================================================================
 
21
// 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
std::string
 
32
valued_id [last_valued] = {
 
33
        "scalar",
 
34
        "vector",
 
35
        "tensor",
 
36
        "unsymmetric_tensor",
 
37
        "tensor4",
 
38
        "mixed"
 
39
};
 
40
const std::string&
 
41
valued_name (valued_type valued_tag)
 
42
{
 
43
  if (valued_tag < last_valued) return valued_id [valued_tag];
 
44
  error_macro ("invalid valued tag = " << valued_tag); 
 
45
  return valued_id [0]; // not reached
 
46
}
 
47
valued_type
 
48
valued_tag (const std::string& name)
 
49
{
 
50
  for (size_t valued_tag = 0; valued_tag < last_valued; valued_tag++) {
 
51
    if (valued_id[valued_tag] == name) return valued_type(valued_tag);
 
52
  }
 
53
  error_macro ("invalid valued `" << name << "'"); 
 
54
  return scalar; // not reached
 
55
}
 
56
// ---------------------------------------------------------------------------
 
57
//  coordinate system helper
 
58
// ---------------------------------------------------------------------------
 
59
static
 
60
const char* 
 
61
coord_sys_table [last_coord_sys] = {
 
62
    "cartesian",
 
63
    "rz",
 
64
    "zr"
 
65
};
 
66
std::string 
 
67
coordinate_system_name (coordinate_type i)
 
68
{
 
69
    assert_macro (i < last_coord_sys, "invalid coordinate_type " << i);
 
70
    return coord_sys_table [i];
 
71
}
 
72
coordinate_type
 
73
coordinate_system (std::string sys_coord)
 
74
{
 
75
    for (size_type i = 0; i < last_coord_sys; i++)
 
76
        if (sys_coord == coord_sys_table[i]) return coordinate_type(i);
 
77
    error_macro ("unexpected coordinate system `" << sys_coord << "'");
 
78
    return last_coord_sys;
 
79
}
 
80
void
 
81
check_coord_sys_and_dimension (coordinate_type i, size_type d)
 
82
{
 
83
    assert_macro (i < last_coord_sys, "invalid coordinate_type " << i);
 
84
    check_macro (!((i == axisymmetric_rz || i == axisymmetric_zr) && d > 2),
 
85
        "inconsistent `" << coord_sys_table[i] 
 
86
         << "' coordinate system for " << d << "D geometry"); 
 
87
}
 
88
// ---------------------------------------------------------------------------------
 
89
// symmetric & unsymmetric 2-tensors field-valued support
 
90
// ---------------------------------------------------------------------------------
 
91
static
 
92
size_type
 
93
symmetric_tensor_index [3][3] = {
 
94
        { 0, 1, 3},
 
95
        { 1, 2, 4},
 
96
        { 3, 4, 5}
 
97
};
 
98
static
 
99
std::pair<size_type,size_type>
 
100
symmetric_tensor_subscript [6] = {
 
101
        {0,0},
 
102
        {0,1},
 
103
        {1,1},
 
104
        {0,2},
 
105
        {1,2},
 
106
        {2,2}
 
107
};
 
108
static
 
109
const char*
 
110
symmetric_tensor_subscript_name [6] = {
 
111
        "00", 
 
112
        "01", 
 
113
        "11",
 
114
        "02", 
 
115
        "12",
 
116
        "22"
 
117
};
 
118
static
 
119
size_type
 
120
unsymmetric_tensor_index [3][3] = {
 
121
        { 0, 1, 4},
 
122
        { 2, 3, 5},
 
123
        { 6, 7, 8}
 
124
};
 
125
static
 
126
std::pair<size_type,size_type>
 
127
unsymmetric_tensor_subscript [9] = {
 
128
        {0,0},
 
129
        {0,1}, 
 
130
        {1,0},
 
131
        {1,1},
 
132
        {0,2},
 
133
        {1,2},
 
134
        {2,0},
 
135
        {2,1},
 
136
        {2,2}
 
137
};
 
138
static
 
139
const char*
 
140
unsymmetric_tensor_subscript_name [9] = {
 
141
        "00",
 
142
        "01",   
 
143
        "10",   
 
144
        "11",   
 
145
        "02",   
 
146
        "12",   
 
147
        "20",   
 
148
        "21",   
 
149
        "22"
 
150
};
 
151
size_type
 
152
n_component (
 
153
    valued_type        valued_tag,
 
154
    size_type          d,
 
155
    coordinate_type    sys_coord)
 
156
 
157
  switch (valued_tag) {
 
158
    case vector: return d;
 
159
    case scalar: return 0;
 
160
    case tensor4: { // A_ijkl with A_ijkl=A_jikl, A_ijkl=A_ijlk and A_ijkl=A_klij
 
161
      if ((sys_coord == axisymmetric_rz)||(sys_coord == axisymmetric_zr)) {
 
162
        return 10; // add all the theta,theta components
 
163
      } 
 
164
      switch (d) {
 
165
        case 1:  return 1;
 
166
        case 2:  return 6; 
 
167
        default: return 21;
 
168
      }
 
169
    }
 
170
    case tensor: {
 
171
      if ((sys_coord == axisymmetric_rz)||(sys_coord == axisymmetric_zr)) {
 
172
        return 4; // add the \tau_{\theta,\theta}" component
 
173
      }
 
174
      return d*(d+1)/2;
 
175
    }
 
176
    case unsymmetric_tensor: {
 
177
      if ((sys_coord == axisymmetric_rz)||(sys_coord == axisymmetric_zr)) {
 
178
        return 5;
 
179
      }
 
180
      return d*d;
 
181
    }
 
182
    default: {
 
183
      error_macro ("unsupported valued space `" << valued_name(valued_tag) << "'");
 
184
      return 0; // not reached
 
185
    }
 
186
  }
 
187
}
 
188
size_type
 
189
n_component (
 
190
    const std::string& valued,
 
191
    size_type          d,
 
192
    coordinate_type    sys_coord)
 
193
{
 
194
  return n_component (valued_tag(valued), d, sys_coord);
 
195
}
 
196
size_type
 
197
tensor_index (
 
198
    valued_type       valued_tag,
 
199
    coordinate_type   sys_coord,
 
200
    size_type         i,
 
201
    size_type         j)
 
202
{
 
203
    if (valued_tag == unsymmetric_tensor) {
 
204
      if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
 
205
          && i == 2 && j == 2)
 
206
          return 4;
 
207
      return unsymmetric_tensor_index [i][j];
 
208
    } else {
 
209
      if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
 
210
          && i == 2 && j == 2)
 
211
          return 3;
 
212
      return   symmetric_tensor_index [i][j];
 
213
    }
 
214
}
 
215
size_type
 
216
tensor_index (
 
217
    std::string      valued,
 
218
    std::string      sys_coord, 
 
219
    size_type   i, 
 
220
    size_type   j)
 
221
{
 
222
    return tensor_index (valued_tag(valued), coordinate_system(sys_coord), i, j);
 
223
}
 
224
std::pair<size_type,size_type>
 
225
tensor_subscript (
 
226
    valued_type       valued_tag,
 
227
    coordinate_type   sys_coord,
 
228
    size_type         i_comp)
 
229
{
 
230
    if (valued_tag == unsymmetric_tensor) {
 
231
      if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
 
232
          && i_comp == 4)
 
233
         return std::pair<size_type,size_type>(2,2);
 
234
      return unsymmetric_tensor_subscript [i_comp];
 
235
    } else {
 
236
      if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
 
237
         && i_comp == 3)
 
238
         return std::pair<size_type,size_type>(2,2);
 
239
      return   symmetric_tensor_subscript [i_comp];
 
240
    }
 
241
}
 
242
std::string
 
243
tensor_subscript_name (
 
244
    valued_type       valued_tag,
 
245
    coordinate_type   sys_coord,
 
246
    size_type         i_comp)
 
247
{
 
248
    if (valued_tag == unsymmetric_tensor) {
 
249
      if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
 
250
          && i_comp == 4)
 
251
        return "22";
 
252
      return unsymmetric_tensor_subscript_name [i_comp];
 
253
    } else {
 
254
      if ((sys_coord == axisymmetric_rz || sys_coord == axisymmetric_zr)
 
255
        && i_comp == 3) 
 
256
        return "22";
 
257
      return   symmetric_tensor_subscript_name [i_comp];
 
258
    }
 
259
}
 
260
std::pair<size_type,size_type>
 
261
tensor_subscript (
 
262
    std::string     valued,
 
263
    std::string     sys_coord,
 
264
    size_type  i_comp)
 
265
{
 
266
    return tensor_subscript (valued_tag(valued),
 
267
                 coordinate_system(sys_coord), i_comp);
 
268
}
 
269
std::string
 
270
tensor_subscript_name (
 
271
    std::string     valued,
 
272
    std::string     sys_coord,
 
273
    size_type  i_comp)
 
274
{
 
275
    return tensor_subscript_name (valued_tag(valued),
 
276
                 coordinate_system(sys_coord), i_comp);
 
277
}
 
278
 
 
279
}} // namespace rheolef::space_constant