Trilinos based (stochastic) FEM solvers
compressibleHyperelasticity.cpp
Go to the documentation of this file.
1 /*
2 Brian Staber (brian.staber@gmail.com)
3 */
4 
6 
8 }
9 
11 }
12 
13 void compressibleHyperelasticity::assemblePureDirichlet_homogeneousForcing(Epetra_Vector & x, Epetra_FECrsMatrix & K, Epetra_FEVector & F){
14  int error;
15  F.PutScalar(0.0);
16  K.PutScalar(0.0);
17 
18  Epetra_Vector u(*OverlapMap);
19  u.Import(x, *ImportToOverlapMap, Insert);
20 
22 
23  Comm->Barrier();
24  error = K.GlobalAssemble();
25  error = K.FillComplete();
26  error = F.GlobalAssemble();
27 }
28 void compressibleHyperelasticity::assemblePureDirichlet_inhomogeneousForcing(Epetra_Vector & x, Epetra_FECrsMatrix & K, Epetra_FEVector & F){
29  int error;
30  F.PutScalar(0.0);
31  K.PutScalar(0.0);
32 
33  Epetra_Vector u(*OverlapMap);
34  u.Import(x, *ImportToOverlapMap, Insert);
35 
37 
38  Comm->Barrier();
39  error = K.GlobalAssemble();
40  error = K.FillComplete();
41  error = F.GlobalAssemble();
42 }
43 void compressibleHyperelasticity::assembleMixedDirichletNeumann_homogeneousForcing(Epetra_Vector & x, Epetra_FECrsMatrix & K, Epetra_FEVector & F){
44  int error;
45  F.PutScalar(0.0);
46  K.PutScalar(0.0);
47 
48  Epetra_Vector u(*OverlapMap);
49  u.Import(x, *ImportToOverlapMap, Insert);
50 
53 
54  Comm->Barrier();
55  error = K.GlobalAssemble();
56  error = K.FillComplete();
57  error = F.GlobalAssemble();
58 }
59 void compressibleHyperelasticity::assembleMixedDirichletNeumann_inhomogeneousForcing(Epetra_Vector & x, Epetra_FECrsMatrix & K, Epetra_FEVector & F){
60  int error;
61  F.PutScalar(0.0);
62  K.PutScalar(0.0);
63 
64  Epetra_Vector u(*OverlapMap);
65  u.Import(x, *ImportToOverlapMap, Insert);
66 
69 
70  Comm->Barrier();
71  error = K.GlobalAssemble();
72  error = K.FillComplete();
73  error = F.GlobalAssemble();
74 }
75 
76 void compressibleHyperelasticity::stiffnessRhs_homogeneousForcing(Epetra_Vector & u, Epetra_FECrsMatrix & K, Epetra_FEVector & F){
77  int node, e_gid, error;
78  int n_gauss_points = Mesh->n_gauss_cells;
79  double gauss_weight;
80 
81  int *Indexes;
82  Indexes = new int [3*Mesh->el_type];
83 
84  Epetra_SerialDenseMatrix Ke(3*Mesh->el_type,3*Mesh->el_type);
85  Epetra_SerialDenseVector Re(3*Mesh->el_type);
86 
87  Epetra_SerialDenseMatrix deformation_gradient(3,3);
88  Epetra_SerialDenseMatrix tangent_matrix(6,6);
89  Epetra_SerialDenseVector scd_piola_stress(6);
90  Epetra_SerialDenseMatrix block_scd_piola_stress(9,9);
91  Epetra_SerialDenseMatrix matrix_x(3,Mesh->el_type);
92 
93  Epetra_SerialDenseMatrix dx_shape_functions(Mesh->el_type,3);
94  Epetra_SerialDenseMatrix matrix_B(6,3*Mesh->el_type);
95  Epetra_SerialDenseMatrix B_times_TM(3*Mesh->el_type,6);
96  Epetra_SerialDenseMatrix matrix_BG(9,3*Mesh->el_type);
97  Epetra_SerialDenseMatrix BG_times_BSPS(3*Mesh->el_type,9);
98 
99  for (unsigned int e_lid=0; e_lid<Mesh->n_local_cells; ++e_lid){
100  e_gid = Mesh->local_cells[e_lid];
101 
102  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
103  node = Mesh->cells_nodes[Mesh->el_type*e_gid+inode];
104  matrix_x(0,inode) = u[OverlapMap->LID(3*node+0)] + Mesh->nodes_coord[3*node+0];
105  matrix_x(1,inode) = u[OverlapMap->LID(3*node+1)] + Mesh->nodes_coord[3*node+1];
106  matrix_x(2,inode) = u[OverlapMap->LID(3*node+2)] + Mesh->nodes_coord[3*node+2];
107  for (int iddl=0; iddl<3; ++iddl){
108  Re(3*inode+iddl) = 0.0;
109  Indexes[3*inode+iddl] = 3*node+iddl;
110  for (unsigned int jnode=0; jnode<Mesh->el_type; ++jnode){
111  for (int jddl=0; jddl<3; ++jddl){
112  Ke(3*inode+iddl,3*jnode+jddl) = 0.0;
113  }
114  }
115  }
116  }
117 
118  for (unsigned int gp=0; gp<n_gauss_points; ++gp){
119  gauss_weight = Mesh->gauss_weight_cells(gp);
120  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
121  dx_shape_functions(inode,0) = Mesh->DX_N_cells(gp+n_gauss_points*inode,e_lid);
122  dx_shape_functions(inode,1) = Mesh->DY_N_cells(gp+n_gauss_points*inode,e_lid);
123  dx_shape_functions(inode,2) = Mesh->DZ_N_cells(gp+n_gauss_points*inode,e_lid);
124  }
125 
126  error=deformation_gradient.Multiply('N','N',1.0,matrix_x,dx_shape_functions,0.0);
127  compute_B_matrices(deformation_gradient,dx_shape_functions,matrix_B,matrix_BG);
128 
129  get_material_parameters(e_lid, gp);
130  get_constitutive_tensors(deformation_gradient, scd_piola_stress, tangent_matrix);
131 
132  for (unsigned int i=0; i<3; ++i){
133  block_scd_piola_stress(3*i+0,3*i+0) = scd_piola_stress(0);
134  block_scd_piola_stress(3*i+0,3*i+1) = scd_piola_stress(5);
135  block_scd_piola_stress(3*i+0,3*i+2) = scd_piola_stress(4);
136  block_scd_piola_stress(3*i+1,3*i+0) = scd_piola_stress(5);
137  block_scd_piola_stress(3*i+1,3*i+1) = scd_piola_stress(1);
138  block_scd_piola_stress(3*i+1,3*i+2) = scd_piola_stress(3);
139  block_scd_piola_stress(3*i+2,3*i+0) = scd_piola_stress(4);
140  block_scd_piola_stress(3*i+2,3*i+1) = scd_piola_stress(3);
141  block_scd_piola_stress(3*i+2,3*i+2) = scd_piola_stress(2);
142  }
143 
144  error = Re.Multiply('T','N',-gauss_weight*Mesh->detJac_cells(e_lid,gp),matrix_B,scd_piola_stress,1.0);
145 
146  error = B_times_TM.Multiply('T','N',gauss_weight*Mesh->detJac_cells(e_lid,gp),matrix_B,tangent_matrix,0.0);
147  error = Ke.Multiply('N','N',1.0,B_times_TM,matrix_B,1.0);
148 
149  error = BG_times_BSPS.Multiply('T','N',gauss_weight*Mesh->detJac_cells(e_lid,gp),matrix_BG,block_scd_piola_stress,0.0);
150  error = Ke.Multiply('N','N',1.0,BG_times_BSPS,matrix_BG,1.0);
151  }
152 
153  for (unsigned int i=0; i<3*Mesh->el_type; ++i){
154  error = F.SumIntoGlobalValues(1, &Indexes[i], &Re(i));
155  for (unsigned int j=0; j<3*Mesh->el_type; ++j){
156  error = K.SumIntoGlobalValues(1, &Indexes[i], 1, &Indexes[j], &Ke(i,j));
157  }
158  }
159  }
160  delete[] Indexes;
161 }
162 
163 void compressibleHyperelasticity::stiffnessRhs_inhomogeneousForcing(Epetra_Vector & u, Epetra_FECrsMatrix & K, Epetra_FEVector & F){
164  int node, e_gid, error;
165  int n_gauss_points = Mesh->n_gauss_cells;
166  double gauss_weight;
167 
168  int *Indexes;
169  Indexes = new int [3*Mesh->el_type];
170 
171  Epetra_SerialDenseMatrix Ke(3*Mesh->el_type,3*Mesh->el_type);
172  Epetra_SerialDenseVector Re(3*Mesh->el_type);
173 
174  Epetra_SerialDenseMatrix deformation_gradient(3,3);
175  Epetra_SerialDenseMatrix tangent_matrix(6,6);
176  Epetra_SerialDenseVector scd_piola_stress(6);
177  Epetra_SerialDenseMatrix block_scd_piola_stress(9,9);
178  Epetra_SerialDenseMatrix matrix_x(3,Mesh->el_type);
179  Epetra_SerialDenseMatrix matrix_X(3,Mesh->el_type);
180  Epetra_SerialDenseMatrix xg(3,n_gauss_points);
181 
182  Epetra_SerialDenseMatrix dx_shape_functions(Mesh->el_type,3);
183  Epetra_SerialDenseMatrix matrix_B(6,3*Mesh->el_type);
184  Epetra_SerialDenseMatrix B_times_TM(3*Mesh->el_type,6);
185  Epetra_SerialDenseMatrix matrix_BG(9,3*Mesh->el_type);
186  Epetra_SerialDenseMatrix BG_times_BSPS(3*Mesh->el_type,9);
187 
188  Epetra_SerialDenseVector fevol(3*Mesh->el_type);
189  Epetra_SerialDenseVector fvol(3);
190 
191  for (unsigned int e_lid=0; e_lid<Mesh->n_local_cells; ++e_lid){
192  e_gid = Mesh->local_cells[e_lid];
193 
194  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
195  node = Mesh->cells_nodes[Mesh->el_type*e_gid+inode];
196  matrix_X(0,inode) = Mesh->nodes_coord[3*node+0];
197  matrix_X(1,inode) = Mesh->nodes_coord[3*node+1];
198  matrix_X(2,inode) = Mesh->nodes_coord[3*node+2];
199  matrix_x(0,inode) = u[OverlapMap->LID(3*node+0)] + Mesh->nodes_coord[3*node+0];
200  matrix_x(1,inode) = u[OverlapMap->LID(3*node+1)] + Mesh->nodes_coord[3*node+1];
201  matrix_x(2,inode) = u[OverlapMap->LID(3*node+2)] + Mesh->nodes_coord[3*node+2];
202  for (int iddl=0; iddl<3; ++iddl){
203  Re(3*inode+iddl) = 0.0;
204  fevol(3*inode+iddl) = 0.0;
205  Indexes[3*inode+iddl] = 3*node+iddl;
206  for (unsigned int jnode=0; jnode<Mesh->el_type; ++jnode){
207  for (int jddl=0; jddl<3; ++jddl){
208  Ke(3*inode+iddl,3*jnode+jddl) = 0.0;
209  }
210  }
211  }
212  }
213  xg.Multiply('N','N',1.0,matrix_X,Mesh->N_cells,0.0);
214  for (unsigned int gp=0; gp<n_gauss_points; ++gp){
215  gauss_weight = Mesh->gauss_weight_cells(gp);
216  fvol = get_forcing(xg(0,gp),xg(1,gp),xg(2,gp),e_lid,gp);
217  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
218  dx_shape_functions(inode,0) = Mesh->DX_N_cells(gp+n_gauss_points*inode,e_lid);
219  dx_shape_functions(inode,1) = Mesh->DY_N_cells(gp+n_gauss_points*inode,e_lid);
220  dx_shape_functions(inode,2) = Mesh->DZ_N_cells(gp+n_gauss_points*inode,e_lid);
221  for (unsigned int iddl=0; iddl<3; ++iddl){
222  fevol(3*inode+iddl) += gauss_weight*pressure_load*fvol(iddl)*Mesh->N_cells(inode,gp)*Mesh->detJac_cells(e_lid,gp);
223  }
224  }
225 
226  error = deformation_gradient.Multiply('N','N',1.0,matrix_x,dx_shape_functions,0.0);
227  compute_B_matrices(deformation_gradient,dx_shape_functions,matrix_B,matrix_BG);
228 
229  get_material_parameters(e_lid, gp);
230  get_constitutive_tensors(deformation_gradient, scd_piola_stress, tangent_matrix);
231 
232  for (unsigned int i=0; i<3; ++i){
233  block_scd_piola_stress(3*i+0,3*i+0) = scd_piola_stress(0);
234  block_scd_piola_stress(3*i+0,3*i+1) = scd_piola_stress(5);
235  block_scd_piola_stress(3*i+0,3*i+2) = scd_piola_stress(4);
236  block_scd_piola_stress(3*i+1,3*i+0) = scd_piola_stress(5);
237  block_scd_piola_stress(3*i+1,3*i+1) = scd_piola_stress(1);
238  block_scd_piola_stress(3*i+1,3*i+2) = scd_piola_stress(3);
239  block_scd_piola_stress(3*i+2,3*i+0) = scd_piola_stress(4);
240  block_scd_piola_stress(3*i+2,3*i+1) = scd_piola_stress(3);
241  block_scd_piola_stress(3*i+2,3*i+2) = scd_piola_stress(2);
242  }
243 
244  error = Re.Multiply('T','N',-gauss_weight*Mesh->detJac_cells(e_lid,gp),matrix_B,scd_piola_stress,1.0);
245 
246  error = B_times_TM.Multiply('T','N',gauss_weight*Mesh->detJac_cells(e_lid,gp),matrix_B,tangent_matrix,0.0);
247  error = Ke.Multiply('N','N',1.0,B_times_TM,matrix_B,1.0);
248 
249  error = BG_times_BSPS.Multiply('T','N',gauss_weight*Mesh->detJac_cells(e_lid,gp),matrix_BG,block_scd_piola_stress,0.0);
250  error = Ke.Multiply('N','N',1.0,BG_times_BSPS,matrix_BG,1.0);
251  }
252 
253  for (unsigned int i=0; i<3*Mesh->el_type; ++i){
254  error = F.SumIntoGlobalValues(1, &Indexes[i], &Re(i));
255  error = F.SumIntoGlobalValues(1, &Indexes[i], &fevol(i));
256  for (unsigned int j=0; j<3*Mesh->el_type; ++j){
257  error = K.SumIntoGlobalValues(1, &Indexes[i], 1, &Indexes[j], &Ke(i,j));
258  }
259  }
260  }
261  delete[] Indexes;
262 }
263 
265 
266  int node;
267  int* Indexes;
268  unsigned int e_gid;
269  Indexes = new int [3*Mesh->face_type];
270 
271  int n_gauss_points = Mesh->n_gauss_faces;
272  double gauss_weight;
273 
274  Epetra_SerialDenseMatrix xg(3,n_gauss_points), matrix_X(3,Mesh->face_type);
275  Epetra_SerialDenseVector force(3*Mesh->face_type);
276  Epetra_SerialDenseVector dead_pressure(3);
277 
278  for (unsigned int e_lid=0; e_lid<Mesh->n_local_faces; ++e_lid){
279  e_gid = Mesh->local_faces[e_lid];
280  for (unsigned int inode=0; inode<Mesh->face_type; ++inode){
281  node = Mesh->faces_nodes[Mesh->face_type*e_gid+inode];
282  Indexes[3*inode+0] = 3*node+0;
283  Indexes[3*inode+1] = 3*node+1;
284  Indexes[3*inode+2] = 3*node+2;
285  matrix_X(0,inode) = Mesh->nodes_coord[3*node+0];
286  matrix_X(1,inode) = Mesh->nodes_coord[3*node+1];
287  matrix_X(2,inode) = Mesh->nodes_coord[3*node+2];
288  for (unsigned int iddl=0; iddl<3; ++iddl){
289  force(3*inode+iddl) = 0.0;
290  }
291  }
292  xg.Multiply('N','T',1.0,matrix_X,Mesh->N_faces,0.0);
293  for (unsigned int gp=0; gp<n_gauss_points; ++gp){
294  gauss_weight = Mesh->gauss_weight_faces(gp);
295  dead_pressure = get_neumannBc(matrix_X,xg,gp);
296  for (unsigned int inode=0; inode<Mesh->face_type; ++inode){
297  for (unsigned int iddl=0; iddl<3; ++iddl){
298  force(3*inode+iddl) += gauss_weight*pressure_load*dead_pressure(iddl)*Mesh->N_faces(gp,inode);
299  }
300  }
301  }
302  for (unsigned int inode=0; inode<Mesh->face_type; ++inode){
303  for (unsigned int iddl=0; iddl<3; ++iddl){
304  F.SumIntoGlobalValues(1, &Indexes[3*inode+iddl], &force(3*inode+iddl));
305  }
306  }
307  }
308  delete[] Indexes;
309 }
Epetra_Comm * Comm
for j
Definition: costFunction.m:42
u
Definition: run.m:9
void assembleMixedDirichletNeumann_homogeneousForcing(Epetra_Vector &x, 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 void get_constitutive_tensors(Epetra_SerialDenseMatrix &deformation_gradient, Epetra_SerialDenseVector &piola_stress, Epetra_SerialDenseMatrix &tangent_piola)=0
Epetra_SerialDenseVector N_cells
Definition: meshpp.hpp:73
int n_local_cells
Definition: meshpp.hpp:94
void stiffnessRhs_inhomogeneousForcing(Epetra_Vector &u, Epetra_FECrsMatrix &K, Epetra_FEVector &F)
void assembleMixedDirichletNeumann_inhomogeneousForcing(Epetra_Vector &x, Epetra_FECrsMatrix &K, Epetra_FEVector &F)
void rhs_NeumannBoundaryCondition(Epetra_FEVector &F)
Epetra_SerialDenseMatrix N_faces
Definition: meshpp.hpp:71
unsigned int n_gauss_faces
Definition: meshpp.hpp:97
int face_type
Definition: meshpp.hpp:91
Epetra_SerialDenseVector DX_N_cells
Definition: meshpp.hpp:73
virtual Epetra_SerialDenseVector get_forcing(double &x1, double &x2, double &x3, unsigned int &e_lid, unsigned int &gp)=0
Epetra_SerialDenseVector detJac_cells
Definition: meshpp.hpp:73
void assemblePureDirichlet_inhomogeneousForcing(Epetra_Vector &x, Epetra_FECrsMatrix &K, Epetra_FEVector &F)
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 assemblePureDirichlet_homogeneousForcing(Epetra_Vector &x, Epetra_FECrsMatrix &K, Epetra_FEVector &F)
std::vector< int > faces_nodes
Definition: meshpp.hpp:78
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
unsigned int n_gauss_cells
Definition: meshpp.hpp:98
Epetra_SerialDenseVector gauss_weight_faces
Definition: meshpp.hpp:99
void compute_B_matrices(Epetra_SerialDenseMatrix &F, Epetra_SerialDenseMatrix &dx_shape_functions, Epetra_SerialDenseMatrix &B, Epetra_SerialDenseMatrix &BG)
void stiffnessRhs_homogeneousForcing(Epetra_Vector &u, Epetra_FECrsMatrix &K, Epetra_FEVector &F)
virtual void get_material_parameters(unsigned int &e_lid, unsigned int &gp)=0
for i
Definition: costFunction.m:38
Epetra_Map * OverlapMap
Epetra_SerialDenseVector gauss_weight_cells
Definition: meshpp.hpp:99