HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
FPPowerSystem3BusUpwind.c
Go to the documentation of this file.
1 
5 #include <stdlib.h>
6 #include <basic.h>
7 #include <arrayfunctions.h>
9 #include <hypar.h>
10 
11 int FPPowerSystem3BusDriftFunction(int,void*,double*,double,double*);
12 
19  double *fI,
20  double *fL,
21  double *fR,
22  double *uL,
23  double *uR,
24  double *u,
25  int dir,
26  void *s,
27  double t
28  )
29 {
30  HyPar *solver = (HyPar*) s;
31  FPPowerSystem3Bus *params = (FPPowerSystem3Bus*) solver->physics;
32  int done,v;
33 
34  int ndims = solver->ndims;
35  int nvars = solver->nvars;
36  int ghosts = solver->ghosts;
37  int *dim = solver->dim_local;
38 
39  int index_outer[ndims], index_inter[ndims], bounds_outer[ndims], bounds_inter[ndims];
40  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
41  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
42 
43  done = 0; _ArraySetValue_(index_outer,ndims,0);
44  while (!done) {
45  _ArrayCopy1D_(index_outer,index_inter,ndims);
46  for (index_inter[dir] = 0; index_inter[dir] < bounds_inter[dir]; index_inter[dir]++) {
47  int p; _ArrayIndex1D_(ndims,bounds_inter,index_inter,0, p);
48  double x[ndims]; /* coordinates of the interface */
49  double x1, x2, drift[ndims];
50  if (dir == 0) {
51  _GetCoordinate_(0,index_inter[0]-1,dim,ghosts,solver->x,x1);
52  _GetCoordinate_(0,index_inter[0] ,dim,ghosts,solver->x,x2);
53  x[0] = 0.5 * ( x1 + x2 );
54  _GetCoordinate_(1,index_inter[1],dim,ghosts,solver->x,x[1]);
55  _GetCoordinate_(2,index_inter[2],dim,ghosts,solver->x,x[2]);
56  _GetCoordinate_(3,index_inter[3],dim,ghosts,solver->x,x[3]);
57  } else if (dir == 1) {
58  _GetCoordinate_(0,index_inter[0],dim,ghosts,solver->x,x[0]);
59  _GetCoordinate_(1,index_inter[1]-1,dim,ghosts,solver->x,x1);
60  _GetCoordinate_(1,index_inter[1] ,dim,ghosts,solver->x,x2);
61  x[1] = 0.5 * ( x1 + x2 );
62  _GetCoordinate_(2,index_inter[2],dim,ghosts,solver->x,x[2]);
63  _GetCoordinate_(3,index_inter[3],dim,ghosts,solver->x,x[3]);
64  } else if (dir == 2) {
65  _GetCoordinate_(0,index_inter[0],dim,ghosts,solver->x,x[0]);
66  _GetCoordinate_(1,index_inter[1],dim,ghosts,solver->x,x[1]);
67  _GetCoordinate_(2,index_inter[2]-1,dim,ghosts,solver->x,x1);
68  _GetCoordinate_(2,index_inter[2] ,dim,ghosts,solver->x,x2);
69  x[2] = 0.5 * ( x1 + x2 );
70  _GetCoordinate_(3,index_inter[3],dim,ghosts,solver->x,x[3]);
71  } else if (dir == 3) {
72  _GetCoordinate_(0,index_inter[0],dim,ghosts,solver->x,x[0]);
73  _GetCoordinate_(1,index_inter[1],dim,ghosts,solver->x,x[1]);
74  _GetCoordinate_(2,index_inter[2],dim,ghosts,solver->x,x[2]);
75  _GetCoordinate_(3,index_inter[3]-1,dim,ghosts,solver->x,x1);
76  _GetCoordinate_(3,index_inter[3] ,dim,ghosts,solver->x,x2);
77  x[3] = 0.5 * ( x1 + x2 );
78  }
79  FPPowerSystem3BusDriftFunction(dir,params,x,t,drift);
80  for (v = 0; v < nvars; v++)
81  fI[nvars*p+v] = drift[dir] * (drift[dir] > 0 ? fL[nvars*p+v] : fR[nvars*p+v] );
82  }
83  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
84  }
85 
86  return(0);
87 }
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
3-Bus Power System model
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)
int FPPowerSystem3BusUpwind(double *, double *, double *, double *, double *, double *, int, void *, double)
int FPPowerSystem3BusDriftFunction(int, void *, double *, double, double *)
#define _ArrayCopy1D_(x, y, size)
int nvars
Definition: hypar.h:29
Structure containing variable and parameters specific to the 3-bus power system model. This structure contains the physical parameters and variables for the Fokker-Planck model for a 3-bus power system.
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.
double * x
Definition: hypar.h:107
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23