HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
WENOFifthOrderCalculateWeights.c File Reference

Functions to compute the nonlinear weights for WENO-type schemes. More...

#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <basic.h>
#include <arrayfunctions.h>
#include <matmult_native.h>
#include <mathfunctions.h>
#include <interpolation.h>
#include <mpivars.h>
#include <hypar.h>
#include <arrayfunctions_gpu.h>

Go to the source code of this file.

Macros

#define _MINIMUM_GHOSTS_   3
 

Functions

static int WENOFifthOrderCalculateWeightsJS (double *, double *, double *, int, void *, void *)
 
static int WENOFifthOrderCalculateWeightsM (double *, double *, double *, int, void *, void *)
 
static int WENOFifthOrderCalculateWeightsZ (double *, double *, double *, int, void *, void *)
 
static int WENOFifthOrderCalculateWeightsYC (double *, double *, double *, int, void *, void *)
 
static int WENOFifthOrderCalculateWeightsCharJS (double *, double *, double *, int, void *, void *)
 
static int WENOFifthOrderCalculateWeightsCharM (double *, double *, double *, int, void *, void *)
 
static int WENOFifthOrderCalculateWeightsCharZ (double *, double *, double *, int, void *, void *)
 
static int WENOFifthOrderCalculateWeightsCharYC (double *, double *, double *, int, void *, void *)
 
int WENOFifthOrderCalculateWeights (double *fC, double *uC, double *x, int dir, void *s, void *m)
 
int WENOFifthOrderCalculateWeightsChar (double *fC, double *uC, double *x, int dir, void *s, void *m)
 

Detailed Description

Functions to compute the nonlinear weights for WENO-type schemes.

Author
Debojyoti Ghosh

Definition in file WENOFifthOrderCalculateWeights.c.

Macro Definition Documentation

◆ _MINIMUM_GHOSTS_

#define _MINIMUM_GHOSTS_   3

Minimum number of ghost points required for this interpolation method.

Definition at line 25 of file WENOFifthOrderCalculateWeights.c.

Function Documentation

◆ WENOFifthOrderCalculateWeightsJS()

int WENOFifthOrderCalculateWeightsJS ( double *  fC,
double *  uC,
double *  x,
int  dir,
void *  s,
void *  m 
)
static

Computes the nonlinear weights for the 5th order component-wise WENO-type schemes using the original formulation of Jiang & Shu:

\begin{equation} \omega_k = \frac {a_k} {\sum_{j=1}^3 a_j },\ a_k = \frac {c_k} {\left(\beta_k+\epsilon\right)^p},\ k = 1,2,3, \end{equation}

where \(c_k\) are the optimal weights, \(p\) is hardcoded to \(2\), and \(\epsilon\) is an input parameter (WENOParameters::eps) (typically \(10^{-6}\)). The smoothness indicators \(\beta_k\) are given by:

\begin{eqnarray} \beta_1 &=& \frac{13}{12} \left(f_{j-2}-2f_{j-1}+f_j\right)^2 + \frac{1}{4}\left(f_{j-2}-4f_{j-1}+3f_j\right)^2 \\ \beta_2 &=& \frac{13}{12} \left(f_{j-1}-2f_j+f_{j+1}\right)^2 + \frac{1}{4}\left(f_{j-1}-f_{j+1}\right)^2 \\ \beta_3 &=& \frac{13}{12} \left(f_j-2f_{j+1}+f_{j+2}\right)^2 + \frac{1}{4}\left(3f_j-4f_{j+1}+f_{j+2}\right)^2 \end{eqnarray}

Notes:

  • This function computes the weights for the entire grid (for interpolation along a given spatial dimension dir ). Thus, it loops over all grid lines along dir.
  • The weights are computed for all components, for both the left- and right-biased interpolations, and for both the flux function \({\bf f}\left({\bf u}\right)\) and the solution \(\bf u\). Thus, this approach of computing and storing the weights is quite memory-intensive.
  • The variable offset denotes the offset in the complete array from where the weights for interpolation along the current interpolation dimension (dir ) are stored.

Reference:

Parameters
fCArray of cell-centered values of the function \({\bf f}\left({\bf u}\right)\)
uCArray of cell-centered values of the solution \({\bf u}\)
xGrid coordinates
dirSpatial dimension along which to interpolation
sObject of type HyPar containing solver-related variables
mObject of type MPIVariables containing MPI-related variables

Definition at line 111 of file WENOFifthOrderCalculateWeights.c.

119 {
120  HyPar *solver = (HyPar*) s;
121  WENOParameters *weno = (WENOParameters*) solver->interp;
122  MPIVariables *mpi = (MPIVariables*) m;
123  int i;
124  double *ww1LF, *ww2LF, *ww3LF, *ww1RF, *ww2RF, *ww3RF;
125  double *ww1LU, *ww2LU, *ww3LU, *ww1RU, *ww2RU, *ww3RU;
126 
127  int ghosts = solver->ghosts;
128  int ndims = solver->ndims;
129  int nvars = solver->nvars;
130  int *dim = solver->dim_local;
131  int *stride= solver->stride_with_ghosts;
132 
133  /* define some constants */
134  static const double thirteen_by_twelve = 13.0/12.0;
135  static const double one_fourth = 1.0/4.0;
136 
137  /* calculate dimension offset */
138  int offset = weno->offset[dir];
139 
140  /* create index and bounds for the outer loop, i.e., to loop over all 1D lines along
141  dimension "dir" */
142  int indexC[ndims], indexI[ndims], index_outer[ndims], bounds_outer[ndims], bounds_inter[ndims];
143  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
144  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
145  int N_outer; _ArrayProduct1D_(bounds_outer,ndims,N_outer);
146 
147  ww1LF = weno->w1 + offset;
148  ww2LF = weno->w2 + offset;
149  ww3LF = weno->w3 + offset;
150  ww1RF = weno->w1 + 2*weno->size + offset;
151  ww2RF = weno->w2 + 2*weno->size + offset;
152  ww3RF = weno->w3 + 2*weno->size + offset;
153  ww1LU = weno->w1 + weno->size + offset;
154  ww2LU = weno->w2 + weno->size + offset;
155  ww3LU = weno->w3 + weno->size + offset;
156  ww1RU = weno->w1 + 2*weno->size + weno->size + offset;
157  ww2RU = weno->w2 + 2*weno->size + weno->size + offset;
158  ww3RU = weno->w3 + 2*weno->size + weno->size + offset;
159 #pragma omp parallel for schedule(auto) default(shared) private(i,index_outer,indexC,indexI)
160  for (i=0; i<N_outer; i++) {
161  _ArrayIndexnD_(ndims,i,bounds_outer,index_outer,0);
162  _ArrayCopy1D_(index_outer,indexC,ndims);
163  _ArrayCopy1D_(index_outer,indexI,ndims);
164  for (indexI[dir] = 0; indexI[dir] < dim[dir]+1; indexI[dir]++) {
165  int qm1L,qm2L,qm3L,qp1L,qp2L,p,qm1R,qm2R,qm3R,qp1R,qp2R;
166  _ArrayIndex1D_(ndims,bounds_inter,indexI,0,p);
167  indexC[dir] = indexI[dir]-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1L);
168  qm3L = qm1L - 2*stride[dir];
169  qm2L = qm1L - stride[dir];
170  qp1L = qm1L + stride[dir];
171  qp2L = qm1L + 2*stride[dir];
172 
173  indexC[dir] = indexI[dir] ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1R);
174  qm3R = qm1R + 2*stride[dir];
175  qm2R = qm1R + stride[dir];
176  qp1R = qm1R - stride[dir];
177  qp2R = qm1R - 2*stride[dir];
178 
179  /* Defining stencil points */
180  double *m3LF, *m2LF, *m1LF, *p1LF, *p2LF;
181  m3LF = (fC+qm3L*nvars);
182  m2LF = (fC+qm2L*nvars);
183  m1LF = (fC+qm1L*nvars);
184  p1LF = (fC+qp1L*nvars);
185  p2LF = (fC+qp2L*nvars);
186  double *m3RF, *m2RF, *m1RF, *p1RF, *p2RF;
187  m3RF = (fC+qm3R*nvars);
188  m2RF = (fC+qm2R*nvars);
189  m1RF = (fC+qm1R*nvars);
190  p1RF = (fC+qp1R*nvars);
191  p2RF = (fC+qp2R*nvars);
192  double *m3LU, *m2LU, *m1LU, *p1LU, *p2LU;
193  m3LU = (uC+qm3L*nvars);
194  m2LU = (uC+qm2L*nvars);
195  m1LU = (uC+qm1L*nvars);
196  p1LU = (uC+qp1L*nvars);
197  p2LU = (uC+qp2L*nvars);
198  double *m3RU, *m2RU, *m1RU, *p1RU, *p2RU;
199  m3RU = (uC+qm3R*nvars);
200  m2RU = (uC+qm2R*nvars);
201  m1RU = (uC+qm1R*nvars);
202  p1RU = (uC+qp1R*nvars);
203  p2RU = (uC+qp2R*nvars);
204 
205  /* optimal weights*/
206  double c1, c2, c3;
207  if (!strcmp(solver->spatial_scheme_hyp,_FIFTH_ORDER_CRWENO_)) {
208  if ( ((mpi->ip[dir] == 0 ) && (indexI[dir] == 0 ))
209  || ((mpi->ip[dir] == mpi->iproc[dir]-1) && (indexI[dir] == dim[dir])) ) {
210  /* Use WENO5 at the physical boundaries */
214  } else {
215  /* CRWENO5 at the interior points */
219  }
220  } else {
221  /* WENO5 and HCWENO5 */
225  }
226 
227  /* calculate WENO weights */
228  _WENOWeights_v_JS_((ww1LF+p*nvars),(ww2LF+p*nvars),(ww3LF+p*nvars),c1,c2,c3,m3LF,m2LF,m1LF,p1LF,p2LF,weno->eps,nvars);
229  _WENOWeights_v_JS_((ww1RF+p*nvars),(ww2RF+p*nvars),(ww3RF+p*nvars),c1,c2,c3,m3RF,m2RF,m1RF,p1RF,p2RF,weno->eps,nvars);
230  _WENOWeights_v_JS_((ww1LU+p*nvars),(ww2LU+p*nvars),(ww3LU+p*nvars),c1,c2,c3,m3LU,m2LU,m1LU,p1LU,p2LU,weno->eps,nvars);
231  _WENOWeights_v_JS_((ww1RU+p*nvars),(ww2RU+p*nvars),(ww3RU+p*nvars),c1,c2,c3,m3RU,m2RU,m1RU,p1RU,p2RU,weno->eps,nvars);
232  }
233  }
234 
235  return(0);
236 }
#define _CRWENO_OPTIMAL_WEIGHT_1_
int nvars
Definition: hypar.h:29
#define _WENO_OPTIMAL_WEIGHT_2_
#define _ArrayIndexnD_(N, index, imax, i, ghost)
int * stride_with_ghosts
Definition: hypar.h:414
#define _CRWENO_OPTIMAL_WEIGHT_2_
int ndims
Definition: hypar.h:26
#define _CRWENO_OPTIMAL_WEIGHT_3_
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _WENOWeights_v_JS_(w1, w2, w3, c1, c2, c3, m3, m2, m1, p1, p2, eps, N)
char spatial_scheme_hyp[_MAX_STRING_SIZE_]
Definition: hypar.h:84
#define _WENO_OPTIMAL_WEIGHT_1_
#define _ArrayIndex1D_(N, imax, i, ghost, index)
Structure of variables/parameters needed by the WENO-type scheme.
int * dim_local
Definition: hypar.h:37
void * interp
Definition: hypar.h:362
#define _FIFTH_ORDER_CRWENO_
Definition: interpolation.h:28
int ghosts
Definition: hypar.h:52
#define _WENO_OPTIMAL_WEIGHT_3_
Structure of MPI-related variables.
#define _ArrayCopy1D_(x, y, size)
#define _ArrayProduct1D_(x, size, p)

◆ WENOFifthOrderCalculateWeightsM()

