Trilinos based (stochastic) FEM solvers
shinozukapp_layeredcomp.cpp
Go to the documentation of this file.
1 /*
2 Brian Staber (brian.staber@gmail.com)
3 */
4 
6 #include <math.h>
7 
8 shinozuka_layeredcomp::shinozuka_layeredcomp(int & nu, double & length_x, double & length_y, double & length_z):
9 psi_(0.0,1.0), phi_(0.0,1.0), order(nu), l1(length_x), l2(length_y), l3(length_z){
10 }
11 
13 }
14 
15 template<typename typearg>
17  double tau = -1.0 + (2.0*double(beta)-1.0)/double(order);
18  return tau;
19 }
20 
21 double shinozuka_layeredcomp::s_tau(double & tau){
22  double s = 0.0;
23  if (tau>=-1.0 && tau<=1.0){
24  s = (2.0/double(order))*(1.0-fabs(tau));
25  }
26  return s;
27 }
28 
29 void shinozuka_layeredcomp::generator_gauss_points(Epetra_SerialDenseVector & v, mesh & Mesh, std::vector<int> & phase){
30 
31  int node, e_gid;
32  int n_local_cells = Mesh.n_local_cells;
33  int n_gauss_cells = Mesh.n_gauss_cells;
34  double x, y, z;
35  double xi, eta, zeta;
36  double ti, tj, tk;
37  double si, sj, sk;
38  double psi, phi, w, arg;
39 
40  Epetra_SerialDenseVector vector_x(3);
41  Epetra_SerialDenseVector shape_functions(Mesh.el_type);
42  Epetra_SerialDenseMatrix matrix_X(3,Mesh.el_type);
43 
44  for (int il=0; il<32; ++il){
45  for (int i=1; i<=order; ++i){
46  ti = tau_beta<int>(i);
47  si = s_tau(ti);
48  for (int j=1; j<=order; ++j){
49  tj = tau_beta<int>(j);
50  sj = s_tau(tj);
51  for (int k=1; k<=order; ++k){
52  tk = tau_beta<int>(k);
53  sk = s_tau(tk);
54  psi = psi_(rng);
55  phi = phi_(rng);
56  w = std::sqrt(-std::log(psi));
57  for (int e_lid=il; e_lid<n_local_cells; e_lid++){
58  e_gid = Mesh.local_cells[e_lid];
59  if(phase[e_gid]==il){
60  for (unsigned inode=0; inode<Mesh.el_type; ++inode){
61  node = Mesh.cells_nodes[Mesh.el_type*e_gid+inode];
62  matrix_X(0,inode) = Mesh.nodes_coord[3*node+0];
63  matrix_X(1,inode) = Mesh.nodes_coord[3*node+1];
64  matrix_X(2,inode) = Mesh.nodes_coord[3*node+2];
65  }
66  for (int gp=0; gp<n_gauss_cells; ++gp){
67  xi = Mesh.xi_cells(gp); eta = Mesh.eta_cells(gp); zeta = Mesh.zeta_cells(gp);
68  switch (Mesh.el_type){
69  case 4:
70  tetra4::shape_functions(shape_functions, xi, eta, zeta);
71  break;
72  case 8:
73  hexa8::shape_functions(shape_functions, xi, eta, zeta);
74  break;
75  case 10:
76  tetra10::shape_functions(shape_functions, xi, eta, zeta);
77  break;
78  }
79  vector_x.Multiply('N','N',1.0,matrix_X,shape_functions,0.0);
80  arg = 2.0*M_PI*phi + (M_PI/l1)*ti*vector_x(0) + (M_PI/l2)*tj*vector_x(1) + (M_PI/l3)*tk*vector_x(2);
81  v(e_lid*n_gauss_cells+gp) += std::sqrt(2.0*si*sj*sk)*w*std::cos(arg);
82  }
83  }
84  }
85  }
86  }
87  }
88  }
89 
90 }
91 
92 void shinozuka_layeredcomp::generator_one_gauss_point(Epetra_SerialDenseVector & v, mesh & Mesh, std::vector<int> & phase, double & xi, double & eta, double & zeta){
93 
94  int node, e_gid;
95  int n_local_cells = Mesh.n_local_cells;
96  int n_gauss_cells = Mesh.n_gauss_cells;
97  double x, y, z;
98  double ti, tj, tk;
99  double si, sj, sk;
100  double psi, phi, w, arg;
101 
102  Epetra_SerialDenseVector vector_x(3);
103  Epetra_SerialDenseVector shape_functions(Mesh.el_type);
104  Epetra_SerialDenseMatrix matrix_X(3,Mesh.el_type);
105 
106  switch (Mesh.el_type){
107  case 4:
108  tetra4::shape_functions(shape_functions, xi, eta, zeta);
109  break;
110  case 8:
111  hexa8::shape_functions(shape_functions, xi, eta, zeta);
112  break;
113  case 10:
114  tetra10::shape_functions(shape_functions, xi, eta, zeta);
115  break;
116  }
117 
118  for (int il=0; il<32; ++il){
119  for (int i=1; i<=order; ++i){
120  ti = tau_beta<int>(i);
121  si = s_tau(ti);
122  for (int j=1; j<=order; ++j){
123  tj = tau_beta<int>(j);
124  sj = s_tau(tj);
125  for (int k=1; k<=order; ++k){
126  tk = tau_beta<int>(k);
127  sk = s_tau(tk);
128  psi = psi_(rng);
129  phi = phi_(rng);
130  w = std::sqrt(-std::log(psi));
131  for (int e_lid=0; e_lid<n_local_cells; ++e_lid){
132  e_gid = Mesh.local_cells[e_lid];
133  if(phase[e_gid]==il){
134  for (unsigned inode=0; inode<Mesh.el_type; ++inode){
135  node = Mesh.cells_nodes[Mesh.el_type*e_gid+inode];
136  matrix_X(0,inode) = Mesh.nodes_coord[3*node+0];
137  matrix_X(1,inode) = Mesh.nodes_coord[3*node+1];
138  matrix_X(2,inode) = Mesh.nodes_coord[3*node+2];
139  }
140  vector_x.Multiply('N','N',1.0,matrix_X,shape_functions,0.0);
141  arg = 2.0*M_PI*phi + (M_PI/l1)*ti*vector_x(0) + (M_PI/l2)*tj*vector_x(1) + (M_PI/l3)*tk*vector_x(2);
142  v(e_lid) += std::sqrt(2.0*si*sj*sk)*w*std::cos(arg);
143  }
144  }
145  }
146  }
147  }
148  }
149 
150 }
151 
152 void shinozuka_layeredcomp::icdf_gamma(Epetra_Vector & V, Epetra_Vector & G, double & alpha, double & beta){
153  for (unsigned int i=0; i<V.MyLength(); ++i){
154  double erfx = boost::math::erf<double>(V[i]/std::sqrt(2.0));
155  double y = (1.0/2.0)*(1.0 + erfx);
156  double yinv = boost::math::gamma_p_inv<double,double>(alpha,y);
157  G[i] = yinv*beta;
158  }
159 }
160 
161 void shinozuka_layeredcomp::icdf_beta(Epetra_Vector & V, Epetra_Vector & B, double & tau1, double & tau2){
162  for (unsigned int i=0; i<V.MyLength(); ++i){
163  double erfx = boost::math::erf<double>(V[i]/std::sqrt(2.0));
164  double y = (1.0/2.0)*(1.0 + erfx);
165  B[i] = boost::math::ibeta_inv<double,double,double>(tau1,tau2,y);
166  }
167 }
168 
170 }
s
Definition: run.m:11
for j
Definition: costFunction.m:42
boost::random::mt19937 rng
void shape_functions(Epetra_SerialDenseVector &N, double &xi, double &eta, double &zeta)
Definition: fepp.cpp:88
double tau_beta(typearg &beta)
std::vector< double > nodes_coord
Definition: meshpp.hpp:77
boost::random::uniform_real_distribution psi_
int n_local_cells
Definition: meshpp.hpp:94
Epetra_SerialDenseVector eta_cells
Definition: meshpp.hpp:100
void icdf_beta(Epetra_Vector &V, Epetra_Vector &B, double &tau1, double &tau2)
Epetra_SerialDenseVector xi_cells
Definition: meshpp.hpp:100
Definition: meshpp.hpp:49
std::vector< int > local_cells
Definition: meshpp.hpp:81
for k
Definition: costFunction.m:51
boost::random::uniform_real_distribution phi_
int el_type
Definition: meshpp.hpp:90
void shape_functions(Epetra_SerialDenseVector &N, double &xi, double &eta, double &zeta)
Definition: fepp.cpp:110
std::vector< int > cells_nodes
Definition: meshpp.hpp:78
void shape_functions(Epetra_SerialDenseVector &N, double &xi, double &eta)
Definition: fepp.cpp:7
unsigned int n_gauss_cells
Definition: meshpp.hpp:98
void icdf_gamma(Epetra_Vector &V, Epetra_Vector &G, double &alpha, double &beta)
void generator_gauss_points(Epetra_SerialDenseVector &v, mesh &Mesh, std::vector< int > &phase)
void generator_one_gauss_point(Epetra_SerialDenseVector &v, mesh &Mesh, std::vector< int > &phase, double &xi, double &eta, double &zeta)
modelParameters beta
Definition: run_station15.m:10
for i
Definition: costFunction.m:38
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