proteus  1.8.1
C/C++/Fortran libraries
testFMMandFSW.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <algorithm>
3 #include <vector>
4 #include <valarray>
5 #include <map>
6 #include "FMMandFSW.h"
7 
8 double pos(double a)
9 {return std::max<double>(a,0.0);}
10 double neg(double a)
11 {return std::min<double>(a,0.0);}
12 
13 int main()
14 {
15  using namespace std;
16 
17  int nx = 11;
18  double Lx = 1.0; double dx = Lx/(nx-1);
19  Mesh mesh;
20  std::cout<<"creating mesh nx= "<<nx<<" Lx= "<<Lx<<std::endl;
21  initializeMesh(mesh);
22 
23  edgeMeshElements(nx,mesh);
24  regularEdgeMeshNodes(nx,Lx,mesh);
26 
27  std::cout<<"creating FMMEikonalSolver1d ... "<<std::endl;
28  FMMEikonalSolver1d fmm(&mesh);
29 
30  //try redistancing from 1d circle
31  double xc = 0.5; double radius = 0.1;
32  std::valarray<double> phi0(nx),T(nx);
33  for (int nN = 0; nN < mesh.nNodes_global; nN++)
34  {
35  double x = mesh.nodeArray[nN*3+0]; double d2 = (x-xc)*(x-xc) - radius*radius;
36  phi0[nN] = d2;
37  }
38 
39  std::cout<<"phi0 :"<<std::endl;
40  for (int nN = 0; nN < mesh.nNodes_global; nN++)
41  {
42  std::cout<<"x= "<<mesh.nodeArray[nN*3+0]<<" phi["<<nN<<"] = "<<phi0[nN]<<std::endl;
43  }
44  double zeroTol=1.0e-4; double trialTol = 1.0e-1; int verbose = 10;
45 
46 // std::cout<<"initializingKnownPointsUsingMagnitude ..."<<std::endl;
47 // fmm.initializeKnownPointsUsingMagnitude(&phi0[0],&T[0],zeroTol,verbose);
48 // std::cout<<"Known= "<<std::endl;
49 // std::copy(fmm.Known.begin(),fmm.Known.end(),std::ostream_iterator<int>(std::cout," , "));
50 // std::cout<<std::endl;
51 // std::cout<<"T= "<<std::endl;
52 // std::copy(&T[0],&T[0]+nx,std::ostream_iterator<double>(std::cout," , "));
53 // std::cout<<std::endl;
54 
55 // std::cout<<"initializingKnownPointsUsingFront ..."<<std::endl;
56 // fmm.initializeKnownPointsUsingFrontIntersection(&phi0[0],&T[0],zeroTol,verbose);
57 // std::cout<<"Known= "<<std::endl;
58 // std::copy(fmm.Known.begin(),fmm.Known.end(),std::ostream_iterator<int>(std::cout," , "));
59 // std::cout<<std::endl;
60 // std::cout<<"T= "<<std::endl;
61 // std::copy(&T[0],&T[0]+nx,std::ostream_iterator<double>(std::cout," , "));
62 // std::cout<<std::endl;
63 
64  //typedef double (*PF)(double);
65  //PF pf = pos;
66  std::valarray<double> phi0p = phi0.apply(pos);
67  //pf = neg;
68  std::valarray<double> phi0m = phi0.apply(neg);
69  std::valarray<double> Tp(T);
70  std::valarray<double> Tm(T);
71  std::valarray<double> nodalSpeeds(1.0,nx);
72 
73  fmm.solve(&phi0p[0],&nodalSpeeds[0],&Tp[0],zeroTol,trialTol,verbose);
74  std::cout<<"phi0p= "<<std::endl;
75  std::copy(&phi0p[0],&phi0p[0]+nx,std::ostream_iterator<double>(std::cout," , "));
76  std::cout<<std::endl;
77  std::cout<<"Tp= "<<std::endl;
78  std::copy(&Tp[0],&Tp[0]+nx,std::ostream_iterator<double>(std::cout," , "));
79  std::cout<<std::endl;
80 
81  fmm.solve(&phi0m[0],&nodalSpeeds[0],&Tm[0],zeroTol,trialTol,verbose);
82  std::cout<<"phi0m= "<<std::endl;
83  std::copy(&phi0m[0],&phi0m[0]+nx,std::ostream_iterator<double>(std::cout," , "));
84  std::cout<<std::endl;
85  std::cout<<"Tm= "<<std::endl;
86  std::copy(&Tm[0],&Tm[0]+nx,std::ostream_iterator<double>(std::cout," , "));
87  std::cout<<std::endl;
88 
89  T = Tp - Tm;
90  std::cout<<"T= "<<std::endl;
91  std::copy(&T[0],&T[0]+nx,std::ostream_iterator<double>(std::cout," , "));
92  std::cout<<std::endl;
93 
94  std::cout<<"cleaning up"<<std::endl;
95  deleteMesh(mesh);
96  return 0;
97 }
Mesh::nodeArray
double * nodeArray
Definition: mesh.h:67
Mesh
Definition: mesh.h:28
neg
double neg(double a)
Definition: testFMMandFSW.cpp:10
main
int main()
Definition: testFMMandFSW.cpp:13
deleteMesh
void deleteMesh(Mesh &mesh)
Definition: mesh.h:164
edgeMeshElements
int edgeMeshElements(const int &nx, Mesh &mesh)
Definition: mesh.cpp:59
T
Double T
Definition: Headers.h:87
constructElementBoundaryElementsArray_edge
int constructElementBoundaryElementsArray_edge(Mesh &mesh)
Definition: mesh.cpp:622
regularEdgeMeshNodes
int regularEdgeMeshNodes(const int &nx, const double &Lx, Mesh &mesh)
Definition: mesh.cpp:73
initializeMesh
void initializeMesh(Mesh &mesh)
Definition: mesh.h:87
Mesh::nNodes_global
int nNodes_global
Definition: mesh.h:31
pos
double pos(double a)
Definition: testFMMandFSW.cpp:8