5 #ifndef NRL_PCA_LIKELIHOOD 6 #define NRL_PCA_LIKELIHOOD 12 #include <boost/random/mersenne_twister.hpp> 13 #include <boost/random/normal_distribution.hpp> 14 #include <boost/random/uniform_real_distribution.hpp> 15 #include <boost/math/special_functions/gamma.hpp> 21 Teuchos::ParameterList _paramList;
22 Teuchos::RCP<newtonRaphson> newton;
23 std::string fullOutputPath;
26 Epetra_Map * MapExpPoints;
27 Epetra_SerialDenseVector lb, ub;
36 _paramList = paramList;
37 std::string pathnrl = Teuchos::getParameter<std::string>(paramList.sublist(
"nrldata"),
"pathnrl");
38 std::string
station = Teuchos::getParameter<std::string>(paramList.sublist(
"nrldata"),
"station");
39 fullOutputPath =
"/home/s/staber/Trilinos_results/nrl/random_generator_for_pca_likelihood/" + station +
"/";
40 interface = Teuchos::rcp(new tiMooneyRandomField(Comm,paramList));
41 newton = Teuchos::rcp(
new newtonRaphson(*interface,paramList));
44 MapExpPoints =
new Epetra_Map(-1,nrldata->global_id_faces.size(),&nrldata->global_id_faces[0],0,Comm);
52 Epetra_IntSerialDenseVector & seeds ,
53 Epetra_SerialDenseVector & mean_parameters ,
54 Epetra_SerialDenseVector & exponents ,
55 Epetra_SerialDenseVector & correlation_lengths ,
56 Epetra_SerialDenseVector & coeff_of_variation ,
58 bool printNewtonIterations,
59 bool printDisplacements ,
60 bool printDeformations ,
61 bool printRandomVariableY)
63 Epetra_SerialDenseVector omega(6);
64 omega(0) = coeff_of_variation(0);
65 omega(1) = coeff_of_variation(1);
66 omega(2) = coeff_of_variation(2);
67 omega(3) = coeff_of_variation(3);
68 omega(4) = correlation_lengths(0);
69 omega(5) = correlation_lengths(1);
71 double plyagl = plyagl_deg*2.0*M_PI/360.0;
72 interface->setParameters(mean_parameters,exponents,omega);
73 interface->set_plyagl(plyagl);
74 interface->RandomFieldGenerator(seeds);
76 Epetra_Vector RandomVariableX(*MapExpPoints);
77 RandomVariableX.PutScalar(0.0);
80 newton->Initialization();
81 for (
unsigned int i=0;
i<nrldata->boundaryconditions.Length(); ++
i){
82 newton->setParameters(_paramList);
84 newton->bc_disp=nrldata->boundaryconditions(
i);
87 newton->bc_disp=nrldata->boundaryconditions(
i)-nrldata->boundaryconditions(
i-1);
90 error = newton->Solve_with_Aztec(printNewtonIterations);
94 if (printDisplacements){
95 std::string path = fullOutputPath +
"u_nmc=" + std::to_string(nmc) +
"_angle=" + std::to_string(
int(plyagl_deg)) +
"_k=" + std::to_string(
i) +
".mtx";
96 int flag = newton->print_newton_solution(path);
98 if (comm->MyPID()==0){
99 std::cout <<
"Failed printing displacements.";
104 if (printDeformations){
105 std::string path = fullOutputPath +
"e_nmc" + std::to_string(nmc) +
"_angle=" + std::to_string(
int(plyagl_deg)) +
"_k=" + std::to_string(
i) +
".mtx";
107 int flag = interface->compute_green_lagrange(*newton->x,xi,xi,xi,path);
109 if (comm->MyPID()==0){
110 std::cout <<
"Failed printing deformations.";
115 Epetra_SerialDenseMatrix eij(nrldata->local_id_faces.size(),3);
118 for (
unsigned int j=0;
j<nrldata->local_id_faces.size(); ++
j){
119 RandomVariableX[
j] += eij(
j,0)*eij(
j,0)+eij(
j,1)*eij(
j,1)+2.0*eij(
j,2)*eij(
j,2);
123 if (comm->MyPID()==0){
124 std::cout <<
"Newton failed at loading " <<
i <<
".\n";
125 std::cout <<
"GIndicator(" << i <<
") set to 0.0.\n";
131 if (printRandomVariableY && !error){
132 std::string pathToRandomVariableX = fullOutputPath +
"RandomVariableY_angle=" + std::to_string(
int(plyagl_deg)) +
"_nmc=" + std::to_string(nmc) +
".mtx";
142 int NumTargetElements = 0;
143 if (comm->MyPID()==0){
144 NumTargetElements = nrldata->npoints;
146 Epetra_Map MapOnRoot(-1,NumTargetElements,0,*comm);
147 Epetra_Export ExportOnRoot(*MapExpPoints,MapOnRoot);
148 Epetra_MultiVector lhs_root(MapOnRoot,
true);
149 lhs_root.Export(X,ExportOnRoot,Insert);
151 int error = EpetraExt::MultiVectorToMatrixMarketFile(filename.c_str(),lhs_root,0,0,
false);
156 Epetra_Vector
u(*(interface->OverlapMap));
157 u.Import(x, *(interface->ImportToOverlapMap), Insert);
161 Epetra_SerialDenseMatrix matrix_X(2,interface->Mesh->face_type);
162 Epetra_SerialDenseMatrix matrix_x(2,interface->Mesh->face_type);
163 Epetra_SerialDenseMatrix D(interface->Mesh->face_type,2);
164 Epetra_SerialDenseMatrix dx_shape_functions(interface->Mesh->face_type,2);
165 Epetra_SerialDenseMatrix deformation_gradient(2,2);
166 Epetra_SerialDenseMatrix JacobianMatrix(2,2);
167 Epetra_SerialDenseMatrix InverseJacobianMatrix(2,2);
168 Epetra_SerialDenseMatrix right_cauchy(2,2);
170 for (
unsigned int e=0;
e<nrldata->local_id_faces.size(); ++
e){
171 e_gid = interface->Mesh->local_faces[nrldata->local_id_faces[
e]];
172 for (
unsigned int inode=0; inode<interface->Mesh->face_type; ++inode){
173 node = interface->Mesh->faces_nodes[interface->Mesh->face_type*e_gid+inode];
174 matrix_X(0,inode) = interface->Mesh->nodes_coord[3*node+0];
175 matrix_X(1,inode) = interface->Mesh->nodes_coord[3*node+1];
176 matrix_x(0,inode) = u[interface->OverlapMap->LID(3*node+0)] + interface->Mesh->nodes_coord[3*node+0];
177 matrix_x(1,inode) = u[interface->OverlapMap->LID(3*node+1)] + interface->Mesh->nodes_coord[3*node+1];
179 switch (interface->Mesh->face_type){
191 det_jac = fabs(JacobianMatrix(0,0)*JacobianMatrix(1,1) - JacobianMatrix(1,0)*JacobianMatrix(0,1));
192 InverseJacobianMatrix(0,0) = (1.0/det_jac)*JacobianMatrix(1,1);
193 InverseJacobianMatrix(1,1) = (1.0/det_jac)*JacobianMatrix(0,0);
194 InverseJacobianMatrix(0,1) = -(1.0/det_jac)*JacobianMatrix(0,1);
195 InverseJacobianMatrix(1,0) = -(1.0/det_jac)*JacobianMatrix(1,0);
196 dx_shape_functions.Multiply(
'N',
'N',1.0,D,InverseJacobianMatrix,0.0);
198 deformation_gradient.Multiply(
'N',
'N',1.0,matrix_x,dx_shape_functions,0.0);
199 right_cauchy.Multiply(
'T',
'N',1.0,deformation_gradient,deformation_gradient,0.0);
201 eij(
e,0) = (1.0/2.0)*(right_cauchy(0,0)-1.0);
202 eij(
e,1) = (1.0/2.0)*(right_cauchy(1,1)-1.0);
203 eij(
e,2) = (1.0/2.0)*right_cauchy(0,1);
void d_shape_functions(Epetra_SerialDenseMatrix &D, double &xi, double &eta)
nrl_PCA_Likelihood(Epetra_Comm &Comm, Teuchos::ParameterList ¶mList)
Teuchos::RCP< tiMooneyRandomField > interface
void compute_green_lagrange(Epetra_Vector &x, Epetra_SerialDenseMatrix &eij)
Teuchos::RCP< distributenrldata > nrldata
int printIndicatorY(std::string filename, Epetra_Vector &X)
int rnd(unsigned int &nmc, Epetra_IntSerialDenseVector &seeds, Epetra_SerialDenseVector &mean_parameters, Epetra_SerialDenseVector &exponents, Epetra_SerialDenseVector &correlation_lengths, Epetra_SerialDenseVector &coeff_of_variation, double &plyagl_deg, bool printNewtonIterations, bool printDisplacements, bool printDeformations, bool printRandomVariableY)
void d_shape_functions(Epetra_SerialDenseMatrix &D, double &xi, double &eta)
void jacobian_matrix(Epetra_SerialDenseMatrix &X, Epetra_SerialDenseMatrix &D, Epetra_SerialDenseMatrix &JacobianMatrix)
void d_shape_functions(Epetra_SerialDenseMatrix &D, double &xi, double &eta)