Trilinos based (stochastic) FEM solvers
damageField.cpp
Go to the documentation of this file.
1 /*
2 Brian Staber (brian.staber@gmail.com)
3 */
4 
5 #include "damageField.hpp"
6 #include "fepp.hpp"
7 
8 damageField::damageField(Epetra_Comm & comm, mesh & mesh, double & gc_, double & lc_):
9 gc(gc_), lc(lc_){
10 
11  Mesh = &mesh;
12  Comm = Mesh->Comm;
13 
15  OverlapMap = new Epetra_Map(-1, Mesh->n_local_nodes, &Mesh->local_nodes[0], 0, *Comm);
16  ImportToOverlapMap = new Epetra_Import(*OverlapMap, *StandardMap);
17 
19 }
20 
22 }
23 
24 void damageField::assemble(Epetra_FECrsMatrix & matrix, Epetra_FEVector & rhs,
25  Epetra_Vector & damageHistory, Epetra_Map & GaussMap){
26 
27  matrix.PutScalar(0.0);
28  rhs.PutScalar(0.0);
29 
30  Epetra_SerialDenseVector shape_functions(Mesh->el_type);
31  Epetra_SerialDenseVector fe(Mesh->el_type);
32 
33  Epetra_SerialDenseMatrix dx_shape_functions(3,Mesh->el_type);
34  Epetra_SerialDenseMatrix ke(Mesh->el_type, Mesh->el_type);
35  Epetra_SerialDenseMatrix me(Mesh->el_type, Mesh->el_type);
36 
37  double gauss_weight, hn, an;
38  double bn = gc*lc;
39  int eglob, id;
40  int n_gauss_points = Mesh->n_gauss_cells;
41  int * index = new int [Mesh->el_type];
42 
43  for (unsigned int eloc=0; eloc<Mesh->n_local_cells; ++eloc){
44  eglob = Mesh->local_cells[eloc];
45  for (int inode=0; inode<Mesh->el_type; ++inode){
46  index[inode] = Mesh->cells_nodes[Mesh->el_type*eglob+inode];
47  fe(inode) = 0.0;
48  for (int jnode=0; jnode<Mesh->el_type; ++jnode){
49  ke(inode,jnode) = 0.0;
50  me(inode,jnode) = 0.0;
51  }
52  }
53 
54  for (unsigned int gp=0; gp<n_gauss_points; ++gp){
55  gauss_weight = Mesh->gauss_weight_cells(gp);
56  id = n_gauss_points*eglob+gp;
57  hn = damageHistory[GaussMap.LID(id)];
58  an = 2.0*hn + gc/double(lc);
59  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
60  dx_shape_functions(0,inode) = Mesh->DX_N_cells(gp+n_gauss_points*inode,eloc);
61  dx_shape_functions(1,inode) = Mesh->DY_N_cells(gp+n_gauss_points*inode,eloc);
62  dx_shape_functions(2,inode) = Mesh->DZ_N_cells(gp+n_gauss_points*inode,eloc);
63  shape_functions(inode) = Mesh->N_cells(inode,gp);
64  fe(inode) += gauss_weight*2.0*hn*shape_functions(inode)*Mesh->detJac_cells(eloc,gp);
65  }
66  me.Multiply('N','T',an*gauss_weight*Mesh->detJac_cells(eloc,gp),shape_functions,shape_functions,1.0);
67  ke.Multiply('T','N',bn*gauss_weight*Mesh->detJac_cells(eloc,gp),dx_shape_functions,dx_shape_functions,1.0);
68  }
69  ke += me;
70 
71  for (unsigned int inode=0; inode<Mesh->el_type; ++inode){
72  rhs.SumIntoGlobalValues(1, &index[inode], &fe(inode));
73  for (unsigned int jnode=0; jnode<Mesh->el_type; ++jnode){
74  matrix.SumIntoGlobalValues(1, &index[inode], 1, &index[jnode], &ke(inode,jnode));
75  }
76  }
77  }
78 
79  Comm->Barrier();
80 
81  matrix.GlobalAssemble();
82  matrix.FillComplete();
83  rhs.GlobalAssemble();
84 
85  delete [] index;
86 }
87 
88 void damageField::solve(Teuchos::ParameterList & Parameters,
89  Epetra_FECrsMatrix & matrix, Epetra_Vector & lhs, Epetra_FEVector & rhs,
90  Epetra_Vector & damageHistory,
91  Epetra_Map & GaussMap){
92 
93  assemble(matrix, rhs, damageHistory, GaussMap);
94 
95  double tol = Teuchos::getParameter<double>(Parameters.sublist("Aztec"), "AZ_tol");
96  int max_iter = Teuchos::getParameter<int>(Parameters.sublist("Aztec"), "AZ_max_iter");
97 
98  lhs.PutScalar(0.0);
99 
100  Epetra_LinearProblem problem(&matrix, &lhs, &rhs);
101 
102  AztecOO solver(problem);
103  solver.SetParameters(Parameters.sublist("Aztec"));
104  solver.Iterate(max_iter, tol);
105 }
106 
108  FEGraph = new Epetra_FECrsGraph(Copy,*StandardMap,100);
109  int eglob, node;
110  int *index;
111  index = new int [Mesh->el_type];
112 
113  for (int eloc=0; eloc<Mesh->n_local_cells; ++eloc){
114  eglob = Mesh->local_cells[eloc];
115  for (int inode=0; inode<Mesh->el_type; ++inode){
116  node = Mesh->cells_nodes[Mesh->el_type*eglob+inode];
117  index[inode] = node;
118  }
119 
120  for (int i=0; i<Mesh->el_type; ++i){
121  for (int j=0; j<Mesh->el_type; ++j){
122  FEGraph->InsertGlobalIndices(1, &index[i], 1, &index[j]);
123  }
124  }
125  }
126  Comm->Barrier();
127  FEGraph->GlobalAssemble();
128  delete[] index;
129 }
130 
132  std::cout << "No essential boundary conditions.\n";
133 }
134 
135 void damageField::apply_dirichlet_conditions(Epetra_FECrsMatrix & K, Epetra_FEVector & F, double & displacement){
136  std::cout << "No essential boundary conditions.\n";
137 }
138 
139 int damageField::print_solution(Epetra_Vector & lhs, std::string fileName){
140  int NumTargetElements = 0;
141  if (Comm->MyPID()==0){
142  NumTargetElements = Mesh->n_nodes;
143  }
144  Epetra_Map MapOnRoot(-1,NumTargetElements,0,*Comm);
145  Epetra_Export ExportOnRoot(*StandardMap,MapOnRoot);
146  Epetra_MultiVector lhs_root(MapOnRoot,true);
147  lhs_root.Export(lhs,ExportOnRoot,Insert);
148  int error = EpetraExt::MultiVectorToMatrixMarketFile(fileName.c_str(),lhs_root,0,0,false);
149  return error;
150 }
Epetra_Comm * Comm
for j
Definition: costFunction.m:42
damageField(Epetra_Comm &comm, mesh &mesh, double &gc_, double &lc_)
Definition: damageField.cpp:8
std::vector< int > local_nodes
Definition: meshpp.hpp:80
void create_FECrsGraph()
Epetra_SerialDenseVector DZ_N_cells
Definition: meshpp.hpp:73
Epetra_SerialDenseVector N_cells
Definition: meshpp.hpp:73
Epetra_Comm * Comm
Definition: meshpp.hpp:69
int n_local_cells
Definition: meshpp.hpp:94
Epetra_SerialDenseVector DX_N_cells
Definition: meshpp.hpp:73
Epetra_FECrsGraph * FEGraph
Epetra_SerialDenseVector detJac_cells
Definition: meshpp.hpp:73
modelParameters lc
Definition: meshpp.hpp:49
std::vector< int > local_cells
Definition: meshpp.hpp:81
clc clear all close all mesh
Definition: run.m:5
void assemble(Epetra_FECrsMatrix &matrix, Epetra_FEVector &rhs, Epetra_Vector &damageHistory, Epetra_Map &GaussMap)
Definition: damageField.cpp:24
int n_local_nodes_without_ghosts
Definition: meshpp.hpp:92
int n_local_nodes
Definition: meshpp.hpp:93
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
void solve(Teuchos::ParameterList &Parameters, Epetra_FECrsMatrix &matrix, Epetra_Vector &lhs, Epetra_FEVector &rhs, Epetra_Vector &damageHistory, Epetra_Map &GaussMap)
Definition: damageField.cpp:88
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
std::vector< int > local_nodes_without_ghosts
Definition: meshpp.hpp:79
optimParameters tol
int n_nodes
Definition: meshpp.hpp:87
for i
Definition: costFunction.m:38
Epetra_Map * OverlapMap
void apply_dirichlet_conditions(Epetra_FECrsMatrix &K, Epetra_FEVector &F, double &displacement)
Epetra_SerialDenseVector gauss_weight_cells
Definition: meshpp.hpp:99
int print_solution(Epetra_Vector &lhs, std::string fileName)
void setup_dirichlet_conditions()