43 template<
typename _value_type,
int _N,
int _CHUNK_SIZE>
45 typedef _value_type value_type;
46 const static int N = _N;
47 const static int CHUNK_SIZE = _CHUNK_SIZE;
50 GENERIC value_type getitem(
const size_t& i)
const{
53 GENERIC void setitem(
const size_t& i,
const value_type& v){
57 GENERIC const value_type& operator[](
const size_t& i)
const{
60 GENERIC value_type& operator[](
const size_t& i){
65 value_type _array[N][CHUNK_SIZE];
109 template<
int _CHUNK_SIZE,
int _NUM_BODY_ATTRIBUTES = NUM_PLANET_ATTRIBUTES,
int _NUM_SYS_ATTRIBUTES = NUM_SYSTEM_ATTRIBUTES >
138 GENERIC double& pos() {
return _pos[0]; }
140 GENERIC double& vel() {
return _vel[0]; }
142 GENERIC const double& pos()
const {
return _pos[0]; }
144 GENERIC const double& vel()
const {
return _vel[0]; }
168 GENERIC Component& getitem(
const int& i){
172 GENERIC const double& x()
const {
return component[0].pos(); }
173 GENERIC double& x() {
return component[0].pos(); }
174 GENERIC const double& y()
const {
return component[1].pos(); }
175 GENERIC double& y() {
return component[1].pos(); }
176 GENERIC const double& z()
const {
return component[2].pos(); }
177 GENERIC double& z() {
return component[2].pos(); }
179 GENERIC const double& vx()
const {
return component[0].vel(); }
180 GENERIC double& vx() {
return component[0].vel(); }
181 GENERIC const double& vy()
const {
return component[1].vel(); }
182 GENERIC double& vy() {
return component[1].vel(); }
183 GENERIC const double& vz()
const {
return component[2].vel(); }
184 GENERIC double& vz() {
return component[2].vel(); }
188 GENERIC const double&
attribute(
const int& i)
const {
return _attributes[i]; }
193 return square(
operator[](0).pos())
194 +
square(
operator[](1).pos())
195 +
square(
operator[](2).pos());
200 return square(
operator[](0).vel())
201 +
square(
operator[](1).vel())
202 +
square(
operator[](2).vel());
209 GENERIC void get(
double& x,
double & y,
double & z
210 ,
double & vx,
double & vy,
double & vz) {
242 GENERIC const double&
time()
const {
return _time[0]; }
246 GENERIC const int&
state()
const {
return _bunch[0].state; }
250 GENERIC const int&
id()
const {
return _bunch[0].id; }
272 SYSTEM_NEEDS_EXAM = 2,
365 const Body& b1 = _body[i], & b2 = _body[j];
366 return square(b1[0].pos()-b2[0].pos())
367 +
square(b1[1].pos()-b2[1].pos())
368 +
square(b1[2].pos()-b2[2].pos());
377 for(
int i = 0; i < _nbod; i++){
378 s[i][0].pos() = _body[i][0].pos();
379 s[i][1].pos() = _body[i][1].pos();
380 s[i][2].pos() = _body[i][2].pos();
381 s[i][0].vel() = _body[i][0].vel();
382 s[i][1].vel() = _body[i][1].vel();
383 s[i][2].vel() = _body[i][2].vel();
384 s[i].mass() = _body[i].
mass();
397 GENERIC double total_energy()
const{
403 double K = 0.0, U = 0.0;
405 for(
int i = 0; i < _nbod; i++)
408 for(
int i = 0; i < _nbod; i++)
409 for(
int j = 0; j < i; j++)
427 GENERIC const Body& operator[](
const int & i )
const {
return _ref[i]; }
428 GENERIC const double& time() {
return _ref.
time(); }
430 GENERIC const double& time()
const {
return _ref.
time(); }
431 GENERIC bool is_active()
const {
return _ref.
state() == Sys::SYSTEM_ACTIVE; }
434 GENERIC const int& state()
const {
return _ref.
state(); }
435 GENERIC const int& id()
const {
return _ref.
id(); }
436 GENERIC const double& attribute(
const int& i)
const {
return _sys[0].attribute(i); }
439 GENERIC const int& nbod()
const{
return _ref.
nbod(); }
484 typedef struct SystemRef value_type;
485 typedef int key_type;
486 typedef int difference_type;
487 typedef int size_type;
519 GENERIC SystemRef getitem(
const int& i){
524 return SystemRefConst( const_cast<EnsembleBase*>(
this)->
operator[](i) ) ;
529 GENERIC double& mass(
const int& sys,
const int & bod){
533 GENERIC double& p(
const int& sys,
const int & bod,
const int&
c){
537 GENERIC double& v(
const int& sys,
const int & bod,
const int& c){
541 GENERIC double&
x(
const int& sys,
const int& bod ) {
return p(sys,bod,0); }
542 GENERIC double& y(
const int& sys,
const int& bod ) {
return p(sys,bod,1); }
543 GENERIC double& z(
const int& sys,
const int& bod ) {
return p(sys,bod,2); }
545 GENERIC double& vx(
const int& sys,
const int& bod ) {
return v(sys,bod,0); }
546 GENERIC double& vy(
const int& sys,
const int& bod ) {
return v(sys,bod,1); }
547 GENERIC double& vz(
const int& sys,
const int& bod ) {
return v(sys,bod,2); }
549 GENERIC double& time(
const int & sys ) {
553 GENERIC int& state(
const int& sys){
557 GENERIC int& flags(
const int& sys){
563 GENERIC const double& mass(
const int& sys,
const int & bod)
const{
567 GENERIC const double& p(
const int& sys,
const int & bod,
const int& c)
const{
571 GENERIC const double& v(
const int& sys,
const int & bod,
const int& c)
const{
575 GENERIC const double&
x(
const int& sys,
const int& bod )
const {
return p(sys,bod,0); }
576 GENERIC const double& y(
const int& sys,
const int& bod )
const {
return p(sys,bod,1); }
577 GENERIC const double& z(
const int& sys,
const int& bod )
const {
return p(sys,bod,2); }
579 GENERIC const double& vx(
const int& sys,
const int& bod )
const {
return v(sys,bod,0); }
580 GENERIC const double& vy(
const int& sys,
const int& bod )
const {
return v(sys,bod,1); }
581 GENERIC const double& vz(
const int& sys,
const int& bod )
const {
return v(sys,bod,2); }
583 GENERIC const double& time(
const int & sys )
const {
587 GENERIC const int& state(
const int& sys)
const{
591 GENERIC const int& flags(
const int& sys)
const{
595 GENERIC void set_time(
const int& sys,
const double& time ) {
600 GENERIC bool is_active(
const int& sys)
const {
603 GENERIC bool is_inactive(
const int& sys)
const {
606 GENERIC bool is_disabled(
const int& sys)
const {
609 GENERIC bool is_enabled(
const int& sys)
const {
612 GENERIC void set_active(
const int& sys) {
615 GENERIC void set_inactive(
const int& sys) {
618 GENERIC void set_disabled(
const int& sys) {
623 GENERIC void set_body(
const int& sys,
const int& bod,
const double& mass_planet
624 ,
const double&
x,
const double & y,
const double& z
625 ,
const double& vx,
const double& vy,
const double& vz) {
627 s[bod][0].pos() =
x ;
628 s[bod][1].pos() = y ;
629 s[bod][2].pos() = z ;
631 s[bod][0].vel() = vx ;
632 s[bod][1].vel() = vy ;
633 s[bod][2].vel() = vz ;
635 s[bod].mass() = mass_planet;
639 GENERIC void get_body(
const int & sys,
const int & bod,
double & m
640 ,
double& x,
double & y,
double& z
641 ,
double& vx,
double& vy,
double& vz)
const {
648 vx = s[bod][0].vel();
649 vy = s[bod][1].vel();
650 vz = s[bod][2].vel();
665 GENERIC void get_barycenter(
const int& sys,
double& x,
double& y,
double& z,
double& vx,
double& vy,
double& vz,
const int& max_body_id = MAX_NBODIES)
const
668 x = 0.; y = 0.; z = 0.; vx = 0.; vy = 0.; vz = 0.;
669 double mass_sum = 0.;
670 const int stop_at_body = std::min(
nbod()-1,max_body_id);
671 for(
int bod=0;bod<=stop_at_body;++bod)
673 double m = mass(sys,bod);
674 x += m* this->
x(sys,bod);
675 y += m* this->y(sys,bod);
676 z += m* this->z(sys,bod);
677 vx += m* this->vx(sys,bod);
678 vy += m* this->vy(sys,bod);
679 vz += m* this->vz(sys,bod);
694 return s.calc_total_energy();
700 for (
int sys = 0; sys !=
nsys(); sys++)
706 double average, min, max,median;
707 range_t(
const double& a,
const double& m,
const double& M,
const double& d)
708 :average(a),min(m),max(M),median(d){}
712 template<
class RandomAccessIterator>
714 size_t n = end - begin;
718 for(RandomAccessIterator i = begin+1; i != end; i++) {
720 if( v < min ) min = v;
721 if( v > max ) max = v;
724 std::nth_element(begin,end, begin+n/2);
725 return range_t(sum/n,min,max,*(begin+n/2));
733 std::vector<double> times(
nsys());
734 for(
int i= 0; i <
nsys(); i++)
735 times[i] =
operator[](i).time();