-
Notifications
You must be signed in to change notification settings - Fork 9
/
Elasticity.C
1382 lines (1126 loc) · 34.9 KB
/
Elasticity.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
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
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// $Id$
//==============================================================================
//!
//! \file Elasticity.C
//!
//! \date Nov 12 2009
//!
//! \author Knut Morten Okstad / SINTEF
//!
//! \brief Base class for linear and nonlinear elasticity problems.
//!
//==============================================================================
#include "Elasticity.h"
#include "GlobalIntegral.h"
#include "IsotropicTextureMat.h"
#include "FiniteElement.h"
#include "HHTMats.h"
#include "BDFMats.h"
#include "ElmNorm.h"
#include "AnaSol.h"
#include "TensorFunction.h"
#include "Vec3Oper.h"
#include "Utilities.h"
#include "VTF.h"
#include "IFEM.h"
#include "tinyxml2.h"
#include <iomanip>
#ifndef epsR
//! \brief Zero tolerance for the radial coordinate.
#define epsR 1.0e-16
#endif
bool Elasticity::wantStrain = false;
bool Elasticity::wantPrincipalStress = false;
bool Elasticity::asolProject = false;
Elasticity::Elasticity (unsigned short int n, bool ax) : axiSymmetry(ax)
{
nsd = axiSymmetry ? 2 : n;
nDF = axiSymmetry ? 3 : nsd;
npv = nsd; // Number of primary unknowns per node
// Assign default material properties, in case of no user-input
static LinIsotropic defaultMat;
material = &defaultMat;
locSys = nullptr;
tracFld = nullptr;
fluxFld = nullptr;
bodyFld = nullptr;
pDirBuf = nullptr;
dualRHS = nullptr;
myReacI = nullptr;
gamma = 1.0;
calcMaxVal = true;
}
Elasticity::~Elasticity ()
{
if (locSys) delete locSys;
if (pDirBuf) delete pDirBuf;
}
bool Elasticity::parse (const tinyxml2::XMLElement* elem)
{
if (this->ElasticBase::parse(elem))
return true;
else if (!strcasecmp(elem->Value(),"stabilization"))
{
utl::getAttribute(elem,"gamma",gamma);
IFEM::cout <<"\tStabilization parameter "<< gamma << std::endl;
}
else if (!strcasecmp(elem->Value(),"localsystem"))
this->parseLocalSystem(elem);
else
return false;
return true;
}
Material* Elasticity::parseMatProp (char* cline, bool planeStrain)
{
double E = atof(strtok(cline," "));
double nu = atof(strtok(nullptr," "));
double rho = atof(strtok(nullptr," "));
IFEM::cout << E <<" "<< nu <<" "<< rho << std::endl;
material = new LinIsotropic(E,nu,rho,!planeStrain,axiSymmetry);
return material;
}
Material* Elasticity::parseMatProp (const tinyxml2::XMLElement* elem, bool planeStrain)
{
if (!strcasecmp(elem->Value(),"texturematerial"))
material = new IsotropicTextureMat(!planeStrain,axiSymmetry);
else
material = new LinIsotropic(!planeStrain,axiSymmetry);
material->parse(elem);
return material;
}
void Elasticity::printLog () const
{
utl::LogStream& os = IFEM::cout;
if (axiSymmetry)
os <<"Axial-symmetric Elasticity problem\n";
os <<"Elasticity: "<< nsd <<"D, gravity =";
for (unsigned short int d = 0; d < nsd; d++)
os <<" "<< gravity[d];
os << std::endl;
material->printLog();
}
void Elasticity::setMaterial (Material* mat)
{
if (mat == material) return;
#ifdef INT_DEBUG
if (mat && material)
{
IFEM::cout <<"\nElasticity::setMaterial: Switching material properties:\n";
mat->printLog();
}
#endif
material = mat;
}
void Elasticity::addExtrFunction (FunctionBase* extr)
{
if (dynamic_cast<VecFunc*>(extr))
{
dualFld.push_back(extr);
this->setNoSolutions(1+dualFld.size(),true);
if (!dualRHS) dualRHS = extr;
}
else
{
dualFld.clear();
dualRHS = nullptr;
}
}
LocalIntegral* Elasticity::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) // linear or nonlinear (quasi-)static analysis
result = new ElmMats();
else if (bdf)
result = new BDFMats(*bdf);
else if (intPrm[3] > 0.0) // linear dynamic analysis
result = new NewmarkMats(intPrm[0], intPrm[1], intPrm[2], intPrm[3],
intPrm[4] == 2.0);
else // nonlinear dynamic analysis
result = new HHTMats(intPrm[2], intPrm[0], intPrm[1], intPrm[4] != 1.0);
switch (m_mode)
{
case SIM::STATIC:
case SIM::MASS_ONLY:
result->rhsOnly = neumann;
result->withLHS = !neumann;
result->resize(neumann ? 0 : 1, neumann || dS == 0 ? 1 : dS, nsd);
break;
case SIM::ARCLEN:
result->rhsOnly = neumann;
result->withLHS = !neumann;
result->resize(neumann ? 0 : 1, 2, nsd);
break;
case SIM::DYNAMIC:
result->rhsOnly = neumann;
result->withLHS = !neumann;
result->resize(neumann ? 0 : (intPrm[3] >= 0.0 ? 3 : 4),
intPrm[4] == 1.0 ? 3 : (neumann || intPrm[3] > 0.0 ? 1:2), nsd);
break;
case SIM::VIBRATION:
case SIM::BUCKLING:
result->resize(2,0);
break;
case SIM::STIFF_ONLY:
result->resize(1,0);
break;
case SIM::RHS_ONLY:
case SIM::INT_FORCES:
result->resize(neumann ? 0 : 1, 1, nsd);
case SIM::RECOVERY:
result->rhsOnly = true;
result->withLHS = false;
break;
default:
;
}
result->redim(nsd*nen);
result->Aname = matNames;
result->Bname = vecNames;
return result;
}
bool Elasticity::hasBoundaryTerms () const
{
return (m_mode >= SIM::STATIC && m_mode <= SIM::DYNAMIC) ||
(m_mode >= SIM::RHS_ONLY && m_mode <= SIM::INT_FORCES) ||
m_mode == SIM::NORMS;
}
void Elasticity::setSecondaryInt (GlobalIntegral* gq)
{
delete myReacI;
myReacI = gq;
}
GlobalIntegral& Elasticity::getGlobalInt (GlobalIntegral* gq) const
{
if (m_mode == SIM::RHS_ONLY && myReacI)
return *myReacI;
return this->ElasticBase::getGlobalInt(gq);
}
Vec3 Elasticity::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 Elasticity::getBodyforce (const Vec3& X, bool grd) const
{
if (grd)
return bodyFld ? bodyFld->deriv(X,4) : Vec3();
Vec3 f(gravity);
f *= material->getMassDensity(X);
if (bodyFld)
f += (*bodyFld)(X);
return f;
}
bool Elasticity::haveLoads () const
{
if (tracFld) return true;
if (fluxFld) return true;
if (bodyFld) return true;
for (unsigned short int i = 0; i < nsd; i++)
if (gravity[i] != 0.0)
return material->getMassDensity(Vec3()) != 0.0;
return false;
}
void Elasticity::initIntegration (size_t, size_t nBp)
{
tracVal.clear();
tracVal.resize(nBp,std::make_pair(Vec3(),Vec3()));
}
void Elasticity::initResultPoints (double, bool prinDir)
{
if (wantPrincipalStress && prinDir)
{
if (!pDirBuf) pDirBuf = new Vec3Vec();
pDirBuf->clear();
}
else if (pDirBuf)
{
delete pDirBuf;
pDirBuf = nullptr;
}
}
bool Elasticity::writeGlvT (VTF* vtf, int iStep, int& geoBlk, int& nBlock) const
{
if (tracVal.empty())
return true;
else if (!vtf)
return false;
// Write boundary tractions as discrete point vectors to the VTF-file
return vtf->writeVectors(tracVal,geoBlk,++nBlock,"Tractions",iStep);
}
/*!
The strain-displacement matrix for a continuum element is formally defined as:
\f[ \mbox{In 3D,~~}
[B] = \left[\begin{array}{ccc}
\frac{\partial}{\partial x} & 0 & 0 \\
0 & \frac{\partial}{\partial y} & 0 \\
0 & 0 & \frac{\partial}{\partial z} \\
\frac{\partial}{\partial y} & \frac{\partial}{\partial x} & 0 \\
0 & \frac{\partial}{\partial z} & \frac{\partial}{\partial y} \\
\frac{\partial}{\partial z} & 0 & \frac{\partial}{\partial x}
\end{array}\right] [N] \hskip 5mm\mbox{and in 2D,~~}
[B] = \left[\begin{array}{ccc}
\frac{\partial}{\partial x} & 0 \\
0 & \frac{\partial}{\partial y} \\
\frac{\partial}{\partial y} & \frac{\partial}{\partial x}
\end{array}\right] [N]
\f]
where
[\a N ] is the element basis functions arranged in a [nsd][nsd*NENOD] matrix.
*/
bool Elasticity::formBmatrix (Matrix& Bmat, const Matrix& dNdX) const
{
const size_t nenod = dNdX.rows();
const size_t nstrc = nsd*(nsd+1)/2;
Bmat.resize(nstrc*nsd,nenod,true);
if (dNdX.cols() < nsd)
{
std::cerr <<" *** Elasticity::formBmatrix: Invalid dimension on dNdX, "
<< dNdX.rows() <<"x"<< dNdX.cols() <<"."<< std::endl;
return false;
}
#define INDEX(i,j) i+nstrc*(j-1)
switch (nsd) {
case 1:
// Strain-displacement matrix for 1D elements:
//
// [B] = | d/dx | * [N]
for (size_t i = 1; i <= nenod; i++)
Bmat(1,i) = dNdX(i,1);
break;
case 2:
// Strain-displacement matrix for 2D elements:
//
// | d/dx 0 |
// [B] = | 0 d/dy | * [N]
// | d/dy d/dx |
for (size_t i = 1; i <= nenod; i++)
{
// Normal strain part
Bmat(INDEX(1,1),i) = dNdX(i,1);
Bmat(INDEX(2,2),i) = dNdX(i,2);
// Shear strain part
Bmat(INDEX(3,1),i) = dNdX(i,2);
Bmat(INDEX(3,2),i) = dNdX(i,1);
}
break;
case 3:
// Strain-displacement matrix for 3D elements:
//
// | d/dx 0 0 |
// | 0 d/dy 0 |
// [B] = | 0 0 d/dz | * [N]
// | d/dy d/dx 0 |
// | 0 d/dz d/dy |
// | d/dz 0 d/dx |
for (size_t i = 1; i <= nenod; i++)
{
// Normal strain part
Bmat(INDEX(1,1),i) = dNdX(i,1);
Bmat(INDEX(2,2),i) = dNdX(i,2);
Bmat(INDEX(3,3),i) = dNdX(i,3);
// Shear strain part
Bmat(INDEX(4,1),i) = dNdX(i,2);
Bmat(INDEX(4,2),i) = dNdX(i,1);
Bmat(INDEX(5,2),i) = dNdX(i,3);
Bmat(INDEX(5,3),i) = dNdX(i,2);
Bmat(INDEX(6,1),i) = dNdX(i,3);
Bmat(INDEX(6,3),i) = dNdX(i,1);
}
break;
default:
std::cerr <<" *** Elasticity::formBmatrix: nsd="<< nsd << std::endl;
return false;
}
#undef INDEX
Bmat.resize(nstrc,nsd*nenod);
return true;
}
/*!
The strain-displacement matrix for an axially symmetric 3D continuum element
is formally defined as:
\f[
[B] = \left[\begin{array}{cc}
\frac{\partial}{\partial r} & 0 \\
0 & \frac{\partial}{\partial z} \\
\frac{1}{r} & 0 \\
\frac{\partial}{\partial z} & \frac{\partial}{\partial r}
\end{array}\right] [N]
\f]
where
[\a N ] is the element basis functions arranged in a [2][2*NENOD] matrix.
*/
bool Elasticity::formBmatrix (Matrix& Bmat, const Vector& N, const Matrix& dNdX,
const double r) const
{
const size_t nenod = N.size();
Bmat.resize(8,nenod,true);
if (dNdX.cols() < 2)
{
std::cerr <<" *** Elasticity::formBmatrix: Invalid dimension on dNdX, "
<< dNdX.rows() <<"x"<< dNdX.cols() <<"."<< std::endl;
return false;
}
else if (r < -epsR)
{
std::cerr <<" *** Elasticity::formBmatrix: Invalid point r < 0, "
<< r << std::endl;
return false;
}
#define INDEX(i,j) i+4*(j-1)
// Strain-displacement matrix for 3D axisymmetric elements:
//
// | d/dr 0 |
// [B] = | 0 d/dz | * [N]
// | 1/r 0 |
// | d/dz d/dr |
for (size_t i = 1; i <= nenod; i++)
{
// Normal strain part
Bmat(INDEX(1,1),i) = dNdX(i,1);
Bmat(INDEX(2,2),i) = dNdX(i,2);
// Hoop strain part
Bmat(INDEX(3,1),i) = r <= epsR ? dNdX(i,1) : N(i)/r;
// Shear strain part
Bmat(INDEX(4,1),i) = dNdX(i,2);
Bmat(INDEX(4,2),i) = dNdX(i,1);
}
#undef INDEX
Bmat.resize(4,2*nenod);
return true;
}
bool Elasticity::formDefGradient (const Vector& eV, const Vector& N,
const Matrix& dNdX, double r, Tensor& F,
bool gradOnly) const
{
F = gradOnly ? 0.0 : 1.0;
if (eV.empty())
return true; // Initial state, deformation gradient is identity tensor
const size_t nenod = dNdX.rows();
if (eV.size() != nsd*nenod || dNdX.cols() < nsd)
{
std::cerr <<" *** Elasticity::formDefGradient: Invalid dimension,"
<<" dNdX("<< nenod <<","<< dNdX.cols() <<")"<< std::endl;
return false;
}
// Compute the deformation gradient, [F] = [I] + [dudX] = [I] + [dNdX]*[u].
// Notice that the matrix multiplication method used here treats the element
// displacement vector, *eV, as a matrix whose number of columns equals the
// number of rows in the matrix dNdX.
Matrix dUdX;
if (!dUdX.multiplyMat(eV,dNdX)) // dUdX = Grad{u} = eV*dNdX
return false;
// Cannot use operator= here, in case F is of higher dimension than dUdX
for (size_t i = 1; i <= dUdX.rows(); i++)
for (size_t j = 1; j <= dUdX.cols(); j++)
F(i,j) += dUdX(i,j);
// Add the dU/r term to the F(3,3)-term for axisymmetric problems
if (axiSymmetry && r > epsR && !gradOnly)
F(3,3) += eV.dot(N,0,nsd)/r;
#if INT_DEBUG > 0
std::cout <<"Elasticity::eV ="<< eV
<<"Elasticity::F =\n"<< F;
#endif
return true;
}
bool Elasticity::kinematics (const Vector& eV,
const Vector& N, const Matrix& dNdX, double r,
Matrix& B, Tensor&, SymmTensor& eps) const
{
// Evaluate the strain-displacement matrix, B
if (axiSymmetry)
{
if (!this->formBmatrix(B,N,dNdX,r))
return false;
}
else
{
if (!this->formBmatrix(B,dNdX))
return false;
}
if (eV.empty() || eps.dim() == 0)
return true;
// Evaluate the strains
return B.multiply(eV,eps); // eps = B*eV
}
void Elasticity::formKG (Matrix& EM, const Vector& N, const Matrix& dNdX,
double r, const Tensor& sigma, double detJW) const
{
#if INT_DEBUG > 3
std::cout <<"Elasticity::sigma =\n"<< sigma
<<"Elasticity::kg =";
#endif
unsigned short int i, j;
double kgrr = axiSymmetry && r > 0.0 ? sigma(3,3)/(r*r) : 0.0;
for (size_t a = 1; a <= dNdX.rows(); a++)
for (size_t b = 1; b <= dNdX.rows(); b++)
{
double kg = 0.0;
for (i = 1; i <= nsd; i++)
for (j = 1; j <= nsd; j++)
kg += dNdX(a,i)*sigma(i,j)*dNdX(b,j);
#if INT_DEBUG > 3
std::cout << (b == 1 ? '\n' : ' ') << kg;
#endif
for (i = 1; i <= nsd; i++)
EM(nsd*(a-1)+i,nsd*(b-1)+i) += kg*detJW;
if (kgrr > 0.0)
EM(nsd*(a-1)+1,nsd*(b-1)+1) += N(a)*kgrr*N(b)*detJW;
}
#if INT_DEBUG > 3
std::cout << std::endl;
#endif
}
void Elasticity::formMassMatrix (Matrix& EM, const Vector& N,
const Vec3& X, double detJW) const
{
double rhow = material->getMassDensity(X)*detJW;
if (rhow == 0.0) return;
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 <= nsd; i++)
EM(nsd*(a-1)+i,nsd*(b-1)+i) += rhow*N(a)*N(b);
}
void Elasticity::formBodyForce (Vector& ES, RealArray& sumLoad, const Vector& N,
const Vec3& X, double detJW, bool grd) const
{
Vec3 f = this->getBodyforce(X,grd);
if (f.isZero()) return;
f *= detJW;
for (size_t a = 1; a <= N.size(); a++)
for (unsigned short int i = 1; i <= nsd; i++)
ES(nsd*(a-1)+i) += f[i-1]*N(a);
if (grd) return;
// Integrate total external load
for (unsigned short int i = 0; i < nsd && i < sumLoad.size(); i++)
sumLoad[i] += f[i];
}
bool Elasticity::evalBou (LocalIntegral& elmInt, const FiniteElement& fe,
const Vec3& X, const Vec3& normal) const
{
if (!tracFld && !fluxFld)
{
std::cerr <<" *** Elasticity::evalBou: No tractions."<< std::endl;
return false;
}
else if (!eS)
{
std::cerr <<" *** Elasticity::evalBou: No load vector."<< std::endl;
return false;
}
// Axi-symmetric integration point volume; 2*pi*r*|J|*w
const double detJW = axiSymmetry ? 2.0*M_PI*X.x*fe.detJxW : fe.detJxW;
// Evaluate the surface traction
Vec3 T = this->getTraction(X,normal);
// Store traction value for visualization
if (fe.iGP < tracVal.size())
{
tracVal[fe.iGP].first = X;
tracVal[fe.iGP].second += T;
}
// Pull-back traction to reference configuration
if (!this->pullBackTraction(T))
return false;
// Integrate the force vector
Vector& ES = static_cast<ElmMats&>(elmInt).b[eS-1];
for (size_t a = 1; a <= fe.N.size(); a++)
for (unsigned short int i = 1; i <= nsd; i++)
ES(nsd*(a-1)+i) += T[i-1]*fe.N(a)*detJW;
// Integrate total external load
RealArray& sumLoad = static_cast<ElmMats&>(elmInt).c;
for (unsigned short int i = 0; i < nsd && i < sumLoad.size(); i++)
sumLoad[i] += T[i]*fe.detJxW;
if (gS)
{
// Evaluate the surface traction gradient
T = this->getTraction(X,normal,true);
// Pull-back traction to reference configuration
if (!this->pullBackTraction(T))
return false;
// Integrate the force gradient vector
Vector& GS = static_cast<ElmMats&>(elmInt).b[gS-1];
for (size_t a = 1; a <= fe.N.size(); a++)
for (unsigned short int i = 1; i <= nsd; i++)
GS(nsd*(a-1)+i) += T[i-1]*fe.N(a)*detJW;
}
return true;
}
Vec3 Elasticity::evalSol (const Vector& eV, const Vector& N) const
{
Vec3 u;
if (eV.size() == nsd*N.size())
for (unsigned short int i = 0; i < nsd; i++)
u[i] = eV.dot(N,i,nsd);
return u;
}
bool Elasticity::formCmat (Matrix& C, const FiniteElement& fe,
const Vec3& X, bool inverted) const
{
SymmTensor dummy(nsd,axiSymmetry); double U;
return material->evaluate(C,dummy,U,fe,X,dummy,dummy, inverted ? -1 : 0);
}
bool Elasticity::evalSol2 (Vector& s, const Vectors& eV,
const FiniteElement& fe, const Vec3& X) const
{
Vec3* pBuf = nullptr;
if (pDirBuf)
{
// Store principal stress directions in the internal buffer
size_t ifirst = pDirBuf->size();
pDirBuf->resize(ifirst+2);
pBuf = pDirBuf->data() + ifirst;
}
// Evaluate the stress tensor
if (fe.detJxW == 0.0)
{
// Singular point, just return an empty vector for now
s.clear();
return true;
}
else if (!this->evalSol(s,eV,fe,X,true,pBuf))
return false;
#if INT_DEBUG > 2
else if (pBuf)
std::cout <<"Elasticity::evalSol2("<< X <<"): "
<<" Pdir1 = "<< pBuf[0] <<", Pdir2 = "<< pBuf[1] << std::endl;
#endif
// Additional result variables?
for (int i = 1; i <= material->getNoIntVariables(); i++)
s.push_back(material->getInternalVariable(i,nullptr,fe.iGP));
if (!calcMaxVal || maxVal.empty())
return true; // Avoid thread sync if no max value calculation
// Find the maximum values for each quantity. This block must be performed
// serially on multi-threaded runs too, due to the update of the maxVal array
// which is a member of the Elasticity class. Therefore the critical pragma.
#pragma omp critical
for (size_t j = 0; j < s.size() && j < maxVal.size(); j++)
{
size_t pidx = maxVal[j].size() > 1 ? LocalSystem::patch : 0;
if (pidx < maxVal[j].size() && fabs(s[j]) > fabs(maxVal[j][pidx].second))
maxVal[j][pidx] = std::make_pair(X,s[j]);
}
return true;
}
bool Elasticity::evalSol (Vector& s, const Vectors& eV, const FiniteElement& fe,
const Vec3& X, bool toLocal, Vec3* pdir) const
{
if (eV.empty())
{
std::cerr <<" *** Elasticity::evalSol: No solutions vector."<< std::endl;
return false;
}
else if (!eV.front().empty() && eV.front().size() != nsd*fe.dNdX.rows())
{
std::cerr <<" *** Elasticity::evalSol: Invalid displacement vector."
<<"\n size(eV) = "<< eV.front().size() <<" size(dNdX) = "
<< fe.dNdX.rows() <<","<< fe.dNdX.cols() << std::endl;
return false;
}
// Evaluate the deformation gradient, dUdX, and/or the strain tensor, eps
Matrix Bmat;
Tensor dUdX(nDF);
SymmTensor eps(nsd,axiSymmetry);
if (!this->kinematics(eV.front(),fe.N,fe.dNdX,X.x,Bmat,dUdX,eps))
return false;
// Add strains due to temperature expansion, if any
double epsT = this->getThermalStrain(eV.back(),fe.N,X);
if (epsT != 0.0) eps -= epsT;
SymmTensor sigma(nsd, axiSymmetry || material->isPlaneStrain());
if (wantStrain)
sigma.copy(eps);
else
{
// Calculate the stress tensor through the constitutive relation
Matrix Cmat;
double U = 0.0;
if (!material->evaluate(Cmat,sigma,U,fe,X,dUdX,eps))
return false;
else if (epsT != 0.0 && nsd == 2 && material->isPlaneStrain())
sigma(3,3) -= material->getStiffness(X)*epsT;
}
Vec3 p;
bool havePval = false;
if (toLocal && wantPrincipalStress)
{
// Calculate principal stresses and associated direction vectors
if (sigma.size() == 4)
{
SymmTensor tmp(2); tmp = sigma; // discard the sigma_zz component
havePval = pdir ? tmp.principal(p,pdir,2) : tmp.principal(p);
}
else
havePval = pdir ? sigma.principal(p,pdir,2) : sigma.principal(p);
// Congruence transformation to local coordinate system at current point
if (locSys) sigma.transform(locSys->getTmat(X));
}
s = sigma;
if (toLocal)
s.push_back(sigma.vonMises());
if (havePval)
{
s.push_back(p.x);
s.push_back(p.y);
if (sigma.dim() == 3)
s.push_back(p.z);
}
return true;
}
bool Elasticity::evalSol (Vector& s, const STensorFunc& asol,
const Vec3& X) const
{
s = asol(X);
SymmTensor sigma(s);
s = sigma;
s.push_back(sigma.vonMises());
if (wantPrincipalStress)
{
Vec3 p;
sigma.principal(p);
s.resize(s.size()+material->getNoIntVariables());
s.push_back(p.x);
s.push_back(p.y);
if (nsd == 3)
s.push_back(p.z);
}
return true;
}
bool Elasticity::evalEps (Vector& s, const Vector& eV, const FiniteElement& fe,
const Vec3& X) const
{
if (eV.size() != fe.dNdX.rows()*nsd)
{
std::cerr <<" *** Elasticity::evalEps: Invalid displacement vector."
<<"\n size(eV) = "<< eV.size() <<" size(dNdX) = "
<< fe.dNdX.rows() <<","<< fe.dNdX.cols() << std::endl;
return false;
}
// Evaluate the strain tensor
Matrix Bmat;
SymmTensor eps(nsd,axiSymmetry);
if (!this->kinematics(eV,fe.N,fe.dNdX,X.x,Bmat,eps,eps))
return false;
s = eps;
return true;
}
Vector* Elasticity::getExtractionField (size_t ifield)
{
return dS && ifield < primsol.size() ? &primsol[ifield] : nullptr;
}
bool Elasticity::getPrincipalDir (Matrix& pdir, size_t nPt, size_t idx) const
{
if (!pDirBuf || idx < 1 || idx > 2) return false;
if (pDirBuf->size() != nPt*2)
{
std::cerr <<" *** Elasticity::getPrincipalDir: Result point mismatch, nPt="
<< nPt <<", pDirBuf->size()="<< pDirBuf->size() << std::endl;
return false;
}
pdir.resize(nsd,nPt);
for (size_t i = 0; i < nPt; i++)
pdir.fillColumn(1+i,(*pDirBuf)[2*i+idx-1].ptr());
return true;
}
size_t Elasticity::getNoFields (int fld) const
{
if (fld < 2)
return nsd; // Displacement components
size_t nf = nsd*(nsd+1)/2; // Symmetric stress tensor components
if (nsd == 2 && (axiSymmetry || material->isPlaneStrain()))
++nf; // Include Hoop or normal stress
if (fld == 2)
{
// Include von Mises stress and internal variables
nf += 1 + material->getNoIntVariables();
if (wantPrincipalStress)
nf += nsd; // Include principal stress components
}
#if INT_DEBUG > 1
std::cout <<"Elasticity::getNoFields: "<< nf << std::endl;
#endif
return nf;
}
std::string Elasticity::getField1Name (size_t i, const char* prefix) const
{
if (i > nsd) i = 4;
static const char* s[5] = { "u_x", "u_y", "u_z", "u_r", "displacement" };
if (!prefix) return s[i];
return prefix + std::string(" ") + s[axiSymmetry ? 3-i : i];
}
std::string Elasticity::getField2Name (size_t i, const char* prefix) const
{
size_t nVars = this->getNoFields(2);
if (i >= nVars) return "";
static const char* r[4] = { "s_rr", "s_zz", "s_tt", "s_zr" };
static const char* s[6] = { "s_xx", "s_yy", "s_zz", "s_xy", "s_yz", "s_xz" };
std::string name;
if (prefix)
name = std::string(prefix) + " ";
else
name.clear();
// Number of components in the stress vector of this problem
size_t nStress = this->getNoFields(3);
if (nsd == 1)
name += "Axial stress";
else if (i == 2 && nStress == 3)
name += s[3]; // No s_zz when plane stress
else if (i < nStress)
{
size_t j = name.size();
name += axiSymmetry ? r[i] : s[i];
if (wantStrain) name[j] = 'e';
}
else if (i == nStress)
name += "von Mises " + std::string(wantStrain ? "strain" : "stress");
else if ((int)(i -= nStress) <= material->getNoIntVariables())
{
char varName[32];
material->getInternalVariable(i,varName);
name += varName;
}
else if ((i -= material->getNoIntVariables()) <= nsd)
name += "P" + std::to_string(i);
return name;
}
void Elasticity::initMaxVals (size_t nP)
{
#ifdef INT_DEBUG
std::cout <<"Elasticity::initMaxVals: "<< maxVal.size()
<<" --> "<< nP << std::endl;
#endif
if (maxVal.empty() && nP > 0)
maxVal.resize(this->getNoFields(2),PointValues(nP,PointValue(Vec3(),0.0)));
else for (PointValues& pval : maxVal)
std::fill(pval.begin(),pval.end(),PointValue(Vec3(),0.0));
}
void Elasticity::printMaxVals (std::streamsize precision, size_t comp) const
{
size_t i1 = 1, i2 = maxVal.size();
if (comp > i2)
return;
else if (comp > 0)
i1 = i2 = comp;
std::streamsize fldWidth = 8 + precision;
utl::LogStream& os = IFEM::cout;
for (size_t i = i1-1; i < i2; i++)
{
if (maxVal[i].empty())
continue;
else if (maxVal[i].size() == 1 && maxVal[i].front().second == 0.0)
continue; // no value
std::string name = this->getField2Name(i,nullptr);