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