int WENOFifthOrderCalculateWeightsM ( double *  fC,
double *  uC,
double *  x,
int  dir,
void *  s,
void *  m 
)
static

Computes the nonlinear weights for the 5th order component-wise WENO-type schemes using the mapped formulation of Henrick, Aslam & Powers:

\begin{eqnarray} \omega_k &=& \frac {a_k} {\sum_{j=1}^3 a_j },\ a_k = \frac {\tilde{\omega}_k \left( c_k + c_k^2 - 3c_k\tilde{\omega}_k + \tilde{\omega}_k^2\right)} {c_k^2 + \tilde{\omega}_k\left(1-2c_k\right)}, \\ \tilde{\omega}_k &=& \frac {\tilde{a}_k} {\sum_{j=1}^3 \tilde{a}_j },\ \tilde{a}_k = \frac {c_k} {\left(\beta_k+\epsilon\right)^p},\ k = 1,2,3, \end{eqnarray}

where \(c_k\) are the optimal weights, \(p\) is hardcoded to \(2\), and \(\epsilon\) is an input parameter (WENOParameters::eps) (typically \(10^{-6}\)). The smoothness indicators \(\beta_k\) are given by:

\begin{eqnarray} \beta_1 &=& \frac{13}{12} \left(f_{j-2}-2f_{j-1}+f_j\right)^2 + \frac{1}{4}\left(f_{j-2}-4f_{j-1}+3f_j\right)^2 \\ \beta_2 &=& \frac{13}{12} \left(f_{j-1}-2f_j+f_{j+1}\right)^2 + \frac{1}{4}\left(f_{j-1}-f_{j+1}\right)^2 \\ \beta_3 &=& \frac{13}{12} \left(f_j-2f_{j+1}+f_{j+2}\right)^2 + \frac{1}{4}\left(3f_j-4f_{j+1}+f_{j+2}\right)^2 \end{eqnarray}

Notes:

  • This function computes the weights for the entire grid (for interpolation along a given spatial dimension dir ). Thus, it loops over all grid lines along dir.
  • The weights are computed for all components, for both the left- and right-biased interpolations, and for both the flux function \({\bf f}\left({\bf u}\right)\) and the solution \(\bf u\). Thus, this approach of computing and storing the weights is quite memory-intensive.
  • The variable offset denotes the offset in the complete array from where the weights for interpolation along the current interpolation dimension (dir ) are stored.

Reference:

Parameters
fCArray of cell-centered values of the function \({\bf f}\left({\bf u}\right)\)
uCArray of cell-centered values of the solution \({\bf u}\)
xGrid coordinates
dirSpatial dimension along which to interpolation
sObject of type HyPar containing solver-related variables
mObject of type MPIVariables containing MPI-related variables

Definition at line 265 of file WENOFifthOrderCalculateWeights.c.

273 {
274  HyPar *solver = (HyPar*) s;
275  WENOParameters *weno = (WENOParameters*) solver->interp;
276  MPIVariables *mpi = (MPIVariables*) m;
277  int i;
278  double *ww1LF, *ww2LF, *ww3LF, *ww1RF, *ww2RF, *ww3RF;
279  double *ww1LU, *ww2LU, *ww3LU, *ww1RU, *ww2RU, *ww3RU;
280 
281  int ghosts = solver->ghosts;
282  int ndims = solver->ndims;
283  int nvars = solver->nvars;
284  int *dim = solver->dim_local;
285  int *stride= solver->stride_with_ghosts;
286 
287  /* define some constants */
288  static const double thirteen_by_twelve = 13.0/12.0;
289  static const double one_fourth = 1.0/4.0;
290 
291  /* calculate dimension offset */
292  int offset = weno->offset[dir];
293 
294  /* create index and bounds for the outer loop, i.e., to loop over all 1D lines along
295  dimension "dir" */
296  int indexC[ndims], indexI[ndims], index_outer[ndims], bounds_outer[ndims], bounds_inter[ndims];
297  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
298  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
299  int N_outer; _ArrayProduct1D_(bounds_outer,ndims,N_outer);
300 
301  ww1LF = weno->w1 + offset;
302  ww2LF = weno->w2 + offset;
303  ww3LF = weno->w3 + offset;
304  ww1RF = weno->w1 + 2*weno->size + offset;
305  ww2RF = weno->w2 + 2*weno->size + offset;
306  ww3RF = weno->w3 + 2*weno->size + offset;
307  ww1LU = weno->w1 + weno->size + offset;
308  ww2LU = weno->w2 + weno->size + offset;
309  ww3LU = weno->w3 + weno->size + offset;
310  ww1RU = weno->w1 + 2*weno->size + weno->size + offset;
311  ww2RU = weno->w2 + 2*weno->size + weno->size + offset;
312  ww3RU = weno->w3 + 2*weno->size + weno->size + offset;
313 
314 #if defined(CPU_STAT)
315  clock_t startTime, endTime;
316  double copyTime = 0.0;
317  startTime = clock();
318 #endif
319 
320 #pragma omp parallel for schedule(auto) default(shared) private(i,index_outer,indexC,indexI)
321  for (i=0; i<N_outer; i++) {
322  _ArrayIndexnD_(ndims,i,bounds_outer,index_outer,0);
323  _ArrayCopy1D_(index_outer,indexC,ndims);
324  _ArrayCopy1D_(index_outer,indexI,ndims);
325  for (indexI[dir] = 0; indexI[dir] < dim[dir]+1; indexI[dir]++) {
326  int qm1L,qm2L,qm3L,qp1L,qp2L,p,qm1R,qm2R,qm3R,qp1R,qp2R;
327  _ArrayIndex1D_(ndims,bounds_inter,indexI,0,p);
328  indexC[dir] = indexI[dir]-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1L);
329  qm3L = qm1L - 2*stride[dir];
330  qm2L = qm1L - stride[dir];
331  qp1L = qm1L + stride[dir];
332  qp2L = qm1L + 2*stride[dir];
333 
334  indexC[dir] = indexI[dir] ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1R);
335  qm3R = qm1R + 2*stride[dir];
336  qm2R = qm1R + stride[dir];
337  qp1R = qm1R - stride[dir];
338  qp2R = qm1R - 2*stride[dir];
339 
340  /* Defining stencil points */
341  double *m3LF, *m2LF, *m1LF, *p1LF, *p2LF;
342  m3LF = (fC+qm3L*nvars);
343  m2LF = (fC+qm2L*nvars);
344  m1LF = (fC+qm1L*nvars);
345  p1LF = (fC+qp1L*nvars);
346  p2LF = (fC+qp2L*nvars);
347  double *m3RF, *m2RF, *m1RF, *p1RF, *p2RF;
348  m3RF = (fC+qm3R*nvars);
349  m2RF = (fC+qm2R*nvars);
350  m1RF = (fC+qm1R*nvars);
351  p1RF = (fC+qp1R*nvars);
352  p2RF = (fC+qp2R*nvars);
353  double *m3LU, *m2LU, *m1LU, *p1LU, *p2LU;
354  m3LU = (uC+qm3L*nvars);
355  m2LU = (uC+qm2L*nvars);
356  m1LU = (uC+qm1L*nvars);
357  p1LU = (uC+qp1L*nvars);
358  p2LU = (uC+qp2L*nvars);
359  double *m3RU, *m2RU, *m1RU, *p1RU, *p2RU;
360  m3RU = (uC+qm3R*nvars);
361  m2RU = (uC+qm2R*nvars);
362  m1RU = (uC+qm1R*nvars);
363  p1RU = (uC+qp1R*nvars);
364  p2RU = (uC+qp2R*nvars);
365 
366  /* optimal weights*/
367  double c1, c2, c3;
368  if (!strcmp(solver->spatial_scheme_hyp,_FIFTH_ORDER_CRWENO_)) {
369  if ( ((mpi->ip[dir] == 0 ) && (indexI[dir] == 0 ))
370  || ((mpi->ip[dir] == mpi->iproc[dir]-1) && (indexI[dir] == dim[dir])) ) {
371  /* Use WENO5 at the physical boundaries */
375  } else {
376  /* CRWENO5 at the interior points */
380  }
381  } else {
382  /* WENO5 and HCWENO5 */
386  }
387 
388  /* calculate WENO weights */
389  _WENOWeights_v_M_((ww1LF+p*nvars),(ww2LF+p*nvars),(ww3LF+p*nvars),c1,c2,c3,m3LF,m2LF,m1LF,p1LF,p2LF,weno->eps,nvars);
390  _WENOWeights_v_M_((ww1RF+p*nvars),(ww2RF+p*nvars),(ww3RF+p*nvars),c1,c2,c3,m3RF,m2RF,m1RF,p1RF,p2RF,weno->eps,nvars);
391  _WENOWeights_v_M_((ww1LU+p*nvars),(ww2LU+p*nvars),(ww3LU+p*nvars),c1,c2,c3,m3LU,m2LU,m1LU,p1LU,p2LU,weno->eps,nvars);
392  _WENOWeights_v_M_((ww1RU+p*nvars),(ww2RU+p*nvars),(ww3RU+p*nvars),c1,c2,c3,m3RU,m2RU,m1RU,p1RU,p2RU,weno->eps,nvars);
393  }
394  }
395 
396 #if defined(CPU_STAT)
397  endTime = clock();
398  printf("WENOFifthOrderCalculateWeightsM CPU time = %8.6f dir = %d\n",
399  (double)(endTime - startTime) / CLOCKS_PER_SEC, dir);
400 #endif
401 
402  return(0);
403 }
#define _WENOWeights_v_M_(w1, w2, w3, c1, c2, c3, m3, m2, m1, p1, p2, eps, N)
#define _CRWENO_OPTIMAL_WEIGHT_1_
int nvars
Definition: hypar.h:29
#define _WENO_OPTIMAL_WEIGHT_2_
#define _ArrayIndexnD_(N, index, imax, i, ghost)
int * stride_with_ghosts
Definition: hypar.h:414
#define _CRWENO_OPTIMAL_WEIGHT_2_
int ndims
Definition: hypar.h:26
#define _CRWENO_OPTIMAL_WEIGHT_3_
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
char spatial_scheme_hyp[_MAX_STRING_SIZE_]
Definition: hypar.h:84
#define _WENO_OPTIMAL_WEIGHT_1_
#define _ArrayIndex1D_(N, imax, i, ghost, index)
Structure of variables/parameters needed by the WENO-type scheme.
int * dim_local
Definition: hypar.h:37
void * interp
Definition: hypar.h:362
#define _FIFTH_ORDER_CRWENO_
Definition: interpolation.h:28
int ghosts
Definition: hypar.h:52
#define _WENO_OPTIMAL_WEIGHT_3_
Structure of MPI-related variables.
#define _ArrayCopy1D_(x, y, size)
#define _ArrayProduct1D_(x, size, p)

◆ WENOFifthOrderCalculateWeightsZ()

int WENOFifthOrderCalculateWeightsZ ( double *  fC,
double *  uC,
double *  x,
int  dir,
void *  s,
void *  m 
)
static

Computes the nonlinear weights for the 5th order component-wise WENO-type schemes using the WENO-Z formulation:

\begin{equation} \omega_k = \frac {a_k} {\sum_{j=1}^3 a_j },\ a_k = c_k \left( 1 + \frac{\tau_5}{\beta_k+\epsilon} \right)^p,\ k = 1,2,3, \end{equation}

where \(c_k\) are the optimal weights, \(p\) is hardcoded to \(2\), and \(\epsilon\) is an input parameter (WENOParameters::eps) (typically \(10^{-6}\)). The smoothness indicators \(\beta_k\) are given by:

\begin{eqnarray} \beta_1 &=& \frac{13}{12} \left(f_{j-2}-2f_{j-1}+f_j\right)^2 + \frac{1}{4}\left(f_{j-2}-4f_{j-1}+3f_j\right)^2 \\ \beta_2 &=& \frac{13}{12} \left(f_{j-1}-2f_j+f_{j+1}\right)^2 + \frac{1}{4}\left(f_{j-1}-f_{j+1}\right)^2 \\ \beta_3 &=& \frac{13}{12} \left(f_j-2f_{j+1}+f_{j+2}\right)^2 + \frac{1}{4}\left(3f_j-4f_{j+1}+f_{j+2}\right)^2, \end{eqnarray}

