5 #include "Vector/vector_dist.hpp"
8 #include "Operators/Vector/vector_dist_operators.hpp"
9 #include "Vector/vector_dist_subset.hpp"
10 #include "Decomposition/Distribution/SpaceDistribution.hpp"
11 #include "OdeIntegrators/OdeIntegrators.hpp"
26 dxdt = x * (1- (1/(1+exp(-t))) );
29 int main(
int argc,
char* argv[])
35 openfpm_init(&argc,&argv);
36 auto &v_cl=create_vcluster();
42 std::ofstream output_file;
43 output_file.open(
"rk4_error_results.csv",std::ios_base::app);
45 size_t edgeSemiSize = std::stof(argv[1]);
46 const size_t sz[2] = {edgeSemiSize,edgeSemiSize };
48 size_t bc[2] = { NON_PERIODIC, NON_PERIODIC };
50 spacing[0] = 1.0 / (sz[0] - 1);
51 spacing[1] = 1.0 / (sz[1] - 1);
52 double rCut = 3.9 * spacing[0];
58 double init_dt = 0.01;
63 auto it = Particles.getGridIterator(sz);
67 mem_id k0 = key.get(0);
68 double xp0 = k0 * spacing[0];
69 Particles.getLastPos()[0] = xp0;
70 mem_id k1 = key.get(1);
71 double yp0 = k1 * spacing[1];
72 Particles.getLastPos()[1] = yp0;
77 Particles.getLastProp<0>() = xp0 * yp0 * exp(t);
78 Particles.getLastProp<1>() = xp0 * yp0 * exp(tf);
82 auto Init = getV<0>(Particles);
83 auto Sol = getV<1>(Particles);
84 auto OdeSol = getV<2>(Particles);
100 timer timer_integrate;
101 timer_integrate.
start();
108 derivative = &Exponential2;
110 while (t < tf - dt) {
116 derivative(x0, k1, t);
118 derivative(x0 + 0.5 * dt * k1, k2, t + 0.5 * dt);
120 derivative(x0 + 0.5 * dt * k2, k3, t + 0.5 * dt);
122 derivative(x0 + dt * k3, k4, t + dt);
124 x0 = x0 + dt / 6.0 * (k1 + 2 * k2 + 2 * k3 + k4);
130 timer_integrate.
stop();
134 double norm_inf = 0.0;
135 double norm_l2 = 0.0;
137 auto it2 = Particles.getDomainIterator();
138 while (it2.isNext()) {
141 double diff = Particles.getProp<1>(p) - Particles.getProp<2>(p);
143 if (fabs(diff) > norm_inf) {
144 norm_inf = fabs(diff);
147 norm_l2 += diff * diff;
151 norm_l2 = sqrt(norm_l2);
153 auto & vcl = create_vcluster();
154 if (vcl.getProcessUnitID() == 0)
156 std::cout <<
"Steps: " << steps << std::endl;
157 std::cout <<
"Time: " << timer_integrate.
getwct() << std::endl;
158 std::cout <<
"Norm inf: " << norm_inf << std::endl;
159 std::cout <<
"Norm L2: " << norm_l2 << std::endl;
161 double tt=timer_integrate.
getwct();
166 {output_file << steps <<
","<<v_cl.size()<<
"," << tt/v_cl.size() <<
"," << norm_inf <<
"," << norm_l2 <<
"\n";}
This class represent an N-dimensional box.
Class for cpu time benchmarking.
void stop()
Stop the timer.
void start()
Start the timer.
double getwct()
Return the elapsed real time.
Main class that encapsulate a vector properties operand to be used for expressions construction.