HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
FPPowerSystem3BusInitialize.c
Go to the documentation of this file.
1 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <math.h>
9 #include <string.h>
10 #include <basic.h>
11 #include <arrayfunctions.h>
13 #include <mpivars.h>
14 #include <hypar.h>
15 
16 double FPPowerSystem3BusComputeCFL (void*,void*,double,double);
17 double FPPowerSystem3BusComputeDiffNumber (void*,void*,double,double);
18 int FPPowerSystem3BusAdvection (double*,double*,int,void*,double);
19 int FPPowerSystem3BusDiffusion (double*,double*,int,int,void*,double);
20 int FPPowerSystem3BusUpwind (double*,double*,double*,double*,
21  double*,double*,int,void*,double);
22 
28  void *s,
29  void *m
30  )
31 {
32  HyPar *solver = (HyPar*) s;
33  MPIVariables *mpi = (MPIVariables*) m;
34  FPPowerSystem3Bus *physics = (FPPowerSystem3Bus*) solver->physics;
35  int ferr, N;
37 
38  static int count = 0;
39 
40  if (solver->nvars != _MODEL_NVARS_) {
41  fprintf(stderr,"Error in FPPowerSystem3BusInitialize(): nvars has to be %d.\n",_MODEL_NVARS_);
42  return(1);
43  }
44  if (solver->ndims != _MODEL_NDIMS_) {
45  fprintf(stderr,"Error in FPPowerSystem3BusInitialize(): ndims has to be %d.\n",_MODEL_NDIMS_);
46  return(1);
47  }
48 
49  double pi = 4.0*atan(1.0);
50  /* default values of model parameters */
51  physics->N = 2;
52  physics->Pm1_avg = 0.8;
53  physics->Pm2_avg = 1.6;
54  physics->Pmref_avg = 0.79330781761651;
55  physics->H1 = 3.20;
56  physics->H2 = 6.40;
57  physics->Href = 13.60;
58  physics->E1 = 1.01556070860155;
59  physics->E2 = 1.0491099265981;
60  physics->Eref = 1.05623172878954;
61  physics->omegaB = 2*pi*60.0;
62  physics->sigma[0][0] = 0.0125;
63  physics->sigma[0][1] = 0.0;
64  physics->sigma[1][0] = 0.0;
65  physics->sigma[1][1] = 0.0125;
66  physics->lambda[0][0] = 10.0/physics->omegaB;
67  physics->lambda[0][1] = 0.0;
68  physics->lambda[1][0] = 0.0;
69  physics->lambda[1][1] = 10.0/physics->omegaB;
70  physics->gamma = 0.25;
71 
72  physics->G = (double*) calloc (3*3,sizeof(double));
73  physics->B = (double*) calloc (3*3,sizeof(double));
74 
75  physics->G[0*3+0] = 0.276805493111691;
76  physics->G[0*3+1] = 0.213024867595501;
77  physics->G[0*3+2] = 0.209205876527443;
78  physics->G[1*3+0] = 0.213024867595501;
79  physics->G[1*3+1] = 0.419642083051144;
80  physics->G[1*3+2] = 0.286592141665043;
81  physics->G[2*3+0] = 0.209205876527443;
82  physics->G[2*3+1] = 0.286592141665044;
83  physics->G[2*3+2] = 0.844559256324453;
84 
85  physics->B[0*3+0] = -2.36794416971567;
86  physics->B[0*3+1] = 1.08817493992579;
87  physics->B[0*3+2] = 1.22601259339234;
88  physics->B[1*3+0] = 1.08817493992579;
89  physics->B[1*3+1] = -2.72352378723346;
90  physics->B[1*3+2] = 1.51348094527252;
91  physics->B[2*3+0] = 1.22601259339234;
92  physics->B[2*3+1] = 1.51348094527252;
93  physics->B[2*3+2] = -2.98729895217208;
94 
95  /* reading physical model specific inputs - all processes */
96  FILE *in;
97  if ((!mpi->rank) && (!count)) printf("Reading physical model inputs from file \"physics.inp\".\n");
98  in = fopen("physics.inp","r");
99  if (!in) {
100  if (!mpi->rank) fprintf(stderr,"Error: File \"physics.inp\" not found.\n");
101  return(1);
102  } else {
103  char word[_MAX_STRING_SIZE_];
104  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
105  if (!strcmp(word, "begin")){
106  while (strcmp(word, "end")){
107  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
108  if (!strcmp(word,"Pm1_avg" )) {ferr=fscanf(in,"%lf",&physics->Pm1_avg ) ;if(ferr!=1)return(1);}
109  else if (!strcmp(word,"Pm2_avg" )) {ferr=fscanf(in,"%lf",&physics->Pm2_avg ) ;if(ferr!=1)return(1);}
110  else if (!strcmp(word,"Pmref_avg" )) {ferr=fscanf(in,"%lf",&physics->Pmref_avg ) ;if(ferr!=1)return(1);}
111  else if (!strcmp(word,"H1" )) {ferr=fscanf(in,"%lf",&physics->H1 ) ;if(ferr!=1)return(1);}
112  else if (!strcmp(word,"H2" )) {ferr=fscanf(in,"%lf",&physics->H2 ) ;if(ferr!=1)return(1);}
113  else if (!strcmp(word,"Href" )) {ferr=fscanf(in,"%lf",&physics->Href ) ;if(ferr!=1)return(1);}
114  else if (!strcmp(word,"E1" )) {ferr=fscanf(in,"%lf",&physics->E1 ) ;if(ferr!=1)return(1);}
115  else if (!strcmp(word,"E2" )) {ferr=fscanf(in,"%lf",&physics->E2 ) ;if(ferr!=1)return(1);}
116  else if (!strcmp(word,"Eref" )) {ferr=fscanf(in,"%lf",&physics->Eref ) ;if(ferr!=1)return(1);}
117  else if (!strcmp(word,"omegaB" )) {ferr=fscanf(in,"%lf",&physics->omegaB ) ;if(ferr!=1)return(1);}
118  else if (!strcmp(word,"gamma" )) {ferr=fscanf(in,"%lf",&physics->gamma ) ;if(ferr!=1)return(1);}
119  else if (!strcmp(word,"sigma" )) {
120  ferr=fscanf(in,"%lf",&physics->sigma[0][0]) ;if(ferr!=1)return(1);
121  ferr=fscanf(in,"%lf",&physics->sigma[0][1]) ;if(ferr!=1)return(1);
122  ferr=fscanf(in,"%lf",&physics->sigma[1][0]) ;if(ferr!=1)return(1);
123  ferr=fscanf(in,"%lf",&physics->sigma[1][1]) ;if(ferr!=1)return(1);
124  } else if (!strcmp(word,"lambda")) {
125  ferr=fscanf(in,"%lf",&physics->lambda[0][0]) ;if(ferr!=1)return(1);
126  ferr=fscanf(in,"%lf",&physics->lambda[0][1]) ;if(ferr!=1)return(1);
127  ferr=fscanf(in,"%lf",&physics->lambda[1][0]) ;if(ferr!=1)return(1);
128  ferr=fscanf(in,"%lf",&physics->lambda[1][1]) ;if(ferr!=1)return(1);
129  } else if (!strcmp(word,"G")) {
130  ferr=fscanf(in,"%lf",&physics->G[0*3+0]) ;if(ferr!=1)return(1);
131  ferr=fscanf(in,"%lf",&physics->G[0*3+1]) ;if(ferr!=1)return(1);
132  ferr=fscanf(in,"%lf",&physics->G[0*3+2]) ;if(ferr!=1)return(1);
133  ferr=fscanf(in,"%lf",&physics->G[1*3+0]) ;if(ferr!=1)return(1);
134  ferr=fscanf(in,"%lf",&physics->G[1*3+1]) ;if(ferr!=1)return(1);
135  ferr=fscanf(in,"%lf",&physics->G[1*3+2]) ;if(ferr!=1)return(1);
136  ferr=fscanf(in,"%lf",&physics->G[2*3+0]) ;if(ferr!=1)return(1);
137  ferr=fscanf(in,"%lf",&physics->G[2*3+1]) ;if(ferr!=1)return(1);
138  ferr=fscanf(in,"%lf",&physics->G[2*3+2]) ;if(ferr!=1)return(1);
139  } else if (!strcmp(word,"B")) {
140  ferr=fscanf(in,"%lf",&physics->B[0*3+0]) ;if(ferr!=1)return(1);
141  ferr=fscanf(in,"%lf",&physics->B[0*3+1]) ;if(ferr!=1)return(1);
142  ferr=fscanf(in,"%lf",&physics->B[0*3+2]) ;if(ferr!=1)return(1);
143  ferr=fscanf(in,"%lf",&physics->B[1*3+0]) ;if(ferr!=1)return(1);
144  ferr=fscanf(in,"%lf",&physics->B[1*3+1]) ;if(ferr!=1)return(1);
145  ferr=fscanf(in,"%lf",&physics->B[1*3+2]) ;if(ferr!=1)return(1);
146  ferr=fscanf(in,"%lf",&physics->B[2*3+0]) ;if(ferr!=1)return(1);
147  ferr=fscanf(in,"%lf",&physics->B[2*3+1]) ;if(ferr!=1)return(1);
148  ferr=fscanf(in,"%lf",&physics->B[2*3+2]) ;if(ferr!=1)return(1);
149  }
150  }
151  } else {
152  if (!mpi->rank) fprintf(stderr,"Error: Illegal format in file \"physics.inp\".\n");
153  return(1);
154  }
155  }
156  fclose(in);
157 
158  if (!strcmp(solver->SplitHyperbolicFlux,"yes")) {
159  if (!mpi->rank) {
160  fprintf(stderr,"Error in FPPowerSystem3BusInitialize: This physical model does not have a splitting ");
161  fprintf(stderr,"of the hyperbolic term defined.\n");
162  }
163  return(1);
164  }
165 
166  /* initializing physical model-specific functions */
172 
173  count++;
174  return(0);
175 }
double FPPowerSystem3BusComputeDiffNumber(void *, void *, double, double)
int nvars
Definition: hypar.h:29
MPI related function definitions.
char SplitHyperbolicFlux[_MAX_STRING_SIZE_]
Definition: hypar.h:92
int(* HFunction)(double *, double *, int, int, void *, double)
Definition: hypar.h:313
Some basic definitions and macros.
int FPPowerSystem3BusDiffusion(double *, double *, int, 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 FPPowerSystem3BusAdvection(double *, double *, int, void *, double)
int(* FFunction)(double *, double *, int, void *, double)
Definition: hypar.h:276
double(* ComputeCFL)(void *, void *, double, double)
Definition: hypar.h:269
3-Bus Power System model
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
double FPPowerSystem3BusComputeCFL(void *, void *, double, double)
#define _MAX_STRING_SIZE_
Definition: basic.h:14
#define _MODEL_NDIMS_
Definition: euler1d.h:56
int FPPowerSystem3BusUpwind(double *, double *, double *, double *, double *, double *, int, void *, double)
Contains structure definition for hypar.
double(* ComputeDiffNumber)(void *, void *, double, double)
Definition: hypar.h:272
void * physics
Definition: hypar.h:266
Structure of MPI-related variables.
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.
#define _MODEL_NVARS_
Definition: euler1d.h:58
#define _DECLARE_IERR_
Definition: basic.h:17
Contains macros and function definitions for common array operations.
int FPPowerSystem3BusInitialize(void *s, void *m)