The FARGO_THORIN code developer's guide
 All Data Structures Files Functions Variables Typedefs Macros
Force.c
Go to the documentation of this file.
1 /**
2  * @file Force.c
3  *
4  * @brief Contains the function to evaluate and write the disk torques acting
5  * on planets and also the function to get the thickness smoothing parameter.
6  *
7  * @author Ondřej Chrenko <chrenko@sirrah.troja.mff.cuni.cz>
8  *
9  * @details The original ComputeForce() function was discarded, the torque computation
10  * follows from the formalism of the vertical averaging which directly
11  * provides the planet accelerations. The normalised torque is now part
12  * of the output. UpdateLog() is called from AdvanceSystemFromDisk() when needed.
13  *
14  * @section LICENSE
15  * Copyright (c) 2017 Ondřej Chrenko. See the LICENSE file of the
16  * distribution.
17  *
18  */
19 
20 #include "fargo.h"
21 
22 extern boolean OpenInner, NonReflecting;
23 
24 /** Calculates and writes the disk torques (both specific and normalized)
25  * acting on the planets. Uses the accelerations provided by the vertical
26  * averaging approach. */
27 void UpdateLog (Rho, psys) /* #THORIN */
28 PolarGrid *Rho;
29 PlanetarySystem *psys;
30 {
31  int i, nb, ii;
32  real x, y, r, m, ax, ay;
33  real *rho, *cs, rho1D[MAX1D], cs1D[MAX1D];
34  real r2, ifrac, frac, rhopl, cspl, omega, h, norm;
35  real tq, tq_norm;
36  FILE *out;
37  char filename[MAX1D];
38  nb = psys->nb;
39  rho = Rho->Field;
40  cs = SoundSpeed->Field;
41  mpi_make1Dprofile (rho, rho1D); /* #THORIN: needed for the torque normalisation */
42  mpi_make1Dprofile (cs, cs1D);
43  for (i = 0; i < nb; i++) {
44  x = psys->x[i];
45  y = psys->y[i];
46  ax = psys->ax[i];
47  ay = psys->ay[i];
48  m = psys->mass[i];
49  if (CPU_Rank == CPU_Number-1) {
50  r2 = x*x+y*y;
51  r = sqrt(r2);
52  ifrac = GetGlobalIFrac (r); /* get radial index w.respect to the global grid */
53  frac = ifrac-floor(ifrac);
54  ii = (int)ifrac;
55  rhopl = rho1D[ii]*(1.0-frac) + rho1D[ii+1]*frac;
56  cspl = cs1D[ii]*(1.0-frac) + cs1D[ii+1]*frac;
57  omega = pow(r, -1.5);
58  h = cspl/(omega*r)*SQRT_ADIABIND_INV;
59  norm = m*omega*r2/h;
60  norm *= norm;
61  norm *= rhopl;
62  tq = x*ay - y*ax;
63  tq_norm = tq*m*ADIABIND/norm;
64  sprintf (filename, "%stqwk%d.dat", OUTPUTDIR, i);
65  out = fopenp (filename, "a");
66  fprintf (out, "%#.18g\t%#.18g\t%#.18g\t%#.18g\t%#.18g\t%#.18g\t%#.18g\n", PhysicalTime,tq,tq_norm,x,y,ax,ay);
67  fclose (out);
68  }
69  }
70 }
71 
72 /** Computes the local thickness from the sound speed and applies
73  * the thickness smoothing parameter. */
74 /* 2DO add an option for the standard isothermal version!!! */
75 real ThicknessSmoothing (x,y) /* #THORIN */
76 real x,y;
77 {
78  real smlength=0.0, globsmlength, r, ang, H, csavrg;
79  int i, j, l, ns;
80  real *cs;
81  /* ----- */
82  cs = SoundSpeed->Field;
83  ns = SoundSpeed->Nsec;
84  smlength = 0.0; /* set the smoothing length 0 on all processes */
85  r = sqrt(x*x + y*y); /* midplane projection of the planet */
86  if (r >= Rinf[Zero_or_active] && r <= Rsup[Max_or_active-1]) { /* condition satisfied only for a CPU which contains the planet within its active zone */
87  ang = atan2(y,x); /* get the smoothing on this cpu */
88  if (ang < 0.0) ang += 2.0*PI;
89  i = Zero_or_active;
90  while (Rsup[i] < r) i++;
91  csavrg = 0.0;
92  for (j=0; j<ns; j++) {
93  l = j + i*ns;
94  csavrg += cs[l];
95  }
96  csavrg /= (real)ns;
97  H = csavrg*OmegaInv[i]*SQRT_ADIABIND_INV;
98  smlength = THICKNESSSMOOTHING*H;
99  }
100  MPI_Allreduce (&smlength, &globsmlength, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); /* other CPUs have smlength = 0.0, thus the correct number (>0) calculated above is distributed */
101  return globsmlength;
102 }
103 /* <--- */
double real
Definition of the type 'real' used throughout the code.
Definition: types.h:20
real Rsup[MAX1D]
Definition: global.h:11
int CPU_Number
Definition: global.h:2
boolean NonReflecting
Definition: Interpret.c:30
#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
PolarGrid * SoundSpeed
Definition: global.h:35
real ThicknessSmoothing(real x, real y)
Computes the local thickness from the sound speed and applies the thickness smoothing parameter...
Definition: Force.c:75
real * y
y-coordinate of the planets
Definition: types.h:100
int Zero_or_active
Definition: global.h:6
real OmegaInv[MAX1D]
Definition: global.h:15
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 * Field
Definition: types.h:40
real * mass
Masses of the planets.
Definition: types.h:98
Contains all the information about a planetary system at a given instant in time. ...
Definition: types.h:96
real SQRT_ADIABIND_INV
Definition: global.h:19
int nb
Number of planets.
Definition: types.h:97
real PhysicalTime
Definition: global.h:20
real THICKNESSSMOOTHING
Definition: param_noex.h:22
#define MPI_MAX
Definition: mpi_dummy.h:16
void MPI_Allreduce(void *ptr, void *ptr2, int count, int type, int foo3, int foo4)
Definition: mpi_dummy.c:72
real * ay
ay-coordinate of the planets' acceleration from the disk
Definition: types.h:106
int Max_or_active
Definition: global.h:7
boolean OpenInner
Definition: main.c:14
real ADIABIND
Definition: param_noex.h:54
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
real * ax
ax-coordinate of the planets' acceleration from the disk
Definition: types.h:105
real GetGlobalIFrac(real r)
Definition: LowTasks.c:21
void UpdateLog(PolarGrid *Rho, PlanetarySystem *psys)
Calculates and writes the disk torques (both specific and normalized) acting on the planets...
Definition: Force.c:27
int CPU_Rank
Definition: global.h:1
void mpi_make1Dprofile(real *gridfield, real *axifield)
Definition: mpiTasks.c:12
#define PI
Definition: fondam.h:12
#define MPI_COMM_WORLD
Definition: mpi_dummy.h:10
#define MAX1D
Definition: types.h:65