Timothy  0.9
Tissue Modelling Framework
 All Data Structures Files Functions Variables Typedefs Macros
chemf.c File Reference

contains functions used for solving chemical global fields More...

#include <float.h>
#include "_hypre_utilities.h"
#include "HYPRE_sstruct_ls.h"
#include "HYPRE_parcsr_ls.h"
#include "HYPRE_krylov.h"
#include "global.h"
#include "fields.h"
Include dependency graph for chemf.c:

Go to the source code of this file.

Functions

void chemSetBoundary (int coord, int boundary)
 
void chemEnvInitSystem (int nch)
 
void chemEnvCellPC (int nch)
 
void chemEnvInitBC (int nch)
 
void chemEnvInitSolver (int nch)
 
void chemEnvSolve (int nch)
 

Variables

HYPRE_SStructGrid chemGrid [NCHEM]
 
HYPRE_SStructGraph chemGraph [NCHEM]
 
HYPRE_SStructStencil chemStencil [NCHEM]
 
HYPRE_SStructMatrix chemA [NCHEM]
 
HYPRE_SStructVector chemb [NCHEM]
 
HYPRE_SStructVector chemx [NCHEM]
 
HYPRE_ParCSRMatrix chemParA [NCHEM]
 
HYPRE_ParVector chemParb [NCHEM]
 
HYPRE_ParVector chemParx [NCHEM]
 
HYPRE_Solver chemSolver [NCHEM]
 
HYPRE_Solver chemPrecond [NCHEM]
 
int chemObjectType
 
long long chemLower [3]
 
long long chemUpper [3]
 
long long bcLower [3]
 
long long bcUpper [3]
 
double dt [NCHEM]
 
double chemLambda = 0.25
 
char chfname [256]
 
int chemIter [NCHEM]
 
double chemZ [NCHEM]
 
HYPRE_SStructVariable chemVartypes [1] = { HYPRE_SSTRUCT_VARIABLE_NODE }
 
int numberOfIters
 
double * chemPC
 

Detailed Description

contains functions used for solving chemical global fields

Definition in file chemf.c.

Function Documentation

void chemEnvCellPC ( int  nch)

This function computes cell production/consumption function based on the interpolated cell density field.

Definition at line 241 of file chemf.c.

References chemPC, densityField, dt, fieldConsumption, fieldProduction, gridSize, NGLOB, step, int64Vector3d::x, int64Vector3d::y, and int64Vector3d::z.

242 {
243  int ch, i, j, k;
244  long long nvalues = gridSize.x * gridSize.y * gridSize.z;
245 
246  if (step == 0)
247  return;
248 
249  int idx = 0;
250  for (k = 0; k < gridSize.z; k++)
251  for (j = 0; j < gridSize.y; j++)
252  for (i = 0; i < gridSize.x; i++, idx++) {
253  chemPC[idx] = (-fieldConsumption[nch + NGLOB] + fieldProduction[nch + NGLOB]) * densityField[gridSize.z * gridSize.y * i + gridSize.z * j + k] * dt[nch]; //*(cellVolume/boxVolume);//*(1.0/cellVolume);//*dt[nch];//*dt[nch];
254  }
255 }
int64_t x
Definition: global.h:229
int64_t z
Definition: global.h:231
int step
Definition: global.h:173
struct int64Vector3d gridSize
Definition: fields.h:41
double dt[NCHEM]
Definition: chemf.c:57
double fieldConsumption[NFIELDS]
Definition: fields.h:64
double * chemPC
Definition: chemf.c:70
int64_t y
Definition: global.h:230
double fieldProduction[NFIELDS]
Definition: fields.h:65
double * densityField
Definition: fields.h:75
#define NGLOB
Definition: fields.h:28

Here is the caller graph for this function:

void chemEnvInitBC ( int  nch)

This function initializes boundary conditions for a given chemical field.

Definition at line 260 of file chemf.c.

References bcLower, bcUpper, chemA, chemb, chemEnvCellPC(), chemGrid, chemLower, chemObjectType, chemPC, chemSetBoundary(), chemUpper, chemx, chemZ, chfname, fieldBC, fieldICMean, gridSize, m, MPI_CART_COMM, MPIcoords, MPIdim, MPIrank, NGLOB, revertStdOut(), switchStdOut(), int64Vector3d::x, int64Vector3d::y, and int64Vector3d::z.

