Trilinos based (stochastic) FEM solvers
nearlyIncompressibleHyperelasticity.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 nearlyIncompressibleHyperelasticity::assemblePureDirichlet_homogeneousForcing(Epetra_Vector & x, Epetra_FECrsMatrix & K, Epetra_FEVector & F){
14 
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 
25  K.GlobalAssemble();
26  K.FillComplete();
27  F.GlobalAssemble();
28 }
29 void nearlyIncompressibleHyperelasticity::assembleMixedDirichletDeformationDependentNeumann_homogeneousForcing(Epetra_Vector & x, Epetra_FECrsMatrix & K, Epetra_FEVector & F){
30 
31  F.PutScalar(0.0);
32  K.PutScalar(0.0);
33 
34  Epetra_Vector u(*OverlapMap);
35  u.Import(x, *ImportToOverlapMap, Insert);
36 
39 
40  Comm->Barrier();
41  K.GlobalAssemble();
42  K.FillComplete();
43  F.GlobalAssemble();
44 }
45 
46 void nearlyIncompressibleHyperelasticity::stiffnessRhsMaterialContribution(Epetra_Vector & u, Epetra_FECrsMatrix & K, Epetra_FEVector & F){
47  int node, e_gid, catch_error;
48  int n_gauss_points = Mesh->n_gauss_cells;
49  double gauss_weight;
50  double det, theta, pressure, dpressure, coeff_kp;
51 
52  int *Indexes;
53  Indexes = new int [3*Mesh->el_type];
54 
55  Epetra_SerialDenseMatrix Ke(3*Mesh->el_type,3*Mesh->el_type), Ke_vol(3*Mesh->el_type,3*Mesh->el_type);
56  Epetra_SerialDenseMatrix Kg(3*Mesh->el_type,3*Mesh->el_type), Kg_vol(3*Mesh->el_type,3*Mesh->el_type);
57  Epetra_SerialDenseMatrix Kp(3*Mesh->el_type,3*Mesh->el_type);
58  Epetra_SerialDenseVector Re(3*Mesh->el_type), Re_vol(3*Mesh->el_type), Re_vol2(3*Mesh->el_type);
59 
60  Epetra_SerialDenseMatrix deformation_gradient(3,3);
61  Epetra_SerialDenseMatrix tangent_matrix_isc(6,6);
62  Epetra_SerialDenseMatrix tangent_matrix_vol(6,6);
63  Epetra_SerialDenseVector scd_piola_stress_isc(6);
64  Epetra_SerialDenseVector scd_piola_stress_vol(6);
65  Epetra_SerialDenseVector piola_vol(6);
66  Epetra_SerialDenseVector inverse_cauchy(6);
67  Epetra_SerialDenseMatrix block_scd_piola_stress_isc(9,9);
68  Epetra_SerialDenseMatrix block_scd_piola_stress_vol(9,9);
69  Epetra_SerialDenseMatrix matrix_x(3,Mesh->el_type);
70 
71  Epetra_SerialDenseMatrix dx_shape_functions(Mesh->el_type,3);
72  Epetra_SerialDenseMatrix matrix_B(6,3*Mesh->el_type);
73  Epetra_SerialDenseMatrix B_times_TM(3*Mesh->el_type,6);
74  Epetra_SerialDenseMatrix matrix_BG(9,3*Mesh->el_type);
75  Epetra_SerialDenseMatrix BG_times_BSPS(3*Mesh->el_type,9);
76 
77  for (unsigned int e_lid=0; e_lid<Mesh->n_local_cells; ++e_lid){
78  e_gid = Mesh->local_cells[e_lid];
79 
80  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
81  node = Mesh->cells_nodes[Mesh->el_type*e_gid+inode];
82  matrix_x(0,inode) = u[OverlapMap->LID(3*node+0)] + Mesh->nodes_coord[3*node+0];
83  matrix_x(1,inode) = u[OverlapMap->LID(3*node+1)] + Mesh->nodes_coord[3*node+1];
84  matrix_x(2,inode) = u[OverlapMap->LID(3*node+2)] + Mesh->nodes_coord[3*node+2];
85 
86  for (int iddl=0; iddl<3; ++iddl){
87  Re(3*inode+iddl) = 0.0;
88  Re_vol(3*inode+iddl) = 0.0;
89  Re_vol2(3*inode+iddl) = 0.0;
90  Indexes[3*inode+iddl] = 3*node+iddl;
91  for (unsigned int jnode=0; jnode<Mesh->el_type; ++jnode){
92  for (int jddl=0; jddl<3; ++jddl){
93  Ke(3*inode+iddl,3*jnode+jddl) = 0.0;
94  Ke_vol(3*inode+iddl,3*jnode+jddl) = 0.0;
95  Kg(3*inode+iddl,3*jnode+jddl) = 0.0;
96  Kg_vol(3*inode+iddl,3*jnode+jddl) = 0.0;
97  }
98  }
99  }
100  }
101 
102  theta = 0.0;
103  for (unsigned int gp=0; gp<n_gauss_points; ++gp){
104  gauss_weight = Mesh->gauss_weight_cells(gp);
105  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
106  dx_shape_functions(inode,0) = Mesh->DX_N_cells(gp+n_gauss_points*inode,e_lid);
107  dx_shape_functions(inode,1) = Mesh->DY_N_cells(gp+n_gauss_points*inode,e_lid);
108  dx_shape_functions(inode,2) = Mesh->DZ_N_cells(gp+n_gauss_points*inode,e_lid);
109  }
110 
111  deformation_gradient.Multiply('N','N',1.0,matrix_x,dx_shape_functions,0.0);
112  compute_B_matrices(deformation_gradient,dx_shape_functions,matrix_B,matrix_BG);
113 
114  get_material_parameters(e_lid, gp);
115  get_constitutive_tensors_static_condensation(deformation_gradient, det, inverse_cauchy, scd_piola_stress_isc, scd_piola_stress_vol, tangent_matrix_isc, tangent_matrix_vol);
116 
117  for (unsigned int i=0; i<3; ++i){
118  block_scd_piola_stress_isc(3*i+0,3*i+0) = scd_piola_stress_isc(0);
119  block_scd_piola_stress_isc(3*i+0,3*i+1) = scd_piola_stress_isc(5);
120  block_scd_piola_stress_isc(3*i+0,3*i+2) = scd_piola_stress_isc(4);
121  block_scd_piola_stress_isc(3*i+1,3*i+0) = scd_piola_stress_isc(5);
122  block_scd_piola_stress_isc(3*i+1,3*i+1) = scd_piola_stress_isc(1);
123  block_scd_piola_stress_isc(3*i+1,3*i+2) = scd_piola_stress_isc(3);
124  block_scd_piola_stress_isc(3*i+2,3*i+0) = scd_piola_stress_isc(4);
125  block_scd_piola_stress_isc(3*i+2,3*i+1) = scd_piola_stress_isc(3);
126  block_scd_piola_stress_isc(3*i+2,3*i+2) = scd_piola_stress_isc(2);
127 
128  block_scd_piola_stress_vol(3*i+0,3*i+0) = scd_piola_stress_vol(0);
129  block_scd_piola_stress_vol(3*i+0,3*i+1) = scd_piola_stress_vol(5);
130  block_scd_piola_stress_vol(3*i+0,3*i+2) = scd_piola_stress_vol(4);
131  block_scd_piola_stress_vol(3*i+1,3*i+0) = scd_piola_stress_vol(5);
132  block_scd_piola_stress_vol(3*i+1,3*i+1) = scd_piola_stress_vol(1);
133  block_scd_piola_stress_vol(3*i+1,3*i+2) = scd_piola_stress_vol(3);
134  block_scd_piola_stress_vol(3*i+2,3*i+0) = scd_piola_stress_vol(4);
135  block_scd_piola_stress_vol(3*i+2,3*i+1) = scd_piola_stress_vol(3);
136  block_scd_piola_stress_vol(3*i+2,3*i+2) = scd_piola_stress_vol(2);
137  }
138 
139  for (unsigned int j=0; j<6; ++j){
140  piola_vol(j) = det*inverse_cauchy(j);
141  }
142 
143  theta += gauss_weight*det*Mesh->detJac_cells(e_lid,gp);
144 
145  Re.Multiply('T','N',-gauss_weight*Mesh->detJac_cells(e_lid,gp),matrix_B,scd_piola_stress_isc,1.0);
146  Re_vol.Multiply('T','N',-gauss_weight*Mesh->detJac_cells(e_lid,gp),matrix_B,scd_piola_stress_vol,1.0);
147  Re_vol2.Multiply('T','N',-gauss_weight*Mesh->detJac_cells(e_lid,gp),matrix_B,piola_vol,1.0);
148 
149  B_times_TM.Multiply('T','N',gauss_weight*Mesh->detJac_cells(e_lid,gp),matrix_B,tangent_matrix_isc,0.0);
150  Ke.Multiply('N','N',1.0,B_times_TM,matrix_B,1.0);
151  B_times_TM.Multiply('T','N',gauss_weight*Mesh->detJac_cells(e_lid,gp),matrix_B,tangent_matrix_vol,0.0);
152  Ke_vol.Multiply('N','N',1.0,B_times_TM,matrix_B,1.0);
153 
154  BG_times_BSPS.Multiply('T','N',gauss_weight*Mesh->detJac_cells(e_lid,gp),matrix_BG,block_scd_piola_stress_isc,0.0);
155  Kg.Multiply('N','N',1.0,BG_times_BSPS,matrix_BG,1.0);
156  BG_times_BSPS.Multiply('T','N',gauss_weight*Mesh->detJac_cells(e_lid,gp),matrix_BG,block_scd_piola_stress_vol,0.0);
157  Kg_vol.Multiply('N','N',1.0,BG_times_BSPS,matrix_BG,1.0);
158  }
159 
160  theta = theta/Mesh->vol_cells(e_lid);
161  get_internal_pressure(theta,pressure,dpressure);
162  coeff_kp = dpressure/Mesh->vol_cells(e_lid);
163 
164  Kp.Multiply('N','T',coeff_kp,Re_vol,Re_vol2,0.0);
165  Re_vol.Scale(pressure);
166  Ke_vol.Scale(pressure);
167  Kg_vol.Scale(pressure);
168 
169  Re += Re_vol;
170  Ke += Ke_vol;
171  Ke += Kg;
172  Ke += Kg_vol;
173  Ke += Kp;
174 
175  for (unsigned int i=0; i<3*Mesh->el_type; ++i){
176  F.SumIntoGlobalValues(1, &Indexes[i], &Re(i));
177  for (unsigned int j=0; j<3*Mesh->el_type; ++j){
178  catch_error = K.SumIntoGlobalValues(1, &Indexes[i], 1, &Indexes[j], &Ke(i,j));
179  }
180  }
181 
182  }
183  delete[] Indexes;
184 }
185 void nearlyIncompressibleHyperelasticity::stiffnessRhsPressureContribution(Epetra_Vector & u, Epetra_FECrsMatrix & K, Epetra_FEVector & F){
186 
187  double kf;
188  int n_gauss_points = Mesh->n_gauss_faces;
189  double gauss_weight;
190 
191  unsigned int e_gid;
192  int node;
193  int * Indexes;
194  Indexes = new int [3*Mesh->face_type];
195 
196  Epetra_SerialDenseMatrix d_shape_functions(Mesh->face_type,2);
197  Epetra_SerialDenseMatrix matrix_x(3,Mesh->face_type);
198  Epetra_SerialDenseMatrix dxi_matrix_x(3,2);
199  Epetra_SerialDenseMatrix k1(Mesh->face_type,Mesh->face_type), k2(Mesh->face_type,Mesh->face_type), k3(Mesh->face_type,Mesh->face_type);
200  Epetra_SerialDenseVector force(3*Mesh->face_type);
201 
202  for (unsigned int e_lid=0; e_lid<Mesh->n_local_faces; ++e_lid){
203  e_gid = Mesh->local_faces[e_lid];
204  for (unsigned int inode=0; inode<Mesh->face_type; ++inode){
205  node = Mesh->faces_nodes[Mesh->face_type*e_gid+inode];
206  Indexes[3*inode+0] = 3*node+0;
207  Indexes[3*inode+1] = 3*node+1;
208  Indexes[3*inode+2] = 3*node+2;
209  matrix_x(0,inode) = Mesh->nodes_coord[3*node+0] + u[OverlapMap->LID(3*node+0)];
210  matrix_x(1,inode) = Mesh->nodes_coord[3*node+1] + u[OverlapMap->LID(3*node+1)];
211  matrix_x(2,inode) = Mesh->nodes_coord[3*node+2] + u[OverlapMap->LID(3*node+2)];
212  force(3*inode+0) = 0.0;
213  force(3*inode+1) = 0.0;
214  force(3*inode+2) = 0.0;
215  for (unsigned int jnode=0; jnode<Mesh->face_type; ++jnode){
216  k1(inode,jnode) = 0.0;
217  k2(inode,jnode) = 0.0;
218  k3(inode,jnode) = 0.0;
219  }
220  }
221 
222  for (unsigned int gp=0; gp<n_gauss_points; ++gp){
223  gauss_weight = Mesh->gauss_weight_faces(gp);
224  for (unsigned int inode=0; inode<Mesh->face_type; ++inode){
225  d_shape_functions(inode,0) = Mesh->D1_N_faces(gp,inode);
226  d_shape_functions(inode,1) = Mesh->D2_N_faces(gp,inode);
227  }
228  dxi_matrix_x.Multiply('N','N',1.0,matrix_x,d_shape_functions,0.0);
229 
230  for (unsigned int inode=0; inode<Mesh->face_type; ++inode){
231  force(3*inode+0) += gauss_weight*pressure_load*Mesh->N_faces(gp,inode)*(dxi_matrix_x(1,0)*dxi_matrix_x(2,1) - dxi_matrix_x(2,0)*dxi_matrix_x(1,1));
232  force(3*inode+1) += gauss_weight*pressure_load*Mesh->N_faces(gp,inode)*(dxi_matrix_x(2,0)*dxi_matrix_x(0,1) - dxi_matrix_x(0,0)*dxi_matrix_x(2,1));
233  force(3*inode+2) += gauss_weight*pressure_load*Mesh->N_faces(gp,inode)*(dxi_matrix_x(0,0)*dxi_matrix_x(1,1) - dxi_matrix_x(1,0)*dxi_matrix_x(0,1));
234 
235  for (unsigned int jnode=0; jnode<Mesh->face_type; ++jnode){
236  k1(inode,jnode) += 0.5*gauss_weight*pressure_load*( dxi_matrix_x(0,0)*(d_shape_functions(inode,1)*Mesh->N_faces(gp,jnode) - d_shape_functions(jnode,1)*Mesh->N_faces(gp,inode)) - dxi_matrix_x(0,1)*(d_shape_functions(inode,0)*Mesh->N_faces(gp,jnode) - d_shape_functions(jnode,0)*Mesh->N_faces(gp,inode)) );
237  k2(inode,jnode) += 0.5*gauss_weight*pressure_load*( dxi_matrix_x(1,0)*(d_shape_functions(inode,1)*Mesh->N_faces(gp,jnode) - d_shape_functions(jnode,1)*Mesh->N_faces(gp,inode)) - dxi_matrix_x(1,1)*(d_shape_functions(inode,0)*Mesh->N_faces(gp,jnode) - d_shape_functions(jnode,0)*Mesh->N_faces(gp,inode)) );
238  k3(inode,jnode) += 0.5*gauss_weight*pressure_load*( dxi_matrix_x(2,0)*(d_shape_functions(inode,1)*Mesh->N_faces(gp,jnode) - d_shape_functions(jnode,1)*Mesh->N_faces(gp,inode)) - dxi_matrix_x(2,1)*(d_shape_functions(inode,0)*Mesh->N_faces(gp,jnode) - d_shape_functions(jnode,0)*Mesh->N_faces(gp,inode)) );
239  //General case (leads to a non symmetric stiffness)
240  //k1(inode,jnode) += gauss_weight*pressure_load*Mesh->N_faces(gp,inode)*(d_shape_functions(jnode,0)*dxi_matrix_x(0,1)-d_shape_functions(jnode,1)*dxi_matrix_x(0,0));
241  //k2(inode,jnode) += gauss_Weight*pressure_load*Mesh->N_faces(gp,inode)*(d_shape_functions(jnode,0)*dxi_matrix_x(1,1)-d_shape_functions(jnode,1)*dxi_matrix_x(1,0));
242  //k3(inode,jnode) += gauss_weight*pressure_load*Mesh->N_faces(gp,inode)*(d_shape_functions(jnode,0)*dxi_matrix_x(2,1)-d_shape_functions(jnode,1)*dxi_matrix_x(2,0));
243  }
244  }
245  }
246 
247  for (unsigned int i=0; i<3*Mesh->face_type; ++i){
248  F.SumIntoGlobalValues(1, &Indexes[i], &force(i));
249  }
250 
251  for (unsigned int inode=0; inode<Mesh->face_type; ++inode){
252  for (unsigned int jnode=0; jnode<Mesh->face_type; ++jnode){
253  kf = k1(inode,jnode);
254  K.SumIntoGlobalValues(1, &Indexes[3*inode+2], 1, &Indexes[3*jnode+1], &kf);
255  kf = -kf;
256  K.SumIntoGlobalValues(1, &Indexes[3*inode+1], 1, &Indexes[3*jnode+2], &kf);
257 
258  kf = k2(inode,jnode);
259  K.SumIntoGlobalValues(1, &Indexes[3*inode+0], 1, &Indexes[3*jnode+2], &kf);
260  kf = -kf;
261  K.SumIntoGlobalValues(1, &Indexes[3*inode+2], 1, &Indexes[3*jnode+0], &kf);
262 
263  kf = k3(inode,jnode);
264  K.SumIntoGlobalValues(1, &Indexes[3*inode+1], 1, &Indexes[3*jnode+0], &kf);
265  kf = -kf;
266  K.SumIntoGlobalValues(1, &Indexes[3*inode+0], 1, &Indexes[3*jnode+1], &kf);
267  }
268  }
269 
270  }
271  delete[] Indexes;
272 }
Epetra_Comm * Comm
for j
Definition: costFunction.m:42
u
Definition: run.m:9
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
Epetra_SerialDenseMatrix D2_N_faces
Definition: meshpp.hpp:71
int n_local_cells
Definition: meshpp.hpp:94
void stiffnessRhsPressureContribution(Epetra_Vector &u, Epetra_FECrsMatrix &K, Epetra_FEVector &F)
Epetra_SerialDenseMatrix N_faces
Definition: meshpp.hpp:71
Epetra_SerialDenseVector vol_cells
Definition: meshpp.hpp:73
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
Epetra_SerialDenseVector detJac_cells
Definition: meshpp.hpp:73
end theta
Definition: costFunction.m:30
std::vector< int > local_cells
Definition: meshpp.hpp:81
void stiffnessRhsMaterialContribution(Epetra_Vector &u, 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
Epetra_SerialDenseMatrix D1_N_faces
Definition: meshpp.hpp:71
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)
virtual void get_material_parameters(unsigned int &e_lid, unsigned int &gp)=0
void d_shape_functions(Epetra_SerialDenseMatrix &D, double &xi, double &eta)
Definition: fepp.cpp:12
void assembleMixedDirichletDeformationDependentNeumann_homogeneousForcing(Epetra_Vector &x, Epetra_FECrsMatrix &K, Epetra_FEVector &F)
for i
Definition: costFunction.m:38
Epetra_Map * OverlapMap
void assemblePureDirichlet_homogeneousForcing(Epetra_Vector &x, Epetra_FECrsMatrix &K, Epetra_FEVector &F)
virtual void get_constitutive_tensors_static_condensation(Epetra_SerialDenseMatrix &deformation_gradient, double &det, Epetra_SerialDenseVector &inverse_cauchy, Epetra_SerialDenseVector &piola_isc, Epetra_SerialDenseVector &piola_vol, Epetra_SerialDenseMatrix &tangent_piola_isc, Epetra_SerialDenseMatrix &tangent_piola_vol)=0
Epetra_SerialDenseVector gauss_weight_cells
Definition: meshpp.hpp:99
virtual void get_internal_pressure(double &theta, double &pressure, double &dpressure)=0