30 namespace swarm {
namespace monitors {
42 bool deactivate_on, log_on, verbose_on;
48 dmin_squared = cfg.
optional(
"collision_distance_to_origin",0.);
49 dmin_squared *= dmin_squared;
51 deactivate_on = cfg.
optional(
"deactivate_on_collision",
false);
52 log_on = cfg.
optional(
"log_on_collision",
false);
53 verbose_on = cfg.
optional(
"verbose_on_collision",
false);
73 bool need_full_test, condition_met;
74 ensemble::SystemRef& _sys;
82 static GENERIC int thread_per_system(T compile_time_param){
87 static GENERIC int shmem_per_system(T compile_time_param) {
90 GPUAPI
bool is_deactivate_on() {
return _params.deactivate_on; };
91 GPUAPI
bool is_log_on() {
return _params.log_on; };
92 GPUAPI
bool is_verbose_on() {
return _params.verbose_on; };
93 GPUAPI
bool is_any_on() {
return is_deactivate_on() || is_log_on() || is_verbose_on() ; }
94 GPUAPI
bool is_condition_met () {
return ( condition_met ); }
95 GPUAPI
bool need_to_log_system ()
96 {
return (is_log_on() && is_condition_met() ); }
97 GPUAPI
bool need_to_deactivate ()
98 {
return ( is_deactivate_on() && is_condition_met() ); }
100 GPUAPI
void log_system() {
log::system(_log, _sys); }
105 need_full_test =
false;
106 condition_met =
false;
107 if(is_any_on()&&(thread_in_system==0))
110 for(
int b = 1; b < _sys.nbod(); b++)
111 for(
int d = 0; d < b; d++)
113 if(condition_met && is_log_on() )
114 { need_full_test =
true; }
117 return need_full_test;
124 { _sys.set_disabled(); }
129 #if 0 // still under development
130 GPUAPI
bool check_close_encounter_possible(
const int& i,
const int& j,
double dt){
133 double target_distance_to_origin_sq = (NUM_ATTRIBUTES>=1) ? attribute(i)*attribute(i) : _params.dmin_squared;
134 double vesc_sq = 2.0*_sys.mass(0)/std::min(_sys.distance_to_origin(i),_sys.distance_to_origin(j));
135 double d_squared = _sys.distance_squared_between(i,j);
136 bool close_encounter = (d_squared < vesc_sq*dt*dt + target_distance_to_origin_sq);
137 return close_encounter;
141 #if 0 // still under development
142 GPUAPI
double min_encounter_distance(
const int& i,
const int& j){
143 const Body& b1 = _body[i], & b2 = _body[j];
144 double d = sqrt(
square(b1[0].pos()-b2[0].pos())
145 +
square(b1[1].pos()-b2[1].pos())
146 +
square(b1[2].pos()-b2[2].pos()) );
154 double d_squared = _sys.distance_squared_between(i,j);
155 double target_distance_to_origin_sq = (NUM_ATTRIBUTES>=1) ? attribute(i)*attribute(i) : _params.dmin_squared;
156 bool close_encounter = d_squared < target_distance_to_origin_sq;
158 if( close_encounter )
160 lprintf(_log,
"Collision detected: "
161 "sys=%d, T=%f j=%d i=%d d=%lg.\n"
162 , _sys.number(), _sys.time(), j, i,sqrt(d_squared));
163 return close_encounter;
178 GPUAPI
void operator () (
int thread_in_system)
179 if(!is_any_on())
return;
182 if(thread_in_system==0)
186 for(
int b = 1; b < _sys.nbod(); b++)
187 for(
int d = 0; d < b; d++)
193 if(is_deactivate_on())
202 :_params(p),_sys(s),_log(l),_counter(0){}