261 {
262  int i, j, k;
263  int m;
264  int nentries = 1;
265  long long stencil_indices[1];
266  long long nvalues = gridSize.x * gridSize.y * gridSize.z;
267  double *values, *bvalues;
268  /* stdout redirected to file */
270 
271  chemPC = (double *) calloc(nvalues, sizeof(double));
272  values = calloc(nvalues, sizeof(double));
273  bvalues = calloc(nvalues, sizeof(double));
274 
275  chemEnvCellPC(nch);
276 
277  /* 5. SETUP STRUCT VECTORS FOR B AND X */
278 
279  /* create an empty vector object */
280  HYPRE_SStructVectorCreate(MPI_CART_COMM, chemGrid[nch], &chemb[nch]);
281  HYPRE_SStructVectorCreate(MPI_CART_COMM, chemGrid[nch], &chemx[nch]);
282 
283  /* as with the matrix, set the appropriate object type for the vectors */
284  HYPRE_SStructVectorSetObjectType(chemb[nch], chemObjectType);
285  HYPRE_SStructVectorSetObjectType(chemx[nch], chemObjectType);
286 
287  /* indicate that the vector coefficients are ready to be set */
288  HYPRE_SStructVectorInitialize(chemb[nch]);
289  HYPRE_SStructVectorInitialize(chemx[nch]);
290 
291  /* set the values */
292  m = 0;
293  for (k = chemLower[2]; k <= chemUpper[2]; k++)
294  for (j = chemLower[1]; j <= chemUpper[1]; j++)
295  for (i = chemLower[0]; i <= chemUpper[0]; i++) {
296  values[m] = fieldICMean[nch + NGLOB];
297  m++;
298  }
299 
300  HYPRE_SStructVectorSetBoxValues(chemb[nch], 0, chemLower, chemUpper, 0,
301  values);
302 
303  m = 0;
304  for (k = chemLower[2]; k <= chemUpper[2]; k++)
305  for (j = chemLower[1]; j <= chemUpper[1]; j++)
306  for (i = chemLower[0]; i <= chemUpper[0]; i++) {
307  values[m] = fieldICMean[nch + NGLOB];
308  m++;
309  }
310 
311  HYPRE_SStructVectorSetBoxValues(chemx[nch], 0, chemLower, chemUpper, 0,
312  values);
313 
314  /* incorporate boundary conditions; Dirichlet on 6 faces */
315 
316  for (i = 0; i < nvalues; i++)
317  values[i] = chemZ[nch];
318  for (i = 0; i < nvalues; i++)
319  bvalues[i] = chemZ[nch] * fieldBC[nch + NGLOB];
320 
321  if (MPIcoords[MPIrank][0] == 0) {
322  nvalues = nentries * gridSize.y * gridSize.z;
323  chemSetBoundary(0, -1);
324  stencil_indices[0] = 1;
325  HYPRE_SStructMatrixAddToBoxValues(chemA[nch], 0, bcLower, bcUpper, 0,
326  nentries, stencil_indices, values);
327  HYPRE_SStructVectorAddToBoxValues(chemb[nch], 0, bcLower, bcUpper, 0,
328  bvalues);
329  }
330  if (MPIcoords[MPIrank][0] == MPIdim[0] - 1) {
331  nvalues = nentries * gridSize.y * gridSize.z;
332  chemSetBoundary(0, 1);
333  stencil_indices[0] = 2;
334  HYPRE_SStructMatrixAddToBoxValues(chemA[nch], 0, bcLower, bcUpper, 0,
335  nentries, stencil_indices, values);
336  HYPRE_SStructVectorAddToBoxValues(chemb[nch], 0, bcLower, bcUpper, 0,
337  bvalues);
338  }
339  if (MPIcoords[MPIrank][1] == 0) {
340  nvalues = nentries * gridSize.x * gridSize.z;
341  chemSetBoundary(1, -1);
342  stencil_indices[0] = 3;
343  HYPRE_SStructMatrixAddToBoxValues(chemA[nch], 0, bcLower, bcUpper, 0,
344  nentries, stencil_indices, values);
345  HYPRE_SStructVectorAddToBoxValues(chemb[nch], 0, bcLower, bcUpper, 0,
346  bvalues);
347  }
348  if (MPIcoords[MPIrank][1] == MPIdim[1] - 1) {
349  nvalues = nentries * gridSize.x * gridSize.z;
350  chemSetBoundary(1, 1);
351  stencil_indices[0] = 4;
352  HYPRE_SStructMatrixAddToBoxValues(chemA[nch], 0, bcLower, bcUpper, 0,
353  nentries, stencil_indices, values);
354  HYPRE_SStructVectorAddToBoxValues(chemb[nch], 0, bcLower, bcUpper, 0,
355  bvalues);
356  }
357  if (MPIcoords[MPIrank][2] == 0) {
358  nvalues = nentries * gridSize.x * gridSize.y;
359  chemSetBoundary(2, -1);
360  stencil_indices[0] = 5;
361  HYPRE_SStructMatrixAddToBoxValues(chemA[nch], 0, bcLower, bcUpper, 0,
362  nentries, stencil_indices, values);
363  HYPRE_SStructVectorAddToBoxValues(chemb[nch], 0, bcLower, bcUpper, 0,
364  bvalues);
365  }
366  if (MPIcoords[MPIrank][2] == MPIdim[2] - 1) {
367  nvalues = nentries * gridSize.x * gridSize.y;
368  chemSetBoundary(2, 1);
369  stencil_indices[0] = 6;
370  HYPRE_SStructMatrixAddToBoxValues(chemA[nch], 0, bcLower, bcUpper, 0,
371  nentries, stencil_indices, values);
372  HYPRE_SStructVectorAddToBoxValues(chemb[nch], 0, bcLower, bcUpper, 0,
373  bvalues);
374  }
375 
376  /* add production consumption function to the right side */
377  HYPRE_SStructVectorAddToBoxValues(chemb[nch], 0, chemLower, chemUpper, 0,
378  chemPC);
379 
380  free(chemPC);
381  free(values);
382  free(bvalues);
383  /* stdout brought back */
384  revertStdOut();
385 }
int64_t x
Definition: global.h:229
long long bcUpper[3]
Definition: chemf.c:55
int MPIdim[3]
Definition: global.h:136
void chemEnvCellPC(int nch)
Definition: chemf.c:241
int MPIrank
Definition: global.h:134
double chemZ[NCHEM]
Definition: chemf.c:64
int64_t z
Definition: global.h:231
long long bcLower[3]
Definition: chemf.c:54
float m
Definition: global.h:188
long long chemLower[3]
Definition: chemf.c:53
long long chemUpper[3]
Definition: chemf.c:53
void switchStdOut(const char *newStream)
Definition: io.c:1790
struct int64Vector3d gridSize
Definition: fields.h:41
double fieldBC[NFIELDS]
Definition: fields.h:57
void revertStdOut()
Definition: io.c:1803
double fieldICMean[NFIELDS]
Definition: fields.h:58
char chfname[256]
Definition: chemf.c:60
double * chemPC
Definition: chemf.c:70
int64_t y
Definition: global.h:230
void chemSetBoundary(int coord, int boundary)
Definition: chemf.c:75
HYPRE_SStructVector chemb[NCHEM]
Definition: chemf.c:41
int ** MPIcoords
Definition: global.h:144
HYPRE_SStructGrid chemGrid[NCHEM]
Definition: chemf.c:36
HYPRE_SStructMatrix chemA[NCHEM]
Definition: chemf.c:40
HYPRE_SStructVector chemx[NCHEM]
Definition: chemf.c:42
MPI_Comm MPI_CART_COMM
Definition: global.h:143
int chemObjectType
Definition: chemf.c:51
#define NGLOB
Definition: fields.h:28

