HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
FPPowerSystem1BusInitialize.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include <string.h>
5 #include <basic.h>
6 #include <arrayfunctions.h>
8 #include <mpivars.h>
9 #include <hypar.h>
10 
11 double FPPowerSystem1BusComputeCFL (void*,void*,double,double);
12 double FPPowerSystem1BusComputeDiffNumber (void*,void*,double,double);
13 int FPPowerSystem1BusAdvection (double*,double*,int,void*,double);
14 int FPPowerSystem1BusDiffusionLaplacian(double*,double*,int,void*,double);
15 int FPPowerSystem1BusDiffusionGeneral (double*,double*,int,int,void*,double);
16 int FPPowerSystem1BusUpwind (double*,double*,double*,double*,
17  double*,double*,int,void*,double);
18 int FPPowerSystem1BusPostStep (double*,void*,void*,double,int);
19 int FPPowerSystem1BusPrintStep (void*,void*,double);
20 
21 int FPPowerSystem1BusInitialize(void *s,void *m)
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
MPI related function definitions.
#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
Some basic definitions and macros.
int FPPowerSystem1BusDiffusionLaplacian(double *, double *, int, void *, double)
int(* Upwind)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:295
int FPPowerSystem1BusInitialize(void *s, void *m)
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
Contains structure definition for hypar.
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
Fokker-Planck Model for 1-Bus Power System.
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
Contains macros and function definitions for common array operations.
double FPPowerSystem1BusComputeCFL(void *, void *, double, double)