v0.10.0
Public Member Functions | Private Attributes | List of all members
OpElasticTools::OpCalculateLogStressTangent Struct Reference

#include <users_modules/multifield_plasticity/src/ElasticOperators.hpp>

Inheritance diagram for OpElasticTools::OpCalculateLogStressTangent:
[legend]
Collaboration diagram for OpElasticTools::OpCalculateLogStressTangent:
[legend]

Public Member Functions

 OpCalculateLogStressTangent (const std::string field_name, boost::shared_ptr< CommonData > common_data_ptr)
 
MoFEMErrorCode doWork (int side, EntityType type, EntData &data)
 [Calculate stress] More...
 
- Public Member Functions inherited from MoFEM::FaceElementForcesAndSourcesCoreBase::UserDataOperator
double getArea ()
 get area of face More...
 
double getMeasure ()
 get measure of element More...
 
VectorDoublegetNormal ()
 get triangle normal More...
 
VectorDoublegetTangent1 ()
 get triangle tangent 1 More...
 
VectorDoublegetTangent2 ()
 get triangle tangent 2 More...
 
auto getFTensor1Normal ()
 get normal as tensor More...
 
auto getFTensor1Tangent1 ()
 get tangentOne as tensor More...
 
auto getFTensor1Tangent2 ()
 get tangentTwo as tensor More...
 
int getNumNodes ()
 get element number of nodes More...
 
const EntityHandlegetConn ()
 get element connectivity More...
 
VectorDoublegetCoords ()
 get triangle coordinates More...
 
auto getFTensor1Coords ()
 get get coords at gauss points More...
 
MatrixDoublegetCoordsAtGaussPts ()
 Gauss points and weight, matrix (nb. of points x 3) More...
 
auto getFTensor1CoordsAtGaussPts ()
 get coordinates at Gauss pts. More...
 
MatrixDoublegetHoCoordsAtGaussPts ()
 coordinate at Gauss points (if hierarchical approximation of element geometry) More...
 
auto getFTensor1HoCoordsAtGaussPts ()
 get coordinates at Gauss pts (takes in account ho approx. of geometry) More...
 
MatrixDoublegetNormalsAtGaussPts ()
 if higher order geometry return normals at Gauss pts. More...
 
DEPRECATED MatrixDoublegetNormalsAtGaussPt ()
 
ublas::matrix_row< MatrixDoublegetNormalsAtGaussPts (const int gg)
 if higher order geometry return normals at Gauss pts. More...
 
DEPRECATED ublas::matrix_row< MatrixDoublegetNormalsAtGaussPt (const int gg)
 
MatrixDoublegetTangent1AtGaussPts ()
 if higher order geometry return tangent vector to triangle at Gauss pts. More...
 
MatrixDoublegetTangent2AtGaussPts ()
 if higher order geometry return tangent vector to triangle at Gauss pts. More...
 
auto getFTensor1NormalsAtGaussPts ()
 get normal at integration points More...
 
auto getFTensor1Tangent1AtGaussPts ()
 get tangent 1 at integration points More...
 
auto getFTensor1Tangent2AtGaussPts ()
 get tangent 2 at integration points More...
 
const FaceElementForcesAndSourcesCoreBasegetFaceFE ()
 return pointer to Generic Triangle Finite Element object More...
 
DEPRECATED const FaceElementForcesAndSourcesCoreBasegetFaceElementForcesAndSourcesCore ()
 
template<int SWITCH>
MoFEMErrorCode loopSideVolumes (const string &fe_name, VolumeElementForcesAndSourcesCoreOnSideSwitch< SWITCH > &fe_method)
 
- Public Member Functions inherited from MoFEM::ForcesAndSourcesCore::UserDataOperator
 UserDataOperator (const FieldSpace space, const char type=OPLAST, const bool symm=true)
 
 UserDataOperator (const std::string &field_name, const char type, const bool symm=true)
 
 UserDataOperator (const std::string &row_field_name, const std::string &col_field_name, const char type, const bool symm=true)
 
boost::shared_ptr< const NumeredEntFiniteElementgetNumeredEntFiniteElementPtr () const
 Return raw pointer to NumeredEntFiniteElement. More...
 
