forked from claudioperez/GeometricTransformations
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExactFrame3d.h
More file actions
542 lines (451 loc) · 12.8 KB
/
Copy pathExactFrame3d.h
File metadata and controls
542 lines (451 loc) · 12.8 KB
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
//===----------------------------------------------------------------------===//
//
// OpenSees - Open System for Earthquake Engineering Simulation
//
//===----------------------------------------------------------------------===//
//
// Claudio M. Perez
//
#include <vector>
#include <array>
#include <Flag.h>
#include <Element.h>
#include <VectorND.h>
#include <MatrixND.h>
#include <Frame/FrameMass.hpp>
#include <FrameSection.h>
#include <FrameTransform.h>
#include <Frame/FiniteElement.h>
#include <Rotations.hpp>
//#include <BeamIntegration.h>
using OpenSees::VectorND; using OpenSees::MatrixND;
template<int nen, int nip>
class ExactFrame3d:
public FiniteElement<nen, 3, 6>
{
public:
ExactFrame3d(int tag, std::array<int,nen>& nodes,
FrameSection *section[nip],
FrameTransform3d& transf
// int mass_type
);
~ExactFrame3d();
const char*
getClassType() const final
{
return "ExactFrame3d";
}
virtual int setNodes();
virtual const Vector &getResistingForce();
virtual const Matrix &getTangentStiff();
virtual const Matrix &getMass();
virtual const Matrix &getInitialStiff();
virtual int update() final;
virtual int revertToStart();
virtual int revertToLastCommit();
virtual int commitState() final {
if (this->Element::commitState() != 0)
opserr << "ExactFrame3d::commitState () - failed in base class";
past = points;
for (GaussPoint& point : points) {
if (point.material->commitState() != 0)
return -1;
}
return OpenSees::Flag::Success;
}
// MovableObject
int sendSelf(int cTag, Channel&);
int recvSelf(int cTag, Channel&, FEM_ObjectBroker&);
// TaggedObject
void Print(OPS_Stream& s, int flag = 0);
private:
//
// Constexpr
//
constexpr static int
nsr = 6, // Number of section resultants
ndm = 3, // Dimension of the problem (3D)
ndf = 6; // Degrees of freedom per node
// Layout of stress resultants
static constexpr FrameStressLayout scheme = {
FrameStress::N,
FrameStress::Vy,
FrameStress::Vz,
FrameStress::T,
FrameStress::My,
FrameStress::Mz,
};
//
//
//
struct GaussPoint {
double point,
weight;
FrameSection* material;
double shape[2][nen];
Matrix3D rotation;
Vector3D curvature;
};
std::array<GaussPoint,nip> points;
std::array<GaussPoint,nip> past;
BeamIntegration* stencil;
FrameTransform3d* transform;
//
//
VectorND<nen*ndf> p;
MatrixND<nen*ndf,nen*ndf> K;
};
//
//===----------------------------------------------------------------------===//
//
// Please cite the following resource in any derivative works:
// https://doi.org/10.5281/zenodo.10456866
//
//===----------------------------------------------------------------------===//
//
// [1] Simo J.C. (1985): A finite strain beam formulation. The three-dimensional
// dynamic problem. Part I.
// Computer Methods in Applied Mechanics and Engineering, 49(1):55–70.
// https://doi.org/10.1016/0045-7825(85)90050-7
//
// [2] Simo J.C., Vu-Quoc L. (1986): A three-dimensional finite-strain rod model
// Part II: Computational aspects.
// Computer Methods in Applied Mechanics and Engineering, 58(1):79–116.
// https://doi.org/10/b8wd4z
//
// [3] Perez C.M., and Filippou F.C. (2024):
// "On Nonlinear Geometric Transformations of Finite Elements"
// Int. J. Numer. Meth. Engrg.
//
//===----------------------------------------------------------------------===//
//
// Claudio M. Perez
//
// Implementation
#include <Flag.h>
#include <Node.h>
#include <Logging.h>
#include <Lagrange1D.cpp>
#include <quadrature/GaussLegendre1D.hpp>
//
template<int nen> static void
G_matrix(MatrixND<6,6> &G,
const VectorND<6>& s, const Vector3D& dx,
double shape[2][nen],
int i, int j)
{
auto sn = Hat(&s[0]);
auto sm = Hat(&s[3]);
G.assemble( sn, 0, 3, -shape[1][i]*shape[0][j]);
G.assemble( sn, 3, 0, shape[1][j]*shape[0][i]);
G.assemble( sm, 3, 3, -shape[1][i]*shape[0][j]);
G.assemble( Hat(dx)*sn, 3, 3, shape[0][i]*shape[0][j]);
}
template<int nen> static void
B_matrix(MatrixND<6,6> &B, double shape[2][nen], const Vector3D& dx, int n)
{
//
// NOTE This is the transpose of B in the paper by Perez and Filippou (2024)
//
for (int i=0; i<6; i++)
B(i,i) = shape[1][n];
//
// B(1:3, 4:end) = shape*Hat(dx);
//
B(0,3) = 0;
B(0,4) = -shape[0][n]*dx[2];
B(0,5) = shape[0][n]*dx[1];
B(1,3) = shape[0][n]*dx[2];
B(1,4) = 0;
B(1,5) = -shape[0][n]*dx[0];
B(2,3) = -shape[0][n]*dx[1];
B(2,4) = shape[0][n]*dx[0];
B(2,5) = 0;
}
template<int nen, int nip>
ExactFrame3d<nen,nip>::ExactFrame3d(int tag,
std::array<int,nen>& nodes,
FrameSection *section[nip],
FrameTransform3d& transf)
: FiniteElement<nen, 3, 6>(tag, 0, nodes),
transform(&transf),
stencil(nullptr)
{
// double wt[nip];
// double xi[nip];
// beamIntegr->getSectionLocations(numSections, L, xi);
// beamIntegr->getSectionWeights(numSections, L, wt);
p.zero();
K.zero();
for (int i=0; i<nip; i++) {
points[i].point = 0.0;
points[i].weight = 0.0;
points[i].material=section[i]->getFrameCopy(scheme);
}
}
template<int nen, int nip>
ExactFrame3d<nen,nip>::~ExactFrame3d()
{
for (GaussPoint& point : points)
if (point.material != nullptr)
delete point.material;
if (stencil != nullptr)
delete stencil;
}
template<int nen, int nip>
int
ExactFrame3d<nen,nip>::setNodes()
{
auto& theNodes = this->FiniteElement<nen,3,6>::theNodes;
if (transform->initialize(theNodes[0], theNodes[nen-1]) != 0) {
opserr << " -- Error initializing coordinate transformation\n";
return -1;
}
const Vector& xi = theNodes[ 0]->getCrds();
const Vector& xj = theNodes[nen-1]->getCrds();
double L = (xi-xj).Norm();
// Node locations in local (scalar) coordinate
double x[nen];
for (int i=0; i < nen; i++)
x[i] = i*L/(nen-1);
GaussLegendre<1, nip> gauss;
for (int i=0; i < nip; i++) {
points[i].point = (gauss.pts[i] + 1.0)*L/2.0;
points[i].weight = gauss.wts[i]*L/2.0;
lagrange<nen>(points[i].point, x, points[i].shape);
}
// Zero out the state of the Gauss points
this->revertToStart();
return 0;
}
template<int nen, int nip>
int
ExactFrame3d<nen,nip>::revertToStart()
{
// Revert the transformation to start
if (transform->revertToStart() != 0)
return -2;
Vector E1(3), E2(3), E3(3);
transform->getLocalAxes(E1, E2, E3);
Matrix3D R0;
for (int i=0; i<ndm; i++) {
R0(i, 0) = E1[i];
R0(i, 1) = E2[i];
R0(i, 2) = E3[i];
}
// Revert the of the Gauss points to start
for (GaussPoint& point : points) {
point.curvature.zero();
point.rotation = R0;
if (point.material->revertToStart() != 0)
return -1;
}
past = points;
// Revert the element state to start
// NOTE: This assumes that there are zero initial stresses?
p.zero();
K.zero();
return 0;
}
template<int nen, int nip>
int
ExactFrame3d<nen,nip>::revertToLastCommit()
{
// TODO
//opserr << "WARNING: revertToLastCommit is incomplete for this element\n";
points = past;
for (GaussPoint& point : points) {
FrameSection& section = *point.material;
if (section.revertToLastCommit() != 0)
return -1;
}
return 0;
}
template<int nen, int nip>
int
ExactFrame3d<nen,nip>::update()
{
const Vector3D D {1, 0, 0};
auto& theNodes = this->FiniteElement<nen,3,6>::theNodes;
//
// Collect nodal parameters
//
VectorND<ndf> ddu[nen];
for (int i=0; i < nen; i++) {
const Vector& ddui = theNodes[i]->getIncrDeltaDisp();
for (int j=0; j<ndf; j++)
ddu[i][j] = ddui[j];
// opserr << "ddu(" << this->getTag() << ")[" << i << "] = " << Vector(ddu[i]) << "\n";
}
// Form displaced node locations xyz
VectorND<ndm> xyz[nen];
for (int i=0; i < nen; i++) {
const Vector& xi = theNodes[i]->getCrds();
const Vector& ui = theNodes[i]->getTrialDisp();
for (int j=0; j<ndm; j++)
xyz[i][j] = xi[j] + ui[j];
}
//
// Gauss loop
//
p.zero();
K.zero();
for (int i=0; i<nip; i++) {
//
// Interpolate
//
Vector3D dx {0.0};
Vector3D theta {0.0};
Vector3D dtheta {0.0};
for (int j=0; j < nen; j++) {
for (int l=0; l<3; l++)
dx[l] += points[i].shape[1][j]*xyz[j][l];
for (int l=0; l<3; l++)
theta[l] += points[i].shape[0][j]*ddu[j][l+3];
for (int l=0; l<3; l++)
dtheta[l] += points[i].shape[1][j]*ddu[j][l+3];
}
//
//
MatrixND<3,3> dR = ExpSO3(theta);
Matrix3D R = dR*points[i].rotation;
points[i].rotation = R;
Vector3D omega = dR*points[i].curvature;
// TODO: choose 'R/L'
// points[i].curvature = omega + TanSO3(theta, 'R')*dtheta;
points[i].curvature = omega + dExpSO3(theta)*dtheta;
Vector3D gamma = (R^dx) - D;
Vector3D kappa = R^points[i].curvature;
VectorND<6> e {
gamma[0], gamma[1], gamma[2],
kappa[0], kappa[1], kappa[2],
};
FrameSection& section = *points[i].material;
section.setTrialState<nsr,scheme>(e);
VectorND<nsr> s = section.getResultant<nsr,scheme>();
MatrixND<nsr,nsr> Ks = section.getTangent<nsr,scheme>(State::Pres);
//
//
//
// A = diag(R, R);
// Note that this is transposed
MatrixND<6,6> A {{
{R(0,0), R(1,0), R(2,0), 0, 0, 0},
{R(0,1), R(1,1), R(2,1), 0, 0, 0},
{R(0,2), R(1,2), R(2,2), 0, 0, 0},
{0, 0, 0, R(0,0), R(1,0), R(2,0)},
{0, 0, 0, R(0,1), R(1,1), R(2,1)},
{0, 0, 0, R(0,2), R(1,2), R(2,2)},
}};
MatrixND<6,6> B[nen], Bj;
Bj.zero();
for (int j=0; j<nen; j++) {
B_matrix(Bj, points[i].shape, dx, j);
B[j] = A^Bj;
// p += B s w
VectorND<ndf> pj = B[j]^s;
for (int l=0; l<ndf; l++)
p[j*ndf+l] += points[i].weight * pj[l];
}
// Material Tangent
MatrixND<ndf,ndf> Kjk;
for (int j=0; j<nen; j++) {
for (int k=0; k<nen; k++) {
Kjk.addMatrixTripleProduct(0.0, B[j], Ks, B[k], points[i].weight);
for (int ii=0; ii<ndf; ii++) {
for (int jj=0; jj<ndf; jj++) {
K(j*ndf+ii, k*ndf+jj) += Kjk(ii,jj);
}
}
}
}
// Geometric Tangent
MatrixND<ndf,ndf> G;
for (int j=0; j<nen; j++) {
for (int k=0; k<nen; k++) {
G.zero();
G_matrix(G, s, dx, points[i].shape, j, k);
K.assemble(G, ndf*j, ndf*k, points[i].weight);
}
}
}
//commitState();
return OpenSees::Flag::Success;
}
template<int nen, int nip>
const Vector &
ExactFrame3d<nen,nip>::getResistingForce()
{
thread_local Vector wrapper;
wrapper.setData(p);
return wrapper;
}
template<int nen, int nip>
const Matrix &
ExactFrame3d<nen,nip>::getTangentStiff()
{
thread_local Matrix wrapper;
wrapper.setData(K);
return wrapper;
}
template<int nen, int nip>
const Matrix &
ExactFrame3d<nen,nip>::getInitialStiff()
{
static MatrixND<ndf*nen,ndf*nen> Ki{};
static Matrix wrapper(Ki);
return wrapper;
}
template<int nen, int nip>
const Matrix &
ExactFrame3d<nen,nip>::getMass()
{
// TODO
static MatrixND<ndf*nen,ndf*nen> M{0};
static Matrix wrapper(M);
return wrapper;
}
template<int nen, int nip>
int
ExactFrame3d<nen,nip>::sendSelf(int commitTag, Channel& theChannel)
{
// TODO
return -1;
}
template<int nen, int nip>
int
ExactFrame3d<nen,nip>::recvSelf(int commitTag, Channel& theChannel, FEM_ObjectBroker& theBroker)
{
// TODO
return -1;
}
template<int nen, int nip>
void
ExactFrame3d<nen,nip>::Print(OPS_Stream& stream, int flag)
{
const ID& node_tags = this->getExternalNodes();
if (flag == OPS_PRINT_PRINTMODEL_JSON) {
stream << OPS_PRINT_JSON_ELEM_INDENT << "{";
stream << "\"name\": " << this->getTag() << ", ";
stream << "\"type\": \"" << this->getClassType() << "\", ";
stream << "\"nodes\": [" << node_tags(0) << ", "
<< node_tags(1) << "], ";
stream << "\"sections\": [";
for (decltype(points.size()) i = 0; i < points.size() - 1; i++)
stream << points[i].material->getTag() << ", ";
stream << points[points.size() - 1].material->getTag() << "], ";
stream << "\"crdTransformation\": " << transform->getTag() ; // << ", ";
// stream << "\"integration\": ";
// stencil->Print(s, flag);
stream << "}";
}
// TODO
//for (int i=0; i < nip; i++) {
// stream << "xi[" << i << "] = " << points[i].point << "\n";
// stream << "wi[" << i << "] = " << points[i].weight << "\n";
// for (int j=0; j < nen; j++) {
// stream << "shp[" << i << "][0][ " << j << "] = " << points[i].shape[0][j] << "\n";
// stream << "shp[" << i << "][1][ " << j << "] = " << points[i].shape[1][j] << "\n";
// }
//}
}