30 namespace swarm {
namespace monitors {
42 bool deactivate_on, log_on, verbose_on;
47 dmin = cfg.
optional(
"close_approach",0.0);
48 deactivate_on = cfg.
optional(
"deactivate_on_close_encounter",
false);
49 log_on = cfg.
optional(
"log_on_close_encounter",
false);
50 verbose_on = cfg.
optional(
"verbose_on_close_encounter",
false);
71 bool need_full_test, condition_met;
72 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) {
88 GPUAPI
bool is_deactivate_on() {
return _params.deactivate_on; };
89 GPUAPI
bool is_log_on() {
return _params.log_on; };
90 GPUAPI
bool is_verbose_on() {
return _params.verbose_on; };
91 GPUAPI
bool is_any_on() {
return is_deactivate_on() || is_log_on() || is_verbose_on() ; }
92 GPUAPI
bool is_condition_met () {
return ( condition_met ); }
93 GPUAPI
bool need_to_log_system ()
94 {
return (is_log_on() && is_condition_met() ); }
95 GPUAPI
bool need_to_deactivate ()
96 {
return ( is_deactivate_on() && is_condition_met() ); }
98 GPUAPI
void log_system() {
log::system(_log, _sys); }
103 need_full_test =
false;
104 condition_met =
false;
105 if(is_any_on()&&(thread_in_system==0))
108 for(
int b = 2; b < _sys.nbod(); b++)
109 for(
int d = 1; d < b; d++)
110 condition_met = condition_met || check_close_encounters(b,d);
111 if( condition_met && is_log_on() )
112 { need_full_test =
true; }
115 return need_full_test;
121 if (need_to_deactivate() && (thread_in_system==0) )
122 { _sys.set_disabled(); }
127 GPUAPI
bool check_close_encounters(
const int& i,
const int& j){
129 double d = _sys.distance_between(i,j);
130 double _GM = _sys[0].mass();
133 double a = 0.5*(_sys[i].distance_to_origin()+_sys[i].distance_to_origin());
134 double rH3 = (_sys[i].mass()+_sys[j].mass())/(3.*_GM)*a*a*a;
135 bool close_encounter = d*d*d < _params.dmin*_params.dmin*_params.dmin * rH3;
137 if( close_encounter )
139 lprintf(_log,
"Close apporach detected: "
140 "sys=%d, T=%f j=%d i=%d d=%lg.\n"
141 , _sys.number(), _sys.time(), j, i,d);
143 return close_encounter;
150 if(need_to_log_system() && (thread_in_system==0) )
156 GPUAPI
void operator () (
int thread_in_system)
158 if(!is_any_on())
return;
161 if(thread_in_system==0)
164 for(
int b = 2; b < _sys.nbod(); b++)
165 for(
int d = 1; d < b; d++)
166 stopit = stopit || check_close_encounters(b,d);
171 if(is_deactivate_on())
178 GPUAPI stop_on_close_encounter(
const params& p,ensemble::SystemRef& s,log_t& l)
179 :_params(p),_sys(s),_log(l){}