-
Notifications
You must be signed in to change notification settings - Fork 10
/
KirchhoffLove.C
403 lines (319 loc) · 9.1 KB
/
KirchhoffLove.C
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
// $Id$
//==============================================================================
//!
//! \file KirchhoffLove.C
//!
//! \date Sep 13 2011
//!
//! \author Knut Morten Okstad / SINTEF
//!
//! \brief Base class for linear Kirchhoff-Love thin plate and shell problems.
//!
//==============================================================================
#include "KirchhoffLove.h"
#include "MaterialBase.h"
#include "FiniteElement.h"
#include "NewmarkMats.h"
#include "TimeDomain.h"
#include "Function.h"
#include "Utilities.h"
#include "Vec3Oper.h"
#include "Tensor.h"
#include "VTF.h"
#include "tinyxml2.h"
KirchhoffLove::KirchhoffLove (unsigned short int n, bool m) : IntegrandBase(n)
{
npv = nsd < 3 ? 1 : 3; // Number of primary unknowns per node
gravity = 0.0;
thickness = 0.1;
material = nullptr;
fluxFld = nullptr;
tracFld = nullptr;
linLoad = nullptr;
locSys = nullptr;
eK = eM = 0;
eS = gS = iS = 0;
includeShear = true;
isModal = m;
memset(intPrm,0,sizeof(intPrm));
}
KirchhoffLove::~KirchhoffLove ()
{
if (locSys) delete locSys;
}
bool KirchhoffLove::parse (const tinyxml2::XMLElement* elem)
{
if (!strcasecmp(elem->Value(),"noshear"))
includeShear = false;
else if (!strcasecmp(elem->Value(),"withshear"))
includeShear = true;
else
return false;
return true;
}
void KirchhoffLove::setMode (SIM::SolutionMode mode)
{
m_mode = isModal && mode == SIM::DYNAMIC ? SIM::RHS_ONLY : mode;
eM = eK = 0;
eS = gS = iS = 0;
if (m_mode == SIM::DYNAMIC)
primsol.resize(3);
else if (m_mode >= SIM::RHS_ONLY)
primsol.resize(1);
else
primsol.clear();
switch (m_mode)
{
case SIM::ARCLEN:
gS = 2;
case SIM::STATIC:
eK = 1;
eS = 1;
break;
case SIM::DYNAMIC:
eK = 3;
eM = 2;
eS = iS = 1;
break;
case SIM::VIBRATION:
eM = 2;
case SIM::STIFF_ONLY:
eK = 1;
break;
case SIM::MASS_ONLY:
eM = 1;
eS = 1;
break;
case SIM::RHS_ONLY:
eS = 1;
case SIM::INT_FORCES:
iS = 1;
break;
default:
;
}
}
void KirchhoffLove::setIntegrationPrm (unsigned short int i, double prm)
{
if (i < sizeof(intPrm)/sizeof(double)) intPrm[i] = prm;
}
double KirchhoffLove::getIntegrationPrm (unsigned short int i) const
{
return i < sizeof(intPrm)/sizeof(double) ? intPrm[i] : 0.0;
}
void KirchhoffLove::setPressure (RealFunc* pf)
{
if (pf)
presFld.push_back(pf);
else
presFld.clear();
}
int KirchhoffLove::getIntegrandType () const
{
int itg_type = SECOND_DERIVATIVES;
if (m_mode == SIM::RECOVERY && includeShear)
itg_type |= THIRD_DERIVATIVES;
if (linLoad)
itg_type |= INTERFACE_TERMS;
return itg_type;
}
void KirchhoffLove::initIntegration (size_t nGp, size_t nBp)
{
presVal.clear();
if (this->haveLoads('I'))
presVal.resize(nGp,std::make_pair(Vec3(),Vec3()));
tracVal.clear();
if (this->haveLoads('B'))
tracVal.resize(nBp,std::make_pair(Vec3(),Vec3()));
}
LocalIntegral* KirchhoffLove::getLocalIntegral (size_t nen, size_t iEl,
bool neumann) const
{
ElmMats* result = nullptr;
if (this->inActive(iEl))
return result; // element is not in current material group
if (m_mode == SIM::DYNAMIC && !isModal)
result = new NewmarkMats(intPrm[0],intPrm[1],intPrm[2],intPrm[3]);
else
result = new ElmMats();
switch (m_mode)
{
case SIM::STATIC:
case SIM::ARCLEN:
case SIM::MASS_ONLY:
result->rhsOnly = neumann;
result->withLHS = !neumann;
result->resize(neumann ? 0 : 1, m_mode==SIM::MASS_ONLY ? 1 : m_mode, npv);
break;
case SIM::DYNAMIC:
result->rhsOnly = neumann;
result->withLHS = !neumann;
result->resize(neumann ? 0 : (intPrm[3] >= 0.0 ? 3 : 4),
neumann || intPrm[3] > 0.0 ? 1 : 2, nsd);
break;
case SIM::VIBRATION:
result->resize(2,0);
break;
case SIM::STIFF_ONLY:
result->resize(1,0);
break;
case SIM::RHS_ONLY:
result->resize(neumann ? 0 : 1, 1, npv);
case SIM::RECOVERY:
result->rhsOnly = true;
result->withLHS = false;
break;
default:
;
}
result->redim(npv*nen);
return result;
}
Vec3 KirchhoffLove::getTraction (const Vec3& X, const Vec3& n, bool grd) const
{
if (fluxFld)
return grd ? fluxFld->timeDerivative(X) : (*fluxFld)(X);
else if (tracFld)
return grd ? tracFld->timeDerivative(X,n) : (*tracFld)(X,n);
else
return Vec3();
}
Vec3 KirchhoffLove::getPressure (const Vec3& X, const Vec3& n, bool grd) const
{
Vec3 p;
if (!grd)
p.z = material->getMassDensity(X)*gravity*thickness;
for (RealFunc* pf : presFld)
if (n.isZero()) // Assume pressure acts in global Z-direction
p.z += grd ? pf->timeDerivative(X) : (*pf)(X);
else
p += (grd ? pf->timeDerivative(X) : (*pf)(X))*n;
return p;
}
Vec3 KirchhoffLove::getLineLoad (const Vec3& X, const Vec3& n, bool grd) const
{
if (!linLoad)
return Vec3();
else if (n.isZero()) // Assume load acts in global Z-direction
return Vec3(0.0, 0.0, grd ? linLoad->timeDerivative(X) : (*linLoad)(X));
else
return (grd ? linLoad->timeDerivative(X) : (*linLoad)(X))*n;
}
bool KirchhoffLove::haveLoads (char type) const
{
if (type == 'A' || type == 'I')
{
if (!presFld.empty() || linLoad)
return true;
if (gravity != 0.0 && material)
if (material->getMassDensity(Vec3()) != 0.0)
return true;
}
if (type == 'A' || type == 'B')
if (fluxFld || tracFld)
return true;
return false;
}
void KirchhoffLove::formBodyForce (Vector& ES, RealArray& sumLoad,
const Vector& N, size_t iP,
const Vec3& X, const Vec3& n,
double detJW, bool grd) const
{
Vec3 p = this->getPressure(X,n,grd);
if (p.isZero()) return;
if (npv == 1)
ES.add(N,p.z*detJW);
else for (size_t a = 1; a <= N.size(); a++)
for (unsigned short int i = 1; i <= npv; i++)
ES(npv*(a-1)+i) += N(a)*p(i)*detJW;
if (grd) return;
// Integrate total external load
if (npv == 1 && !sumLoad.empty())
sumLoad.front() += p.z*detJW;
else for (unsigned short int i = 0; i < npv && i < sumLoad.size(); i++)
sumLoad[i] += p[i]*detJW;
// Store pressure value for visualization
if (iP < presVal.size())
presVal[iP] = std::make_pair(X,p);
}
void KirchhoffLove::formMassMatrix (Matrix& EM, const Vector& N,
const Vec3& X, double detJW) const
{
double rhow = material->getMassDensity(X)*thickness*detJW;
if (rhow == 0.0) return;
if (npv == 1)
EM.outer_product(N,N*rhow,true);
else
for (size_t a = 1; a <= N.size(); a++)
for (size_t b = 1; b <= N.size(); b++)
for (unsigned short int i = 1; i <= npv; i++)
EM(npv*(a-1)+i,npv*(b-1)+i) += rhow*N(a)*N(b);
}
bool KirchhoffLove::hasTractionValues () const
{
return !tracVal.empty() || !presVal.empty();
}
bool KirchhoffLove::writeGlvT (VTF* vtf, int iStep,
int& geoBlk, int& nBlock) const
{
if (tracVal.empty() && presVal.empty())
return true;
else if (!vtf)
return false;
if (!tracVal.empty())
// Write boundary tractions as discrete point vectors to the VTF-file
return vtf->writeVectors(tracVal,geoBlk,++nBlock,"Tractions",iStep);
else
// Write surface pressures as discrete point vectors to the VTF-file
return vtf->writeVectors(presVal,geoBlk,++nBlock,"Pressure",iStep);
}
bool KirchhoffLove::evalSol (Vector& s,
const FiniteElement& fe, const Vec3& X,
const std::vector<int>& MNPC) const
{
// Extract element displacements
Vectors eV(primsol.size());
for (size_t i = 0; i < primsol.size(); i++)
if (!primsol[i].empty())
{
int ierr = utl::gather(MNPC,npv,primsol[i],eV[i]);
if (ierr > 0)
{
std::cerr <<" *** KirchhoffLove::evalSol: Detected "
<< ierr <<" node numbers out of range."<< std::endl;
return false;
}
}
// Evaluate the stress resultants
return this->evalSol(s,eV,fe,X,true);
}
bool KirchhoffLove::evalPoint (LocalIntegral& elmInt, const FiniteElement& fe,
const Vec3& pval)
{
if (!eS)
{
std::cerr <<" *** KirchhoffLove::evalPoint: No load vector."<< std::endl;
return false;
}
Vector& ES = static_cast<ElmMats&>(elmInt).b[eS-1];
if (npv == 1)
ES.add(fe.N,pval.x*fe.detJxW);
else for (size_t a = 1; a <= fe.N.size(); a++)
for (unsigned short int i = 1; i <= npv; i++)
ES(npv*(a-1)+i) += pval(i)*fe.N(a)*fe.detJxW;
if (eS == 1)
{
RealArray& sumLoad = static_cast<ElmMats&>(elmInt).c;
if (npv == 1 && !sumLoad.empty())
sumLoad.front() += pval.x*fe.detJxW;
else for (unsigned short int i = 0; i < npv && i < sumLoad.size(); i++)
sumLoad[i] += pval[i]*fe.detJxW;
}
return true;
}
bool KirchhoffLove::finalizeElement (LocalIntegral& elmInt,
const TimeDomain& time, size_t)
{
static_cast<ElmMats&>(elmInt).setStepSize(time.dt,time.it);
return true;
}