/nemo_cvs/src/orbit/potential/data/tidaldisk.c

https://github.com/Milkyway-at-home/nemo · C · 158 lines · 68 code · 6 blank · 84 comment · 17 complexity · 4621209bd6bc26c6c43ff0b989ba92d7 MD5 · raw file

  1. /*******************************************************************************
  2. * *
  3. * tidaldisk.c *
  4. * *
  5. * copyright by Walter Dehnen 2001 *
  6. * *
  7. *******************************************************************************/
  8. /*CTEX
  9. *
  10. * Tidal field exerted by a (plane-parallel) stellar disk on a cluster passing
  11. * through with constant vertical velocity.
  12. * Useful for simulations of disk-shocking of, say, globular clusters
  13. *
  14. * The following three density models are available
  15. *
  16. * 1. thin disk:
  17. *
  18. * $$
  19. * \rho(z) = \Sigma * \delta(z)
  20. * $$
  21. *
  22. * 2. exponential disk:
  23. *
  24. * $$
  25. * \rho(z) = {\Sigma \over {2h}} \exp{ { -|z|} \over h}
  26. * $$
  27. *
  28. * 3. sech$^2$ disk:
  29. *
  30. * $$
  31. * \rho(z) = {\Sigma \over {4h}} sech^2{ { z \over {2h}}}
  32. * $$
  33. *
  34. * Parameters (to be given by potpars=...) are:
  35. * \begin{verbatim}
  36. * par[0] = not used (reserved for pattern speed in NEMO)
  37. * par[1] = h scale-height
  38. * . par[1] = 0 -> thin disk
  39. * . par[1] > 0 -> vertically exponential disk
  40. * . par[1] < 0 -> sech$^2$ disk with h=|par[1]|
  41. * par[2] = Sig disk surface density
  42. * par[3] = Vz constant vertical velocity of cluster center
  43. * par[4] = Z0 cluster center z-position at t=0
  44. * par[5] = add boolean: add tidal potential or not?
  45. * \end{verbatim}
  46. *
  47. * We always assume G=1.
  48. *
  49. * If you want to include the acceleration of the disk on the cluster as a
  50. * whole, rather than assume a constant velocity, use {\bf vertdisk}
  51. *
  52. * Some words on the mechanics
  53. *
  54. * Assume that the plane-parallel disk potential and force are given by
  55. * $$
  56. * \Phi(Z)
  57. * $$
  58. * and
  59. * $$
  60. * F(Z) = -\Phi'(Z).
  61. * $$
  62. * Then, the tidal force exerted on a star at position z w.r.t. to cluster
  63. * center, which in turn is at absolute height Zc = Z0 + t Vz, is simply
  64. * $$
  65. * F_t(z) = F(Zc+z) - F(Zc).
  66. * $$
  67. * Integrating this from z=0 to z gives the associated tidal potential as
  68. * $$
  69. * \Phi_t(z) = \Phi(Zc+z) - \Phi(Zc) + z * F(Zc).
  70. * $$
  71. * Whenever the tidal force \& potential are desired at a new time t, we
  72. * pre-compute $Zc$ and the plane-parallel potential and force at $Z=Zc$.
  73. * Note that when both $Zc$ and $Zc+z$ are outside of the mass of the disk (and
  74. * $Z=0$
  75. * is not between them), both tidal force and potential vanish identically.
  76. * The standard treatment of tidal forces corresponds to approximating (2) by
  77. * $F(Zc) + z * F'(Zc)$. This method, however, breaks down for disks that are
  78. * thin compared to the cluster, while our method is always valid, even for a
  79. * razor thin disk.
  80. */
  81. #include "vertdisk.h"
  82. local double Vz = 1.0; /* vertical v of cluster center */
  83. local double Z0 = 0.0; /* height of cluster center at t=0*/
  84. local bool add = 1; /* add tidal potential */
  85. local double tnow,Znow,Anow,Pnow; /* auxiliary variables */
  86. /*----------------------------------------------------------------------------*/
  87. void ini_potential(int *npar, double *par, string name)
  88. {
  89. DISKPOTENTIAL_VARS /* vertdisk.h: aux vars */
  90. int n = *npar;
  91. if(n>0) omega = par[0];
  92. ini_vertdisk(n-1,par+1);
  93. if(n<2) warning("tidaldisk: h defaulting to %f",h);
  94. if(n<3) warning("tidaldisk: Sig defaulting to %f",Sig);
  95. if(n>3) Vz = par[3];
  96. else warning("tidaldisk: Vz defaulting to %f",Vz);
  97. if(n>4) Z0 = par[4];
  98. else warning("tidaldisk: Z0 defaulting to %f",Z0);
  99. if(n>5) add= par[5] > 0.;
  100. if(n>6) warning("tidaldisk: npar=%d only 5 parameters accepted",n);
  101. dprintf(1," inipotential: tidaldisk\n");
  102. dprintf(1," parameters: h, Sig, Vz, Z0, add= %f %f %f %f %d\n",h,Sig,Vz,Z0,add);
  103. par[0] = omega;
  104. tnow = 0.0; /* current time */
  105. Znow = Z0+Vz*tnow; /* current z_c */
  106. DISKPOTENTIAL_FUNC(Znow,Anow,Pnow); /* current acc_c & pot_c */
  107. }
  108. /*----------------------------------------------------------------------------*/
  109. void potential_double(int *ndim, /* I: # dims, ignored */
  110. double*pos, /* I: (x,y,z) */
  111. double*acc, /* O: (ax,ay,az) */
  112. double*pot, /* O: potential */
  113. double*time) /* I: time */
  114. {
  115. DISKPOTENTIAL_VARS /* vertdisk.h: aux vars */
  116. register double Z; /* position w.r.t. disk */
  117. acc[0] = 0.0; /* no force in x and */
  118. acc[1] = 0.0; /* no force in y */
  119. if(*time != tnow) { /* IF(new time) > */
  120. tnow =*time; /* current time */
  121. Znow = Z0+Vz*tnow; /* current z_c */
  122. DISKPOTENTIAL_FUNC(Znow,Anow,Pnow) /* current acc_c & pot_c*/
  123. } /* < */
  124. Z=Znow+pos[2]; /* position w.r.t. disk*/
  125. DISKPOTENTIAL_FUNC(Z,acc[2],*pot); /* force & pot w.r.t. disk*/
  126. if(add) *pot+= pos[2]*Anow - Pnow; /* pot w.r.t. center */
  127. else *pot = 0.0; /* pot not given */
  128. acc[2] -= Anow; /* force w.r.t. center */
  129. }
  130. /*----------------------------------------------------------------------------*/
  131. void potential_float(int *ndim, /* I: # dims, ignored */
  132. float*pos, /* I: (x,y,z) */
  133. float*acc, /* O: (ax,ay,az) */
  134. float*pot, /* O: potential */
  135. float*time) /* I: time */
  136. {
  137. DISKPOTENTIAL_VARS /* vertdisk.h: aux vars */
  138. register double Z; /* position w.r.t. disk */
  139. acc[0] = 0.0; /* no force in x and */
  140. acc[1] = 0.0; /* no force in y */
  141. if(*time != tnow) { /* IF(new time) > */
  142. tnow =*time; /* current time */
  143. Znow = Z0+Vz*tnow; /* current z_c */
  144. DISKPOTENTIAL_FUNC(Znow,Anow,Pnow) /* current acc_c & pot_c*/
  145. } /* < */
  146. Z=Znow+pos[2]; /* position w.r.t. disk*/
  147. DISKPOTENTIAL_FUNC(Z,acc[2],*pot); /* force & pot w.r.t. disk*/
  148. if(add) *pot+= pos[2]*Anow - Pnow; /* pot w.r.t. center */
  149. else *pot = 0.0; /* pot not given */
  150. acc[2] -= Anow; /* force w.r.t. center */
  151. }
  152. /*----------------------------------------------------------------------------*/