HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
FPPowerSystem3BusComputeCFL.c
Go to the documentation of this file.
1 
6 #include <stdlib.h>
7 #include <basic.h>
8 #include <mathfunctions.h>
9 #include <arrayfunctions.h>
11 #include <mpivars.h>
12 #include <hypar.h>
13 
14 int FPPowerSystem3BusDriftFunction(int,void*,double*,double,double*);
15 
20  void *s,
21  void *m,
22  double dt,
23  double t
24  )
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
MPI related function definitions.
Contains function definitions for common mathematical functions.
Some basic definitions and macros.
double * x
Definition: hypar.h:107
#define drift(x)
Definition: fpdoublewell.h:31
int ndims
Definition: hypar.h:26
double FPPowerSystem3BusComputeCFL(void *s, void *m, double dt, double t)
3-Bus Power System model
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int FPPowerSystem3BusDriftFunction(int, void *, double *, double, double *)
Contains structure definition for hypar.
#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.
Contains macros and function definitions for common array operations.
double * dxinv
Definition: hypar.h:110