aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/prolongate_3d_cc_rf2.cc
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@cct.lsu.edu>2007-01-12 20:58:00 +0000
committerErik Schnetter <schnetter@cct.lsu.edu>2007-01-12 20:58:00 +0000
commitc23315efb5b4fea80c92f747173e47a7d29d644d (patch)
treed56de98cca60845ae083fe3d397843dda6102160 /Carpet/CarpetLib/src/prolongate_3d_cc_rf2.cc
parent3c4993dd3e36426d62cbf8e574cba9ec6cf2ec89 (diff)
CarpetLib: Reorganise prolongation and restriction operators
Reorganise prolongation and restriction operators. This is a major implementation change. Most operators are now written as C++ templates instead of as Fortran 77 code. This simplifies the code, since C++ routines can be called more easily, and they also have access to CarpetLib's high-level data structures. Previously, the operators combined temporal and spatial interpolation. Now, time interpolation and space interpolation are handled separately. This may be less efficient, but simplifies the code significantly, since there are now N+M instead of N*M routines, for N time interpolation and M space interpolation methods. Remove the minmod prolongation operator, which was previously disabled. Add support for cell centering, using a method described by Simon Hern, and suggested for Carpet by Ian Hawke. darcs-hash:20070112205812-dae7b-5329795aa698e7bbc3671b1504134885dd830238.gz
Diffstat (limited to 'Carpet/CarpetLib/src/prolongate_3d_cc_rf2.cc')
-rw-r--r--Carpet/CarpetLib/src/prolongate_3d_cc_rf2.cc441
1 files changed, 441 insertions, 0 deletions
diff --git a/Carpet/CarpetLib/src/prolongate_3d_cc_rf2.cc b/Carpet/CarpetLib/src/prolongate_3d_cc_rf2.cc
new file mode 100644
index 000000000..e0748ea56
--- /dev/null
+++ b/Carpet/CarpetLib/src/prolongate_3d_cc_rf2.cc
@@ -0,0 +1,441 @@
+// See also Hern, "Numerical Relativity and Inhomogeneous
+// Cosmologies", gr-qc/0004036, section 3.2, pp. 29 ff.; especially
+// the last equation on page 37.
+
+
+
+#include <algorithm>
+#include <cassert>
+#include <cmath>
+
+#include <cctk.h>
+#include <cctk_Parameters.h>
+
+#include "operator_prototypes.hh"
+#include "typeprops.hh"
+
+using namespace std;
+
+
+
+namespace CarpetLib {
+
+
+
+#define SRCIND3(i,j,k) \
+ index3 (srcioff + (i), srcjoff + (j), srckoff + (k), \
+ srciext, srcjext, srckext)
+#define DSTIND3(i,j,k) \
+ index3 (dstioff + (i), dstjoff + (j), dstkoff + (k), \
+ dstiext, dstjext, dstkext)
+
+
+
+ // Convert from the "standard" form of the grid function to the
+ // "primitive" version, i.e., the antiderivative
+
+ template <typename T>
+ void
+ prolongate_3d_cc_rf2_std2prim (T const * restrict const src,
+ ivect3 const & srcext,
+ T * restrict const dst,
+ ivect3 const & dstext,
+ ibbox3 const & srcbbox,
+ ibbox3 const & dstbbox,
+ ibbox3 const & regbbox)
+ {
+ DECLARE_CCTK_PARAMETERS;
+
+ typedef typename typeprops<T>::real RT;
+ T (* const fromreal) (RT) = typeprops<T>::fromreal;
+
+
+
+ if (any (srcbbox.stride() != regbbox.stride() or
+ dstbbox.stride() != regbbox.stride()))
+ {
+ CCTK_WARN (0, "Internal error: strides disagree");
+ }
+
+ if (any (srcbbox.stride() != dstbbox.stride())) {
+ CCTK_WARN (0, "Internal error: strides disagree");
+ }
+
+ // This could be handled, but is likely to point to an error
+ // elsewhere
+ if (regbbox.empty()) {
+ CCTK_WARN (0, "Internal error: region extent is empty");
+ }
+
+ if (not regbbox.is_contained_in(srcbbox) or
+ not regbbox.is_contained_in(dstbbox))
+ {
+ CCTK_WARN (0, "Internal error: region extent is not contained in array extent");
+ }
+
+ if (any (srcext != srcbbox.shape() / srcbbox.stride() or
+ dstext != dstbbox.shape() / dstbbox.stride()))
+ {
+ CCTK_WARN (0, "Internal error: array sizes don't agree with bounding boxes");
+ }
+
+
+
+ ivect3 const regext = regbbox.shape() / regbbox.stride();
+ assert (all (regbbox.stride() % 2 == 0));
+ assert (all ((regbbox.lower() - srcbbox.lower() + regbbox.stride() / 2) %
+ regbbox.stride() == 0));
+ ivect3 const srcoff =
+ (regbbox.lower() - srcbbox.lower() + regbbox.stride() / 2) /
+ regbbox.stride();
+ assert (all ((regbbox.lower() - dstbbox.lower()) % regbbox.stride() == 0));
+ ivect3 const dstoff =
+ (regbbox.lower() - dstbbox.lower()) / regbbox.stride();
+
+
+
+ int const srciext = srcext[0];
+ int const srcjext = srcext[1];
+ int const srckext = srcext[2];
+
+ int const dstiext = dstext[0];
+ int const dstjext = dstext[1];
+ int const dstkext = dstext[2];
+
+ int const regiext = regext[0];
+ int const regjext = regext[1];
+ int const regkext = regext[2];
+
+ int const srcioff = srcoff[0];
+ int const srcjoff = srcoff[1];
+ int const srckoff = srcoff[2];
+
+ int const dstioff = dstoff[0];
+ int const dstjoff = dstoff[1];
+ int const dstkoff = dstoff[2];
+
+
+
+ T const zero = fromreal (0);
+
+
+
+#if 0
+ // Original version
+
+ // Initialize the corner
+
+ dst [DSTIND3(0, 0, 0)] =
+ zero;
+
+ // Compute the axis lines
+
+ for (int i=1; i<regiext; ++i) {
+ dst [DSTIND3(i, 0, 0)] =
+ + dst [DSTIND3(i-1, 0, 0)]
+ + src [SRCIND3(i-1, 0, 0)];
+ }
+
+ for (int j=1; j<regjext; ++j) {
+ dst [DSTIND3(0, j, 0)] =
+ + dst [DSTIND3(0, j-1, 0)]
+ + src [SRCIND3(0, j-1, 0)];
+ }
+
+ for (int k=1; k<regkext; ++k) {
+ dst [DSTIND3(0, 0, k)] =
+ + dst [DSTIND3(0, 0, k-1)]
+ + src [SRCIND3(0, 0, k-1)];
+ }
+
+ // Compute the planes
+
+ for (int j=1; j<regjext; ++j) {
+ for (int i=1; i<regiext; ++i) {
+ dst [DSTIND3(i, j, 0)] =
+ + dst [DSTIND3(i-1, j, 0)]
+ + dst [DSTIND3(i, j-1, 0)]
+ - dst [DSTIND3(i-1, j-1, 0)]
+ + src [SRCIND3(i-1, j-1, 0)];
+ }
+ }
+
+ for (int k=1; k<regkext; ++k) {
+ for (int i=1; i<regiext; ++i) {
+ dst [DSTIND3(i, 0, k)] =
+ + dst [DSTIND3(i-1, 0, k)]
+ + dst [DSTIND3(i, 0, k-1)]
+ - dst [DSTIND3(i-1, 0, k-1)]
+ + src [SRCIND3(i-1, 0, k-1)];
+ }
+ }
+
+ for (int k=1; k<regkext; ++k) {
+ for (int j=1; j<regjext; ++j) {
+ dst [DSTIND3(0, j, k)] =
+ + dst [DSTIND3(0, j-1, k)]
+ + dst [DSTIND3(0, j, k-1)]
+ - dst [DSTIND3(0, j-1, k-1)]
+ + src [SRCIND3(0, j-1, k-1)];
+ }
+ }
+
+ // Compute the interior
+
+ for (int k=1; k<regkext; ++k) {
+ for (int j=1; j<regjext; ++j) {
+ for (int i=1; i<regiext; ++i) {
+ dst [DSTIND3(i, j, k)] =
+ + dst [DSTIND3(i-1, j, k)]
+ + dst [DSTIND3(i, j-1, k)]
+ + dst [DSTIND3(i, j, k-1)]
+ - 2 * dst [DSTIND3(i-1, j-1, k-1)]
+ + src [SRCIND3(i-1, j-1, k-1)];
+ }
+ }
+ }
+
+#endif
+
+#if 1
+
+ for (int k=0; k<regkext; ++k) {
+ for (int j=0; j<regjext; ++j) {
+ for (int i=0; i<regiext; ++i) {
+ if (i==0 or j==0 or k==0) {
+ dst [DSTIND3(i, j, k)] = zero;
+ } else {
+ // // 1D
+ // dst [DSTIND1(i)] =
+ // + dst [DSTIND1(i-1)]
+ // + src [SRCIND1(i-1)];
+ // // 2D
+ // dst [DSTIND2(i, j, k)] =
+ // + dst [DSTIND2(i-1, j)]
+ // + dst [DSTIND2(i, j-1)]
+ // - dst [DSTIND2(i-1, j-1)]
+ // + src [SRCIND2(i-1, j-1)];
+ // 3D
+ dst [DSTIND3(i, j, k)] =
+ + dst [DSTIND3(i-1, j, k)]
+ + dst [DSTIND3(i, j-1, k)]
+ + dst [DSTIND3(i, j, k-1)]
+ - dst [DSTIND3(i, j-1, k-1)]
+ - dst [DSTIND3(i-1, j, k-1)]
+ - dst [DSTIND3(i-1, j-1, k)]
+ + dst [DSTIND3(i-1, j-1, k-1)]
+ + src [SRCIND3(i-1, j-1, k-1)];
+ }
+ }
+ }
+ }
+
+#endif
+
+#if 0
+ // For testing
+
+#warning "TODO"
+ for (int k=0; k<regkext; ++k) {
+ for (int j=0; j<regjext; ++j) {
+ for (int i=0; i<regiext; ++i) {
+ if (i==0 or j==0 or k==0) {
+ dst [DSTIND3(i, j, k)] = zero;
+ } else {
+ dst [DSTIND3(i, j, k)] = src [SRCIND3(i-1, j-1, k-1)];
+ }
+ }
+ }
+ }
+
+#endif
+
+ }
+
+
+
+ template
+ void
+ prolongate_3d_cc_rf2_std2prim (CCTK_REAL const * restrict const src,
+ ivect3 const & srcext,
+ CCTK_REAL * restrict const dst,
+ ivect3 const & dstext,
+ ibbox3 const & srcbbox,
+ ibbox3 const & dstbbox,
+ ibbox3 const & regbbox);
+
+ template
+ void
+ prolongate_3d_cc_rf2_std2prim (CCTK_COMPLEX const * restrict const src,
+ ivect3 const & srcext,
+ CCTK_COMPLEX * restrict const dst,
+ ivect3 const & dstext,
+ ibbox3 const & srcbbox,
+ ibbox3 const & dstbbox,
+ ibbox3 const & regbbox);
+
+
+
+ // Convert from the "primitive" form of the grid function to the
+ // "standard" version
+
+ template <typename T>
+ void
+ prolongate_3d_cc_rf2_prim2std (T const * restrict const src,
+ ivect const & srcext,
+ T * restrict const dst,
+ ivect const & dstext,
+ ibbox3 const & srcbbox,
+ ibbox3 const & dstbbox,
+ ibbox3 const & regbbox)
+ {
+ DECLARE_CCTK_PARAMETERS;
+
+
+
+ if (any (srcbbox.stride() != regbbox.stride() or
+ dstbbox.stride() != regbbox.stride()))
+ {
+ CCTK_WARN (0, "Internal error: strides disagree");
+ }
+
+ if (any (srcbbox.stride() != dstbbox.stride())) {
+ CCTK_WARN (0, "Internal error: strides disagree");
+ }
+
+ // This could be handled, but is likely to point to an error
+ // elsewhere
+ if (regbbox.empty()) {
+ CCTK_WARN (0, "Internal error: region extent is empty");
+ }
+
+ if (not regbbox.is_contained_in(srcbbox) or
+ not regbbox.is_contained_in(dstbbox))
+ {
+ CCTK_WARN (0, "Internal error: region extent is not contained in array extent");
+ }
+
+ if (any (srcext != srcbbox.shape() / srcbbox.stride() or
+ dstext != dstbbox.shape() / dstbbox.stride()))
+ {
+ CCTK_WARN (0, "Internal error: array sizes don't agree with bounding boxes");
+ }
+
+
+
+ ivect3 const regext = regbbox.shape() / regbbox.stride();
+ assert (all (regbbox.stride() % 2 == 0));
+ assert (all ((regbbox.lower() - srcbbox.lower() - regbbox.stride() / 2) %
+ regbbox.stride() == 0));
+ ivect3 const srcoff =
+ (regbbox.lower() - srcbbox.lower() - regbbox.stride() / 2) /
+ regbbox.stride();
+ assert (all ((regbbox.lower() - dstbbox.lower()) % regbbox.stride() == 0));
+ ivect3 const dstoff =
+ (regbbox.lower() - dstbbox.lower()) / regbbox.stride();
+
+
+
+ int const srciext = srcext[0];
+ int const srcjext = srcext[1];
+ int const srckext = srcext[2];
+
+ int const dstiext = dstext[0];
+ int const dstjext = dstext[1];
+ int const dstkext = dstext[2];
+
+ int const regiext = regext[0];
+ int const regjext = regext[1];
+ int const regkext = regext[2];
+
+ int const srcioff = srcoff[0];
+ int const srcjoff = srcoff[1];
+ int const srckoff = srcoff[2];
+
+ int const dstioff = dstoff[0];
+ int const dstjoff = dstoff[1];
+ int const dstkoff = dstoff[2];
+
+
+
+#if 0
+ // Original version
+
+ // Compute the interior
+
+ for (int k=0; k<regkext; ++k) {
+ for (int j=0; j<regjext; ++j) {
+ for (int i=0; i<regiext; ++i) {
+ dst [DSTIND3(i, j, k)] =
+ + src [SRCIND3(i+1, j+1, k+1)]
+ - src [SRCIND3(i, j+1, k+1)]
+ - src [SRCIND3(i+1, j, k+1)]
+ - src [SRCIND3(i+1, j+1, k)]
+ + 2 * src [SRCIND3(i-1, j-1, k-1)];
+ }
+ }
+ }
+
+#endif
+
+#if 1
+
+ for (int k=0; k<regkext; ++k) {
+ for (int j=0; j<regjext; ++j) {
+ for (int i=0; i<regiext; ++i) {
+ dst [DSTIND3(i, j, k)] = reffact2 *
+ (- src [SRCIND3(i, j+1, k+1)]
+ - src [SRCIND3(i+1, j, k+1)]
+ - src [SRCIND3(i+1, j+1, k)]
+ + src [SRCIND3(i+1, j, k)]
+ + src [SRCIND3(i, j+1, k)]
+ + src [SRCIND3(i, j, k+1)]
+ - src [SRCIND3(i, j, k)]
+ + src [SRCIND3(i+1, j+1, k+1)]);
+ }
+ }
+ }
+
+#endif
+
+#if 0
+ // For testing
+
+#warning "TODO"
+ for (int k=0; k<regkext; ++k) {
+ for (int j=0; j<regjext; ++j) {
+ for (int i=0; i<regiext; ++i) {
+ dst [DSTIND3(i, j, k)] = src [SRCIND3(i+1, j+1, k+1)];
+ }
+ }
+ }
+
+#endif
+
+ }
+
+
+
+ template
+ void
+ prolongate_3d_cc_rf2_prim2std (CCTK_REAL const * restrict const src,
+ ivect const & srcext,
+ CCTK_REAL * restrict const dst,
+ ivect const & dstext,
+ ibbox3 const & srcbbox,
+ ibbox3 const & dstbbox,
+ ibbox3 const & regbbox);
+
+ template
+ void
+ prolongate_3d_cc_rf2_prim2std (CCTK_COMPLEX const * restrict const src,
+ ivect const & srcext,
+ CCTK_COMPLEX * restrict const dst,
+ ivect const & dstext,
+ ibbox3 const & srcbbox,
+ ibbox3 const & dstbbox,
+ ibbox3 const & regbbox);
+
+
+
+} // namespace CarpetLib