/** * This procedure was copied from the other Monte Carlo simulation code * * I had to change all the floats to double because in the new swarm we * use double for masses. Also, our ensemble classes now use reference * counted pointers and we create them in a functional way than old * fill-this-for-me-please pointers(references). The generate name * makes more sense that the set_initial_conditions. I only added * one line for generating the ensemble. In the other monte carlo, * the ensemble is generated first and then passed to this function * to fill it in. * * */ defaultEnsemble generate_ensemble_with_randomized_initial_conditions(const config& cfg) { defaultEnsemble ens = defaultEnsemble::create( cfg.require("nbod",0), cfg.require("nsys",0) ); std::cerr << "# nsystems = " << ens.nsys() << " nbodies/system = " << ens.nbod() << "\n"; // std::cerr << "# Set initial time for all systems = "; double time_init = cfg.optional("time_init", 0.0); // std::cerr << time_init << ".\n"; const bool use_jacobi = cfg.optional("use_jacobi", 0); bool keplerian_ephemeris = cfg.optional("use_keplerian", 1); bool transit_ephemeris = cfg.optional("use_transit", 0); if(transit_ephemeris) keplerian_ephemeris = 0; assert(!(keplerian_ephemeris && transit_ephemeris)); // find a better way for(unsigned int sys=0;sys<ens.nsys();++sys) { generate_initial_conditions_for_system(cfg,ens,sys,sys); } // end loop over systems return ens; }
until_time_end_params(const config &cfg) { time_end = cfg.require("time_end", 0.0); }
/** * Read in Keplerian coordinates from a text file * */ defaultEnsemble generate_ensemble_with_initial_conditions_keplerian_from_file(const config& cfg) { defaultEnsemble ens = defaultEnsemble::create( cfg.require("nbod",0), cfg.require("nsys",0) ); std::cerr << "# nsystems = " << ens.nsys() << " nbodies/system = " << ens.nbod() << "\n"; // std::cerr << "# Set initial time for all systems = "; double time_init = cfg.optional("time_init", 0.0); // std::cerr << time_init << ".\n"; const bool use_jacobi = cfg.optional("use_jacobi", 0); // std::cerr << "# Writing stable system ids\n"; ifstream jacobi_input( cfg.optional("input_mcmc_keplerian", string("mcmc.out")).c_str() ); for(unsigned int sysid=0;sysid<ens.nsys();++sysid) { assert(jacobi_input.good()); string id; double mass_star; jacobi_input >> id >> mass_star; ens[sysid].id() = sysid; ens[sysid].time() = time_init; ens[sysid].set_active(); double x=0, y=0, z=0, vx=0, vy=0, vz=0; ens.set_body(sysid, 0, mass_star, x, y, z, vx, vy, vz); double mass_enclosed = mass_star; for(unsigned int bod=1;bod<ens.nbod();++bod) { double mass_planet, a, e, i, O, w, M; jacobi_input >> mass_planet >> a >> e >> i >> w >> O >> M; // a = pow((period/365.25)*(period/365.25)*mass_enclosed,1.0/3.0); i *= M_PI/180.; O *= M_PI/180.; w *= M_PI/180.; M *= M_PI/180.; mass_enclosed += mass_planet; double mass = use_jacobi ? mass_enclosed : mass_star+mass_planet; if(cfg.count("verbose")&&(sysid<10)) std::cout << "# Drawing sysid= " << sysid << " bod= " << bod << ' ' << mass_planet << " " << a << ' ' << e << ' ' << i*180./M_PI << ' ' << O*180./M_PI << ' ' << w*180./M_PI << ' ' << M*180./M_PI << '\n'; calc_cartesian_for_ellipse(x,y,z,vx,vy,vz, a, e, i, O, w, M, mass); // printf("%d %d: %lg (%lg %lg %lg) (%lg %lg %lg) \n", sysid, bod, mass_planet, x,y,z,vx,vy,vz); if(use_jacobi) { double bx, by, bz, bvx, bvy, bvz; ens.get_barycenter(sysid,bx,by,bz,bvx,bvy,bvz,bod-1); x += bx; y += by; z += bz; vx += bvx; vy += bvy; vz += bvz; } // assign body a mass, position and velocity ens.set_body(sysid, bod, mass_planet, x, y, z, vx, vy, vz); if(cfg.count("verbose")&&(sysid<10)) { double x_t = ens.x(sysid,bod); double y_t = ens.y(sysid,bod); double z_t = ens.z(sysid,bod); double vx_t = ens.vx(sysid,bod); double vy_t = ens.vy(sysid,bod); double vz_t = ens.vz(sysid,bod); std::cout << " x= " << x << "=" << x_t << " "; std::cout << " y= " << y << "=" << y_t << " "; std::cout << " z= " << z << "=" << z_t << " "; std::cout << "vx= " << vx << "=" << vx_t << " "; std::cout << "vy= " << vy << "=" << vy_t << " "; std::cout << "vz= " << vz << "=" << vz_t << "\n"; } } // end loop over bodies // Shift into barycentric frame ens.get_barycenter(sysid,x,y,z,vx,vy,vz); for(unsigned int bod=0;bod<ens.nbod();++bod) { ens.set_body(sysid, bod, ens.mass(sysid,bod), ens.x(sysid,bod)-x, ens.y(sysid,bod)-y, ens.z(sysid,bod)-z, ens.vx(sysid,bod)-vx, ens.vy(sysid,bod)-vy, ens.vz(sysid,bod)-vz); } // end loop over bodies } // end loop over systems return ens; }
/** * Read in Cartesian coordinates from a text file * */ defaultEnsemble generate_ensemble_with_initial_conditions_cartesian_from_file(const config& cfg) { defaultEnsemble ens = defaultEnsemble::create( cfg.require("nbod",0), cfg.require("nsys",0) ); std::cerr << "# nsystems = " << ens.nsys() << " nbodies/system = " << ens.nbod() << "\n"; // std::cerr << "# Set initial time for all systems = "; double time_init = cfg.optional("time_init", 0.0); // std::cerr << time_init << ".\n"; const bool use_jacobi = cfg.optional("use_jacobi", 0); // std::cerr << "# Writing stable system ids\n"; ifstream mcmc_input( cfg.optional("input_mcmc_cartesian", string("mcmc.out")).c_str() ); assert(mcmc_input.good()); const int lines_to_skip = cfg.optional("lines_to_skip", 0); for(int i=0;i<lines_to_skip;++i) { assert(mcmc_input.good()); char junk[1024]; mcmc_input.getline(junk,1024); } for(unsigned int sysid=0;sysid<ens.nsys();++sysid) { assert(mcmc_input.good()); #if 1 std::vector<double> masses(ens.nbod(),0.0); for(unsigned int bod=0;bod<ens.nbod();++bod) { mcmc_input >> masses[bod]; } // end loop over bodies ens[sysid].id() = sysid; ens[sysid].time() = time_init; ens[sysid].set_active(); double x=0, y=0, z=0, vx=0, vy=0, vz=0; ens.set_body(sysid, 0, masses[0], x, y, z, vx, vy, vz); double mass_enclosed = masses[0]; for(unsigned int bod=1;bod<ens.nbod();++bod) { mcmc_input >> x >> y >> z >> vx >> vy >> vz; mass_enclosed += masses[bod]; double mass = use_jacobi ? mass_enclosed : masses[0]+masses[bod]; if(cfg.count("verbose")&&(sysid<10)) std::cout << "# Drawing sysid= " << sysid << " bod= " << bod << ' ' << masses[bod] << " " << x << ' ' << y << ' ' << z << ' ' << vx << ' ' << vy << ' ' << vz << '\n'; if(use_jacobi) { double bx, by, bz, bvx, bvy, bvz; ens.get_barycenter(sysid,bx,by,bz,bvx,bvy,bvz,bod-1); x += bx; y += by; z += bz; vx += bvx; vy += bvy; vz += bvz; } // assign body a mass, position and velocity ens.set_body(sysid, bod, masses[bod], x, y, z, vx, vy, vz); if(cfg.count("verbose")&&(sysid<10)) { double x_t = ens.x(sysid,bod); double y_t = ens.y(sysid,bod); double z_t = ens.z(sysid,bod); double vx_t = ens.vx(sysid,bod); double vy_t = ens.vy(sysid,bod); double vz_t = ens.vz(sysid,bod); std::cout << " x= " << x << "=" << x_t << " "; std::cout << " y= " << y << "=" << y_t << " "; std::cout << " z= " << z << "=" << z_t << " "; std::cout << "vx= " << vx << "=" << vx_t << " "; std::cout << "vy= " << vy << "=" << vy_t << " "; std::cout << "vz= " << vz << "=" << vz_t << "\n"; } #else std::vector<double> masses(ens.nbod(),0.0); double x=0, y=0, z=0, vx=0, vy=0, vz=0; double mass_enclosed = 0.0; ens[sysid].id() = sysid; ens[sysid].time() = time_init; ens[sysid].set_active(); for(unsigned int bod=0;bod<ens.nbod();++bod) { mcmc_input >> masses[bod]; mcmc_input >> x >> y >> z >> vx >> vy >> vz; mass_enclosed += masses[bod]; double mass = use_jacobi ? mass_enclosed : masses[0]+masses[bod]; if(cfg.count("verbose")&&(sysid<10)) std::cout << "# Drawing sysid= " << sysid << " bod= " << bod << ' ' << masses[bod] << " " << x << ' ' << y << ' ' << z << ' ' << vx << ' ' << vy << ' ' << vz << '\n'; if(use_jacobi) { double bx, by, bz, bvx, bvy, bvz; ens.get_barycenter(sysid,bx,by,bz,bvx,bvy,bvz,bod-1); x += bx; y += by; z += bz; vx += bvx; vy += bvy; vz += bvz; } // assign body a mass, position and velocity ens.set_body(sysid, bod, masses[bod], x, y, z, vx, vy, vz); if(cfg.count("verbose")&&(sysid<10)) { double x_t = ens.x(sysid,bod); double y_t = ens.y(sysid,bod); double z_t = ens.z(sysid,bod); double vx_t = ens.vx(sysid,bod); double vy_t = ens.vy(sysid,bod); double vz_t = ens.vz(sysid,bod); std::cout << " x= " << x << "=" << x_t << " "; std::cout << " y= " << y << "=" << y_t << " "; std::cout << " z= " << z << "=" << z_t << " "; std::cout << "vx= " << vx << "=" << vx_t << " "; std::cout << "vy= " << vy << "=" << vy_t << " "; std::cout << "vz= " << vz << "=" << vz_t << "\n"; } #endif } // end loop over bodies // Shift into barycentric frame ens.get_barycenter(sysid,x,y,z,vx,vy,vz); for(unsigned int bod=0;bod<ens.nbod();++bod) { ens.set_body(sysid, bod, ens.mass(sysid,bod), ens.x(sysid,bod)-x, ens.y(sysid,bod)-y, ens.z(sysid,bod)-z, ens.vx(sysid,bod)-vx, ens.vy(sysid,bod)-vy, ens.vz(sysid,bod)-vz); } // end loop over bodies } // end loop over systems return ens; } void print_system(const swarm::ensemble& ens, const int systemid, std::ostream &os = std::cout) { enum { JACOBI, BARYCENTRIC, ASTROCENTRIC } COORDINATE_SYSTEM = BARYCENTRIC; const bool use_jacobi = cfg.optional("use_jacobi_output", 0); if(use_jacobi) COORDINATE_SYSTEM = JACOBI; std::streamsize cout_precision_old = os.precision(); os.precision(10); os << "sys_idx= " << systemid << " sys_id= " << ens[systemid].id() << " time= " << ens.time(systemid) << "\n"; double star_mass = ens.mass(systemid,0); double mass_effective = star_mass; double bx, by, bz, bvx, bvy, bvz; switch(COORDINATE_SYSTEM) { case JACOBI: ens.get_barycenter(systemid,bx,by,bz,bvx,bvy,bvz,0); break; case BARYCENTRIC: ens.get_barycenter(systemid,bx,by,bz,bvx,bvy,bvz); break; case ASTROCENTRIC: ens.get_body(systemid,0,star_mass,bx,by,bz,bvx,bvy,bvz); break; } for(unsigned int bod=1;bod<ens.nbod();++bod) // Skip star since printing orbits { // std::cout << "pos= (" << ens.x(systemid, bod) << ", " << ens.y(systemid, bod) << ", " << ens.z(systemid, bod) << ") vel= (" << ens.vx(systemid, bod) << ", " << ens.vy(systemid, bod) << ", " << ens.vz(systemid, bod) << ").\n"; double mass = ens.mass(systemid,bod); switch(COORDINATE_SYSTEM) { case JACOBI: ens.get_barycenter(systemid,bx,by,bz,bvx,bvy,bvz,bod-1); mass_effective += mass; break; case BARYCENTRIC: mass_effective = star_mass + mass; break; case ASTROCENTRIC: mass_effective = star_mass + mass; break; } double x = ens.x(systemid,bod)-bx; double y = ens.y(systemid,bod)-by; double z = ens.z(systemid,bod)-bz; double vx = ens.vx(systemid,bod)-bvx; double vy = ens.vy(systemid,bod)-bvy; double vz = ens.vz(systemid,bod)-bvz; double a, e, i, O, w, M; calc_keplerian_for_cartesian(a,e,i,O,w,M, x,y,z,vx,vy,vz, mass_effective); i *= 180/M_PI; O *= 180/M_PI; w *= 180/M_PI; M *= 180/M_PI; // os << " b= " << bod << " m= " << mass << " a= " << a << " e= " << e << " i= " << i << " Omega= " << O << " omega= " << w << " M= " << M << "\n"; os << ens[systemid].id() << " " << bod << " " << mass << " " << a << " " << e << " " << i << " " << O << " " << w << " " << M << "\n"; } os.precision(cout_precision_old); os << std::flush; } void print_selected_systems(swarm::ensemble& ens, std::vector<unsigned int> systemindices, std::ostream &os = std::cout) { for(unsigned int i=0; i<systemindices.size(); ++i) print_system(ens,systemindices[i], os); } void print_selected_systems_for_demo(swarm::ensemble& ens, unsigned int nprint, std::ostream &os = std::cout) { if(nprint>ens.nsys()) nprint = ens.nsys(); for(unsigned int systemid = 0; systemid< nprint; ++systemid) print_system(ens,systemid,os); } void write_stable_systems(defaultEnsemble &ens, defaultEnsemble &ens_init) { // find the stable ones and output the initial conditions for the stable // ones in keplerian coordinates // std::cerr << "# Finding stable system ids\n"; std::vector<unsigned int> stable_system_indices, unstable_system_indices; for(int i = 0; i < ens.nsys() ; i++ ) { if(ens[i].is_disabled()) unstable_system_indices.push_back(i); else stable_system_indices.push_back(i); } // std::cerr << "# Writing stable system ids\n"; if(cfg.count("stable_init_output")) { ofstream stable_init_output( cfg.optional("stable_init_output", string("stable_init_output.txt")).c_str() ); print_selected_systems(ens_init,stable_system_indices, stable_init_output); } if(cfg.count("stable_final_output")) { ofstream stable_final_output( cfg.optional("stable_final_output", string("stable_final_output.txt")).c_str() ); print_selected_systems(ens,stable_system_indices, stable_final_output); } if(cfg.count("unstable_init_output")) { ofstream unstable_init_output( cfg.optional("unstable_init_output", string("unstable_init_output.txt")).c_str() ); print_selected_systems(ens_init,unstable_system_indices, unstable_init_output); } if(cfg.count("unstable_final_output")) { ofstream unstable_final_output( cfg.optional("unstable_final_output", string("unstable_final_output.txt")).c_str() ); print_selected_systems(ens,unstable_system_indices, unstable_final_output); } }
mvs_cpu(const config& cfg): base(cfg),_time_step(0.001), _mon_params(cfg) { _time_step = cfg.require("time_step", 0.0); }
//! Constructor for MVSPropagatorParams MVSPropagatorParams(const config& cfg){ time_step = cfg.require("time_step", 0.0); }