HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WENOFifthOrderInitializeWeights.c
Go to the documentation of this file.
1 
6 #include <stdlib.h>
7 #include <string.h>
8 #include <basic.h>
9 #include <arrayfunctions.h>
10 #include <mathfunctions.h>
11 #include <interpolation.h>
12 #include <mpivars.h>
13 #include <hypar.h>
14 
33 int WENOFifthOrderInitializeWeights( double* const a_w1,
34  double* const a_w2,
35  double* const a_w3,
36  const int* const a_offset,
37  int dir,
38  void *s,
39  void *m
40  )
41 {
42  HyPar *solver = (HyPar*) s;
43  WENOParameters *weno = (WENOParameters*) solver->interp;
44  MPIVariables *mpi = (MPIVariables*) m;
45  int done;
46  double *ww1, *ww2, *ww3;
47 
48 
49  int ndims = solver->ndims;
50  int nvars = solver->nvars;
51  int *dim = solver->dim_local;
52 
53  /* calculate dimension offset */
54  int offset = a_offset[dir];
55 
56  /* create index and bounds for the outer loop, i.e., to loop over all 1D lines along
57  dimension "dir" */
58  int indexI[ndims], index_outer[ndims], bounds_outer[ndims], bounds_inter[ndims];
59  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
60  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
61 
62  /* calculate weights for a left-biased interpolation */
63  ww1 = a_w1 + offset;
64  ww2 = a_w2 + offset;
65  ww3 = a_w3 + offset;
66  done = 0; _ArraySetValue_(index_outer,ndims,0);
67  while (!done) {
68  _ArrayCopy1D_(index_outer,indexI,ndims);
69  for (indexI[dir] = 0; indexI[dir] < dim[dir]+1; indexI[dir]++) {
70  int p, v;
71  _ArrayIndex1D_(ndims,bounds_inter,indexI,0,p);
72  for (v=0; v<nvars; v++) {
73  /* optimal weights*/
74  double c1, c2, c3;
75  if (!strcmp(solver->spatial_scheme_hyp,_FIFTH_ORDER_CRWENO_)) {
76  if ( ((mpi->ip[dir] == 0 ) && (indexI[dir] == 0 ))
77  || ((mpi->ip[dir] == mpi->iproc[dir]-1) && (indexI[dir] == dim[dir])) ) {
78  /* Use WENO5 at the physical boundaries */
82  } else {
83  /* CRWENO5 at the interior points */
87  }
88  } else {
89  /* WENO5 and HCWENO5 */
93  }
94 
95  /* save the weights */
96  *(ww1+p*nvars+v) = c1;
97  *(ww2+p*nvars+v) = c2;
98  *(ww3+p*nvars+v) = c3;
99  }
100  }
101  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
102  }
103 
104  ww1 = a_w1 + weno->size + offset;
105  ww2 = a_w2 + weno->size + offset;
106  ww3 = a_w3 + weno->size + offset;
107  done = 0; _ArraySetValue_(index_outer,ndims,0);
108  while (!done) {
109  _ArrayCopy1D_(index_outer,indexI,ndims);
110  for (indexI[dir] = 0; indexI[dir] < dim[dir]+1; indexI[dir]++) {
111  int p, v;
112  _ArrayIndex1D_(ndims,bounds_inter,indexI,0,p);
113  for (v=0; v<nvars; v++) {
114 
115  /* optimal weights*/
116  double c1, c2, c3;
117  if (!strcmp(solver->spatial_scheme_hyp,_FIFTH_ORDER_CRWENO_)) {
118  if ( ((mpi->ip[dir] == 0 ) && (indexI[dir] == 0 ))
119  || ((mpi->ip[dir] == mpi->iproc[dir]-1) && (indexI[dir] == dim[dir])) ) {
120  /* Use WENO5 at the physical boundaries */
124  } else {
125  /* CRWENO5 at the interior points */
129  }
130  } else {
131  /* WENO5 and HCWENO5 */
135  }
136 
137  /* save the weights */
138  *(ww1+p*nvars+v) = c1;
139  *(ww2+p*nvars+v) = c2;
140  *(ww3+p*nvars+v) = c3;
141  }
142  }
143  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
144  }
145 
146  /* calculate weights for a right-biased interpolation */
147  ww1 = a_w1 + 2*weno->size + offset;
148  ww2 = a_w2 + 2*weno->size + offset;
149  ww3 = a_w3 + 2*weno->size + offset;
150  done = 0; _ArraySetValue_(index_outer,ndims,0);
151  while (!done) {
152  _ArrayCopy1D_(index_outer,indexI,ndims);
153  for (indexI[dir] = 0; indexI[dir] < dim[dir]+1; indexI[dir]++) {
154  int p, v;
155  _ArrayIndex1D_(ndims,bounds_inter,indexI,0,p);
156  for (v=0; v<nvars; v++) {
157 
158  /* optimal weights*/
159  double c1, c2, c3;
160  if (!strcmp(solver->spatial_scheme_hyp,_FIFTH_ORDER_CRWENO_)) {
161  if ( ((mpi->ip[dir] == 0 ) && (indexI[dir] == 0 ))
162  || ((mpi->ip[dir] == mpi->iproc[dir]-1) && (indexI[dir] == dim[dir])) ) {
163  /* Use WENO5 at the physical boundaries */
167  } else {
168  /* CRWENO5 at the interior points */
172  }
173  } else {
174  /* WENO5 and HCWENO5 */
178  }
179 
180  /* save the weights */
181  *(ww1+p*nvars+v) = c1;
182  *(ww2+p*nvars+v) = c2;
183  *(ww3+p*nvars+v) = c3;
184  }
185  }
186  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
187  }
188 
189  ww1 = a_w1 + 2*weno->size + weno->size + offset;
190  ww2 = a_w2 + 2*weno->size + weno->size + offset;
191  ww3 = a_w3 + 2*weno->size + weno->size + offset;
192  done = 0; _ArraySetValue_(index_outer,ndims,0);
193  while (!done) {
194  _ArrayCopy1D_(index_outer,indexI,ndims);
195  for (indexI[dir] = 0; indexI[dir] < dim[dir]+1; indexI[dir]++) {
196  int p, v;
197  _ArrayIndex1D_(ndims,bounds_inter,indexI,0,p);
198  for (v=0; v<nvars; v++) {
199 
200  /* optimal weights*/
201  double c1, c2, c3;
202  if (!strcmp(solver->spatial_scheme_hyp,_FIFTH_ORDER_CRWENO_)) {
203  if ( ((mpi->ip[dir] == 0 ) && (indexI[dir] == 0 ))
204  || ((mpi->ip[dir] == mpi->iproc[dir]-1) && (indexI[dir] == dim[dir])) ) {
205  /* Use WENO5 at the physical boundaries */
209  } else {
210  /* CRWENO5 at the interior points */
214  }
215  } else {
216  /* WENO5 and HCWENO5 */
220  }
221 
222  /* save the weights */
223  *(ww1+p*nvars+v) = c1;
224  *(ww2+p*nvars+v) = c2;
225  *(ww3+p*nvars+v) = c3;
226  }
227  }
228  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
229  }
230 
231  return(0);
232 }
char spatial_scheme_hyp[_MAX_STRING_SIZE_]
Definition: hypar.h:84
void * interp
Definition: hypar.h:362
#define _ArraySetValue_(x, size, value)
Definitions for the functions computing the interpolated value of the primitive at the cell interface...
#define _ArrayIncrementIndex_(N, imax, i, done)
int * dim_local
Definition: hypar.h:37
MPI related function definitions.
#define _WENO_OPTIMAL_WEIGHT_2_
int WENOFifthOrderInitializeWeights(double *const a_w1, double *const a_w2, double *const a_w3, const int *const a_offset, int dir, void *s, void *m)
Structure of variables/parameters needed by the WENO-type scheme.
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _CRWENO_OPTIMAL_WEIGHT_1_
#define _WENO_OPTIMAL_WEIGHT_3_
Contains function definitions for common mathematical functions.
#define _WENO_OPTIMAL_WEIGHT_1_
#define _ArrayCopy1D_(x, y, size)
int nvars
Definition: hypar.h:29
Contains structure definition for hypar.
#define _CRWENO_OPTIMAL_WEIGHT_2_
#define _CRWENO_OPTIMAL_WEIGHT_3_
Some basic definitions and macros.
int ndims
Definition: hypar.h:26
Contains macros and function definitions for common array operations.
#define _FIFTH_ORDER_CRWENO_
Definition: interpolation.h:28
Structure of MPI-related variables.
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23