23 #pragma STDC FENV_ACCESS ON 35 static LoggerPtr loggerr(Logger::getLogger(
"logtensor"));
52 TPZDecomposed() : fDistinctEigenvalues(0), fGeometricMultiplicity(3, 0), fEigenvalues(3, 0.), fEigenvectors(3), fEigentensors(3) {
55 TPZDecomposed(
const TPZDecomposed ©) : fDistinctEigenvalues(copy.fDistinctEigenvalues), fGeometricMultiplicity(copy.fGeometricMultiplicity), fEigenvalues(copy.fEigenvalues), fEigenvectors(copy.fEigenvectors), fEigentensors(copy.fEigentensors) {
67 TPZDecomposed(
const TPZTensor<T> &source) : fDistinctEigenvalues(0), fGeometricMultiplicity(3, 0), fEigenvalues(3, 0.), fEigenvectors(3), fEigentensors(3) {
71 void Print(std::ostream &out)
const {
73 if (fDistinctEigenvalues == 0 || fDistinctEigenvalues > 3) {
74 std::stringstream str;
75 str <<
"TPZTensor::Decomposed::Print Invalid number of distinct eigenvalues: " << fDistinctEigenvalues << std::endl;
79 out <<
"TPZTensor::Decomposed Eigenvalues (" << fDistinctEigenvalues <<
" distinct):" << std::endl;
80 unsigned int vIndex = 0;
81 unsigned int lambda = 0;
83 const unsigned int geoMult(fGeometricMultiplicity[lambda]);
85 if (geoMult == 0 || geoMult > 3) {
86 std::stringstream str;
87 str <<
"TPZTensor::Decomposed::Print Invalid geometric multiplicity (" << geoMult <<
") for eigenvalue " << fEigenvalues[lambda] << std::endl;
91 out <<
"Eigenvalue: " << fEigenvalues[lambda] <<
" (" << geoMult <<
" time" << (geoMult > 1 ?
"s" :
"") <<
")" << std::endl;
92 out <<
"Eigenvector" << (geoMult > 1 ?
"s" :
"") <<
":" << std::endl;
93 if (fEigenvectors.
size() == 0 || fEigenvectors[0].
size() == 0) {
94 out <<
" Not computed." << std::endl;
96 for (
unsigned int v = 0; v < geoMult; ++v) {
97 out << fEigenvectors[vIndex][0] <<
" ";
98 out << fEigenvectors[vIndex][1] <<
" ";
99 out << fEigenvectors[vIndex][2] << std::endl;
103 out <<
"Eigentensor:" << std::endl;
104 fEigentensors[lambda].
Print(out);
109 std::stringstream str;
110 str <<
"TPZTensor::Decomposed::Print Total geometric multiplicity greater than expected!" << std::endl;
114 }
while (lambda < 3);
130 for (
int i = 0; i < 6; i++) {
140 for (
int i = 0; i < 3; i++) {
141 gEigval[i] = objdec.fEigenvalues[i];
143 for (
int j = 0; j < 6; j++) {
144 tangent(0, j) = objdec.fEigentensors[icase][j];
145 tangent(0, 6) = objdec.fEigentensors[icase].
XY();
146 tangent(0, 7) = objdec.fEigentensors[icase].
XZ();
147 tangent(0, 8) = objdec.fEigentensors[icase].
YZ();
149 STATE sum = 0., sum2 = 0.;
150 for (
int i = 0; i < 9; i++) {
151 sum += tangent(0, i) * tangent(0, i);
153 sum2 = tangent(0,
_XX_) + tangent(0,
_YY_) + tangent(0,
_ZZ_);
154 tangent.
Print(
"tangent");
155 std::cout <<
"sum2 = " << sum2 << std::endl;
156 std::cout <<
"sum = " << sum << std::endl;
167 for (
int i = 0; i < 6; i++) {
170 obj[
_XY_] = obj[
_XY_]*0.5 + 0.5 * state(6);
171 obj[
_XZ_] = (obj[
_XZ_] + state(7))*0.5;
172 obj[
_YZ_] = (obj[
_YZ_] + state(8))*0.5;
180 residual(0, 0) = objdec.fEigenvalues[icase];
182 for (
int i = 0; i < 3; i++) {
186 if (gEigval[i] == gEigval[icase]) {
188 residual(0) += objdec.fEigenvalues[i];
191 residual(0) /= numequal;
202 sig1 = this->fEigenvalues[0];
203 sig2 = this->fEigenvalues[1];
204 sig3 = this->fEigenvalues[2];
205 J2 = (
pow(sig1 + (-sig1 - sig2 - sig3) / 3., 2) +
pow(sig2 + (-sig1 - sig2 - sig3) / 3., 2) +
pow((-sig1 - sig2 - sig3) / 3. + sig3, 2)) / 2.;
209 T sig1, sig2, sig3, s1, s2, s3, temp;
210 sig1 = this->fEigenvalues[0];
211 sig2 = this->fEigenvalues[1];
212 sig3 = this->fEigenvalues[2];
213 s1 = sig1 - (1. / 3.)*(sig1 + sig2 + sig3);
214 s2 = sig2 - (1. / 3.)*(sig1 + sig2 + sig3);
215 s3 = sig3 - (1. / 3.)*(sig1 + sig2 + sig3);
216 temp = (1. / 3.)*(s1 * s1 * s1 + s2 * s2 * s2 + s3 * s3 * s3);
221 I1 = this->fEigenvalues[0] + this->fEigenvalues[1] + this->fEigenvalues[2];
225 const T sig1 = this->fEigenvalues[0];
226 const T sig2 = this->fEigenvalues[1];
227 const T sig3 = this->fEigenvalues[2];
228 const T trace = sig1 + sig2 + sig3;
229 const T trace_3 = trace / 3.;
232 SigVol.
XX() = SigVol.
YY() = SigVol.
ZZ() = K * trace;
234 Stress.
XX() = sig1 - trace_3;
235 Stress.
YY() = sig2 - trace_3;
236 Stress.
ZZ() = sig3 - trace_3;
265 for (i = 0; i < 3; i += eigensystem.fGeometricMultiplicity[i]) {
266 Add(eigensystem.fEigentensors[i], eigensystem.fEigenvalues[i]);
276 return Hash(
"TPZTensor") ^ ClassIdOrHash<T>() << 1;
288 result(0, 1) = result(1, 0) =
XY();
289 result(0, 2) = result(2, 0) =
XZ();
291 result(1, 2) = result(2, 1) =
YZ();
298 if (input.
Rows() != 3 || input.
Cols() != 3) {
303 for (
int i = 0; i < 3; i++) {
304 for (
int j = 0; j < 3; j++) {
306 std::cout <<
"diff = " << input.
GetVal(i, j) - input.
GetVal(j, i) << std::endl;
322 void Print(std::ostream &out)
const;
361 return fData[row * (5 - row) / 2 + col];
363 return fData[col * (5 - col) / 2 + row];
369 return fData[row * (5 - row) / 2 + col];
371 return fData[col * (5 - col) / 2 + row];
379 template <
class TBASE>
390 template <
class T1,
class T2 >
398 template <
class T1,
class T2>
399 void Multiply(
const T1 & multipl,
const T2 & constant);
413 void Scale(
const T2 & constant);
495 Diag *= sigIJ[0] / T(3.);
500 if (
fabs(sqj2val) > 1.e-6) {
501 ratio = sigIJ[1] / sqj2;
536 for (
unsigned int i = 0; i < 6; ++i) {
546 if ((
fabs(this->
XY()) > realTol) || (
fabs(this->
XZ()) > realTol) || (
fabs(this->
YZ()) > realTol)) {
566 inline T &
XX()
const {
570 inline T &
XY()
const {
574 inline T &
XZ()
const {
578 inline T &
YY()
const {
582 inline T &
YZ()
const {
586 inline T &
ZZ()
const {
599 template <
class TBASE>
611 template <
class T1 >
660 bool AreEqual(
const T &val1,
const T &val2,
const T
tol = T(1.e-9))
const {
693 template <
class TBASE>
695 fData[
_XX_] = TBASE(1.);
696 fData[
_YY_] = TBASE(1.);
697 fData[
_ZZ_] = TBASE(1.);
699 fData[
_XY_] = TBASE(0.);
700 fData[
_XZ_] = TBASE(0.);
701 fData[
_YZ_] = TBASE(0.);
712 fData = source.
fData;
719 for (i = 0; i < 6; i++)fData[i] += source.
fData[i];
726 for (i = 0; i < 6; i++)fData[i] -= source.
fData[i];
733 for (i = 0; i < 6; i++)fData[i] *= multipl;
740 return temp += source;
746 return temp -= source;
752 return temp *= multipl;
756 template <
class T1,
class T2 >
759 for (i = 0; i < size; i++) {
760 fData[i] += tensor.
fData[i] * T1(constant);
765 template <
class T1,
class T2 >
768 for (i = 0; i < size; i++) {
770 fData[i] *= constant;
776 const T
XX = this->fData[
_XX_];
777 const T
YY = this->fData[
_YY_];
778 const T
ZZ = this->fData[
_ZZ_];
779 const T
XY = this->fData[
_XY_];
780 const T
XZ = this->fData[
_XZ_];
781 const T
YZ = this->fData[
_YZ_];
782 resp.
fData[
_XX_] = XX * tensor.
XX() + XY * tensor.
XY() + XZ * tensor.
XZ();
783 resp.
fData[
_YY_] = XY * tensor.
XY() + YY * tensor.
YY() + YZ * tensor.
YZ();
784 resp.
fData[
_ZZ_] = XZ * tensor.
XZ() + YZ * tensor.
YZ() + ZZ * tensor.
ZZ();
785 resp.
fData[
_XY_] = XX * tensor.
XY() + XY * tensor.
YY() + XZ * tensor.
YZ();
786 resp.
fData[
_XZ_] = XX * tensor.
XZ() + XY * tensor.
YZ() + XZ * tensor.
ZZ();
787 resp.
fData[
_YZ_] = XY * tensor.
XZ() + YY * tensor.
YZ() + YZ * tensor.
ZZ();
791 template <
class T2 >
794 const T Tconst = T(constant);
795 for (i = 0; i < size; i++) {
803 const T Tzero = T(0.);
804 for (i = 0; i < size; i++) {
812 for (i = 0; i < size; i++) {
813 fData[i] = Solution[i];
818 template <
class T1 >
820 for (
unsigned int i = 0; i < 6; i++) {
827 for (
unsigned int i = 0; i < 6; i++) {
834 for (
unsigned int i = 0; i < 6; i++) {
835 fData[i] = source.
Get(i, 0);
840 template <
class TBASE >
842 T p =
I1() / T(TBASE(3.));
843 vec[0] = fData[
_XX_] - p;
844 vec[1] = fData[
_YY_] - p;
845 vec[2] = fData[
_ZZ_] - p;
850 DeviatoricDiagonal_T<REAL>(vec);
856 for (
unsigned int i = 0; i < 6; i++) {
857 norm += fData[i] * fData[i];
866 std::ostream &operator<<(std::ostream &out, const TPZTensor<T> &tens) {
896 T mult = -
I1() / T(3);
909 return -(fData[
_XY_] * fData[
_XY_] +
929 DeviatoricDiagonal_T<T>(s);
930 T value = -s[0] * s[1] - s[0] * s[2] - s[1] * s[2] + fData[
_XY_] * fData[
_XY_] + fData[
_XZ_] * fData[
_XZ_] + fData[
_YZ_] * fData[
_YZ_];
957 T state0(fData[
_XX_]), state1(fData[
_XY_]), statex1(fData[_XY_]),
958 state2(fData[
_XZ_]), statex2(fData[_XZ_]), state3(fData[
_YY_]),
959 state4(fData[
_YZ_]), statex4(fData[_YZ_]), state5(fData[
_ZZ_]);
964 deriv.
fData[
_XY_] = (state0 * state1) / 3. + (state1 * state3) / 3. -
965 (state1 * state5 * 2.) / 3. + (state0 * statex1) / 3. +
966 (state3 * statex1) / 3. - (state5 * statex1 * 2.) / 3. +
967 state4 * statex2 + state2*statex4;
968 deriv.
fData[
_XZ_] = (state0 * state2) / 3. - (state2 * state3 * 2.) / 3. +
969 state1 * state4 + (state2 * state5) / 3. +
970 (state0 * statex2) / 3. - (state3 * statex2 * 2.) / 3. +
971 (state5 * statex2) / 3. + statex1*statex4;
973 (fData[_XY_] * fData[_XY_]) / 3. - ((fData[
_XZ_] * fData[
_XZ_])*2.) / 3. - (fData[
_XX_] * fData[
_YY_]*2.) / 9. + ((fData[
_YY_] * fData[
_YY_])*2.) / 9. +
974 (fData[
_YZ_] * fData[
_YZ_]) / 3. + (fData[_XX_] * fData[_ZZ_]*4.) / 9. - (fData[
_YY_] * fData[
_ZZ_]*2.) / 9. -
976 deriv.
fData[
_YZ_] = (state0 * state4 * (-2.)) / 3. + (state3 * state4) / 3. +
977 (state4 * state5) / 3. + state2 * statex1 +
978 state1 * statex2 - (state0 * statex4 * 2.) / 3. +
979 (state3 * statex4) / 3. + (state5 * statex4) / 3.;
980 deriv.
fData[
_ZZ_] = -(fData[
_XX_] * fData[
_XX_]) / 9. - (2. * (fData[_XY_] * fData[_XY_])) / 3. +
981 (fData[_XZ_] * fData[_XZ_]) / 3. + (fData[
_XX_] * fData[
_YY_]*4.) / 9. - (fData[
_YY_] * fData[
_YY_]) / 9. +
982 (fData[_YZ_] * fData[_YZ_]) / 3. - (fData[
_XX_] * fData[
_ZZ_]*2.) / 9. - (fData[
_YY_] * fData[
_ZZ_]*2.) /
983 9. + ((fData[
_ZZ_] * fData[
_ZZ_])*2.) / 9.;
991 Tensor(0, 1) = Tensor(1, 0) =
XY();
992 Tensor(0, 2) = Tensor(2, 0) =
XZ();
994 Tensor(1, 2) = Tensor(2, 1) =
YZ();
999 static T
Polynom(
const T &x,
const T &I1,
const T &I2,
const T &I3) {
1000 T result = x * x * x - I1 * x * x + I2 * x -
I3;
1006 T result = T(3.) * x * x - T(2.) * I1 * x +
I2;
1012 T residue =
Polynom(x, I1, I2, I3);
1014 return x - residue / dres;
1021 int64_t numiterations = 1000;
1034 eigensystem.fEigenvalues = Eigenvalues;
1037 if (
AreEqual(Eigenvalues[0], Eigenvalues[1]) &&
AreEqual(Eigenvalues[0], Eigenvalues[2])) {
1038 eigensystem.fDistinctEigenvalues = 1;
1039 for (
unsigned int i = 0; i < 3; ++i) {
1040 eigensystem.fGeometricMultiplicity[i] = 3;
1041 eigensystem.fEigenvectors[i][i] = 1.;
1042 Eigentensors[i].Identity();
1045 for (
unsigned int i = 0; i < 3; ++i) {
1046 for (
unsigned int j = 0; j < 3; ++j) {
1047 eigensystem.fEigenvectors[i][j] = Eigenvectors(i, j);
1051 if (
AreEqual(Eigenvalues[0], Eigenvalues[1]) ||
AreEqual(Eigenvalues[1], Eigenvalues[2]) ||
AreEqual(Eigenvalues[0], Eigenvalues[2])) {
1052 eigensystem.fDistinctEigenvalues = 2;
1055 int equals[2] = {-1, -1};
1056 if (
AreEqual(Eigenvalues[0], Eigenvalues[1])) {
1060 }
else if (
AreEqual(Eigenvalues[0], Eigenvalues[2])) {
1064 }
else if (
AreEqual(Eigenvalues[1], Eigenvalues[2])) {
1069 eigensystem.fGeometricMultiplicity[different] = 1;
1070 eigensystem.fGeometricMultiplicity[equals[0]] = 2;
1071 eigensystem.fGeometricMultiplicity[equals[1]] = 2;
1073 Eigentensors[different].XX() = Eigenvectors(different, 0) * Eigenvectors(different, 0);
1074 Eigentensors[different].XY() = Eigenvectors(different, 0) * Eigenvectors(different, 1);
1075 Eigentensors[different].XZ() = Eigenvectors(different, 0) * Eigenvectors(different, 2);
1076 Eigentensors[different].YY() = Eigenvectors(different, 1) * Eigenvectors(different, 1);
1077 Eigentensors[different].YZ() = Eigenvectors(different, 1) * Eigenvectors(different, 2);
1078 Eigentensors[different].ZZ() = Eigenvectors(different, 2) * Eigenvectors(different, 2);
1080 Eigentensors[equals[0]].Identity();
1081 Eigentensors[equals[0]] -= Eigentensors[different];
1082 Eigentensors[equals[1]] = Eigentensors[equals[0]];
1085 eigensystem.fDistinctEigenvalues = 3;
1086 for (
int i = 0; i < 3; i++) {
1087 eigensystem.fGeometricMultiplicity[i] = 1;
1088 Eigentensors[i].XX() = Eigenvectors(i, 0) * Eigenvectors(i, 0);
1089 Eigentensors[i].XY() = Eigenvectors(i, 0) * Eigenvectors(i, 1);
1090 Eigentensors[i].XZ() = Eigenvectors(i, 0) * Eigenvectors(i, 2);
1091 Eigentensors[i].YY() = Eigenvectors(i, 1) * Eigenvectors(i, 1);
1092 Eigentensors[i].YZ() = Eigenvectors(i, 1) * Eigenvectors(i, 2);
1093 Eigentensors[i].ZZ() = Eigenvectors(i, 2) * Eigenvectors(i, 2);
1100 if (loggerr->isDebugEnabled()) {
1101 std::stringstream str;
1102 str <<
"\n-------------AUTOVETORES JACOBI--------------" << std::endl;
1103 str <<
"Tensor:" << std::endl;
1105 str <<
"Eigenvalues = " << Eigenvalues << std::endl;
1106 str <<
"Eigenvectors:" << std::endl;
1107 Eigenvectors.
Print(
"Eigenvec:", str);
1108 str <<
"Eigenprojections:" << std::endl;
1109 for (
int k = 0; k < 3; k++) {
1110 str <<
"EigenProjection " << k <<
":" << std::endl;
1111 Eigentensors[k].
Print(str);
1114 str <<
"\n-------------FIM AUTOVETORES JACOBI--------------" << std::endl;
1129 eigensystem.fDistinctEigenvalues = 1;
1130 eigenvalues[0] = eigenvalues[1] = eigenvalues[2] = 0.;
1131 eigensystem.fGeometricMultiplicity[0] = 3;
1132 eigensystem.fGeometricMultiplicity[1] = 3;
1133 eigensystem.fGeometricMultiplicity[2] = 3;
1134 if (compute_eigenvectors) {
1136 eigenvectors[0][0] = 1.0;
1138 eigenvectors[1][1] = 1.0;
1140 eigenvectors[2][2] = 1.0;
1143 eigenvalues[0] = this->
XX();
1144 eigenvalues[1] = this->
YY();
1145 eigenvalues[2] = this->
ZZ();
1147 if (compute_eigenvectors) {
1150 eigenvectors[0][0] = 1.0;
1152 eigenvectors[1][1] = 1.0;
1154 eigenvectors[2][2] = 1.0;
1157 bool ev0eqev1 =
AreEqual(eigenvalues[0], eigenvalues[1], tol);
1158 bool ev1eqev2 =
AreEqual(eigenvalues[1], eigenvalues[2], tol);
1160 if (ev0eqev1 && ev1eqev2) {
1162 eigensystem.fDistinctEigenvalues = 1;
1163 eigensystem.fGeometricMultiplicity[0] = 3;
1164 eigensystem.fGeometricMultiplicity[1] = 3;
1165 eigensystem.fGeometricMultiplicity[2] = 3;
1167 }
else if (ev0eqev1 || ev1eqev2 ||
AreEqual(eigenvalues[0], eigenvalues[2], tol)) {
1168 eigensystem.fDistinctEigenvalues = 2;
1170 int equals[2] = {-1, -1};
1175 }
else if (ev1eqev2) {
1184 eigensystem.fGeometricMultiplicity[different] = 1;
1185 eigensystem.fGeometricMultiplicity[equals[0]] = 2;
1186 eigensystem.fGeometricMultiplicity[equals[1]] = 2;
1188 eigensystem.fDistinctEigenvalues = 3;
1189 eigensystem.fGeometricMultiplicity[0] = 1;
1190 eigensystem.fGeometricMultiplicity[1] = 1;
1191 eigensystem.fGeometricMultiplicity[2] = 1;
1194 if (eigenvalues[0] < eigenvalues[1]) {
1195 T eigenvalueTemp = eigenvalues[0];
1196 eigenvalues[0] = eigenvalues[1];
1197 eigenvalues[1] = eigenvalueTemp;
1198 std::swap(eigensystem.fGeometricMultiplicity[0], eigensystem.fGeometricMultiplicity[1]);
1199 if (compute_eigenvectors) {
1200 auto temp = eigenvectors[0];
1201 eigenvectors[0] = eigenvectors[1];
1202 eigenvectors[1] = temp;
1205 if (eigenvalues[1] < eigenvalues[2]) {
1206 T eigenvalueTemp = eigenvalues[1];
1207 eigenvalues[1] = eigenvalues[2];
1208 eigenvalues[2] = eigenvalueTemp;
1209 std::swap(eigensystem.fGeometricMultiplicity[1], eigensystem.fGeometricMultiplicity[2]);
1210 if (compute_eigenvectors) {
1211 auto temp = eigenvectors[1];
1212 eigenvectors[1] = eigenvectors[2];
1213 eigenvectors[2] = temp;
1216 if (eigenvalues[0] < eigenvalues[1]) {
1217 T eigenvalueTemp = eigenvalues[0];
1218 eigenvalues[0] = eigenvalues[1];
1219 eigenvalues[1] = eigenvalueTemp;
1220 std::swap(eigensystem.fGeometricMultiplicity[0], eigensystem.fGeometricMultiplicity[1]);
1221 if (compute_eigenvectors) {
1222 auto temp = eigenvectors[0];
1223 eigenvectors[0] = eigenvectors[1];
1224 eigenvectors[1] = temp;
1230 bool ev0eqev1 =
AreEqual(eigenvalues[0], eigenvalues[1], tol);
1231 bool ev1eqev2 =
AreEqual(eigenvalues[1], eigenvalues[2], tol);
1233 if (ev0eqev1 && ev1eqev2) {
1234 eigensystem.fDistinctEigenvalues = 1;
1235 eigensystem.fGeometricMultiplicity[0] = 3;
1236 eigensystem.fGeometricMultiplicity[1] = 3;
1237 eigensystem.fGeometricMultiplicity[2] = 3;
1238 }
else if (ev0eqev1 || ev1eqev2) {
1240 eigensystem.fDistinctEigenvalues = 2;
1251 eigensystem.fGeometricMultiplicity[1] = 2;
1252 eigensystem.fGeometricMultiplicity[equals] = 2;
1253 eigensystem.fGeometricMultiplicity[different] = 1;
1256 eigensystem.fDistinctEigenvalues = 3;
1257 eigensystem.fGeometricMultiplicity[0] = 1;
1258 eigensystem.fGeometricMultiplicity[1] = 1;
1259 eigensystem.fGeometricMultiplicity[2] = 1;
1274 for (
unsigned int i = 0; i < 3; ++i) {
1275 if (eigensystem.fGeometricMultiplicity[i] != 1) {
1278 for (
unsigned int j = 0; j < 3; ++j) {
1279 for (
unsigned int k = j; k < 3; ++k) {
1280 eigentensors[i](j, k) = eigensystem.fEigenvectors[i][j] * eigensystem.fEigenvectors[i][k];
1284 if (indices_to_add.
size() > 0) {
1286 for (
auto i : indices_to_add) {
1287 sum += eigentensors[i];
1289 for (
auto i : indices_to_add) {
1290 eigentensors[i] = sum;
1296 for (i = 0; i < 3; i += eigensystem.fGeometricMultiplicity[i]) {
1297 total.
Add(eigentensors[i], eigenvalues[i]);
1300 std::cout <<
"Tensor decomposition error: " << std::endl;
1301 std::cout <<
"Incorrect total geometric multiplicity: " << i << std::endl;
1304 for (
unsigned int i = 0; i < 6; ++i) {
1305 if (!
AreEqual(total[i], this->
operator[](i), tol)) {
1306 std::cout << std::setprecision(15);
1307 std::cout <<
"Tensor decomposition error: " << std::endl;
1308 std::cout <<
"Original Tensor: ";
1309 this->
Print(std::cout);
1310 std::cout <<
"Reconstruction from decomposition: ";
1311 total.
Print(std::cout);
1312 std::cout <<
"Decomposition: " << std::endl;
1313 eigensystem.Print(std::cout);
1323 if (eigensystem.fDistinctEigenvalues == 0) {
1329 switch (eigensystem.fDistinctEigenvalues) {
1331 eigensystem.fEigenvectors[0][0] = 1.;
1332 eigensystem.fEigenvectors[1][1] = 1.;
1333 eigensystem.fEigenvectors[2][2] = 1.;
1340 for (
unsigned int i = 0; i < 3; ++i) {
1342 for (j = 0; j < 3; ++j) {
1343 if (
AreEqual(eigensystem.fEigenvalues[i], this->operator()(j, j), tol)) {
1344 eigensystem.fEigenvectors[i][j] = 1;
1353 REAL conditionFactor;
1358 eigensystem.fEigenvectors = eigensystemTemp.fEigenvectors;
1368 for (
unsigned int lambda = 0; lambda < 3; ++lambda) {
1370 for (
unsigned int i = 0; i < 3; ++i) {
1374 for (
unsigned int i = 0; i < 3; ++i) {
1375 eigensystem.fEigenvectors[lambda][i] /=
Norm;
1382 const int p = DistinctEigenvalues.
NElements();
1385 for (
int count = 0; count < p; ++count) {
1386 const int j = DistinctEigenvalues[count];
1387 if (j == index)
continue;
1389 local *= -1. * EigenVals[j];
1397 local *= 1. / (EigenVals[index] - EigenVals[j]);
1399 aux.Multiply(local, resultingTensor);
1400 Ei[
_XX_] = resultingTensor(0, 0);
1401 Ei[
_XY_] = resultingTensor(0, 1);
1402 Ei[
_XZ_] = resultingTensor(0, 2);
1403 Ei[
_YY_] = resultingTensor(1, 1);
1404 Ei[
_YZ_] = resultingTensor(1, 2);
1405 Ei[
_ZZ_] = resultingTensor(2, 2);
1416 row0[0] =
XX() - eigenvalue;
1421 row1[1] =
YY() - eigenvalue;
1426 row2[2] =
ZZ() - eigenvalue;
1428 Cross(row0, row1, r0xr1);
1430 Cross(row0, row2, r0xr2);
1432 Cross(row1, row2, r1xr2);
1433 T d0 =
Dot(r0xr1, r0xr1);
1434 T d1 =
Dot(r0xr2, r0xr2);
1435 T d2 =
Dot(r1xr2, r1xr2);
1448 T inv_sqrt_val = 1. /
sqrt(d0);
1449 eigenvector[0] = r0xr1[0] * inv_sqrt_val;
1450 eigenvector[1] = r0xr1[1] * inv_sqrt_val;
1451 eigenvector[2] = r0xr1[2] * inv_sqrt_val;
1452 }
else if (imax == 1) {
1453 T inv_sqrt_val = 1. /
sqrt(d1);
1454 eigenvector[0] = r0xr2[0] * inv_sqrt_val;
1455 eigenvector[1] = r0xr2[1] * inv_sqrt_val;
1456 eigenvector[2] = r0xr2[2] * inv_sqrt_val;
1458 T inv_sqrt_val = 1. /
sqrt(d2);
1459 eigenvector[0] = r1xr2[0] * inv_sqrt_val;
1460 eigenvector[1] = r1xr2[1] * inv_sqrt_val;
1461 eigenvector[2] = r1xr2[2] * inv_sqrt_val;
1473 if (
fabs(eigenvector0[0]) >
fabs(eigenvector0[1])) {
1475 invLength = (T) 1 /
sqrt(eigenvector0[0] * eigenvector0[0] + eigenvector0[2] * eigenvector0[2]);
1476 U[0] = -eigenvector0[2] * invLength;
1478 U[2] = +eigenvector0[0] * invLength;
1481 invLength = (T) 1 /
sqrt(eigenvector0[1] * eigenvector0[1] + eigenvector0[2] * eigenvector0[2]);
1483 U[1] = +eigenvector0[2] * invLength;
1484 U[2] = -eigenvector0[1] * invLength;
1486 Cross(eigenvector0, U, V);
1505 AU[0] =
XX() * U[0] +
XY() * U[1] +
XZ() * U[2];
1506 AU[1] =
XY() * U[0] +
YY() * U[1] +
YZ() * U[2];
1507 AU[2] =
XZ() * U[0] +
YZ() * U[1] +
ZZ() * U[2];
1510 AV[0] =
XX() * V[0] +
XY() * V[1] +
XZ() * V[2];
1511 AV[1] =
XY() * V[0] +
YY() * V[1] +
YZ() * V[2];
1512 AV[2] =
XZ() * V[0] +
YZ() * V[1] +
ZZ() * V[2];
1514 T m00 = U[0] * AU[0] + U[1] * AU[1] + U[2] * AU[2] - eigenvalue1;
1515 T m01 = U[0] * AV[0] + U[1] * AV[1] + U[2] * AV[2];
1516 T m11 = V[0] * AV[0] + V[1] * AV[1] + V[2] * AV[2] - eigenvalue1;
1527 if (absM00 >= absM11) {
1528 maxAbsComp = max(absM00, absM01);
1532 if (absM00 >= absM01) {
1534 m00 = T(1.) /
sqrt(T(1.) + m01 * m01);
1538 m01 = T(1.) /
sqrt(T(1.) + m00 * m00);
1544 saxpy(eigenvector1, V, -m00);
1547 maxAbsComp = std::max(absM11, absM01);
1551 if (absM11 >= absM01) {
1553 m11 = T(1.) /
sqrt(T(1.) + m01 * m01);
1557 m01 = T(1.) /
sqrt(T(1.) + m11 * m11);
1563 saxpy(eigenvector1, V, -m01);
1579 if (eigensystem.fGeometricMultiplicity[0] == 1) {
1582 Cross(eigenvec[0], eigenvec[1], eigenvec[2]);
1586 Cross(eigenvec[1], eigenvec[2], eigenvec[0]);
1598 conditionFactor = max(max(max0, max1), max2);
1600 REAL invMaxAbsElement = 1. / conditionFactor;
1601 for (
unsigned int i = 0; i < 6; ++i) {
1602 A.
fData[i] = this->fData[i] * invMaxAbsElement;
1604 if (decomposition.fDistinctEigenvalues != 0) {
1605 decomposition.fEigenvalues[0] *= invMaxAbsElement;
1606 decomposition.fEigenvalues[1] *= invMaxAbsElement;
1607 decomposition.fEigenvalues[2] *= invMaxAbsElement;
1615 REAL conditionFactor;
1624 T traceDiv3 = A.
I1() / 3.;
1625 T b00 = A.
XX() - traceDiv3;
1626 T b11 = A.
YY() - traceDiv3;
1627 T b22 = A.
ZZ() - traceDiv3;
1628 T denom =
sqrt((
pow(b00, 2.) +
pow(b11, 2.) +
pow(b22, 2.) + norm * T(2.)) / T(6.));
1629 T c00 = b11 * b22 - A.
YZ() * A.
YZ();
1630 T c01 = A.
XY() * b22 - A.
YZ() * A.
XZ();
1631 T c02 = A.
XY() * A.
YZ() - b11 * A.
XZ();
1632 T det = (b00 * c00 - A.
XY() * c01 + A.
XZ() * c02) / (denom * denom * denom);
1633 T halfDet = det * T(0.5);
1640 const T twoThirdsPi = T(2.09439510239319549);
1641 T beta2 =
cos(angle) * T(2.);
1642 T beta0 =
cos(angle + twoThirdsPi) * T(2.);
1643 T beta1 = -(beta0 + beta2);
1646 eigenval[0] = traceDiv3 + denom * beta2;
1647 eigenval[1] = traceDiv3 + denom * beta1;
1648 eigenval[2] = traceDiv3 + denom * beta0;
1650 if (eigenval[0] < eigenval[1]) {
1654 if (eigenval[1] < eigenval[2]) {
1658 if (halfDet > 0. ||
IsZeroVal(halfDet)) {
1659 eigensystem.fGeometricMultiplicity[0] = 1;
1661 eigensystem.fGeometricMultiplicity[2] = 1;
1664 if (compute_eigenvectors) {
1669 eigenval[0] *= conditionFactor;
1670 eigenval[1] *= conditionFactor;
1671 eigenval[2] *= conditionFactor;
1680 T sqrtJ2t =
sqrt(J2t);
1696 T lodetemp = (T(3.) *
sqrt(T(3.)) * J3t) / (T(2.) *
sqrt(J2t * J2t * J2t));
1698 lodetemp *= T(0.999);
1709 lodetemp *= T(0.999);
1717 T j33 = T(3.) * J3t;
1720 T j22 = T(2.) * J2t;
1726 T checknegativeroot = ((T(9.) * J3t * J3t) / (J2t * J2t * J2t));
1728 T denom = T(2.) *
sqrt(J2t * J2t * J2t * J2t * J2t) *
sqrt((T(4 / 3.)) - checknegativeroot);
1730 T oneoverden = T(1.) / denom;
1735 T acoslodetemp =
acos(lodetemp);
1736 Lode = acoslodetemp / T(3.);
1751 T sqrtJ2 =
sqrt(J2);
1761 T pi23 = T(2. * M_PI / 3.);
1762 T TwoOverSqrThree = T(2. /
sqrt(3.));
1763 T TwoOverSqrThreeJ2 = TwoOverSqrThree * sqrtJ2;
1766 T tempCosLode =
cos(Lode) * TwoOverSqrThreeJ2;
1767 T tempCosMinusLode =
cos(Lode - pi23) * TwoOverSqrThreeJ2;
1768 T tempCosPlusLode =
cos(Lode + pi23) * TwoOverSqrThreeJ2;
1771 cout <<
"Lode angle é Menor que ZERO. Valido somente para sig1 > sig2 > sig3 -> 0 < theta < Pi/3 " << endl;
1775 cout <<
"Lode angle é Maior que Pi/3. Valido somente para sig1 > sig2 > sig3 -> 0 < theta < Pi/3 " << endl;
1782 eigenval.
XX() = I13 + tempCosLode;
1783 eigenval.
YY() = I13 + tempCosMinusLode;
1784 eigenval.
ZZ() = I13 + tempCosPlusLode;
1785 eigenval.
XY() *= T(0.);
1786 eigenval.
XZ() *= T(0.);
1787 eigenval.
YZ() *= T(0.);
1794 std::stringstream sout;
1795 sout <<
"\n TPZTENSOR \n" << endl;
1796 sout <<
"\n LodeAngle = \n" << Lode << endl;
1797 sout <<
"\n dLodeAngle= " << dLode << endl;
1805 T OneOverTwoJ2 = T(0.5) /
J2;
1810 tempCosLode *= OneOverTwoJ2;
1811 tempCosMinusLode *= OneOverTwoJ2;
1812 tempCosPlusLode *= OneOverTwoJ2;
1815 dSigma1 *= tempCosLode;
1818 dLodeAngleTemp *=
sin(Lode) * TwoOverSqrThreeJ2;
1819 dSigma1 -= dLodeAngleTemp;
1822 dSigma2 *= tempCosMinusLode;
1824 dLodeAngleTemp = dLode;
1825 dLodeAngleTemp *=
sin(pi23 - Lode) * TwoOverSqrThreeJ2;
1826 dSigma2 += dLodeAngleTemp;
1829 dSigma3 *= tempCosPlusLode;
1831 dLodeAngleTemp = dLode;
1832 dLodeAngleTemp *=
sin(pi23 + Lode) * TwoOverSqrThreeJ2;
1833 dSigma3 -= dLodeAngleTemp;
1838 output <<
"XX = " <<
XX() <<
"\nXY = " <<
XY() <<
"\nXZ = " <<
XZ() <<
"\nYY = " <<
YY() <<
"\nYZ = " <<
YZ() <<
"\nZZ = " <<
ZZ() << std::endl;
1843 output <<
"XX = " <<
XX() <<
"\nXY = " <<
XY() <<
"\nXZ = " <<
XZ() <<
"\nYY = " <<
YY() <<
"\nYZ = " <<
YZ() <<
"\nZZ = " <<
ZZ() << std::endl;
1848 output <<
"XX = " <<
XX() <<
" XY = " <<
XY() <<
" XZ = " <<
XZ() <<
" YY = " <<
YY() <<
" YZ = " <<
YZ() <<
" ZZ = " <<
ZZ() << std::endl;
1851 #endif //TPZTENSOR_H
void Print(std::ostream &out=std::cout)
Prints the structural information of the vector object to the output stream. This method will not p...
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ fabs
void CopyTo(TPZTensor< T1 > &target) const
void Add(const TPZTensor< T1 > &tensor, const T2 &constant)
void CopyFrom(const TPZFMatrix< T > &source)
void Multiply(const T1 &multipl, const T2 &constant)
void Print(std::ostream &out) const
T & operator()(const int64_t row, const int64_t col)
Contains definitions to LOGPZ_DEBUG, LOGPZ_INFO, LOGPZ_WARN, LOGPZ_ERROR and LOGPZ_FATAL, and the implementation of the inline InitializePZLOG(string) function using log4cxx library or not. It must to be called out of "#ifdef LOG4CXX" scope.
void DeviatoricDiagonal_T(TPZVec< T > &vec) const
TPZManVector< T, 6 > fData
virtual void resize(const int64_t newsize)
void Write(TPZStream &buf, int withclassid) const override
Method to write to a pzstream.
void ComputeEigenvectors(TPZDecomposed &eigensystem) const
void Read(TPZStream &buf, void *context) override
Method to read the object from a pzstream.
virtual bool SolveEigensystemJacobi(int64_t &numiterations, REAL &tol, TPZVec< TVar > &Eigenvalues, TPZFMatrix< TVar > &Eigenvectors) const
Compute Eigenvalues and Eigenvectors of this matrix. This method is efficient only for small matrice...
void EigenProjection(const TPZVec< T > &EigenVals, int index, const TPZVec< int > &DistinctEigenvalues, TPZTensor< T > &Ei) const
virtual const TVar & Get(const int64_t row, const int64_t col) const
Get value with bound checking.
void ComputeEigenvectorsInternal(TPZDecomposed &eigensystem) const
TPZTensor(const TPZTensor< T > &source)
static void ResidualCheckConv(TPZFMatrix< STATE > &state, TPZFMatrix< STATE > &residual, int icase)
Compute the residual for a particular state.
TVar Dot(const TPZFMatrix< TVar > &A, const TPZFMatrix< TVar > &B)
Implement dot product for matrices.
void ComputeEigenvector1(const TPZManVector< T, 3 > &eigenvector0, const T &eigenvalue1, TPZManVector< T, 3 > &eigenvector1) const
clarg::argString input("-if", "input file", "cube1.txt")
This class implements a simple vector storage scheme for a templated class T. Utility.
REAL val(STATE &number)
Returns value of the variable.
void ComputeEigenvalues(TPZDecomposed &eigensystem, const bool compute_eigenvectors=false) const
TPZManVector< TPZTensor< T >, 3 > fEigentensors
void DeviatoricDiagonal(TPZVec< T > &vec) const
TPZTensor< T > operator*(const T &multipl) const
void Precondition(REAL &conditionFactor, TPZTensor< T > &A, TPZDecomposed &decomposition) const
bool AreEqual(const T &val1, const T &val2, const T tol=T(1.e-9)) const
void saxpy(TPZVec< T1 > &x, const TPZVec< T2 > &y, Scalar s)
Performs a saxpy operation: x <- x + s * y.
T & operator()(const int64_t row, const int64_t col) const
unsigned int fDistinctEigenvalues
int ClassId() const override
Define the class id associated with the class.
void DirectEigenValues(TPZDecomposed &eigensystem, bool compute_eigenvectors) const
const TPZTensor< T > & operator*=(const T &multipl)
static void TangentCheckConv(TPZFMatrix< STATE > &state, TPZFMatrix< STATE > &tangent, int icase)
Compute the tangent matrix for a particular case.
TPZManVector< unsigned int, 3 > fGeometricMultiplicity
void HaighWestergaard(T &LodeAngle, T &qsi, T &rho) const
int64_t size() const
Returns the number of elements of the vector.
expr_ expr_ expr_ expr_ acos
#define LOGPZ_INFO(A, B)
Define log for informations.
void CopyToTensor(TPZFMatrix< T > &Tensor) const
TPZDecomposed(const TPZDecomposed ©)
virtual void Write(const bool val)
TPZTensor< T > operator-(const TPZTensor< T > &source) const
Contains TPZMatrixclass which implements full matrix (using column major representation).
#define DebugStop()
Returns a message to user put a breakpoint in.
static T Polynom(const T &x, const T &I1, const T &I2, const T &I3)
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
void dJ3(TPZTensor< T > &deriv) const
void EigenSystem(TPZDecomposed &eigensystem) const
void Lodeangle(TPZTensor< T > &GradLode, T &Lode) const
void dJ2(TPZTensor< T > &Tangent) const
Free store vector implementation.
void sscal(TPZVec< T1 > &x, const Scalar s)
Performs a sscal operation: x <- x * s.
void Scale(const T2 &constant)
TPZTensor(const TPZFMatrix< T > &input)
int64_t Rows() const
Returns number of rows.
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
void SetUp(const TPZVec< REAL > &Solution)
bool IsZeroTensor(T tol=1.e-9) const
void EigenVector(TPZVec< TPZVec< T > > &eigVec) const
TPZManVector< TPZManVector< T, 3 >, 3 > fEigenvectors
void Adjust(TPZVec< T > &sigIJ, TPZTensor< T > &result) const
adjust the tensor to the given values of I1 and sqj2
void EigenSystemJacobi(TPZDecomposed &eigensystem) const
T & operator[](int i) const
#define LOGPZ_ERROR(A, B)
Define log for errors (cout)
const TPZTensor< T > & operator+=(const TPZTensor< T > &source)
int32_t Hash(std::string str)
void Print(std::ostream &out) const
static REAL angle
Angle in radians to test.
void ApplyStrainComputeElasticStress(TPZTensor< T > &Stress, REAL &K, REAL &G)
void ComputeEigenvector0(const T &eigenvalue, TPZManVector< T, 3 > &eigenvector) const
void Eigenvalue(TPZTensor< T > &eigenval, TPZTensor< T > &dSigma1, TPZTensor< T > &dSigma2, TPZTensor< T > &dSigma3) const
TPZFlopCounter pow(const TPZFlopCounter &orig, const TPZFlopCounter &xp)
Returns the power and increments the counter of the power.
This class implements a stack object. Utility.
static T DerivPolynom(const T &x, const T &I1, const T &I2, const T &I3)
static int NumCasesCheckConv()
Number of test cases implemented by this class.
TPZTensor< T > operator+(const TPZTensor< T > &source) const
static T & NonNegative(T &value)
static bool IsZeroVal(const T &val, T tol=1.e-9)
TPZDecomposed(const TPZTensor< T > &source)
static T UpdateNewton(const T &x, const T &I1, const T &I2, const T &I3)
int64_t Cols() const
Returns number of cols.
virtual void Print(std::ostream &out) const
int Resize(const int64_t newRows, const int64_t wCols) override
Redimension a matrix, but maintain your elements.
TPZManVector< T, 3 > fEigenvalues
Defines the interface for saving and reading data. Persistency.
int64_t NElements() const
Returns the number of elements of the vector.
const TPZTensor< T > & operator-=(const TPZTensor< T > &source)
const TPZTensor< T > & operator=(const TPZTensor< T > &source)
REAL ZeroTolerance()
Returns the tolerance to Zero value. Actually: .
This class defines the interface to save and restore objects from TPZStream objects. Persistency.
TPZFlopCounter cos(const TPZFlopCounter &orig)
Returns the cosine in radians and increments the counter of the Cosine.
TPZDecomposed & operator=(const TPZDecomposed ©)
void push_back(const T object)
const TVar & GetVal(const int64_t row, const int64_t col) const override
Get values without bounds checking This method is faster than "Get" if DEBUG is defined.
bool IsDiagonal(T tol=1.e-9) const
TPZTensor(const TPZDecomposed &eigensystem)
void S(TPZTensor< T > &s) const
void Cross(const TPZVec< T > &x1, const TPZVec< T > &x2, TPZVec< T > &result)
virtual void Read(bool &val)
void dDet(TPZTensor< T > &grad) const