50 bool deactivate_on, log_on, verbose_on;
55 double rmax = cfg.
optional(
"rmax",std::numeric_limits<float>::max());
56 deactivate_on = cfg.
optional(
"deactivate_on_all_but_two_at_large_distance",
false);
57 log_on = cfg.
optional(
"log_on_all_but_two_at_large_distance",
false);
58 verbose_on = cfg.
optional(
"verbose_on_all_but_two_at_large_distance",
false)
74 bool need_full_test, condition_met;
76 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 int num_body_near_origin = 0, id1 = -1, id2 = -2;
111 for(
int b = 0 ; b < _sys.nbod(); b ++ ){
112 if(_sys.distance_to_origin_squared(b) <= _params.rmax*_params.rmax )
114 if(num_body_near_origin==0) id1 = b;
115 if(num_body_near_origin==1) id2 = b;
116 num_body_near_origin++;
119 if( num_body_near_origin <= 2 )
120 { need_full_test =
true; }
122 return need_full_test;
128 int new_state = _sys.state();
129 if(is_any_on() && need_full_test)
132 int num_body_far_from_all = 0;
133 for(
int b = 0 ; b < _sys.nbod(); b ++ )
135 if(_sys.distance_to_origin_squared(b) <= _params.rmax*_params.rmax )
continue;
136 bool is_far_from_every_body =
true;
137 for(
int bb = 0 ; bb < _sys.nbod(); bb ++ ){
138 if(b == bb)
continue;
139 if(_sys.distance_squared_between(b,bb) < _params.rmax*_params.rmax )
140 { is_far_from_every_body =
false;
break; }
142 if(is_far_from_every_body)
143 { num_body_far_from_all++; }
145 if(num_body_far_from_all+2>=_sys.nbod())
147 condition_met =
true;
149 lprintf(_log,
"No more than two bodies are within rmax of other bodies: _sys=%d, bod1=%d, bod2=%d, T=%lg r=%lg rmax=%lg.\n"
150 , _sys.number(), id1, id2, _sys.time() , r, _params.rmax);
151 if(is_deactivate_on() && (_sys.state()>=0) )
152 { _sys.set_disabled(); new_state = _sys.state(); }
169 GPUAPI
void operator () (
int thread_in_system) {
170 if(!is_any_on())
return;
172 if(thread_in_system==0)
175 int num_body_near_origin = 0, id1 = -1, id2 = -2;
176 for(
int b = 0 ; b < _sys.nbod(); b ++ ){
177 if(_sys.distance_to_origin_squared(b) <= _params.rmax*_params.rmax )
179 if(num_body_near_origin==0) id1 = b;
180 if(num_body_near_origin==1) id2 = b;
181 num_body_near_origin++;
184 if( num_body_near_origin > 2 )
188 int num_body_far_from_all = 0;
189 for(
int b = 0 ; b < _sys.nbod(); b ++ ){
190 if(_sys.distance_to_origin_squared(b) <= _params.rmax*_params.rmax )
continue;
191 bool is_far_from_every_body =
true;
192 for(
int bb = 0 ; bb < _sys.nbod(); bb ++ ){
193 if(b == bb)
continue;
194 if(_sys.distance_squared_between(b,bb) < _params.rmax*_params.rmax )
195 { is_far_from_every_body =
false;
break; }
197 if(is_far_from_every_body)
199 num_body_far_from_all++;
202 if(num_body_far_from_all+2>=_sys.nbod())
205 lprintf(_log,
"No more than two bodies are within rmax of other bodies: _sys=%d, bod1=%d, bod2=%d, T=%lg r=%lg rmax=%lg.\n"
206 , _sys.number(), id1, id2, _sys.time() , r, _params.rmax);
209 if(is_deactivate_on())
216 GPUAPI stop_on_all_but_two_at_large_distance(
const params& p,ensemble::SystemRef& s,log_t& l)
217 :_params(p),_sys(s),_log(l),_counter(0){}