Trilinos based (stochastic) FEM solvers
main.cpp
Go to the documentation of this file.
1 #include "Epetra_ConfigDefs.h"
2 #ifdef HAVE_MPI
3 #include "mpi.h"
4 #include "Epetra_MpiComm.h"
5 #else
6 #include "Epetra_SerialComm.h"
7 #endif
8 
9 #include "Teuchos_CommandLineProcessor.hpp"
10 #include "Teuchos_StandardCatchMacros.hpp"
11 #include "Teuchos_ParameterList.hpp"
12 #include "Teuchos_XMLParameterListCoreHelpers.hpp"
13 #include "shinozukapp.hpp"
14 
15 int main(int argc, char *argv[]){
16 
17  std::string xmlInFileName = "";
18  std::string extraXmlFile = "";
19  std::string xmlOutFileName = "paramList.out";
20 
21  Teuchos::CommandLineProcessor clp(false);
22  clp.setOption("xml-in-file",&xmlInFileName,"The XML file to read into a parameter list");
23  clp.setDocString("TO DO.");
24 
25  Teuchos::CommandLineProcessor::EParseCommandLineReturn
26  parse_return = clp.parse(argc,argv);
27  if( parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) {
28  std::cout << "\nEnd Result: TEST FAILED" << std::endl;
29  return parse_return;
30  }
31 
32 #ifdef HAVE_MPI
33  MPI_Init(&argc, &argv);
34  Epetra_MpiComm Comm(MPI_COMM_WORLD);
35 #else
36  Epetra_SerialComm Comm;
37 #endif
38 
39  Teuchos::RCP<Teuchos::ParameterList> paramList = Teuchos::rcp(new Teuchos::ParameterList);
40  if(xmlInFileName.length()) {
41  Teuchos::updateParametersFromXmlFile(xmlInFileName, inoutArg(*paramList));
42  if (Comm.MyPID()==0){
43  paramList->print(std::cout,2,true,true);
44  }
45  }
46 
47  std::string mesh_file = Teuchos::getParameter<std::string>(paramList->sublist("Shinozuka"),"mesh_file");
48  mesh Mesh(Comm,mesh_file);
49  Epetra_Map StandardMap(-1,Mesh.n_local_nodes_without_ghosts,&Mesh.local_nodes_without_ghosts[0],0,Comm);
50 
51  int order = Teuchos::getParameter<int>(paramList->sublist("Shinozuka"), "order");
52  int nmc = Teuchos::getParameter<int>(paramList->sublist("Shinozuka"), "nmc");
53  double L1 = Teuchos::getParameter<double>(paramList->sublist("Shinozuka"), "lx");
54  double L2 = Teuchos::getParameter<double>(paramList->sublist("Shinozuka"), "ly");
55  double L3 = Teuchos::getParameter<double>(paramList->sublist("Shinozuka"), "lz");
56 
57  Teuchos::RCP<shinozuka> RandomField = Teuchos::rcp(new shinozuka(order,L1,L2,L3));
58 
59  Epetra_Vector V(StandardMap);
60  Epetra_Vector W(StandardMap);
61  Epetra_Vector scdOrderMoment(StandardMap);
62 
63  W.PutScalar(0.0);
64  scdOrderMoment.PutScalar(0.0);
65  double convScdOrderMoment = 0.0;
66  double GRFNorm2 = 0.0;
67 
68  if (Comm.MyPID()==0){
69  std::cout << std::setw(10) << "(||E{V.*V}||)\n";
70  }
71  for (unsigned int j=1; j<=nmc; ++j){
72  RandomField->rng.seed(j);
73  RandomField->generator(V,Mesh);
74 
75  W.Multiply(1.0,V,V,0.0);
76  scdOrderMoment.Update(1.0/double(j),W,(double(j)-1.0)/double(j));
77  scdOrderMoment.Norm2(&convScdOrderMoment);
78  //scdOrderMoment = ((double(j)-1.0)/double(j))*scdOrderMoment + (1.0/double(j))*V[0]*V[0];
79 
80  if (Comm.MyPID()==0){
81  std::cout << std::setw(10) << convScdOrderMoment/std::sqrt(Mesh.n_nodes) << "\n";
82  }
83  }
84  convScdOrderMoment = convScdOrderMoment/std::sqrt(Mesh.n_nodes);
85 
86  //Epetra_Vector G(StandardMap);
87  //Epetra_Vector B(StandardMap);
88  //double alpha = 1.0/(0.10*0.10); double beta = 10.0*0.10*0.10;
89  //RandomField->icdf_gamma(V,G,alpha,beta);
90  //double tau1 = 5.0; double tau2 = 8.0;
91  //RandomField->icdf_beta(V,B,tau1,tau2);
92 
93  std::string path = "/Users/brian/Documents/GitHub/Trilinos_results/examples/shinozuka/";
94  int NumTargetElements = 0;
95  if (Comm.MyPID()==0){
96  NumTargetElements = Mesh.n_nodes;
97  }
98  Epetra_Map MapOnRoot(-1,NumTargetElements,0,Comm);
99  Epetra_Export ExportOnRoot(StandardMap,MapOnRoot);
100  Epetra_MultiVector lhs_root(MapOnRoot,true);
101 
102  lhs_root.PutScalar(0.0);
103  lhs_root.Export(V,ExportOnRoot,Insert);
104  std::string filename = path + "shinozuka_gaussian.mtx";
105  int error = EpetraExt::MultiVectorToMatrixMarketFile(filename.c_str(),lhs_root,0,0,false);
106 
107  /*
108  lhs_root.Export(G,ExportOnRoot,Insert);
109  std::string filename = path + "shinozuka_gamma.mtx";
110  int error = EpetraExt::MultiVectorToMatrixMarketFile(filename.c_str(),lhs_root,0,0,false);
111  lhs_root.PutScalar(0.0);
112  lhs_root.Export(B,ExportOnRoot,Insert);
113  filename = path + "shinozuka_beta.mtx";
114  error = EpetraExt::MultiVectorToMatrixMarketFile(filename.c_str(),lhs_root,0,0,false);
115  */
116 
117 #ifdef HAVE_MPI
118  MPI_Finalize();
119 #endif
120 return 0;
121 
122 }
for j
Definition: costFunction.m:42
Definition: meshpp.hpp:49
optimParameters nmc
filename
Definition: costFunction.m:44
int main(int argc, char *argv[])
Definition: main.cpp:23