32 namespace swarm {
namespace monitors {
43 bool deactivate_on, log_on, verbose_on;
48 deactivate_on = cfg.
optional(
"deactivate_on_crossing",
false);
49 log_on = cfg.
optional(
"log_on_crossing",
false);
50 verbose_on = cfg.
optional(
"verbose_on_crossing",
false);
54 GPUAPI
double sqr(
const double& d){
73 ensemble::SystemRef& _sys;
79 static GENERIC int thread_per_system(T compile_time_param){
84 static GENERIC int shmem_per_system(T compile_time_param) {
87 GPUAPI
bool is_deactivate_on() {
return _params.deactivate_on; };
88 GPUAPI
bool is_log_on() {
return _params.log_on; };
89 GPUAPI
bool is_verbose_on() {
return _params.verbose_on; };
90 GPUAPI
bool is_any_on() {
return is_deactivate_on() || is_log_on() || is_verbose_on() ; }
91 GPUAPI
bool is_condition_met () {
return ( condition_met ); }
92 GPUAPI
bool need_to_log_system ()
93 {
return (is_log_on() && is_condition_met() ); }
94 GPUAPI
bool need_to_deactivate ()
95 {
return ( is_deactivate_on() && is_condition_met() ); }
97 GPUAPI
void log_system() {
log::system(_log, _sys); }
104 GPUAPI
void calc_a_e(
const int& b,
double& a,
double& e) {
105 double x,y,z,vx,vy,vz; _sys[b].get(x,y,z,vx,vy,vz);
107 double h2 = sqr(y*vz-z*vy) + sqr(z*vx-x*vz) + sqr(x*vy-y*vx);
108 double _GM = _sys[b].mass();
109 double r = _sys[b].distance_to_origin(), sp = _sys[b].speed();
110 double energy = sp*0.5-_GM/r;
113 double fac = 1.-h2/(_GM*a);
114 e = (fac>1.e-8) ? sqrtf(fac) : 0.;
126 double a_i, e_i, a_j, e_j;
130 bool is_orbits_crossing;
132 is_orbits_crossing = a_i * (1. + e_i) > a_j * ( 1. - e_j ) ;
134 is_orbits_crossing = a_i * (1. + e_i) < a_j * ( 1. - e_j ) ;
136 if( is_orbits_crossing && is_verbose_on())
137 lprintf(_log,
"Crossing orbits detected: "
138 "sys=%d, T=%lg i=%d j=%d a_i=%lg e_i=%lg a_j=%lg e_j=%lg.\n"
139 , _sys.number(), _sys.time(),i,j, a_i,e_i, a_j, e_j);
141 return is_orbits_crossing;
147 if(!is_any_on())
return;
149 if(thread_in_system==0)
151 condition_met =
false;
153 for(
int j = 2; j < _sys.nbod(); j++)
154 for(
int i = 1; i < j; i++)
160 if(is_deactivate_on())
167 GPUAPI
void operator () (
int thread_in_system)
169 pass_one(thread_in_system);
170 pass_two(thread_in_system);
171 if(need_to_log_system() && (thread_in_system==0) )
176 GPUAPI
bool pass_one (
int thread_in_system)
178 condition_met =
false;
183 GPUAPI
int pass_two (
int thread_in_system)
185 if(is_any_on() && (thread_in_system==0) )
188 for(
int j = 2; j < _sys.nbod(); j++)
189 for(
int i = 1; i < j; i++)
192 if(condition_met && is_deactivate_on() )
193 { _sys.set_disabled(); }
200 GPUAPI stop_on_crossing_orbit(
const params& p,ensemble::SystemRef& s,log_t& l)
201 :_params(p),_sys(s),_log(l){}