PLUTO
plm_coeffs.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Compute linear reconstruction coefficients.
5 
6  Reconstruction coefficients needed for linear interpolation are
7  computed in the ::PLM_CoefficientsSet() each time a new grid
8  is created.
9  There's a different set of 1D coefficients in each direction.
10 
11  The function ::PLM_CoefficientsGet() can be used to obtain
12  a set of coefficients along a desired direction.
13 
14  \b References
15  - "High-order conservative reconstruction schemes for finite
16  volume methods in cylindrical and spherical coordinates"
17  A. Mignone, JCP (2014), 270, 784.
18 
19  \authors A. Mignone (mignone@ph.unito.it)
20  \date May 19, 2014
21 */
22 /* ///////////////////////////////////////////////////////////////////// */
23 #include "pluto.h"
24 
25 static double **cp3D, **cm3D;
26 static double **wp3D, **wm3D;
27 static double **dp3D, **dm3D;
28 
29 /* ********************************************************************* */
31 /*!
32  * Compute interpolation coefficients for linear reconstruction.
33  *
34  * \param[in] grid pointer to array of grid structure
35  *
36  * \return This function has no return value
37  *********************************************************************** */
38 {
39  int i, d, beg, end;
40  double *dx, *xr, *xgc;
41 
42  if (cp3D == NULL) {
43  cp3D = ARRAY_2D(DIMENSIONS, NMAX_POINT, double);
44  cm3D = ARRAY_2D(DIMENSIONS, NMAX_POINT, double);
45  dp3D = ARRAY_2D(DIMENSIONS, NMAX_POINT, double);
46  dm3D = ARRAY_2D(DIMENSIONS, NMAX_POINT, double);
47  wp3D = ARRAY_2D(DIMENSIONS, NMAX_POINT, double);
48  wm3D = ARRAY_2D(DIMENSIONS, NMAX_POINT, double);
49  }
50 
51 /* -----------------------------------------------------
52  Compute interpolation coefficients.
53  This must be the first call to this function in
54  order to store coefficients into memory.
55  ----------------------------------------------------- */
56 
57  for (d = 0; d < DIMENSIONS; d++){
58  dx = grid[d].dx;
59  xgc = grid[d].xgc;
60  xr = grid[d].xr;
61 
62  /* -- first and last zone are excluded -- */
63 
64  beg = 1;
65  end = grid[d].np_tot - 2;
66  for (i = beg; i <= end; i++){
67  wp3D[d][i] = dx[i]/(xgc[i+1] - xgc[i]); /* coeff. for dQF in Eq. [29] */
68  wm3D[d][i] = dx[i]/(xgc[i] - xgc[i-1]); /* coeff. for dQB in Eq. [29] */
69 
70  cp3D[d][i] = (xgc[i+1] - xgc[i])/(xr[i] - xgc[i]); /* Eq. [33], cF */
71  cm3D[d][i] = (xgc[i] - xgc[i-1])/(xgc[i] - xr[i-1]); /* Eq. [33], cB */
72 
73  dp3D[d][i] = (xr[i] - xgc[i])/dx[i]; /* Eq. [30], plus sign */
74  dm3D[d][i] = (xgc[i] - xr[i-1])/dx[i]; /* Eq. [30], minus sign */
75  }
76  }
77 }
78 /* ********************************************************************* */
79 void PLM_CoefficientsGet(PLM_Coeffs *plm_coeffs, int dir)
80 /*!
81  * Retrieve reconstruction coefficients in the PLM_Coeffs structure.
82  * This function can be called only if the previous one has been
83  * completed already.
84  *
85  * \param[out] plm_coeffs a pointer to a PLM_Coeffs structure containing
86  * the 1D coefficients needed for reconstruction
87  * \param[in] dir the desired direction
88  *
89  *********************************************************************** */
90 {
91  if (cp3D == NULL) {
92  print1 ("! PLM_Coefficients: coefficients not set.\n");
93  QUIT_PLUTO(1);
94  }
95 
96  plm_coeffs->cp = cp3D[dir];
97  plm_coeffs->cm = cm3D[dir];
98 
99  plm_coeffs->wp = wp3D[dir];
100  plm_coeffs->wm = wm3D[dir];
101 
102  plm_coeffs->dp = dp3D[dir];
103  plm_coeffs->dm = dm3D[dir];
104 
105 }
int end
Global end index for the local array.
Definition: structs.h:116
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
double * xr
Definition: structs.h:81
double * cm
Definition: plm_coeffs.h:40
static double ** dm3D
Definition: plm_coeffs.c:27
static double ** cp3D
Definition: plm_coeffs.c:25
static double ** wp3D
Definition: plm_coeffs.c:26
double * dx
Definition: structs.h:83
int beg
Global start index for the local array.
Definition: structs.h:115
void PLM_CoefficientsSet(Grid *grid)
Definition: plm_coeffs.c:30
Definition: structs.h:78
double * cp
Definition: plm_coeffs.h:39
static double ** wm3D
Definition: plm_coeffs.c:26
double * xgc
Cell volumetric centroid (!= x when geometry != CARTESIAN).
Definition: structs.h:84
static double ** cm3D
Definition: plm_coeffs.c:25
void PLM_CoefficientsGet(PLM_Coeffs *plm_coeffs, int dir)
Definition: plm_coeffs.c:79
PLUTO main header file.
double * dm
Definition: plm_coeffs.h:44
static double ** dp3D
Definition: plm_coeffs.c:27
double * dp
Definition: plm_coeffs.h:43
long int NMAX_POINT
Maximum number of points among the three directions, boundaries excluded.
Definition: globals.h:62
int i
Definition: analysis.c:2
double * wm
Definition: plm_coeffs.h:42
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
int np_tot
Total number of points in the local domain (boundaries included).
Definition: structs.h:100
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
double * wp
Definition: plm_coeffs.h:41
#define DIMENSIONS
Definition: definitions_01.h:2