HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
FPPowerSystem1BusInitialize.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <basic.h>
#include <arrayfunctions.h>
#include <physicalmodels/fppowersystem1bus.h>
#include <mpivars.h>
#include <hypar.h>

Go to the source code of this file.

Functions

double FPPowerSystem1BusComputeCFL (void *, void *, double, double)
 
double FPPowerSystem1BusComputeDiffNumber (void *, void *, double, double)
 
int FPPowerSystem1BusAdvection (double *, double *, int, void *, double)
 
int FPPowerSystem1BusDiffusionLaplacian (double *, double *, int, void *, double)
 
int FPPowerSystem1BusDiffusionGeneral (double *, double *, int, int, void *, double)
 
int FPPowerSystem1BusUpwind (double *, double *, double *, double *, double *, double *, int, void *, double)
 
int FPPowerSystem1BusPostStep (double *, void *, void *, double, int)
 
int FPPowerSystem1BusPrintStep (void *, void *, double)
 
int FPPowerSystem1BusInitialize (void *s, void *m)
 

Function Documentation

◆ FPPowerSystem1BusComputeCFL()

double FPPowerSystem1BusComputeCFL ( void *  ,
void *  ,
double  ,
double   
)

Definition at line 11 of file FPPowerSystem1BusComputeCFL.c.

12 {
13  HyPar *solver = (HyPar*) s;
14  FPPowerSystem1Bus *params = (FPPowerSystem1Bus*) solver->physics;
15 
16  int ndims = solver->ndims;
17  int ghosts = solver->ghosts;
18  int *dim = solver->dim_local;
19 
20  double max_cfl = 0;
21  int index[ndims];
22  int done = 0; _ArraySetValue_(index,ndims,0);
23  while (!done) {
24  double x; _GetCoordinate_(_XDIR_,index[_XDIR_],dim,ghosts,solver->x,x);
25  double y; _GetCoordinate_(_YDIR_,index[_YDIR_],dim,ghosts,solver->x,y);
26  double dxinv; _GetCoordinate_(_XDIR_,index[_XDIR_],dim,ghosts,solver->dxinv,dxinv);
27  double dyinv; _GetCoordinate_(_YDIR_,index[_YDIR_],dim,ghosts,solver->dxinv,dyinv);
28  double drift_x= FPPowerSystem1BusDriftFunction(_XDIR_,params,x,y,t);
29  double drift_y= FPPowerSystem1BusDriftFunction(_YDIR_,params,x,y,t);
30 
31  double local_cfl_x = absolute(drift_x) * dt * dxinv;
32  double local_cfl_y = absolute(drift_y) * dt * dyinv;
33 
34  if (local_cfl_x > max_cfl) max_cfl = local_cfl_x;
35  if (local_cfl_y > max_cfl) max_cfl = local_cfl_y;
36 
37  _ArrayIncrementIndex_(ndims,dim,index,done);
38  }
39 
40  return(max_cfl);
41 }
#define absolute(a)
Definition: math_ops.h:32
double FPPowerSystem1BusDriftFunction(int, void *, double, double, double)
double * x
Definition: hypar.h:107
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _YDIR_
Definition: euler2d.h:41
#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
#define _XDIR_
Definition: euler1d.h:75
int ghosts
Definition: hypar.h:52
double * dxinv
Definition: hypar.h:110

◆ FPPowerSystem1BusComputeDiffNumber()

double FPPowerSystem1BusComputeDiffNumber ( void *  ,
void *  ,
double  ,
double   
)

Definition at line 11 of file FPPowerSystem1BusComputeDiffNumber.c.

12 {
13  HyPar *solver = (HyPar*) s;
14  FPPowerSystem1Bus *params = (FPPowerSystem1Bus*) solver->physics;
15 
16  int ndims = solver->ndims;
17  int ghosts = solver->ghosts;
18  int *dim = solver->dim_local;
19 
20  double max_diff = 0;
21  int index[ndims];
22  int done = 0; _ArraySetValue_(index,ndims,0);
23  while (!done) {
24  double dxinv; _GetCoordinate_(0,index[0],dim,ghosts,solver->dxinv,dxinv);
25  double dyinv; _GetCoordinate_(1,index[1],dim,ghosts,solver->dxinv,dyinv);
26  double dissp_yx= FPPowerSystem1BusDissipationFunction(_YDIR_,_XDIR_,params,t);
27  double dissp_yy= FPPowerSystem1BusDissipationFunction(_YDIR_,_YDIR_,params,t);
28 
29  double local_diff_yx = absolute(dissp_yx) * dt * dyinv * dxinv;
30  double local_diff_yy = absolute(dissp_yy) * dt * dyinv * dyinv;
31 
32  if (local_diff_yx > max_diff) max_diff = local_diff_yx;
33  if (local_diff_yy > max_diff) max_diff = local_diff_yy;
34 
35  _ArrayIncrementIndex_(ndims,dim,index,done);
36  }
37 
38  return(max_diff);
39 }
#define absolute(a)
Definition: math_ops.h:32
double FPPowerSystem1BusDissipationFunction(int, int, void *, double)
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _YDIR_
Definition: euler2d.h:41
#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
#define _XDIR_
Definition: euler1d.h:75
int ghosts
Definition: hypar.h:52
double * dxinv
Definition: hypar.h:110