Here is the call graph for this function:

Here is the caller graph for this function:

void chemEnvInitSolver ( int  nch)

This function initializes Hypre for solving a given chemical field.

Definition at line 390 of file chemf.c.

References chemA, chemb, chemParA, chemParb, chemParx, chemPrecond, chemSolver, chemx, chfname, MPI_CART_COMM, revertStdOut(), and switchStdOut().

391 {
392  /* stdout redirected to file */
394 
395  HYPRE_SStructMatrixAssemble(chemA[nch]);
396  /* This is a collective call finalizing the vector assembly.
397  The vector is now ``ready to be used'' */
398  HYPRE_SStructVectorAssemble(chemb[nch]);
399  HYPRE_SStructVectorAssemble(chemx[nch]);
400 
401  HYPRE_SStructMatrixGetObject(chemA[nch], (void **) &chemParA[nch]);
402  HYPRE_SStructVectorGetObject(chemb[nch], (void **) &chemParb[nch]);
403  HYPRE_SStructVectorGetObject(chemx[nch], (void **) &chemParx[nch]);
404 
405  HYPRE_ParCSRPCGCreate(MPI_CART_COMM, &chemSolver[nch]);
406  HYPRE_ParCSRPCGSetTol(chemSolver[nch], 1.0e-12);
407  HYPRE_ParCSRPCGSetPrintLevel(chemSolver[nch], 2);
408  HYPRE_ParCSRPCGSetMaxIter(chemSolver[nch], 50);
409 
410  HYPRE_BoomerAMGCreate(&chemPrecond[nch]);
411  HYPRE_BoomerAMGSetMaxIter(chemPrecond[nch], 1);
412  HYPRE_BoomerAMGSetTol(chemPrecond[nch], 0.0);
413  HYPRE_BoomerAMGSetPrintLevel(chemPrecond[nch], 2);
414  HYPRE_BoomerAMGSetCoarsenType(chemPrecond[nch], 6);
415  HYPRE_BoomerAMGSetRelaxType(chemPrecond[nch], 6);
416  HYPRE_BoomerAMGSetNumSweeps(chemPrecond[nch], 1);
417 
418  HYPRE_ParCSRPCGSetPrecond(chemSolver[nch], HYPRE_BoomerAMGSolve,
419  HYPRE_BoomerAMGSetup, chemPrecond[nch]);
420  HYPRE_ParCSRPCGSetup(chemSolver[nch], chemParA[nch], chemParb[nch],
421  chemParx[nch]);
422 
423  /* stdout brought back */
424  revertStdOut();
425 }
HYPRE_ParCSRMatrix chemParA[NCHEM]
Definition: chemf.c:44
HYPRE_ParVector chemParb[NCHEM]
Definition: chemf.c:45
void switchStdOut(const char *newStream)
Definition: io.c:1790
HYPRE_ParVector chemParx[NCHEM]
Definition: chemf.c:46
void revertStdOut()
Definition: io.c:1803
char chfname[256]
Definition: chemf.c:60
HYPRE_SStructVector chemb[NCHEM]
Definition: chemf.c:41
HYPRE_Solver chemPrecond[NCHEM]
Definition: chemf.c:49
HYPRE_SStructMatrix chemA[NCHEM]
Definition: chemf.c:40
HYPRE_SStructVector chemx[NCHEM]
Definition: chemf.c:42
MPI_Comm MPI_CART_COMM
Definition: global.h:143
HYPRE_Solver chemSolver[NCHEM]
Definition: chemf.c:48

