HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
FPPowerSystem3BusComputeDiffNumber.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 FPPowerSystem3BusDissipationFunction(int,int,void*,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_diff = 0;
34  int index[ndims];
35  int done = 0; _ArraySetValue_(index,ndims,0);
36  while (!done) {
37  double dxinv[ndims],dissp[ndims*ndims];
38  _GetCoordinate_(0,index[0],dim,ghosts,solver->dxinv,dxinv[0]);
39  _GetCoordinate_(1,index[1],dim,ghosts,solver->dxinv,dxinv[1]);
40  _GetCoordinate_(2,index[2],dim,ghosts,solver->dxinv,dxinv[2]);
41  _GetCoordinate_(3,index[3],dim,ghosts,solver->dxinv,dxinv[3]);
42  FPPowerSystem3BusDissipationFunction(0,0,params,t,dissp);
43 
44  double local_diff[ndims];
45  local_diff[0] = absolute(dissp[0*ndims+0]) * dt * dxinv[0] * dxinv[0];
46  local_diff[1] = absolute(dissp[1*ndims+1]) * dt * dxinv[1] * dxinv[1];
47  local_diff[2] = absolute(dissp[2*ndims+2]) * dt * dxinv[2] * dxinv[2];
48  local_diff[3] = absolute(dissp[3*ndims+3]) * dt * dxinv[3] * dxinv[3];
49 
50  if (local_diff[0] > max_diff) max_diff = local_diff[0];
51  if (local_diff[1] > max_diff) max_diff = local_diff[1];
52  if (local_diff[2] > max_diff) max_diff = local_diff[2];
53  if (local_diff[3] > max_diff) max_diff = local_diff[3];
54 
55  _ArrayIncrementIndex_(ndims,dim,index,done);
56  }
57 
58  return(max_diff);
59 }
60 
#define absolute(a)
Definition: math_ops.h:32
MPI related function definitions.
Contains function definitions for common mathematical functions.
Some basic definitions and macros.
int FPPowerSystem3BusDissipationFunction(int, int, void *, double, double *)
double FPPowerSystem3BusComputeDiffNumber(void *s, void *m, double dt, double t)
int ndims
Definition: hypar.h:26
3-Bus Power System model
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
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