and \(\tau_5 = \left|\beta_1 - \beta_3 \right|\).

Notes:

  • This function computes the weights for the entire grid (for interpolation along a given spatial dimension dir ). Thus, it loops over all grid lines along dir.
  • The weights are computed for all components, for both the left- and right-biased interpolations, and for both the flux function \({\bf f}\left({\bf u}\right)\) and the solution \(\bf u\). Thus, this approach of computing and storing the weights is quite memory-intensive.
  • The variable offset denotes the offset in the complete array from where the weights for interpolation along the current interpolation dimension (dir ) are stored.

Reference:

Parameters
fCArray of cell-centered values of the function \({\bf f}\left({\bf u}\right)\)
uCArray of cell-centered values of the solution \({\bf u}\)
xGrid coordinates
dirSpatial dimension along which to interpolation
sObject of type HyPar containing solver-related variables
mObject of type MPIVariables containing MPI-related variables

Definition at line 434 of file WENOFifthOrderCalculateWeights.c.

442 {
443  HyPar *solver = (HyPar*) s;
444  WENOParameters *weno = (WENOParameters*) solver->interp;
445  MPIVariables *mpi = (MPIVariables*) m;
446  int i;
447  double *ww1LF, *ww2LF, *ww3LF, *ww1RF, *ww2RF, *ww3RF;
448  double *ww1LU, *ww2LU, *ww3LU, *ww1RU, *ww2RU, *ww3RU;
449 
450  int ghosts = solver->ghosts;
451  int ndims = solver->ndims;
452  int nvars = solver->nvars;
453  int *dim = solver->dim_local;
454  int *stride= solver->stride_with_ghosts;
455 
456  /* define some constants */
457  static const double thirteen_by_twelve = 13.0/12.0;
458  static const double one_fourth = 1.0/4.0;
459 
460  /* calculate dimension offset */
461  int offset = weno->offset[dir];
462 
463  /* create index and bounds for the outer loop, i.e., to loop over all 1D lines along
464  dimension "dir" */
465  int indexC[ndims], indexI[ndims], index_outer[ndims], bounds_outer[ndims], bounds_inter[ndims];
466  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
467  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
468  int N_outer; _ArrayProduct1D_(bounds_outer,ndims,N_outer);
469 
470  ww1LF = weno->w1 + offset;
471  ww2LF = weno->w2 + offset;
472  ww3LF = weno->w3 + offset;
473  ww1RF = weno->w1 + 2*weno->size + offset;
474  ww2RF = weno->w2 + 2*weno->size + offset;
475  ww3RF = weno->w3 + 2*weno->size + offset;
476  ww1LU = weno->w1 + weno->size + offset;
477  ww2LU = weno->w2 + weno->size + offset;
478  ww3LU = weno->w3 + weno->size + offset;
479  ww1RU = weno->w1 + 2*weno->size + weno->size + offset;
480  ww2RU = weno->w2 + 2*weno->size + weno->size + offset;
481  ww3RU = weno->w3 + 2*weno->size + weno->size + offset;
482 #pragma omp parallel for schedule(auto) default(shared) private(i,index_outer,indexC,indexI)
483  for (i=0; i<N_outer; i++) {
484  _ArrayIndexnD_(ndims,i,bounds_outer,index_outer,0);
485  _ArrayCopy1D_(index_outer,indexC,ndims);
486  _ArrayCopy1D_(index_outer,indexI,ndims);
487  for (indexI[dir] = 0; indexI[dir] < dim[dir]+1; indexI[dir]++) {
488  int qm1L,qm2L,qm3L,qp1L,qp2L,p,qm1R,qm2R,qm3R,qp1R,qp2R;
489  _ArrayIndex1D_(ndims,bounds_inter,indexI,0,p);
490  indexC[dir] = indexI[dir]-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1L);
491  qm3L = qm1L - 2*stride[dir];
492  qm2L = qm1L - stride[dir];
493  qp1L = qm1L + stride[dir];
494  qp2L = qm1L + 2*stride[dir];
495 
496  indexC[dir] = indexI[dir] ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1R);
497  qm3R = qm1R + 2*stride[dir];
498  qm2R = qm1R + stride[dir];
499  qp1R = qm1R - stride[dir];
500  qp2R = qm1R - 2*stride[dir];
501 
502  /* Defining stencil points */
503  double *m3LF, *m2LF, *m1LF, *p1LF, *p2LF;
504  m3LF = (fC+qm3L*nvars);
505  m2LF = (fC+qm2L*nvars);
506  m1LF = (fC+qm1L*nvars);
507  p1LF = (fC+qp1L*nvars);
508  p2LF = (fC+qp2L*nvars);
509  double *m3RF, *m2RF, *m1RF, *p1RF, *p2RF;
510  m3RF = (fC+qm3R*nvars);
511  m2RF = (fC+qm2R*nvars);
512  m1RF = (fC+qm1R*nvars);
513  p1RF = (fC+qp1R*nvars);
514  p2RF = (fC+qp2R*nvars);
515  double *m3LU, *m2LU, *m1LU, *p1LU, *p2LU;
516  m3LU = (uC+qm3L*nvars);
517  m2LU = (uC+qm2L*nvars);
518  m1LU = (uC+qm1L*nvars);
519  p1LU = (uC+qp1L*nvars);
520  p2LU = (uC+qp2L*nvars);
521  double *m3RU, *m2RU, *m1RU, *p1RU, *p2RU;
522  m3RU = (uC+qm3R*nvars);
523  m2RU = (uC+qm2R*nvars);
524  m1RU = (uC+qm1R*nvars);
525  p1RU = (uC+qp1R*nvars);
526  p2RU = (uC+qp2R*nvars);
527 
528  /* optimal weights*/
529  double c1, c2, c3;
530  if (!strcmp(solver->spatial_scheme_hyp,_FIFTH_ORDER_CRWENO_)) {
531  if ( ((mpi->ip[dir] == 0 ) && (indexI[dir] == 0 ))
532  || ((mpi->ip[dir] == mpi->iproc[dir]-1) && (indexI[dir] == dim[dir])) ) {
533  /* Use WENO5 at the physical boundaries */
537  } else {
538  /* CRWENO5 at the interior points */
542  }
543  } else {
544  /* WENO5 and HCWENO5 */
548  }
549 
550  /* calculate WENO weights */
551  _WENOWeights_v_Z_((ww1LF+p*nvars),(ww2LF+p*nvars),(ww3LF+p*nvars),c1,c2,c3,m3LF,m2LF,m1LF,p1LF,p2LF,weno->eps,nvars);
552  _WENOWeights_v_Z_((ww1RF+p*nvars),(ww2RF+p*nvars),(ww3RF+p*nvars),c1,c2,c3,m3RF,m2RF,m1RF,p1RF,p2RF,weno->eps,nvars);
553  _WENOWeights_v_Z_((ww1LU+p*nvars),(ww2LU+p*nvars),(ww3LU+p*nvars),c1,c2,c3,m3LU,m2LU,m1LU,p1LU,p2LU,weno->eps,nvars);
554  _WENOWeights_v_Z_((ww1RU+p*nvars),(ww2RU+p*nvars),(ww3RU+p*nvars),c1,c2,c3,m3RU,m2RU,m1RU,p1RU,p2RU,weno->eps,nvars);
555  }
556  }
557 
558  return(0);
559 }
#define _CRWENO_OPTIMAL_WEIGHT_1_
int nvars
Definition: hypar.h:29
#define _WENO_OPTIMAL_WEIGHT_2_
#define _WENOWeights_v_Z_(w1, w2, w3, c1, c2, c3, m3, m2, m1, p1, p2, eps, N)
#define _ArrayIndexnD_(N, index, imax, i, ghost)
int * stride_with_ghosts
Definition: hypar.h:414
#define _CRWENO_OPTIMAL_WEIGHT_2_
int ndims
Definition: hypar.h:26
#define _CRWENO_OPTIMAL_WEIGHT_3_
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
char spatial_scheme_hyp[_MAX_STRING_SIZE_]
Definition: hypar.h:84
#define _WENO_OPTIMAL_WEIGHT_1_
#define _ArrayIndex1D_(N, imax, i, ghost, index)
Structure of variables/parameters needed by the WENO-type scheme.
int * dim_local
Definition: hypar.h:37
void * interp
Definition: hypar.h:362
#define _FIFTH_ORDER_CRWENO_
Definition: interpolation.h:28
int ghosts
Definition: hypar.h:52
#define _WENO_OPTIMAL_WEIGHT_3_
Structure of MPI-related variables.
#define _ArrayCopy1D_(x, y, size)
#define _ArrayProduct1D_(x, size, p)

◆ WENOFifthOrderCalculateWeightsYC()

int WENOFifthOrderCalculateWeightsYC ( double *  fC,
double *  uC,
double *  x,
int  dir,
void *  s,
void *  m 
)
static

Computes the nonlinear weights for the 5th order component-wise WENO-type schemes using the ESWENO formulation of Yamaleev & Carpenter. Note that only the formulation for the nonlinear weights is adopted and implemented here, not the ESWENO scheme as a whole.

\begin{equation} \omega_k = \frac {a_k} {\sum_{j=1}^3 a_j },\ a_k = c_k \left( 1 + \frac{\tau_5}{\beta_k+\epsilon} \right)^p,\ k = 1,2,3, \end{equation}

where \(c_k\) are the optimal weights, \(p\) is hardcoded to \(2\), and \(\epsilon\) is an input parameter (WENOParameters::eps) (typically \(10^{-6}\)). The smoothness indicators \(\beta_k\) are given by:

\begin{eqnarray} \beta_1 &=& \frac{13}{12} \left(f_{j-2}-2f_{j-1}+f_j\right)^2 + \frac{1}{4}\left(f_{j-2}-4f_{j-1}+3f_j\right)^2 \\ \beta_2 &=& \frac{13}{12} \left(f_{j-1}-2f_j+f_{j+1}\right)^2 + \frac{1}{4}\left(f_{j-1}-f_{j+1}\right)^2 \\ \beta_3 &=& \frac{13}{12} \left(f_j-2f_{j+1}+f_{j+2}\right)^2 + \frac{1}{4}\left(3f_j-4f_{j+1}+f_{j+2}\right)^2, \end{eqnarray}

and \(\tau_5 = \left( f_{j-2}-4f_{j-1}+6f_j-4f_{j+1}+f_{j+2} \right)^2\).

Notes:

  • This function computes the weights for the entire grid (for interpolation along a given spatial dimension dir ). Thus, it loops over all grid lines along dir.
  • The weights are computed for all components, for both the left- and right-biased interpolations, and for both the flux function \({\bf f}\left({\bf u}\right)\) and the solution \(\bf u\). Thus, this approach of computing and storing the weights is quite memory-intensive.
  • The variable offset denotes the offset in the complete array from where the weights for interpolation along the current interpolation dimension (dir ) are stored.

Reference:

Parameters
fCArray of cell-centered values of the function \({\bf f}\left({\bf u}\right)\)
uCArray of cell-centered values of the solution \({\bf u}\)
xGrid coordinates
dirSpatial dimension along which to interpolation
sObject of type HyPar containing solver-related variables
mObject of type MPIVariables containing MPI-related variables

Definition at line 590 of file WENOFifthOrderCalculateWeights.c.

