File: Lib_Elasticity_u.pro

package info (click to toggle)
getdp 3.0.4%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,856 kB
  • sloc: cpp: 63,020; fortran: 13,955; yacc: 9,350; f90: 1,640; lex: 799; makefile: 55; ansic: 34; awk: 33; sh: 23
file content (299 lines) | stat: -rw-r--r-- 9,396 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
// Lib_Elasticity_u.pro
//
// Template library for elastostatics, elastodynamics and modal analysis using a
// displacement (u) formulation, in both 2D (plane stress or plain strain) and
// 3D.

// Default definitions of constants, groups and functions that can/should be
// redefined from outside the template:

DefineConstant[
  modelPath = "", // default path of the model
  resPath = StrCat[modelPath, "res/"], // path for post-operation files
  modelDim = 2, // default model dimension (2D)
  Flag_PlaneStress = 0, // plain stress in 2D?
  Flag_Regime = 0, // static (0), harmonic (1), time-domain (2), modal (3)
  Freq = 1, // frequency (for harmonic simulations)
  Freq_Target = 1, // frequency target (for modal simulations)
  Num_Modes = 10, // number of modes (for modal simulations)
  TimeInit = 0, // intial time (for time-domain simulations)
  TimeFinal = 1/50, // final time (for time-domain simulations)
  DeltaTime = 1/500, // time step (for time-domain simulations)
  Flag_Axi = 0, // axisymmetric model?
  FE_Order = 1 // finite element order
];

Group {
  DefineGroup[
    // Full elastic domain:
    Vol_Mec,

    // Subsets of Vol_Mec:
    Vol_F_Mec, // region with imposed force

    // Boundaries:
    Sur_Neu_Mec // surfaces with Neumann boundary conditions (pressure)
  ];
  Dom_Mec = Region[ {Vol_Mec, Sur_Neu_Mec} ];
}

Function{
  DefineFunction[
    E, // Young modulus (in Vol_Mec)
    nu, // Poisson coefficient (in Vol_Mec)
    rho, // mass density (in Vol_Mec)
    f, // force per unit volume (in Vol_Force_Mec)
    sigman // traction (on Sur_Neu_Mec)
  ];
}

// End of definitions.

Jacobian {
  { Name Vol;
    Case {
      If(Flag_Axi && modelDim < 3)
        { Region All; Jacobian VolAxiSqu; }
      Else
        { Region All; Jacobian Vol; }
      EndIf
    }
  }
  { Name Sur;
    Case {
      If(Flag_Axi && modelDim < 3)
        { Region All; Jacobian SurAxi; }
      Else
        { Region All; Jacobian Sur; }
      EndIf
    }
  }
}

Integration {
  { Name Int;
    Case {
      { Type Gauss;
        Case {
          { GeoElement Point; NumberOfPoints 1; }
          { GeoElement Line; NumberOfPoints 3; }
          { GeoElement Triangle; NumberOfPoints 3; }
          { GeoElement Quadrangle; NumberOfPoints 4; }
          { GeoElement Tetrahedron; NumberOfPoints 4; }
          { GeoElement Hexahedron; NumberOfPoints 6; }
          { GeoElement Prism; NumberOfPoints 9; }
          { GeoElement Pyramid; NumberOfPoints 8; }
	}
      }
    }
  }
}

Function {
  If(Flag_PlaneStress) // plane stress (EPC)
    a[] = E[]/(1.-nu[]^2);
    c[] = E[]*nu[]/(1.-nu[]^2);
  Else // plane strain (EPD) or 3D
    a[] = E[]*(1.-nu[])/(1.+nu[])/(1.-2.*nu[]);
    c[] = E[]*nu[]/(1.+nu[])/(1.-2.*nu[]);
  EndIf
  b[] = E[]/2./(1.+nu[]); // = mu = G

  C_xx[] = Tensor[ a[],0  ,0  ,    0  ,b[],0  ,    0  ,0  ,b[] ];
  C_xy[] = Tensor[ 0  ,c[],0  ,    b[],0  ,0  ,    0  ,0  ,0   ];
  C_xz[] = Tensor[ 0  ,0  ,c[],    0  ,0  ,0  ,    b[],0  ,0   ];

  C_yx[] = Tensor[ 0  ,b[],0  ,    c[],0  ,0  ,    0  ,0  ,0   ];
  C_yy[] = Tensor[ b[],0  ,0  ,    0  ,a[],0  ,    0  ,0  ,b[] ];
  C_yz[] = Tensor[ 0  ,0  ,0  ,    0  ,0  ,c[],    0  ,b[],0   ];

  C_zx[] = Tensor[ 0  ,0  ,b[],    0  ,0  ,0  ,    c[],0  ,0   ];
  C_zy[] = Tensor[ 0  ,0  ,0  ,    0  ,0  ,b[],    0  ,c[],0   ];
  C_zz[] = Tensor[ b[],0  ,0  ,    0  ,b[],0  ,    0  ,0  ,a[] ];
}