EntityHandle getFEEntityHandle () const
 Return finite element entity handle. More...
 
boost::weak_ptr< SideNumber > getSideNumberPtr (const int side_number, const EntityType type)
 Get the side number pointer. More...
 
EntityHandle getSideEntity (const int side_number, const EntityType type)
 Get the side entity. More...
 
int getNumberOfNodesOnElement ()
 Get the number of nodes on finite element. More...
 
MoFEMErrorCode getProblemRowIndices (const std::string filed_name, const EntityType type, const int side, VectorInt &indices) const
 Get row indices. More...
 
MoFEMErrorCode getProblemColIndices (const std::string filed_name, const EntityType type, const int side, VectorInt &indices) const
 Get col indices. More...
 
const FEMethodgetFEMethod () const
 Return raw pointer to Finite Element Method object. More...
 
int getOpType () const
 Get operator types. More...
 
void setOpType (const OpType type)
 Set operator type. More...
 
void addOpType (const OpType type)
 Add operator type. More...
 
int getNinTheLoop () const
 get number of finite element in the loop More...
 
int getLoopSize () const
 get size of elements in the loop More...
 
const std::string & getFEName () const
 Get name of the element. More...
 
const PetscData::SwitchesgetDataCtx () const
 
const KspMethod::KSPContext getKSPCtx () const
 
const SnesMethod::SNESContext getSNESCtx () const
 
const TSMethod::TSContext getTSCtx () const
 
Vec getKSPf () const
 
Mat getKSPA () const
 
Mat getKSPB () const
 
Vec getSNESf () const
 
Vec getSNESx () const
 
Mat getSNESA () const
 
Mat getSNESB () const
 
DEPRECATED Vec getSnesF () const
 
DEPRECATED Vec getSnesX () const
 
DEPRECATED Mat getSnesA () const
 
DEPRECATED Mat getSnesB () const
 
Vec getTSu () const
 
Vec getTSu_t () const
 
Vec getTSu_tt () const
 
Vec getTSf () const
 
Mat getTSA () const
 
Mat getTSB () const
 
int getTSstep () const
 
double getTStime () const
 
double getTSa () const
 
MatrixDoublegetGaussPts ()
 matrix of integration (Gauss) points for Volume Element More...
 
auto getFTensor0IntegrationWeight ()
 Get integration weights. More...
 
DEPRECATED MoFEMErrorCode getPorblemRowIndices (const std::string filed_name, const EntityType type, const int side, VectorInt &indices) const
 
- Public Member Functions inherited from MoFEM::DataOperator
 DataOperator (const bool symm=true)
 
virtual ~DataOperator ()=default
 
virtual MoFEMErrorCode doWork (int row_side, int col_side, EntityType row_type, EntityType col_type, DataForcesAndSourcesCore::EntData &row_data, DataForcesAndSourcesCore::EntData &col_data)
 Operator for bi-linear form, usually to calculate values on left hand side. More...
 
virtual MoFEMErrorCode opLhs (DataForcesAndSourcesCore &row_data, DataForcesAndSourcesCore &col_data)
 
virtual MoFEMErrorCode opRhs (DataForcesAndSourcesCore &data, const bool error_if_no_base=false)
 
bool getSymm () const
 Get if operator uses symmetry of DOFs or not. More...
 
void setSymm ()
 set if operator is executed taking in account symmetry More...
 
void unSetSymm ()
 unset if operator is executed for non symmetric problem More...
 

Private Attributes

boost::shared_ptr< CommonDatacommonDataPtr
 

Additional Inherited Members

- Public Types inherited from MoFEM::ForcesAndSourcesCore::UserDataOperator
enum  OpType { OPROW = 1 << 0, OPCOL = 1 << 1, OPROWCOL = 1 << 2, OPLAST = 1 << 3 }
 Controls loop over entities on element. More...
 
- Public Attributes inherited from MoFEM::ForcesAndSourcesCore::UserDataOperator
char opType
 
std::string rowFieldName
 
std::string colFieldName
 
FieldSpace sPace
 