Here is the call graph for this function:

Here is the caller graph for this function:

void chemEnvInitSystem ( int  nch)

This function initializes grid, stencil and matrix for a given chemical field.

Definition at line 130 of file chemf.c.

References cellFields, chemA, chemField, chemGraph, chemGrid, chemIter, chemLower, chemObjectType, chemStencil, chemUpper, chemVartypes, chemZ, chfname, csize, csizeInUnits, dt, fieldDiffCoef, fieldDt, fieldICMean, fieldLambda, fieldMax, fieldMin, gridEndIdx, gridResolution, gridSize, gridStartIdx, logdir, maxCellsPerProc, MPI_CART_COMM, MPIrank, NGLOB, numberOfIters, revertStdOut(), switchStdOut(), int64Vector3d::x, int64Vector3d::y, and int64Vector3d::z.

131 {
132  int i, j, k, c;
133  int entry;
134  long long offsets[7][3] =
135  { {0, 0, 0}, {-1, 0, 0}, {1, 0, 0}, {0, -1, 0}, {0, 1, 0}, {0, 0,
136  -1}, {0,
137  0,
138  1}
139  };
140  double gridResolutionInUnits; /* grid resolution in centimeters */
141 
142  dt[nch] = fieldDt[nch + NGLOB];
143  numberOfIters = 1;
144  chemIter[nch] = 0;
145 
146  sprintf(chfname, "%s/chemSolver.log", logdir);
147  /* stdout will go to the file */
149 
150  /* 1. INIT GRID */
151 
152  /* create an empty 3D grid object */
153  HYPRE_SStructGridCreate(MPI_CART_COMM, 3, 1, &chemGrid[nch]);
154 
155  /* set this process box */
159 
163 
164  /* add a new box to the grid */
165  HYPRE_SStructGridSetExtents(chemGrid[nch], 0, chemLower, chemUpper);
166 
167  HYPRE_SStructGridSetVariables(chemGrid[nch], 0, 1, chemVartypes);
168  HYPRE_SStructGridAssemble(chemGrid[nch]);
169 
170  /* 2. INIT STENCIL */
171  HYPRE_SStructStencilCreate(3, 7, &chemStencil[nch]);
172  for (entry = 0; entry < 7; entry++)
173  HYPRE_SStructStencilSetEntry(chemStencil[nch], entry, offsets[entry],
174  0);
175 
176  /* 3. SET UP THE GRAPH */
177  chemObjectType = HYPRE_PARCSR;
178  HYPRE_SStructGraphCreate(MPI_CART_COMM, chemGrid[nch], &chemGraph[nch]);
179  HYPRE_SStructGraphSetObjectType(chemGraph[nch], chemObjectType);
180  HYPRE_SStructGraphSetStencil(chemGraph[nch], 0, 0, chemStencil[nch]);
181  HYPRE_SStructGraphAssemble(chemGraph[nch]);
182 
183  /* 4. SET UP MATRIX */
184  long long nentries = 7;
185  long long nvalues;
186  double *values;
187  long long stencil_indices[7];
188 
189  nvalues = nentries * gridSize.x * gridSize.y * gridSize.z;
190  /* create an empty matrix object */
191  HYPRE_SStructMatrixCreate(MPI_CART_COMM, chemGraph[nch], &chemA[nch]);
192  HYPRE_SStructMatrixSetObjectType(chemA[nch], chemObjectType);
193  /* indicate that the matrix coefficients are ready to be set */
194  HYPRE_SStructMatrixInitialize(chemA[nch]);
195 
196  values = calloc(nvalues, sizeof(double));
197 
198  for (j = 0; j < nentries; j++)
199  stencil_indices[j] = j;
200 
201  gridResolutionInUnits = (gridResolution / csize) * csizeInUnits * 0.0001;
202 
203  chemZ[nch] =
204  fieldDiffCoef[nch +
205  NGLOB] * dt[nch] / (gridResolutionInUnits *
206  gridResolutionInUnits);
207 
208  /* set the standard stencil at each grid point,
209  * we will fix the boundaries later */
210  for (i = 0; i < nvalues; i += nentries) {
211  values[i] = 1 + 6.0 * chemZ[nch] + fieldLambda[nch + NGLOB] * dt[nch];
212  for (j = 1; j < nentries; j++)
213  values[i + j] = -chemZ[nch];
214  }
215 
216  HYPRE_SStructMatrixSetBoxValues(chemA[nch], 0, chemLower, chemUpper, 0,
217  nentries, stencil_indices, values);
218 
219  for (k = 0; k < gridSize.z; k++)
220  for (j = 0; j < gridSize.y; j++)
221  for (i = 0; i < gridSize.x; i++) {
222  chemField[nch][gridSize.y * gridSize.z * i + gridSize.z * j + k] =
223  fieldICMean[nch + NGLOB];
224  }
225  fieldMax[nch + NGLOB] = fieldICMean[nch + NGLOB];
226  fieldMin[nch + NGLOB] = fieldICMean[nch + NGLOB];
227 
228  for (c = 0; c < maxCellsPerProc; c++) {
229  cellFields[nch + NGLOB][c] = fieldICMean[nch + NGLOB];
230  }
231 
232  free(values);
233  /* stdout brought back */
234  revertStdOut();
235 }
int64_t x
Definition: global.h:229
double csizeInUnits
Definition: global.h:198
int MPIrank
Definition: global.h:134
double chemZ[NCHEM]
Definition: chemf.c:64
struct int64Vector3d * gridEndIdx
Definition: fields.h:42
double fieldMin[NFIELDS]
Definition: fields.h:72
double * chemField[NCHEM]
Definition: fields.h:77
double fieldDiffCoef[NFIELDS]
Definition: fields.h:55
int chemIter[NCHEM]
Definition: chemf.c:62
int64_t z
Definition: global.h:231
double fieldDt[NFIELDS]
Definition: fields.h:60
double fieldMax[NFIELDS]
Definition: fields.h:73
long long chemLower[3]
Definition: chemf.c:53
long long chemUpper[3]
Definition: chemf.c:53
void switchStdOut(const char *newStream)
Definition: io.c:1790
HYPRE_SStructVariable chemVartypes[1]
Definition: chemf.c:66
struct int64Vector3d gridSize
Definition: fields.h:41
double dt[NCHEM]
Definition: chemf.c:57
char logdir[128]
Definition: global.h:167
int maxCellsPerProc
Definition: global.h:132
double csize
Definition: global.h:197
HYPRE_SStructGraph chemGraph[NCHEM]
Definition: chemf.c:37
struct int64Vector3d * gridStartIdx
Definition: fields.h:42
double gridResolution
Definition: fields.h:45
void revertStdOut()
Definition: io.c:1803
double fieldICMean[NFIELDS]
Definition: fields.h:58
int numberOfIters
Definition: chemf.c:68
char chfname[256]
Definition: chemf.c:60
HYPRE_SStructStencil chemStencil[NCHEM]
Definition: chemf.c:38
int64_t y
Definition: global.h:230
double ** cellFields
Definition: global.h:83
HYPRE_SStructGrid chemGrid[NCHEM]
Definition: chemf.c:36
double fieldLambda[NFIELDS]
Definition: fields.h:56
HYPRE_SStructMatrix chemA[NCHEM]
Definition: chemf.c:40
MPI_Comm MPI_CART_COMM
Definition: global.h:143
int chemObjectType
Definition: chemf.c:51
#define NGLOB
Definition: fields.h:28

