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 "manufacturedSolution.hpp"
14 
15 int main(int argc, char *argv[]){
16 
17  std::string xmlInFileName = "";
18  int meshIndex;
19 
20  Teuchos::CommandLineProcessor clp(false);
21  clp.setOption("xml-in-file",&xmlInFileName,"The XML file to read into a parameter list");
22  clp.setOption("mesh-index",&meshIndex,"The index of the manufactured mesh.");
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  }
43 
44  if (Comm.MyPID()==0){
45  paramList->print(std::cout,2,true,true);
46  }
47 
48  Epetra_SerialDenseVector parameters(7);
49  parameters(0) = Teuchos::getParameter<double>(paramList->sublist("TIMooney"),"mu1");
50  parameters(1) = Teuchos::getParameter<double>(paramList->sublist("TIMooney"),"mu2");
51  parameters(2) = Teuchos::getParameter<double>(paramList->sublist("TIMooney"),"mu3");
52  parameters(3) = Teuchos::getParameter<double>(paramList->sublist("TIMooney"),"mu4");
53  parameters(4) = Teuchos::getParameter<double>(paramList->sublist("TIMooney"),"mu5");
54  parameters(5) = Teuchos::getParameter<double>(paramList->sublist("TIMooney"),"beta4");
55  parameters(6) = Teuchos::getParameter<double>(paramList->sublist("TIMooney"),"beta5");
56  for (unsigned int i=0; i<5; ++i){
57  parameters(i) = 1.0e3*parameters(i);
58  }
59  double plyagl = 2.0*M_PI*30.0/360.0;
60 
61  double errorL2;
62  std::string path = Teuchos::getParameter<std::string>(paramList->sublist("Mesh"),"path");
63  std::string meshname = "manufactured" + std::to_string(meshIndex) + ".msh";
64  std::string fullpath = path + meshname;
65  Teuchos::RCP<manufacturedSolution> manufactured = Teuchos::rcp(new manufacturedSolution(Comm,*paramList,fullpath));
66  Teuchos::RCP<newtonRaphson> Newton = Teuchos::rcp(new newtonRaphson(*manufactured,*paramList));
67  manufactured->set_parameters(parameters,plyagl);
68  Comm.Barrier();
69 
70  Newton->Initialization();
71  Newton->setParameters(*paramList);
72  int error = Newton->Solve_with_Aztec(true);
73 
74  std::string outpath = Teuchos::getParameter<std::string>(paramList->sublist("Mesh"),"outpath");
75  std::string fulloutpath = outpath + std::to_string(meshIndex) + ".mtx";
76  Newton->print_newton_solution(fulloutpath);
77 
78  double xi = 0.0;
79  fulloutpath = outpath + "_gl_" + std::to_string(meshIndex) + ".mtx";
80  manufactured->compute_green_lagrange(*Newton->x,xi,xi,xi,fulloutpath);
81  errorL2 = manufactured->errorL2(*Newton->x);
82 
83  if (Comm.MyPID()==0){
84  std::ofstream output;
85  output.open("output.txt",std::ios_base::app);
86  output << meshname << std::setw(5) << Comm.NumProc() << std::setw(15) << errorL2 << "\n";
87  output.close();
88  }
89 
90 #ifdef HAVE_MPI
91  MPI_Finalize();
92 #endif
93 return 0;
94 
95 }
output
int main(int argc, char *argv[])
Definition: main.cpp:23
for i
Definition: costFunction.m:38