Trilinos based (stochastic) FEM solvers
distributenrldata.cpp
Go to the documentation of this file.
1 /*
2 Brian Staber (brian.staber@gmail.com)
3 */
4 
5 #include "distributenrldata.hpp"
6 #include <math.h>
7 
8 distributenrldata::distributenrldata(mesh & Mesh, std::string & path){
9  retrieve_data(Mesh,path);
10 }
11 
13 }
14 
15 void distributenrldata::retrieve_data(mesh & Mesh, std::string & path){
16 
17  double testx, testy, testz, xi, eta, residual;
18  unsigned int n_local_faces = Mesh.n_local_faces;
19  int nvert = Mesh.face_type;
20  int node, result, e_gid;
21 
22  Epetra_SerialDenseVector x(nvert), y(nvert), z(nvert);
23 
24  std::vector<double> data_xyz;
25  std::vector<double> data_exx, data_eyy, data_exy;
26 
27  Teuchos::RCP<readnrldata> nrldata = Teuchos::rcp(new readnrldata(true,path));
28  npoints = nrldata->npoints;
29  nloads = nrldata->nloads;
30  boundaryconditions = nrldata->boundaryconditions;
31  //energy = nrldata->energy;
32  angles = nrldata->angles;
33 
34  for (unsigned int p=0; p<npoints; ++p){
35  testx = nrldata->points(p,0);
36  testy = nrldata->points(p,1);
37  testz = nrldata->points(p,2);
38  for (unsigned int e_lid=0; e_lid<n_local_faces; ++e_lid){
39  e_gid = Mesh.local_faces[e_lid];
40  result = -1;
41  for (unsigned int inode=0; inode<nvert; ++inode){
42  node = Mesh.faces_nodes[nvert*e_gid+inode];
43  x(inode) = Mesh.nodes_coord[3*node+0];
44  y(inode) = Mesh.nodes_coord[3*node+1];
45  z(inode) = Mesh.nodes_coord[3*node+2];
46  }
47  if (z(0)==testz && testx>=0.0 && testx<=50.0 && testy>=0.0 && testy<=25.0){
48  result = pnpoly(nvert,x,y,testx,testy);
49  }
50  if (result==1){
51  local_id_faces.push_back(e_lid);
52  global_id_faces.push_back(p);
53  residual = inverse_isoparametric_mapping(testx,testy,x,y,xi,eta);
54  local_xi.push_back(xi);
55  local_eta.push_back(eta);
56  }
57  }
58  }
59 }
60 
61 double distributenrldata::inverse_isoparametric_mapping(double & testx, double & testy, Epetra_SerialDenseVector & x, Epetra_SerialDenseVector & y, double & xi, double & eta){
62 
63  Epetra_SerialDenseSolver solver;
64 
65  double rhs_inf = 1.0;
66  int nvert = x.Length();;
67  int iter = 0;
68 
69  Epetra_SerialDenseVector f(2);
70  Epetra_SerialDenseVector dxi(2);
71  Epetra_SerialDenseVector N(nvert);
72  Epetra_SerialDenseMatrix D(nvert,2);
73  Epetra_SerialDenseMatrix A(2,2);
74  Epetra_SerialDenseMatrix mat_x(2,nvert);
75 
76  for (unsigned int i=0; i<nvert; ++i){
77  mat_x(0,i) = x(i);
78  mat_x(1,i) = y(i);
79  }
80 
81  xi = 0.0; eta = 0.0;
82  while (rhs_inf>1e-10){
83  switch (nvert){
84  case 3:
85  tri3::shape_functions(N,xi,eta);
86  tri3::d_shape_functions(D,xi,eta);
87  break;
88  case 4:
89  quad4::shape_functions(N,xi,eta);
90  quad4::d_shape_functions(D,xi,eta);
91  break;
92  case 6:
93  tri6::shape_functions(N,xi,eta);
94  tri6::d_shape_functions(D,xi,eta);
95  break;
96  }
97  f(0) = testx;
98  f(1) = testy;
99  f.Multiply('N','N',-1.0,mat_x,N,1.0);
100 
101  iter++;
102  if (iter>1){
103  rhs_inf = f.NormInf();
104  if (rhs_inf>1e8){
105  std::cout << "Inverse Isoparametric Mapping: Newton-Raphson failed to converge.\n";
106  break;
107  }
108  }
109  if (iter>1000){
110  std::cout << "Inverse Isoparametric Mapping: Iteration number exceeds 1000.\n";
111  break;
112  }
113 
114  A.Multiply('N','N',1.0,mat_x,D,0.0);
115 
116  solver.SetMatrix(A);
117  solver.SetVectors(dxi,f);
118  int error = solver.Solve();
119  if (error){
120  std::cout << "Inverse Isoparametric Mapping: Error with Epetra_SerialDenseSolver.\n";
121  }
122  xi += dxi(0);
123  eta += dxi(1);
124  }
125 
126  return rhs_inf;
127 }
void shape_functions(Epetra_SerialDenseVector &N, double &xi, double &eta)
Definition: fepp.cpp:28
Epetra_SerialDenseVector angles
std::vector< int > local_id_faces
std::vector< int > local_faces
Definition: meshpp.hpp:81
int n_local_faces
Definition: meshpp.hpp:95
std::vector< double > nodes_coord
Definition: meshpp.hpp:77
void d_shape_functions(Epetra_SerialDenseMatrix &D, double &xi, double &eta)
Definition: fepp.cpp:34
std::vector< double > local_eta
void shape_functions(Epetra_SerialDenseVector &N, double &xi, double &eta)
Definition: fepp.cpp:51
p
Definition: run.m:6
int face_type
Definition: meshpp.hpp:91
Definition: meshpp.hpp:49
std::vector< int > faces_nodes
Definition: meshpp.hpp:78
double inverse_isoparametric_mapping(double &testx, double &testy, Epetra_SerialDenseVector &x, Epetra_SerialDenseVector &y, double &xi, double &eta)
std::vector< double > local_xi
void shape_functions(Epetra_SerialDenseVector &N, double &xi, double &eta)
Definition: fepp.cpp:7
distributenrldata(mesh &Mesh, std::string &path)
void d_shape_functions(Epetra_SerialDenseMatrix &D, double &xi, double &eta)
Definition: fepp.cpp:12
std::vector< int > global_id_faces
void retrieve_data(mesh &Mesh, std::string &path)
for i
Definition: costFunction.m:38
e
Definition: run.m:10
Epetra_SerialDenseVector boundaryconditions
void d_shape_functions(Epetra_SerialDenseMatrix &D, double &xi, double &eta)
Definition: fepp.cpp:61
int pnpoly(int &nvert, Epetra_SerialDenseVector &vertx, Epetra_SerialDenseVector &verty, double &testx, double &testy)
Definition: fepp.cpp:315
output eta
Definition: costFunction.m:33