Swarm-NG  1.1
euler.hpp
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 2011 by Saleh Dindar and the Swarm-NG Development Team *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 3 of the License. *
7  * *
8  * This program is distributed in the hope that it will be useful, *
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11  * GNU General Public License for more details. *
12  * *
13  * You should have received a copy of the GNU General Public License *
14  * along with this program; if not, write to the *
15  * Free Software Foundation, Inc., *
16  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
17  ************************************************************************/
18 
24 #include "swarm/swarmplugin.h"
25 
26 namespace swarm {
27 
28 namespace gpu {
29 namespace bppt {
30 
36  double time_step;
39  time_step = cfg.require("time_step", 0.0);
40  }
41 };
42 
50 template<class T,class Gravitation>
53  const static int nbod = T::n;
54 
55  params _params;
56 
57 
59  ensemble::SystemRef& sys;
60  Gravitation& calcForces;
61  int b;
62  int c;
63  int ij;
64  bool body_component_grid;
65  bool first_thread_in_system;
66  double max_timestep;
67 
69  GPUAPI EulerPropagator(const params& p,ensemble::SystemRef& s,
70  Gravitation& calc)
71  :_params(p),sys(s),calcForces(calc){}
72 
73  GPUAPI void init() { }
74 
75  GPUAPI void shutdown() { }
76 
77  GPUAPI void convert_internal_to_std_coord() {}
78  GPUAPI void convert_std_to_internal_coord() {}
79 
80  static GENERIC int thread_per_system(){
81  return nbod * 3;
82  }
83 
84  static GENERIC int shmem_per_system() {
85  return 0;
86  }
87 
88  __device__ bool is_in_body_component_grid()
89 // { return body_component_grid; }
90  { return ((b < nbod) && (c < 3)); }
91 
92  __device__ bool is_in_body_component_grid_no_star()
93 // { return ( body_component_grid && (b!=0) ); }
94  { return ( (b!=0) && (b < nbod) && (c < 3) ); }
95 
96  __device__ bool is_first_thread_in_system()
97 // { return first_thread_in_system; }
98  { return (thread_in_system()==0); }
99 
101  GPUAPI void advance(){
102  double h = min(_params.time_step, max_timestep);
103  double pos = 0.0, vel = 0.0;
104  double acc = 0.0, jerk = 0.0;
105  const double third = 1.0/3.0;
106 
107  if( is_in_body_component_grid() )
108  pos = sys[b][c].pos() , vel = sys[b][c].vel();
109 
110 
111  calcForces(ij,b,c,pos,vel,acc,jerk);
113  pos = pos + h*(vel+(h*0.5)*(acc+(h*third)*jerk));
114  vel = vel + h*(acc+(h*0.5)*jerk);
115 
116 
118  if( is_in_body_component_grid() )
119  sys[b][c].pos() = pos , sys[b][c].vel() = vel;
120  if( is_first_thread_in_system() )
121  sys.time() += h;
122  }
123 };
124 
125 }
126 }
127 }