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 load_solution(std::string & filesolution, Epetra_Vector * x);
22 
23 int main(int argc, char *argv[]){
24 
25  std::string xmlInFileName = "";
26  std::string extraXmlFile = "";
27  std::string xmlOutFileName = "paramList.out";
28 
29  Teuchos::CommandLineProcessor clp(false);
30  clp.setOption("xml-in-file",&xmlInFileName,"The XML file to read into a parameter list");
31  clp.setDocString("TO DO.");
32 
33  Teuchos::CommandLineProcessor::EParseCommandLineReturn
34  parse_return = clp.parse(argc,argv);
35  if( parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) {
36  std::cout << "\nEnd Result: TEST FAILED" << std::endl;
37  return parse_return;
38  }
39 
40 #ifdef HAVE_MPI
41  MPI_Init(&argc, &argv);
42  Epetra_MpiComm Comm(MPI_COMM_WORLD);
43 #else
44  Epetra_SerialComm Comm;
45 #endif
46 
47  Teuchos::RCP<Teuchos::ParameterList> paramList = Teuchos::rcp(new Teuchos::ParameterList);
48  if(xmlInFileName.length()) {
49  Teuchos::updateParametersFromXmlFile(xmlInFileName, inoutArg(*paramList));
50  }
51 
52  if (Comm.MyPID()==0){
53  paramList->print(std::cout,2,true,true);
54  }
55 
56  Teuchos::RCP<neumannInnerSurface_PolyconvexHGO> interface = Teuchos::rcp(new neumannInnerSurface_PolyconvexHGO(Comm,*paramList));
57 
58  /*std::ifstream parameters_file_1, parameters_file_2, parameters_file_3, parameters_file_4;
59  std::string path = Teuchos::getParameter<std::string>(paramList->sublist("Mesh"), "path_to_gmrf");
60  parameters_file_1.open(path+"w1.txt");
61  parameters_file_2.open(path+"w2.txt");
62  parameters_file_3.open(path+"w3.txt");
63  parameters_file_4.open(path+"w4.txt");
64 
65  unsigned int n_cells_p1_med = 297828;
66  unsigned int n_nodes_p1_med = 58464;
67 
68  int error;
69  std::string path_p1 = Teuchos::getParameter<std::string>(paramList->sublist("Mesh"), "path_to_p1_connectivity");
70  interface->get_media(n_cells_p1_med,n_nodes_p1_med,path_p1);*/
71 
72  Epetra_Vector * x = new Epetra_Vector(*interface->StandardMap);
73 
74  //if (parameters_file_1.is_open() && parameters_file_2.is_open() && parameters_file_3.is_open() && parameters_file_4.is_open()){
75 
76  /*for (unsigned nmc=0; nmc<1; ++nmc){
77  for (int i=0; i<n_nodes_p1_med; ++i){
78  parameters_file_1 >> interface->w1_gmrf(i);
79  parameters_file_2 >> interface->w2_gmrf(i);
80  parameters_file_3 >> interface->w3_gmrf(i);
81  parameters_file_4 >> interface->w4_gmrf(i);
82  }*/
83  Teuchos::RCP<newtonRaphson> Newton = Teuchos::rcp(new newtonRaphson(*interface,*paramList));
84  Newton->setParameters(*paramList);
85 
86  std::string filesolution = "/Users/Brian/Documents/Thesis/Trilinos_results/arteries/gmrf_neumann/disp_mean_model.mtx";
87  int error = load_solution(filesolution,x);
88  std::string filestress = "/Users/Brian/Documents/Thesis/Trilinos_results/arteries/gmrf_neumann/stress_mean_model";
89  interface->compute_center_cauchy_stress(*x,filestress);
90  /*if (!error){
91  }
92  else{
93  if (Comm.MyPID()==0){
94  std::cout << "Error with EpetraExt::MatrixMarketFileToVector\n";
95  }
96  }*/
97  //}
98  /*Comm.Barrier();
99  parameters_file_1.close();
100  parameters_file_2.close();
101  parameters_file_3.close();
102  parameters_file_4.close();
103  }
104  else{
105  std::cout << "Couldn't open one of the parameters_file.\n";
106  }*/
107 
108 #ifdef HAVE_MPI
109  MPI_Finalize();
110 #endif
111  return 0;
112 
113 }
114 
115 int load_solution(std::string & filesolution, Epetra_Vector * x){
116 
117  int LID;
118  int error = 0;
119  double data;
120  x->PutScalar(0.0);
121 
122  std::ifstream file;
123  file.open(filesolution);
124  if (file.is_open()){
125  for (int i=0; i<x->GlobalLength(); ++i){
126  file >> data;
127  if ( (x->Map()).MyGID(i) ){
128  LID = (x->Map()).LID(i);
129  x->ReplaceMyValues(1,&data,&LID);
130  }
131  }
132 
133  std::cout << std::setw(10) << x->GlobalLength() << std::setw(10) << x->MyLength() << "\n";
134 
135 
136  }
137  else{
138  std::cout << "Couldn't open the file: " << filesolution << "\n";
139  error = -1;
140  }
141  return error;
142 }
int load_solution(std::string &filesolution, Epetra_Vector *x)
Definition: main.cpp:115
int main(int argc, char *argv[])
Definition: main.cpp:23
for i
Definition: costFunction.m:38