| 1 | /*
|
|---|
| 2 | * Defined petsc.h header for provesa PETSc examples: ex2a.c, ex2b.c,
|
|---|
| 3 | * ex2c.c,ex2d.c. This header is used for verifying the equivalence of those
|
|---|
| 4 | * examples by using CIVL. This header is made based on the functions and
|
|---|
| 5 | * types which is used in those PETSc examples. The definition of types and
|
|---|
| 6 | * funcitons comes from PETSc home page: https://www.mcs.anl.gov/petsc/
|
|---|
| 7 | * PETSc examples: https://repo.anl-external.org/repos/provesa/codes/mxm/
|
|---|
| 8 | *
|
|---|
| 9 | * Author: Si Li <sili@udel.edu>
|
|---|
| 10 | */
|
|---|
| 11 |
|
|---|
| 12 | #ifndef _PETSC_
|
|---|
| 13 | #define _PETSC_
|
|---|
| 14 |
|
|---|
| 15 | #include <math.h>
|
|---|
| 16 | #define PetscExpScalar(x) exp(x)
|
|---|
| 17 |
|
|---|
| 18 | /* -------Types------- */
|
|---|
| 19 |
|
|---|
| 20 | /* PetscErrorCode - datatype used for return error code from almost
|
|---|
| 21 | * all PETSc functions */
|
|---|
| 22 | typedef int PetscErrorCode;
|
|---|
| 23 |
|
|---|
| 24 | /* PETSc type that represents a PetscReal.
|
|---|
| 25 | * This is the same as a PetscReal except in code that is automatically
|
|---|
| 26 | * differentiated it is treated as a constant (not an indendent or
|
|---|
| 27 | * dependent variable)
|
|---|
| 28 | */
|
|---|
| 29 | typedef double PassiveReal;
|
|---|
| 30 |
|
|---|
| 31 | /* PETSc type that represents integer - used primarily to represent size
|
|---|
| 32 | * of arrays and indexing into arrays. Its size can be * configured with
|
|---|
| 33 | * the option-with-64-bit-indices - to be either
|
|---|
| 34 | * 32bit or 64bit [default 32 bit ints]
|
|---|
| 35 | */
|
|---|
| 36 | typedef int PetscInt;
|
|---|
| 37 |
|
|---|
| 38 | /* PetscReal - PETSc type that represents a real number version of
|
|---|
| 39 | * PetscScalar */
|
|---|
| 40 | typedef double PetscReal;
|
|---|
| 41 |
|
|---|
| 42 | /* PetscScalar - PETSc type that represents either a double precision
|
|---|
| 43 | * real number, a double precision complex number, a single precision
|
|---|
| 44 | * real number, a long double or an int - if the code is configured
|
|---|
| 45 | * with --with-scalar-type=real, complex --with-precision=single,
|
|---|
| 46 | * double,__float128
|
|---|
| 47 | */
|
|---|
| 48 | typedef double PetscScalar;
|
|---|
| 49 |
|
|---|
| 50 | /* C struct that contains information about a structured grid and
|
|---|
| 51 | a processors logical location in it. */
|
|---|
| 52 | typedef struct DMDALocalInfo { /* using distributed arrays */
|
|---|
| 53 | PetscInt dim,dof,sw;
|
|---|
| 54 | PetscInt mx,my,mz; /* global number of grid points in each direction */
|
|---|
| 55 | PetscInt xs,ys,zs; /* starting point of this processor, excluding ghosts */
|
|---|
| 56 | PetscInt xm,ym,zm; /* number of grid points on this processor, excluding ghosts */
|
|---|
| 57 | PetscInt gxs,gys,gzs; /* starting point of this processor including ghosts */
|
|---|
| 58 | PetscInt gxm,gym,gzm; /* number of grid points on this processor including ghosts */
|
|---|
| 59 | } DMDALocalInfo;
|
|---|
| 60 |
|
|---|
| 61 | /* ----------Functions---------- */
|
|---|
| 62 |
|
|---|
| 63 | /* First executable line of each PETSc function, used for error handling.
|
|---|
| 64 | * Final line of PETSc functions should be PetscFunctionReturn(0);
|
|---|
| 65 | */
|
|---|
| 66 | #define PetscFunctionBegin
|
|---|
| 67 |
|
|---|
| 68 | /* Last executable line of each PETSc function used for error handling.
|
|---|
| 69 | * Replaces return() */
|
|---|
| 70 | #define PetscFunctionReturn(x) return(x)
|
|---|
| 71 |
|
|---|
| 72 | /* Adds floating point operations to the global counter. */
|
|---|
| 73 | PetscErrorCode PetscLogFlops(double );
|
|---|
| 74 |
|
|---|
| 75 | /* Checks error code, if non-zero it calls the error handler and then
|
|---|
| 76 | * returns */
|
|---|
| 77 | PetscErrorCode CHKERRQ(PetscErrorCode );
|
|---|
| 78 |
|
|---|
| 79 | /*
|
|---|
| 80 | #undef __FUNCT__
|
|---|
| 81 | #define __FUNCT__ "PetscLogFlops"
|
|---|
| 82 | PETSC_STATIC_INLINE PetscErrorCode PetscLogFlops(PetscLogDouble n)
|
|---|
| 83 | {
|
|---|
| 84 | PetscFunctionBegin;
|
|---|
| 85 | #if defined(PETSC_USE_DEBUG)
|
|---|
| 86 | if (n < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Cannot log negative flops");
|
|---|
| 87 | #endif
|
|---|
| 88 | petsc_TotalFlops += PETSC_FLOPS_PER_OP*n;
|
|---|
| 89 | PetscFunctionReturn(0);
|
|---|
| 90 | }
|
|---|
| 91 | */
|
|---|
| 92 |
|
|---|
| 93 | #endif
|
|---|