PLUTO
entropy_switch.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Compute entropy after boundary condition have been set.
5 
6  \author A. Mignone (mignone@ph.unito.it)
7  \date July 28, 2015
8 */
9 /* ///////////////////////////////////////////////////////////////////// */
10 #include"pluto.h"
11 
12 #if HAVE_ENERGY && ENTROPY_SWITCH
13 /* ********************************************************************* */
14 void ComputeEntropy (const Data *d, Grid *grid)
15 /*!
16  * Compute entropy as a primitive variable.
17  *
18  * \param [in,out] d pointer to Data structure
19  * \param [in] grid pointer to an array of Grid structures.
20  *
21  * \return This function has no return value.
22  *
23  *********************************************************************** */
24 {
25  int i, j, k;
26  static double **v1d;
27 
28  if (v1d == NULL) v1d = ARRAY_2D(NMAX_POINT, NVAR, double);
29  KTOT_LOOP(k) {
30  JTOT_LOOP(j) {
31  ITOT_LOOP(i) {
32  v1d[i][RHO] = d->Vc[RHO][k][j][i];
33  v1d[i][PRS] = d->Vc[PRS][k][j][i];
34  }
35  Entropy(v1d, d->Vc[ENTR][k][j], 0, NX1_TOT-1);
36  }}
37 }
38 
39 /* ********************************************************************* */
40 void EntropyOhmicHeating (const Data *d, Data_Arr UU, double dt, Grid *grid)
41 /*!
42  * Add Ohmic heating term to the conservative entropy equation when
43  * RESISTIVITY is set to YES.
44  *
45  * \return This function has no return value.
46  *********************************************************************** */
47 {
48 #if PHYSICS == MHD && (RESISTIVITY == EXPLICIT) /* at the moment ... remove later ! */
49  int i,j,k,nv;
50  double rho, rhog, gm1, vc[NVAR];
51  double Jc[3], eta[3], J2eta;
52  double ***Jx1, *x1, *dx1;
53  double ***Jx2, *x2, *dx2;
54  double ***Jx3, *x3, *dx3;
55  Data_Arr V;
56 
57 /* ---------------------------------------------
58  1. Set pointer shortcuts
59  --------------------------------------------- */
60 
61  V = d->Vc;
62  Jx1 = d->J[IDIR]; x1 = grid[IDIR].x ; dx1 = grid[IDIR].dx;
63  Jx2 = d->J[JDIR]; x2 = grid[JDIR].x ; dx2 = grid[JDIR].dx;
64  Jx3 = d->J[KDIR]; x3 = grid[KDIR].x ; dx3 = grid[KDIR].dx;
65 
66  gm1 = g_gamma - 1.0;
67  Jc[IDIR] = Jc[JDIR] = Jc[KDIR] = 0.0;
68 
69 /* ---------------------------------------------
70  2. Main spatial loop
71  --------------------------------------------- */
72 
73  DOM_LOOP(k,j,i){
74 
75  /* ---------------------------------
76  2a. compute currents at cell center
77  --------------------------------- */
78 
79  #ifdef STAGGERED_MHD /* Staggered MHD */
80 
81  #if COMPONENTS == 3
82  Jc[IDIR] = AVERAGE_YZ(Jx1,k-1,j-1,i);
83  Jc[JDIR] = AVERAGE_XZ(Jx2,k-1,j,i-1);
84  #endif
85  Jc[KDIR] = AVERAGE_XY(Jx3,k,j-1,i-1);
86 
87  #else /* Cell-centered MHD */
88 
89  #if COMPONENTS == 3
90  Jc[IDIR] = CDIFF_X2(V[BX3],k,j,i)/dx2[j] - CDIFF_X3(V[BX2],k,j,i)/dx3[k];
91  Jc[JDIR] = CDIFF_X3(V[BX1],k,j,i)/dx3[k] - CDIFF_X1(V[BX3],k,j,i)/dx1[i];
92  #endif
93  Jc[KDIR] = CDIFF_X1(V[BX2],k,j,i)/dx1[i] - CDIFF_X2(V[BX1],k,j,i)/dx2[j];
94 
95  #if GEOMETRY != CARTESIAN
96  print1 ("! EntropyOhmicHeating: only CT supported in this geometry.\n")
97  QUIT_PLUTO(1);
98  #endif
99 
100  #endif
101 
102  /* ----------------------------------------
103  2b. compute resistivity at cell center.
104  ---------------------------------------- */
105 
106  VAR_LOOP(nv) vc[nv] = V[nv][k][j][i];
107  rho = vc[RHO];
108  rhog = pow(rho,-gm1);
109 
110  Resistive_eta (vc, x1[i], x2[j], x3[k], Jc, eta);
111  J2eta = 0.0;
112  for (nv = 0; nv < 3; nv++) J2eta += Jc[nv]*Jc[nv]*eta[nv];
113 
114  /* ----------------------------------------
115  2c. Update conserved entropy
116  ---------------------------------------- */
117 
118  UU[k][j][i][ENTR] += dt*rhog*gm1*J2eta;
119  }
120 #endif
121 }
122 #endif
double g_gamma
Definition: globals.h:112
void EntropyOhmicHeating(const Data *, Data_Arr, double, Grid *)
double **** Data_Arr
Definition: pluto.h:492
DOM_LOOP(k, j, i)
Definition: analysis.c:22
double **** J
Electric current defined as curl(B).
Definition: structs.h:54
#define AVERAGE_YZ(q, k, j, i)
Definition: macros.h:264
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
#define CDIFF_X2(b, k, j, i)
Definition: macros.h:241
#define RHO
Definition: mod_defs.h:19
static double *** eta[3]
Definition: res_functions.c:94
double **** Vc
The main four-index data array used for cell-centered primitive variables.
Definition: structs.h:31
#define KTOT_LOOP(k)
Definition: macros.h:40
double * dx
Definition: structs.h:83
#define KDIR
Definition: pluto.h:195
void ComputeEntropy(const Data *, Grid *)
void Entropy(double **v, double *s, int beg, int end)
Definition: eos.c:80
#define VAR_LOOP(n)
Definition: macros.h:226
#define IDIR
Definition: pluto.h:193
Definition: structs.h:78
int j
Definition: analysis.c:2
#define AVERAGE_XY(q, k, j, i)
Definition: macros.h:260
int k
Definition: analysis.c:2
double * x
Definition: structs.h:80
void Resistive_eta(double *v, double x1, double x2, double x3, double *J, double *eta)
Definition: res_eta.c:17
#define BX3
Definition: mod_defs.h:27
#define CDIFF_X1(b, k, j, i)
Definition: macros.h:240
PLUTO main header file.
#define ITOT_LOOP(i)
Definition: macros.h:38
Definition: structs.h:30
long int NMAX_POINT
Maximum number of points among the three directions, boundaries excluded.
Definition: globals.h:62
#define JTOT_LOOP(j)
Definition: macros.h:39
int i
Definition: analysis.c:2
#define BX1
Definition: mod_defs.h:25
#define AVERAGE_XZ(q, k, j, i)
Definition: macros.h:262
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
#define BX2
Definition: mod_defs.h:26
#define CDIFF_X3(b, k, j, i)
Definition: macros.h:242
#define JDIR
Definition: pluto.h:194
#define NVAR
Definition: pluto.h:609
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
Definition: globals.h:55