Trilinos based (stochastic) FEM solvers
compressible_Mooney_Transverse_Isotropic_Random_Field.hpp
Go to the documentation of this file.
1 /*
2 Brian Staber (brian.staber@gmail.com)
3 */
4 
5 #ifndef COMPRESSIBLE_MOONEY_TRANSVERSE_ISOTROPIC_RANDOM_FIELD_HPP
6 #define COMPRESSIBLE_MOONEY_TRANSVERSE_ISOTROPIC_RANDOM_FIELD_HPP
7 
8 #include "tensor_calculus.hpp"
11 
13 {
14 public:
15 
16  Teuchos::RCP<shinozuka_layeredcomp_2d> GRF_Generator;
17 
18  Epetra_SerialDenseVector mu1rf, mu2rf, mu3rf, mu4rf, mu5rf;
19  Epetra_SerialDenseVector omega;
20  Epetra_SerialDenseVector mean_mu;
21  double mu1, mu2, mu3, mu4, mu5;
25  double topcoord;
26  std::vector<int> phase;
27 
28  tiMooneyRandomField(Epetra_Comm & comm,
29  Teuchos::ParameterList & Parameters){
30 
31  std::string mesh_file = Teuchos::getParameter<std::string>(Parameters.sublist("Mesh"), "mesh_file");
32  Mesh = new mesh(comm, mesh_file, 1.0);
33  Comm = Mesh->Comm;
34 
35  StandardMap = new Epetra_Map(-1,3*Mesh->n_local_nodes_without_ghosts,&Mesh->local_dof_without_ghosts[0],0,*Comm);
36  OverlapMap = new Epetra_Map(-1,3*Mesh->n_local_nodes,&Mesh->local_dof[0],0,*Comm);
37  ImportToOverlapMap = new Epetra_Import(*OverlapMap,*StandardMap);
38 
40 
41  findtop();
43  for (unsigned int e=0; e<Mesh->n_cells/32; ++e){
44  for (unsigned int j=0; j<32; ++j){
45  phase.push_back(j);
46  }
47  }
48  mean_mu.Resize(5);
49  omega.Resize(6);
50 
51  int order = Teuchos::getParameter<int>(Parameters.sublist("Shinozuka"), "order");
52  GRF_Generator = Teuchos::rcp(new shinozuka_layeredcomp_2d(order));
53  }
54 
56  }
57 
58  void findtop(){
59  topcoord = 0.0;
60  if (Comm->MyPID()==0){
61  for (unsigned int n=0; n<Mesh->n_nodes; ++n){
62  if (Mesh->nodes_coord[3*n+1]>topcoord){
63  topcoord = Mesh->nodes_coord[3*n+1];
64  }
65  }
66  }
67  Comm->Broadcast(&topcoord,1,0);
68  Comm->Barrier();
69  }
70 
71  void set_plyagl(double & Plyagl){
72  plyagl = Plyagl;
73  GRF_Generator->rotation = plyagl;
74  }
75 
76  void setParameters(Epetra_SerialDenseVector & parameters,
77  Epetra_SerialDenseVector & exponents,
78  Epetra_SerialDenseVector & hyperParameters){
79  mean_mu = parameters;
80  beta3 = -0.5;
81  beta4 = exponents(0);
82  beta5 = exponents(1);
83  omega = hyperParameters;
84  }
85 
86  void RandomFieldGenerator(Epetra_IntSerialDenseVector & seeds){
87 
88  Epetra_SerialDenseVector w1_shino(Mesh->n_local_cells*Mesh->n_gauss_cells);
89  Epetra_SerialDenseVector w2_shino(Mesh->n_local_cells*Mesh->n_gauss_cells);
90  Epetra_SerialDenseVector w3_shino(Mesh->n_local_cells*Mesh->n_gauss_cells);
91  Epetra_SerialDenseVector w4_shino(Mesh->n_local_cells*Mesh->n_gauss_cells);
92  Epetra_SerialDenseVector w5_shino(Mesh->n_local_cells*Mesh->n_gauss_cells);
93 
94  mu1rf.Resize(Mesh->n_local_cells*Mesh->n_gauss_cells);
95  mu2rf.Resize(Mesh->n_local_cells*Mesh->n_gauss_cells);
96  mu3rf.Resize(Mesh->n_local_cells*Mesh->n_gauss_cells);
97  mu4rf.Resize(Mesh->n_local_cells*Mesh->n_gauss_cells);
98  mu5rf.Resize(Mesh->n_local_cells*Mesh->n_gauss_cells);
99 
100  GRF_Generator->l1 = omega(4);
101  GRF_Generator->l2 = omega(5);
102 
103  GRF_Generator->rng.seed(seeds(0));
104  GRF_Generator->generator_gauss_points(w1_shino,*Mesh,phase);
105 
106  GRF_Generator->rng.seed(seeds(1));
107  GRF_Generator->generator_gauss_points(w2_shino,*Mesh,phase);
108 
109  GRF_Generator->rng.seed(seeds(2));
110  GRF_Generator->generator_gauss_points(w3_shino,*Mesh,phase);
111 
112  GRF_Generator->rng.seed(seeds(3));
113  GRF_Generator->generator_gauss_points(w4_shino,*Mesh,phase);
114 
115  GRF_Generator->rng.seed(seeds(4));
116  GRF_Generator->generator_gauss_points(w5_shino,*Mesh,phase);
117 
118  double alpha, beta;
119  for (unsigned int i=0; i<w1_shino.Length(); ++i){
120  alpha = 1.0/(omega(0)*omega(0)); beta = mean_mu(0)*omega(0)*omega(0);
121  mu1rf(i) = icdf_gamma(w1_shino(i),alpha,beta);
122 
123  alpha = 1.0/(omega(1)*omega(1)); beta = mean_mu(1)*omega(1)*omega(1);
124  mu2rf(i) = icdf_gamma(w2_shino(i),alpha,beta);
125 
126  alpha = 1.0/(omega(2)*omega(2)); beta = mean_mu(2)*omega(2)*omega(2);
127  mu3rf(i) = icdf_gamma(w3_shino(i),alpha,beta);
128 
129  alpha = 1.0/(omega(3)*omega(3)); beta = mean_mu(3)*omega(3)*omega(3);
130  mu4rf(i) = icdf_gamma(w4_shino(i),alpha,beta);
131 
132  alpha = (2.0*alpha)-1.0; beta = mean_mu(4)/alpha;
133  mu5rf(i) = icdf_gamma(w5_shino(i),alpha,beta);
134  }
135 
136  }
137 
138  double icdf_gamma(double & w,
139  double & alpha,
140  double & beta){
141  double erfx = boost::math::erf<double>(w/std::sqrt(2.0));
142  double y = (1.0/2.0)*(1.0 + erfx);
143  double yinv = boost::math::gamma_p_inv<double,double>(alpha,y);
144  double z = yinv*beta;
145  return z;
146  }
147 
148  void get_matrix_and_rhs(Epetra_Vector & x,
149  Epetra_FECrsMatrix & K,
150  Epetra_FEVector & F){
152  }
153 
155  n_bc_dof = 0;
156  double coord;
157  unsigned int node;
158  for (unsigned int i=0; i<Mesh->n_local_nodes_without_ghosts; ++i){
159  node = Mesh->local_nodes[i];
160  coord = Mesh->nodes_coord[3*node+1];
161  if(coord==0.0){
162  n_bc_dof+=3;
163  }
164  if(coord==topcoord){
165  n_bc_dof+=3;
166  }
167  }
168 
169  int indbc = 0;
170  dof_on_boundary = new int [n_bc_dof];
171  for (unsigned int inode=0; inode<Mesh->n_local_nodes_without_ghosts; ++inode){
172  node = Mesh->local_nodes[inode];
173  coord = Mesh->nodes_coord[3*node+1];
174  if (coord==0.0){
175  dof_on_boundary[indbc+0] = 3*inode+0;
176  dof_on_boundary[indbc+1] = 3*inode+1;
177  dof_on_boundary[indbc+2] = 3*inode+2;
178  indbc+=3;
179  }
180  if (coord==topcoord){
181  dof_on_boundary[indbc+0] = 3*inode+0;
182  dof_on_boundary[indbc+1] = 3*inode+1;
183  dof_on_boundary[indbc+2] = 3*inode+2;
184  indbc+=3;
185  }
186  }
187  }
188 
189  void apply_dirichlet_conditions(Epetra_FECrsMatrix & K,
190  Epetra_FEVector & F,
191  double & displacement){
192  Epetra_MultiVector v(*StandardMap,true);
193  v.PutScalar(0.0);
194 
195  int node;
196  double coord;
197  for (unsigned int inode=0; inode<Mesh->n_local_nodes_without_ghosts; ++inode){
198  node = Mesh->local_nodes[inode];
199  coord = Mesh->nodes_coord[3*node+1];
200  if (coord==topcoord){
201  v[0][StandardMap->LID(3*node+1)] = displacement;
202  }
203  }
204 
205  Epetra_MultiVector rhs_dir(*StandardMap,true);
206  K.Apply(v,rhs_dir);
207  F.Update(-1.0,rhs_dir,1.0);
208 
209  for (unsigned int inode=0; inode<Mesh->n_local_nodes_without_ghosts; ++inode){
210  node = Mesh->local_nodes[inode];
211  coord = Mesh->nodes_coord[3*node+1];
212  if (coord==0.0){
213  F[0][StandardMap->LID(3*node+0)] = v[0][StandardMap->LID(3*node+0)];
214  F[0][StandardMap->LID(3*node+1)] = v[0][StandardMap->LID(3*node+1)];
215  F[0][StandardMap->LID(3*node+2)] = v[0][StandardMap->LID(3*node+2)];
216  }
217  if (coord==topcoord){
218  F[0][StandardMap->LID(3*node+0)] = v[0][StandardMap->LID(3*node+0)];
219  F[0][StandardMap->LID(3*node+1)] = v[0][StandardMap->LID(3*node+1)];
220  F[0][StandardMap->LID(3*node+2)] = v[0][StandardMap->LID(3*node+2)];
221  }
222  }
223  ML_Epetra::Apply_OAZToMatrix(dof_on_boundary,n_bc_dof,K);
224  }
225 
226  void get_material_parameters(unsigned int & e_lid,
227  unsigned int & gp){
228  unsigned int e_gid = Mesh->local_cells[e_lid];
229  int n_gauss_cells = Mesh->n_gauss_cells;
230  mu1 = mu1rf(e_lid*n_gauss_cells+gp);
231  mu2 = mu2rf(e_lid*n_gauss_cells+gp);
232  mu3 = mu3rf(e_lid*n_gauss_cells+gp);
233  mu4 = mu4rf(e_lid*n_gauss_cells+gp);
234  mu5 = mu5rf(e_lid*n_gauss_cells+gp);
235  mu = 2.0*mu1 + 4.0*mu2 + 2.0*mu3;
236  trm = mu4 + 2.0*mu5;
237  ptrmbeta4 = std::pow(trm,beta4);
238  ptrmbeta5 = std::pow(trm,beta5);
239  if (phase[e_gid] % 2){
240  cos_plyagl = std::cos(plyagl);
241  sin_plyagl = std::sin(plyagl);
242  }
243  else{
244  cos_plyagl = std::cos(plyagl);
245  sin_plyagl = -std::sin(plyagl);
246  }
247  }
248 
249  void get_constitutive_tensors(Epetra_SerialDenseMatrix & deformation_gradient,
250  Epetra_SerialDenseVector & piola_stress,
251  Epetra_SerialDenseMatrix & tangent_piola){
252 
253  double det = deformation_gradient(0,0)*deformation_gradient(1,1)*deformation_gradient(2,2)
254  - deformation_gradient(0,0)*deformation_gradient(1,2)*deformation_gradient(2,1)
255  - deformation_gradient(0,1)*deformation_gradient(1,0)*deformation_gradient(2,2)
256  + deformation_gradient(0,1)*deformation_gradient(1,2)*deformation_gradient(2,0)
257  + deformation_gradient(0,2)*deformation_gradient(1,0)*deformation_gradient(2,1)
258  - deformation_gradient(0,2)*deformation_gradient(1,1)*deformation_gradient(2,0);
259 
260  Epetra_SerialDenseMatrix C(3,3), CC(3,3), ddJ5(6,6);
261  Epetra_SerialDenseVector LML(6), eye(6), dJ5(6), M(6), L(6), c(6);
262 
263  C.Multiply('T','N',1.0,deformation_gradient,deformation_gradient,0.0);
264  CC.Multiply('N','N',1.0,C,C,0.0);
265 
266  c(0) = C(0,0); c(1) = C(1,1); c(2) = C(2,2); c(3) = C(1,2); c(4) = C(0,2); c(5) = C(0,1);
267 
268  L(0) = (1.0/(det*det))*(C(1,1)*C(2,2)-C(1,2)*C(2,1));
269  L(1) = (1.0/(det*det))*(C(0,0)*C(2,2)-C(0,2)*C(2,0));
270  L(2) = (1.0/(det*det))*(C(0,0)*C(1,1)-C(0,1)*C(1,0));
271  L(3) = (1.0/(det*det))*(C(0,2)*C(1,0)-C(0,0)*C(1,2));
272  L(4) = (1.0/(det*det))*(C(0,1)*C(1,2)-C(0,2)*C(1,1));
273  L(5) = (1.0/(det*det))*(C(0,2)*C(2,1)-C(0,1)*C(2,2));
274 
275  M(0) = mu4*sin_plyagl*sin_plyagl+mu5*cos_plyagl*cos_plyagl;
276  M(1) = mu4*cos_plyagl*cos_plyagl+mu5*sin_plyagl*sin_plyagl;
277  M(2) = mu5;
278  M(3) = 0.0;
279  M(4) = 0.0;
280  M(5) = (mu4-mu5)*cos_plyagl*sin_plyagl;
281 
282  LML(0) = M(0)*L(0)*L(0)+2.0*M(4)*L(0)*L(4)+2.0*M(5)*L(0)*L(5)+M(2)*L(4)*L(4)+2.0*M(3)*L(4)*L(5)+M(1)*L(5)*L(5);
283  LML(1) = M(1)*L(1)*L(1)+2.0*M(4)*L(1)*L(3)+2.0*M(5)*L(1)*L(5)+M(2)*L(3)*L(3)+2.0*M(4)*L(3)*L(5)+M(0)*L(5)*L(5);
284  LML(2) = M(2)*L(2)*L(2)+2.0*M(3)*L(2)*L(3)+2.0*M(4)*L(2)*L(4)+M(1)*L(3)*L(3)+2.0*M(5)*L(3)*L(4)+M(0)*L(4)*L(4);
285  LML(3) = L(2)*(L(1)*M(3)+L(3)*M(2)+L(5)*M(4))+L(3)*(L(1)*M(1)+L(3)*M(3)+L(5)*M(5))+L(4)*(L(5)*M(0)+L(1)*M(5)+L(3)*M(4));
286  LML(4) = L(2)*(L(0)*M(4)+L(4)*M(2)+L(5)*M(3))+L(3)*(L(0)*M(5)+L(5)*M(1)+L(4)*M(3))+L(4)*(L(0)*M(0)+L(4)*M(4)+L(5)*M(5));
287  LML(5) = L(1)*(L(0)*M(5)+L(5)*M(1)+L(4)*M(3))+L(3)*(L(0)*M(4)+L(4)*M(2)+L(5)*M(3))+L(5)*(L(0)*M(0)+L(4)*M(4)+L(5)*M(5));
288 
289  eye(0) = 1.0; eye(1) = 1.0; eye(2) = 1.0; eye(3) = 0.0; eye(4) = 0.0; eye(5) = 0.0;
290 
291  double I1 = C(0,0) + C(1,1) + C(2,2);
292  double II1 = C(0,0)*C(0,0) + C(1,1)*C(1,1) + C(2,2)*C(2,2) + 2.0*C(1,2)*C(1,2) + 2.0*C(0,2)*C(0,2) + 2.0*C(0,1)*C(0,1);
293  double I2 = (1.0/2.0)*(I1*I1-II1);
294  double I3 = det*det;
295  double I4 = C(0,0)*M(0) + C(1,1)*M(1) + C(2,2)*M(2) + 2.0*C(0,1)*M(5) + 2.0*C(0,2)*M(4) + 2.0*C(1,2)*M(3);
296  double I5 = CC(0,0)*M(0) + CC(1,1)*M(1) + CC(2,2)*M(2) + 2.0*CC(0,1)*M(5) + 2.0*CC(0,2)*M(4) + 2.0*CC(1,2)*M(3);
297  double J5 = I5 - I1*I4 + I2*trm;
298  double pI3 = std::pow(I3,-beta3);
299  double pI4 = std::pow(I4, beta4);
300  double pJ5 = std::pow(J5, beta5);
301 
302  for (unsigned int i=0; i<6; ++i){
303  dJ5(i) = J5*L(i) - I3*LML(i);
304  piola_stress(i) = 2.0*mu1*eye(i) + 2.0*mu2*(I1*eye(i)-c(i)) + (2.0*mu3*det*det-mu)*L(i)
305  + (2.0/ptrmbeta4)*pI4*M(i) + (2.0/ptrmbeta5)*pJ5*dJ5(i) - 2.0*trm*pI3*L(i);
306  }
307 
308  tensor_product(4.0*mu2,eye,eye,tangent_piola,0.0);
309  sym_tensor_product(-4.0*mu2,eye,eye,tangent_piola,1.0);
310 
311  tensor_product(4.0*mu3*det*det,L,L,tangent_piola,1.0);
312  sym_tensor_product(-4.0*mu3*det*det+2.0*mu,L,L,tangent_piola,1.0);
313 
314  tensor_product(J5,L,L,ddJ5,0.0);
315  sym_tensor_product(-J5,L,L,ddJ5,1.0);
316 
317  tensor_product(-I3,L,LML,ddJ5,1.0);
318  tensor_product(-I3,LML,L,ddJ5,1.0);
319 
320  sym_tensor_product(I3,L,LML,ddJ5,1.0);
321  sym_tensor_product(I3,LML,L,ddJ5,1.0);
322 
323  tensor_product(4.0*beta4*pI4/(I4*ptrmbeta4),M,M,tangent_piola,1.0);
324  tensor_product(4.0*beta5*pJ5/(J5*ptrmbeta5),dJ5,dJ5,tangent_piola,1.0);
325 
326  tensor_product(4.0*trm*beta3*pI3,L,L,tangent_piola,1.0);
327  sym_tensor_product(4.0*trm*pI3,L,L,tangent_piola,1.0);
328 
329  ddJ5.Scale(4.0*pJ5/ptrmbeta5);
330  tangent_piola += ddJ5;
331  }
332 
333  Epetra_SerialDenseVector get_neumannBc(Epetra_SerialDenseMatrix & matrix_X,
334  Epetra_SerialDenseMatrix & xg,
335  unsigned int & gp){
336  Epetra_SerialDenseVector h(3);
337  std::cout << "**Err: Not using that method in this example!\n";
338  return h;
339  }
340 
341  Epetra_SerialDenseVector get_forcing(double & x1,
342  double & x2,
343  double & x3,
344  unsigned int & e_lid,
345  unsigned int & gp){
346  Epetra_SerialDenseVector f(3);
347  std::cout << "**Err: Not using that method in this example!\n";
348  return f;
349  }
350 
351  void get_material_parameters_for_recover(unsigned int & e_lid){
352  std::cout << "**Err: Not using that method in this example!\n";
353  }
354 
355  void get_stress_for_recover(Epetra_SerialDenseMatrix & deformation_gradient,
356  double & det,
357  Epetra_SerialDenseMatrix & piola_stress){
358  std::cout << "**Err: Not using that method in this example!\n";
359  }
360 
361 };
362 
363 #endif
Epetra_Comm * Comm
for j
Definition: costFunction.m:42
std::vector< int > local_nodes
Definition: meshpp.hpp:80
void tensor_product(double scalarAB, Epetra_SerialDenseVector &A, Epetra_SerialDenseVector &B, Epetra_SerialDenseMatrix &AoB, double scalarThis)
std::vector< double > nodes_coord
Definition: meshpp.hpp:77
unsigned int n_bc_dof
void get_constitutive_tensors(Epetra_SerialDenseMatrix &deformation_gradient, Epetra_SerialDenseVector &piola_stress, Epetra_SerialDenseMatrix &tangent_piola)
void get_stress_for_recover(Epetra_SerialDenseMatrix &deformation_gradient, double &det, Epetra_SerialDenseMatrix &piola_stress)
int n_local_cells
Definition: meshpp.hpp:94
void setParameters(Epetra_SerialDenseVector &parameters, Epetra_SerialDenseVector &exponents, Epetra_SerialDenseVector &hyperParameters)
double icdf_gamma(double &w, double &alpha, double &beta)
Teuchos::RCP< shinozuka_layeredcomp_2d > GRF_Generator
void get_matrix_and_rhs(Epetra_Vector &x, Epetra_FECrsMatrix &K, Epetra_FEVector &F)
std::vector< int > local_cells
Definition: meshpp.hpp:81
clc clear all close all mesh
Definition: run.m:5
void assemblePureDirichlet_homogeneousForcing(Epetra_Vector &x, Epetra_FECrsMatrix &K, Epetra_FEVector &F)
int n_local_nodes_without_ghosts
Definition: meshpp.hpp:92
void RandomFieldGenerator(Epetra_IntSerialDenseVector &seeds)
L
Definition: costFunction.m:66
Epetra_Import * ImportToOverlapMap
Epetra_Map * StandardMap
Epetra_SerialDenseVector get_neumannBc(Epetra_SerialDenseMatrix &matrix_X, Epetra_SerialDenseMatrix &xg, unsigned int &gp)
unsigned int n_gauss_cells
Definition: meshpp.hpp:98
tiMooneyRandomField(Epetra_Comm &comm, Teuchos::ParameterList &Parameters)
void sym_tensor_product(double scalarAB, Epetra_SerialDenseVector &A, Epetra_SerialDenseVector &B, Epetra_SerialDenseMatrix &AoB, double scalarThis)
void get_material_parameters(unsigned int &e_lid, unsigned int &gp)
int n_nodes
Definition: meshpp.hpp:87
modelParameters beta
Definition: run_station15.m:10
for i
Definition: costFunction.m:38
Epetra_Map * OverlapMap
e
Definition: run.m:10
void apply_dirichlet_conditions(Epetra_FECrsMatrix &K, Epetra_FEVector &F, double &displacement)
Epetra_SerialDenseVector get_forcing(double &x1, double &x2, double &x3, unsigned int &e_lid, unsigned int &gp)