aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorschnetter <schnetter@1bf05452-ddb3-4880-bfa1-00436340132b>2003-05-05 11:58:09 +0000
committerschnetter <schnetter@1bf05452-ddb3-4880-bfa1-00436340132b>2003-05-05 11:58:09 +0000
commit7d957cbc6da68f0b6bc24065ee7ada778f688a70 (patch)
tree2f4a11db596e0664d8a575c0707c07c8f1f8e688 /src
parent7e2caf1a266d0cef99ebf57b7bf451d47dc37457 (diff)
Initial coding of a thorn that provides periodic boundary conditions
that are independent of PUGH, i.e. that work with both PUGH and Carpet. git-svn-id: http://svn.cactuscode.org/arrangements/CactusNumerical/Periodic/trunk@2 1bf05452-ddb3-4880-bfa1-00436340132b
Diffstat (limited to 'src')
-rw-r--r--src/make.code.defn9
-rw-r--r--src/periodic.c163
-rw-r--r--src/periodic.h29
3 files changed, 201 insertions, 0 deletions
diff --git a/src/make.code.defn b/src/make.code.defn
new file mode 100644
index 0000000..a62de81
--- /dev/null
+++ b/src/make.code.defn
@@ -0,0 +1,9 @@
+# Main make.code.defn file for thorn Periodic
+# $Header$
+
+# Source files in this directory
+SRCS =
+
+# Subdirectories containing source files
+SUBDIRS =
+
diff --git a/src/periodic.c b/src/periodic.c
new file mode 100644
index 0000000..feb6aec
--- /dev/null
+++ b/src/periodic.c
@@ -0,0 +1,163 @@
+/* $Header$ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include "cctk.h"
+#include "cctk_Parameters.h"
+#include "Slab.h"
+#include "Periodic.h"
+
+static const char * restrict const rcsid = "$Header$";
+CCTK_FILEVERSION(TAT_Periodic_periodic_c);
+
+
+
+int
+BndPeriodicVI (cGH const * restrict const cctkGH,
+ int const * restrict const stencil,
+ int const vi)
+{
+ cGroup group;
+ cGroupDynamicData data;
+ void * restrict varptr;
+ struct xferinfo * restrict xferinfo;
+ int do_periodic[3];
+ int gi;
+ int dir;
+ int d, f;
+ int ierr;
+
+ /* Check arguments */
+ assert (cctkGH);
+ assert (stencil);
+ assert (vi>=0 && vi<CCTK_NumVars());
+
+ /* Get and check group info */
+ gi = CCTK_GroupIndexFromVarI (vi);
+ assert (gi>=0 && gi<CCTK_NumGroups());
+
+ ierr = CCTK_GroupData (gi, &group);
+ assert (!ierr);
+ assert (group.grouptype == CCTK_GF);
+ assert (group.disttype == CCTK_DISTRIB_DEFAULT);
+ assert (group.stagtype == 0);
+
+ ierr = CCTK_GroupDynamicData (cctkGH, gi, &data);
+ assert (!ierr);
+
+ varptr = CCTK_VarDataPtrI (cctkGH, 0, vi);
+ assert (varptr);
+
+ /* Condition periodicity information */
+ do_periodic[0] = periodic || periodic_x;
+ do_periodic[1] = periodic || periodic_y;
+ do_periodic[2] = periodic || periodic_z;
+
+ /* Allocate slab transfer description */
+ xferinfo = malloc(group.dim * sizeof *xferinfo);
+ assert (xferinfo);
+
+ for (dir=0; dir<group.dim; ++dir) {
+ if (dir<3 && do_periodic[dir]) {
+
+ /* Loop over faces */
+ for (f=0; f<2; ++f) {
+
+ /* Fill in slab transfer description */
+ for (d=0; d<group.dim; ++d) {
+ xferinfo[d].src.gsh = data.gsh [d];
+ xferinfo[d].src.lbnd = data.lbnd [d];
+ xferinfo[d].src.lsh = data.lsh [d];
+ xferinfo[d].src.lbbox = data.bbox [2*d ];
+ xferinfo[d].src.ubbox = data.bbox [2*d+1];
+ xferinfo[d].src.nghostzones = data.nghostzones[d];
+ xferinfo[d].src.off = 0;
+ xferinfo[d].src.str = 1;
+ xferinfo[d].src.len = data.lsh [d];
+
+ xferinfo[d].dst.gsh = data.gsh [d];
+ xferinfo[d].dst.lbnd = data.lbnd [d];
+ xferinfo[d].dst.lsh = data.lsh [d];
+ xferinfo[d].dst.lbbox = data.bbox [2*d ];
+ xferinfo[d].dst.ubbox = data.bbox [2*d+1];
+ xferinfo[d].dst.nghostzones = data.nghostzones[d];
+ xferinfo[d].dst.off = 0;
+ xferinfo[d].dst.str = 1;
+ xferinfo[d].dst.len = data.lsh [d];
+
+ xferinfo[d].xpose = d;
+ xferinfo[d].flip = 0;
+ }
+
+ if (f==0) {
+ /* Fill in lower face */
+ xferinfo[dir].src.off = data.lsh[d] - data.nghostzones[d];
+ xferinfo[dir].src.len = data.nghostzones[d];
+ xferinfo[dir].dst.len = data.nghostzones[d];
+ } else {
+ /* Fill in upper face */
+ xferinfo[dir].src.len = data.nghostzones[d];
+ xferinfo[dir].dst.off = data.lsh[d] - data.nghostzones[d];
+ xferinfo[dir].dst.len = data.nghostzones[d];
+ }
+
+ ierr = Slab_Transfer (cctkGH, group.dim, xferinfo, -1,
+ group.vartype, varptr, group.vartype, varptr);
+ assert (ierr);
+
+ } /* for f */
+
+ } /* if dir */
+ } /* for dir */
+
+ free (xferinfo);
+
+ return 0;
+}
+
+
+
+int
+BndPeriodicVN (cGH const * restrict const cctkGH,
+ int const * restrict const stencil,
+ char const * restrict const vn)
+{
+ int const vi = CCTK_VarIndex (vn);
+ assert (vi>=0 && vi<CCTK_NumVars());
+ return BndPeriodicVI (cctkGH, stencil, vi);
+}
+
+
+
+int
+BndPeriodicGI (cGH const * restrict const cctkGH,
+ int const * restrict const stencil,
+ int const gi)
+{
+ int vi1, vi2;
+ int vi;
+ int ierr;
+ assert (gi>=0 && gi<CCTK_NumGroups());
+ vi1 = CCTK_FirstVarIndexI(gi);
+ assert (vi1>=0 && vi1<CCTK_NumVars());
+ vi2 = vi1 + CCTK_NumVarsInGroupI(gi);
+ assert (vi2>=vi1 && vi2<CCTK_NumVars());
+ assert (vi>=0 && vi<CCTK_NumVars());
+ for (vi=vi1; vi<vi2; ++vi) {
+ ierr = BndPeriodicVI (cctkGH, stencil, vi);
+ if (ierr) return ierr;
+ }
+ return 0;
+}
+
+
+
+int
+BndPeriodicGN (cGH const * restrict const cctkGH,
+ int const * restrict const stencil,
+ char const * restrict const gn)
+{
+ int const gi = CCTK_GroupIndex (gn);
+ assert (gi>=0 && gi<CCTK_NumGroups());
+ return BndPeriodicGI (cctkGH, stencil, gi);
+}
diff --git a/src/periodic.h b/src/periodic.h
new file mode 100644
index 0000000..2f381f3
--- /dev/null
+++ b/src/periodic.h
@@ -0,0 +1,29 @@
+/* $Header$ */
+
+#ifndef PERIODIC_H
+#define PERIODIC_H
+
+#include "cctk.h"
+
+int
+BndPeriodicVI (cGH const * restrict const cctkGH,
+ int const * restrict const stencil,
+ int const vi);
+
+int
+BndPeriodicVN (cGH const * restrict const cctkGH,
+ int const * restrict const stencil,
+ char const * restrict const vn);
+
+int
+BndPeriodicGI (cGH const * restrict const cctkGH,
+ int const * restrict const stencil,
+ int const gi);
+
+int
+BndPeriodicGN (cGH const * restrict const cctkGH,
+ int const * restrict const stencil,
+ char const * restrict const gn);
+
+#endif /* defined PERIODIC_H */
+