HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Interp1PrimSecondOrderMUSCL.c
Go to the documentation of this file.
1 
6 #include <stdio.h>
7 #include <stdlib.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 
15 #ifdef with_omp
16 #include <omp.h>
17 #endif
18 
19 #undef _MINIMUM_GHOSTS_
20 
24 #define _MINIMUM_GHOSTS_ 2
25 
77  double *fI,
78  double *fC,
79  double *u,
80  double *x,
81  int upw,
82  int dir,
83  void *s,
84  void *m,
85  int uflag
86  )
87 {
88  HyPar *solver = (HyPar*) s;
89  MUSCLParameters *muscl = (MUSCLParameters*) solver->interp;
90 
91  int ghosts = solver->ghosts;
92  int ndims = solver->ndims;
93  int nvars = solver->nvars;
94  int *dim = solver->dim_local;
95 
96  /* define some constants */
97  double half = 1.0/2.0;
98 
99  /* create index and bounds for the outer loop, i.e., to loop over all 1D lines along
100  dimension "dir" */
101  int indexC[ndims], indexI[ndims], index_outer[ndims], bounds_outer[ndims], bounds_inter[ndims];
102  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
103  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
104  int N_outer; _ArrayProduct1D_(bounds_outer,ndims,N_outer);
105 
106  int i;
107  if (upw > 0) {
108 #pragma omp parallel for schedule(auto) default(shared) private(i,index_outer,indexC,indexI)
109  for (i=0; i<N_outer; i++) {
110  _ArrayIndexnD_(ndims,i,bounds_outer,index_outer,0);
111  _ArrayCopy1D_(index_outer,indexC,ndims);
112  _ArrayCopy1D_(index_outer,indexI,ndims);
113  for (indexI[dir] = 0; indexI[dir] < dim[dir]+1; indexI[dir]++) {
114  int p; _ArrayIndex1D_(ndims,bounds_inter,indexI,0,p);
115  int qm2,qm1,qp1,v;
116  indexC[dir] = indexI[dir]-2; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm2);
117  indexC[dir] = indexI[dir]-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1);
118  indexC[dir] = indexI[dir] ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qp1);
119  for (v=0; v<nvars; v++) {
120  /* Defining stencil points */
121  double m2, m1, p1;
122  m2 = fC[qm2*nvars+v];
123  m1 = fC[qm1*nvars+v];
124  p1 = fC[qp1*nvars+v];
125 
126  double slope_ratio = (m1 - m2) / ((p1 - m1) + 1e-40);
127  double phi = muscl->LimiterFunction(slope_ratio);
128  fI[p*nvars+v] = m1 + 0.5 * phi * (p1-m1);
129  }
130  }
131  }
132  } else {
133 #pragma omp parallel for schedule(auto) default(shared) private(i,index_outer,indexC,indexI)
134  for (i=0; i<N_outer; i++) {
135  _ArrayIndexnD_(ndims,i,bounds_outer,index_outer,0);
136  _ArrayCopy1D_(index_outer,indexC,ndims);
137  _ArrayCopy1D_(index_outer,indexI,ndims);
138  for (indexI[dir] = 0; indexI[dir] < dim[dir]+1; indexI[dir]++) {
139  int p; _ArrayIndex1D_(ndims,bounds_inter,indexI,0,p);
140  int qm1,qp1,qp2,v;
141  indexC[dir] = indexI[dir]-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1);
142  indexC[dir] = indexI[dir] ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qp1);
143  indexC[dir] = indexI[dir]+1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qp2);
144  for (v=0; v<nvars; v++) {
145  /* Defining stencil points */
146  double m1, p1, p2;
147  m1 = fC[qm1*nvars+v];
148  p1 = fC[qp1*nvars+v];
149  p2 = fC[qp2*nvars+v];
150 
151  double slope_ratio = (p1 - m1) / ((p2 - p1) + 1e-40);
152  double phi = muscl->LimiterFunction(slope_ratio);
153  fI[p*nvars+v] = p1 + 0.5 * phi * (p1-p2);
154  }
155  }
156  }
157  }
158 
159  return(0);
160 }
void * interp
Definition: hypar.h:362
Definitions for the functions computing the interpolated value of the primitive at the cell interface...
#define _ArrayIndexnD_(N, index, imax, i, ghost)
int * dim_local
Definition: hypar.h:37
MPI related function definitions.
double(* LimiterFunction)(double)
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
Contains function definitions for common mathematical functions.
#define _ArrayCopy1D_(x, y, size)
int nvars
Definition: hypar.h:29
int Interp1PrimSecondOrderMUSCL(double *, double *, double *, double *, int, int, void *, void *, int)
2nd order MUSCL scheme (component-wise) on a uniform grid
Contains structure definition for hypar.
Some basic definitions and macros.
Structure of variables/parameters needed by the MUSCL scheme.
int ndims
Definition: hypar.h:26
Contains macros and function definitions for common array operations.
#define _ArrayProduct1D_(x, size, p)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23