HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
LinearADRInitialize.c
Go to the documentation of this file.
1 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <basic.h>
10 #include <arrayfunctions.h>
11 #include <bandedmatrix.h>
13 #include <mpivars.h>
14 #include <hypar.h>
15 
16 int LinearADRAdvectionField (void*,void*,int,int,int*);
17 double LinearADRComputeCFL (void*,void*,double,double);
18 double LinearADRComputeDiffNumber (void*,void*,double,double);
19 int LinearADRAdvection (double*,double*,int,void*,double);
20 int LinearADRDiffusionG (double*,double*,int,void*,double);
21 int LinearADRDiffusionH (double*,double*,int,int,void*,double);
22 int LinearADRReaction ();
23 int LinearADRUpwind (double*,double*,double*,double*,
24  double*,double*,int,void*,double);
25 int LinearADRCenteredFlux (double*,double*,double*,double*,
26  double*,double*,int,void*,double);
27 int LinearADRWriteAdvField (void*,void*,double);
28 
29 int LinearADRAdvectionJacobian (double*,double*,void*,int,int,int);
30 int LinearADRDiffusionJacobian (double*,double*,void*,int,int);
31 
59 int LinearADRInitialize(void *s,
60  void *m )
61 {
62  HyPar *solver = (HyPar*) s;
63  MPIVariables *mpi = (MPIVariables*) m;
64  LinearADR *physics = (LinearADR*) solver->physics;
65  int i,ferr;
66 
67  static int count = 0;
68 
69  /* default values */
70  physics->constant_advection = -1;
71  strcpy(physics->adv_filename,"none");
72  physics->a = NULL;
73  physics->adv_arr_size = -1;
74  strcpy(physics->centered_flux,"no");
75 
76  physics->d = (double*) calloc (solver->ndims*solver->nvars,sizeof(double));
77  _ArraySetValue_(physics->d,solver->ndims*solver->nvars,0.0);
78 
79  /* reading physical model specific inputs - all processes */
80  if (!mpi->rank) {
81 
82  FILE *in;
83  if (!count) printf("Reading physical model inputs from file \"physics.inp\".\n");
84  in = fopen("physics.inp","r");
85 
86  if (!in) {
87 
88  fprintf(stderr,"Error: File \"physics.inp\" not found.\n");
89  return(1);
90 
91  } else {
92 
93  char word[_MAX_STRING_SIZE_];
94  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
95  if (!strcmp(word, "begin")) {
96  while (strcmp(word, "end")) {
97 
98  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
99 
100  if (!strcmp(word, "advection_filename")) {
101  if (physics->constant_advection != -1) {
102  fprintf(stderr,"Error in LinearADRInitialize():\n");
103  fprintf(stderr,"Maybe advection_filename and advection are both specified.\n");
104  return 1;
105  } else {
106  /* read filename for spatially-varying advection field */
107  physics->constant_advection = 0;
108  physics->adv_arr_size = solver->npoints_local_wghosts*solver->ndims*solver->nvars;
109  physics->a = (double*) calloc ( physics->adv_arr_size, sizeof(double) );
110  _ArraySetValue_(physics->a, physics->adv_arr_size, 0.0);
111  ferr = fscanf(in,"%s",physics->adv_filename); if (ferr != 1) return(ferr);
112  }
113  } else if (!strcmp(word, "advection")) {
114  if (physics->constant_advection != -1) {
115  fprintf(stderr,"Error in LinearADRInitialize():\n");
116  fprintf(stderr,"Maybe advection_filename and advection are both specified.\n");
117  return 1;
118  } else {
119  /* read advection coefficients */
120  physics->constant_advection = 1;
121  physics->adv_arr_size = solver->ndims*solver->nvars;
122  physics->a = (double*) calloc ( physics->adv_arr_size, sizeof(double) );
123  for (i=0; i<solver->ndims*solver->nvars; i++) ferr = fscanf(in,"%lf",&physics->a[i]);
124  if (ferr != 1) return(1);
125  }
126  } else if (!strcmp(word, "diffusion")) {
127  /* read diffusion coefficients */
128  for (i=0; i<solver->ndims*solver->nvars; i++) ferr = fscanf(in,"%lf",&physics->d[i]);
129  if (ferr != 1) return(1);
130  } else if (!strcmp(word, "centered_flux")) {
131  ferr = fscanf(in, "%s", physics->centered_flux);
132  if (ferr != 1) return(ferr);
133  } else if (strcmp(word,"end")) {
134  char useless[_MAX_STRING_SIZE_];
135  ferr = fscanf(in,"%s",useless); if (ferr != 1) return(ferr);
136  printf("Warning: keyword %s in file \"physics.inp\" with value %s not ",word,useless);
137  printf("recognized or extraneous. Ignoring.\n");
138  }
139  }
140 
141  } else {
142 
143  fprintf(stderr,"Error: Illegal format in file \"physics.inp\".\n");
144  return(1);
145 
146  }
147  }
148 
149  fclose(in);
150 
151  }
152 
153 #ifndef serial
154  MPIBroadcast_integer(&physics->constant_advection,1,0,&mpi->world);
155  MPIBroadcast_integer(&physics->adv_arr_size,1,0,&mpi->world);
156 #endif
157 
158  if (mpi->rank) {
159  physics->a = (double*) calloc (physics->adv_arr_size,sizeof(double));
160  _ArraySetValue_(physics->a, physics->adv_arr_size, 0.0);
161  }
162 
163  if (physics->constant_advection == 1) {
164 #ifndef serial
165  MPIBroadcast_double(physics->a,physics->adv_arr_size,0,&mpi->world);
166 #endif
167  } else if (physics->constant_advection == 0) {
168 #ifndef serial
170 #endif
171  }
172 
173 #ifndef serial
174  MPIBroadcast_double(physics->d,solver->ndims*solver->nvars,0,&mpi->world);
176 #endif
177 
178  if (!strcmp(solver->SplitHyperbolicFlux,"yes")) {
179  if (!mpi->rank) {
180  fprintf(stderr,"Error in LinearADRInitialize: This physical model does not have a splitting ");
181  fprintf(stderr,"of the hyperbolic term defined.\n");
182  }
183  return(1);
184  }
185 
186  /* initializing physical model-specific functions */
189  solver->FFunction = LinearADRAdvection;
190  solver->GFunction = LinearADRDiffusionG;
191  solver->HFunction = LinearADRDiffusionH;
192  solver->SFunction = LinearADRReaction;
195 
196  if (!strcmp(physics->centered_flux,"no")) {
197  solver->Upwind = LinearADRUpwind;
198  } else {
199  solver->Upwind = LinearADRCenteredFlux;
200  }
201 
202  if (physics->constant_advection == 0) {
205  } else {
206  solver->PhysicsInput = NULL;
207  solver->PhysicsOutput = NULL;
208  }
209 
210  count++;
211  return(0);
212 }
int LinearADRDiffusionJacobian(double *, double *, void *, int, int)
int(* PhysicsOutput)(void *, void *, double)
Definition: hypar.h:347
int constant_advection
Definition: linearadr.h:40
int LinearADRAdvectionField(void *, void *, int, int, int *)
int(* GFunction)(double *, double *, int, void *, double)
Definition: hypar.h:310
int nvars
Definition: hypar.h:29
MPI related function definitions.
int adv_arr_size
Definition: linearadr.h:47
char SplitHyperbolicFlux[_MAX_STRING_SIZE_]
Definition: hypar.h:92
Data structure and some function declarations for banded block matrices.
int MPIBroadcast_integer(int *, int, int, void *)
Definition: MPIBroadcast.c:23
int(* KFunction)(double *, double *, void *, int, int)
Definition: hypar.h:331
int(* HFunction)(double *, double *, int, int, void *, double)
Definition: hypar.h:313
Some basic definitions and macros.
double LinearADRComputeDiffNumber(void *, void *, double, double)
int(* SFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:317
int(* PhysicsInput)(void *, void *, int, int, int *)
Definition: hypar.h:351
int LinearADRUpwind(double *, double *, double *, double *, double *, double *, int, void *, double)
int(* Upwind)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:295
char adv_filename[_MAX_STRING_SIZE_]
Definition: linearadr.h:43
int ndims
Definition: hypar.h:26
Structure containing variables and parameters specific to the linear advection-diffusion-reaction mod...
Definition: linearadr.h:37
int LinearADRWriteAdvField(void *, void *, double)
int MPIBroadcast_character(char *, int, int, void *)
Definition: MPIBroadcast.c:37
double * a
Definition: linearadr.h:50
int(* FFunction)(double *, double *, int, void *, double)
Definition: hypar.h:276
int MPIBroadcast_double(double *, int, int, void *)
Definition: MPIBroadcast.c:9
int LinearADRAdvectionJacobian(double *, double *, void *, int, int, int)
int LinearADRCenteredFlux(double *, double *, double *, double *, 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
int LinearADRReaction()
int LinearADRAdvection(double *, double *, int, void *, double)
int LinearADRInitialize(void *s, void *m)
Contains structure definition for hypar.
MPI_Comm world
double(* ComputeDiffNumber)(void *, void *, double, double)
Definition: hypar.h:272
Linear Advection-Diffusion-Reaction model.
#define _ArraySetValue_(x, size, value)
int LinearADRDiffusionH(double *, double *, int, int, void *, double)
char centered_flux[_MAX_STRING_SIZE_]
Definition: linearadr.h:57
void * physics
Definition: hypar.h:266
int(* JFunction)(double *, double *, void *, int, int, int)
Definition: hypar.h:326
double LinearADRComputeCFL(void *, void *, double, double)
Structure of MPI-related variables.
int npoints_local_wghosts
Definition: hypar.h:42
Contains macros and function definitions for common array operations.
double * d
Definition: linearadr.h:53
int LinearADRDiffusionG(double *, double *, int, void *, double)