HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
FPPowerSystem3BusDiffusion.c
Go to the documentation of this file.
1 
6 #include <stdlib.h>
7 #include <basic.h>
8 #include <arrayfunctions.h>
10 #include <hypar.h>
11 
12 int FPPowerSystem3BusDissipationFunction(int,int,void*,double,double*);
13 
16  double *f,
17  double *u,
18  int dir1,
19  int dir2,
20  void *s,
21  double t
22  )
23 {
24  HyPar *solver = (HyPar*) s;
25  FPPowerSystem3Bus *params = (FPPowerSystem3Bus*) solver->physics;
26  int i, v;
27 
28  int *dim = solver->dim_local;
29  int ghosts = solver->ghosts;
30  static int index[_MODEL_NDIMS_], bounds[_MODEL_NDIMS_], offset[_MODEL_NDIMS_];
31  static double dissipation[_MODEL_NDIMS_*_MODEL_NDIMS_];
32 
33  /* set bounds for array index to include ghost points */
34  _ArrayCopy1D_(dim,bounds,_MODEL_NDIMS_);
35  for (i=0; i<_MODEL_NDIMS_; i++) bounds[i] += 2*ghosts;
36 
37  /* set offset such that index is compatible with ghost point arrangement */
38  _ArraySetValue_(offset,_MODEL_NDIMS_,-ghosts);
39 
40  int done = 0; _ArraySetValue_(index,_MODEL_NDIMS_,0);
41  while (!done) {
42  int p; _ArrayIndex1DWO_(_MODEL_NDIMS_,dim,index,offset,ghosts,p);
43  FPPowerSystem3BusDissipationFunction(dir1,dir2,params,t,dissipation);
44  for (v = 0; v < _MODEL_NVARS_; v++) f[_MODEL_NVARS_*p+v] = dissipation[dir1*_MODEL_NDIMS_+dir2] * u[_MODEL_NVARS_*p+v];
45  _ArrayIncrementIndex_(_MODEL_NDIMS_,bounds,index,done);
46  }
47 
48  return(0);
49 }
Some basic definitions and macros.
3-Bus Power System model
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _MODEL_NDIMS_
Definition: euler1d.h:56
Contains structure definition for hypar.
int FPPowerSystem3BusDiffusion(double *f, double *u, int dir1, int dir2, void *s, double t)
int FPPowerSystem3BusDissipationFunction(int, int, void *, double, double *)
#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)
void * physics
Definition: hypar.h:266
int ghosts
Definition: hypar.h:52
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.
#define _MODEL_NVARS_
Definition: euler1d.h:58
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.