The FARGO_THORIN code developer's guide
 All Data Structures Files Functions Variables Typedefs Macros
Theo.c
Go to the documentation of this file.
1 /** \file Theo.c
2 
3 A few functions that manipulate the surface density profile.
4 
5 @author THORIN modifications by
6 Ondřej Chrenko <chrenko@sirrah.troja.mff.cuni.cz>, Copyright (C) 2017;
7 original code by Frédéric Masset
8 
9 */
10 
11 #include "fargo.h"
12 
13 extern real ScalingFactor;
14 
16 real r;
17 {
18  real cavity=1.0;
19  if (r < CAVITYRADIUS) cavity = 1.0/CAVITYRATIO; /* This is *not* a steady state */
20  /* profile, if a cavity is defined. It first needs */
21  /* to relax towards steady state, on a viscous time scale */
22  return cavity*ScalingFactor*SIGMA0*pow(r,-SIGMASLOPE);
23 }
24 
25 void FillSigma() {
26  int i;
27  for (i = 0; i < NRAD; i++) {
28  SigmaMed[i] = Sigma(Rmed[i]);
29  SigmaInf[i] = Sigma(Rinf[i]);
30  }
31 }
32 
33 void RefillSigma (Surfdens)
34  PolarGrid *Surfdens;
35 {
36  int i, j, nr, ns, l;
37  real *field;
38  real moy;
39  nr = Surfdens->Nrad;
40  ns = Surfdens->Nsec;
41  field = Surfdens->Field;
42  for (i = 0; i < nr; i++) {
43  moy = 0.0;
44  for (j = 0; j < ns; j++) {
45  l = j+i*ns;
46  moy += field[l];
47  }
48  moy /= (real)ns;
49  SigmaMed[i] = moy;
50  }
51  SigmaInf[0] = SigmaMed[0];
52  for (i = 1; i < nr; i++) {
53  SigmaInf[i] = (SigmaMed[i-1]*(Rmed[i]-Rinf[i])+\
54  SigmaMed[i]*(Rinf[i]-Rmed[i-1]))/\
55  (Rmed[i]-Rmed[i-1]);
56  }
57 }
58 
59 /** Initialises the energy array. */
60 real Energy(r) /* #THORIN */
61 real r;
62 {
63  real fac, power, Einit;
64  if (ADIABIND == 1.0) {
65  mastererr ("The internal energy cannot be initialized with the adiabatic index equal to unity. Terminating now...\n");
66  Einit = -1.0; /* just a randomly chosen irelevant value of energy to prevent a compilation warning */
67  prs_exit (1);
68  } else {
69  fac = 1.0/(MOLWEIGHT*(ADIABIND-1.0));
70  power = -SIGMASLOPE-1.0+2.0*FLARINGINDEX;
71  Einit = GASCONST*SIGMA0*pow(ASPECTRATIO,2.0)*pow(r,power)*fac;
72  }
73  return Einit;
74 }
75 
76 void FillEnergy() /* #THORIN */
77 {
78  int i;
79  for (i=0; i < NRAD; i++) EnergyMed[i] = Energy(Rmed[i]);
80 }
81 
82 void RefillEnergy (Energy) /* similar to RefillSigma() */
84 {
85  int i, j, nr, ns, l;
86  real *field;
87  real moy;
88  nr = Energy->Nrad;
89  ns = Energy->Nsec;
90  field = Energy->Field;
91  for (i = 0; i < nr; i++) {
92  moy = 0.0;
93  for (j = 0; j < ns; j++) {
94  l = j+i*ns;
95  moy += field[l];
96  }
97  moy /= (real)ns;
98  EnergyMed[i] = moy;
99  }
100 }
101 
103 real r;
104 {
105  real coolt;
106  coolt = COOLINGTIME*pow(r,2.0+2.0*FLARINGINDEX);
107  return coolt;
108 }
109 
111 {
112  int i;
113  for (i=0; i<NRAD; i++) CoolingTimeMed[i] = InitCoolingTime(Rmed[i]);
114 }
115 
117 real r;
118 {
119  real viscosity, Qplus;
120  viscosity = FViscosity(r);
121  Qplus = 2.25*viscosity*SIGMA0*pow(r,-SIGMASLOPE-3.0);
122  return Qplus;
123 }
124 
125 void FillQplus()
126 {
127  int i;
128  for (i=0; i<NRAD; i++) QplusMed[i] = InitQplus(Rmed[i]);
129 }
130 
131 
132 void FillVtheta (Vtheta)
133 PolarGrid *Vtheta;
134 {
135  int i, j, nr, ns, l;
136  real *field, vtcorr;
137  real moy;
138  nr = Vtheta->Nrad;
139  ns = Vtheta->Nsec;
140  field = Vtheta->Field;
141  for (i = 0; i < nr; i++) {
142  moy = 0.0;
143  vtcorr = Rmed[i]*OmegaFrame;
144  for (j = 0; j < ns; j++) {
145  l = j+i*ns;
146  moy += field[l] + vtcorr; /* use values in the inertial frame */
147  }
148  moy /= (real)ns;
149  VthetaMed[i] = moy;
150  }
151 }
152 /* <--- */
153 
double real
Definition of the type 'real' used throughout the code.
Definition: types.h:20
real InitCoolingTime(real r)
Definition: Theo.c:102
real VthetaMed[MAX1D]
Definition: global.h:16
real SIGMASLOPE
Definition: param_noex.h:27
PolarGrid * Qplus
Definition: global.h:35
real EnergyMed[MAX1D]
Definition: global.h:16
A structure used to store any scalar fied on the computational domain.
Definition: types.h:37
int Nrad
Radial size of the grid, in number of zones.
Definition: types.h:38
real Rmed[MAX1D]
Definition: global.h:11
real ScalingFactor
Definition: main.c:19
real CAVITYRATIO
Definition: param_noex.h:42
real CoolingTimeMed[MAX1D]
Definition: global.h:17
real Energy(real r)
Initialises the energy array.
Definition: Theo.c:60
real FLARINGINDEX
Definition: param_noex.h:39
real InitQplus(real r)
Definition: Theo.c:116
real SigmaInf[MAX1D]
Definition: global.h:14
void FillCoolingTime()
Definition: Theo.c:110
real FViscosity()
real OmegaFrame
Definition: global.h:20
void FillSigma()
Definition: Theo.c:25
#define GASCONST
Definition: fondam.h:17
#define MOLWEIGHT
Definition: fondam.h:18
real ASPECTRATIO
Definition: param_noex.h:24
void FillVtheta(PolarGrid *Vtheta)
Definition: Theo.c:132
void mastererr(const char *template,...)
Definition: LowTasks.c:49
real ADIABIND
Definition: param_noex.h:54
int NRAD
Definition: param_noex.h:18
real QplusMed[MAX1D]
Definition: global.h:17
Contains all the include directives requested by the code.
real Rinf[MAX1D]
Definition: global.h:11
real SigmaMed[MAX1D]
Definition: global.h:14
real SIGMA0
Definition: param_noex.h:8
real Sigma(real r)
Definition: Theo.c:15
void FillQplus()
Definition: Theo.c:125
void RefillEnergy(PolarGrid *Energy)
Definition: Theo.c:82
real CAVITYRADIUS
Definition: param_noex.h:41
real COOLINGTIME
Definition: param_noex.h:55
void prs_exit(int numb)
Definition: LowTasks.c:33
void FillEnergy()
Definition: Theo.c:76
void RefillSigma(PolarGrid *Surfdens)
Definition: Theo.c:33