OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
main.cpp
1 /*
2  * ### WIKI 1 ###
3  *
4  * ## Simple example
5  *
6  * In this example we show 1D PSE derivative function approximation
7  * convergence plot
8  *
9  * ### WIKI END ###
10  *
11  */
12 
13 #include "config/config.h"
14 
15 // Some compiler like clang does not have libquadmath this example
16 // require libquadmath. So is active only if in openfpm installation
17 // such library has been detected
18 
19 #ifdef HAVE_LIBQUADMATH
20 
21 #include "VCluster.hpp"
22 #include "PSE/Kernels_test_util.hpp"
23 #include "Plot/GoogleChart.hpp"
24 #include <boost/multiprecision/float128.hpp>
25 
26 /*
27  *
28  * ### WIKI 2 ###
29  *
30  * In this header we encapsulate the example 0_Derivative_approx_1D.
31  * In particular instead of printing the l2 and l_infinity norm, it
32  * expose a function PSE_test that given a number of particles it
33  * return the calculated l2 and l_inf error for the second order Laplacian
34  * approximation of the function x*e^{-x^2} in the interval 0.0 and 4.0
35  *
36  */
37 
38 /*
39  *
40  * ### WIKI END ###
41  *
42  */
43 
44 int main(int argc, char* argv[])
45 {
46  //
47  // ### WIKI 2 ###
48  //
49  // Here we Initialize the library and we define Ghost size
50  // and non-periodic boundary conditions
51  //
52  openfpm_init(&argc,&argv);
53  Vcluster & v_cl = create_vcluster();
54 
55  // This test is not made to run in parallel
56  if (v_cl.getProcessingUnits() > 1)
57  {
58  std::cerr << "Error: only one processor is allowed" << "\n";
59  return 1;
60  }
61 
64 
66  yn.add("(order 2) float128 overlap=2");
67  yn.add("(order 2) float128 overlap=4");
68  yn.add("(order 2) overlap 2 double ");
69  yn.add("(order 2) overlap 4 double (order 2)");
70  yn.add("(order 2) overlap 2 float (order 2)");
71  yn.add("(order 2) overlap 4 float (order 2)");
72 
73  yn.add("(order 4) float128 overlap=2");
74  yn.add("(order 4) float128 overlap=4");
75 
76  yn.add("(order 6) float128 overlap=2");
77  yn.add("(order 6) float128 overlap=4");
78 
79  yn.add("(order 8) float128 overlap=2");
80  yn.add("(order 8) float128 overlap=4");
81 
82  // Every time increase the number of particles by 2
83  for (size_t i = 125 ; i <= 2097152000 ; i*=2)
84  {
85  x.add(i);
86  y.add();
87 
88  PSEError err;
89 
91 
92  PSE_test<boost::multiprecision::float128,Lap_PSE<1,boost::multiprecision::float128,2>>(i,2,err);
93  std::cout << "Particles: " << i << " error: " << err.linf_error << std::endl;
94  y.last().add(err.linf_error);
95 
96  PSE_test<boost::multiprecision::float128,Lap_PSE<1,boost::multiprecision::float128,2>>(i,4,err);
97  std::cout << "Particles: " << i << " error: " << err.linf_error << std::endl;
98  y.last().add(err.linf_error);
99 
100  PSE_test<double,Lap_PSE<1,double,2>>(i,2,err);
101  std::cout << "Particles: " << i << " error: " << err.linf_error << std::endl;
102  y.last().add(err.linf_error);
103 
104  PSE_test<double,Lap_PSE<1,double,2>>(i,4,err);
105  std::cout << "Particles: " << i << " error: " << err.linf_error << std::endl;
106  y.last().add(err.linf_error);
107 
108  PSE_test<float,Lap_PSE<1,float,2>>(i,2,err);
109  std::cout << "Particles: " << i << " error: " << err.linf_error << std::endl;
110  y.last().add(err.linf_error);
111 
112  PSE_test<float,Lap_PSE<1,float,2>>(i,4,err);
113  std::cout << "Particles: " << i << " error: " << err.linf_error << std::endl;
114  y.last().add(err.linf_error);
115 
117 
118  PSE_test<boost::multiprecision::float128,Lap_PSE<1,boost::multiprecision::float128,4>>(i,2,err);
119  std::cout << "Particles: " << i << " error: " << err.linf_error << std::endl;
120  y.last().add(err.linf_error);
121 
122  PSE_test<boost::multiprecision::float128,Lap_PSE<1,boost::multiprecision::float128,4>>(i,4,err);
123  std::cout << "Particles: " << i << " error: " << err.linf_error << std::endl;
124  y.last().add(err.linf_error);
125 
126 
128 
129  PSE_test<boost::multiprecision::float128,Lap_PSE<1,boost::multiprecision::float128,6>>(i,2,err);
130  std::cout << "Particles: " << i << " error: " << err.linf_error << std::endl;
131  y.last().add(err.linf_error);
132 
133  PSE_test<boost::multiprecision::float128,Lap_PSE<1,boost::multiprecision::float128,6>>(i,4,err);
134  std::cout << "Particles: " << i << " error: " << err.linf_error << std::endl;
135  y.last().add(err.linf_error);
136 
138 
139  PSE_test<boost::multiprecision::float128,Lap_PSE<1,boost::multiprecision::float128,8>>(i,8,err);
140  std::cout << "Particles: " << i << " error: " << err.linf_error << std::endl;
141  y.last().add(err.linf_error);
142 
143  PSE_test<boost::multiprecision::float128,Lap_PSE<1,boost::multiprecision::float128,8>>(i,16,err);
144  std::cout << "Particles: " << i << " error: " << err.linf_error << std::endl;
145  y.last().add(err.linf_error);
146  }
147 
148  // Google charts options
149  GCoptions options;
150 
151  options.title = std::string("PSE Laplacian convergence");
152  options.yAxis = std::string("Y Axis");
153  options.xAxis = std::string("X Axis");
154  options.more = std::string("hAxis:{logScale: true},vAxis:{logScale: true,format: 'scientific'}");
155  options.lineWidth = 1.0;
156 
157  GoogleChart cg;
158  cg.AddLinesGraph(x,y,yn,options);
159  cg.write("PSE_plot.html");
160 
161  //
162  // ### WIKI 8 ###
163  //
164  // Deinitialize the library
165  //
166  openfpm_finalize();
167 }
168 
169 #else
170 
171 int main()
172 {
173 
174 }
175 
176 #endif
void AddLinesGraph(openfpm::vector< X > &x, openfpm::vector< Y > &y, const GCoptions &opt)
Add a simple lines graph.
std::string title
Title of the chart.
Definition: GoogleChart.hpp:27
std::string more
more
Definition: GoogleChart.hpp:66
Implementation of VCluster class.
Definition: VCluster.hpp:36
std::string yAxis
Y axis name.
Definition: GoogleChart.hpp:29
Small class to produce graph with Google chart in HTML.
size_t lineWidth
Width of the line.
Definition: GoogleChart.hpp:55
void write(std::string file)
It write the graphs on file in html format using Google charts.
size_t getProcessingUnits()
Get the total number of processors.
std::string xAxis
X axis name.
Definition: GoogleChart.hpp:31
Google chart options.
Definition: GoogleChart.hpp:24