598 {
599  HyPar *solver = (HyPar*) s;
600  WENOParameters *weno = (WENOParameters*) solver->interp;
601  MPIVariables *mpi = (MPIVariables*) m;
602  int i;
603  double *ww1LF, *ww2LF, *ww3LF, *ww1RF, *ww2RF, *ww3RF;
604  double *ww1LU, *ww2LU, *ww3LU, *ww1RU, *ww2RU, *ww3RU;
605 
606  int ghosts = solver->ghosts;
607  int ndims = solver->ndims;
608  int nvars = solver->nvars;
609  int *dim = solver->dim_local;
610  int *stride= solver->stride_with_ghosts;
611 
612  /* define some constants */
613  static const double thirteen_by_twelve = 13.0/12.0;
614  static const double one_fourth = 1.0/4.0;
615 
616  /* calculate dimension offset */
617  int offset = weno->offset[dir];
618 
619  /* create index and bounds for the outer loop, i.e., to loop over all 1D lines along
620  dimension "dir" */
621  int indexC[ndims], indexI[ndims], index_outer[ndims], bounds_outer[ndims], bounds_inter[ndims];
622  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
623  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
624  int N_outer; _ArrayProduct1D_(bounds_outer,ndims,N_outer);
625 
626  ww1LF = weno->w1 + offset;
627  ww2LF = weno->w2 + offset;
628  ww3LF = weno->w3 + offset;
629  ww1RF = weno->w1 + 2*weno->size + offset;
630  ww2RF = weno->w2 + 2*weno->size + offset;
631  ww3RF = weno->w3 + 2*weno->size + offset;
632  ww1LU = weno->w1 + weno->size + offset;
633  ww2LU = weno->w2 + weno->size + offset;
634  ww3LU = weno->w3 + weno->size + offset;
635  ww1RU = weno->w1 + 2*weno->size + weno->size + offset;
636  ww2RU = weno->w2 + 2*weno->size + weno->size + offset;
637  ww3RU = weno->w3 + 2*weno->size + weno->size + offset;
638 
639 #if defined(CPU_STAT)
640  clock_t cpu_start, cpu_end;
641  cpu_start = clock();
642 #endif
643 
644 #pragma omp parallel for schedule(auto) default(shared) private(i,index_outer,indexC,indexI)
645  for (i=0; i<N_outer; i++) {
646  _ArrayIndexnD_(ndims,i,bounds_outer,index_outer,0);
647  _ArrayCopy1D_(index_outer,indexC,ndims);
648  _ArrayCopy1D_(index_outer,indexI,ndims);
649  for (indexI[dir] = 0; indexI[dir] < dim[dir]+1; indexI[dir]++) {
650  int qm1L,qm2L,qm3L,qp1L,qp2L,p,qm1R,qm2R,qm3R,qp1R,qp2R;
651  _ArrayIndex1D_(ndims,bounds_inter,indexI,0,p);
652  indexC[dir] = indexI[dir]-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1L);
653  qm3L = qm1L - 2*stride[dir];
654  qm2L = qm1L - stride[dir];
655  qp1L = qm1L + stride[dir];
656  qp2L = qm1L + 2*stride[dir];
657 
658  indexC[dir] = indexI[dir] ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1R);
659  qm3R = qm1R + 2*stride[dir];
660  qm2R = qm1R + stride[dir];
661  qp1R = qm1R - stride[dir];
662  qp2R = qm1R - 2*stride[dir];
663 
664  /* Defining stencil points */
665  double *m3LF, *m2LF, *m1LF, *p1LF, *p2LF;
666  m3LF = (fC+qm3L*nvars);
667  m2LF = (fC+qm2L*nvars);
668  m1LF = (fC+qm1L*nvars);
669  p1LF = (fC+qp1L*nvars);
670  p2LF = (fC+qp2L*nvars);
671  double *m3RF, *m2RF, *m1RF, *p1RF, *p2RF;
672  m3RF = (fC+qm3R*nvars);
673  m2RF = (fC+qm2R*nvars);
674  m1RF = (fC+qm1R*nvars);
675  p1RF = (fC+qp1R*nvars);
676  p2RF = (fC+qp2R*nvars);
677  double *m3LU, *m2LU, *m1LU, *p1LU, *p2LU;
678  m3LU = (uC+qm3L*nvars);
679  m2LU = (uC+qm2L*nvars);
680  m1LU = (uC+qm1L*nvars);
681  p1LU = (uC+qp1L*nvars);
682  p2LU = (uC+qp2L*nvars);
683  double *m3RU, *m2RU, *m1RU, *p1RU, *p2RU;
684  m3RU = (uC+qm3R*nvars);
685  m2RU = (uC+qm2R*nvars);
686  m1RU = (uC+qm1R*nvars);
687  p1RU = (uC+qp1R*nvars);
688  p2RU = (uC+qp2R*nvars);
689 
690  /* optimal weights*/
691  double c1, c2, c3;
692  if (!strcmp(solver->spatial_scheme_hyp,_FIFTH_ORDER_CRWENO_)) {
693  if ( ((mpi->ip[dir] == 0 ) && (indexI[dir] == 0 ))
694  || ((mpi->ip[dir] == mpi->iproc[dir]-1) && (indexI[dir] == dim[dir])) ) {
695  /* Use WENO5 at the physical boundaries */
699  } else {
700  /* CRWENO5 at the interior points */
704  }
705  } else {
706  /* WENO5 and HCWENO5 */
710  }
711 
712  /* calculate WENO weights */
713  _WENOWeights_v_YC_((ww1LF+p*nvars),(ww2LF+p*nvars),(ww3LF+p*nvars),c1,c2,c3,m3LF,m2LF,m1LF,p1LF,p2LF,weno->eps,nvars);
714  _WENOWeights_v_YC_((ww1RF+p*nvars),(ww2RF+p*nvars),(ww3RF+p*nvars),c1,c2,c3,m3RF,m2RF,m1RF,p1RF,p2RF,weno->eps,nvars);
715  _WENOWeights_v_YC_((ww1LU+p*nvars),(ww2LU+p*nvars),(ww3LU+p*nvars),c1,c2,c3,m3LU,m2LU,m1LU,p1LU,p2LU,weno->eps,nvars);
716  _WENOWeights_v_YC_((ww1RU+p*nvars),(ww2RU+p*nvars),(ww3RU+p*nvars),c1,c2,c3,m3RU,m2RU,m1RU,p1RU,p2RU,weno->eps,nvars);
717  }
718  }
719 
720 #if defined(CPU_STAT)
721  cpu_end = clock();
722  printf("WENOFifthOrderCalculateWeightsYC:\n");
723  printf(" CPU time = %8.6lf dir = %d\n", (double)(cpu_end - cpu_start) / CLOCKS_PER_SEC, dir);
724 #endif
725 
726  return(0);
727 }
#define _CRWENO_OPTIMAL_WEIGHT_1_
int nvars
Definition: hypar.h:29
#define _WENO_OPTIMAL_WEIGHT_2_
#define _ArrayIndexnD_(N, index, imax, i, ghost)
int * stride_with_ghosts
Definition: hypar.h:414
#define _CRWENO_OPTIMAL_WEIGHT_2_
int ndims
Definition: hypar.h:26
#define _CRWENO_OPTIMAL_WEIGHT_3_
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
char spatial_scheme_hyp[_MAX_STRING_SIZE_]
Definition: hypar.h:84
#define _WENO_OPTIMAL_WEIGHT_1_
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _WENOWeights_v_YC_(w1, w2, w3, c1, c2, c3, m3, m2, m1, p1, p2, eps, N)
Structure of variables/parameters needed by the WENO-type scheme.
int * dim_local
Definition: hypar.h:37
void * interp
Definition: hypar.h:362
#define _FIFTH_ORDER_CRWENO_
Definition: interpolation.h:28
int ghosts
Definition: hypar.h:52
#define _WENO_OPTIMAL_WEIGHT_3_
Structure of MPI-related variables.
#define _ArrayCopy1D_(x, y, size)
#define _ArrayProduct1D_(x, size, p)

◆ WENOFifthOrderCalculateWeightsCharJS()

int WENOFifthOrderCalculateWeightsCharJS ( double *  fC,
double *  uC,
double *  x,
int  dir,
void *  s,
void *  m 
)
static

Computes the nonlinear weights for the 5th order characteristic-based WENO-type schemes using the original formulation of Jiang & Shu:

\begin{equation} \omega_k = \frac {a_k} {\sum_{j=1}^3 a_j },\ a_k = \frac {c_k} {\left(\beta_k+\epsilon\right)^p},\ k = 1,2,3, \end{equation}

where \(c_k\) are the optimal weights, \(p\) is hardcoded to \(2\), and \(\epsilon\) is an input parameter (WENOParameters::eps) (typically \(10^{-6}\)). The smoothness indicators \(\beta_k\) are given by:

\begin{eqnarray} \beta_1 &=& \frac{13}{12} \left(\alpha_{j-2}-2\alpha_{j-1}+\alpha_j\right)^2 + \frac{1}{4}\left(\alpha_{j-2}-4\alpha_{j-1}+3\alpha_j\right)^2 \\ \beta_2 &=& \frac{13}{12} \left(\alpha_{j-1}-2\alpha_j+\alpha_{j+1}\right)^2 + \frac{1}{4}\left(\alpha_{j-1}-\alpha_{j+1}\right)^2 \\ \beta_3 &=& \frac{13}{12} \left(\alpha_j-2\alpha_{j+1}+\alpha_{j+2}\right)^2 + \frac{1}{4}\left(3\alpha_j-4\alpha_{j+1}+\alpha_{j+2}\right)^2 \end{eqnarray}

where \(\alpha\) is the characteristic flux or the solution.

Notes:

  • This function computes the weights for the entire grid (for interpolation along a given spatial dimension dir ). Thus, it loops over all grid lines along dir.
  • The weights are computed for all components, for both the left- and right-biased interpolations, and for both the flux function \({\bf f}\left({\bf u}\right)\) and the solution \(\bf u\). Thus, this approach of computing and storing the weights is quite memory-intensive.
  • The variable offset denotes the offset in the complete array from where the weights for interpolation along the current interpolation dimension (dir ) are stored.
  • This function requires functions to compute the average state and the left eigenvectors for the characteristic decomposition. These are provided by the physical model through

Reference:

Parameters
fCArray of cell-centered values of the function \({\bf f}\left({\bf u}\right)\)
uCArray of cell-centered values of the solution \({\bf u}\)
xGrid coordinates
dirSpatial dimension along which to interpolation
sObject of type HyPar containing solver-related variables
mObject of type MPIVariables containing MPI-related variables

Definition at line 760 of file WENOFifthOrderCalculateWeights.c.

