Trilinos based (stochastic) FEM solvers
hyperelasticity.cpp
Go to the documentation of this file.
1 /*
2 Brian Staber (brian.staber@gmail.com)
3 */
4 
5 #include "hyperelasticity.hpp"
6 #include "fepp.hpp"
7 
9 }
10 
12 }
13 
15  FEGraph = new Epetra_FECrsGraph(Copy,*StandardMap,100);
16  int eglob, node;
17  int *index;
18  index = new int [3*Mesh->el_type];
19 
20  for (int e_lid=0; e_lid<Mesh->n_local_cells; ++e_lid){
21  eglob = Mesh->local_cells[e_lid];
22  for (int inode=0; inode<Mesh->el_type; ++inode){
23  node = Mesh->cells_nodes[Mesh->el_type*eglob+inode];
24  for (int ddl=0; ddl<3; ++ddl){
25  index[3*inode+ddl] = 3*node+ddl;
26  }
27  }
28  for (int i=0; i<3*Mesh->el_type; ++i){
29  for (int j=0; j<3*Mesh->el_type; ++j){
30  FEGraph->InsertGlobalIndices(1, &index[i], 1, &index[j]);
31  }
32  }
33 
34  }
35  Comm->Barrier();
36  FEGraph->GlobalAssemble();
37  delete[] index;
38 }
39 
40 int hyperelasticity::compute_green_lagrange(Epetra_Vector & x, double & xi, double & eta, double & zeta, std::string & filename){
41 
42  Epetra_Vector u(*OverlapMap);
43  u.Import(x, *ImportToOverlapMap, Insert);
44 
45  Epetra_Map CellsMap(-1,Mesh->n_local_cells,&Mesh->local_cells[0],0,*Comm);
46  Epetra_Vector green_lagrange(CellsMap);
47 
48  int node, e_gid;
49  double det_jac_cells;
50 
51  Epetra_SerialDenseMatrix deformation_gradient(3,3);
52  Epetra_SerialDenseMatrix right_cauchy(3,3);
53  Epetra_SerialDenseMatrix matrix_X(3,Mesh->el_type);
54  Epetra_SerialDenseMatrix matrix_x(3,Mesh->el_type);
55  Epetra_SerialDenseMatrix dx_shape_functions(Mesh->el_type,3);
56  Epetra_SerialDenseMatrix D(Mesh->el_type,3), DX(Mesh->el_type,3);
57  Epetra_SerialDenseMatrix JacobianMatrix(3,3);
58 
59  switch (Mesh->el_type){
60  case 4:
61  tetra4::d_shape_functions(D, xi, eta, zeta);
62  break;
63  case 8:
64  hexa8::d_shape_functions(D, xi, eta, zeta);
65  break;
66  case 10:
67  tetra10::d_shape_functions(D, xi, eta, zeta);
68  break;
69  };
70 
71  for (unsigned int e_lid=0; e_lid<Mesh->n_local_cells; ++e_lid){
72  e_gid = Mesh->local_cells[e_lid];
73 
74  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
75  node = Mesh->cells_nodes[Mesh->el_type*e_gid+inode];
76  matrix_X(0,inode) = Mesh->nodes_coord[3*node+0];
77  matrix_X(1,inode) = Mesh->nodes_coord[3*node+1];
78  matrix_X(2,inode) = Mesh->nodes_coord[3*node+2];
79  matrix_x(0,inode) = u[OverlapMap->LID(3*node+0)] + Mesh->nodes_coord[3*node+0];
80  matrix_x(1,inode) = u[OverlapMap->LID(3*node+1)] + Mesh->nodes_coord[3*node+1];
81  matrix_x(2,inode) = u[OverlapMap->LID(3*node+2)] + Mesh->nodes_coord[3*node+2];
82  }
83 
84  jacobian_matrix(matrix_X,D,JacobianMatrix);
85  jacobian_det(JacobianMatrix,det_jac_cells);
86  dX_shape_functions(D,JacobianMatrix,det_jac_cells,dx_shape_functions);
87 
88  deformation_gradient.Multiply('N','N',1.0,matrix_x,dx_shape_functions,0.0);
89  right_cauchy.Multiply('T','N',1.0,deformation_gradient,deformation_gradient,0.0);
90  green_lagrange[e_lid] = 0.5*(right_cauchy(1,1)-1.0);
91  }
92 
93  int NumTargetElements = 0;
94  if (Comm->MyPID()==0){
95  NumTargetElements = Mesh->n_cells;
96  }
97  Epetra_Map MapOnRoot(-1,NumTargetElements,0,*Comm);
98  Epetra_Export ExportOnRoot(CellsMap,MapOnRoot);
99  Epetra_MultiVector lhs_root(MapOnRoot,true);
100  lhs_root.Export(green_lagrange,ExportOnRoot,Insert);
101 
102  int error = EpetraExt::MultiVectorToMatrixMarketFile(filename.c_str(),lhs_root,0,0,false);
103  return error;
104 }
105 
106 void hyperelasticity::compute_center_cauchy_stress(Epetra_Vector & x, std::string & filename){
107 
108  Epetra_Vector u(*OverlapMap);
109  u.Import(x, *ImportToOverlapMap, Insert);
110 
111  Epetra_Map CellsMap(-1,Mesh->n_local_cells,&Mesh->local_cells[0],0,*Comm);
112  Epetra_Vector sigma11(CellsMap); sigma11.PutScalar(0.0);
113  Epetra_Vector sigma22(CellsMap); sigma22.PutScalar(0.0);
114  Epetra_Vector sigma33(CellsMap); sigma33.PutScalar(0.0);
115  Epetra_Vector sigma12(CellsMap); sigma12.PutScalar(0.0);
116  Epetra_Vector sigma13(CellsMap); sigma13.PutScalar(0.0);
117  Epetra_Vector sigma23(CellsMap); sigma23.PutScalar(0.0);
118 
119  int node, e_gid;
120  int n_gauss_points = Mesh->n_gauss_cells;
121  double det_jac_cells, det, gauss_weight, theta;
122 
123  Epetra_SerialDenseMatrix deformation_gradient(3,3);
124  Epetra_SerialDenseMatrix right_cauchy(3,3);
125  Epetra_SerialDenseMatrix matrix_X(3,Mesh->el_type), matrix_x(3,Mesh->el_type);
126  Epetra_SerialDenseMatrix dx_shape_functions(Mesh->el_type,3), D(Mesh->el_type,3);
127  Epetra_SerialDenseMatrix JacobianMatrix(3,3);
128  Epetra_SerialDenseMatrix piola_stress(3,3);
129  Epetra_SerialDenseMatrix cauchy_stress(3,3);
130  Epetra_SerialDenseMatrix dg_times_ps(3,3);
131 
132  switch (Mesh->el_type){
133  double xi;
134  case 4:
135  xi = 1.0/3.0;
136  tetra4::d_shape_functions(D, xi, xi, xi);
137  break;
138  case 8:
139  xi = 0.0;
140  hexa8::d_shape_functions(D, xi, xi, xi);
141  break;
142  case 10:
143  xi = 1.0/3.0;
144  tetra10::d_shape_functions(D, xi, xi, xi);
145  break;
146  };
147 
148  for (unsigned int e_lid=0; e_lid<Mesh->n_local_cells; ++e_lid){
149  e_gid = Mesh->local_cells[e_lid];
150 
151  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
152  node = Mesh->cells_nodes[Mesh->el_type*e_gid+inode];
153  matrix_X(0,inode) = Mesh->nodes_coord[3*node+0];
154  matrix_X(1,inode) = Mesh->nodes_coord[3*node+1];
155  matrix_X(2,inode) = Mesh->nodes_coord[3*node+2];
156  matrix_x(0,inode) = u[OverlapMap->LID(3*node+0)] + Mesh->nodes_coord[3*node+0];
157  matrix_x(1,inode) = u[OverlapMap->LID(3*node+1)] + Mesh->nodes_coord[3*node+1];
158  matrix_x(2,inode) = u[OverlapMap->LID(3*node+2)] + Mesh->nodes_coord[3*node+2];
159  }
160 
161  jacobian_matrix(matrix_X,D,JacobianMatrix);
162  jacobian_det(JacobianMatrix,det_jac_cells);
163  dX_shape_functions(D,JacobianMatrix,det_jac_cells,dx_shape_functions);
164 
165  deformation_gradient.Multiply('N','N',1.0,matrix_x,dx_shape_functions,0.0);
167  get_stress_for_recover(deformation_gradient, det, piola_stress);
168  dg_times_ps.Multiply('N','N',1.0,deformation_gradient,piola_stress,0.0);
169  cauchy_stress.Multiply('N','T',1.0,dg_times_ps,deformation_gradient,0.0);
170 
171  sigma11[e_lid] = cauchy_stress(0,0);
172  sigma22[e_lid] = cauchy_stress(1,1);
173  sigma33[e_lid] = cauchy_stress(2,2);
174  sigma12[e_lid] = cauchy_stress(0,1);
175  sigma13[e_lid] = cauchy_stress(0,2);
176  sigma23[e_lid] = cauchy_stress(1,2);
177  }
178 
179  int NumTargetElements = 0;
180  if (Comm->MyPID()==0){
181  NumTargetElements = Mesh->n_cells;
182  }
183  Epetra_Map MapOnRoot(-1,NumTargetElements,0,*Comm);
184  Epetra_Export ExportOnRoot(CellsMap,MapOnRoot);
185 
186  Epetra_MultiVector lhs_root11(MapOnRoot,true);
187  lhs_root11.Export(sigma11,ExportOnRoot,Insert);
188  std::string file11 = filename + "_sigma11.mtx";
189  int error11 = EpetraExt::MultiVectorToMatrixMarketFile(file11.c_str(),lhs_root11,0,0,false);
190 
191  Epetra_MultiVector lhs_root22(MapOnRoot,true);
192  lhs_root22.Export(sigma22,ExportOnRoot,Insert);
193  std::string file22 = filename + "_sigma22.mtx";
194  int error22 = EpetraExt::MultiVectorToMatrixMarketFile(file22.c_str(),lhs_root22,0,0,false);
195 
196  Epetra_MultiVector lhs_root33(MapOnRoot,true);
197  lhs_root33.Export(sigma33,ExportOnRoot,Insert);
198  std::string file33 = filename + "_sigma33.mtx";
199  int error33 = EpetraExt::MultiVectorToMatrixMarketFile(file33.c_str(),lhs_root33,0,0,false);
200 
201  Epetra_MultiVector lhs_root12(MapOnRoot,true);
202  lhs_root12.Export(sigma12,ExportOnRoot,Insert);
203  std::string file12 = filename + "_sigma12.mtx";
204  int error12 = EpetraExt::MultiVectorToMatrixMarketFile(file12.c_str(),lhs_root12,0,0,false);
205 
206  Epetra_MultiVector lhs_root13(MapOnRoot,true);
207  lhs_root13.Export(sigma13,ExportOnRoot,Insert);
208  std::string file13 = filename + "_sigma13.mtx";
209  int error13 = EpetraExt::MultiVectorToMatrixMarketFile(file13.c_str(),lhs_root13,0,0,false);
210 
211  Epetra_MultiVector lhs_root23(MapOnRoot,true);
212  lhs_root23.Export(sigma23,ExportOnRoot,Insert);
213  std::string file23 = filename + "_sigma23.mtx";
214  int error23 = EpetraExt::MultiVectorToMatrixMarketFile(file23.c_str(),lhs_root23,0,0,false);
215 }
216 
217 void hyperelasticity::compute_gauss_vonmises(Epetra_Vector & x, std::string & filename){
218 
219  Epetra_Vector u(*OverlapMap);
220  u.Import(x, *ImportToOverlapMap, Insert);
221 
222  int node, e_gid;
223  int n_gauss_points = Mesh->n_gauss_cells;
224  double det_jac_cells, det, gauss_weight;
225 
226  Epetra_SerialDenseMatrix deformation_gradient(3,3);
227  Epetra_SerialDenseMatrix right_cauchy(3,3);
228  Epetra_SerialDenseMatrix matrix_x(3,Mesh->el_type);
229  Epetra_SerialDenseMatrix dx_shape_functions(Mesh->el_type,3);
230  Epetra_SerialDenseMatrix piola_stress(3,3);
231  Epetra_SerialDenseMatrix cauchy_stress(3,3);
232  Epetra_SerialDenseMatrix dg_times_ps(3,3);
233 
234  std::vector<int> local_gauss_points;
235  for (unsigned int e_lid=0; e_lid<Mesh->n_local_cells; ++e_lid){
236  e_gid = Mesh->local_cells[e_lid];
237  for (unsigned int j=0; j<Mesh->n_gauss_cells; ++j){
238  local_gauss_points.push_back(Mesh->n_gauss_cells*e_gid+j);
239  }
240  }
241  Epetra_Map CellsMap(-1,Mesh->n_local_cells,&local_gauss_points[0],0,*Comm);
242  Epetra_Vector vonmises(CellsMap);
243 
244  for (unsigned int e_lid=0; e_lid<Mesh->n_local_cells; ++e_lid){
245  e_gid = Mesh->local_cells[e_lid];
246 
247  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
248  node = Mesh->cells_nodes[Mesh->el_type*e_gid+inode];
249  matrix_x(0,inode) = u[OverlapMap->LID(3*node+0)] + Mesh->nodes_coord[3*node+0];
250  matrix_x(1,inode) = u[OverlapMap->LID(3*node+1)] + Mesh->nodes_coord[3*node+1];
251  matrix_x(2,inode) = u[OverlapMap->LID(3*node+2)] + Mesh->nodes_coord[3*node+2];
252  }
253 
254  for (unsigned int gp=0; gp<n_gauss_points; ++gp){
255  gauss_weight = Mesh->gauss_weight_cells(gp);
256  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
257  dx_shape_functions(inode,0) = Mesh->DX_N_cells(gp+n_gauss_points*inode,e_lid);
258  dx_shape_functions(inode,1) = Mesh->DY_N_cells(gp+n_gauss_points*inode,e_lid);
259  dx_shape_functions(inode,2) = Mesh->DZ_N_cells(gp+n_gauss_points*inode,e_lid);
260  }
261 
262  deformation_gradient.Multiply('N','N',1.0,matrix_x,dx_shape_functions,0.0);
263 
264  get_material_parameters(e_lid, gp);
265  get_stress_for_recover(deformation_gradient, det, piola_stress);
266  dg_times_ps.Multiply('N','N',1.0,deformation_gradient,piola_stress,0.0);
267  cauchy_stress.Multiply('N','T',1.0,dg_times_ps,deformation_gradient,0.0);
268 
269  vonmises[Mesh->n_gauss_cells*e_lid+gp] = std::sqrt( (cauchy_stress(0,0)-cauchy_stress(1,1))*(cauchy_stress(0,0)-cauchy_stress(1,1)) + (cauchy_stress(1,1)-cauchy_stress(2,2))*(cauchy_stress(1,1)-cauchy_stress(2,2)) + (cauchy_stress(2,2)-cauchy_stress(0,0))*(cauchy_stress(2,2)-cauchy_stress(0,0)) + 6.0*(cauchy_stress(1,2)*cauchy_stress(1,2) + cauchy_stress(2,0)*cauchy_stress(2,0) + cauchy_stress(0,1)*cauchy_stress(0,1)) );
270  }
271  }
272 
273  int NumTargetElements = 0;
274  if (Comm->MyPID()==0){
275  NumTargetElements = Mesh->n_cells*Mesh->n_gauss_cells;
276  }
277  Epetra_Map MapOnRoot(-1,NumTargetElements,0,*Comm);
278  Epetra_Export ExportOnRoot(CellsMap,MapOnRoot);
279 
280  Epetra_MultiVector lhs_root11(MapOnRoot,true);
281  lhs_root11.Export(vonmises,ExportOnRoot,Insert);
282  std::string file11 = filename + "_gauss_vonmises.mtx";
283  int error11 = EpetraExt::MultiVectorToMatrixMarketFile(file11.c_str(),lhs_root11,0,0,false);
284 
285 }
286 
287 void hyperelasticity::compute_B_matrices(Epetra_SerialDenseMatrix & F, Epetra_SerialDenseMatrix & dx_shape_functions, Epetra_SerialDenseMatrix & B, Epetra_SerialDenseMatrix & BG){
288 
289  for (unsigned inode=0; inode<Mesh->el_type; ++inode){
290  B(0,3*inode) = F(0,0)*dx_shape_functions(inode,0);
291  B(0,3*inode+1) = F(1,0)*dx_shape_functions(inode,0);
292  B(0,3*inode+2) = F(2,0)*dx_shape_functions(inode,0);
293 
294  B(1,3*inode) = F(0,1)*dx_shape_functions(inode,1);
295  B(1,3*inode+1) = F(1,1)*dx_shape_functions(inode,1);
296  B(1,3*inode+2) = F(2,1)*dx_shape_functions(inode,1);
297 
298  B(2,3*inode) = F(0,2)*dx_shape_functions(inode,2);
299  B(2,3*inode+1) = F(1,2)*dx_shape_functions(inode,2);
300  B(2,3*inode+2) = F(2,2)*dx_shape_functions(inode,2);
301 
302  B(3,3*inode) = F(0,1)*dx_shape_functions(inode,2) + F(0,2)*dx_shape_functions(inode,1);
303  B(3,3*inode+1) = F(1,1)*dx_shape_functions(inode,2) + F(1,2)*dx_shape_functions(inode,1);
304  B(3,3*inode+2) = F(2,1)*dx_shape_functions(inode,2) + F(2,2)*dx_shape_functions(inode,1);
305 
306  B(4,3*inode) = F(0,0)*dx_shape_functions(inode,2) + F(0,2)*dx_shape_functions(inode,0);
307  B(4,3*inode+1) = F(1,0)*dx_shape_functions(inode,2) + F(1,2)*dx_shape_functions(inode,0);
308  B(4,3*inode+2) = F(2,0)*dx_shape_functions(inode,2) + F(2,2)*dx_shape_functions(inode,0);
309 
310  B(5,3*inode) = F(0,0)*dx_shape_functions(inode,1) + F(0,1)*dx_shape_functions(inode,0);
311  B(5,3*inode+1) = F(1,0)*dx_shape_functions(inode,1) + F(1,1)*dx_shape_functions(inode,0);
312  B(5,3*inode+2) = F(2,0)*dx_shape_functions(inode,1) + F(2,1)*dx_shape_functions(inode,0);
313 
314  BG(0,3*inode) = dx_shape_functions(inode,0);
315  BG(1,3*inode) = dx_shape_functions(inode,1);
316  BG(2,3*inode) = dx_shape_functions(inode,2);
317 
318  BG(3,3*inode+1) = dx_shape_functions(inode,0);
319  BG(4,3*inode+1) = dx_shape_functions(inode,1);
320  BG(5,3*inode+1) = dx_shape_functions(inode,2);
321 
322  BG(6,3*inode+2) = dx_shape_functions(inode,0);
323  BG(7,3*inode+2) = dx_shape_functions(inode,1);
324  BG(8,3*inode+2) = dx_shape_functions(inode,2);
325  }
326 
327 }
Epetra_Comm * Comm
for j
Definition: costFunction.m:42
u
Definition: run.m:9
Epetra_SerialDenseVector DZ_N_cells
Definition: meshpp.hpp:73
std::vector< double > nodes_coord
Definition: meshpp.hpp:77
virtual void get_stress_for_recover(Epetra_SerialDenseMatrix &deformation_gradient, double &det, Epetra_SerialDenseMatrix &piola_stress)=0
int n_local_cells
Definition: meshpp.hpp:94
void d_shape_functions(Epetra_SerialDenseMatrix &D, double &xi, double &eta, double &zeta)
Definition: fepp.cpp:99
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
void compute_center_cauchy_stress(Epetra_Vector &x, std::string &filename)
Epetra_FECrsGraph * FEGraph
end theta
Definition: costFunction.m:30
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 jacobian_det(Epetra_SerialDenseMatrix &JacobianMatrix, double &jac)
Definition: fepp.cpp:175
void compute_gauss_vonmises(Epetra_Vector &x, std::string &filename)
filename
Definition: costFunction.m:44
int el_type
Definition: meshpp.hpp:90
Epetra_SerialDenseVector DY_N_cells
Definition: meshpp.hpp:73
std::vector< int > cells_nodes
Definition: meshpp.hpp:78
Epetra_Import * ImportToOverlapMap
Epetra_Map * StandardMap
unsigned int n_gauss_cells
Definition: meshpp.hpp:98
int compute_green_lagrange(Epetra_Vector &x, double &xi, double &eta, double &zeta, std::string &filename)
int n_cells
Definition: meshpp.hpp:88
void compute_B_matrices(Epetra_SerialDenseMatrix &F, Epetra_SerialDenseMatrix &dx_shape_functions, Epetra_SerialDenseMatrix &B, Epetra_SerialDenseMatrix &BG)
virtual void get_material_parameters_for_recover(unsigned int &e_lid)=0
virtual void get_material_parameters(unsigned int &e_lid, unsigned int &gp)=0
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
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