The FARGO_THORIN code developer's guide
 All Data Structures Files Functions Variables Typedefs Macros
Viscosity.c
Go to the documentation of this file.
1 /** \file Viscosity.c
2 
3 Calculation of the viscous %force. The function FViscosity() returns
4 the (kinematic) viscosity as a function of the radius (it handles all
5 case: alpha or uniform viscosity, and inner cavity with a different
6 viscosity). The update of the velocity is done in ViscousTerm(),
7 which properly evaluate the stress tensor in 2D cylindrical
8 coordinates. This file also contains the function AspectRatio(), which
9 gives the aspect ratio as a function of the radius, in the case of a
10 temperature jump in the disk (much in the manner as cavities arising
11 from a viscosity jump are handled, hence the location of this
12 function). Note that AspectRatio() does not feature the FLARINGINDEX,
13 which is taken into account by the calling function.
14 
15 @author THORIN modifications by
16 Ondřej Chrenko <chrenko@sirrah.troja.mff.cuni.cz>, Copyright (C) 2017;
17 original code by Frédéric Masset
18 
19 */
20 
21 #include "fargo.h"
22 
23 static PolarGrid *DRR, *DRP, *DPP;
24 /* #THORIN: DivergenceVelocity, TAURR, TAUPP, TAURP are now declared in global.h */
25 
27  real rad;
28 {
29  real viscosity, rmin, rmax, scale;
30  int i=0;
31  /* ----- */
32  viscosity = VISCOSITY;
33  if (ViscosityAlpha) {
34  while (GlobalRmed[i] < rad) i++; /* ! this spans the GLOBAL grid (among all MPI processes) */
35  /* #THORIN: globcsvec[] used here */
36  viscosity = ALPHAVISCOSITY*globcsvec[i]*globcsvec[i]*pow(rad, 1.5);
37  }
41  rmin *= scale;
42  rmax *= scale;
43  if (rad < rmin) viscosity *= CAVITYRATIO;
44  if ((rad >= rmin) && (rad <= rmax)) {
45  viscosity *= exp((rmax-rad)/(rmax-rmin)*log(CAVITYRATIO));
46  }
47  return viscosity;
48 }
49 
51  real rad;
52 {
53  real aspectratio, rmin, rmax, scale;
54  aspectratio = ASPECTRATIO;
58  rmin *= scale;
59  rmax *= scale;
60  if (rad < rmin) aspectratio *= TRANSITIONRATIO;
61  if ((rad >= rmin) && (rad <= rmax)) {
62  aspectratio *= exp((rmax-rad)/(rmax-rmin)*log(TRANSITIONRATIO));
63  }
64  return aspectratio;
65 }
66 
68 {
70  DRR = CreatePolarGrid(NRAD, NSEC, "Drr");
71  DRP = CreatePolarGrid(NRAD, NSEC, "Drp");
72  DPP = CreatePolarGrid(NRAD, NSEC, "Dpp");
73  TAURR = CreatePolarGrid(NRAD, NSEC, "TAUrr");
74  TAURP = CreatePolarGrid(NRAD, NSEC, "TAUrp");
75  TAUPP = CreatePolarGrid(NRAD, NSEC, "TAUpp");
76 }
77 
78 /** A function derived from the original ViscousTerms(). */
79 void UpdateDivVelocAndStressTensor (Vrad, Vtheta, Rho) /* #THORIN */
80 PolarGrid *Vrad, *Vtheta, *Rho;
81 {
82  int i,j,l,nr,ns,lip,ljp,ljm,lim,ljmim;
83  real *rho, *vr, *vt;
84  real *Drr, *Drp, *Dpp, *divergence;
85  real *Trr, *Trp, *Tpp;
86  real dphi, onethird, invdphi;
87  real viscosity;
88  /* ----- */
89  nr = Rho->Nrad;
90  ns = Rho->Nsec;
91  rho = Rho->Field;
92  vr = Vrad->Field;
93  vt = Vtheta->Field;
94  divergence = DivergenceVelocity->Field;
95  Drr = DRR->Field;
96  Drp = DRP->Field;
97  Dpp = DPP->Field;
98  Trr = TAURR->Field;
99  Trp = TAURP->Field;
100  Tpp = TAUPP->Field;
101  dphi = 2.0*M_PI/(real)ns;
102  invdphi = 1.0/dphi;
103  onethird = 1.0/3.0;
104  /* The rest of this routine corresponds to the 1st part of the original ViscousTerms() ----> */
105 #pragma omp parallel private(l,lip,ljp,j,ljm,lim)
106  {
107 #pragma omp for nowait
108  for (i = 0; i < nr; i++) { /* Drr, Dpp and divV computation */
109  for (j = 0; j < ns; j++) {
110  l = j+i*ns;
111  lip = l+ns;
112  ljp = l+1;
113  if (j == ns-1) ljp = i*ns;
114  Drr[l] = (vr[lip]-vr[l])*InvDiffRsup[i];
115  Dpp[l] = (vt[ljp]-vt[l])*invdphi*InvRmed[i]+0.5*(vr[lip]+vr[l])*InvRmed[i];
116  divergence[l] = (vr[lip]*Rsup[i]-vr[l]*Rinf[i])*InvDiffRsup[i]*InvRmed[i];
117  divergence[l] += (vt[ljp]-vt[l])*invdphi*InvRmed[i];
118  }
119  }
120 #pragma omp for
121  for (i = 1; i < nr; i++) { /* Drp computation */
122  for (j = 0; j < ns; j++) {
123  l = j+i*ns;
124  ljm = l-1;
125  if (j == 0) ljm = i*ns+ns-1;
126  lim = l-ns;
127  Drp[l] = 0.5*(Rinf[i]*(vt[l]*InvRmed[i]-vt[lim]*InvRmed[i-1])*InvDiffRmed[i]+\
128  (vr[l]-vr[ljm])*invdphi*InvRinf[i]);
129  }
130  }
131  }
132 #pragma omp parallel private(l,ljmim,j,ljm,lim,viscosity)
133  {
134 #pragma omp for nowait
135  for (i = 0; i < nr; i++) { /* TAUrr and TAUpp computation */
136  viscosity = FViscosity (Rmed[i]);
137  for (j = 0; j < ns; j++) {
138  l = j+i*ns;
139  Trr[l] = 2.0*rho[l]*viscosity*(Drr[l]-onethird*divergence[l]);
140  Tpp[l] = 2.0*rho[l]*viscosity*(Dpp[l]-onethird*divergence[l]);
141  }
142  }
143 #pragma omp for
144  for (i = 1; i < nr; i++) { /* TAUrp computation */
145  viscosity = FViscosity (Rinf[i]);
146  for (j = 0; j < ns; j++) {
147  l = j+i*ns;
148  lim = l-ns;
149  ljm = l-1;
150  if (j == 0) ljm = i*ns+ns-1;
151  ljmim=ljm-ns;
152  Trp[l] = 2.0*0.25*(rho[l]+rho[lim]+rho[ljm]+rho[ljmim])*viscosity*Drp[l];
153  }
154  }
155  }
156 }
157 
158 /** A function derived from the original ViscousTerms(). */
159 void UpdateVelocityWithViscousTerms (Vrad, Vtheta, Rho, DeltaT) /* #THORIN */
160 PolarGrid *Vrad, *Vtheta, *Rho;
161 real DeltaT;
162 {
163  int i,j,l,nr,ns,lip,ljp,ljm,lim;
164  real *rho, *vr, *vt;
165  real *Trr, *Trp, *Tpp;
166  real dphi, invdphi;
167  /* ----- */
168  nr = Rho->Nrad;
169  ns = Rho->Nsec;
170  rho = Rho->Field;
171  vr = Vrad->Field;
172  vt = Vtheta->Field;
173  Trr = TAURR->Field;
174  Trp = TAURP->Field;
175  Tpp = TAUPP->Field;
176  dphi = 2.0*M_PI/(real)ns;
177  invdphi = 1.0/dphi;
178  /* The rest of this routine corresponds to the 2nd part of the original ViscousTerms() ----> */
179  /* Now we can update velocities */
180  /* with the viscous source term */
181  /* of Navier-Stokes equations */
182 #pragma omp parallel private(l,j,lip,ljp,ljm,lim)
183  {
184 #pragma omp for nowait
185  for (i = 1; i < nr-1; i++) { /* vtheta first */
186  for (j = 0; j < ns; j++) {
187  l = j+i*ns;
188  lip = l+ns;
189  ljp = l+1;
190  if (j == ns-1) ljp = i*ns;
191  ljm = l-1;
192  if (j == 0) ljm = i*ns+ns-1;
193  vt[l] += DeltaT*InvRmed[i]*((Rsup[i]*Trp[lip]-Rinf[i]*Trp[l])*InvDiffRsup[i]+\
194  (Tpp[l]-Tpp[ljm])*invdphi+\
195  0.5*(Trp[l]+Trp[lip]))/(0.5*(rho[l]+rho[ljm]));
196  }
197  }
198 #pragma omp for nowait
199  for (i = 1; i < nr; i++) { /* and now vrad */
200  for (j = 0; j < ns; j++) {
201  l = j+i*ns;
202  lip = l+ns;
203  lim = l-ns;
204  ljp = l+1;
205  if (j == ns-1) ljp = i*ns;
206  vr[l] += DeltaT*InvRinf[i]*((Rmed[i]*Trr[l]-Rmed[i-1]*Trr[lim])*InvDiffRmed[i]+\
207  (Trp[ljp]-Trp[l])*invdphi-\
208  0.5*(Tpp[l]+Tpp[lim]))/(0.5*(rho[l]+rho[lim]));
209  }
210  }
211  }
212 }
213 
214 /** A function derived from the original ViscousTerms(). */
215 void ImposeKeplerianEdges (Vtheta) /* #THORIN */
216 PolarGrid *Vtheta;
217 {
218  real VKepIn, VKepOut;
219  int i, j, l, nr, ns;
220  real *vt;
221  /* ----- */
222  nr = Vtheta->Nrad;
223  ns = Vtheta->Nsec;
224  vt = Vtheta->Field;
225 /* The routine corresponds to the 3rd part of the original ViscousTerms() ----> */
226 #pragma omp parallel private(l,j)
227  {
228 #pragma omp single
229  {
230  VKepIn = sqrt(G*1.0/Rmed[0])*\
231  sqrt(1.0-pow(AspectRatio(Rmed[0]),2.0)* \
232  pow(Rmed[0],2.0*FLARINGINDEX)*\
233  (1.+SIGMASLOPE-2.0*FLARINGINDEX));
234  VKepOut = sqrt(G*1.0/Rmed[nr-1])*\
235  sqrt(1.0-pow(AspectRatio(Rmed[nr-1]),2.0)* \
236  pow(Rmed[nr-1],2.0*FLARINGINDEX)*\
237  (1.+SIGMASLOPE-2.0*FLARINGINDEX));
238  i = 0;
239  if (CPU_Rank == 0) {
240  for (j = 0; j < ns; j++) {
241  l = j+i*ns;
242  vt[l] = VKepIn-Rmed[0]*OmegaFrame;
243  }
244  }
245  i = nr-1;
246  if (CPU_Rank == CPU_Number-1) {
247  for (j = 0; j < ns; j++) {
248  l = j+i*ns;
249  vt[l] = VKepOut-Rmed[nr-1]*OmegaFrame;
250  }
251  }
252  }
253  }
254 }
double real
Definition of the type 'real' used throughout the code.
Definition: types.h:20
real InvDiffRmed[MAX1D]
Definition: global.h:12
void UpdateVelocityWithViscousTerms(PolarGrid *Vrad, PolarGrid *Vtheta, PolarGrid *Rho, real DeltaT)
A function derived from the original ViscousTerms().
Definition: Viscosity.c:159
real SIGMASLOPE
Definition: param_noex.h:27
real CAVITYWIDTH
Definition: param_noex.h:43
real Rsup[MAX1D]
Definition: global.h:11
real TRANSITIONWIDTH
Definition: param_noex.h:46
int CPU_Number
Definition: global.h:2
PolarGrid * TAURR
Definition: global.h:36
PolarGrid * TAURP
Definition: global.h:36
PolarGrid * CreatePolarGrid(int Nr, int Ns, char *name)
Definition: LowTasks.c:73
real InvRinf[MAX1D]
Definition: global.h:13
A structure used to store any scalar fied on the computational domain.
Definition: types.h:37
real GlobalRmed[MAX1D]
Definition: global.h:13
real * Field
Definition: types.h:40
int Nrad
Radial size of the grid, in number of zones.
Definition: types.h:38
real Rmed[MAX1D]
Definition: global.h:11
PolarGrid * TAUPP
Definition: global.h:36
real ALPHAVISCOSITY
Definition: param_noex.h:26
real CAVITYRATIO
Definition: param_noex.h:42
real PhysicalTime
Definition: global.h:20
real InvDiffRsup[MAX1D]
Definition: global.h:13
real globcsvec[MAX1D]
Definition: global.h:16
real VISCOSITY
Definition: param_noex.h:25
real FLARINGINDEX
Definition: param_noex.h:39
#define G
Definition: fondam.h:11
void InitViscosity()
Definition: Viscosity.c:67
real OmegaFrame
Definition: global.h:20
int NSEC
Definition: param_noex.h:19
static PolarGrid * DRR
Definition: Viscosity.c:23
static PolarGrid * DRP
Definition: Viscosity.c:23
real PhysicalTimeInitial
Definition: global.h:20
real ASPECTRATIO
Definition: param_noex.h:24
real AspectRatio(real rad)
Definition: Viscosity.c:50
int NRAD
Definition: param_noex.h:18
PolarGrid * DivergenceVelocity
Definition: global.h:36
real TRANSITIONRATIO
Definition: param_noex.h:45
Contains all the include directives requested by the code.
real Rinf[MAX1D]
Definition: global.h:11
boolean ViscosityAlpha
Definition: global.h:30
int CPU_Rank
Definition: global.h:1
void ImposeKeplerianEdges(PolarGrid *Vtheta)
A function derived from the original ViscousTerms().
Definition: Viscosity.c:215
real LAMBDADOUBLING
Definition: param_noex.h:47
real TRANSITIONRADIUS
Definition: param_noex.h:44
real InvRmed[MAX1D]
Definition: global.h:12
real CAVITYRADIUS
Definition: param_noex.h:41
static PolarGrid * DPP
Definition: Viscosity.c:23
real FViscosity(real rad)
Definition: Viscosity.c:26
void UpdateDivVelocAndStressTensor(PolarGrid *Vrad, PolarGrid *Vtheta, PolarGrid *Rho)
A function derived from the original ViscousTerms().
Definition: Viscosity.c:79