The FARGO_THORIN code developer's guide
 All Data Structures Files Functions Variables Typedefs Macros
Planet.c
Go to the documentation of this file.
1 /** \file Planet.c
2 
3 Accretion of disk material onto the planets, and solver of planetary
4 orbital elements. The prescription used for the accretion is the one
5 designed by W. Kley.
6 
7 @author THORIN modifications by
8 Ondřej Chrenko <chrenko@sirrah.troja.mff.cuni.cz>, Copyright (C) 2017;
9 original code by Frédéric Masset
10 
11 */
12 
13 #include "fargo.h"
14 
15 void AccreteOntoPlanets (Rho, Vrad, Vtheta, dt, sys) /* 2DO has to be refined for 3D orbits !! */
16 real dt;
17 PolarGrid *Rho, *Vrad, *Vtheta;
18 PlanetarySystem *sys;
19 {
20  real RRoche, Rplanet, distance, dx, dy, deltaM, angle, temp;
21  int i_min,i_max, j_min, j_max, i, j, l, jf, ns, nr, lip, ljp, k;
22  real Xplanet, Yplanet, Mplanet, VXplanet, VYplanet;
23  real facc, facc1, facc2, frac1, frac2; /* We adopt the same notations as W. Kley */
24  real *dens, *abs, *ord, *vrad, *vtheta;
25  real PxPlanet, PyPlanet, vrcell, vtcell, vxcell, vycell, xc, yc;
26  real dPxPlanet, dPyPlanet, dMplanet;
27  nr = Rho->Nrad;
28  ns = Rho->Nsec;
29  dens = Rho->Field;
30  abs = CellAbscissa->Field;
31  ord = CellOrdinate->Field;
32  vrad = Vrad->Field;
33  vtheta = Vtheta->Field;
34  for (k=0; k < sys->nb; k++) {
35  if (sys->acc[k] > 1e-10) {
36  dMplanet = dPxPlanet = dPyPlanet = 0.0;
37  /* Hereafter : initialization of W. Kley's parameters */
38  facc = dt*(sys->acc[k]);
39  facc1 = 1.0/3.0*facc;
40  facc2 = 2.0/3.0*facc;
41  frac1 = 0.75;
42  frac2 = 0.45;
43  /* W. Kley's parameters initialization finished */
44  Xplanet = sys->x[k];
45  Yplanet = sys->y[k];
46  VXplanet = sys->vx[k];
47  VYplanet = sys->vy[k];
48  Mplanet = sys->mass[k];
49  Rplanet = sqrt(Xplanet*Xplanet+Yplanet*Yplanet);
50  RRoche = pow((1.0/3.0*Mplanet),(1.0/3.0))*Rplanet; /* Central mass is 1.0 */
51  i_min=0;
52  i_max=nr-1;
53  while ((Rsup[i_min] < Rplanet-RRoche) && (i_min < nr)) i_min++;
54  while ((Rinf[i_max] > Rplanet+RRoche) && (i_max > 0)) i_max--;
55  angle = atan2 (Yplanet, Xplanet);
56  j_min =(int)((real)ns/2.0/PI*(angle - 2.0*RRoche/Rplanet));
57  j_max =(int)((real)ns/2.0/PI*(angle + 2.0*RRoche/Rplanet));
58  PxPlanet = Mplanet*VXplanet;
59  PyPlanet = Mplanet*VYplanet;
60 /* #THORIN 'shared' & 'atomic' construct is now replaced with 'reduction' construct */
61 #pragma omp parallel for private(j,jf,vrcell,vtcell,vxcell,vycell,l,lip,ljp,xc,yc,dx,dy,distance,deltaM) reduction(+ : dPxPlanet, dPyPlanet, dMplanet)
62  for (i = i_min; i <= i_max; i++) {
63  for (j = j_min; j <= j_max; j++) {
64  jf = j;
65  while (jf < 0) jf += ns;
66  while (jf >= ns) jf -= ns;
67  l = jf+i*ns;
68  lip = l+ns;
69  ljp = l+1;
70  if (jf == ns-1) ljp = i*ns;
71  xc = abs[l];
72  yc = ord[l];
73  dx = Xplanet-xc;
74  dy = Yplanet-yc;
75  distance = sqrt(dx*dx+dy*dy);
76  vtcell=0.5*(vtheta[l]+vtheta[ljp])+Rmed[i]*OmegaFrame;
77  vrcell=0.5*(vrad[l]+vrad[lip]);
78  vxcell=(vrcell*xc-vtcell*yc)/Rmed[i];
79  vycell=(vrcell*yc+vtcell*xc)/Rmed[i];
80  if (distance < frac1*RRoche) {
81  deltaM = facc1*dens[l]*Surf[i];
82  if (i < Zero_or_active) deltaM = 0.0;
83  if (i >= Max_or_active) deltaM = 0.0;
84  dens[l] *= (1.0 - facc1);
85  dPxPlanet += deltaM*vxcell; /* #THORIN 'atomic' directives used to be here */
86  dPyPlanet += deltaM*vycell;
87  dMplanet += deltaM;
88  }
89  if (distance < frac2*RRoche) {
90  deltaM = facc2*dens[l]*Surf[i];
91  if (i < Zero_or_active) deltaM = 0.0;
92  if (i >= Max_or_active) deltaM = 0.0;
93  dens[l] *= (1.0 - facc2);
94  dPxPlanet += deltaM*vxcell;
95  dPyPlanet += deltaM*vycell;
96  dMplanet += deltaM;
97  }
98  }
99  }
100  MPI_Allreduce (&dMplanet, &temp, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
101  dMplanet = temp;
102  MPI_Allreduce (&dPxPlanet, &temp, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
103  dPxPlanet = temp;
104  MPI_Allreduce (&dPyPlanet, &temp, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
105  dPyPlanet = temp;
106  PxPlanet += dPxPlanet;
107  PyPlanet += dPyPlanet;
108  Mplanet += dMplanet;
109  if (sys->FeelDisk[k] == YES) {
110  sys->vx[k] = PxPlanet/Mplanet;
111  sys->vy[k] = PyPlanet/Mplanet;
112  }
113  sys->mass[k] = Mplanet;
114  }
115  }
116 }
117 
118 
119 void FindOrbitalElements (x,y,vx,vy,m,n)
120 real x,y,vx,vy,m;
121 int n;
122 {
123  real Ax, Ay, e, d, h, a, E, M, V;
124  real PerihelionPA;
125  FILE *output;
126  char name[256];
127  if (CPU_Rank != CPU_Number-1) return;
128  sprintf (name, "%sorbit%d.dat", OUTPUTDIR, n);
129  output = fopenp (name, "a");
130  h = x*vy-y*vx;
131  d = sqrt(x*x+y*y);
132  Ax = x*vy*vy-y*vx*vy-G*m*x/d;
133  Ay = y*vx*vx-x*vx*vy-G*m*y/d;
134  e = sqrt(Ax*Ax+Ay*Ay)/G/m;
135  a = h*h/G/m/(1-e*e);
136  if (e != 0.0) {
137  E = acos((1.0-d/a)/e);
138  } else {
139  E = 0.0;
140  }
141  if ((x*y*(vy*vy-vx*vx)+vx*vy*(x*x-y*y)) < 0) E= -E;
142  M = E-e*sin(E);
143  if (e != 0.0) {
144  V = acos ((a*(1.0-e*e)/d-1.0)/e);
145  } else {
146  V = 0.0;
147  }
148  if (E < 0.0) V = -V;
149  if (e != 0.0) {
150  PerihelionPA=atan2(Ay,Ax);
151  } else {
152  PerihelionPA=atan2(y,x);
153  }
154  fprintf (output, "%.12g\t%.12g\t%.12g\t%.12g\t%.12g\t%.12g\n", PhysicalTime, e, a, M, V,\
155  PerihelionPA);
156  fclose (output);
157 }
158 
double real
Definition of the type 'real' used throughout the code.
Definition: types.h:20
void FindOrbitalElements(real x, real y, real vx, real vy, real m, int n)
Definition: Planet.c:119
real Rsup[MAX1D]
Definition: global.h:11
int CPU_Number
Definition: global.h:2
#define YES
Definition: types.h:46
boolean * FeelDisk
For each planet tells if it feels the disk (ie migrates)
Definition: types.h:110
#define MPI_DOUBLE
Definition: mpi_dummy.h:11
char OUTPUTDIR[512]
Definition: param_noex.h:11
real * x
x-coordinate of the planets
Definition: types.h:99
real * y
y-coordinate of the planets
Definition: types.h:100
int Zero_or_active
Definition: global.h:6
A structure used to store any scalar fied on the computational domain.
Definition: types.h:37
FILE * fopenp(char *string, char *mode)
Definition: LowTasks.c:163
real * vx
x-coordinate of the planets'velocities
Definition: types.h:102
real * Field
Definition: types.h:40
static real VXplanet
Definition: Output.c:17
real * mass
Masses of the planets.
Definition: types.h:98
int Nrad
Radial size of the grid, in number of zones.
Definition: types.h:38
real Rmed[MAX1D]
Definition: global.h:11
Contains all the information about a planetary system at a given instant in time. ...
Definition: types.h:96
PolarGrid * CellOrdinate
Definition: global.h:33
int nb
Number of planets.
Definition: types.h:97
static real a[7]
Definition: EnergySources.c:27
real PhysicalTime
Definition: global.h:20
static real Yplanet
Definition: Output.c:17
void AccreteOntoPlanets(PolarGrid *Rho, PolarGrid *Vrad, PolarGrid *Vtheta, real dt, PlanetarySystem *sys)
Definition: Planet.c:15
#define G
Definition: fondam.h:11
real * acc
The planets' accretion times^-1.
Definition: types.h:108
real OmegaFrame
Definition: global.h:20
void MPI_Allreduce(void *ptr, void *ptr2, int count, int type, int foo3, int foo4)
Definition: mpi_dummy.c:72
#define MPI_SUM
Definition: mpi_dummy.h:17
real * vy
y-coordinate of the planets'velocities
Definition: types.h:103
int Max_or_active
Definition: global.h:7
PolarGrid * CellAbscissa
Definition: global.h:33
real Surf[MAX1D]
Definition: global.h:11
static real VYplanet
Definition: Output.c:17
Contains all the include directives requested by the code.
real Rinf[MAX1D]
Definition: global.h:11
int Nsec
Azimuthal size of the grid, in number of zones.
Definition: types.h:39
int CPU_Rank
Definition: global.h:1
static real Xplanet
Definition: Output.c:17
#define PI
Definition: fondam.h:12
#define MPI_COMM_WORLD
Definition: mpi_dummy.h:10