◆ FPPowerSystem1BusAdvection()

int FPPowerSystem1BusAdvection ( double *  ,
double *  ,
int  ,
void *  ,
double   
)

Definition at line 7 of file FPPowerSystem1BusAdvection.c.

8 {
9  HyPar *solver = (HyPar*) s;
10  int *dim = solver->dim_local;
11  int ghosts = solver->ghosts;
12  int ndims = solver->ndims;
13  int nvars = solver->nvars;
14 
15  /* calculate total size of arrays */
16  int bounds[ndims]; _ArrayAddCopy1D_(dim,(2*ghosts),bounds,ndims);
17  int size; _ArrayProduct1D_(bounds,ndims,size); size *= nvars;
18 
19  /* f = u */
20  _ArrayCopy1D_(u,f,size);
21 
22  return(0);
23 }
int nvars
Definition: hypar.h:29
int ndims
Definition: hypar.h:26
#define _ArrayAddCopy1D_(x, a, y, size)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int * dim_local
Definition: hypar.h:37
int ghosts
Definition: hypar.h:52
#define _ArrayCopy1D_(x, y, size)
#define _ArrayProduct1D_(x, size, p)

◆ FPPowerSystem1BusDiffusionLaplacian()

int FPPowerSystem1BusDiffusionLaplacian ( double *  ,
double *  ,
int  ,
void *  ,
double   
)

Definition at line 9 of file FPPowerSystem1BusDiffusion.c.

10 {
11  HyPar *solver = (HyPar*) s;
12  FPPowerSystem1Bus *params = (FPPowerSystem1Bus*) solver->physics;
13 
14  int *dim = solver->dim_local;
15  int ghosts = solver->ghosts;
16  int ndims = solver->ndims;
17  int nvars = solver->nvars;
18 
19  /* calculate total size of arrays */
20  int bounds[ndims]; _ArrayAddCopy1D_(dim,(2*ghosts),bounds,ndims);
21  int size; _ArrayProduct1D_(bounds,ndims,size); size *= nvars;
22 
23  /* calculate dissipation coefficient -- constant in x and y */
24  double dissipation = FPPowerSystem1BusDissipationFunction(dir,dir,params,t);
25 
26  /* f = dissipation * u */
27  _ArrayScaleCopy1D_(u,dissipation,f,size);
28 
29  return(0);
30 }
int nvars
Definition: hypar.h:29
int ndims
Definition: hypar.h:26
#define _ArrayScaleCopy1D_(x, a, y, size)
#define _ArrayAddCopy1D_(x, a, y, size)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int * dim_local
Definition: hypar.h:37
double FPPowerSystem1BusDissipationFunction(int, int, void *, double)
void * physics
Definition: hypar.h:266
int ghosts
Definition: hypar.h:52
#define _ArrayProduct1D_(x, size, p)

◆ FPPowerSystem1BusDiffusionGeneral()

int FPPowerSystem1BusDiffusionGeneral ( double *  ,
double *  ,
int  ,
int  ,
void *  ,
double   
)

Definition at line 32 of file FPPowerSystem1BusDiffusion.c.

