Trilinos based (stochastic) FEM solvers
shinozukapp_2d.cpp
Go to the documentation of this file.
1 /*
2 Brian Staber (brian.staber@gmail.com)
3 */
4 
5 #include "shinozukapp_2d.hpp"
6 #include <math.h>
7 
8 shinozuka_2d::shinozuka_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>
16 double shinozuka_2d::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_2d::s_tau(double & tau){
22  double s = (2.0/double(order))*(1.0-fabs(tau));
23  return s;
24 }
25 
26 void shinozuka_2d::generator(Epetra_Vector & v, mesh & Mesh){
27 
28  double c = std::cos(rotation);
29  double s = std::sin(rotation);
30 
31  int node;
32  double x, y;
33  double ti, tj;
34  double si, sj;
35  double k1, k2, DELTA;
36  double psi, phi, w, arg;
37  v.PutScalar(0.0);
38 
39  for (int i=1; i<=order; ++i){
40  ti = tau_beta<int>(i);
41  si = s_tau(ti);
42 
43  for (int j=1; j<=order; ++j){
44  tj = tau_beta<int>(j);
45  sj = s_tau(tj);
46 
47  psi = psi_(rng);
48  phi = phi_(rng);
49  w = std::sqrt(-std::log(psi));
50 
51  //k1 = (M_PI/l1)*ti*c + (M_PI/l2)*tj*s;
52  //k2 = (M_PI/l2)*tj*c - (M_PI/l1)*ti*s;
53  //DELTA = l1*l2*fabs((c/l1) + (s/l2))*fabs((c/l2)-(s/l1));
54  for (int inode=0; inode<v.MyLength(); ++inode){
55  node = Mesh.local_nodes_without_ghosts[inode];
56  x = Mesh.nodes_coord[3*node+0];
57  y = Mesh.nodes_coord[3*node+1];
58  //arg = 2.0*M_PI*phi + (M_PI/l1)*ti*x + (M_PI/l2)*tj*y;
59  //arg = 2.0*M_PI*phi + (M_PI/l1)*ti*(x*s+y*c) + (M_PI/l2)*tj*(x*c-y*s);
60  //arg = 2.0*M_PI*phi + (M_PI*ti*c/l1 + M_PI*tj*s/l2)*x + (-M_PI*ti*s/l1 + M_PI*tj*c/l2)*y;
61  //arg = 2.0*M_PI*phi + k1*x + k2*y;
62  arg = 2.0*M_PI*phi + (M_PI/l1)*ti*(x*c - y*s) + (M_PI/l2)*tj*(x*s + y*c);
63  v[inode] += std::sqrt(2.0*si*sj)*w*std::cos(arg);
64  }
65 
66  }
67  }
68 
69 }
70 
71 void shinozuka_2d::icdf_gamma(Epetra_Vector & V, Epetra_Vector & G, double & alpha, double & beta){
72  for (unsigned int i=0; i<V.MyLength(); ++i){
73  double erfx = boost::math::erf<double>(V[i]/std::sqrt(2.0));
74  double y = (1.0/2.0)*(1.0 + erfx);
75  double yinv = boost::math::gamma_p_inv<double,double>(alpha,y);
76  G[i] = yinv*beta;
77  }
78 }
79 
80 void shinozuka_2d::icdf_beta(Epetra_Vector & V, Epetra_Vector & B, double & tau1, double & tau2){
81  for (unsigned int i=0; i<V.MyLength(); ++i){
82  double erfx = boost::math::erf<double>(V[i]/std::sqrt(2.0));
83  double y = (1.0/2.0)*(1.0 + erfx);
84  B[i] = boost::math::ibeta_inv<double,double,double>(tau1,tau2,y);
85  }
86 }
87 
89 }
double s_tau(double &tau)
s
Definition: run.m:11
for j
Definition: costFunction.m:42
double tau_beta(typearg &beta)
std::vector< double > nodes_coord
Definition: meshpp.hpp:77
void icdf_gamma(Epetra_Vector &V, Epetra_Vector &G, double &alpha, double &beta)
boost::random::uniform_real_distribution psi_
void icdf_beta(Epetra_Vector &V, Epetra_Vector &B, double &tau1, double &tau2)
Definition: meshpp.hpp:49
void generator(Epetra_Vector &v, mesh &Mesh)
boost::random::mt19937 rng
std::vector< int > local_nodes_without_ghosts
Definition: meshpp.hpp:79
modelParameters beta
Definition: run_station15.m:10
for i
Definition: costFunction.m:38
boost::random::uniform_real_distribution phi_