From 23ee00e4816499f09c77e082206320f260d98290 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Thu, 24 Jul 2008 18:08:17 -0500 Subject: CarpetLib: Introduce vect::index Introduce a new function vect::index(lsh,ind), which calculates the linear grid point index given the array size and an index triplet. --- Carpet/CarpetLib/src/vect.hh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Carpet/CarpetLib') 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& a) { return r; } +/** Return the n-dimensional linear array index. */ +template +inline T index (const vect& lsh, const vect& ind) PURE; +template +inline T index (const vect& lsh, const vect& ind) { + T r(0); + for (int d=D-1; d>=0; --d) { + assert (lsh[d]>=0); + assert (ind[d]>=0 and ind[d]