33 {
34  HyPar *solver = (HyPar*) s;
35  FPPowerSystem1Bus *params = (FPPowerSystem1Bus*) solver->physics;
36 
37  int *dim = solver->dim_local;
38  int ghosts = solver->ghosts;
39  int ndims = solver->ndims;
40  int nvars = solver->nvars;
41 
42  /* calculate total size of arrays */
43  int bounds[ndims]; _ArrayAddCopy1D_(dim,(2*ghosts),bounds,ndims);
44  int size; _ArrayProduct1D_(bounds,ndims,size); size *= nvars;
45 
46  /* calculate dissipation coefficient -- constant in x and y */
47  double dissipation = FPPowerSystem1BusDissipationFunction(dir1,dir2,params,t);
48 
49  /* f = dissipation * u */
50  _ArrayScaleCopy1D_(u,dissipation,f,size);
51 
52  return(0);
53 }
int nvars
Definition: hypar.h:29
int ndims
Definition: hypar.h:26
#define _ArrayScaleCopy1D_(x, a, y, size)
#define _ArrayAddCopy1D_(x, a, y, size)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int * dim_local
Definition: hypar.h:37
double FPPowerSystem1BusDissipationFunction(int, int, void *, double)
void * physics
Definition: hypar.h:266
int ghosts
Definition: hypar.h:52
#define _ArrayProduct1D_(x, size, p)

◆ FPPowerSystem1BusUpwind()

int FPPowerSystem1BusUpwind ( double *  ,
double *  ,
double *  ,
double *  ,
double *  ,
double *  ,
int  ,
void *  ,
double   
)

Definition at line 9 of file FPPowerSystem1BusUpwind.c.

11 {
12  HyPar *solver = (HyPar*) s;
13  FPPowerSystem1Bus *params = (FPPowerSystem1Bus*) solver->physics;
14  int done,v;
15 
16  int ndims = solver->ndims;
17  int nvars = solver->nvars;
18  int ghosts = solver->ghosts;
19  int *dim = solver->dim_local;
20 
21  int index_outer[ndims], index_inter[ndims], bounds_outer[ndims], bounds_inter[ndims];
22  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
23  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
24 
25  done = 0; _ArraySetValue_(index_outer,ndims,0);
26  while (!done) {
27  _ArrayCopy1D_(index_outer,index_inter,ndims);
28  for (index_inter[dir] = 0; index_inter[dir] < bounds_inter[dir]; index_inter[dir]++) {
29  int p; _ArrayIndex1D_(ndims,bounds_inter,index_inter,0, p);
30  double x = 0,y = 0; /* x,y coordinates of the interface */
31  if (dir == 0) {
32  /* x-interface */
33  double x1, x2;
34  _GetCoordinate_(_XDIR_,index_inter[_XDIR_]-1,dim,ghosts,solver->x,x1);
35  _GetCoordinate_(_XDIR_,index_inter[_XDIR_] ,dim,ghosts,solver->x,x2);
36  x = 0.5 * ( x1 + x2 );
37  _GetCoordinate_(_YDIR_,index_inter[_YDIR_],dim,ghosts,solver->x,y);
38  } else if (dir == 1) {
39  /* y-interface */
40  _GetCoordinate_(_XDIR_,index_inter[_XDIR_],dim,ghosts,solver->x,x);
41  double y1, y2;
42  _GetCoordinate_(_YDIR_,index_inter[_YDIR_]-1,dim,ghosts,solver->x,y1);
43  _GetCoordinate_(_YDIR_,index_inter[_YDIR_] ,dim,ghosts,solver->x,y2);
44  y = 0.5 * ( y1 + y2 );
45  }
46  double drift = FPPowerSystem1BusDriftFunction(dir,params,x,y,t);
47  for (v = 0; v < nvars; v++)
48  fI[nvars*p+v] = drift * (drift > 0 ? fL[nvars*p+v] : fR[nvars*p+v] );
49  }
50  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
51  }
52 
53  return(0);
54 }
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
#define _YDIR_
Definition: euler2d.h:41
#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
#define _XDIR_
Definition: euler1d.h:75
int ghosts
Definition: hypar.h:52
double FPPowerSystem1BusDriftFunction(int, void *, double, double, double)
#define _ArrayCopy1D_(x, y, size)

◆ FPPowerSystem1BusPostStep()

int FPPowerSystem1BusPostStep ( double *  ,
void *  ,
void *  ,
double  ,
int   
)

Definition at line 8 of file FPPowerSystem1BusPostStep.c.

