cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gravity.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2022 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 #include "cddefines.h"
4 #include "gravity.h"
5 #include "dense.h"
6 #include "pressure.h"
7 #include "radius.h"
8 #include "colden.h"
9 #include "dark_matter.h"
10 #include "cosmology.h"
11 #include "physconst.h"
12 
14 {
15  DEBUG_ENTRY( "GravitationalPressure()" );
16 
17  double M_self, M_external, g_dark, g_self, g_external;
18  double R = radius.Radius - radius.dRadSign * radius.drad / 2;
19 
20  M_self = M_external = g_dark = g_self = g_external = 0.;
21 
22  if( dark.lgNFW_Set )
23  {
24  double rho_crit = 3.*POW2(cosmology.H_0*1e5/MEGAPARSEC)/(8.*PI*GRAV_CONST);
25  double c_200 = dark.r_200/dark.r_s;
26  ASSERT( c_200 > 0. );
27  double delta_c = (200./3.) * POW3( c_200 ) / ( log(1.+c_200) - c_200/(1.+c_200) );
28  double M_dark = 4*PI*rho_crit*delta_c*POW3(dark.r_s);
29  M_dark *= 1./(1.+R/dark.r_s) + log(1.+R/dark.r_s) - 1.;
30 
31  g_dark = -GRAV_CONST * M_dark / (R*R);
32  }
33 
34  /* (self-)Gravity forces: Yago Ascasibar (UAM, Spring 2009) */
35 
36  // add all external mass components
37  for( unsigned int i=0; i < pressure.external_mass[0].size(); i++ )
38  {
39  double M_i = pressure.external_mass[0][i];
40  if( R < pressure.external_mass[1][i] )
41  M_i *= pow( R / pressure.external_mass[1][i], pressure.external_mass[2][i] );
42  M_external += M_i;
43  }
44 
45  // evaluate gravitational acceleration
46  switch( pressure.gravity_symmetry )
47  {
48  case -1: // no self-gravity
49  break;
50 
51  case 0: // spherical symmetry
53  // dense.xMassTotal has already been updated in radius_increment.cpp
54  M_self *= 4*PI* radius.rinner*radius.rinner;
55  M_self *= pressure.self_mass_factor;
56 
57  g_self = - GRAV_CONST * M_self / (R*R);
58  g_external = - GRAV_CONST * M_external * SOLAR_MASS / (R*R);
59  break;
60 
61  case 1: // mid-plane symmetry
63  // colden.TotMassColl will be updated later on in radius_increment.cpp
64  M_self *= pressure.self_mass_factor;
65  M_self *= 2.; // mid-plane symmetry
66 
67  // Gravitational acceleration due to an infinite slab is independent of distance from
68  // the slab and is given by g = - 2 PI G * sigma.
69  g_self = - 2*PI* GRAV_CONST * M_self;
70  g_external = - 2*PI* GRAV_CONST * M_external * SOLAR_MASS/PARSEC/PARSEC;
71 
72  if( dark.lgNFW_Set )
73  fprintf( ioQQQ, " WARNING: Setting both mid-plane baryonic gravity symmetry and an NFW dark matter halo is almost certainly unphysical!\n" );
74  break;
75 
76  default:
77  fprintf( ioQQQ, " Unknown gravitational symmetry = %d !!!\n", pressure.gravity_symmetry );
78  TotalInsanity();
79  };
80 
85 
86  return;
87 }
double Radius
Definition: radius.h:31
t_colden colden
Definition: colden.cpp:5
NORETURN void TotalInsanity(void)
Definition: service.cpp:971
double RhoGravity_dark
Definition: pressure.h:79
FILE * ioQQQ
Definition: cddefines.cpp:7
realnum H_0
Definition: cosmology.h:38
t_dense dense
Definition: global.cpp:15
double dVeffVol
Definition: radius.h:87
double drad
Definition: radius.h:31
double rinner
Definition: radius.h:31
t_dark_matter dark
Definition: dark_matter.cpp:5
double RhoGravity
Definition: pressure.h:82
#define POW2
Definition: cddefines.h:979
t_pressure pressure
Definition: pressure.cpp:9
int gravity_symmetry
Definition: pressure.h:84
t_radius radius
Definition: radius.cpp:5
double dRadSign
Definition: radius.h:74
realnum TotMassColl
Definition: colden.h:61
#define ASSERT(exp)
Definition: cddefines.h:613
void GravitationalPressure(void)
Definition: gravity.cpp:13
double drad_x_fillfac
Definition: radius.h:77
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:723
t_cosmology cosmology
Definition: cosmology.cpp:8
realnum xMassDensity
Definition: dense.h:101
realnum xMassTotal
Definition: dense.h:117
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1121
double RhoGravity_external
Definition: pressure.h:81
vector< double > external_mass[3]
Definition: pressure.h:86
double self_mass_factor
Definition: pressure.h:85
double RhoGravity_self
Definition: pressure.h:80
#define POW3
Definition: cddefines.h:986
double r_200
Definition: dark_matter.h:19