HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
Numa2DParabolicFunction.c File Reference
#include <stdlib.h>
#include <basic.h>
#include <arrayfunctions.h>
#include <mathfunctions.h>
#include <physicalmodels/numa2d.h>
#include <mpivars.h>
#include <hypar.h>

Go to the source code of this file.

Functions

int Numa2DParabolicFunction (double *par, double *u, void *s, void *m, double t)
 

Function Documentation

◆ Numa2DParabolicFunction()

int Numa2DParabolicFunction ( double *  par,
double *  u,
void *  s,
void *  m,
double  t 
)

Definition at line 17 of file Numa2DParabolicFunction.c.

18 {
19  HyPar *solver = (HyPar*) s;
20  MPIVariables *mpi = (MPIVariables*) m;
21  Numa2D *physics = (Numa2D*) solver->physics;
22  int i,v,done;
23  double dxinv, dyinv;
25 
26  int ghosts = solver->ghosts;
27  int imax = solver->dim_local[0];
28  int jmax = solver->dim_local[1];
29  int *dim = solver->dim_local;
30  int size = (imax+2*ghosts)*(jmax+2*ghosts)*_MODEL_NVARS_;
31 
32  _ArraySetValue_(par,size,0.0);
33  if (physics->mu <= 0) return(0); /* inviscid flow */
34  solver->count_par++;
35 
36  double mu = physics->mu;
37 
38  /* allocate some arrays */
39  double *Q, *QDeriv, *FViscous, *FDeriv;
40  Q = (double*) calloc (size,sizeof(double)); /* primitive variables */
41  QDeriv = (double*) calloc (size,sizeof(double)); /* derivative of primitive variables */
42  FViscous = (double*) calloc (size,sizeof(double)); /* viscous flux */
43  FDeriv = (double*) calloc (size,sizeof(double)); /* derivative of viscous flux */
44 
45  int index[_MODEL_NDIMS_], bounds[_MODEL_NDIMS_], offset[_MODEL_NDIMS_];
46  /* set bounds for array index to include ghost points */
47  _ArrayCopy1D_(dim,bounds,_MODEL_NDIMS_); for (i=0; i<_MODEL_NDIMS_; i++) bounds[i] += 2*ghosts;
48  /* set offset such that index is compatible with ghost point arrangement */
49  _ArraySetValue_(offset,_MODEL_NDIMS_,-ghosts);
50 
51  done = 0; _ArraySetValue_(index,_MODEL_NDIMS_,0);
52  while (!done) {
53  int p; _ArrayIndex1DWO_(_MODEL_NDIMS_,dim,index,offset,ghosts,p);
54  double drho,uvel,vvel,dT,rho0,T0,P0,EP,ycoord;
55 
56  _GetCoordinate_ (_YDIR_,index[_YDIR_]-ghosts,dim,ghosts,solver->x,ycoord);
57  physics->StandardAtmosphere (physics,ycoord,&EP,&P0,&rho0,&T0);
58  _Numa2DGetFlowVars_ ( (u+_MODEL_NVARS_*p),drho,uvel,vvel,dT,rho0);
59 
60  Q[_MODEL_NVARS_*p+0] = rho0 + drho; /* density */
61  Q[_MODEL_NVARS_*p+1] = uvel; /* x-velocity */
62  Q[_MODEL_NVARS_*p+2] = vvel; /* y-velocity */
63  Q[_MODEL_NVARS_*p+3] = (dT+T0)/(drho+rho0); /* potential temperature*/
64 
65  _ArrayIncrementIndex_(_MODEL_NDIMS_,bounds,index,done);
66  }
67 
68  /* Along X */
69  _ArraySetValue_(QDeriv,size,0.0);
70  IERR solver->FirstDerivativePar(QDeriv,Q,_XDIR_,1,solver,mpi); CHECKERR(ierr);
72  done = 0; _ArraySetValue_(index,_MODEL_NDIMS_,0);
73  while (!done) {
74  int p; _ArrayIndex1DWO_(_MODEL_NDIMS_,dim,index,offset,ghosts,p);
75  _GetCoordinate_(_XDIR_,index[_XDIR_]-ghosts,dim,ghosts,solver->dxinv,dxinv);
76 
77  double rho, ux, vx, tx;
78  rho = Q [_MODEL_NVARS_*p+0];
79  ux = QDeriv[_MODEL_NVARS_*p+1] / dxinv;
80  vx = QDeriv[_MODEL_NVARS_*p+2] / dxinv;
81  tx = QDeriv[_MODEL_NVARS_*p+3] / dxinv;
82 
83  FViscous[_MODEL_NVARS_*p+0] = 0.0;
84  FViscous[_MODEL_NVARS_*p+1] = mu * rho * ux;
85  FViscous[_MODEL_NVARS_*p+2] = mu * rho * vx;
86  FViscous[_MODEL_NVARS_*p+3] = mu * rho * tx;
87 
88  _ArrayIncrementIndex_(_MODEL_NDIMS_,bounds,index,done);
89  }
90  _ArraySetValue_(FDeriv,size,0.0);
91  IERR solver->FirstDerivativePar(FDeriv,FViscous,_XDIR_,-1,solver,mpi); CHECKERR(ierr);
92  done = 0; _ArraySetValue_(index,_MODEL_NDIMS_,0);
93  while (!done) {
94  int p; _ArrayIndex1D_(_MODEL_NDIMS_,dim,index,ghosts,p); p *= _MODEL_NVARS_;
95  _GetCoordinate_(_XDIR_,index[_XDIR_],dim,ghosts,solver->dxinv,dxinv);
96  for (v=0; v<_MODEL_NVARS_; v++) (par+p)[v] += (dxinv * (FDeriv+p)[v] );
97  _ArrayIncrementIndex_(_MODEL_NDIMS_,dim,index,done);
98  }
99 
100  /* Along Y */
101  _ArraySetValue_(QDeriv,size,0.0);
102  IERR solver->FirstDerivativePar(QDeriv,Q,_YDIR_,1,solver,mpi); CHECKERR(ierr);
103  IERR MPIExchangeBoundariesnD(_MODEL_NDIMS_,_MODEL_NVARS_,dim,ghosts,mpi,QDeriv);CHECKERR(ierr);
104  done = 0; _ArraySetValue_(index,_MODEL_NDIMS_,0);
105  while (!done) {
106  int p; _ArrayIndex1DWO_(_MODEL_NDIMS_,dim,index,offset,ghosts,p);
107  _GetCoordinate_(_YDIR_,index[_YDIR_]-ghosts,dim,ghosts,solver->dxinv,dyinv);
108 
109  double rho, uy, vy, ty;
110  rho = Q [_MODEL_NVARS_*p+0];
111  uy = QDeriv[_MODEL_NVARS_*p+1] / dyinv;
112  vy = QDeriv[_MODEL_NVARS_*p+2] / dyinv;
113  ty = QDeriv[_MODEL_NVARS_*p+3] / dyinv;
114 
115  FViscous[_MODEL_NVARS_*p+0] = 0.0;
116  FViscous[_MODEL_NVARS_*p+1] = mu * rho * uy;
117  FViscous[_MODEL_NVARS_*p+2] = mu * rho * vy;
118  FViscous[_MODEL_NVARS_*p+3] = mu * rho * ty;
119 
120  _ArrayIncrementIndex_(_MODEL_NDIMS_,bounds,index,done);
121  }
122  _ArraySetValue_(FDeriv,size,0.0);
123  IERR solver->FirstDerivativePar(FDeriv,FViscous,_YDIR_,-1,solver,mpi); CHECKERR(ierr);
124  done = 0; _ArraySetValue_(index,_MODEL_NDIMS_,0);
125  while (!done) {
126  int p; _ArrayIndex1D_(_MODEL_NDIMS_,dim,index,ghosts,p); p *= _MODEL_NVARS_;
127  _GetCoordinate_(_YDIR_,index[_YDIR_],dim,ghosts,solver->dxinv,dyinv);
128  for (v=0; v<_MODEL_NVARS_; v++) (par+p)[v] += (dyinv * (FDeriv+p)[v] );
129  _ArrayIncrementIndex_(_MODEL_NDIMS_,dim,index,done);
130  }
131 
132  free(Q);
133  free(QDeriv);
134  free(FViscous);
135  free(FDeriv);
136 
137  return(0);
138 }
#define IERR
Definition: basic.h:16
#define CHECKERR(ierr)
Definition: basic.h:18
double mu
Definition: numa2d.h:114
int MPIExchangeBoundariesnD(int, int, int *, int, void *, double *)
double * x
Definition: hypar.h:107
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
Definition: numa2d.h:109
#define _YDIR_
Definition: euler2d.h:41
#define _MODEL_NDIMS_
Definition: euler1d.h:56
int count_par
Definition: hypar.h:418
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArrayIndex1DWO_(N, imax, i, offset, ghost, index)
#define _ArraySetValue_(x, size, value)
int * dim_local
Definition: hypar.h:37
#define _ArrayIncrementIndex_(N, imax, i, done)
int(* FirstDerivativePar)(double *, double *, int, int, void *, void *)
Definition: hypar.h:243
#define _GetCoordinate_(dir, i, dim, ghosts, x, coord)
Definition: basic.h:31
void * physics
Definition: hypar.h:266
#define _Numa2DGetFlowVars_(u, drho, uvel, vvel, dT, rho0)
Definition: numa2d.h:33
#define _XDIR_
Definition: euler1d.h:75
int ghosts
Definition: hypar.h:52
Structure of MPI-related variables.
#define _MODEL_NVARS_
Definition: euler1d.h:58
void(* StandardAtmosphere)(void *, double, double *, double *, double *, double *)
Definition: numa2d.h:120
#define _DECLARE_IERR_
Definition: basic.h:17
#define _ArrayCopy1D_(x, y, size)
double * dxinv
Definition: hypar.h:110