- Public Attributes inherited from MoFEM::DataOperator
bool sYmm
 If true assume that matrix is symmetric structure. More...
 
std::array< bool, MBMAXTYPE > doEntities
 If true operator is executed for entity. More...
 
booldoVertices
 \deprectaed If false skip vertices More...
 
booldoEdges
 \deprectaed If false skip edges More...
 
booldoQuads
 \deprectaed More...
 
booldoTris
 \deprectaed More...
 
booldoTets
 \deprectaed More...
 
booldoPrisms
 \deprectaed More...
 
- Protected Member Functions inherited from MoFEM::ForcesAndSourcesCore::UserDataOperator
ForcesAndSourcesCoregetPtrFE () const
 
ForcesAndSourcesCoregetSidePtrFE () const
 
- Protected Attributes inherited from MoFEM::ForcesAndSourcesCore::UserDataOperator
ForcesAndSourcesCoreptrFE
 

Detailed Description

Definition at line 792 of file ElasticOperators.hpp.

Constructor & Destructor Documentation

◆ OpCalculateLogStressTangent()

OpElasticTools::OpCalculateLogStressTangent::OpCalculateLogStressTangent ( const std::string  field_name,
boost::shared_ptr< CommonData common_data_ptr 
)

Definition at line 154 of file ElasticOperators.cpp.

156  : DomainEleOp(field_name, DomainEleOp::OPROW),
157  commonDataPtr(common_data_ptr) {
158  // Operator is only executed for vertices
159  std::fill(&doEntities[MBEDGE], &doEntities[MBMAXTYPE], false);
160 }
std::array< bool, MBMAXTYPE > doEntities
If true operator is executed for entity.
boost::shared_ptr< CommonData > commonDataPtr
DomainEle::UserDataOperator DomainEleOp

Member Function Documentation

◆ doWork()

MoFEMErrorCode OpElasticTools::OpCalculateLogStressTangent::doWork ( int  side,
EntityType  type,
EntData data 
)
virtual

[Calculate stress]

Reimplemented from MoFEM::DataOperator.

Definition at line 163 of file ElasticOperators.cpp.

