HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
FPPowerSystemInitialize.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 FPPowerSystemComputeCFL (void*,void*,double,double);
12 double FPPowerSystemComputeDiffNumber (void*,void*,double,double);
13 int FPPowerSystemAdvection (double*,double*,int,void*,double);
14 int FPPowerSystemDiffusion (double*,double*,int,void*,double);
15 int FPPowerSystemUpwind (double*,double*,double*,double*,
16  double*,double*,int,void*,double);
17 int FPPowerSystemPostStep (double*,void*,void*,double,int);
18 int FPPowerSystemPrintStep (void*,void*,double);
19 
20 int FPPowerSystemInitialize(void *s,void *m)
21 {
22  HyPar *solver = (HyPar*) s;
23  MPIVariables *mpi = (MPIVariables*) m;
24  FPPowerSystem *physics = (FPPowerSystem*) solver->physics;
25  int ferr;
27 
28  static int count = 0;
29 
30  if (solver->nvars != _MODEL_NVARS_) {
31  fprintf(stderr,"Error in FPPowerSystemInitialize(): nvars has to be %d.\n",_MODEL_NVARS_);
32  return(1);
33  }
34  if (solver->ndims != _MODEL_NDIMS_) {
35  fprintf(stderr,"Error in FPPowerSystemInitialize(): ndims has to be %d.\n",_MODEL_NDIMS_);
36  return(1);
37  }
38 
39  /* default values of model parameters */
40  physics->H = 5.0;
41  physics->D = 5.0;
42  physics->E = 1.1358;
43  physics->V = 1.0;
44  physics->g1 = 0.545;
45  physics->g2 = 0.745;
46  physics->Pm = 0.9;
47  physics->l = 0.1;
48  physics->q = 1.0;
49  physics->O_s = 120*(4.0*atan(1.0));
50  physics->tf = 0.1;
51  physics->tcl = 0.2;
52 
53  /* reading physical model specific inputs - all processes */
54  FILE *in;
55  if ((!mpi->rank) && (!count)) printf("Reading physical model inputs from file \"physics.inp\".\n");
56  in = fopen("physics.inp","r");
57  if (!in) {
58  fprintf(stderr,"Error: File \"physics.inp\" not found.\n");
59  return(1);
60  } else {
61  char word[_MAX_STRING_SIZE_];
62  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
63  if (!strcmp(word, "begin")){
64  while (strcmp(word, "end")){
65  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
66  if (!strcmp(word, "inertia")) {ferr=fscanf(in,"%lf",&physics->H );if(ferr!=1)return(1);}
67  else if (!strcmp(word, "omega_s")) {ferr=fscanf(in,"%lf",&physics->O_s);if(ferr!=1)return(1);}
68  else if (!strcmp(word, "E" )) {ferr=fscanf(in,"%lf",&physics->E );if(ferr!=1)return(1);}
69  else if (!strcmp(word, "V" )) {ferr=fscanf(in,"%lf",&physics->V );if(ferr!=1)return(1);}
70  else if (!strcmp(word, "g1" )) {ferr=fscanf(in,"%lf",&physics->g1 );if(ferr!=1)return(1);}
71  else if (!strcmp(word, "g2" )) {ferr=fscanf(in,"%lf",&physics->g2 );if(ferr!=1)return(1);}
72  else if (!strcmp(word, "D" )) {ferr=fscanf(in,"%lf",&physics->D );if(ferr!=1)return(1);}
73  else if (!strcmp(word, "PM_min" )) {ferr=fscanf(in,"%lf",&physics->Pm );if(ferr!=1)return(1);}
74  else if (!strcmp(word, "lambda" )) {ferr=fscanf(in,"%lf",&physics->l );if(ferr!=1)return(1);}
75  else if (!strcmp(word, "q" )) {ferr=fscanf(in,"%lf",&physics->q );if(ferr!=1)return(1);}
76  else if (!strcmp(word, "tf" )) {ferr=fscanf(in,"%lf",&physics->tf );if(ferr!=1)return(1);}
77  else if (!strcmp(word, "tcl" )) {ferr=fscanf(in,"%lf",&physics->tcl);if(ferr!=1)return(1);}
78  }
79  } else {
80  fprintf(stderr,"Error: Illegal format in file \"physics.inp\".\n");
81  return(1);
82  }
83  }
84  fclose(in);
85 
86  if (!strcmp(solver->SplitHyperbolicFlux,"yes")) {
87  if (!mpi->rank) {
88  fprintf(stderr,"Error in FPPowerSystemInitialize: This physical model does not have a splitting ");
89  fprintf(stderr,"of the hyperbolic term defined.\n");
90  }
91  return(1);
92  }
93 
94  /* initializing physical model-specific functions */
99  solver->Upwind = FPPowerSystemUpwind;
102 
103  /* Calculate and print the PDF integral of the initial solution */
104  IERR FPPowerSystemPostStep(solver->u,solver,mpi,0.0,0); CHECKERR(ierr);
105  if (!mpi->rank) IERR FPPowerSystemPrintStep(solver,mpi,0.0); CHECKERR(ierr);
106 
107  count++;
108  return(0);
109 }
int(* PrintStep)(void *, void *, double)
Definition: hypar.h:344
double FPPowerSystemComputeCFL(void *, void *, double, double)
double FPPowerSystemComputeDiffNumber(void *, void *, double, double)
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
char SplitHyperbolicFlux[_MAX_STRING_SIZE_]
Definition: hypar.h:92
double * u
Definition: hypar.h:116
Some basic definitions and macros.
int(* Upwind)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:295
int FPPowerSystemPrintStep(void *, void *, double)
int ndims
Definition: hypar.h:26
int(* FFunction)(double *, double *, int, void *, double)
Definition: hypar.h:276
int FPPowerSystemDiffusion(double *, double *, int, void *, double)
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.
int FPPowerSystemPostStep(double *, void *, void *, double, int)
double(* ComputeDiffNumber)(void *, void *, double, double)
Definition: hypar.h:272
int FPPowerSystemAdvection(double *, double *, int, void *, double)
int(* PostStep)(double *, void *, void *, double, int)
Definition: hypar.h:341
void * physics
Definition: hypar.h:266
Structure of MPI-related variables.
int FPPowerSystemInitialize(void *s, void *m)
#define _MODEL_NVARS_
Definition: euler1d.h:58
#define _DECLARE_IERR_
Definition: basic.h:17
int FPPowerSystemUpwind(double *, double *, double *, double *, double *, double *, int, void *, double)
Contains macros and function definitions for common array operations.