PLUTO
mappers3D.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief 3D wrapper for conservative/primitive conversion.
5 
6  Provide 3D wrappers to the standard 1D conversion functions
7  ConsToPrim() and PrimToCons().
8 
9  \authors A. Mignone (mignone@ph.unito.it)
10  \date June 24, 2015
11 */
12 /* ///////////////////////////////////////////////////////////////////// */
13 #include "pluto.h"
14 
15 /* ********************************************************************* */
16 void ConsToPrim3D (Data_Arr U, Data_Arr V, unsigned char ***flag, RBox *box)
17 /*!
18  * Convert a 3D array of conservative variables \c U to
19  * an array of primitive variables \c V.
20  * Note that <tt>[nv]</tt> is the fastest running index for \c U
21  * while it is the slowest running index for \c V.
22  *
23  * \param [in] U pointer to 3D array of conserved variables,
24  * with array indexing <tt>[k][j][i][nv]</tt>
25  * \param [out] V pointer to 3D array of primitive variables,
26  * with array indexing <tt>[nv][k][j][i]</tt>
27  * \param [in,out] flag pointer to 3D array of flags.
28  * \param [in] box pointer to RBox structure containing the domain
29  * portion over which conversion must be performed.
30  *
31  *********************************************************************** */
32 {
33  int i, j, k, nv, err;
34  int ibeg, iend, jbeg, jend, kbeg, kend;
35  int current_dir;
36  static double **v, **u;
37 
38  if (v == NULL){
39  v = ARRAY_2D(NMAX_POINT, NVAR, double);
40  u = ARRAY_2D(NMAX_POINT, NVAR, double);
41  }
42 
43 /* ----------------------------------------------
44  Save current sweep direction and by default,
45  perform the conversion along X1 stripes
46  ---------------------------------------------- */
47 
48  current_dir = g_dir;
49  g_dir = IDIR;
50 
51 /* -----------------------------------------------
52  Set (beg,end) indices in ascending order for
53  proper call to ConsToPrim()
54  ----------------------------------------------- */
55 
56  ibeg = (box->ib <= box->ie) ? (iend=box->ie, box->ib):(iend=box->ib, box->ie);
57  jbeg = (box->jb <= box->je) ? (jend=box->je, box->jb):(jend=box->jb, box->je);
58  kbeg = (box->kb <= box->ke) ? (kend=box->ke, box->kb):(kend=box->kb, box->ke);
59 
60  for (k = kbeg; k <= kend; k++){ g_k = k;
61  for (j = jbeg; j <= jend; j++){ g_j = j;
62 
63 #ifdef CHOMBO
64  for (i = ibeg; i <= iend; i++) NVAR_LOOP(nv) u[i][nv] = U[nv][k][j][i];
65  #if COOLING == MINEq || COOLING == H2_COOL
66  if (g_intStage == 1) for (i = ibeg; i <= iend; i++) NormalizeIons(u[i]);
67  #endif
68  err = ConsToPrim (u, v, ibeg, iend, flag[k][j]);
69 
70  /* -------------------------------------------------------------
71  Ensure any change to 1D conservative arrays is not lost.
72  Note: Conversion must be done even when err = 0 in case
73  ENTROPY_SWITCH is employed.
74  ------------------------------------------------------------- */
75 
76  for (i = ibeg; i <= iend; i++) NVAR_LOOP(nv) U[nv][k][j][i] = u[i][nv];
77 #else
78  err = ConsToPrim (U[k][j], v, ibeg, iend, flag[k][j]);
79 #endif
80  for (i = ibeg; i <= iend; i++) NVAR_LOOP(nv) V[nv][k][j][i] = v[i][nv];
81  }}
82  g_dir = current_dir;
83 
84 }
85 /* ********************************************************************* */
87 /*!
88  * Convert a 3D array of primitive variables \c V to
89  * an array of conservative variables \c U.
90  * Note that <tt>[nv]</tt> is the fastest running index for \c U
91  * while it is the slowest running index for \c V.
92  *
93  * \param [in] V pointer to 3D array of primitive variables,
94  * with array indexing <tt>[nv][k][j][i]</tt>
95  * \param [out] U pointer to 3D array of conserved variables,
96  * with array indexing <tt>[k][j][i][nv]</tt>
97  * \param [in] box pointer to RBox structure containing the domain
98  * portion over which conversion must be performed.
99  *
100  *********************************************************************** */
101 {
102  int i, j, k, nv;
103  int ibeg, iend, jbeg, jend, kbeg, kend;
104  int current_dir;
105  static double **v, **u;
106 
107  if (v == NULL) {
108  v = ARRAY_2D(NMAX_POINT, NVAR, double);
109  u = ARRAY_2D(NMAX_POINT, NVAR, double);
110  }
111 
112  current_dir = g_dir; /* save current direction */
113  g_dir = IDIR;
114 
115 /* -----------------------------------------------
116  Set (beg,end) indices in ascending order for
117  proper call to ConsToPrim()
118  ----------------------------------------------- */
119 
120  ibeg = (box->ib <= box->ie) ? (iend=box->ie, box->ib):(iend=box->ib, box->ie);
121  jbeg = (box->jb <= box->je) ? (jend=box->je, box->jb):(jend=box->jb, box->je);
122  kbeg = (box->kb <= box->ke) ? (kend=box->ke, box->kb):(kend=box->kb, box->ke);
123 
124  for (k = kbeg; k <= kend; k++){ g_k = k;
125  for (j = jbeg; j <= jend; j++){ g_j = j;
126  for (i = ibeg; i <= iend; i++) VAR_LOOP(nv) v[i][nv] = V[nv][k][j][i];
127 #ifdef CHOMBO
128  PrimToCons(v, u, ibeg, iend);
129  for (i = ibeg; i <= iend; i++) VAR_LOOP(nv) U[nv][k][j][i] = u[i][nv];
130 #else
131  PrimToCons (v, U[k][j], ibeg, iend);
132 #endif
133  }}
134  g_dir = current_dir; /* restore current direction */
135 
136 }
int jb
Lower corner index in the x2 direction.
Definition: structs.h:349
double **** Data_Arr
Definition: pluto.h:492
void PrimToCons3D(Data_Arr V, Data_Arr U, RBox *box)
Definition: mappers3D.c:86
int g_intStage
Gives the current integration stage of the time stepping method (predictor = 0, 1st corrector = 1...
Definition: globals.h:98
int kb
Lower corner index in the x3 direction.
Definition: structs.h:351
void NormalizeIons(double *)
void ConsToPrim3D(Data_Arr U, Data_Arr V, unsigned char ***flag, RBox *box)
Definition: mappers3D.c:16
int ib
Lower corner index in the x1 direction.
Definition: structs.h:347
#define VAR_LOOP(n)
Definition: macros.h:226
#define IDIR
Definition: pluto.h:193
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
#define NVAR_LOOP(n)
Definition: pluto.h:618
int ConsToPrim(double **ucons, double **uprim, int ibeg, int iend, unsigned char *flag)
Definition: mappers.c:89
int g_j
x2 grid index when sweeping along the x1 or x3 direction.
Definition: globals.h:83
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
int g_k
x3 grid index when sweeping along the x1 or x2 direction.
Definition: globals.h:84
PLUTO main header file.
long int NMAX_POINT
Maximum number of points among the three directions, boundaries excluded.
Definition: globals.h:62
void PrimToCons(double **uprim, double **ucons, int ibeg, int iend)
Definition: mappers.c:26
int i
Definition: analysis.c:2
int ie
Upper corner index in the x1 direction.
Definition: structs.h:348
int ke
Upper corner index in the x3 direction.
Definition: structs.h:352
int je
Upper corner index in the x2 direction.
Definition: structs.h:350
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
#define NVAR
Definition: pluto.h:609
Definition: structs.h:346