Swarm-NG  1.1
parabolic_collision.cpp
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 2011 by Saleh Dindar and the Swarm-NG Development Team *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 3 of the License. *
7  * *
8  * This program is distributed in the hope t`hat it will be useful, *
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11  * GNU General Public License for more details. *
12  * *
13  * You should have received a copy of the GNU General Public License *
14  * along with this program; if not, write to the *
15  * Free Software Foundation, Inc., *
16  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
17  ************************************************************************/
18 
36 #include "swarm/swarm.h"
37 #include <iostream>
38 using namespace swarm;
39 using namespace std;
40 
41 const int nbod = 3;
42 const int nsys = 64;
43 
44 const double mass_planet = 0.0001;
45 
48 const double xpos[4] = { -2.0, +2.0, -4.0, +4.0 };
49 
50 
52 const double mu = 1;
53 
56 const double R = 1;
57 
58 double norm(double x,double y){
59  return sqrt(x*x+y*y);
60 }
61 
62 
63 
64 int main(int argc, char* argv[]){
65  if(argc <= 1){
66  cout << "Usage: parabolic_collision <outputfilename>" << endl;
67  }
68  const string outputfn = argv[1];
69  init(config());
71 
72  for(int i = 0; i < nsys ; i++){
73  ensemble::SystemRef s = ens[i];
74  s.id() = 0;
75  s.time() = 0;
76  s.set_active();
77 
78  // Stationary star at origin
79  s[0].mass() = 1;
80  s[0][0].pos() = 0, s[0][1].pos() = 0, s[0][2].pos() = 0 ;
81  s[0][0].vel() = 0, s[0][1].vel() = 0, s[0][2].vel() = 0 ;
82 
83 
84  // Planets on the parabola
85  for(int b = 1; b < nbod; b++){
86  s[b].mass() = mass_planet;
87 
88  double x = xpos[b-1], y = x*x/4/R - R ;
89  double vmag = sqrt(2*mu/norm(x,y)) ;
90  double vdirx = (x/abs(x))/norm(1,x/2/R), vdiry = abs(x)/2/R / norm(1,x/2/R);
91 
92 
93  s[b][0].pos() = x , s[b][0].vel() = -vmag*vdirx ;
94  s[b][1].pos() = y , s[b][1].vel() = -vmag*vdiry ;
95  s[b][2].pos() = 0 , s[b][2].vel() = 0 ;
96  }
97 
98 
99  }
100  snapshot::save_text(ens,outputfn);
101 }