164  {
166 
167  const size_t nb_gauss_pts = commonDataPtr->mStrainPtr->size2();
168  auto &t_D = commonDataPtr->tD;
169  auto t_stress = getFTensor2SymmetricFromMat<3>(*(commonDataPtr->mStressPtr));
170  // auto t_grad = getFTensor2FromMat<3, 3>(*(commonDataPtr->mGradPtr));
171  auto F = getFTensor2FromMat<3, 3>(*(commonDataPtr->mDeformationGradient));
172  auto C = getFTensor2SymmetricFromMat<3>(*(commonDataPtr->matC));
173  auto t_eigen_vec = getFTensor2FromMat<3, 3>(*(commonDataPtr->matEigenVector));
174  auto t_eigen = getFTensor1FromMat<3>(*(commonDataPtr->matEigenVal));
175 
176  MatrixDouble &dP_dF = *(commonDataPtr->materialTangent);
177  dP_dF.resize(81, nb_gauss_pts, false);
178  MatrixDouble &dE_dF = *(commonDataPtr->dE_dF_mat);
179  dE_dF.resize(81, nb_gauss_pts, false);
180 
181  Tensor4<PackPtr<double *, 1>, 3, 3, 3, 3> D1(MAT_TO_TENSOR4_3D(dP_dF));
182  Tensor4<PackPtr<double *, 1>, 3, 3, 3, 3> D2(MAT_TO_TENSOR4_3D(dE_dF));
183 
184  constexpr auto t_kd = Kronecker_Delta<int>();
185 
186  for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
187 
188  const bool compute_tangent = (int)getTSCtx() == 3;
189 
190  auto my_new_L = calculate_nominal_moduli_TL(C, F, t_stress, t_eigen,
191  t_eigen_vec, D1, false);
192  D2(i, j, k, l) = my_new_L(i, j, k, l);
193 
194  if (compute_tangent) {
195  Tensor2<double, 3, 3> stress_tmp;
196  auto Piola = to_non_symm(t_stress);
197  stress_tmp(i, j) = Piola(i, j);
198  Piola(k, l) = stress_tmp(i, j) * my_new_L(i, j, k, l);
199  auto D1_from_fd_p = getDTensorFunction(*commonDataPtr, F, Piola);
200  D1(i, j, k, l) = D1_from_fd_p(i, j, k, l);
201  }
202 
203  if (true && compute_tangent) {
206  prod1(i, j, k, l) = t_D(i, j, m, n) * my_new_L(m, n, k, l);
207  prod3(i, j, k, l) = 0.;
208 
209  for (int i = 0; i != 3; ++i)
210  for (int j = 0; j != 3; ++j)
211  for (int k = 0; k != 3; ++k)
212  for (int l = 0; l != 3; ++l)
213  for (int m = 0; m != 3; ++m)
214  for (int n = 0; n != 3; ++n)
215  prod3(i, j, k, l) += my_new_L(m, n, i, j) * prod1(m, n, k, l);
216 
217  auto myRand = []() {
218  const double fMin = -1;
219  double f = (double)rand() / RAND_MAX;
220  return fMin + f * (1 - fMin);
221  };
222  // if (getTStime() > 0.4) {
223  if (true) {
224  Tensor2<double, 3, 3> test1(myRand(), myRand(), myRand(), myRand(),
225  myRand(), myRand(), myRand(), myRand(),
226  myRand());
227  Tensor2<double, 3, 3> test2;
229  test2(i, j) = test1(i, j) + kronecker_delta(i, j);
230  test(i, j) = test2(k, i) ^ test2(k, j);
231 
232  Tensor2<double, 3, 3> eig_vec;
233  int counter = 10000;
234  {
235 
236  // {
237  // cerr << "LAPACK: " << endl;
238  // MeasureTime time1;
239  // for (int n(0); n < counter; n++) {
240  // auto lnX = get_ln_X_lapack(test);
241  // if (n == 1)
242  // cout << lnX << endl;
243  // }
244  // }
245  // {
246  // cerr << "SOUZA: " << endl;
247  // MeasureTime time1;
248  // for (int n(0); n < counter; n++) {
249  // auto lnX = get_ln_X(test);
250  // if (n == 1)
251  // cout << lnX << endl;
252  // }
253  // }
254  // {
255  // cerr << "TAYLOR SERIES: " << endl;
256  // MeasureTime time1;
257  // for (int n(0); n < counter; n++) {
258  // auto lnX = get_log_map(test);
259  // if (n == 1)
260  // cout << lnX << endl;
261  // }
262  // }
263  // string wait;
264  // }
265  // {
266  // cerr << "LAPACK: " << endl;
267  // MeasureTime time1;
268  // for (int n(0); n < counter; n++) {
269  // auto d05lnX_dX =
270  // calculate_nominal_moduli_TL(test, F, t_stress, false);
271  // // if (n == 1)
272  // // cout << 05lnX_dX << endl;
273  // }
274  // }
275  // {
276  // cerr << "SOUZA: " << endl;
277  // MeasureTime time1;
278  // for (int n(0); n < counter; n++) {
279  // // auto d05lnX_dX = calculate_d_05lnX_dX(C);
280  // // auto d05lnX_dX = calculate_d_05lnX_dX(C);
281  // auto d05lnX_dX = getDTensorFunction(*commonDataPtr, test2,
282  // o_stress);
283  // // if (n == 1)
284  // // cout << 05lnX_dX << endl;
285  // }
286  // }
287  // {
288  // cerr << "TAYLOR SERIES: " << endl;
289  // MeasureTime time1;
290  // for (int n(0); n < counter; n++) {
291  // auto d05lnX_dX = get_diff_log_map(C);
292  // // if (n == 1)
293  // // cout << 05lnX_dX << endl;
294  // }
295  // }
296  string wait;
297  }
298  }
301  auto myp = calculate_nominal_moduli_TL(C, F, t_stress, t_eigen,
302  t_eigen_vec, myDs, true);
303  // D1(i, j, k, l) = test_TK(i, j, k, l);
304  // D1(i, j, k, l) = D1_from_fd(i, j, k, l) + prod3(i, j, k, l);
305  // D1_from_fd(i, j, k, l) *= 0.25;
306  myDFin(i, j, k, l) = myDs(i, j, k, l) + prod3(i, j, k, l);
307  // myDs(i, j, k, l) = D1_from_fd(i, j, k, l) + prod3(i, j, k, l);
308  // D1(i, j, m, n) = (*cache).II(i, m, k, n) * (0.5 * o_stress(k, j));
309  // auto myDs_symm = tensor4_to_ddg(myDs);
310  // myDs_symm(k, j, o, p) *= 0.25;
311  // D1_from_fd(k, j, m, n) += myDs_symm(k, j, o, p) * dC_dF(o, p, m, n);
312  // D1(i, j, m, n) += F(i, k) * D1_from_fd(k, j, m, n);
313  // D1(i, j, m, n) *= 0.5;
314  auto testL = get_diff_log_map(C);
315  testL(i, j, k, l) *= 0.5;
316 
318  dC_dF(i, j, k, l) = (t_kd(i, l) * F(k, j)) + (t_kd(j, l) * F(k, i));
319  // auto t_L = calculate_d_05lnX_dX(C);
320  D2(i, j, k, l) = testL(i, j, m, n) * dC_dF(m, n, k, l);
321 
322  double sum = 0;
323  double sum2 = 0;
324  for (int i = 0; i != 3; ++i)
325  for (int j = 0; j != 3; ++j)
326  for (int k = 0; k != 3; ++k)
327  for (int l = 0; l != 3; ++l) {
328  sum += abs(my_new_L(i, j, k, l) - D2(i, j, k, l));
329  sum2 += abs(myDFin(i, j, k, l) - D1(i, j, k, l));
330  // if (abs(myDFin(i, j, k, l) - D1(i, j, k, l)) > 1e-6)
331  cout << i << j << k << l << " "
332  << myDFin(i, j, k, l) / D1(i, j, k, l) << endl;
333  }
334  // D1(i, j, k, l) = myDFin(i, j, k, l);
335  if (getTStime() > 0.2)
336  string wait;
337  }
338 
339  ++t_eigen;
340  ++t_eigen_vec;
341  ++D1;
342  ++D2;
343  ++t_stress;
344  ++F;
345  ++C;
346  }
347 
349 }
auto get_diff_log_map(Tensor2_symmetric< T, 3 > &X)
auto calculate_nominal_moduli_TL(Tensor2_symmetric< T, 3 > &X, Tensor2< TP, 3, 3 > &F, Tensor2_symmetric< TP, 3 > &stress, Tensor1< T, 3 > &lambda, Tensor2< T, 3, 3 > &eig_vec, Tensor4< T3, 3, 3, 3, 3 > &TLs3, bool compute_tangent)
FTensor::Index< 'j', 2 > j
Definition: ElasticOps.hpp:27
#define MAT_TO_TENSOR4_3D(MAT)
ublas::matrix< double, ublas::row_major, DoubleAllocator > MatrixDouble
Definition: Types.hpp:76
Kronecker Delta class.
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:485
Tensor4< double, 3, 3, 3, 3 > getDTensorFunction(CommonData &common_data, Tensor2< T, 3, 3 > &F, Tensor2< double, 3, 3 > &t_stress)
static Index< 'n', 3 > n
boost::shared_ptr< CommonData > commonDataPtr
static Index< 'm', 3 > m
FTensor::Index< 'k', 2 > k
Definition: ElasticOps.hpp:28
FTensor::Index< 'i', 2 > i
[Common data]
Definition: ElasticOps.hpp:26
FTensor::Index< 'l', 2 > l
Definition: ElasticOps.hpp:29
Tensor2_Expr< Kronecker_Delta< T >, T, Dim0, Dim1, i, j > kronecker_delta(const Index< i, Dim0 > &, const Index< j, Dim1 > &)
Rank 2.
auto to_non_symm(T &symm)
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:415

Member Data Documentation

◆ commonDataPtr

boost::shared_ptr<CommonData> OpElasticTools::OpCalculateLogStressTangent::commonDataPtr
private

Definition at line 798 of file ElasticOperators.hpp.


The documentation for this struct was generated from the following files: