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