FunctionSpace {
  { Name H_ux_Mec; Type Form0;
    BasisFunction {
      { Name sxn; NameOfCoef uxn; Function BF_Node;
        Support Dom_Mec; Entity NodesOf[ All ]; }
      If(FE_Order == 2)
        { Name sxn2; NameOfCoef uxn2; Function BF_Node_2E;
          Support Dom_Mec; Entity EdgesOf[ All ]; }
      EndIf
    }
    Constraint {
      { NameOfCoef uxn; EntityType NodesOf; NameOfConstraint Displacement_x; }
      If(FE_Order == 2)
        { NameOfCoef uxn2; EntityType EdgesOf; NameOfConstraint Displacement_x; }
      EndIf
    }
  }
  { Name H_uy_Mec; Type Form0;
    BasisFunction {
      { Name syn; NameOfCoef uyn; Function BF_Node;
        Support Dom_Mec; Entity NodesOf[ All ]; }
      If(FE_Order == 2)
        { Name syn2; NameOfCoef uyn2; Function BF_Node_2E;
          Support Dom_Mec; Entity EdgesOf[ All ]; }
      EndIf
    }
    Constraint {
      { NameOfCoef uyn; EntityType NodesOf; NameOfConstraint Displacement_y; }
      If(FE_Order == 2)
        { NameOfCoef uyn2; EntityType EdgesOf; NameOfConstraint Displacement_y; }
      EndIf
    }
  }
  { Name H_uz_Mec; Type Form0;
    BasisFunction {
      { Name syn; NameOfCoef uzn; Function BF_Node;
        Support Dom_Mec; Entity NodesOf[ All ]; }
      If(FE_Order == 2)
        { Name szn2; NameOfCoef uzn2; Function BF_Node_2E;
          Support Dom_Mec; Entity EdgesOf[ All ]; }
      EndIf
    }
    Constraint {
      { NameOfCoef uzn; EntityType NodesOf; NameOfConstraint Displacement_z; }
      If(FE_Order == 2)
        { NameOfCoef uzn2; EntityType EdgesOf; NameOfConstraint Displacement_z; }
      EndIf
    }
  }
}

