Trilinos based (stochastic) FEM solvers
rubberblock.hpp
Go to the documentation of this file.
1 #ifndef RUBBERBLOCK_HPP
2 #define RUBBERBLOCK_HPP
3 
4 #include "tensor_calculus.hpp"
6 
8 {
9 public:
10 
11  double topcoord;
12  double lambda, mu;
13 
14  rubberblock(Epetra_Comm & comm, Teuchos::ParameterList & Parameters){
15 
16  std::string mesh_file = Teuchos::getParameter<std::string>(Parameters.sublist("Mesh"), "mesh_file");
17  Mesh = new mesh(comm, mesh_file, 1000.0);
18  Comm = Mesh->Comm;
19  findtop();
20 
21  StandardMap = new Epetra_Map(-1,3*Mesh->n_local_nodes_without_ghosts,&Mesh->local_dof_without_ghosts[0],0,*Comm);
22  OverlapMap = new Epetra_Map(-1,3*Mesh->n_local_nodes,&Mesh->local_dof[0],0,*Comm);
23  ImportToOverlapMap = new Epetra_Import(*OverlapMap,*StandardMap);
25 
27  }
28 
30  }
31 
32  void set_parameters(Epetra_SerialDenseVector & x){
33  lambda = x(0);
34  mu = x(1);
35  }
36 
37  void findtop(){
38  topcoord = 0.0;
39  if (Comm->MyPID()==0){
40  for (unsigned int n=0; n<Mesh->n_nodes; ++n){
41  if (Mesh->nodes_coord[3*n+1]>topcoord){
42  topcoord = Mesh->nodes_coord[3*n+1];
43  }
44  }
45  }
46  Comm->Broadcast(&topcoord,1,0);
47  Comm->Barrier();
48  }
49 
50  void get_matrix_and_rhs(Epetra_Vector & x, Epetra_FECrsMatrix & K, Epetra_FEVector & F){
52  }
53 
55  n_bc_dof = 0;
56  double y;
57  unsigned int node;
58  for (unsigned int i=0; i<Mesh->n_local_nodes_without_ghosts; ++i){
59  node = Mesh->local_nodes[i];
60  y = Mesh->nodes_coord[3*node+1];
61  if(y==0.0){
62  n_bc_dof+=3;
63  }
64  if(y==topcoord){
65  n_bc_dof+=1;
66  }
67  }
68 
69  int indbc = 0;
70  dof_on_boundary = new int [n_bc_dof];
71  for (unsigned int inode=0; inode<Mesh->n_local_nodes_without_ghosts; ++inode){
72  node = Mesh->local_nodes[inode];
73  y = Mesh->nodes_coord[3*node+1];
74  if (y==0.0){
75  dof_on_boundary[indbc+0] = 3*inode+0;
76  dof_on_boundary[indbc+1] = 3*inode+1;
77  dof_on_boundary[indbc+2] = 3*inode+2;
78  indbc+=3;
79  }
80  if (y==topcoord){
81  dof_on_boundary[indbc] = 3*inode+1;
82  indbc+=1;
83  }
84  }
85  }
86 
87  void apply_dirichlet_conditions(Epetra_FECrsMatrix & K, Epetra_FEVector & F, double & displacement){
88  Epetra_MultiVector v(*StandardMap,true);
89  v.PutScalar(0.0);
90 
91  int node;
92  double y;
93  for (unsigned int inode=0; inode<Mesh->n_local_nodes_without_ghosts; ++inode){
94  node = Mesh->local_nodes[inode];
95  y = Mesh->nodes_coord[3*node+1];
96  if (y==topcoord){
97  v[0][StandardMap->LID(3*node+1)] = displacement;
98  }
99  }
100 
101  Epetra_MultiVector rhs_dir(*StandardMap,true);
102  K.Apply(v,rhs_dir);
103  F.Update(-1.0,rhs_dir,1.0);
104 
105  for (unsigned int inode=0; inode<Mesh->n_local_nodes_without_ghosts; ++inode){
106  node = Mesh->local_nodes[inode];
107  y = Mesh->nodes_coord[3*node+1];
108  if (y==0.0){
109  F[0][StandardMap->LID(3*node+0)] = 0.0;
110  F[0][StandardMap->LID(3*node+1)] = 0.0;
111  F[0][StandardMap->LID(3*node+2)] = 0.0;
112  }
113  if (y==topcoord){
114  F[0][StandardMap->LID(3*node+1)] = displacement;
115  }
116  }
117  ML_Epetra::Apply_OAZToMatrix(dof_on_boundary,n_bc_dof,K);
118  }
119 
120  void get_constitutive_tensors(Epetra_SerialDenseMatrix & deformation_gradient, Epetra_SerialDenseVector & piola_stress, Epetra_SerialDenseMatrix & tangent_piola){
121 
122  double det = deformation_gradient(0,0)*deformation_gradient(1,1)*deformation_gradient(2,2)-deformation_gradient(0,0)*deformation_gradient(1,2)*deformation_gradient(2,1)-deformation_gradient(0,1)*deformation_gradient(1,0)*deformation_gradient(2,2)+deformation_gradient(0,1)*deformation_gradient(1,2)*deformation_gradient(2,0)+deformation_gradient(0,2)*deformation_gradient(1,0)*deformation_gradient(2,1)-deformation_gradient(0,2)*deformation_gradient(1,1)*deformation_gradient(2,0);
123 
124  Epetra_SerialDenseMatrix C(3,3);
125  Epetra_SerialDenseVector eye(6), L(6);
126 
127  C.Multiply('T','N',1.0,deformation_gradient,deformation_gradient,0.0);
128 
129  L(0) = (1.0/(det*det))*(C(1,1)*C(2,2)-C(1,2)*C(2,1));
130  L(1) = (1.0/(det*det))*(C(0,0)*C(2,2)-C(0,2)*C(2,0));
131  L(2) = (1.0/(det*det))*(C(0,0)*C(1,1)-C(0,1)*C(1,0));
132  L(3) = (1.0/(det*det))*(C(0,2)*C(1,0)-C(0,0)*C(1,2));
133  L(4) = (1.0/(det*det))*(C(0,1)*C(1,2)-C(0,2)*C(1,1));
134  L(5) = (1.0/(det*det))*(C(0,2)*C(2,1)-C(0,1)*C(2,2));
135 
136  eye(0) = 1.0; eye(1) = 1.0; eye(2) = 1.0; eye(3) = 0.0; eye(4) = 0.0; eye(5) = 0.0;
137 
138  double I1 = C(0,0) + C(1,1) + C(2,2);
139  double dpressure = (lambda/2.0)*det - ((lambda/2.0) + mu)/det;
140  double ddpressure = (lambda/2.0) + ((lambda/2.0) + mu)/(det*det);
141 
142  for (unsigned int i=0; i<6; ++i){
143  piola_stress(i) = mu*eye(i) + det*dpressure*L(i);
144  }
145 
146  double scalarAB = det*(dpressure+det*ddpressure);
147  tensor_product(scalarAB,L,L,tangent_piola,0.0);
148  scalarAB = -2.0*det*dpressure;
149  sym_tensor_product(scalarAB,L,L,tangent_piola,1.0);
150  }
151 
152  void compute_cauchy(Epetra_Vector & solution, double & xi, double & eta, double & zeta, std::string & filename){
153 
154  Epetra_Vector u(*OverlapMap);
155  u.Import(solution, *ImportToOverlapMap, Insert);
156 
157  Epetra_Map CellsMap(-1,Mesh->n_local_cells,&Mesh->local_cells[0],0,*Comm);
158  Epetra_Vector sig22(CellsMap);
159 
160  int node, e_gid;
161  double det_jac_cells;
162  double I1, det, dpressure;
163 
164  Epetra_SerialDenseMatrix deformation_gradient(3,3), right_cauchy(3,3), inv_right_cauchy(3,3);
165  Epetra_SerialDenseMatrix s(3,3), sig(3,3), sf(3,3), eye(3,3);
166  Epetra_SerialDenseMatrix matrix_X(3,Mesh->el_type);
167  Epetra_SerialDenseMatrix matrix_x(3,Mesh->el_type);
168  Epetra_SerialDenseMatrix dx_shape_functions(Mesh->el_type,3);
169  Epetra_SerialDenseMatrix D(Mesh->el_type,3), DX(Mesh->el_type,3);
170  Epetra_SerialDenseMatrix JacobianMatrix(3,3);
171 
172  eye(0,0) = 1.0; eye(0,1) = 0.0; eye(0,2) = 0.0;
173  eye(1,0) = 0.0; eye(1,1) = 1.0; eye(1,2) = 0.0;
174  eye(2,0) = 0.0; eye(2,1) = 0.0; eye(2,2) = 1.0;
175 
176  for (unsigned int e_lid=0; e_lid<Mesh->n_local_cells; ++e_lid){
177  e_gid = Mesh->local_cells[e_lid];
178 
179  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
180  node = Mesh->cells_nodes[Mesh->el_type*e_gid+inode];
181  matrix_X(0,inode) = Mesh->nodes_coord[3*node+0];
182  matrix_X(1,inode) = Mesh->nodes_coord[3*node+1];
183  matrix_X(2,inode) = Mesh->nodes_coord[3*node+2];
184  matrix_x(0,inode) = u[OverlapMap->LID(3*node+0)] + Mesh->nodes_coord[3*node+0];
185  matrix_x(1,inode) = u[OverlapMap->LID(3*node+1)] + Mesh->nodes_coord[3*node+1];
186  matrix_x(2,inode) = u[OverlapMap->LID(3*node+2)] + Mesh->nodes_coord[3*node+2];
187  }
188 
189  switch (Mesh->el_type){
190  case 4:
191  tetra4::d_shape_functions(D, xi, eta, zeta);
192  break;
193  case 8:
194  hexa8::d_shape_functions(D, xi, eta, zeta);
195  break;
196  case 10:
197  tetra10::d_shape_functions(D, xi, eta, zeta);
198  break;
199  }
200  jacobian_matrix(matrix_X,D,JacobianMatrix);
201  jacobian_det(JacobianMatrix,det_jac_cells);
202  dX_shape_functions(D,JacobianMatrix,det_jac_cells,dx_shape_functions);
203 
204  deformation_gradient.Multiply('N','N',1.0,matrix_x,dx_shape_functions,0.0);
205  det = deformation_gradient(0,0)*deformation_gradient(1,1)*deformation_gradient(2,2)-deformation_gradient(0,0)*deformation_gradient(1,2)*deformation_gradient(2,1)-deformation_gradient(0,1)*deformation_gradient(1,0)*deformation_gradient(2,2)+deformation_gradient(0,1)*deformation_gradient(1,2)*deformation_gradient(2,0)+deformation_gradient(0,2)*deformation_gradient(1,0)*deformation_gradient(2,1)-deformation_gradient(0,2)*deformation_gradient(1,1)*deformation_gradient(2,0);
206  right_cauchy.Multiply('T','N',1.0,deformation_gradient,deformation_gradient,0.0);
207  inv_right_cauchy(0,0) = (1.0/(det*det))*(right_cauchy(1,1)*right_cauchy(2,2)-right_cauchy(1,2)*right_cauchy(2,1));
208  inv_right_cauchy(1,1) = (1.0/(det*det))*(right_cauchy(0,0)*right_cauchy(2,2)-right_cauchy(0,2)*right_cauchy(2,0));
209  inv_right_cauchy(2,2) = (1.0/(det*det))*(right_cauchy(0,0)*right_cauchy(1,1)-right_cauchy(0,1)*right_cauchy(1,0));
210  inv_right_cauchy(1,2) = (1.0/(det*det))*(right_cauchy(0,2)*right_cauchy(1,0)-right_cauchy(0,0)*right_cauchy(1,2));
211  inv_right_cauchy(2,1) = inv_right_cauchy(1,2);
212  inv_right_cauchy(0,2) = (1.0/(det*det))*(right_cauchy(0,1)*right_cauchy(1,2)-right_cauchy(0,2)*right_cauchy(1,1));
213  inv_right_cauchy(2,0) = inv_right_cauchy(0,2);
214  inv_right_cauchy(0,1) = (1.0/(det*det))*(right_cauchy(0,2)*right_cauchy(2,1)-right_cauchy(0,1)*right_cauchy(2,2));
215  inv_right_cauchy(1,0) = inv_right_cauchy(0,1);
216  I1 = right_cauchy(0,0) + right_cauchy(1,1) + right_cauchy(2,2);
217  dpressure = (lambda/2.0)*det - ((lambda/2.0) + mu)/det;
218  for (unsigned int i=0; i<3; ++i){
219  for (unsigned int j=0; j<3; ++j){
220  s(i,j) = mu*eye(i,j) + det*dpressure*inv_right_cauchy(i,j);
221  }
222  }
223  sf.Multiply('N','T',1.0,s,deformation_gradient,0.0);
224  sig.Multiply('N','N',1.0,deformation_gradient,sf,0.0);
225  sig.Scale(1.0/det);
226  sig22[e_lid] = sig(1,1);
227  }
228 
229  int NumTargetElements = 0;
230  if (Comm->MyPID()==0){
231  NumTargetElements = Mesh->n_cells;
232  }
233  Epetra_Map MapOnRoot(-1,NumTargetElements,0,*Comm);
234  Epetra_Export ExportOnRoot(CellsMap,MapOnRoot);
235  Epetra_MultiVector lhs_root(MapOnRoot,true);
236  lhs_root.Export(sig22,ExportOnRoot,Insert);
237 
238  int error = EpetraExt::MultiVectorToMatrixMarketFile(filename.c_str(),lhs_root,0,0,false);
239  }
240 
241  Epetra_SerialDenseVector get_neumannBc(Epetra_SerialDenseMatrix & matrix_X, Epetra_SerialDenseMatrix & xg, unsigned int & gp){
242  Epetra_SerialDenseVector h(3);
243  std::cout << "**Err: Not using that method in this example!\n";
244  return h;
245  }
246 
247  Epetra_SerialDenseVector get_forcing(double & x1, double & x2, double & x3, unsigned int & e_lid, unsigned int & gp){
248  Epetra_SerialDenseVector f(3);
249  std::cout << "**Err: Not using that method in this example!\n";
250  return f;
251  }
252 
253  void get_material_parameters(unsigned int & e_lid, unsigned int & gp){
254  //std::cout << "**Err: Not using that method in this example!\n";
255  }
256 
257  void get_material_parameters_for_recover(unsigned int & e_lid){
258  std::cout << "**Err: Not using that method in this example!\n";
259  }
260 
261  void get_stress_for_recover(Epetra_SerialDenseMatrix & deformation_gradient, double & det, Epetra_SerialDenseMatrix & piola_stress){
262  std::cout << "**Err: Not using that method in this example!\n";
263  }
264 
265 };
266 
267 #endif
s
Definition: run.m:11
Epetra_Comm * Comm
for j
Definition: costFunction.m:42
u
Definition: run.m:9
void set_parameters(Epetra_SerialDenseVector &x)
Definition: rubberblock.hpp:32
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)
rubberblock(Epetra_Comm &comm, Teuchos::ParameterList &Parameters)
Definition: rubberblock.hpp:14
std::vector< double > nodes_coord
Definition: meshpp.hpp:77
unsigned int n_bc_dof
void compute_cauchy(Epetra_Vector &solution, double &xi, double &eta, double &zeta, std::string &filename)
void apply_dirichlet_conditions(Epetra_FECrsMatrix &K, Epetra_FEVector &F, double &displacement)
Definition: rubberblock.hpp:87
void findtop()
Definition: rubberblock.hpp:37
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
void setup_dirichlet_conditions()
Definition: rubberblock.hpp:54
Epetra_SerialDenseVector get_neumannBc(Epetra_SerialDenseMatrix &matrix_X, Epetra_SerialDenseMatrix &xg, unsigned int &gp)
double topcoord
Definition: rubberblock.hpp:11
void get_stress_for_recover(Epetra_SerialDenseMatrix &deformation_gradient, double &det, Epetra_SerialDenseMatrix &piola_stress)
std::vector< int > local_cells
Definition: meshpp.hpp:81
clc clear all close all mesh
Definition: run.m:5
void d_shape_functions(Epetra_SerialDenseMatrix &D, double &xi, double &eta, double &zeta)
Definition: fepp.cpp:139
void assemblePureDirichlet_homogeneousForcing(Epetra_Vector &x, Epetra_FECrsMatrix &K, Epetra_FEVector &F)
int n_local_nodes_without_ghosts
Definition: meshpp.hpp:92
void jacobian_det(Epetra_SerialDenseMatrix &JacobianMatrix, double &jac)
Definition: fepp.cpp:175
filename
Definition: costFunction.m:44
int el_type
Definition: meshpp.hpp:90
void get_material_parameters_for_recover(unsigned int &e_lid)
std::vector< int > cells_nodes
Definition: meshpp.hpp:78
void get_constitutive_tensors(Epetra_SerialDenseMatrix &deformation_gradient, Epetra_SerialDenseVector &piola_stress, Epetra_SerialDenseMatrix &tangent_piola)
L
Definition: costFunction.m:66
Epetra_Import * ImportToOverlapMap
Epetra_Map * StandardMap
Epetra_SerialDenseVector get_forcing(double &x1, double &x2, double &x3, unsigned int &e_lid, unsigned int &gp)
void get_material_parameters(unsigned int &e_lid, unsigned int &gp)
int n_cells
Definition: meshpp.hpp:88
void sym_tensor_product(double scalarAB, Epetra_SerialDenseVector &A, Epetra_SerialDenseVector &B, Epetra_SerialDenseMatrix &AoB, double scalarThis)
int n_nodes
Definition: meshpp.hpp:87
void get_matrix_and_rhs(Epetra_Vector &x, Epetra_FECrsMatrix &K, Epetra_FEVector &F)
Definition: rubberblock.hpp:50
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 jacobian_matrix(Epetra_SerialDenseMatrix &X, Epetra_SerialDenseMatrix &D, Epetra_SerialDenseMatrix &JacobianMatrix)
Definition: fepp.cpp:171
double lambda
Definition: rubberblock.hpp:12
output eta
Definition: costFunction.m:33