Here is the call graph for this function:

Here is the caller graph for this function:

void chemEnvSolve ( int  nch)

This is a driving function for solving next time step of a given chemical field.

Definition at line 431 of file chemf.c.

References bcLower, bcUpper, chemb, chemEnvCellPC(), chemField, chemIter, chemLower, chemParA, chemParb, chemParx, chemPC, chemSetBoundary(), chemSolver, chemUpper, chemx, chemZ, chfname, fieldBC, fieldMax, fieldMin, fieldName, gfIter, gfIterPerStep, gridSize, MPIcoords, MPIdim, MPIrank, NGLOB, numberOfIters, revertStdOut(), statOutStep, step, switchStdOut(), int64Vector3d::x, int64Vector3d::y, and int64Vector3d::z.

432 {
433  int i, j, k;
434  int idx;
435  double *values;
436  int stepIter = 0;
437  long long nvalues = gridSize.x * gridSize.y * gridSize.z;
438 #ifdef DEBUG
439  if (MPIrank == 0 && !(step % statOutStep) && gfIter == 0) {
440  printf(" Solving field: %s...", fieldName[nch + NGLOB]);
441  fflush(stdout);
442  }
443 #endif
444  /* redirecting stdout to log file */
446 
447  values = (double *) calloc(nvalues, sizeof(double));
448  chemPC = (double *) calloc(nvalues, sizeof(double));
449  chemEnvCellPC(nch);
450 
451  fieldMin[nch + NGLOB] = DBL_MAX;
452  fieldMax[nch + NGLOB] = DBL_MIN;
453 
454  while (stepIter < numberOfIters) {
455  if (chemIter[nch] > 0) {
456  /* update right hand side */
457  HYPRE_SStructVectorGetBoxValues(chemx[nch], 0, chemLower, chemUpper,
458  0, values);
459  HYPRE_SStructVectorSetBoxValues(chemb[nch], 0, chemLower, chemUpper,
460  0, values);
461  for (i = 0; i < nvalues; i++)
462  values[i] = chemZ[nch] * fieldBC[nch + NGLOB];
463  if (MPIcoords[MPIrank][0] == 0) {
464  chemSetBoundary(0, -1);
465  HYPRE_SStructVectorAddToBoxValues(chemb[nch], 0, bcLower, bcUpper,
466  0, values);
467  }
468  if (MPIcoords[MPIrank][0] == MPIdim[0] - 1) {
469  chemSetBoundary(0, 1);
470  HYPRE_SStructVectorAddToBoxValues(chemb[nch], 0, bcLower, bcUpper,
471  0, values);
472  }
473  if (MPIcoords[MPIrank][1] == 0) {
474  chemSetBoundary(1, -1);
475  HYPRE_SStructVectorAddToBoxValues(chemb[nch], 0, bcLower, bcUpper,
476  0, values);
477  }
478  if (MPIcoords[MPIrank][1] == MPIdim[1] - 1) {
479  chemSetBoundary(1, 1);
480  HYPRE_SStructVectorAddToBoxValues(chemb[nch], 0, bcLower, bcUpper,
481  0, values);
482  }
483  if (MPIcoords[MPIrank][2] == 0) {
484  chemSetBoundary(2, -1);
485  HYPRE_SStructVectorAddToBoxValues(chemb[nch], 0, bcLower, bcUpper,
486  0, values);
487  }
488  if (MPIcoords[MPIrank][2] == MPIdim[2] - 1) {
489  chemSetBoundary(2, 1);
490  HYPRE_SStructVectorAddToBoxValues(chemb[nch], 0, bcLower, bcUpper,
491  0, values);
492  }
493  HYPRE_SStructVectorAddToBoxValues(chemb[nch], 0, chemLower,
494  chemUpper, 0, chemPC);
495  HYPRE_SStructVectorAssemble(chemb[nch]);
496  HYPRE_SStructVectorAssemble(chemx[nch]);
497  }
498 
499  HYPRE_ParCSRPCGSolve(chemSolver[nch], chemParA[nch], chemParb[nch],
500  chemParx[nch]);
501 
502  /* copy solution to field buffer */
503  HYPRE_SStructVectorGather(chemx[nch]);
504  HYPRE_SStructVectorGetBoxValues(chemx[nch], 0, chemLower, chemUpper, 0,
505  values);
506  idx = 0;
507  for (k = 0; k < gridSize.z; k++)
508  for (j = 0; j < gridSize.y; j++)
509  for (i = 0; i < gridSize.x; i++, idx++) {
510  chemField[nch][gridSize.y * gridSize.z * i + gridSize.z * j +
511  k] = values[idx];
512  if (values[idx] > fieldMax[nch + NGLOB])
513  fieldMax[nch + NGLOB] = values[idx];
514  if (values[idx] < fieldMin[nch + NGLOB])
515  fieldMin[nch + NGLOB] = values[idx];
516  }
517  chemIter[nch]++;
518  stepIter++;
519  }
520 
521  free(values);
522  free(chemPC);
523  /* stdout brought back */
524  revertStdOut();
525 #ifdef DEBUG
526  if (MPIrank == 0 && !(step % statOutStep) && gfIter == gfIterPerStep - 1) {
527  printf("done\n");
528  fflush(stdout);
529  }
530 #endif
531 }
int statOutStep
Definition: global.h:214
int64_t x
Definition: global.h:229
long long bcUpper[3]
Definition: chemf.c:55
int MPIdim[3]
Definition: global.h:136
void chemEnvCellPC(int nch)
Definition: chemf.c:241
HYPRE_ParCSRMatrix chemParA[NCHEM]
Definition: chemf.c:44
int MPIrank
Definition: global.h:134
double chemZ[NCHEM]
Definition: chemf.c:64
double fieldMin[NFIELDS]
Definition: fields.h:72
int gfIter
Definition: global.h:252
double * chemField[NCHEM]
Definition: fields.h:77
int chemIter[NCHEM]
Definition: chemf.c:62
HYPRE_ParVector chemParb[NCHEM]
Definition: chemf.c:45
int64_t z
Definition: global.h:231
char fieldName[NFIELDS][128]
Definition: fields.h:51
long long bcLower[3]
Definition: chemf.c:54
double fieldMax[NFIELDS]
Definition: fields.h:73
long long chemLower[3]
Definition: chemf.c:53
long long chemUpper[3]
Definition: chemf.c:53
void switchStdOut(const char *newStream)
Definition: io.c:1790
int step
Definition: global.h:173
struct int64Vector3d gridSize
Definition: fields.h:41
double fieldBC[NFIELDS]
Definition: fields.h:57
HYPRE_ParVector chemParx[NCHEM]
Definition: chemf.c:46
void revertStdOut()
Definition: io.c:1803
int gfIterPerStep
Definition: global.h:253
int numberOfIters
Definition: chemf.c:68
char chfname[256]
Definition: chemf.c:60
double * chemPC
Definition: chemf.c:70
int64_t y
Definition: global.h:230
void chemSetBoundary(int coord, int boundary)
Definition: chemf.c:75
HYPRE_SStructVector chemb[NCHEM]
Definition: chemf.c:41
int ** MPIcoords
Definition: global.h:144
HYPRE_SStructVector chemx[NCHEM]
Definition: chemf.c:42
HYPRE_Solver chemSolver[NCHEM]
Definition: chemf.c:48
#define NGLOB
Definition: fields.h:28

