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

Function to compute the maximum CFL for the FPPowerSystem3Bus system. More...

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

Go to the source code of this file.

Functions

int FPPowerSystem3BusDriftFunction (int, void *, double *, double, double *)
 
double FPPowerSystem3BusComputeCFL (void *s, void *m, double dt, double t)
 

Detailed Description

Function to compute the maximum CFL for the FPPowerSystem3Bus system.

Author
Debojyoti Ghosh

Definition in file FPPowerSystem3BusComputeCFL.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.

◆ FPPowerSystem3BusComputeCFL()

double FPPowerSystem3BusComputeCFL ( void *  s,
void *  m,
double  dt,
double  t 
)

Computes the maximum CFL number over the domain. Note that the CFL is computed over the local domain on this processor only.

Parameters
sSolver object of type HyPar
mMPI object of type MPIVariables
dtTime step size for which to compute the CFL
tTime

Definition at line 19 of file FPPowerSystem3BusComputeCFL.c.

25 {
26  HyPar *solver = (HyPar*) s;
27  FPPowerSystem3Bus *params = (FPPowerSystem3Bus*) solver->physics;
28 
29  int ndims = solver->ndims;
30  int ghosts = solver->ghosts;
31  int *dim = solver->dim_local;
32 
33  double max_cfl = 0;
34  int index[ndims];
35  int done = 0; _ArraySetValue_(index,ndims,0);
36  while (!done) {
37  double x[ndims], dxinv[ndims], drift[ndims];
38  _GetCoordinate_(0,index[0],dim,ghosts,solver->x,x[0]);
39  _GetCoordinate_(1,index[1],dim,ghosts,solver->x,x[1]);
40  _GetCoordinate_(2,index[2],dim,ghosts,solver->x,x[2]);
41  _GetCoordinate_(3,index[3],dim,ghosts,solver->x,x[3]);
42  _GetCoordinate_(0,index[0],dim,ghosts,solver->dxinv,dxinv[0]);
43  _GetCoordinate_(1,index[1],dim,ghosts,solver->dxinv,dxinv[1]);
44  _GetCoordinate_(2,index[2],dim,ghosts,solver->dxinv,dxinv[2]);
45  _GetCoordinate_(3,index[3],dim,ghosts,solver->dxinv,dxinv[3]);
46 
48 
49  double local_cfl[ndims];
50  local_cfl[0] = absolute(drift[0]) * dt * dxinv[0];
51  local_cfl[1] = absolute(drift[1]) * dt * dxinv[1];
52  local_cfl[2] = absolute(drift[2]) * dt * dxinv[2];
53  local_cfl[3] = absolute(drift[3]) * dt * dxinv[3];
54 
55  if (local_cfl[0] > max_cfl) max_cfl = local_cfl[0];
56  if (local_cfl[1] > max_cfl) max_cfl = local_cfl[1];
57  if (local_cfl[2] > max_cfl) max_cfl = local_cfl[2];
58  if (local_cfl[3] > max_cfl) max_cfl = local_cfl[3];
59 
60  _ArrayIncrementIndex_(ndims,dim,index,done);
61  }
62 
63  return(max_cfl);
64 }
#define absolute(a)
Definition: math_ops.h:32
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 _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.
double * dxinv
Definition: hypar.h:110