3 #include "Operators/Vector/vector_dist_operators.hpp"
4 #include "DCPSE/DCPSE_op/DCPSE_op.hpp"
5 #include "OdeIntegrators/OdeIntegrators.hpp"
12 double dt=1.0,tf=5000.0;
14 void *PointerDistGlobal;
20 template<
typename laplacian_type,
typename verletList_type>
26 verletList_type &verletList;
36 RHSFunctor(laplacian_type &
Lap, verletList_type& verletList) :
Lap(
Lap), verletList(verletList)
45 auto C = getV<0>(Particles);
54 dxdt.data.get<0>() = d1*
Lap(C[x]) - C[x] * C[y] * C[y] +
F -
F * C[x];
55 dxdt.data.get<1>() = d2*
Lap(C[y]) + C[x] * C[y] * C[y] - (
F+K) * C[y];
78 auto C = getV<0>(Particles);
81 auto &v_cl=create_vcluster();
84 std::cout<<
"Time: "<<t<<
", "<<
"dt: "<<t-t_old<<std::endl;
87 Particles.write_frame(
"PDE_sol",ctr,t);
97 template <
typename stepper_type,
typename laplacian_type,
typename verletList_type>
98 void run_stepper_const(
dist_vector_type &Particles, std::vector<double> &runtime_v, laplacian_type &
Lap, verletList_type& verletList) {
102 auto C = getV<0>(Particles);
103 auto InitC = getV<1>(Particles);
106 x0.data.get<x>() = InitC[x];
107 x0.data.get<y>() = InitC[y];
109 timer timer_integrate;
110 timer_integrate.
start();
111 boost::numeric::odeint::integrate_const(stepper_type(), System, x0, 0.0, tf, dt, ObserveAndUpdate);
113 timer_integrate.stop();
114 double rt=timer_integrate.getwct();
115 auto &v_cl=create_vcluster();
119 runtime_v.push_back(rt);
120 C[x]=x0.data.get<x>();
121 C[y]=x0.data.get<y>();
122 if(v_cl.rank()==0)std::cout <<
"Runtime: " << rt << std::endl;
125 template <
typename stepper_type,
typename laplacian_type,
typename verletList_type>
126 void run_stepper_adaptive(
dist_vector_type &Particles, std::vector<double> &runtime_v, laplacian_type &
Lap, verletList_type& verletList) {
130 auto C = getV<0>(Particles);
131 auto InitC = getV<1>(Particles);
134 x0.data.get<x>() = InitC[x];
135 x0.data.get<y>() = InitC[y];
137 timer timer_integrate;
138 timer_integrate.
start();
139 boost::numeric::odeint::integrate_adaptive(boost::numeric::odeint::make_controlled(1e-3,1e-3,stepper_type()), System , x0 , 0.0 , tf , dt, ObserveAndUpdate);
141 timer_integrate.stop();
142 double rt=timer_integrate.getwct();
143 auto &v_cl=create_vcluster();
146 runtime_v.push_back(rt);
148 C[x]=x0.data.get<x>();
149 C[y]=x0.data.get<y>();
150 if(v_cl.rank()==0)std::cout <<
"Runtime: " << rt << std::endl;
153 double average(std::vector<double> &nums) {
154 return std::accumulate(nums.begin(), nums.end(), 0.0) /
static_cast<double>(nums.size());
158 int main(
int argc,
char *argv[])
161 openfpm_init(&argc, &argv);
162 tf=std::atof(argv[2]);
164 std::vector<double> runtime_rk4_const;
165 std::vector<double> runtime_rk5_const;
166 std::vector<double> runtime_rk78_const;
167 std::vector<double> runtime_rk5_adapt;
168 size_t gdsz=std::atof(argv[1]);
170 size_t sz[3] = {gdsz,gdsz,gdsz};
172 size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};
174 spacing[0] = 2.5 / (sz[0]);
175 spacing[1] = 2.5 / (sz[1]);
176 spacing[2] = 2.5 / (sz[2]);
177 double rCut = 2.9 * spacing[0];
184 while (it.isNext()) {
187 double x = 0.0 + key.get(0) * spacing[0];
189 double y = 0.0 + key.get(1) * spacing[1];
191 double z = 0.0 + key.get(2) * spacing[2];
194 Particles.template getLastProp<1>()[0] = 1.0;
195 Particles.template getLastProp<1>()[1] = 0.0;
197 if (x > 1.55 && x < 1.85 && y > 1.55 && y < 1.85 && z > 1.55 && z < 1.85) {
198 Particles.template getLastProp<1>()[0] = 0.5 + (((double)std::rand())/RAND_MAX -0.5)/10.0;
199 Particles.template getLastProp<1>()[1] = 0.25 + (((double)std::rand())/RAND_MAX -0.5)/20.0;
212 PointerDistGlobal = (
void *) &Particles;
213 auto verletList = Particles.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
216 Laplacian<decltype(verletList)>
Lap(Particles, verletList, 2, rCut, support_options::RADIUS);
217 auto C = getV<0>(Particles);
218 auto Init = getV<1>(Particles);
222 typedef boost::numeric::odeint::runge_kutta4<state_type_2d_ofp, double, state_type_2d_ofp, double, boost::numeric::odeint::vector_space_algebra_ofp> Odeint_rk4;
223 typedef boost::numeric::odeint::runge_kutta_cash_karp54< state_type_2d_ofp,double,state_type_2d_ofp,double,boost::numeric::odeint::vector_space_algebra_ofp> Odeint_rk5;
224 typedef boost::numeric::odeint::runge_kutta_fehlberg78< state_type_2d_ofp,double,state_type_2d_ofp,double,boost::numeric::odeint::vector_space_algebra_ofp> Odeint_rk8;
226 RHSFunctor<Laplacian<decltype(verletList)>, decltype(verletList)> System(
Lap, verletList);
235 X.data.get<x>() = C[0];
236 X.data.get<y>() = C[1];
239 std::vector<double> inter_times;
241 Particles.write(
"Initial");
256 run_stepper_adaptive<Odeint_rk5>(Particles, runtime_rk5_adapt,
Lap,verletList);
258 Particles.write(
"AdapRK5");
268 auto & vcl = create_vcluster();
270 if (vcl.getProcessUnitID() == 0) {
272 std::ofstream output_runtime;
275 std::string headline =
"cores,rk4,dopri5,fehlberg78,dopri5 adaptive";
276 if (access(
"runtime.csv", F_OK) == -1) {
277 output_runtime.open(
"runtime.csv");
278 output_runtime << headline <<
"\n";
280 output_runtime.open(
"runtime.csv", std::ios::app);
283 output_runtime << vcl.getProcessingUnits()
284 <<
"," << average(runtime_rk4_const)
285 <<
"," << average(runtime_rk5_const)
286 <<
"," << average(runtime_rk78_const)
287 <<
"," << average(runtime_rk5_adapt)
292 Lap.deallocate(Particles);
This class represent an N-dimensional box.
Laplacian second order on h (spacing)
This class implement the point shape in an N-dimensional space.
Class for cpu time benchmarking.
void start()
Start the timer.
void setPropNames(const openfpm::vector< std::string > &names)
Set the properties names.
grid_dist_id_iterator_dec< Decomposition > getGridIterator(const size_t(&sz)[dim])
void ghost_get(size_t opt=WITH_POSITION)
It synchronize the properties and position of the ghost particles.
void map(size_t opt=NONE)
It move all the particles that does not belong to the local processor to the respective processor.
void add()
Add local particle.
void deleteGhost()
Delete the particles on the ghost.
auto getLastPos() -> decltype(vPos.template get< 0 >(0))
Get the position of the last element.
[v_transform metafunction]
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
A 2d Odeint and Openfpm compatible structure.