Trilinos based (stochastic) FEM solvers
main.cpp
Go to the documentation of this file.
1 /*
2 Brian Staber (brian.staber@gmail.com)
3 */
4 
5 #include "Epetra_ConfigDefs.h"
6 #ifdef HAVE_MPI
7 #include "mpi.h"
8 #include "Epetra_MpiComm.h"
9 #else
10 #include "Epetra_SerialComm.h"
11 #endif
12 
13 #include "Teuchos_CommandLineProcessor.hpp"
14 #include "Teuchos_StandardCatchMacros.hpp"
15 #include "Teuchos_ParameterList.hpp"
16 #include "Teuchos_XMLParameterListCoreHelpers.hpp"
17 #include "shinozukapp.hpp"
18 
19 int main(int argc, char *argv[]){
20 
21  std::string xmlInFileName = "";
22  std::string extraXmlFile = "";
23  std::string xmlOutFileName = "paramList.out";
24 
25  Teuchos::CommandLineProcessor clp(false);
26  clp.setOption("xml-in-file",&xmlInFileName,"The XML file to read into a parameter list");
27  clp.setDocString("TO DO.");
28 
29  Teuchos::CommandLineProcessor::EParseCommandLineReturn
30  parse_return = clp.parse(argc,argv);
31  if( parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) {
32  std::cout << "\nEnd Result: TEST FAILED" << std::endl;
33  return parse_return;
34  }
35 
36 #ifdef HAVE_MPI
37  MPI_Init(&argc, &argv);
38  Epetra_MpiComm Comm(MPI_COMM_WORLD);
39 #else
40  Epetra_SerialComm Comm;
41 #endif
42 
43  Teuchos::RCP<Teuchos::ParameterList> paramList = Teuchos::rcp(new Teuchos::ParameterList);
44  if(xmlInFileName.length()) {
45  Teuchos::updateParametersFromXmlFile(xmlInFileName, inoutArg(*paramList));
46  if (Comm.MyPID()==0){
47  paramList->print(std::cout,2,true,true);
48  }
49  }
50 
51  std::string mesh_file = Teuchos::getParameter<std::string>(paramList->sublist("Shinozuka"),"mesh_file");
52  mesh Mesh(Comm,mesh_file);
53  Epetra_Map StandardMap(-1,Mesh.n_local_nodes_without_ghosts,&Mesh.local_nodes_without_ghosts[0],0,Comm);
54 
55  int order = Teuchos::getParameter<int>(paramList->sublist("Shinozuka"), "order");
56  double L1 = Teuchos::getParameter<double>(paramList->sublist("Shinozuka"), "lx");
57  double L2 = Teuchos::getParameter<double>(paramList->sublist("Shinozuka"), "ly");
58  double L3 = Teuchos::getParameter<double>(paramList->sublist("Shinozuka"), "lz");
59 
60  for (int real=0; real<32; ++real){
61 
62  Teuchos::RCP<shinozuka> RandomField = Teuchos::rcp(new shinozuka(order,L1,L2,L3));
63 
64  Epetra_MultiVector V(StandardMap,5,"true");
65  Epetra_MultiVector G(StandardMap,5,"true");
66 
67  RandomField->rng.seed(real);
68  for (unsigned int i=0; i<5; ++i){
69  RandomField->generator(*V(i),Mesh);
70  }
71 
72  double deltaN = 0.10;
73  double deltaMk = 0.10;
74 
75  double alpha = 3.0/(2.0*deltaN*deltaN); double beta = 1.0;
76  RandomField->icdf_gamma(*V(0),*G(0),alpha,beta);
77 
78  alpha = 3.0/(2.0*deltaN*deltaN) - 1.0/2.0;
79  RandomField->icdf_gamma(*V(1),*G(1),alpha,beta);
80 
81  alpha = 1.0/(deltaMk*deltaMk); beta = 1.0*deltaMk*deltaMk;
82  RandomField->icdf_gamma(*V(3),*G(3),alpha,beta);
83  RandomField->icdf_gamma(*V(4),*G(4),alpha,beta);
84  *G(2) = *V(2);
85 
86  // it gives the translated field but not the coefficients M1,...,M5.
87 
88  std::string path = "/Users/brian/Documents/GitHub/Trilinos_results/isotransrandomfield/";
89  int NumTargetElements = 0;
90  if (Comm.MyPID()==0){
91  NumTargetElements = Mesh.n_nodes;
92  }
93  Epetra_Map MapOnRoot(-1,NumTargetElements,0,Comm);
94  Epetra_Export ExportOnRoot(StandardMap,MapOnRoot);
95  Epetra_MultiVector lhs_root(MapOnRoot,5,true);
96 
97  lhs_root.PutScalar(0.0);
98  lhs_root.Export(G,ExportOnRoot,Insert);
99  std::string filename = path + "shinozuka_translatedfield_deltaN_" + std::to_string(deltaN) + "_deltaMk_" + std::to_string(deltaMk) + "_real_" + std::to_string(real) +".mtx";
100  int error = EpetraExt::MultiVectorToMatrixMarketFile(filename.c_str(),lhs_root,0,0,false);
101  }
102 
103 #ifdef HAVE_MPI
104  MPI_Finalize();
105 #endif
106 return 0;
107 
108 }
Definition: meshpp.hpp:49
filename
Definition: costFunction.m:44
int main(int argc, char *argv[])
Definition: main.cpp:23
modelParameters beta
Definition: run_station15.m:10
for i
Definition: costFunction.m:38