From c47a4e5376c935baa2a4ebf787911dbee90a59bc Mon Sep 17 00:00:00 2001 From: Ian Hinder Date: Fri, 27 May 2011 11:20:55 +0200 Subject: GenericFD: Add GenericFD_EnsureStencilFits This function checks that there are enough ghost and boundary points for the stencil widths (ni, nj, nk) passed to it. --- .../KrancNumericalTools/GenericFD/src/GenericFD.c | 42 ++++++++++++++++++++++ .../KrancNumericalTools/GenericFD/src/GenericFD.h | 1 + 2 files changed, 43 insertions(+) (limited to 'Auxiliary/Cactus') diff --git a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.c b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.c index 3f34e54..8c06940 100644 --- a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.c +++ b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.c @@ -556,3 +556,45 @@ void GenericFD_GroupDataPointers(cGH const * restrict const cctkGH, const char * ptrs[v] = (CCTK_REAL const *) CCTK_VarDataPtrI(cctkGH, 0 /* timelevel */, v1+v); } } + +void GenericFD_EnsureStencilFits(cGH const * restrict const cctkGH, const char *calc, int ni, int nj, int nk) +{ + DECLARE_CCTK_ARGUMENTS + + int bws[6]; + GenericFD_GetBoundaryWidths(cctkGH, bws); + + int ns[] = {ni, nj, nk}; + const char *dirs[] = {"x", "y", "z"}; + const char *faces[] = {"lower", "upper"}; + int abort = 0; + + for (int dir = 0; dir < 3; dir++) + { + for (int face = 0; face < 2; face++) + { + int bw = bws[2*dir+face]; + if (bw < ns[dir]) + { + CCTK_VInfo(CCTK_THORNSTRING, + "The stencil for %s requires %d points, but the %s %s boundary has only %d points.", + calc, ns[dir], faces[face], dirs[dir], bw); + abort = 1; + } + } + int gz = cctk_nghostzones[dir]; + if (gz < ns[dir]) + { + CCTK_VInfo(CCTK_THORNSTRING, + "The stencil for %s requires %d points, but there are only %d ghost zones in the %s direction.", + calc, ns[dir], gz, dirs[dir]); + abort = 1; + } + } + + if (abort) + { + CCTK_VWarn(CCTK_WARN_ABORT, __LINE__, __FILE__, CCTK_THORNSTRING, + "Insufficient ghost or boundary points for %s", calc); + } +} diff --git a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h index ee35b05..401b4e0 100644 --- a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h +++ b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h @@ -154,6 +154,7 @@ void GenericFD_LoopOverInterior(cGH const * restrict cctkGH, Kranc_Calculation c void GenericFD_GroupDataPointers(cGH const * restrict const cctkGH, const char *group_name, int nvars, CCTK_REAL const *restrict *ptrs); +void GenericFD_EnsureStencilFits(cGH const * restrict const cctkGH, const char *calc, int ni, int nj, int nk); #ifdef __cplusplus -- cgit v1.2.3