HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
FPPowerSystem3BusUpwind.c File Reference

Upwinding function for the 3-bus power system model. More...

#include <stdlib.h>
#include <basic.h>
#include <arrayfunctions.h>
#include <physicalmodels/fppowersystem3bus.h>
#include <hypar.h>

Go to the source code of this file.

Functions

int FPPowerSystem3BusDriftFunction (int, void *, double *, double, double *)
 
int FPPowerSystem3BusUpwind (double *fI, double *fL, double *fR, double *uL, double *uR, double *u, int dir, void *s, double t)
 

Detailed Description

Upwinding function for the 3-bus power system model.

Author
Debojyoti Ghosh

Definition in file FPPowerSystem3BusUpwind.c.

Function Documentation

◆ FPPowerSystem3BusDriftFunction()

int FPPowerSystem3BusDriftFunction ( int  dir,
void *  p,
double *  x,
double  t,
double *  drift 
)

Compute the drift (advection) coefficients for the 3-bus power system

Parameters
dirSpatial dimension (not used)
pObject of type FPPowerSystem3Bus
xSpatial coordinates
tCurrent simulation time
driftArray to hold the drift velocities

Definition at line 76 of file FPPowerSystem3BusFunctions.c.

83 {
84  FPPowerSystem3Bus *params = (FPPowerSystem3Bus*) p;
85 
86  double theta1 = x[0];
87  double theta2 = x[1];
88  double Omega1 = x[2];
89  double Omega2 = x[3];
90 
91  double omegaB = params->omegaB;
92  double Pm1_avg = params->Pm1_avg;
93  double Pm2_avg = params->Pm2_avg;
94  double Pmref_avg = params->Pmref_avg;
95  double H1 = params->H1;
96  double H2 = params->H2;
97  double Href = params->Href;
98  double gamma = params->gamma;
99 
100  double Pe1, Pe2, Peref;
101  ComputeElectricalPower(theta1,theta2,params,&Pe1,&Pe2,&Peref);
102 
103  double F1 = Pm1_avg / (2*H1) - Pmref_avg / (2*Href);
104  double F2 = Pm2_avg / (2*H2) - Pmref_avg / (2*Href);
105  double S1 = Pe1 / (2*H1) - Peref / (2*Href);
106  double S2 = Pe2 / (2*H2) - Peref / (2*Href);
107 
108  drift[0] = omegaB * Omega1;
109  drift[1] = omegaB * Omega2;
110  drift[2] = F1 - gamma*Omega1 - S1;
111  drift[3] = F2 - gamma*Omega2 - S2;
112 
113  return(0);
114 }
static void ComputeElectricalPower(double theta1, double theta2, void *p, double *Pe1, double *Pe2, double *Pe3)
#define drift(x)
Definition: fpdoublewell.h:31
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.

◆ FPPowerSystem3BusUpwind()

int FPPowerSystem3BusUpwind ( double *  fI,
double *  fL,
double *  fR,
double *  uL,
double *  uR,
double *  u,
int  dir,
void *  s,
double  t 
)

Compute the upwind flux at the interface, based on the drift velocity at that interface, from the left and right biased approximations to the interface flux. The drift (advection) velocity is multiplied to the solution in this function to get the advective flux.

Parameters
fIComputed upwind interface flux
fLLeft-biased reconstructed interface flux
fRRight-biased reconstructed interface flux
uLLeft-biased reconstructed interface solution
uRRight-biased reconstructed interface solution
uCell-centered solution
dirSpatial dimension (x or y)
sSolver object of type HyPar
tCurrent solution time

Definition at line 18 of file FPPowerSystem3BusUpwind.c.

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 }
int nvars
Definition: hypar.h:29
double * x
Definition: hypar.h:107
#define drift(x)
Definition: fpdoublewell.h:31
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int FPPowerSystem3BusDriftFunction(int, void *, double *, double, double *)
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArraySetValue_(x, size, value)
int * dim_local
Definition: hypar.h:37
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _GetCoordinate_(dir, i, dim, ghosts, x, coord)
Definition: basic.h:31
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 _ArrayCopy1D_(x, y, size)