768 {
769  HyPar *solver = (HyPar*) s;
770  WENOParameters *weno = (WENOParameters*) solver->interp;
771  MPIVariables *mpi = (MPIVariables*) m;
772  int i;
773  double *ww1LF, *ww2LF, *ww3LF, *ww1RF, *ww2RF, *ww3RF;
774  double *ww1LU, *ww2LU, *ww3LU, *ww1RU, *ww2RU, *ww3RU;
775 
776  int ghosts = solver->ghosts;
777  int ndims = solver->ndims;
778  int nvars = solver->nvars;
779  int *dim = solver->dim_local;
780  int *stride= solver->stride_with_ghosts;
781 
782  /* define some constants */
783  static const double thirteen_by_twelve = 13.0/12.0;
784  static const double one_fourth = 1.0/4.0;
785 
786  /* calculate dimension offset */
787  int offset = weno->offset[dir];
788 
789  /* create index and bounds for the outer loop, i.e., to loop over all 1D lines along
790  dimension "dir" */
791  int indexC[ndims], indexI[ndims], index_outer[ndims], bounds_outer[ndims], bounds_inter[ndims];
792  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
793  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
794  int N_outer; _ArrayProduct1D_(bounds_outer,ndims,N_outer);
795 
796  /* allocate arrays for the averaged state, eigenvectors and characteristic interpolated f */
797  double L[nvars*nvars], uavg[nvars];
798 
799  ww1LF = weno->w1 + offset;
800  ww2LF = weno->w2 + offset;
801  ww3LF = weno->w3 + offset;
802  ww1RF = weno->w1 + 2*weno->size + offset;
803  ww2RF = weno->w2 + 2*weno->size + offset;
804  ww3RF = weno->w3 + 2*weno->size + offset;
805  ww1LU = weno->w1 + weno->size + offset;
806  ww2LU = weno->w2 + weno->size + offset;
807  ww3LU = weno->w3 + weno->size + offset;
808  ww1RU = weno->w1 + 2*weno->size + weno->size + offset;
809  ww2RU = weno->w2 + 2*weno->size + weno->size + offset;
810  ww3RU = weno->w3 + 2*weno->size + weno->size + offset;
811 #pragma omp parallel for schedule(auto) default(shared) private(i,index_outer,indexC,indexI)
812  for (i=0; i<N_outer; i++) {
813  _ArrayIndexnD_(ndims,i,bounds_outer,index_outer,0);
814  _ArrayCopy1D_(index_outer,indexC,ndims);
815  _ArrayCopy1D_(index_outer,indexI,ndims);
816  for (indexI[dir] = 0; indexI[dir] < dim[dir]+1; indexI[dir]++) {
817  int qm1L,qm2L,qm3L,qp1L,qp2L,p,qm1R,qm2R,qm3R,qp1R,qp2R;
818  _ArrayIndex1D_(ndims,bounds_inter,indexI,0,p);
819  indexC[dir] = indexI[dir]-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1L);
820  qm3L = qm1L - 2*stride[dir];
821  qm2L = qm1L - stride[dir];
822  qp1L = qm1L + stride[dir];
823  qp2L = qm1L + 2*stride[dir];
824 
825  indexC[dir] = indexI[dir] ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1R);
826  qm3R = qm1R + 2*stride[dir];
827  qm2R = qm1R + stride[dir];
828  qp1R = qm1R - stride[dir];
829  qp2R = qm1R - 2*stride[dir];
830 
831  /* find averaged state and left eigenvectors at this interface */
832  IERR solver->AveragingFunction(uavg,(uC+nvars*qm1L),(uC+nvars*qp1L),solver->physics); CHECKERR(ierr);
833  IERR solver->GetLeftEigenvectors(uavg,L,solver->physics,dir); CHECKERR(ierr);
834 
835  /* Defining stencil points */
836  double m3LF[nvars], m2LF[nvars], m1LF[nvars], p1LF[nvars], p2LF[nvars];
837  double m3RF[nvars], m2RF[nvars], m1RF[nvars], p1RF[nvars], p2RF[nvars];
838  double m3LU[nvars], m2LU[nvars], m1LU[nvars], p1LU[nvars], p2LU[nvars];
839  double m3RU[nvars], m2RU[nvars], m1RU[nvars], p1RU[nvars], p2RU[nvars];
840 
841  MatVecMult(nvars,m3LF,L,(fC+nvars*qm3L));
842  MatVecMult(nvars,m2LF,L,(fC+nvars*qm2L));
843  MatVecMult(nvars,m1LF,L,(fC+nvars*qm1L));
844  MatVecMult(nvars,p1LF,L,(fC+nvars*qp1L));
845  MatVecMult(nvars,p2LF,L,(fC+nvars*qp2L));
846 
847  MatVecMult(nvars,m3RF,L,(fC+nvars*qm3R));
848  MatVecMult(nvars,m2RF,L,(fC+nvars*qm2R));
849  MatVecMult(nvars,m1RF,L,(fC+nvars*qm1R));
850  MatVecMult(nvars,p1RF,L,(fC+nvars*qp1R));
851  MatVecMult(nvars,p2RF,L,(fC+nvars*qp2R));
852 
853  MatVecMult(nvars,m3LU,L,(uC+nvars*qm3L));
854  MatVecMult(nvars,m2LU,L,(uC+nvars*qm2L));
855  MatVecMult(nvars,m1LU,L,(uC+nvars*qm1L));
856  MatVecMult(nvars,p1LU,L,(uC+nvars*qp1L));
857  MatVecMult(nvars,p2LU,L,(uC+nvars*qp2L));
858 
859  MatVecMult(nvars,m3RU,L,(uC+nvars*qm3R));
860  MatVecMult(nvars,m2RU,L,(uC+nvars*qm2R));
861  MatVecMult(nvars,m1RU,L,(uC+nvars*qm1R));
862  MatVecMult(nvars,p1RU,L,(uC+nvars*qp1R));
863  MatVecMult(nvars,p2RU,L,(uC+nvars*qp2R));
864 
865  /* optimal weights*/
866  double c1, c2, c3;
867  if (!strcmp(solver->spatial_scheme_hyp,_FIFTH_ORDER_CRWENO_)) {
868  if ( ((mpi->ip[dir] == 0 ) && (indexI[dir] == 0 ))
869  || ((mpi->ip[dir] == mpi->iproc[dir]-1) && (indexI[dir] == dim[dir])) ) {
870  /* Use WENO5 at the physical boundaries */
874  } else {
875  /* CRWENO5 at the interior points */
879  }
880  } else {
881  /* WENO5 and HCWENO5 */
885  }
886 
887  /* calculate WENO weights */
888  _WENOWeights_v_JS_((ww1LF+p*nvars),(ww2LF+p*nvars),(ww3LF+p*nvars),c1,c2,c3,m3LF,m2LF,m1LF,p1LF,p2LF,weno->eps,nvars);
889  _WENOWeights_v_JS_((ww1RF+p*nvars),(ww2RF+p*nvars),(ww3RF+p*nvars),c1,c2,c3,m3RF,m2RF,m1RF,p1RF,p2RF,weno->eps,nvars);
890  _WENOWeights_v_JS_((ww1LU+p*nvars),(ww2LU+p*nvars),(ww3LU+p*nvars),c1,c2,c3,m3LU,m2LU,m1LU,p1LU,p2LU,weno->eps,nvars);
891  _WENOWeights_v_JS_((ww1RU+p*nvars),(ww2RU+p*nvars),(ww3RU+p*nvars),c1,c2,c3,m3RU,m2RU,m1RU,p1RU,p2RU,weno->eps,nvars);
892  }
893  }
894 
895  return(0);
896 }
#define _CRWENO_OPTIMAL_WEIGHT_1_
int nvars
Definition: hypar.h:29
#define IERR
Definition: basic.h:16
#define CHECKERR(ierr)
Definition: basic.h:18
int(* AveragingFunction)(double *, double *, double *, void *)
Definition: hypar.h:354
#define _WENO_OPTIMAL_WEIGHT_2_
#define _ArrayIndexnD_(N, index, imax, i, ghost)
int * stride_with_ghosts
Definition: hypar.h:414
#define _CRWENO_OPTIMAL_WEIGHT_2_
int ndims
Definition: hypar.h:26
#define _CRWENO_OPTIMAL_WEIGHT_3_
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _WENOWeights_v_JS_(w1, w2, w3, c1, c2, c3, m3, m2, m1, p1, p2, eps, N)
char spatial_scheme_hyp[_MAX_STRING_SIZE_]
Definition: hypar.h:84
#define _WENO_OPTIMAL_WEIGHT_1_
#define _ArrayIndex1D_(N, imax, i, ghost, index)
Structure of variables/parameters needed by the WENO-type scheme.
int * dim_local
Definition: hypar.h:37
void * interp
Definition: hypar.h:362
void * physics
Definition: hypar.h:266
#define _FIFTH_ORDER_CRWENO_
Definition: interpolation.h:28
int ghosts
Definition: hypar.h:52
#define _WENO_OPTIMAL_WEIGHT_3_
Structure of MPI-related variables.
#define MatVecMult(N, y, A, x)
#define _ArrayCopy1D_(x, y, size)
#define _ArrayProduct1D_(x, size, p)
int(* GetLeftEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:357

◆ WENOFifthOrderCalculateWeightsCharM()

int WENOFifthOrderCalculateWeightsCharM ( double *  fC,
double *  uC,
double *  x,
int  dir,
void *  s,
void *  m 
)
static

Computes the nonlinear weights for the 5th order characteristic-based WENO-type schemes using the mapped formulation of Henrick, Aslam & Powers:

\begin{eqnarray} \omega_k &=& \frac {a_k} {\sum_{j=1}^3 a_j },\ a_k = \frac {\tilde{\omega}_k \left( c_k + c_k^2 - 3c_k\tilde{\omega}_k + \tilde{\omega}_k^2\right)} {c_k^2 + \tilde{\omega}_k\left(1-2c_k\right)}, \\ \tilde{\omega}_k &=& \frac {\tilde{a}_k} {\sum_{j=1}^3 \tilde{a}_j },\ \tilde{a}_k = \frac {c_k} {\left(\beta_k+\epsilon\right)^p},\ k = 1,2,3, \end{eqnarray}

where \(c_k\) are the optimal weights, \(p\) is hardcoded to \(2\), and \(\epsilon\) is an input parameter (WENOParameters::eps) (typically \(10^{-6}\)). The smoothness indicators \(\beta_k\) are given by:

\begin{eqnarray} \beta_1 &=& \frac{13}{12} \left(\alpha_{j-2}-2\alpha_{j-1}+\alpha_j\right)^2 + \frac{1}{4}\left(\alpha_{j-2}-4\alpha_{j-1}+3\alpha_j\right)^2 \\ \beta_2 &=& \frac{13}{12} \left(\alpha_{j-1}-2\alpha_j+\alpha_{j+1}\right)^2 + \frac{1}{4}\left(\alpha_{j-1}-\alpha_{j+1}\right)^2 \\ \beta_3 &=& \frac{13}{12} \left(\alpha_j-2\alpha_{j+1}+\alpha_{j+2}\right)^2 + \frac{1}{4}\left(3\alpha_j-4\alpha_{j+1}+\alpha_{j+2}\right)^2 \end{eqnarray}

where \(\alpha\) is the characteristic flux or the solution.

Notes:

  • This function computes the weights for the entire grid (for interpolation along a given spatial dimension dir ). Thus, it loops over all grid lines along dir.
  • The weights are computed for all components, for both the left- and right-biased interpolations, and for both the flux function \({\bf f}\left({\bf u}\right)\) and the solution \(\bf u\). Thus, this approach of computing and storing the weights is quite memory-intensive.
  • The variable offset denotes the offset in the complete array from where the weights for interpolation along the current interpolation dimension (dir ) are stored.
  • This function requires functions to compute the average state and the left eigenvectors for the characteristic decomposition. These are provided by the physical model through

Reference:

Parameters
fCArray of cell-centered values of the function \({\bf f}\left({\bf u}\right)\)
uCArray of cell-centered values of the solution \({\bf u}\)
xGrid coordinates
dirSpatial dimension along which to interpolation
sObject of type HyPar containing solver-related variables
mObject of type MPIVariables containing MPI-related variables

Definition at line 930 of file WENOFifthOrderCalculateWeights.c.

938 {
939  HyPar *solver = (HyPar*) s;
940  WENOParameters *weno = (WENOParameters*) solver->interp;
941  MPIVariables *mpi = (MPIVariables*) m;
942  int i;
943  double *ww1LF, *ww2LF, *ww3LF, *ww1RF, *ww2RF, *ww3RF;
944  double *ww1LU, *ww2LU, *ww3LU, *ww1RU, *ww2RU, *ww3RU;
945 
946  int ghosts = solver->ghosts;
947  int ndims = solver->ndims;
948  int nvars = solver->nvars;
949  int *dim = solver->dim_local;
950  int *stride= solver->stride_with_ghosts;
951 
952  /* define some constants */
953  static const double thirteen_by_twelve = 13.0/12.0;
954  static const double one_fourth = 1.0/4.0;
955 
956  /* calculate dimension offset */
957  int offset = weno->offset[dir];
958 
959  /* create index and bounds for the outer loop, i.e., to loop over all 1D lines along
960  dimension "dir" */
961  int indexC[ndims], indexI[ndims], index_outer[ndims], bounds_outer[ndims], bounds_inter[ndims];
962  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
963  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
964  int N_outer; _ArrayProduct1D_(bounds_outer,ndims,N_outer);
965 
966  /* allocate arrays for the averaged state, eigenvectors and characteristic interpolated f */
967  double L[nvars*nvars], uavg[nvars];
968 
969  ww1LF = weno->w1 + offset;
970  ww2LF = weno->w2 + offset;
971  ww3LF = weno->w3 + offset;
972  ww1RF = weno->w1 + 2*weno->size + offset;
973  ww2RF = weno->w2 + 2*weno->size + offset;
974  ww3RF = weno->w3 + 2*weno->size + offset;
975  ww1LU = weno->w1 + weno->size + offset;
976  ww2LU = weno->w2 + weno->size + offset;
977  ww3LU = weno->w3 + weno->size + offset;
978  ww1RU = weno->w1 + 2*weno->size + weno->size + offset;
979  ww2RU = weno->w2 + 2*weno->size + weno->size + offset;
980  ww3RU = weno->w3 + 2*weno->size + weno->size + offset;
981 #pragma omp parallel for schedule(auto) default(shared) private(i,index_outer,indexC,indexI)
982  for (i=0; i<N_outer; i++) {
983  _ArrayIndexnD_(ndims,i,bounds_outer,index_outer,0);
984  _ArrayCopy1D_(index_outer,indexC,ndims);
985  _ArrayCopy1D_(index_outer,indexI,ndims);
986  for (indexI[dir] = 0; indexI[dir] < dim[dir]+1; indexI[dir]++) {
987  int qm1L,qm2L,qm3L,qp1L,qp2L,p,qm1R,qm2R,qm3R,qp1R,qp2R;
988  _ArrayIndex1D_(ndims,bounds_inter,indexI,0,p);
989  indexC[dir] = indexI[dir]-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1L);
990  qm3L = qm1L - 2*stride[dir];
991  qm2L = qm1L - stride[dir];
992  qp1L = qm1L + stride[dir];
993  qp2L = qm1L + 2*stride[dir];
994 
995  indexC[dir] = indexI[dir] ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1R);
996  qm3R = qm1R + 2*stride[dir];
997  qm2R = qm1R + stride[dir];
998  qp1R = qm1R - stride[dir];
999  qp2R = qm1R - 2*stride[dir];
1000 
1001  /* find averaged state and left eigenvectors at this interface */
1002  IERR solver->AveragingFunction(uavg,(uC+nvars*qm1L),(uC+nvars*qp1L),solver->physics); CHECKERR(ierr);
1003  IERR solver->GetLeftEigenvectors(uavg,L,solver->physics,dir); CHECKERR(ierr);
1004 
1005  /* Defining stencil points */
1006  double m3LF[nvars], m2LF[nvars], m1LF[nvars], p1LF[nvars], p2LF[nvars];
1007  double m3RF[nvars], m2RF[nvars], m1RF[nvars], p1RF[nvars], p2RF[nvars];
1008  double m3LU[nvars], m2LU[nvars], m1LU[nvars], p1LU[nvars], p2LU[nvars];
1009  double m3RU[nvars], m2RU[nvars], m1RU[nvars], p1RU[nvars], p2RU[nvars];
1010 
1011  MatVecMult(nvars,m3LF,L,(fC+nvars*qm3L));
1012  MatVecMult(nvars,m2LF,L,(fC+nvars*qm2L));
1013  MatVecMult(nvars,m1LF,L,(fC+nvars*qm1L));
1014  MatVecMult(nvars,p1LF,L,(fC+nvars*qp1L));
1015  MatVecMult(nvars,p2LF,L,(fC+nvars*qp2L));
1016 
1017  MatVecMult(nvars,m3RF,L,(fC+nvars*qm3R));
1018  MatVecMult(nvars,m2RF,L,(fC+nvars*qm2R));
1019  MatVecMult(nvars,m1RF,L,(fC+nvars*qm1R));
1020  MatVecMult(nvars,p1RF,L,(fC+nvars*qp1R));
1021  MatVecMult(nvars,p2RF,L,(fC+nvars*qp2R));
1022 
1023  MatVecMult(nvars,m3LU,L,(uC+nvars*qm3L));
1024  MatVecMult(nvars,m2LU,L,(uC+nvars*qm2L));
1025  MatVecMult(nvars,m1LU,L,(uC+nvars*qm1L));
1026  MatVecMult(nvars,p1LU,L,(uC+nvars*qp1L));
1027  MatVecMult(nvars,p2LU,L,(uC+nvars*qp2L));
1028 
1029  MatVecMult(nvars,m3RU,L,(uC+nvars*qm3R));
1030  MatVecMult(nvars,m2RU,L,(uC+nvars*qm2R));
1031  MatVecMult(nvars,m1RU,L,(uC+nvars*qm1R));
1032  MatVecMult(nvars,p1RU,L,(uC+nvars*qp1R));
1033  MatVecMult(nvars,p2RU,L,(uC+nvars*qp2R));
1034 
1035  /* optimal weights*/
1036  double c1, c2, c3;
1037  if (!strcmp(solver->spatial_scheme_hyp,_FIFTH_ORDER_CRWENO_)) {
1038  if ( ((mpi->ip[dir] == 0 ) && (indexI[dir] == 0 ))
1039  || ((mpi->ip[dir] == mpi->iproc[dir]-1) && (indexI[dir] == dim[dir])) ) {
1040  /* Use WENO5 at the physical boundaries */
1044  } else {
1045  /* CRWENO5 at the interior points */
1049  }
1050  } else {
1051  /* WENO5 and HCWENO5 */
1055  }
1056 
1057  /* calculate WENO weights */
1058  _WENOWeights_v_M_((ww1LF+p*nvars),(ww2LF+p*nvars),(ww3LF+p*nvars),c1,c2,c3,m3LF,m2LF,m1LF,p1LF,p2LF,weno->eps,nvars);
1059  _WENOWeights_v_M_((ww1RF+p*nvars),(ww2RF+p*nvars),(ww3RF+p*nvars),c1,c2,c3,m3RF,m2RF,m1RF,p1RF,p2RF,weno->eps,nvars);
1060  _WENOWeights_v_M_((ww1LU+p*nvars),(ww2LU+p*nvars),(ww3LU+p*nvars),c1,c2,c3,m3LU,m2LU,m1LU,p1LU,p2LU,weno->eps,nvars);
1061  _WENOWeights_v_M_((ww1RU+p*nvars),(ww2RU+p*nvars),(ww3RU+p*nvars),c1,c2,c3,m3RU,m2RU,m1RU,p1RU,p2RU,weno->eps,nvars);
1062  }
1063  }
1064 
1065  return(0);
1066 }
#define _WENOWeights_v_M_(w1, w2, w3, c1, c2, c3, m3, m2, m1, p1, p2, eps, N)
#define _CRWENO_OPTIMAL_WEIGHT_1_
int nvars
Definition: hypar.h:29
#define IERR
Definition: basic.h:16
#define CHECKERR(ierr)
Definition: basic.h:18
int(* AveragingFunction)(double *, double *, double *, void *)
Definition: hypar.h:354
#define _WENO_OPTIMAL_WEIGHT_2_
#define _ArrayIndexnD_(N, index, imax, i, ghost)
int * stride_with_ghosts
Definition: hypar.h:414
#define _CRWENO_OPTIMAL_WEIGHT_2_
int ndims
Definition: hypar.h:26
#define _CRWENO_OPTIMAL_WEIGHT_3_
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
char spatial_scheme_hyp[_MAX_STRING_SIZE_]
Definition: hypar.h:84
#define _WENO_OPTIMAL_WEIGHT_1_
#define _ArrayIndex1D_(N, imax, i, ghost, index)
Structure of variables/parameters needed by the WENO-type scheme.
int * dim_local
Definition: hypar.h:37
void * interp
Definition: hypar.h:362
void * physics
Definition: hypar.h:266
#define _FIFTH_ORDER_CRWENO_
Definition: interpolation.h:28
int ghosts
Definition: hypar.h:52
#define _WENO_OPTIMAL_WEIGHT_3_
Structure of MPI-related variables.
#define MatVecMult(N, y, A, x)
#define _ArrayCopy1D_(x, y, size)
#define _ArrayProduct1D_(x, size, p)
int(* GetLeftEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:357

◆ WENOFifthOrderCalculateWeightsCharZ()

int WENOFifthOrderCalculateWeightsCharZ ( double *  fC,
double *  uC,
double *  x,
int  dir,
void *  s,
void *  m 
)
static

Computes the nonlinear weights for the 5th order characteristic-based WENO-type schemes using the WENO-Z formulation:

\begin{equation} \omega_k = \frac {a_k} {\sum_{j=1}^3 a_j },\ a_k = c_k \left( 1 + \frac{\tau_5}{\beta_k+\epsilon} \right)^p,\ k = 1,2,3, \end{equation}

where \(c_k\) are the optimal weights, \(p\) is hardcoded to \(2\), and \(\epsilon\) is an input parameter (WENOParameters::eps) (typically \(10^{-6}\)). The smoothness indicators \(\beta_k\) are given by:

\begin{eqnarray} \beta_1 &=& \frac{13}{12} \left(\alpha_{j-2}-2\alpha_{j-1}+\alpha_j\right)^2 + \frac{1}{4}\left(\alpha_{j-2}-4\alpha_{j-1}+3\alpha_j\right)^2 \\ \beta_2 &=& \frac{13}{12} \left(\alpha_{j-1}-2\alpha_j+\alpha_{j+1}\right)^2 + \frac{1}{4}\left(\alpha_{j-1}-\alpha_{j+1}\right)^2 \\ \beta_3 &=& \frac{13}{12} \left(\alpha_j-2\alpha_{j+1}+\alpha_{j+2}\right)^2 + \frac{1}{4}\left(3\alpha_j-4\alpha_{j+1}+\alpha_{j+2}\right)^2 \end{eqnarray}

and \(\tau_5 = \left|\beta_1 - \beta_3 \right|\), and \(\alpha\) is the characteristic flux or the solution.

Notes:

  • This function computes the weights for the entire grid (for interpolation along a given spatial dimension dir ). Thus, it loops over all grid lines along dir.
  • The weights are computed for all components, for both the left- and right-biased interpolations, and for both the flux function \({\bf f}\left({\bf u}\right)\) and the solution \(\bf u\). Thus, this approach of computing and storing the weights is quite memory-intensive.
  • The variable offset denotes the offset in the complete array from where the weights for interpolation along the current interpolation dimension (dir ) are stored.
  • This function requires functions to compute the average state and the left eigenvectors for the characteristic decomposition. These are provided by the physical model through

Reference:

Parameters
fCArray of cell-centered values of the function \({\bf f}\left({\bf u}\right)\)
uCArray of cell-centered values of the solution \({\bf u}\)
xGrid coordinates
dirSpatial dimension along which to interpolation
sObject of type HyPar containing solver-related variables
mObject of type MPIVariables containing MPI-related variables

Definition at line 1101 of file WENOFifthOrderCalculateWeights.c.

1109 {
1110  HyPar *solver = (HyPar*) s;
1111  WENOParameters *weno = (WENOParameters*) solver->interp;
1112  MPIVariables *mpi = (MPIVariables*) m;
1113  int i;
1114  double *ww1LF, *ww2LF, *ww3LF, *ww1RF, *ww2RF, *ww3RF;
1115  double *ww1LU, *ww2LU, *ww3LU, *ww1RU, *ww2RU, *ww3RU;
1116 
1117  int ghosts = solver->ghosts;
1118  int ndims = solver->ndims;
1119  int nvars = solver->nvars;
1120  int *dim = solver->dim_local;
1121  int *stride= solver->stride_with_ghosts;
1122 
1123  /* define some constants */
1124  static const double thirteen_by_twelve = 13.0/12.0;
1125  static const double one_fourth = 1.0/4.0;
1126 
1127  /* calculate dimension offset */
1128  int offset = weno->offset[dir];
1129 
1130  /* create index and bounds for the outer loop, i.e., to loop over all 1D lines along
1131  dimension "dir" */
1132  int indexC[ndims], indexI[ndims], index_outer[ndims], bounds_outer[ndims], bounds_inter[ndims];
1133  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
1134  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
1135  int N_outer; _ArrayProduct1D_(bounds_outer,ndims,N_outer);
1136 
1137  /* allocate arrays for the averaged state, eigenvectors and characteristic interpolated f */
1138  double L[nvars*nvars], uavg[nvars];
1139 
1140  ww1LF = weno->w1 + offset;
1141  ww2LF = weno->w2 + offset;
1142  ww3LF = weno->w3 + offset;
1143  ww1RF = weno->w1 + 2*weno->size + offset;
1144  ww2RF = weno->w2 + 2*weno->size + offset;
1145  ww3RF = weno->w3 + 2*weno->size + offset;
1146  ww1LU = weno->w1 + weno->size + offset;
1147  ww2LU = weno->w2 + weno->size + offset;
1148  ww3LU = weno->w3 + weno->size + offset;
1149  ww1RU = weno->w1 + 2*weno->size + weno->size + offset;
1150  ww2RU = weno->w2 + 2*weno->size + weno->size + offset;
1151  ww3RU = weno->w3 + 2*weno->size + weno->size + offset;
1152 #pragma omp parallel for schedule(auto) default(shared) private(i,index_outer,indexC,indexI)
1153  for (i=0; i<N_outer; i++) {
1154  _ArrayIndexnD_(ndims,i,bounds_outer,index_outer,0);
1155  _ArrayCopy1D_(index_outer,indexC,ndims);
1156  _ArrayCopy1D_(index_outer,indexI,ndims);
1157  for (indexI[dir] = 0; indexI[dir] < dim[dir]+1; indexI[dir]++) {
1158  int qm1L,qm2L,qm3L,qp1L,qp2L,p,qm1R,qm2R,qm3R,qp1R,qp2R;
1159  _ArrayIndex1D_(ndims,bounds_inter,indexI,0,p);
1160  indexC[dir] = indexI[dir]-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1L);
1161  qm3L = qm1L - 2*stride[dir];
1162  qm2L = qm1L - stride[dir];
1163  qp1L = qm1L + stride[dir];
1164  qp2L = qm1L + 2*stride[dir];
1165 
1166  indexC[dir] = indexI[dir] ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1R);
1167  qm3R = qm1R + 2*stride[dir];
1168  qm2R = qm1R + stride[dir];
1169  qp1R = qm1R - stride[dir];
1170  qp2R = qm1R - 2*stride[dir];
1171 
1172  /* find averaged state and left eigenvectors at this interface */
1173  IERR solver->AveragingFunction(uavg,(uC+nvars*qm1L),(uC+nvars*qp1L),solver->physics); CHECKERR(ierr);
1174  IERR solver->GetLeftEigenvectors(uavg,L,solver->physics,dir); CHECKERR(ierr);
1175 
1176  /* Defining stencil points */
1177  double m3LF[nvars], m2LF[nvars], m1LF[nvars], p1LF[nvars], p2LF[nvars];
1178  double m3RF[nvars], m2RF[nvars], m1RF[nvars], p1RF[nvars], p2RF[nvars];
1179  double m3LU[nvars], m2LU[nvars], m1LU[nvars], p1LU[nvars], p2LU[nvars];
1180  double m3RU[nvars], m2RU[nvars], m1RU[nvars], p1RU[nvars], p2RU[nvars];
1181 
1182  MatVecMult(nvars,m3LF,L,(fC+nvars*qm3L));
1183  MatVecMult(nvars,m2LF,L,(fC+nvars*qm2L));
1184  MatVecMult(nvars,m1LF,L,(fC+nvars*qm1L));
1185  MatVecMult(nvars,p1LF,L,(fC+nvars*qp1L));
1186  MatVecMult(nvars,p2LF,L,(fC+nvars*qp2L));
1187 
1188  MatVecMult(nvars,m3RF,L,(fC+nvars*qm3R));
1189  MatVecMult(nvars,m2RF,L,(fC+nvars*qm2R));
1190  MatVecMult(nvars,m1RF,L,(fC+nvars*qm1R));
1191  MatVecMult(nvars,p1RF,L,(fC+nvars*qp1R));
1192  MatVecMult(nvars,p2RF,L,(fC+nvars*qp2R));
1193 
1194  MatVecMult(nvars,m3LU,L,(uC+nvars*qm3L));
1195  MatVecMult(nvars,m2LU,L,(uC+nvars*qm2L));
1196  MatVecMult(nvars,m1LU,L,(uC+nvars*qm1L));
1197  MatVecMult(nvars,p1LU,L,(uC+nvars*qp1L));
1198  MatVecMult(nvars,p2LU,L,(uC+nvars*qp2L));
1199 
1200  MatVecMult(nvars,m3RU,L,(uC+nvars*qm3R));
1201  MatVecMult(nvars,m2RU,L,(uC+nvars*qm2R));
1202  MatVecMult(nvars,m1RU,L,(uC+nvars*qm1R));
1203  MatVecMult(nvars,p1RU,L,(uC+nvars*qp1R));
1204  MatVecMult(nvars,p2RU,L,(uC+nvars*qp2R));
1205 
1206  /* optimal weights*/
1207  double c1, c2, c3;
1208  if (!strcmp(solver->spatial_scheme_hyp,_FIFTH_ORDER_CRWENO_)) {
1209  if ( ((mpi->ip[dir] == 0 ) && (indexI[dir] == 0 ))
1210  || ((mpi->ip[dir] == mpi->iproc[dir]-1) && (indexI[dir] == dim[dir])) ) {
1211  /* Use WENO5 at the physical boundaries */
1215  } else {
1216  /* CRWENO5 at the interior points */
1220  }
1221  } else {
1222  /* WENO5 and HCWENO5 */
1226  }
1227 
1228  /* calculate WENO weights */
1229  _WENOWeights_v_Z_((ww1LF+p*nvars),(ww2LF+p*nvars),(ww3LF+p*nvars),c1,c2,c3,m3LF,m2LF,m1LF,p1LF,p2LF,weno->eps,nvars);
1230  _WENOWeights_v_Z_((ww1RF+p*nvars),(ww2RF+p*nvars),(ww3RF+p*nvars),c1,c2,c3,m3RF,m2RF,m1RF,p1RF,p2RF,weno->eps,nvars);
1231  _WENOWeights_v_Z_((ww1LU+p*nvars),(ww2LU+p*nvars),(ww3LU+p*nvars),c1,c2,c3,m3LU,m2LU,m1LU,p1LU,p2LU,weno->eps,nvars);
1232  _WENOWeights_v_Z_((ww1RU+p*nvars),(ww2RU+p*nvars),(ww3RU+p*nvars),c1,c2,c3,m3RU,m2RU,m1RU,p1RU,p2RU,weno->eps,nvars);
1233  }
1234  }
1235 
1236  return(0);
1237 }
#define _CRWENO_OPTIMAL_WEIGHT_1_
int nvars
Definition: hypar.h:29
#define IERR
Definition: basic.h:16
#define CHECKERR(ierr)
Definition: basic.h:18
int(* AveragingFunction)(double *, double *, double *, void *)
Definition: hypar.h:354
#define _WENO_OPTIMAL_WEIGHT_2_
#define _WENOWeights_v_Z_(w1, w2, w3, c1, c2, c3, m3, m2, m1, p1, p2, eps, N)
#define _ArrayIndexnD_(N, index, imax, i, ghost)
int * stride_with_ghosts
Definition: hypar.h:414
#define _CRWENO_OPTIMAL_WEIGHT_2_
int ndims
Definition: hypar.h:26
#define _CRWENO_OPTIMAL_WEIGHT_3_
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
char spatial_scheme_hyp[_MAX_STRING_SIZE_]
Definition: hypar.h:84
#define _WENO_OPTIMAL_WEIGHT_1_
#define _ArrayIndex1D_(N, imax, i, ghost, index)
Structure of variables/parameters needed by the WENO-type scheme.
int * dim_local
Definition: hypar.h:37
void * interp
Definition: hypar.h:362
void * physics
Definition: hypar.h:266
#define _FIFTH_ORDER_CRWENO_
Definition: interpolation.h:28
int ghosts
Definition: hypar.h:52
#define _WENO_OPTIMAL_WEIGHT_3_
Structure of MPI-related variables.
#define MatVecMult(N, y, A, x)
#define _ArrayCopy1D_(x, y, size)
#define _ArrayProduct1D_(x, size, p)
int(* GetLeftEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:357

◆ WENOFifthOrderCalculateWeightsCharYC()

int WENOFifthOrderCalculateWeightsCharYC ( double *  fC,
double *  uC,
double *  x,
int  dir,
void *  s,
void *  m 
)
static

Computes the nonlinear weights for the 5th order characteristic-based WENO-type schemes using the ESWENO formulation of Yamaleev & Carpenter. Note that only the formulation for the nonlinear weights is adopted and implemented here, not the ESWENO scheme as a whole.

\begin{equation} \omega_k = \frac {a_k} {\sum_{j=1}^3 a_j },\ a_k = c_k \left( 1 + \frac{\tau_5}{\beta_k+\epsilon} \right)^p,\ k = 1,2,3, \end{equation}

where \(c_k\) are the optimal weights, \(p\) is hardcoded to \(2\), and \(\epsilon\) is an input parameter (WENOParameters::eps) (typically \(10^{-6}\)). The smoothness indicators \(\beta_k\) are given by:

\begin{eqnarray} \beta_1 &=& \frac{13}{12} \left(\alpha_{j-2}-2\alpha_{j-1}+\alpha_j\right)^2 + \frac{1}{4}\left(\alpha_{j-2}-4\alpha_{j-1}+3\alpha_j\right)^2 \\ \beta_2 &=& \frac{13}{12} \left(\alpha_{j-1}-2\alpha_j+\alpha_{j+1}\right)^2 + \frac{1}{4}\left(\alpha_{j-1}-\alpha_{j+1}\right)^2 \\ \beta_3 &=& \frac{13}{12} \left(\alpha_j-2\alpha_{j+1}+\alpha_{j+2}\right)^2 + \frac{1}{4}\left(3\alpha_j-4\alpha_{j+1}+\alpha_{j+2}\right)^2 \end{eqnarray}

and \(\tau_5 = \left( \alpha_{j-2}-4\alpha_{j-1}+6\alpha_j-4\alpha_{j+1}+\alpha_{j+2} \right)^2\) and \(\alpha\) is the characteristic flux or the solution.

Notes:

  • This function computes the weights for the entire grid (for interpolation along a given spatial dimension dir ). Thus, it loops over all grid lines along dir.
  • The weights are computed for all components, for both the left- and right-biased interpolations, and for both the flux function \({\bf f}\left({\bf u}\right)\) and the solution \(\bf u\). Thus, this approach of computing and storing the weights is quite memory-intensive.
  • The variable offset denotes the offset in the complete array from where the weights for interpolation along the current interpolation dimension (dir ) are stored.
  • This function requires functions to compute the average state and the left eigenvectors for the characteristic decomposition. These are provided by the physical model through

Reference:

Parameters
fCArray of cell-centered values of the function \({\bf f}\left({\bf u}\right)\)
uCArray of cell-centered values of the solution \({\bf u}\)
xGrid coordinates
dirSpatial dimension along which to interpolation
sObject of type HyPar containing solver-related variables
mObject of type MPIVariables containing MPI-related variables

Definition at line 1272 of file WENOFifthOrderCalculateWeights.c.

1280 {
1281  HyPar *solver = (HyPar*) s;
1282  WENOParameters *weno = (WENOParameters*) solver->interp;
1283  MPIVariables *mpi = (MPIVariables*) m;
1284  int i;
1285  double *ww1LF, *ww2LF, *ww3LF, *ww1RF, *ww2RF, *ww3RF;
1286  double *ww1LU, *ww2LU, *ww3LU, *ww1RU, *ww2RU, *ww3RU;
1287 
1288  int ghosts = solver->ghosts;
1289  int ndims = solver->ndims;
1290  int nvars = solver->nvars;
1291  int *dim = solver->dim_local;
1292  int *stride= solver->stride_with_ghosts;
1293 
1294  /* define some constants */
1295  static const double thirteen_by_twelve = 13.0/12.0;
1296  static const double one_fourth = 1.0/4.0;
1297 
1298  /* calculate dimension offset */
1299  int offset = weno->offset[dir];
1300 
1301  /* create index and bounds for the outer loop, i.e., to loop over all 1D lines along
1302  dimension "dir" */
1303  int indexC[ndims], indexI[ndims], index_outer[ndims], bounds_outer[ndims], bounds_inter[ndims];
1304  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
1305  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
1306  int N_outer; _ArrayProduct1D_(bounds_outer,ndims,N_outer);
1307 
1308  /* allocate arrays for the averaged state, eigenvectors and characteristic interpolated f */
1309  double L[nvars*nvars], uavg[nvars];
1310 
1311  ww1LF = weno->w1 + offset;
1312  ww2LF = weno->w2 + offset;
1313  ww3LF = weno->w3 + offset;
1314  ww1RF = weno->w1 + 2*weno->size + offset;
1315  ww2RF = weno->w2 + 2*weno->size + offset;
1316  ww3RF = weno->w3 + 2*weno->size + offset;
1317  ww1LU = weno->w1 + weno->size + offset;
1318  ww2LU = weno->w2 + weno->size + offset;
1319  ww3LU = weno->w3 + weno->size + offset;
1320  ww1RU = weno->w1 + 2*weno->size + weno->size + offset;
1321  ww2RU = weno->w2 + 2*weno->size + weno->size + offset;
1322  ww3RU = weno->w3 + 2*weno->size + weno->size + offset;
1323 #pragma omp parallel for schedule(auto) default(shared) private(i,index_outer,indexC,indexI)
1324  for (i=0; i<N_outer; i++) {
1325  _ArrayIndexnD_(ndims,i,bounds_outer,index_outer,0);
1326  _ArrayCopy1D_(index_outer,indexC,ndims);
1327  _ArrayCopy1D_(index_outer,indexI,ndims);
1328  for (indexI[dir] = 0; indexI[dir] < dim[dir]+1; indexI[dir]++) {
1329  int qm1L,qm2L,qm3L,qp1L,qp2L,p,qm1R,qm2R,qm3R,qp1R,qp2R;
1330  _ArrayIndex1D_(ndims,bounds_inter,indexI,0,p);
1331  indexC[dir] = indexI[dir]-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1L);
1332  qm3L = qm1L - 2*stride[dir];
1333  qm2L = qm1L - stride[dir];
1334  qp1L = qm1L + stride[dir];
1335  qp2L = qm1L + 2*stride[dir];
1336 
1337  indexC[dir] = indexI[dir] ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1R);
1338  qm3R = qm1R + 2*stride[dir];
1339  qm2R = qm1R + stride[dir];
1340  qp1R = qm1R - stride[dir];
1341  qp2R = qm1R - 2*stride[dir];
1342 
1343  /* find averaged state and left eigenvectors at this interface */
1344  IERR solver->AveragingFunction(uavg,(uC+nvars*qm1L),(uC+nvars*qp1L),solver->physics); CHECKERR(ierr);
1345  IERR solver->GetLeftEigenvectors(uavg,L,solver->physics,dir); CHECKERR(ierr);
1346 
1347  /* Defining stencil points */
1348  double m3LF[nvars], m2LF[nvars], m1LF[nvars], p1LF[nvars], p2LF[nvars];
1349  double m3RF[nvars], m2RF[nvars], m1RF[nvars], p1RF[nvars], p2RF[nvars];
1350  double m3LU[nvars], m2LU[nvars], m1LU[nvars], p1LU[nvars], p2LU[nvars];
1351  double m3RU[nvars], m2RU[nvars], m1RU[nvars], p1RU[nvars], p2RU[nvars];
1352 
1353  MatVecMult(nvars,m3LF,L,(fC+nvars*qm3L));
1354  MatVecMult(nvars,m2LF,L,(fC+nvars*qm2L));
1355  MatVecMult(nvars,m1LF,L,(fC+nvars*qm1L));
1356  MatVecMult(nvars,p1LF,L,(fC+nvars*qp1L));
1357  MatVecMult(nvars,p2LF,L,(fC+nvars*qp2L));
1358 
1359  MatVecMult(nvars,m3RF,L,(fC+nvars*qm3R));
1360  MatVecMult(nvars,m2RF,L,(fC+nvars*qm2R));
1361  MatVecMult(nvars,m1RF,L,(fC+nvars*qm1R));
1362  MatVecMult(nvars,p1RF,L,(fC+nvars*qp1R));
1363  MatVecMult(nvars,p2RF,L,(fC+nvars*qp2R));
1364 
1365  MatVecMult(nvars,m3LU,L,(uC+nvars*qm3L));
1366  MatVecMult(nvars,m2LU,L,(uC+nvars*qm2L));
1367  MatVecMult(nvars,m1LU,L,(uC+nvars*qm1L));
1368  MatVecMult(nvars,p1LU,L,(uC+nvars*qp1L));
1369  MatVecMult(nvars,p2LU,L,(uC+nvars*qp2L));
1370 
1371  MatVecMult(nvars,m3RU,L,(uC+nvars*qm3R));
1372  MatVecMult(nvars,m2RU,L,(uC+nvars*qm2R));
1373  MatVecMult(nvars,m1RU,L,(uC+nvars*qm1R));
1374  MatVecMult(nvars,p1RU,L,(uC+nvars*qp1R));
1375  MatVecMult(nvars,p2RU,L,(uC+nvars*qp2R));
1376 
1377  /* optimal weights*/
1378  double c1, c2, c3;
1379  if (!strcmp(solver->spatial_scheme_hyp,_FIFTH_ORDER_CRWENO_)) {
1380  if ( ((mpi->ip[dir] == 0 ) && (indexI[dir] == 0 ))
1381  || ((mpi->ip[dir] == mpi->iproc[dir]-1) && (indexI[dir] == dim[dir])) ) {
1382  /* Use WENO5 at the physical boundaries */
1386  } else {
1387  /* CRWENO5 at the interior points */
1391  }
1392  } else {
1393  /* WENO5 and HCWENO5 */
1397  }
1398 
1399  /* calculate WENO weights */
1400  _WENOWeights_v_YC_((ww1LF+p*nvars),(ww2LF+p*nvars),(ww3LF+p*nvars),c1,c2,c3,m3LF,m2LF,m1LF,p1LF,p2LF,weno->eps,nvars);
1401  _WENOWeights_v_YC_((ww1RF+p*nvars),(ww2RF+p*nvars),(ww3RF+p*nvars),c1,c2,c3,m3RF,m2RF,m1RF,p1RF,p2RF,weno->eps,nvars);
1402  _WENOWeights_v_YC_((ww1LU+p*nvars),(ww2LU+p*nvars),(ww3LU+p*nvars),c1,c2,c3,m3LU,m2LU,m1LU,p1LU,p2LU,weno->eps,nvars);
1403  _WENOWeights_v_YC_((ww1RU+p*nvars),(ww2RU+p*nvars),(ww3RU+p*nvars),c1,c2,c3,m3RU,m2RU,m1RU,p1RU,p2RU,weno->eps,nvars);
1404  }
1405  }
1406 
1407  return(0);
1408 }
#define _CRWENO_OPTIMAL_WEIGHT_1_
int nvars
Definition: hypar.h:29
#define IERR
Definition: basic.h:16
#define CHECKERR(ierr)
Definition: basic.h:18
int(* AveragingFunction)(double *, double *, double *, void *)
Definition: hypar.h:354
#define _WENO_OPTIMAL_WEIGHT_2_
#define _ArrayIndexnD_(N, index, imax, i, ghost)
int * stride_with_ghosts
Definition: hypar.h:414
#define _CRWENO_OPTIMAL_WEIGHT_2_
int ndims
Definition: hypar.h:26
#define _CRWENO_OPTIMAL_WEIGHT_3_
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
char spatial_scheme_hyp[_MAX_STRING_SIZE_]
Definition: hypar.h:84
#define _WENO_OPTIMAL_WEIGHT_1_
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _WENOWeights_v_YC_(w1, w2, w3, c1, c2, c3, m3, m2, m1, p1, p2, eps, N)
Structure of variables/parameters needed by the WENO-type scheme.
int * dim_local
Definition: hypar.h:37
void * interp
Definition: hypar.h:362
void * physics
Definition: hypar.h:266
#define _FIFTH_ORDER_CRWENO_
Definition: interpolation.h:28
int ghosts
Definition: hypar.h:52
#define _WENO_OPTIMAL_WEIGHT_3_
Structure of MPI-related variables.
#define MatVecMult(N, y, A, x)
#define _ArrayCopy1D_(x, y, size)
#define _ArrayProduct1D_(x, size, p)
int(* GetLeftEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:357

◆ WENOFifthOrderCalculateWeights()

int WENOFifthOrderCalculateWeights ( double *  fC,
double *  uC,
double *  x,
int  dir,
void *  s,
void *  m 
)

Compute the nonlinear weights for 5th order WENO-type schemes. This function is a wrapper that calls the appropriate function, depending on the type of WENO weights.

Parameters
fCArray of cell-centered values of the function \({\bf f}\left({\bf u}\right)\)
uCArray of cell-centered values of the solution \({\bf u}\)
xGrid coordinates
dirSpatial dimension along which to interpolation
sObject of type HyPar containing solver-related variables
mObject of type MPIVariables containing MPI-related variables

Definition at line 40 of file WENOFifthOrderCalculateWeights.c.

48 {
49  HyPar *solver = (HyPar*) s;
50  WENOParameters *weno = (WENOParameters*) solver->interp;
51  MPIVariables *mpi = (MPIVariables*) m;
52 
53  int ret;
54 
55  if (weno->yc) ret = WENOFifthOrderCalculateWeightsYC (fC,uC,x,dir,solver,mpi);
56  else if (weno->borges) ret = WENOFifthOrderCalculateWeightsZ (fC,uC,x,dir,solver,mpi);
57  else if (weno->mapped) ret = WENOFifthOrderCalculateWeightsM (fC,uC,x,dir,solver,mpi);
58  else ret = WENOFifthOrderCalculateWeightsJS (fC,uC,x,dir,solver,mpi);
59 
60  return ret;
61 }
static int WENOFifthOrderCalculateWeightsZ(double *, double *, double *, int, void *, void *)
static int WENOFifthOrderCalculateWeightsM(double *, double *, double *, int, void *, void *)
static int WENOFifthOrderCalculateWeightsJS(double *, double *, double *, int, void *, void *)
static int WENOFifthOrderCalculateWeightsYC(double *, double *, double *, int, void *, void *)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
Structure of variables/parameters needed by the WENO-type scheme.
void * interp
Definition: hypar.h:362
Structure of MPI-related variables.

◆ WENOFifthOrderCalculateWeightsChar()

int WENOFifthOrderCalculateWeightsChar ( double *  fC,
double *  uC,
double *  x,
int  dir,
void *  s,
void *  m 
)

Compute the nonlinear weights for 5th order WENO-type schemes. This function is a wrapper that calls the appropriate function, depending on the type of WENO weights.

Parameters
fCArray of cell-centered values of the function \({\bf f}\left({\bf u}\right)\)
uCArray of cell-centered values of the solution \({\bf u}\)
xGrid coordinates
dirSpatial dimension along which to interpolation
sObject of type HyPar containing solver-related variables
mObject of type MPIVariables containing MPI-related variables

Definition at line 66 of file WENOFifthOrderCalculateWeights.c.

74 {
75  HyPar *solver = (HyPar*) s;
76  WENOParameters *weno = (WENOParameters*) solver->interp;
77  MPIVariables *mpi = (MPIVariables*) m;
78 
79  if (weno->yc) return(WENOFifthOrderCalculateWeightsCharYC (fC,uC,x,dir,solver,mpi));
80  else if (weno->borges) return(WENOFifthOrderCalculateWeightsCharZ (fC,uC,x,dir,solver,mpi));
81  else if (weno->mapped) return(WENOFifthOrderCalculateWeightsCharM (fC,uC,x,dir,solver,mpi));
82  else return(WENOFifthOrderCalculateWeightsCharJS (fC,uC,x,dir,solver,mpi));
83 }
static int WENOFifthOrderCalculateWeightsCharJS(double *, double *, double *, int, void *, void *)
static int WENOFifthOrderCalculateWeightsCharZ(double *, double *, double *, int, void *, void *)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
static int WENOFifthOrderCalculateWeightsCharM(double *, double *, double *, int, void *, void *)
static int WENOFifthOrderCalculateWeightsCharYC(double *, double *, double *, int, void *, void *)
Structure of variables/parameters needed by the WENO-type scheme.
void * interp
Definition: hypar.h:362
Structure of MPI-related variables.