-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgsElasticityFunctions.hpp
289 lines (265 loc) · 11.6 KB
/
gsElasticityFunctions.hpp
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
/** @file gsElasticityFunctions.hpp
@brief Provides useful classes derived from gsFunction which can be used
for visualization or coupling.
This file is part of the G+Smo library.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
Author(s):
A.Shamanskiy (2016 - ...., TU Kaiserslautern)
*/
#pragma once
#include <gsElasticity/gsElasticityFunctions.h>
#include <gsCore/gsFuncData.h>
#include <gsAssembler/gsAssembler.h>
namespace gismo
{
template <class T>
void gsCauchyStressFunction<T>::linearElastic(const gsMatrix<T> & u, gsMatrix<T> & result) const
{
result.setZero(targetDim(),outputCols(u.cols()));
// evaluating the fields
gsMapData<T> mdGeo(NEED_GRAD_TRANSFORM);
mdGeo.points = u;
m_geometry->patch(m_patch).computeMap(mdGeo);
gsMapData<T> mdDisp(NEED_DERIV);
mdDisp.points = u;
m_displacement->patch(m_patch).computeMap(mdDisp);
// define temporary matrices here for efficieny
gsMatrix<T> I = gsMatrix<T>::Identity(m_dim,m_dim);
gsMatrix<T> sigma,eps,dispGrad;
// material parameters
T YM = m_options.getReal("YoungsModulus");
T PR = m_options.getReal("PoissonsRatio");
T lambda = YM * PR / ( ( 1. + PR ) * ( 1. - 2. * PR ) );
T mu = YM / ( 2. * ( 1. + PR ) );
for (index_t q = 0; q < u.cols(); ++q)
{
// linear strain tensor eps = (gradU+gradU^T)/2
if (mdGeo.jacobian(q).determinant() <= 0)
gsInfo << "Invalid domain parametrization: J = " << mdGeo.jacobian(q).determinant() <<
" at point (" << u.col(q).transpose() << ") of patch " << m_patch << std::endl;
if (abs(mdGeo.jacobian(q).determinant()) > 1e-20)
dispGrad = mdDisp.jacobian(q)*(mdGeo.jacobian(q).cramerInverse());
else
dispGrad = gsMatrix<T>::Zero(m_dim,m_dim);
eps = (dispGrad + dispGrad.transpose())/2;
// Cauchy stress tensor
sigma = lambda*eps.trace()*I + 2*mu*eps;
saveStress(sigma,result,q);
}
}
template <class T>
void gsCauchyStressFunction<T>::nonLinearElastic(const gsMatrix<T> & u, gsMatrix<T> & result) const
{
result.setZero(targetDim(),outputCols(u.cols()));
// evaluating the fields
gsMapData<T> mdGeo(NEED_GRAD_TRANSFORM);
mdGeo.points = u;
m_geometry->patch(m_patch).computeMap(mdGeo);
gsMapData<T> mdDisp(NEED_DERIV);
mdDisp.points = u;
m_displacement->patch(m_patch).computeMap(mdDisp);
// define temporary matrices here for efficieny
gsMatrix<T> I = gsMatrix<T>::Identity(m_dim,m_dim);
gsMatrix<T> S,sigma,F,C,E;
// material parameters
T YM = m_options.getReal("YoungsModulus");
T PR = m_options.getReal("PoissonsRatio");
T lambda = YM * PR / ( ( 1. + PR ) * ( 1. - 2. * PR ) );
T mu = YM / ( 2. * ( 1. + PR ) );
for (index_t q = 0; q < u.cols(); ++q)
{
// deformation gradient F = I + gradU*gradGeo^-1
if (mdGeo.jacobian(q).determinant() <= 0)
gsInfo << "Invalid domain parametrization: J = " << mdGeo.jacobian(q).determinant() <<
" at point (" << u.col(q).transpose() << ") of patch " << m_patch << std::endl;
if (abs(mdGeo.jacobian(q).determinant()) > 1e-20)
F = I + mdDisp.jacobian(q)*(mdGeo.jacobian(q).cramerInverse());
else
F = I;
T J = F.determinant();
if (J <= 0)
gsInfo << "Invalid displacement field: J = " << J <<
" at point (" << u.col(q).transpose() << ") of patch " << m_patch << std::endl;
// Second Piola-Kirchhoff stress tensor
if (material_law::law(m_options.getInt("MaterialLaw")) == material_law::saint_venant_kirchhoff)
{
// Green-Lagrange strain tensor E = 0.5(F^T*F-I)
E = (F.transpose() * F - I)/2;
S = lambda*E.trace()*I + 2*mu*E;
}
if (material_law::law(m_options.getInt("MaterialLaw")) == material_law::neo_hooke_ln)
{
// Right Cauchy Green strain, C = F'*F
C = F.transpose() * F;
S = (lambda*log(J)-mu)*(C.cramerInverse()) + mu*I;
}
if (material_law::law(m_options.getInt("MaterialLaw")) == material_law::neo_hooke_quad)
{
// Right Cauchy Green strain, C = F'*F
C = F.transpose() * F;
S = (lambda*(J*J-1)/2-mu)*(C.cramerInverse()) + mu*I;
}
// transformation to Cauchy stress
sigma = F*S*F.transpose()/J;
saveStress(sigma,result,q);
}
}
template <class T>
void gsCauchyStressFunction<T>::mixedLinearElastic(const gsMatrix<T> & u, gsMatrix<T> & result) const
{
result.setZero(targetDim(),outputCols(u.cols()));
// evaluating the fields
gsMapData<T> mdGeo(NEED_GRAD_TRANSFORM);
mdGeo.points = u;
m_geometry->patch(m_patch).computeMap(mdGeo);
gsMapData<T> mdDisp(NEED_DERIV);
mdDisp.points = u;
m_displacement->patch(m_patch).computeMap(mdDisp);
gsMatrix<T> presVals;
m_pressure->patch(m_patch).eval_into(u,presVals);
// define temporary matrices here for efficieny
gsMatrix<T> I = gsMatrix<T>::Identity(m_dim,m_dim);
gsMatrix<T> sigma,eps,dispGrad;
// material parameters
T YM = m_options.getReal("YoungsModulus");
T PR = m_options.getReal("PoissonsRatio");
T mu = YM / ( 2. * ( 1. + PR ) );
for (index_t q = 0; q < u.cols(); ++q)
{
// linear strain tensor eps = (gradU+gradU^T)/2
if (mdGeo.jacobian(q).determinant() <= 0)
gsInfo << "Invalid domain parametrization: J = " << mdGeo.jacobian(q).determinant() <<
" at point (" << u.col(q).transpose() << ") of patch " << m_patch << std::endl;
if (abs(mdGeo.jacobian(q).determinant()) > 1e-20)
dispGrad = mdDisp.jacobian(q)*(mdGeo.jacobian(q).cramerInverse());
else
dispGrad = gsMatrix<T>::Zero(m_dim,m_dim);
eps = (dispGrad + dispGrad.transpose())/2;
// Cauchy stress tensor
sigma = presVals.at(q)*I + 2*mu*eps;
saveStress(sigma,result,q);
}
}
template <class T>
void gsCauchyStressFunction<T>::mixedNonLinearElastic(const gsMatrix<T> & u, gsMatrix<T> & result) const
{
result.setZero(targetDim(),outputCols(u.cols()));
// evaluating the fields
gsMapData<T> mdGeo(NEED_GRAD_TRANSFORM);
mdGeo.points = u;
m_geometry->patch(m_patch).computeMap(mdGeo);
gsMapData<T> mdDisp(NEED_DERIV);
mdDisp.points = u;
m_displacement->patch(m_patch).computeMap(mdDisp);
gsMatrix<T> presVals;
m_pressure->patch(m_patch).eval_into(u,presVals);
// define temporary matrices here for efficieny
gsMatrix<T> I = gsMatrix<T>::Identity(m_dim,m_dim);
gsMatrix<T> S,sigma,F,C,E;
// material parameters
T YM = m_options.getReal("YoungsModulus");
T PR = m_options.getReal("PoissonsRatio");
T mu = YM / ( 2. * ( 1. + PR ) );
for (index_t q = 0; q < u.cols(); ++q)
{
if (mdGeo.jacobian(q).determinant() <= 0)
gsInfo << "Invalid domain parametrization: J = " << mdGeo.jacobian(q).determinant() <<
" at point (" << u.col(q).transpose() << ") of patch " << m_patch << std::endl;
// deformation gradient F = I + gradU*gradGeo^-1
if (abs(mdGeo.jacobian(q).determinant()) > 1e-20)
F = I + mdDisp.jacobian(q)*(mdGeo.jacobian(q).cramerInverse());
else
F = I;
T J = F.determinant();
if (J <= 0)
gsInfo << "Invalid displacement field: J = " << J <<
" at point (" << u.col(q).transpose() << ") of patch " << m_patch << std::endl;
// Second Piola-Kirchhoff stress tensor
C = F.transpose() * F;
S = (presVals.at(q)-mu)*(C.cramerInverse()) + mu*I;
// transformation to Cauchy stress
sigma = F*S*F.transpose()/J;
saveStress(sigma,result,q);
}
}
template <class T>
void gsCauchyStressFunction<T>::saveStress(const gsMatrix<T> & S, gsMatrix<T> & result, index_t q) const
{
switch (m_type)
{
case stress_components::von_mises :
{
if (m_geometry->parDim() == 2)
result(0,q) = sqrt( S(0,0)*S(0,0) + S(1,1)*S(1,1) - S(0,0)*S(1,1) + 3*S(0,1)*S(0,1) );
if (m_geometry->parDim() == 3)
result(0,q) = sqrt(0.5*( pow(S(0,0)-S(1,1),2) + pow(S(0,0)-S(2,2),2) + pow(S(1,1)-S(2,2),2) +
6 * (pow(S(0,1),2) + pow(S(0,2),2) + pow(S(1,2),2) ) ) );
return;
}
case stress_components::all_2D_vector : result(0,q) = S(0,0); result(1,q) = S(1,1); result(2,q) = S(0,1); return;
case stress_components::all_2D_matrix : result.middleCols(q*2,2) = S; return;
case stress_components::normal_3D_vector : result(0,q) = S(0,0); result(1,q) = S(1,1); result(2,q) = S(2,2); return;
case stress_components::shear_3D_vector : result(0,q) = S(0,1); result(1,q) = S(0,2); result(2,q) = S(1,2); return;
case stress_components::all_3D_matrix : result.middleCols(q*3,3) = S; return;
}
}
template <class T>
void gsDetFunction<T>::eval_into(const gsMatrix<T> & u, gsMatrix<T> & result) const
{
result.resize(1,u.cols());
gsMapData<T> mappingData;
mappingData.points = u;
mappingData.flags = NEED_DERIV;
m_geo.patch(m_patch).computeMap(mappingData);
for (index_t i = 0; i < u.cols(); ++i)
result(0,i) = mappingData.jacobian(i).determinant();
}
template <class T>
void gsFsiLoad<T>::eval_into(const gsMatrix<T> & u, gsMatrix<T> & result) const
{
result.setZero(targetDim(),u.cols());
// mapping points back to the parameter space via the reference configuration
gsMatrix<T> paramPoints;
m_geo.patch(m_patchGeo).invertPoints(u,paramPoints);
// evaluate reference geometry mapping at the param points
// NEED_GRAD_TRANSFORM for velocity gradients transformation from parametric to reference domain
gsMapData<T> mdGeo(NEED_GRAD_TRANSFORM);
mdGeo.points = paramPoints;
m_geo.patch(m_patchGeo).computeMap(mdGeo);
// evaluate velocity at the param points
// NEED_DERIV for velocity gradients
gsMapData<T> mdVel(NEED_DERIV);
mdVel.points = paramPoints;
m_vel.patch(m_patchVP).computeMap(mdVel);
// evaluate pressure at the quad points
gsMatrix<T> pressureValues;
m_pres.patch(m_patchVP).eval_into(paramPoints,pressureValues);
// evaluate ALE dispacement at the param points
// NEED_DERIV for gradients
gsMapData<T> mdALE(NEED_DERIV);
mdALE.points = paramPoints;
m_ale.patch(m_patchGeo).computeMap(mdALE);
gsMatrix<T> I = gsMatrix<T>::Identity(targetDim(),targetDim());
for (index_t p = 0; p < paramPoints.cols(); ++p)
{
// transform velocity gradients from parametric to reference
gsMatrix<T> physGradVel = mdVel.jacobian(p)*(mdGeo.jacobian(p).cramerInverse());
// ALE jacobian (identity + physical displacement gradient)
gsMatrix<T> physJacALE = I + mdALE.jacobian(p)*(mdGeo.jacobian(p).cramerInverse());
// inverse ALE jacobian
gsMatrix<T> invJacALE = physJacALE.cramerInverse();
// ALE stress tensor
gsMatrix<T> sigma = pressureValues.at(p)*I
- m_density*m_viscosity*(physGradVel*invJacALE +
invJacALE.transpose()*physGradVel.transpose());
// stress tensor pull back
gsMatrix<T> sigmaALE = physJacALE.determinant()*sigma*(invJacALE.transpose());
// normal length is the local measure
gsVector<T> normal;
outerNormal(mdGeo,p,m_sideGeo,normal);
result.col(p) = sigmaALE * normal / normal.norm();
}
}
} // namespace gismo ends