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;
38 verletList_type& verletList
41 verletList(verletList)
44 void operator()(
const state_type_2d_ofp_gpu &X , state_type_2d_ofp_gpu &dxdt ,
const double t )
const
50 auto C = getV<0>(Particles);
59 dxdt.data.get<0>() = d1*
Lap(C[x]) - C[x] * C[y] * C[y] +
F -
F * C[x];
60 dxdt.data.get<1>() = d2*
Lap(C[y]) + C[x] * C[y] * C[y] - (
F+K) * C[y];
67 template<
typename dist_vector_type_ker>
73 dist_vector_type_ker &vectorDistKer;
77 : vectorDistKer(vectorDistKer)
91 auto C = getV<0>(Particles);
94 auto &v_cl=create_vcluster();
97 std::cout<<
"Time: "<<t<<
", "<<
"dt: "<<t-t_old<<std::endl;
100 Particles.write_frame(
"PDE_sol",ctr,t);
112 template <
typename stepper_type,
typename laplacian_type,
typename verletList_type>
113 void run_stepper_const(
dist_vector_type &Particles, std::vector<double> &runtime_v, laplacian_type &
Lap, verletList_type& verletList) {
115 auto vectorDistKer = vd.toKernel();
118 auto C = getV<0>(Particles);
119 auto InitC = getV<1>(Particles);
122 x0.data.get<x>() = InitC[x];
123 x0.data.get<y>() = InitC[y];
126 timer timer_integrate;
127 timer_integrate.
start();
128 boost::numeric::odeint::integrate_const(stepper_type(), System, x0, 0.0, tf, dt, ObserveAndUpdate);
130 timer_integrate.
stop();
131 double rt=timer_integrate.
getwct();
132 auto &v_cl=create_vcluster();
136 runtime_v.push_back(rt);
137 C[x]=x0.data.get<x>();
138 C[y]=x0.data.get<y>();
139 if(v_cl.rank()==0)std::cout <<
"Runtime: " << rt << std::endl;
170 double average(std::vector<double> &nums) {
171 return std::accumulate(nums.begin(), nums.end(), 0.0) /
static_cast<double>(nums.size());
175 int main(
int argc,
char *argv[])
178 openfpm_init(&argc, &argv);
179 tf=std::atof(argv[2]);
181 std::vector<double> runtime_rk4_const;
182 std::vector<double> runtime_rk5_const;
183 std::vector<double> runtime_rk78_const;
184 std::vector<double> runtime_rk5_adapt;
185 size_t gdsz=std::atof(argv[1]);
187 size_t sz[3] = {gdsz,gdsz,gdsz};
189 size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};
191 spacing[0] = 2.5 / (sz[0]);
192 spacing[1] = 2.5 / (sz[1]);
193 spacing[2] = 2.5 / (sz[2]);
194 double rCut = 2.9 * spacing[0];
201 while (it.isNext()) {
204 double x = 0.0 + key.get(0) * spacing[0];
206 double y = 0.0 + key.get(1) * spacing[1];
208 double z = 0.0 + key.get(2) * spacing[2];
211 Particles.template getLastProp<1>()[0] = 1.0;
212 Particles.template getLastProp<1>()[1] = 0.0;
214 if (x > 1.55 && x < 1.85 && y > 1.55 && y < 1.85 && z > 1.55 && z < 1.85) {
215 Particles.template getLastProp<1>()[0] = 0.5 + (((double)std::rand())/RAND_MAX -0.5)/10.0;
216 Particles.template getLastProp<1>()[1] = 0.25 + (((double)std::rand())/RAND_MAX -0.5)/20.0;
229 PointerDistGlobal = (
void *) &Particles;
230 auto verletList = Particles.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
233 Laplacian<decltype(verletList)>
Lap(Particles, verletList, 2, rCut, support_options::RADIUS);
234 auto C = getV<0>(Particles);
235 auto Init = getV<1>(Particles);
239 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;
240 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;
241 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;
243 RHSFunctor<Laplacian<decltype(verletList)>, decltype(verletList)> System(
Lap, verletList);
252 X.data.get<x>() = C[0];
253 X.data.get<y>() = C[1];
256 std::vector<double> inter_times;
258 Particles.write(
"Initial");
261 run_stepper_const<Odeint_rk4>(Particles, runtime_rk4_const,
Lap, verletList);
285 auto & vcl = create_vcluster();
287 if (vcl.getProcessUnitID() == 0) {
289 std::ofstream output_runtime;
292 std::string headline =
"cores,rk4,dopri5,fehlberg78,dopri5 adaptive";
293 if (access(
"runtime.csv", F_OK) == -1) {
294 output_runtime.open(
"runtime.csv");
295 output_runtime << headline <<
"\n";
297 output_runtime.open(
"runtime.csv", std::ios::app);
300 output_runtime << vcl.getProcessingUnits()
301 <<
"," << average(runtime_rk4_const)
302 <<
"," << average(runtime_rk5_const)
303 <<
"," << average(runtime_rk78_const)
304 <<
"," << average(runtime_rk5_adapt)
309 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 stop()
Stop the timer.
void start()
Start the timer.
double getwct()
Return the elapsed real time.
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 deviceToHostProp()
Move the memory from the device to host memory.
void add()
Add local particle.
void hostToDeviceProp()
Move the memory from the device to host memory.
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.