aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@cct.lsu.edu>2008-07-24 18:08:17 -0500
committerErik Schnetter <schnetter@cct.lsu.edu>2008-07-24 18:15:00 -0500
commit23ee00e4816499f09c77e082206320f260d98290 (patch)
tree3db7f175d03c0581f3ef7743056bd64149f44cf9 /Carpet/CarpetLib
parentb38ff94d338f66bd32204d96512b67f9c917b6c9 (diff)
CarpetLib: Introduce vect<T,D>::index
Introduce a new function vect<T,D>::index(lsh,ind), which calculates the linear grid point index given the array size and an index triplet.
Diffstat (limited to 'Carpet/CarpetLib')
-rw-r--r--Carpet/CarpetLib/src/vect.hh14
1 files changed, 14 insertions, 0 deletions
diff --git a/Carpet/CarpetLib/src/vect.hh b/Carpet/CarpetLib/src/vect.hh
index e3f6b086b..3c4232525 100644
--- a/Carpet/CarpetLib/src/vect.hh
+++ b/Carpet/CarpetLib/src/vect.hh
@@ -434,6 +434,20 @@ inline int minloc (const vect<T,D>& a) {
return r;
}
+/** Return the n-dimensional linear array index. */
+template<typename T,int D>
+inline T index (const vect<T,D>& lsh, const vect<T,D>& ind) PURE;
+template<typename T,int D>
+inline T index (const vect<T,D>& lsh, const vect<T,D>& ind) {
+ T r(0);
+ for (int d=D-1; d>=0; --d) {
+ assert (lsh[d]>=0);
+ assert (ind[d]>=0 and ind[d]<lsh[d]);
+ r = r * lsh[d] + ind[d];
+ }
+ return r;
+}
+
// Higher order functions