Trilinos based (stochastic) FEM solvers
phaseFieldLinearizedElasticity.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 phaseFieldLinearizedElasticity::initialize(Epetra_Comm & comm, Teuchos::ParameterList & Parameters){
14 
15  std::string mesh_file = Teuchos::getParameter<std::string>(Parameters.sublist("Mesh"), "mesh_file");
16 
17  gc = Teuchos::getParameter<double>(Parameters.sublist("Damage"), "gc");
18  lc = Teuchos::getParameter<double>(Parameters.sublist("Damage"), "lc");
19  E = Teuchos::getParameter<double>(Parameters.sublist("Elasticity"), "young");
20  nu = Teuchos::getParameter<double>(Parameters.sublist("Elasticity"), "poisson");
21 
22  Mesh = new mesh(comm, mesh_file, 1.0);
23  Comm = Mesh->Comm;
24 
25  damageInterface = Teuchos::rcp(new damageField(comm, *Mesh, gc, lc));
26 
27  StandardMap = new Epetra_Map(-1, 3*Mesh->n_local_nodes_without_ghosts, &Mesh->local_dof_without_ghosts[0], 0, *Comm);
28  OverlapMap = new Epetra_Map(-1, 3*Mesh->n_local_nodes, &Mesh->local_dof[0], 0, *Comm);
29  ImportToOverlapMap = new Epetra_Import(*OverlapMap, *StandardMap);
31 
32  damageSolutionOverlaped = new Epetra_Vector(*damageInterface->OverlapMap);
33 
34  lambda = E*nu/((1.0+nu)*(1.0-2.0*nu));
35  mu = E/(2.0*(1.0+nu));
36 
37  elasticity.Reshape(6,6);
38  double c11 = E*(1.0-nu)/((1.0+nu)*(1.0-2.0*nu));
39  double c12 = E*nu/((1.0+nu)*(1.0-2.0*nu));
40  double c44 = E/(2.0*(1.0+nu));
41 
42  elasticity(0,0) = c11; elasticity(0,1) = c12; elasticity(0,2) = c12; elasticity(0,3) = 0.0; elasticity(0,4) = 0.0; elasticity(0,5) = 0.0;
43  elasticity(1,0) = c12; elasticity(1,1) = c11; elasticity(1,2) = c12; elasticity(1,3) = 0.0; elasticity(1,4) = 0.0; elasticity(1,5) = 0.0;
44  elasticity(2,0) = c12; elasticity(2,1) = c12; elasticity(2,2) = c11; elasticity(2,3) = 0.0; elasticity(2,4) = 0.0; elasticity(2,5) = 0.0;
45  elasticity(3,0) = 0.0; elasticity(3,1) = 0.0; elasticity(3,2) = 0.0; elasticity(3,3) = c44; elasticity(3,4) = 0.0; elasticity(3,5) = 0.0;
46  elasticity(4,0) = 0.0; elasticity(4,1) = 0.0; elasticity(4,2) = 0.0; elasticity(4,3) = 0.0; elasticity(4,4) = c44; elasticity(4,5) = 0.0;
47  elasticity(5,0) = 0.0; elasticity(5,1) = 0.0; elasticity(5,2) = 0.0; elasticity(5,3) = 0.0; elasticity(5,4) = 0.0; elasticity(5,5) = c44;
48 }
49 
50 void phaseFieldLinearizedElasticity::staggeredAlgorithmDirichletBC(Teuchos::ParameterList & ParametersList,
51  bool print){
52 
53  double delta_u = Teuchos::getParameter<double>(ParametersList.sublist("Elasticity"), "delta_u");
54  int n_steps = Teuchos::getParameter<int>(ParametersList.sublist("Elasticity"), "n_steps");
55 
56  Epetra_Time Time(*Comm);
57 
58  Epetra_FECrsMatrix matrix_d(Copy,*damageInterface->FEGraph);
59  Epetra_FECrsMatrix matrix_u(Copy,*FEGraph);
60 
61  Epetra_FEVector rhs_d(*damageInterface->StandardMap);
62  Epetra_FEVector rhs_u(*StandardMap);
63 
64  Epetra_Vector lhs_d(*damageInterface->StandardMap);
65  Epetra_Vector lhs_u(*StandardMap);
66 
67  Epetra_Map GaussMap = constructGaussMap();
68  Epetra_Vector damageHistory(GaussMap);
69 
70  if (Comm->MyPID()==0){
71  std::cout << "step" << std::setw(15) << "cpu_time (s)" << "\n";
72  }
73 
74  double bc_disp = 0.0;
75  damageHistory.PutScalar(0.0);
76  for (int n=0; n<n_steps; ++n){
77 
78  Time.ResetStartTime();
79 
80  damageInterface->solve(ParametersList.sublist("Damage"), matrix_d, lhs_d, rhs_d, damageHistory, GaussMap);
81 
82  damageSolutionOverlaped->Import(lhs_d, *damageInterface->ImportToOverlapMap, Insert);
83 
84  bc_disp = (double(n)+1.0)*delta_u;
85  computeDisplacement(ParametersList.sublist("Elasticity"), matrix_u, lhs_u, rhs_u, bc_disp);
86 
87  updateDamageHistory(damageHistory, lhs_u, GaussMap);
88 
89  if (Comm->MyPID()==0){
90  std::cout << n << std::setw(15) << Time.ElapsedTime() << "\n";
91  }
92 
93  if (print){
94  std::string dispfile = "/home/s/staber/Trilinos_results/examples/phasefield/displacement" + std::to_string(int(n)) + ".mtx";
95  std::string damgfile = "/home/s/staber/Trilinos_results/examples/phasefield/damage" + std::to_string(int(n)) + ".mtx";
96  int error_u = print_solution(lhs_u, dispfile);
97  int error_d = damageInterface->print_solution(lhs_d, damgfile);
98  }
99 
100  }
101 
102 }
103 
104 void phaseFieldLinearizedElasticity::computeDisplacement(Teuchos::ParameterList & Parameters,
105  Epetra_FECrsMatrix & matrix, Epetra_Vector & lhs, Epetra_FEVector & rhs,
106  double & bc_disp){
107 
108  rhs.PutScalar(0.0);
109  lhs.PutScalar(0.0);
110 
112  apply_dirichlet_conditions(matrix, rhs, bc_disp);
113 
114  int max_iter = Teuchos::getParameter<int>(Parameters.sublist("Aztec"), "AZ_max_iter");
115  double tol = Teuchos::getParameter<double>(Parameters.sublist("Aztec"), "AZ_tol");
116 
117  Epetra_LinearProblem problem(&matrix, &lhs, &rhs);
118 
119  AztecOO solver(problem);
120  solver.SetParameters(Parameters.sublist("Aztec"));
121  solver.Iterate(max_iter, tol);
122 }
123 
124 void phaseFieldLinearizedElasticity::updateDamageHistory(Epetra_Vector & damageHistory,
125  Epetra_Vector & displacement,
126  Epetra_Map & GaussMap){
127 
128  Epetra_Vector u(*OverlapMap);
129  u.Import(displacement, *ImportToOverlapMap, Insert);
130 
131  //Mesh->update_store_feinterp_cells(u, *OverlapMap);
132 
133  int n_gauss_points = Mesh->n_gauss_cells;
134 
135  double trepsilon, trepsilon2, potential, history;
136 
137  Epetra_SerialDenseMatrix dx_shape_functions(Mesh->el_type,3);
138  Epetra_SerialDenseMatrix matrix_B(6,3*Mesh->el_type);
139  Epetra_SerialDenseVector cells_u(3*Mesh->el_type);
140  Epetra_SerialDenseVector epsilon(6);
141 
142  int egid, node, id;
143  for (unsigned int elid=0; elid<Mesh->n_local_cells; ++elid){
144  egid = Mesh->local_cells[elid];
145  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
146  node = Mesh->cells_nodes[Mesh->el_type*egid+inode];
147  for (unsigned int ddl=0; ddl<3; ++ddl){
148  id = 3*node+ddl;
149  cells_u(3*inode+ddl) = u[OverlapMap->LID(id)];
150  }
151  }
152  for (unsigned int gp=0; gp<n_gauss_points; ++gp){
153  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
154  dx_shape_functions(inode,0) = Mesh->DX_N_cells(gp+n_gauss_points*inode,elid);
155  dx_shape_functions(inode,1) = Mesh->DY_N_cells(gp+n_gauss_points*inode,elid);
156  dx_shape_functions(inode,2) = Mesh->DZ_N_cells(gp+n_gauss_points*inode,elid);
157  }
158 
159  compute_B_matrices(dx_shape_functions,matrix_B);
160  epsilon.Multiply('N','N',1.0,matrix_B,cells_u,0.0);
161 
162  trepsilon = epsilon(0) + epsilon(1) + epsilon(2);
163  trepsilon2 = epsilon(0)*epsilon(0) + epsilon(1)*epsilon(1) + epsilon(2)*epsilon(2) +
164  0.5*epsilon(3)*epsilon(3) + 0.5*epsilon(4)*epsilon(4) + 0.5*epsilon(5)*epsilon(5);
165 
166  id = n_gauss_points*egid+gp;
167  history = damageHistory[GaussMap.LID(id)];
168  potential = (lambda/2.0)*trepsilon*trepsilon + mu*trepsilon2;
169  if (potential>history){
170  damageHistory[GaussMap.LID(id)] = potential;
171  }
172  }
173  }
174 
175 }
176 
178  int e_gid;
179  int n_local_cells = Mesh->n_local_cells;
180  int n_gauss_cells = Mesh->n_gauss_cells;
181  std::vector<int> local_gauss_points(n_local_cells*n_gauss_cells);
182  for (unsigned int e_lid=0; e_lid<n_local_cells; ++e_lid){
183  e_gid = Mesh->local_cells[e_lid];
184  for (unsigned int gp=0; gp<n_gauss_cells; ++gp){
185  local_gauss_points[e_lid*n_gauss_cells+gp] = e_gid*n_gauss_cells+gp;
186  }
187 
188  }
189  Epetra_Map GaussMap(-1, n_local_cells*n_gauss_cells, &local_gauss_points[0], 0, *Comm);
190  return GaussMap;
191 }
192 
194  unsigned int & gp,
195  Epetra_SerialDenseMatrix & tangent_matrix){
196  int n_gauss_points = Mesh->n_gauss_cells;
197  int e_gid = Mesh->local_cells[e_lid];
198  int node;
199  double xi = Mesh->xi_cells[gp]; double eta = Mesh->eta_cells[gp]; double zeta = Mesh->zeta_cells[gp];
200 
201  Epetra_SerialDenseVector shape_functions(Mesh->el_type);
202  switch (Mesh->el_type){
203  case 4:
204  tetra4::shape_functions(shape_functions, xi, eta, zeta);
205  break;
206  case 8:
207  hexa8::shape_functions(shape_functions, xi, eta, zeta);
208  break;
209  case 10:
210  tetra10::shape_functions(shape_functions, xi, eta, zeta);
211  break;
212  }
213 
214  double d = 0.0;
215  for (unsigned int j=0; j<Mesh->el_type; ++j){
216  node = Mesh->cells_nodes[Mesh->el_type*e_gid+j];
217  d += shape_functions(j) * damageSolutionOverlaped[0][damageInterface->OverlapMap->LID(node)];
218  }
219 
220  double g = (1.0-d)*(1.0-d) + 1.0e-6;
221  tangent_matrix = elasticity;
222  tangent_matrix.Scale(g);
223 }
224 
226  Epetra_SerialDenseMatrix & tangent_matrix){
227  std::cout << "Not using this method yet.\n";
228 }
void updateDamageHistory(Epetra_Vector &damageHistory, Epetra_Vector &displacement, Epetra_Map &GaussMap)
Epetra_Comm * Comm
for j
Definition: costFunction.m:42
u
Definition: run.m:9
int print_solution(Epetra_Vector &solution, std::string fileName)
void shape_functions(Epetra_SerialDenseVector &N, double &xi, double &eta, double &zeta)
Definition: fepp.cpp:88
Epetra_SerialDenseVector DZ_N_cells
Definition: meshpp.hpp:73
void get_elasticity_tensor_for_recovery(unsigned int &e_lid, Epetra_SerialDenseMatrix &tangent_matrix)
void initialize(Epetra_Comm &comm, Teuchos::ParameterList &Parameters)
void computeDisplacement(Teuchos::ParameterList &ParameterList, Epetra_FECrsMatrix &matrix, Epetra_Vector &lhs, Epetra_FEVector &rhs, double &bc_disp)
virtual void apply_dirichlet_conditions(Epetra_FECrsMatrix &K, Epetra_FEVector &F, double &displacement)
int n_local_cells
Definition: meshpp.hpp:94
Epetra_SerialDenseVector eta_cells
Definition: meshpp.hpp:100
void staggeredAlgorithmDirichletBC(Teuchos::ParameterList &ParametersList, bool print)
Epetra_SerialDenseVector xi_cells
Definition: meshpp.hpp:100
Epetra_SerialDenseVector DX_N_cells
Definition: meshpp.hpp:73
Epetra_FECrsGraph * FEGraph
void compute_B_matrices(Epetra_SerialDenseMatrix &dx_shape_functions, Epetra_SerialDenseMatrix &B)
std::vector< int > local_cells
Definition: meshpp.hpp:81
clc clear all close all mesh
Definition: run.m:5
int el_type
Definition: meshpp.hpp:90
void shape_functions(Epetra_SerialDenseVector &N, double &xi, double &eta, double &zeta)
Definition: fepp.cpp:110
Epetra_SerialDenseVector DY_N_cells
Definition: meshpp.hpp:73
std::vector< int > cells_nodes
Definition: meshpp.hpp:78
void assemblePureDirichlet_homogeneousForcing(Epetra_FECrsMatrix &K)
Epetra_Import * ImportToOverlapMap
Epetra_Map * StandardMap
void shape_functions(Epetra_SerialDenseVector &N, double &xi, double &eta)
Definition: fepp.cpp:7
unsigned int n_gauss_cells
Definition: meshpp.hpp:98
void get_elasticity_tensor(unsigned int &e_lid, unsigned int &gp, Epetra_SerialDenseMatrix &tangent_matrix)
optimParameters tol
Epetra_Map * OverlapMap
Epetra_SerialDenseVector zeta_cells
Definition: meshpp.hpp:100
void shape_functions(Epetra_SerialDenseVector &N, double &xi, double &eta, double &zeta)
Definition: fepp.cpp:125
output eta
Definition: costFunction.m:33