Trilinos based (stochastic) FEM solvers
linearizedElasticity.cpp
Go to the documentation of this file.
1 /*
2 Brian Staber (brian.staber@gmail.com)
3 */
4 
6 #include "fepp.hpp"
7 
9 }
10 
12  delete[] dof_on_boundary;
13 }
14 
16 
17  FEGraph = new Epetra_FECrsGraph(Copy,*StandardMap,100);
18  int eglob, node;
19  int *index;
20  index = new int [3*Mesh->el_type];
21 
22  for (int e_lid=0; e_lid<Mesh->n_local_cells; ++e_lid){
23  eglob = Mesh->local_cells[e_lid];
24  for (int inode=0; inode<Mesh->el_type; ++inode){
25  node = Mesh->cells_nodes[Mesh->el_type*eglob+inode];
26  for (int ddl=0; ddl<3; ++ddl){
27  index[3*inode+ddl] = 3*node+ddl;
28  }
29  }
30  for (int i=0; i<3*Mesh->el_type; ++i){
31  for (int j=0; j<3*Mesh->el_type; ++j){
32  FEGraph->InsertGlobalIndices(1, &index[i], 1, &index[j]);
33  }
34  }
35 
36  }
37  Comm->Barrier();
38  FEGraph->GlobalAssemble();
39  delete[] index;
40 }
41 
42 void linearizedElasticity::aztecSolver(Epetra_FECrsMatrix & A, Epetra_FEVector & b, Epetra_Vector & u, Teuchos::ParameterList & paramList){
43  u.PutScalar(0.0);
44  Epetra_LinearProblem problem;
45  AztecOO solver;
46  problem.SetOperator(&A);
47  problem.SetLHS(&u);
48  problem.SetRHS(&b);
49  solver.SetProblem(problem);
50  solver.SetParameters(paramList);
51  double tol = Teuchos::getParameter<double>(paramList,"AZ_tol");
52  int maxIter = Teuchos::getParameter<int>(paramList,"AZ_max_iter");
53  solver.Iterate(maxIter,tol);
54 }
55 
57 
58  int error;
59 
60  K.PutScalar(0.0);
61 
63 
64  Comm->Barrier();
65 
66  error=K.GlobalAssemble();
67  error=K.FillComplete();
68 }
69 
70 void linearizedElasticity::assembleMixedDirichletNeumann_homogeneousForcing(Epetra_FECrsMatrix & K, Epetra_FEVector & F){
71 
72  F.PutScalar(0.0);
73  K.PutScalar(0.0);
74 
77 
78  Comm->Barrier();
79 
80  K.GlobalAssemble();
81  K.FillComplete();
82  F.GlobalAssemble();
83 }
84 
85 void linearizedElasticity::assembleMixedDirichletNeumann_inhomogeneousForcing(Epetra_FECrsMatrix & K, Epetra_FEVector & F){
86 
87  F.PutScalar(0.0);
88  K.PutScalar(0.0);
89 
92 
93  Comm->Barrier();
94 
95  K.GlobalAssemble();
96  K.FillComplete();
97  F.GlobalAssemble();
98 }
99 
101 
102  int node, e_gid, error;
103  int n_gauss_points = Mesh->n_gauss_cells;
104  double gauss_weight;
105 
106  int *Indices_cells;
107  Indices_cells = new int [3*Mesh->el_type];
108 
109  Epetra_SerialDenseMatrix Ke(3*Mesh->el_type,3*Mesh->el_type);
110 
111  Epetra_SerialDenseMatrix tangent_matrix(6,6);
112  Epetra_SerialDenseMatrix dx_shape_functions(Mesh->el_type,3);
113  Epetra_SerialDenseMatrix matrix_B(6,3*Mesh->el_type);
114  Epetra_SerialDenseMatrix B_times_TM(3*Mesh->el_type,6);
115 
116  for (unsigned int e_lid=0; e_lid<Mesh->n_local_cells; ++e_lid){
117  e_gid = Mesh->local_cells[e_lid];
118 
119  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
120  node = Mesh->cells_nodes[Mesh->el_type*e_gid+inode];
121  for (int iddl=0; iddl<3; ++iddl){
122  Indices_cells[3*inode+iddl] = 3*node+iddl;
123  for (unsigned int jnode=0; jnode<Mesh->el_type; ++jnode){
124  for (int jddl=0; jddl<3; ++jddl){
125  Ke(3*inode+iddl,3*jnode+jddl) = 0.0;
126  }
127  }
128  }
129  }
130 
131  for (unsigned int gp=0; gp<n_gauss_points; ++gp){
132  gauss_weight = Mesh->gauss_weight_cells(gp);
133  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
134  dx_shape_functions(inode,0) = Mesh->DX_N_cells(gp+n_gauss_points*inode,e_lid);
135  dx_shape_functions(inode,1) = Mesh->DY_N_cells(gp+n_gauss_points*inode,e_lid);
136  dx_shape_functions(inode,2) = Mesh->DZ_N_cells(gp+n_gauss_points*inode,e_lid);
137  }
138 
139  compute_B_matrices(dx_shape_functions,matrix_B);
140  get_elasticity_tensor(e_lid, gp, tangent_matrix);
141 
142  error = B_times_TM.Multiply('T','N',gauss_weight*Mesh->detJac_cells(e_lid,gp),matrix_B,tangent_matrix,0.0);
143  error = Ke.Multiply('N','N',1.0,B_times_TM,matrix_B,1.0);
144  }
145 
146  for (unsigned int i=0; i<3*Mesh->el_type; ++i){
147  for (unsigned int j=0; j<3*Mesh->el_type; ++j){
148  error = K.SumIntoGlobalValues(1, &Indices_cells[i], 1, &Indices_cells[j], &Ke(i,j));
149  }
150  }
151  }
152  delete[] Indices_cells;
153 }
154 
155 void linearizedElasticity::stiffness_inhomogeneousForcing(Epetra_FECrsMatrix & K, Epetra_FEVector & F){
156 
157  int node, e_gid, error;
158  int n_gauss_points = Mesh->n_gauss_cells;
159  double gauss_weight;
160 
161  int *Indices_cells;
162  Indices_cells = new int [3*Mesh->el_type];
163 
164  Epetra_SerialDenseMatrix Ke(3*Mesh->el_type,3*Mesh->el_type);
165  Epetra_SerialDenseMatrix tangent_matrix(6,6);
166  Epetra_SerialDenseMatrix dx_shape_functions(Mesh->el_type,3), matrix_X(3,Mesh->el_type), xg(3,n_gauss_points);
167  Epetra_SerialDenseMatrix matrix_B(6,3*Mesh->el_type);
168  Epetra_SerialDenseMatrix B_times_TM(3*Mesh->el_type,6);
169  Epetra_SerialDenseVector fevol(3*Mesh->el_type), fvol(3);
170 
171  for (unsigned int e_lid=0; e_lid<Mesh->n_local_cells; ++e_lid){
172  e_gid = Mesh->local_cells[e_lid];
173  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
174  node = Mesh->cells_nodes[Mesh->el_type*e_gid+inode];
175  matrix_X(0,inode) = Mesh->nodes_coord[3*node+0];
176  matrix_X(1,inode) = Mesh->nodes_coord[3*node+1];
177  matrix_X(2,inode) = Mesh->nodes_coord[3*node+2];
178  for (int iddl=0; iddl<3; ++iddl){
179  Indices_cells[3*inode+iddl] = 3*node+iddl;
180  fevol(3*inode+iddl) = 0.0;
181  for (unsigned int jnode=0; jnode<Mesh->el_type; ++jnode){
182  for (int jddl=0; jddl<3; ++jddl){
183  Ke(3*inode+iddl,3*jnode+jddl) = 0.0;
184  }
185  }
186  }
187  }
188 
189  xg.Multiply('N','N',1.0,matrix_X,Mesh->N_cells,0.0);
190  for (unsigned int gp=0; gp<n_gauss_points; ++gp){
191  gauss_weight = Mesh->gauss_weight_cells(gp);
192  fvol = get_forcing(xg(0,gp),xg(1,gp),xg(2,gp),e_lid,gp);
193  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
194  dx_shape_functions(inode,0) = Mesh->DX_N_cells(gp+n_gauss_points*inode,e_lid);
195  dx_shape_functions(inode,1) = Mesh->DY_N_cells(gp+n_gauss_points*inode,e_lid);
196  dx_shape_functions(inode,2) = Mesh->DZ_N_cells(gp+n_gauss_points*inode,e_lid);
197  for (unsigned int iddl=0; iddl<3; ++iddl){
198  fevol(3*inode+iddl) += gauss_weight*fvol(iddl)*Mesh->N_cells(inode,gp)*Mesh->detJac_cells(e_lid,gp);
199  }
200  }
201  compute_B_matrices(dx_shape_functions,matrix_B);
202  get_elasticity_tensor(e_lid,gp,tangent_matrix);
203 
204  error = B_times_TM.Multiply('T','N',gauss_weight*Mesh->detJac_cells(e_lid,gp),matrix_B,tangent_matrix,0.0);
205  error = Ke.Multiply('N','N',1.0,B_times_TM,matrix_B,1.0);
206  }
207 
208  for (unsigned int i=0; i<3*Mesh->el_type; ++i){
209  error = F.SumIntoGlobalValues(1, &Indices_cells[i], &fevol(i));
210  for (unsigned int j=0; j<3*Mesh->el_type; ++j){
211  error = K.SumIntoGlobalValues(1, &Indices_cells[i], 1, &Indices_cells[j], &Ke(i,j));
212  }
213  }
214  }
215  delete[] Indices_cells;
216 }
217 
219 
220  int node;
221  int* Indexes;
222  unsigned int e_gid;
223  Indexes = new int [3*Mesh->face_type];
224 
225  int n_gauss_points = Mesh->n_gauss_faces;
226  double gauss_weight;
227 
228  Epetra_SerialDenseMatrix xg(3,n_gauss_points), matrix_X(3,Mesh->face_type);
229  Epetra_SerialDenseVector force(3*Mesh->face_type);
230  Epetra_SerialDenseVector dead_pressure(3);
231 
232  for (unsigned int e_lid=0; e_lid<Mesh->n_local_faces; ++e_lid){
233  e_gid = Mesh->local_faces[e_lid];
234  for (unsigned int inode=0; inode<Mesh->face_type; ++inode){
235  node = Mesh->faces_nodes[Mesh->face_type*e_gid+inode];
236  Indexes[3*inode+0] = 3*node+0;
237  Indexes[3*inode+1] = 3*node+1;
238  Indexes[3*inode+2] = 3*node+2;
239  matrix_X(0,inode) = Mesh->nodes_coord[3*node+0];
240  matrix_X(1,inode) = Mesh->nodes_coord[3*node+1];
241  matrix_X(2,inode) = Mesh->nodes_coord[3*node+2];
242  for (unsigned int iddl=0; iddl<3; ++iddl){
243  force(3*inode+iddl) = 0.0;
244  }
245  }
246  xg.Multiply('N','T',1.0,matrix_X,Mesh->N_faces,0.0);
247  for (unsigned int gp=0; gp<n_gauss_points; ++gp){
248  gauss_weight = Mesh->gauss_weight_faces(gp);
249  dead_pressure = get_neumannBc(matrix_X,xg,gp);
250  for (unsigned int inode=0; inode<Mesh->face_type; ++inode){
251  for (unsigned int iddl=0; iddl<3; ++iddl){
252  force(3*inode+iddl) += gauss_weight*dead_pressure(iddl)*Mesh->N_faces(gp,inode);
253  }
254  }
255  }
256  //std::cout << "\n";
257  for (unsigned int inode=0; inode<Mesh->face_type; ++inode){
258  for (unsigned int iddl=0; iddl<3; ++iddl){
259  F.SumIntoGlobalValues(1, &Indexes[3*inode+iddl], &force(3*inode+iddl));
260  }
261  }
262  }
263  delete[] Indexes;
264 }
265 
266 void linearizedElasticity::compute_B_matrices(Epetra_SerialDenseMatrix & dx_shape_functions, Epetra_SerialDenseMatrix & B){
267  double factor = 1.0/std::sqrt(2.0);
268  for (unsigned inode=0; inode<Mesh->el_type; ++inode){
269  B(0,3*inode) = dx_shape_functions(inode,0);
270  B(0,3*inode+1) = 0.0;
271  B(0,3*inode+2) = 0.0;
272 
273  B(1,3*inode) = 0.0;
274  B(1,3*inode+1) = dx_shape_functions(inode,1);
275  B(1,3*inode+2) = 0.0;
276 
277  B(2,3*inode) = 0.0;
278  B(2,3*inode+1) = 0.0;
279  B(2,3*inode+2) = dx_shape_functions(inode,2);
280 
281  B(3,3*inode) = 0.0;
282  B(3,3*inode+1) = factor*dx_shape_functions(inode,2);
283  B(3,3*inode+2) = factor*dx_shape_functions(inode,1);
284 
285  B(4,3*inode) = factor*dx_shape_functions(inode,2);
286  B(4,3*inode+1) = 0.0;
287  B(4,3*inode+2) = factor*dx_shape_functions(inode,0);
288 
289  B(5,3*inode) = factor*dx_shape_functions(inode,1);
290  B(5,3*inode+1) = factor*dx_shape_functions(inode,0);
291  B(5,3*inode+2) = 0.0;
292  }
293 }
294 
295 int linearizedElasticity::print_solution(Epetra_Vector & solution, std::string fileName){
296 
297  int NumTargetElements = 0;
298  if (Comm->MyPID()==0){
299  NumTargetElements = 3*Mesh->n_nodes;
300  }
301  Epetra_Map MapOnRoot(-1,NumTargetElements,0,*Comm);
302  Epetra_Export ExportOnRoot(*StandardMap,MapOnRoot);
303  Epetra_MultiVector lhs_root(MapOnRoot,true);
304  lhs_root.Export(solution,ExportOnRoot,Insert);
305 
306  int error = EpetraExt::MultiVectorToMatrixMarketFile(fileName.c_str(),lhs_root,0,0,false);
307 
308  return error;
309 
310 }
311 
312 void linearizedElasticity::compute_deformation(Epetra_Vector & x, std::string & filename, bool printCauchy, bool printVM){
313 
314  Epetra_Vector u(*OverlapMap);
315  u.Import(x, *ImportToOverlapMap, Insert);
316 
317  Epetra_Map CellsMap(-1,Mesh->n_local_cells,&Mesh->local_cells[0],0,*Comm);
318  Epetra_Vector epsilon11(CellsMap); epsilon11.PutScalar(0.0);
319  Epetra_Vector epsilon22(CellsMap); epsilon22.PutScalar(0.0);
320  Epetra_Vector epsilon33(CellsMap); epsilon33.PutScalar(0.0);
321  Epetra_Vector epsilon12(CellsMap); epsilon12.PutScalar(0.0);
322  Epetra_Vector epsilon13(CellsMap); epsilon13.PutScalar(0.0);
323  Epetra_Vector epsilon23(CellsMap); epsilon23.PutScalar(0.0);
324  Epetra_Vector vonmises(CellsMap); vonmises.PutScalar(0.0);
325 
326  int node, e_gid;
327  int n_gauss_points = Mesh->n_gauss_cells;
328  double det_jac_cells, gauss_weight, theta;
329 
330  Epetra_SerialDenseVector epsilon(6);
331  Epetra_SerialDenseVector vector_u(3*Mesh->el_type);
332  Epetra_SerialDenseMatrix matrix_B(6,3*Mesh->el_type);
333  Epetra_SerialDenseMatrix dx_shape_functions(Mesh->el_type,3);
334 
335  Epetra_SerialDenseMatrix matrix_X(3,Mesh->el_type);
336  Epetra_SerialDenseMatrix D(Mesh->el_type,3);
337  Epetra_SerialDenseMatrix JacobianMatrix(3,3);
338 
339  double xi = 0.0;
340  double eta = 0.0;
341  double zeta = 0.0;
342 
343  for (unsigned int e_lid=0; e_lid<Mesh->n_local_cells; ++e_lid){
344  e_gid = Mesh->local_cells[e_lid];
345 
346  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
347  node = Mesh->cells_nodes[Mesh->el_type*e_gid+inode];
348  matrix_X(0,inode) = Mesh->nodes_coord[3*node+0];
349  matrix_X(1,inode) = Mesh->nodes_coord[3*node+1];
350  matrix_X(2,inode) = Mesh->nodes_coord[3*node+2];
351  vector_u(3*inode+0) = u[OverlapMap->LID(3*node+0)];
352  vector_u(3*inode+1) = u[OverlapMap->LID(3*node+1)];
353  vector_u(3*inode+2) = u[OverlapMap->LID(3*node+2)];
354  }
355  for (unsigned int i=0; i<6; ++i){
356  epsilon(i) = 0.0;
357  }
358 
359  switch (Mesh->el_type){
360  case 4:
361  tetra4::d_shape_functions(D, xi, eta, zeta);
362  break;
363  case 8:
364  hexa8::d_shape_functions(D, xi, eta, zeta);
365  break;
366  case 10:
367  tetra10::d_shape_functions(D, xi, eta, zeta);
368  break;
369  }
370 
371  jacobian_matrix(matrix_X,D,JacobianMatrix);
372  jacobian_det(JacobianMatrix,det_jac_cells);
373  dX_shape_functions(D,JacobianMatrix,det_jac_cells,dx_shape_functions);
374  compute_B_matrices(dx_shape_functions,matrix_B);
375  epsilon.Multiply('N','N',1.0,matrix_B,vector_u,0.0);
376 
377  epsilon11[e_lid] = epsilon(0);
378  epsilon22[e_lid] = epsilon(1);
379  epsilon33[e_lid] = epsilon(2);
380  epsilon12[e_lid] = epsilon(5);
381  epsilon13[e_lid] = epsilon(4);
382  epsilon23[e_lid] = epsilon(3);
383 
384  vonmises[e_lid] = std::sqrt( (epsilon11[e_lid]-epsilon22[e_lid])*(epsilon11[e_lid]-epsilon22[e_lid]) + (epsilon22[e_lid]-epsilon33[e_lid])*(epsilon22[e_lid]-epsilon33[e_lid]) + (epsilon33[e_lid]-epsilon11[e_lid])*(epsilon33[e_lid]-epsilon11[e_lid]) + 6.0*(epsilon23[e_lid]*epsilon23[e_lid] + epsilon13[e_lid]*epsilon13[e_lid] + epsilon12[e_lid]*epsilon12[e_lid]) );
385  }
386 
387  int NumTargetElements = 0;
388  if (Comm->MyPID()==0){
389  NumTargetElements = Mesh->n_cells;
390  }
391  Epetra_Map MapOnRoot(-1,NumTargetElements,0,*Comm);
392  Epetra_Export ExportOnRoot(CellsMap,MapOnRoot);
393  if (printCauchy){
394  /*Epetra_MultiVector lhs_root11(MapOnRoot,true);
395  lhs_root11.Export(epsilon11,ExportOnRoot,Insert);
396  std::string file11 = filename + "_epsilon11.mtx";
397  int error11 = EpetraExt::MultiVectorToMatrixMarketFile(file11.c_str(),lhs_root11,0,0,false);*/
398 
399  Epetra_MultiVector lhs_root22(MapOnRoot,true);
400  lhs_root22.Export(epsilon22,ExportOnRoot,Insert);
401  std::string file22 = filename + "_epsilon22.mtx";
402  int error22 = EpetraExt::MultiVectorToMatrixMarketFile(file22.c_str(),lhs_root22,0,0,false);
403 
404  /*Epetra_MultiVector lhs_root33(MapOnRoot,true);
405  lhs_root33.Export(epsilon33,ExportOnRoot,Insert);
406  std::string file33 = filename + "_epsilon33.mtx";
407  int error33 = EpetraExt::MultiVectorToMatrixMarketFile(file33.c_str(),lhs_root33,0,0,false);
408 
409  Epetra_MultiVector lhs_root12(MapOnRoot,true);
410  lhs_root12.Export(epsilon12,ExportOnRoot,Insert);
411  std::string file12 = filename + "_epsilon12.mtx";
412  int error12 = EpetraExt::MultiVectorToMatrixMarketFile(file12.c_str(),lhs_root12,0,0,false);
413 
414  Epetra_MultiVector lhs_root13(MapOnRoot,true);
415  lhs_root13.Export(epsilon13,ExportOnRoot,Insert);
416  std::string file13 = filename + "_epsilon13.mtx";
417  int error13 = EpetraExt::MultiVectorToMatrixMarketFile(file13.c_str(),lhs_root13,0,0,false);
418 
419  Epetra_MultiVector lhs_root23(MapOnRoot,true);
420  lhs_root23.Export(epsilon23,ExportOnRoot,Insert);
421  std::string file23 = filename + "_epsilon23.mtx";
422  int error23 = EpetraExt::MultiVectorToMatrixMarketFile(file23.c_str(),lhs_root23,0,0,false);*/
423  }
424  if (printVM){
425  Epetra_MultiVector lhs_rootvm(MapOnRoot,true);
426  lhs_rootvm.Export(vonmises,ExportOnRoot,Insert);
427  std::string filevm = filename + "_epsilon_vm.mtx";
428  int errorvm = EpetraExt::MultiVectorToMatrixMarketFile(filevm.c_str(),lhs_rootvm,0,0,false);
429  }
430 
431 }
432 
433 void linearizedElasticity::compute_center_cauchy_stress(Epetra_Vector & x, std::string & filename, bool printCauchy, bool printVM){
434 
435  Epetra_Vector u(*OverlapMap);
436  u.Import(x, *ImportToOverlapMap, Insert);
437 
438  Epetra_Map CellsMap(-1,Mesh->n_local_cells,&Mesh->local_cells[0],0,*Comm);
439  Epetra_Vector sigma11(CellsMap); sigma11.PutScalar(0.0);
440  Epetra_Vector sigma22(CellsMap); sigma22.PutScalar(0.0);
441  Epetra_Vector sigma33(CellsMap); sigma33.PutScalar(0.0);
442  Epetra_Vector sigma12(CellsMap); sigma12.PutScalar(0.0);
443  Epetra_Vector sigma13(CellsMap); sigma13.PutScalar(0.0);
444  Epetra_Vector sigma23(CellsMap); sigma23.PutScalar(0.0);
445  Epetra_Vector vonmises(CellsMap); vonmises.PutScalar(0.0);
446 
447  int node, e_gid;
448  int n_gauss_points = Mesh->n_gauss_cells;
449  double det_jac_cells, gauss_weight, theta;
450 
451  Epetra_SerialDenseVector epsilon(6);
452  Epetra_SerialDenseVector cauchy_stress(6);
453  Epetra_SerialDenseVector vector_u(3*Mesh->el_type);
454  Epetra_SerialDenseMatrix tangent_matrix(6,6);
455  Epetra_SerialDenseMatrix matrix_B(6,3*Mesh->el_type);
456  Epetra_SerialDenseMatrix dx_shape_functions(Mesh->el_type,3);
457 
458  Epetra_SerialDenseMatrix matrix_X(3,Mesh->el_type);
459  Epetra_SerialDenseMatrix D(Mesh->el_type,3);
460  Epetra_SerialDenseMatrix JacobianMatrix(3,3);
461 
462  double xi = 0.0;
463  double eta = 0.0;
464  double zeta = 0.0;
465 
466  switch (Mesh->el_type){
467  case 4:
468  tetra4::d_shape_functions(D, xi, eta, zeta);
469  break;
470  case 8:
471  hexa8::d_shape_functions(D, xi, eta, zeta);
472  break;
473  case 10:
474  tetra10::d_shape_functions(D, xi, eta, zeta);
475  break;
476  }
477 
478  for (unsigned int e_lid=0; e_lid<Mesh->n_local_cells; ++e_lid){
479  e_gid = Mesh->local_cells[e_lid];
480 
481  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
482  node = Mesh->cells_nodes[Mesh->el_type*e_gid+inode];
483  matrix_X(0,inode) = Mesh->nodes_coord[3*node+0];
484  matrix_X(1,inode) = Mesh->nodes_coord[3*node+1];
485  matrix_X(2,inode) = Mesh->nodes_coord[3*node+2];
486  vector_u(3*inode+0) = u[OverlapMap->LID(3*node+0)];
487  vector_u(3*inode+1) = u[OverlapMap->LID(3*node+1)];
488  vector_u(3*inode+2) = u[OverlapMap->LID(3*node+2)];
489  }
490  for (unsigned int i=0; i<6; ++i){
491  epsilon(i) = 0.0;
492  }
493 
494  jacobian_matrix(matrix_X,D,JacobianMatrix);
495  jacobian_det(JacobianMatrix,det_jac_cells);
496  dX_shape_functions(D,JacobianMatrix,det_jac_cells,dx_shape_functions);
497  compute_B_matrices(dx_shape_functions,matrix_B);
498  epsilon.Multiply('N','N',1.0,matrix_B,vector_u,0.0);
499  get_elasticity_tensor_for_recovery(e_lid, tangent_matrix);
500  cauchy_stress.Multiply('N','N',1.0,tangent_matrix,epsilon,0.0);
501 
502  sigma11[e_lid] = cauchy_stress(0);
503  sigma22[e_lid] = cauchy_stress(1);
504  sigma33[e_lid] = cauchy_stress(2);
505  sigma12[e_lid] = cauchy_stress(5);
506  sigma13[e_lid] = cauchy_stress(4);
507  sigma23[e_lid] = cauchy_stress(3);
508 
509  vonmises[e_lid] = std::sqrt( (sigma11[e_lid]-sigma22[e_lid])*(sigma11[e_lid]-sigma22[e_lid]) + (sigma22[e_lid]-sigma33[e_lid])*(sigma22[e_lid]-sigma33[e_lid]) + (sigma33[e_lid]-sigma11[e_lid])*(sigma33[e_lid]-sigma11[e_lid]) + 6.0*(sigma23[e_lid]*sigma23[e_lid] + sigma13[e_lid]*sigma13[e_lid] + sigma12[e_lid]*sigma12[e_lid]) );
510  }
511 
512  int NumTargetElements = 0;
513  if (Comm->MyPID()==0){
514  NumTargetElements = Mesh->n_cells;
515  }
516  Epetra_Map MapOnRoot(-1,NumTargetElements,0,*Comm);
517  Epetra_Export ExportOnRoot(CellsMap,MapOnRoot);
518  if (printCauchy){
519  /*Epetra_MultiVector lhs_root11(MapOnRoot,true);
520  lhs_root11.Export(sigma11,ExportOnRoot,Insert);
521  std::string file11 = filename + "_sigma11.mtx";
522  int error11 = EpetraExt::MultiVectorToMatrixMarketFile(file11.c_str(),lhs_root11,0,0,false);*/
523 
524  Epetra_MultiVector lhs_root22(MapOnRoot,true);
525  lhs_root22.Export(sigma22,ExportOnRoot,Insert);
526  std::string file22 = filename + "_sigma22.mtx";
527  int error22 = EpetraExt::MultiVectorToMatrixMarketFile(file22.c_str(),lhs_root22,0,0,false);
528 
529  /*Epetra_MultiVector lhs_root33(MapOnRoot,true);
530  lhs_root33.Export(sigma33,ExportOnRoot,Insert);
531  std::string file33 = filename + "_sigma33.mtx";
532  int error33 = EpetraExt::MultiVectorToMatrixMarketFile(file33.c_str(),lhs_root33,0,0,false);
533 
534  Epetra_MultiVector lhs_root12(MapOnRoot,true);
535  lhs_root12.Export(sigma12,ExportOnRoot,Insert);
536  std::string file12 = filename + "_sigma12.mtx";
537  int error12 = EpetraExt::MultiVectorToMatrixMarketFile(file12.c_str(),lhs_root12,0,0,false);
538 
539  Epetra_MultiVector lhs_root13(MapOnRoot,true);
540  lhs_root13.Export(sigma13,ExportOnRoot,Insert);
541  std::string file13 = filename + "_sigma13.mtx";
542  int error13 = EpetraExt::MultiVectorToMatrixMarketFile(file13.c_str(),lhs_root13,0,0,false);
543 
544  Epetra_MultiVector lhs_root23(MapOnRoot,true);
545  lhs_root23.Export(sigma23,ExportOnRoot,Insert);
546  std::string file23 = filename + "_sigma23.mtx";
547  int error23 = EpetraExt::MultiVectorToMatrixMarketFile(file23.c_str(),lhs_root23,0,0,false);*/
548  }
549  if (printVM){
550  Epetra_MultiVector lhs_rootvm(MapOnRoot,true);
551  lhs_rootvm.Export(vonmises,ExportOnRoot,Insert);
552  std::string filevm = filename + "_vm.mtx";
553  int errorvm = EpetraExt::MultiVectorToMatrixMarketFile(filevm.c_str(),lhs_rootvm,0,0,false);
554  }
555 }
Epetra_Comm * Comm
for j
Definition: costFunction.m:42
u
Definition: run.m:9
int print_solution(Epetra_Vector &solution, std::string fileName)
void assembleMixedDirichletNeumann_inhomogeneousForcing(Epetra_FECrsMatrix &K, Epetra_FEVector &F)
std::vector< int > local_faces
Definition: meshpp.hpp:81
int n_local_faces
Definition: meshpp.hpp:95
Epetra_SerialDenseVector DZ_N_cells
Definition: meshpp.hpp:73
std::vector< double > nodes_coord
Definition: meshpp.hpp:77
virtual Epetra_SerialDenseVector get_forcing(double &x1, double &x2, double &x3, unsigned int &e_lid, unsigned int &gp)=0
Epetra_SerialDenseVector N_cells
Definition: meshpp.hpp:73
void assembleMixedDirichletNeumann_homogeneousForcing(Epetra_FECrsMatrix &K, Epetra_FEVector &F)
int n_local_cells
Definition: meshpp.hpp:94
void stiffness_homogeneousForcing(Epetra_FECrsMatrix &K)
Epetra_SerialDenseMatrix N_faces
Definition: meshpp.hpp:71
void d_shape_functions(Epetra_SerialDenseMatrix &D, double &xi, double &eta, double &zeta)
Definition: fepp.cpp:99
unsigned int n_gauss_faces
Definition: meshpp.hpp:97
virtual void get_elasticity_tensor(unsigned int &e_lid, unsigned int &gp, Epetra_SerialDenseMatrix &tangent_matrix)=0
int face_type
Definition: meshpp.hpp:91
void dX_shape_functions(Epetra_SerialDenseMatrix &D, Epetra_SerialDenseMatrix JacobianMatrix, double &jac, Epetra_SerialDenseMatrix &DX)
Definition: fepp.cpp:152
Epetra_SerialDenseVector DX_N_cells
Definition: meshpp.hpp:73
Epetra_SerialDenseVector detJac_cells
Definition: meshpp.hpp:73
Epetra_FECrsGraph * FEGraph
end theta
Definition: costFunction.m:30
void compute_B_matrices(Epetra_SerialDenseMatrix &dx_shape_functions, Epetra_SerialDenseMatrix &B)
virtual Epetra_SerialDenseVector get_neumannBc(Epetra_SerialDenseMatrix &matrix_X, Epetra_SerialDenseMatrix &xg, unsigned int &gp)=0
std::vector< int > local_cells
Definition: meshpp.hpp:81
void d_shape_functions(Epetra_SerialDenseMatrix &D, double &xi, double &eta, double &zeta)
Definition: fepp.cpp:139
void compute_deformation(Epetra_Vector &x, std::string &filename, bool printCauchy, bool printVM)
void jacobian_det(Epetra_SerialDenseMatrix &JacobianMatrix, double &jac)
Definition: fepp.cpp:175
std::vector< int > faces_nodes
Definition: meshpp.hpp:78
filename
Definition: costFunction.m:44
int el_type
Definition: meshpp.hpp:90
Epetra_SerialDenseVector DY_N_cells
Definition: meshpp.hpp:73
void compute_center_cauchy_stress(Epetra_Vector &x, std::string &filename, bool printCauchy, bool printVM)
std::vector< int > cells_nodes
Definition: meshpp.hpp:78
void assemblePureDirichlet_homogeneousForcing(Epetra_FECrsMatrix &K)
Epetra_Import * ImportToOverlapMap
Epetra_Map * StandardMap
unsigned int n_gauss_cells
Definition: meshpp.hpp:98
int n_cells
Definition: meshpp.hpp:88
Epetra_SerialDenseVector gauss_weight_faces
Definition: meshpp.hpp:99
virtual void get_elasticity_tensor_for_recovery(unsigned int &e_lid, Epetra_SerialDenseMatrix &tangent_matrix)=0
optimParameters tol
void rhs_NeumannBoundaryCondition(Epetra_FEVector &F)
int n_nodes
Definition: meshpp.hpp:87
void d_shape_functions(Epetra_SerialDenseMatrix &D, double &xi, double &eta, double &zeta)
Definition: fepp.cpp:118
for i
Definition: costFunction.m:38
Epetra_Map * OverlapMap
void stiffness_inhomogeneousForcing(Epetra_FECrsMatrix &K, Epetra_FEVector &F)
void aztecSolver(Epetra_FECrsMatrix &A, Epetra_FEVector &b, Epetra_Vector &u, Teuchos::ParameterList &paramList)
Epetra_SerialDenseVector gauss_weight_cells
Definition: meshpp.hpp:99
void jacobian_matrix(Epetra_SerialDenseMatrix &X, Epetra_SerialDenseMatrix &D, Epetra_SerialDenseMatrix &JacobianMatrix)
Definition: fepp.cpp:171
output eta
Definition: costFunction.m:33