HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
FPPowerSystem1BusUpwind.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <basic.h>
3 #include <arrayfunctions.h>
5 #include <hypar.h>
6 
7 double FPPowerSystem1BusDriftFunction(int,void*,double,double,double);
8 
9 int FPPowerSystem1BusUpwind(double *fI,double *fL,double *fR,double *uL,double *uR,
10  double *u,int dir,void *s,double t)
11 {
12  HyPar *solver = (HyPar*) s;
13  FPPowerSystem1Bus *params = (FPPowerSystem1Bus*) solver->physics;
14  int done,v;
15 
16  int ndims = solver->ndims;
17  int nvars = solver->nvars;
18  int ghosts = solver->ghosts;
19  int *dim = solver->dim_local;
20 
21  int index_outer[ndims], index_inter[ndims], bounds_outer[ndims], bounds_inter[ndims];
22  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
23  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
24 
25  done = 0; _ArraySetValue_(index_outer,ndims,0);
26  while (!done) {
27  _ArrayCopy1D_(index_outer,index_inter,ndims);
28  for (index_inter[dir] = 0; index_inter[dir] < bounds_inter[dir]; index_inter[dir]++) {
29  int p; _ArrayIndex1D_(ndims,bounds_inter,index_inter,0, p);
30  double x = 0,y = 0; /* x,y coordinates of the interface */
31  if (dir == 0) {
32  /* x-interface */
33  double x1, x2;
34  _GetCoordinate_(_XDIR_,index_inter[_XDIR_]-1,dim,ghosts,solver->x,x1);
35  _GetCoordinate_(_XDIR_,index_inter[_XDIR_] ,dim,ghosts,solver->x,x2);
36  x = 0.5 * ( x1 + x2 );
37  _GetCoordinate_(_YDIR_,index_inter[_YDIR_],dim,ghosts,solver->x,y);
38  } else if (dir == 1) {
39  /* y-interface */
40  _GetCoordinate_(_XDIR_,index_inter[_XDIR_],dim,ghosts,solver->x,x);
41  double y1, y2;
42  _GetCoordinate_(_YDIR_,index_inter[_YDIR_]-1,dim,ghosts,solver->x,y1);
43  _GetCoordinate_(_YDIR_,index_inter[_YDIR_] ,dim,ghosts,solver->x,y2);
44  y = 0.5 * ( y1 + y2 );
45  }
46  double drift = FPPowerSystem1BusDriftFunction(dir,params,x,y,t);
47  for (v = 0; v < nvars; v++)
48  fI[nvars*p+v] = drift * (drift > 0 ? fL[nvars*p+v] : fR[nvars*p+v] );
49  }
50  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
51  }
52 
53  return(0);
54 }
#define _YDIR_
Definition: euler2d.h:41
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
void * physics
Definition: hypar.h:266
int * dim_local
Definition: hypar.h:37
#define drift(x)
Definition: fpdoublewell.h:31
#define _GetCoordinate_(dir, i, dim, ghosts, x, coord)
Definition: basic.h:31
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArrayCopy1D_(x, y, size)
int nvars
Definition: hypar.h:29
Contains structure definition for hypar.
Some basic definitions and macros.
int ndims
Definition: hypar.h:26
Contains macros and function definitions for common array operations.
int FPPowerSystem1BusUpwind(double *, double *, double *, double *, double *, double *, int, void *, double)
double * x
Definition: hypar.h:107
double FPPowerSystem1BusDriftFunction(int, void *, double, double, double)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
Fokker-Planck Model for 1-Bus Power System.
#define _XDIR_
Definition: euler1d.h:75