Formulation {
  { Name Elasticity_u; Type FemEquation;
    Quantity {
      { Name ux; Type Local; NameOfSpace H_ux_Mec; }
      { Name uy; Type Local; NameOfSpace H_uy_Mec; }
      If(modelDim == 3)
        { Name uz; Type Local; NameOfSpace H_uz_Mec; }
      EndIf
    }
    Equation {
      Integral { [ -C_xx[] * Dof{d ux}, {d ux} ];
        In Vol_Mec; Jacobian Vol; Integration Int; }
      Integral { [ -C_xy[] * Dof{d uy}, {d ux} ];
        In Vol_Mec; Jacobian Vol; Integration Int; }
      If(modelDim == 3)
        Integral { [ -C_xz[] * Dof{d uz}, {d ux} ];
          In Vol_Mec; Jacobian Vol; Integration Int; }
      EndIf

      Integral { [ -C_yx[] * Dof{d ux}, {d uy} ];
        In Vol_Mec; Jacobian Vol; Integration Int; }
      Integral { [ -C_yy[] * Dof{d uy}, {d uy} ];
        In Vol_Mec; Jacobian Vol; Integration Int; }
      If(modelDim == 3)
        Integral { [ -C_yz[] * Dof{d uz}, {d uy} ];
          In Vol_Mec; Jacobian Vol; Integration Int; }
      EndIf

      If(modelDim == 3)
        Integral { [ -C_zx[] * Dof{d ux}, {d uz} ];
          In Vol_Mec; Jacobian Vol; Integration Int; }
        Integral { [ -C_zy[] * Dof{d uy}, {d uz} ];
          In Vol_Mec; Jacobian Vol; Integration Int; }
        Integral { [ -C_zz[] * Dof{d uz}, {d uz} ];
          In Vol_Mec; Jacobian Vol; Integration Int; }
      EndIf

      If(Flag_Regime)
        Integral { DtDtDof [ -rho[] * Dof{ux} , {ux} ];
          In Vol_Mec ; Jacobian Vol ; Integration Int ; }
        Integral { DtDtDof [ -rho[] * Dof{uy} , {uy} ];
          In Vol_Mec ; Jacobian Vol ; Integration Int ; }
        If(modelDim == 3)
          Integral { DtDtDof [ -rho[] * Dof{uz} , {uz} ];
            In Vol_Mec ; Jacobian Vol ; Integration Int ; }
        EndIf
      EndIf

      If(Flag_Regime != 3)
        Integral { [ CompX[f[]] , {ux} ];
          In Vol_F_Mec; Jacobian Vol; Integration Int; }
        Integral { [ CompY[f[]] , {uy} ];
          In Vol_F_Mec; Jacobian Vol; Integration Int; }
        If(modelDim == 3)
          Integral { [ CompZ[f[]] , {uy} ];
            In Vol_F_Mec; Jacobian Vol; Integration Int; }
        EndIf

        Integral { [ CompX[sigman[]] , {ux} ];
          In Sur_Neu_Mec; Jacobian Sur; Integration Int; }
        Integral { [ CompY[sigman[]] , {uy} ];
          In Sur_Neu_Mec; Jacobian Sur; Integration Int; }
        If(modelDim == 3)
          Integral { [ CompZ[sigman[]] , {uz} ];
            In Sur_Neu_Mec; Jacobian Sur; Integration Int; }
        EndIf
      EndIf
    }
  }
}

Resolution {
  { Name Elasticity_u;
    System {
      { Name A; NameOfFormulation Elasticity_u;
        If(Flag_Regime == 1)
          Type Complex; Frequency Freq;
        EndIf
      }
    }
    Operation {
      If(Flag_Regime == 0 || Flag_Regime == 1)
        Generate[A]; Solve[A]; SaveSolution[A];
      ElseIf(Flag_Regime == 2)
        InitSolution[A]; InitSolution[A] ;
        TimeLoopNewmark[TimeInit, TimeFinal, DeltaTime, 1/4, 1/2] {
          Generate[A]; Solve[A]; SaveSolution[A];
        }
      Else
        GenerateSeparate[A]; EigenSolve[A, Num_Modes, (2*Pi*Freq_Target)^2, 0];
        SaveSolutions[A];
      EndIf
    }
  }
}

PostProcessing {
  { Name Elasticity_u; NameOfFormulation Elasticity_u;
    PostQuantity {
      { Name u; Value {
          If(modelDim == 3)
            Term { [ Vector[ {ux}, {uy}, {uz} ]]; In Vol_Mec; Jacobian Vol; }
          Else
            Term { [ Vector[ {ux}, {uy}, 0 ]]; In Vol_Mec; Jacobian Vol; }
          EndIf
        }
      }
      { Name sigma; Value {
          If(modelDim == 3)
            Term { [ TensorV[ C_xx[]*{d ux} + C_xy[]*{d uy} + C_xz[]*{d uz},
                              C_yx[]*{d ux} + C_yy[]*{d uy} + C_yz[]*{d uz},
                              C_zx[]*{d ux} + C_zy[]*{d uy} + C_zz[]*{d uz} ] ];
              In Vol_Mec; Jacobian Vol; }
          Else
            Term { [ TensorV[ C_xx[]*{d ux} + C_xy[]*{d uy},
                              C_yx[]*{d ux} + C_yy[]*{d uy},
                              Vector[0,0,0]] ];
              In Vol_Mec; Jacobian Vol; }
          EndIf
          }
      }
    }
  }
}

PostOperation {
  { Name Elasticity_u; NameOfPostProcessing Elasticity_u;
    Operation {
      CreateDir[resPath];
      Print[ sigma, OnElementsOf Vol_Mec, File StrCat[resPath, "sigma.pos"] ];
      Print[ u, OnElementsOf Vol_Mec, File StrCat[resPath, "u.pos"] ];
    }
  }
}