Trilinos based (stochastic) FEM solvers
example_pnpoly_inverse_isoparam.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 "NRL_ModelF.hpp"
10 #include "newtonRaphson.hpp"
11 #include "objectiveFunction.hpp"
12 #include <random>
13 
14 int main(int argc, char *argv[]){
15 
16  std::string xmlInFileName = "";
17  std::string xmlExtraFileName = "";
18 
19  Teuchos::CommandLineProcessor clp(false);
20  clp.setOption("xml-in-file",&xmlInFileName,"The XML file to read into a parameter list");
21  clp.setOption("extra-file",&xmlExtraFileName,"Extra XML file to read into a parameter list");
22  clp.setDocString("TO DO.");
23 
24  Teuchos::CommandLineProcessor::EParseCommandLineReturn
25  parse_return = clp.parse(argc,argv);
26  if( parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) {
27  std::cout << "\nEnd Result: TEST FAILED" << std::endl;
28  return parse_return;
29  }
30 
31 #ifdef HAVE_MPI
32  MPI_Init(&argc, &argv);
33  Epetra_MpiComm Comm(MPI_COMM_WORLD);
34 #else
35  Epetra_SerialComm Comm;
36 #endif
37 
38  Teuchos::RCP<Teuchos::ParameterList> paramList = Teuchos::rcp(new Teuchos::ParameterList);
39  if(xmlInFileName.length()) {
40  Teuchos::updateParametersFromXmlFile(xmlInFileName, inoutArg(*paramList));
41  }
42  if(xmlExtraFileName.length()) {
43  Teuchos::updateParametersFromXmlFile(xmlExtraFileName, inoutArg(*paramList));
44  }
45 
46  if (Comm.MyPID()==0){
47  paramList->print(std::cout,2,true,true);
48  }
49 
50  Teuchos::RCP<objectiveFunction<double>> obj = Teuchos::rcp(new objectiveFunction<double>(Comm,*paramList));
51 
52  if (Comm.MyPID()==0){
53  int width = 20;
54  int eglob = 4000;
55  int nvert = obj->interface->Mesh->face_type;
56  Epetra_SerialDenseVector x(nvert), y(nvert);
57 
58  double testx = 0.0;
59  double testy = 0.0;
60  double xmin, xmax;
61  double ymin, ymax;
62 
63  int node;
64  for (unsigned int inode=0; inode<nvert; ++inode){
65  node = obj->interface->Mesh->faces_nodes[nvert*eglob+inode];
66  x(inode) = obj->interface->Mesh->nodes_coord[3*node+0];
67  y(inode) = obj->interface->Mesh->nodes_coord[3*node+1];
68  testx += x(inode);
69  testy += y(inode);
70  if (inode==0){
71  xmin = x(inode); xmax = x(inode);
72  ymin = y(inode); ymax = y(inode);
73  }
74  else{
75  if (x(inode)<xmin){
76  xmin = x(inode);
77  }
78  if (x(inode)>xmax){
79  xmax = x(inode);
80  }
81  if (y(inode)<ymin){
82  ymin = y(inode);
83  }
84  if (y(inode)>ymax){
85  ymax = y(inode);
86  }
87  }
88  }
89 
90  std::mt19937 G(time(NULL));
91  std::uniform_real_distribution<double> u(xmin,xmax);
92  std::uniform_real_distribution<double> v(ymin,ymax);
93 
94  std::cout << std::setw(width) << "cell" << std::setw(width) << "testx" << std::setw(width) << "testy" << std::setw(width) << "pnpoly" << std::setw(width) << "xi" << std::setw(width) << "eta" << std::setw(width) << "residual\n";
95  int nnmc = 500;
96  for (unsigned int nmc=0; nmc<nnmc; ++nmc){
97  testx = u(G);
98  testy = v(G);
99 
100  int result = pnpoly(nvert,x,y,testx,testy);
101  /*if (!result){
102  std::cout << "**ERR: I'm not in the cell!\n";
103  }*/
104 
105  double xi = 0.0;
106  double eta = 0.0;
107  double residual = 0.0;
108  if (result){
109  residual = obj->inverse_isoparametric_mapping(testx, testy, x, y, xi, eta);
110  }
111 
112  std::cout << std::setw(width) << eglob << std::setw(width) << testx << std::setw(width) << testy << std::setw(width) << result << std::setw(width) << xi << std::setw(width) << eta << std::setw(width) << residual << "\n";
113  }
114  }
115 
116 #ifdef HAVE_MPI
117  MPI_Finalize();
118 #endif
119 return 0;
120 
121 }
u
Definition: run.m:9
optimParameters nmc
int main(int argc, char *argv[])
int pnpoly(int &nvert, Epetra_SerialDenseVector &vertx, Epetra_SerialDenseVector &verty, double &testx, double &testy)
Definition: fepp.cpp:315
output eta
Definition: costFunction.m:33