Here is the call graph for this function:

Here is the caller graph for this function:

void chemSetBoundary ( int  coord,
int  boundary 
)

This function sets boundary conditions for domain faces.

Definition at line 75 of file chemf.c.

References bcLower, bcUpper, chemLower, and chemUpper.

76 {
77  if (coord == 0 && boundary == -1) {
78  bcLower[0] = chemLower[0];
79  bcUpper[0] = chemLower[0];
80  bcLower[1] = chemLower[1];
81  bcUpper[1] = chemUpper[1];
82  bcLower[2] = chemLower[2];
83  bcUpper[2] = chemUpper[2];
84  }
85  if (coord == 0 && boundary == 1) {
86  bcLower[0] = chemUpper[0];
87  bcUpper[0] = chemUpper[0];
88  bcLower[1] = chemLower[1];
89  bcUpper[1] = chemUpper[1];
90  bcLower[2] = chemLower[2];
91  bcUpper[2] = chemUpper[2];
92  }
93  if (coord == 1 && boundary == -1) {
94  bcLower[0] = chemLower[0];
95  bcUpper[0] = chemUpper[0];
96  bcLower[1] = chemLower[1];
97  bcUpper[1] = chemLower[1];
98  bcLower[2] = chemLower[2];
99  bcUpper[2] = chemUpper[2];
100  }
101  if (coord == 1 && boundary == 1) {
102  bcLower[0] = chemLower[0];
103  bcUpper[0] = chemUpper[0];
104  bcLower[1] = chemUpper[1];
105  bcUpper[1] = chemUpper[1];
106  bcLower[2] = chemLower[2];
107  bcUpper[2] = chemUpper[2];
108  }
109  if (coord == 2 && boundary == -1) {
110  bcLower[0] = chemLower[0];
111  bcUpper[0] = chemUpper[0];
112  bcLower[1] = chemLower[1];
113  bcUpper[1] = chemUpper[1];
114  bcLower[2] = chemLower[2];
115  bcUpper[2] = chemLower[2];
116  }
117  if (coord == 2 && boundary == 1) {
118  bcLower[0] = chemLower[0];
119  bcUpper[0] = chemUpper[0];
120  bcLower[1] = chemLower[1];
121  bcUpper[1] = chemUpper[1];
122  bcLower[2] = chemUpper[2];
123  bcUpper[2] = chemUpper[2];
124  }
125 }
long long bcUpper[3]
Definition: chemf.c:55
long long bcLower[3]
Definition: chemf.c:54
long long chemLower[3]
Definition: chemf.c:53
long long chemUpper[3]
Definition: chemf.c:53

