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"
18 #include "newtonRaphson.hpp"
19 #include <boost/math/special_functions/gamma.hpp>
20 
21 int main(int argc, char *argv[]){
22 
23  std::string xmlInFileName = "";
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  }
47 
48  if (Comm.MyPID()==0){
49  paramList->print(std::cout,2,true,true);
50  }
51 
52  Teuchos::RCP<neumannInnerSurface_StochasticPolyconvexHGO> my_interface =
53  Teuchos::rcp(new neumannInnerSurface_StochasticPolyconvexHGO(Comm,*paramList));
54 
55  std::ifstream parameters_file_1, parameters_file_2, parameters_file_3, parameters_file_4;
56  std::string path = Teuchos::getParameter<std::string>(paramList->sublist("Mesh"), "path_to_gmrf");
57  parameters_file_1.open(path+"w1.txt");
58  parameters_file_2.open(path+"w2.txt");
59  parameters_file_3.open(path+"w3.txt");
60  parameters_file_4.open(path+"w4.txt");
61 
62  unsigned int n_cells_p1_med = 297828;
63  unsigned int n_nodes_p1_med = 58464;
64 
65  int error;
66  std::string path_p1 = Teuchos::getParameter<std::string>(paramList->sublist("Mesh"), "path_to_p1_connectivity");
67 
68  my_interface->get_media(n_cells_p1_med,n_nodes_p1_med,path_p1);
69 
70  if (parameters_file_1.is_open() && parameters_file_2.is_open() && parameters_file_3.is_open() && parameters_file_4.is_open()){
71  for (unsigned nmc=0; nmc<3; ++nmc){
72  for (int i=0; i<n_nodes_p1_med; ++i){
73  parameters_file_1 >> my_interface->w1_gmrf(i);
74  parameters_file_2 >> my_interface->w2_gmrf(i);
75  parameters_file_3 >> my_interface->w3_gmrf(i);
76  parameters_file_4 >> my_interface->w4_gmrf(i);
77  }
78  Teuchos::RCP<newtonRaphson> Newton = Teuchos::rcp(new newtonRaphson(*my_interface,*paramList));
79  Newton->setParameters(*paramList);
80  Newton->Initialization();
81  error = Newton->Solve_with_Aztec(true);
82  if (!error){
83  std::string filename1 = path + "/review/disp_realization" + std::to_string(nmc) + ".mtx";
84  Newton->print_newton_solution(filename1);
85  std::string filename2 = path + "/review/stress_realization" + std::to_string(nmc);
86  my_interface->compute_center_cauchy_stress(*Newton->x,filename2);
87  }
88  else{
89  if (Comm.MyPID()==0){
90  std::cout << "Newton failed | realization nb. " << nmc << "\n";
91  }
92  }
93  Comm.Barrier();
94  }
95  parameters_file_1.close();
96  parameters_file_2.close();
97  parameters_file_3.close();
98  parameters_file_4.close();
99  }
100  else{
101  std::cout << "Couldn't open one of the parameters_file.\n";
102  }
103 #ifdef HAVE_MPI
104  MPI_Finalize();
105 #endif
106 return 0;
107 
108 }
optimParameters nmc
int main(int argc, char *argv[])
Definition: main.cpp:23
for i
Definition: costFunction.m:38