9 {
10  HyPar *solver = (HyPar*) s;
11  MPIVariables *mpi = (MPIVariables*) m;
12  FPPowerSystem1Bus *params = (FPPowerSystem1Bus*) solver->physics;
14 
15  int *dim = solver->dim_local;
16  int ghosts = solver->ghosts;
17  int ndims = solver->ndims;
18  int index[ndims];
19 
20  double local_sum = 0;
21  int done = 0; _ArraySetValue_(index,ndims,0);
22  while (!done) {
23  int p; _ArrayIndex1D_(ndims,dim,index,ghosts,p);
24  double dxinv; _GetCoordinate_(_XDIR_,index[_XDIR_],dim,ghosts,solver->dxinv,dxinv);
25  double dyinv; _GetCoordinate_(_YDIR_,index[_YDIR_],dim,ghosts,solver->dxinv,dyinv);
26  local_sum += (u[p] / (dxinv * dyinv));
27  _ArrayIncrementIndex_(ndims,dim,index,done);
28  }
29  double local_integral = local_sum;
30  double global_integral = 0;
31  IERR MPISum_double(&global_integral,&local_integral,1,&mpi->world); CHECKERR(ierr);
32  params->pdf_integral = global_integral;
33 
34  return(0);
35 }
#define IERR
Definition: basic.h:16
#define CHECKERR(ierr)
Definition: basic.h:18
int MPISum_double(double *, double *, int, void *)
Definition: MPISum.c:39
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _YDIR_
Definition: euler2d.h:41
MPI_Comm world
#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
#define _XDIR_
Definition: euler1d.h:75
int ghosts
Definition: hypar.h:52
Structure of MPI-related variables.
#define _DECLARE_IERR_
Definition: basic.h:17
double * dxinv
Definition: hypar.h:110

◆ FPPowerSystem1BusPrintStep()

int FPPowerSystem1BusPrintStep ( void *  ,
void *  ,
double   
)

Definition at line 5 of file FPPowerSystem1BusPrintStep.c.

6 {
7  HyPar *solver = (HyPar*) s;
8  FPPowerSystem1Bus *params = (FPPowerSystem1Bus*) solver->physics;
9  printf("Domain integral of the probability density function: %1.16E\n",params->pdf_integral);
10  return(0);
11 }
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
void * physics
Definition: hypar.h:266

◆ FPPowerSystem1BusInitialize()

int FPPowerSystem1BusInitialize ( void *  s,
void *  m 
)

Definition at line 21 of file FPPowerSystem1BusInitialize.c.