Here is the caller graph for this function:

Variable Documentation

long long bcLower[3]

Definition at line 54 of file chemf.c.

long long bcUpper[3]

Definition at line 55 of file chemf.c.

HYPRE_SStructMatrix chemA[NCHEM]

Definition at line 40 of file chemf.c.

HYPRE_SStructVector chemb[NCHEM]

Definition at line 41 of file chemf.c.

HYPRE_SStructGraph chemGraph[NCHEM]

Definition at line 37 of file chemf.c.

HYPRE_SStructGrid chemGrid[NCHEM]

Definition at line 36 of file chemf.c.

int chemIter[NCHEM]

Definition at line 62 of file chemf.c.

double chemLambda = 0.25

Definition at line 58 of file chemf.c.

long long chemLower[3]

Definition at line 53 of file chemf.c.

int chemObjectType

Definition at line 51 of file chemf.c.

HYPRE_ParCSRMatrix chemParA[NCHEM]

Definition at line 44 of file chemf.c.

HYPRE_ParVector chemParb[NCHEM]

Definition at line 45 of file chemf.c.

HYPRE_ParVector chemParx[NCHEM]

Definition at line 46 of file chemf.c.

double* chemPC

Definition at line 70 of file chemf.c.

HYPRE_Solver chemPrecond[NCHEM]

Definition at line 49 of file chemf.c.

HYPRE_Solver chemSolver[NCHEM]

Definition at line 48 of file chemf.c.

HYPRE_SStructStencil chemStencil[NCHEM]

Definition at line 38 of file chemf.c.

long long chemUpper[3]

Definition at line 53 of file chemf.c.

HYPRE_SStructVariable chemVartypes[1] = { HYPRE_SSTRUCT_VARIABLE_NODE }

Definition at line 66 of file chemf.c.

HYPRE_SStructVector chemx[NCHEM]

Definition at line 42 of file chemf.c.

double chemZ[NCHEM]

Definition at line 64 of file chemf.c.

char chfname[256]

Definition at line 60 of file chemf.c.

double dt[NCHEM]

Definition at line 57 of file chemf.c.

int numberOfIters

Definition at line 68 of file chemf.c.