HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
FPDoubleWellInitialize.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <basic.h>
5 #include <arrayfunctions.h>
7 #include <mpivars.h>
8 #include <hypar.h>
9 
10 double FPDoubleWellComputeCFL (void*,void*,double,double);
11 double FPDoubleWellComputeDiffNumber (void*,void*,double,double);
12 int FPDoubleWellAdvection (double*,double*,int,void*,double);
13 int FPDoubleWellDiffusion (double*,double*,int,void*,double);
14 int FPDoubleWellUpwind (double*,double*,double*,double*,
15  double*,double*,int,void*,double);
16 int FPDoubleWellPostStep (double*,void*,void*,double,int);
17 int FPDoubleWellPrintStep (void*,void*,double);
18 
19 int FPDoubleWellInitialize(void *s,void *m)
20 {
21  HyPar *solver = (HyPar*) s;
22  MPIVariables *mpi = (MPIVariables*) m;
23  FPDoubleWell *physics = (FPDoubleWell*) solver->physics;
24  int ferr = 0;
26 
27  static int count = 0;
28 
29  if (solver->nvars != _MODEL_NVARS_) {
30  fprintf(stderr,"Error in FPDoubleWellInitializeO(): nvars has to be %d.\n",_MODEL_NVARS_);
31  return(1);
32  }
33  if (solver->ndims != _MODEL_NDIMS_) {
34  fprintf(stderr,"Error in FPDoubleWellInitializeO(): ndims has to be %d.\n",_MODEL_NDIMS_);
35  return(1);
36  }
37 
38  /* reading physical model specific inputs - all processes */
39  if (!mpi->rank) {
40  FILE *in;
41  if (!count) printf("Reading physical model inputs from file \"physics.inp\".\n");
42  in = fopen("physics.inp","r");
43  if (!in) {
44  fprintf(stderr,"Error: File \"physics.inp\" not found.\n");
45  return(1);
46  } else {
47  char word[_MAX_STRING_SIZE_];
48  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
49  if (!strcmp(word, "begin")){
50  while (strcmp(word, "end")){
51  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
52  if (!strcmp(word, "q")) {
53  /* read diffusion coefficient */
54  ferr = fscanf(in,"%lf",&physics->q);
55  if (ferr != 1) return(1);
56  } else if (strcmp(word,"end")) {
57  char useless[_MAX_STRING_SIZE_];
58  ferr = fscanf(in,"%s",useless); if (ferr != 1) return(ferr);
59  printf("Warning: keyword %s in file \"physics.inp\" with value %s not ",word,useless);
60  printf("recognized or extraneous. Ignoring.\n");
61  }
62  }
63  } else {
64  fprintf(stderr,"Error: Illegal format in file \"physics.inp\".\n");
65  return(1);
66  }
67  }
68  fclose(in);
69  }
70 
71 #ifndef serial
72  IERR MPIBroadcast_double(&physics->q,1,0,&mpi->world); CHECKERR(ierr);
73 #endif
74 
75  if (!strcmp(solver->SplitHyperbolicFlux,"yes")) {
76  if (!mpi->rank) {
77  fprintf(stderr,"Error in FPDoubleWellInitialize: This physical model does not have a splitting ");
78  fprintf(stderr,"of the hyperbolic term defined.\n");
79  }
80  return(1);
81  }
82 
83  /* initializing physical model-specific functions */
88  solver->Upwind = FPDoubleWellUpwind;
91 
92  /* Calculate and print the PDF integral of the initial solution */
93  IERR FPDoubleWellPostStep(solver->u,solver,mpi,0.0,0);CHECKERR(ierr);
94  IERR FPDoubleWellPrintStep(solver,mpi,0.0); CHECKERR(ierr);
95 
96  count++;
97  return(0);
98 }
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
double FPDoubleWellComputeCFL(void *, void *, double, double)
#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 ndims
Definition: hypar.h:26
int(* FFunction)(double *, double *, int, void *, double)
Definition: hypar.h:276
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
double FPDoubleWellComputeDiffNumber(void *, void *, double, double)
#define _MODEL_NDIMS_
Definition: euler1d.h:56
int FPDoubleWellUpwind(double *, double *, double *, double *, double *, double *, int, void *, double)
Contains structure definition for hypar.
int FPDoubleWellDiffusion(double *, double *, int, void *, double)
MPI_Comm world
int FPDoubleWellPrintStep(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 FPDoubleWellPostStep(double *, void *, void *, double, int)
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.
int FPDoubleWellAdvection(double *, double *, int, void *, double)
int FPDoubleWellInitialize(void *s, void *m)