22 {
23  HyPar *solver = (HyPar*) s;
24  MPIVariables *mpi = (MPIVariables*) m;
25  FPPowerSystem1Bus *physics = (FPPowerSystem1Bus*) solver->physics;
26  int ferr;
28 
29  static int count = 0;
30 
31  if (solver->nvars != _MODEL_NVARS_) {
32  fprintf(stderr,"Error in FPPowerSystem1BusInitialize(): nvars has to be %d.\n",_MODEL_NVARS_);
33  return(1);
34  }
35  if (solver->ndims != _MODEL_NDIMS_) {
36  fprintf(stderr,"Error in FPPowerSystem1BusInitialize(): ndims has to be %d.\n",_MODEL_NDIMS_);
37  return(1);
38  }
39 
40  /* default values of model parameters */
41  physics->omegaS = 1.0;
42  physics->omegaB = 120 * (4.0 * atan(1.0));
43  physics->H = 5.0;
44  physics->D = 5.0;
45  physics->Pm_avg = 0.9;
46  physics->Pmax = 2.1;
47  physics->sigma = 0.2;
48  physics->lambda = 100.0 / physics->omegaB;
49 
50  /* reading physical model specific inputs */
51  if (!mpi->rank) {
52  FILE *in;
53  if (!count) printf("Reading physical model inputs from file \"physics.inp\".\n");
54  in = fopen("physics.inp","r");
55  if (!in) printf("Warning: File \"physics.inp\" not found. Using default values.\n");
56  else {
57  char word[_MAX_STRING_SIZE_];
58  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
59  if (!strcmp(word, "begin")){
60  while (strcmp(word, "end")){
61  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
62  if (!strcmp(word, "omegaS")) {ferr=fscanf(in,"%lf",&physics->omegaS);if(ferr!=1)return(1);}
63  else if (!strcmp(word, "omegaB")) {ferr=fscanf(in,"%lf",&physics->omegaB);if(ferr!=1)return(1);}
64  else if (!strcmp(word, "H" )) {ferr=fscanf(in,"%lf",&physics->H );if(ferr!=1)return(1);}
65  else if (!strcmp(word, "D" )) {ferr=fscanf(in,"%lf",&physics->D );if(ferr!=1)return(1);}
66  else if (!strcmp(word, "Pm_avg")) {ferr=fscanf(in,"%lf",&physics->Pm_avg);if(ferr!=1)return(1);}
67  else if (!strcmp(word, "Pmax" )) {ferr=fscanf(in,"%lf",&physics->Pmax );if(ferr!=1)return(1);}
68  else if (!strcmp(word, "sigma" )) {ferr=fscanf(in,"%lf",&physics->sigma );if(ferr!=1)return(1);}
69  else if (!strcmp(word, "lambda")) {ferr=fscanf(in,"%lf",&physics->lambda);if(ferr!=1)return(1);}
70  }
71  } else {
72  fprintf(stderr,"Error: Illegal format in file \"physics.inp\".\n");
73  return(1);
74  }
75  }
76  fclose(in);
77  }
78 
79 #ifndef serial
80  IERR MPIBroadcast_double(&physics->omegaS,1,0,&mpi->world); CHECKERR(ierr);
81  IERR MPIBroadcast_double(&physics->omegaB,1,0,&mpi->world); CHECKERR(ierr);
82  IERR MPIBroadcast_double(&physics->H ,1,0,&mpi->world); CHECKERR(ierr);
83  IERR MPIBroadcast_double(&physics->D ,1,0,&mpi->world); CHECKERR(ierr);
84  IERR MPIBroadcast_double(&physics->Pm_avg,1,0,&mpi->world); CHECKERR(ierr);
85  IERR MPIBroadcast_double(&physics->Pmax ,1,0,&mpi->world); CHECKERR(ierr);
86  IERR MPIBroadcast_double(&physics->sigma ,1,0,&mpi->world); CHECKERR(ierr);
87  IERR MPIBroadcast_double(&physics->lambda,1,0,&mpi->world); CHECKERR(ierr);
88 #endif
89 
90  if (!strcmp(solver->SplitHyperbolicFlux,"yes")) {
91  if (!mpi->rank) {
92  fprintf(stderr,"Error in FPPowerSystem1BusInitialize: This physical model does not have a splitting ");
93  fprintf(stderr,"of the hyperbolic term defined.\n");
94  }
95  return(1);
96  }
97 
98  /* initializing physical model-specific functions */
107 
108  /* check that solver is using the correct diffusion formulation */
109 /*
110  if ((strcmp(solver->spatial_type_par,_NC_2STAGE_)) && (strcmp(solver->spatial_type_par,_NC_1_5STAGE_))) {
111  if (!mpi->rank) {
112  fprintf(stderr,"Error in FPPowerSystem1BusInitialize(): Parabolic term spatial discretization must be ");
113  fprintf(stderr,"\"%s\" or \"%s\".\n",_NC_2STAGE_,_NC_1_5STAGE_);
114  }
115  return(1);
116  }
117 */
118 
119  count++;
120  return(0);
121 }
int(* PrintStep)(void *, void *, double)
Definition: hypar.h:344
int(* GFunction)(double *, double *, int, void *, double)
Definition: hypar.h:310
int nvars
Definition: hypar.h:29
#define IERR
Definition: basic.h:16
#define CHECKERR(ierr)
Definition: basic.h:18
int FPPowerSystem1BusUpwind(double *, double *, double *, double *, double *, double *, int, void *, double)
char SplitHyperbolicFlux[_MAX_STRING_SIZE_]
Definition: hypar.h:92
double FPPowerSystem1BusComputeDiffNumber(void *, void *, double, double)
int FPPowerSystem1BusPostStep(double *, void *, void *, double, int)
int(* HFunction)(double *, double *, int, int, void *, double)
Definition: hypar.h:313
int FPPowerSystem1BusDiffusionLaplacian(double *, double *, int, void *, double)
int(* Upwind)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:295
int ndims
Definition: hypar.h:26
int(* FFunction)(double *, double *, int, void *, double)
Definition: hypar.h:276
int FPPowerSystem1BusDiffusionGeneral(double *, double *, int, int, void *, double)
int MPIBroadcast_double(double *, int, int, void *)
Definition: MPIBroadcast.c:9
double(* ComputeCFL)(void *, void *, double, double)
Definition: hypar.h:269
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _MAX_STRING_SIZE_
Definition: basic.h:14
#define _MODEL_NDIMS_
Definition: euler1d.h:56
MPI_Comm world
int FPPowerSystem1BusPrintStep(void *, void *, double)
double(* ComputeDiffNumber)(void *, void *, double, double)
Definition: hypar.h:272
int(* PostStep)(double *, void *, void *, double, int)
Definition: hypar.h:341
void * physics
Definition: hypar.h:266
int FPPowerSystem1BusAdvection(double *, double *, int, void *, double)
Structure of MPI-related variables.
#define _MODEL_NVARS_
Definition: euler1d.h:58
#define _DECLARE_IERR_
Definition: basic.h:17
double FPPowerSystem1BusComputeCFL(void *, void *, double, double)