Chombo + EB  3.2
IndicesFunctions.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _INDICESFUNCTIONS_H_
12 #define _INDICESFUNCTIONS_H_
13 
14 #include "Box.H"
15 
16 #include "NamespaceHeader.H"
17 
18 inline size_t FortranArrayIndex(IntVect a_iv,
19  IntVect a_dims)
20 {
21  CH_assert(a_iv >= IntVect::Zero);
22  CH_assert(a_dims >= IntVect::Zero);
23  // Fortran array order: last dimension changes most slowly.
24  size_t ind = a_iv[CH_SPACEDIM-1];
25  for (int idir = CH_SPACEDIM-2; idir >= 0; idir--)
26  {
27  ind *= a_dims[idir];
28  ind += a_iv[idir];
29  }
30  return ind;
31 }
32 
33 inline size_t FortranArrayIndex(IntVect a_iv,
34  Box a_bx)
35 {
36  IntVect dims = a_bx.size();
37  IntVect offset = a_iv - a_bx.smallEnd();
38  return FortranArrayIndex(offset, dims);
39 }
40 
41 inline IntVect FortranArrayIndex(size_t a_ind,
42  IntVect a_dims)
43 {
44  IntVect iv;
45  // Fortran array order: first dimension changes fastest
46  size_t indRemaining = a_ind;
47  for (int idir = 0; idir < CH_SPACEDIM-1; idir++)
48  {
49  iv[idir] = indRemaining % a_dims[idir];
50  indRemaining -= iv[idir];
51  indRemaining /= a_dims[idir];
52  }
53  iv[CH_SPACEDIM-1] = indRemaining;
54  return iv;
55 }
56 
57 // Return inverse permutation of a_permutation.
58 IntVect inversePermutation(const IntVect& a_permutation);
59 
60 // Test whether the IntVect represents a legal permutation of dimensions.
61 bool isPermutationVect(const IntVect& a_permutation);
62 
63 // Test whether the IntVect represents a legal sign vector.
64 bool isSignVect(const IntVect& a_sign);
65 
66 // Test whether the index is within the range of dimensions.
67 inline bool inDimensionRange(int a_ind)
68 {
69  return ((a_ind >= 0) && (a_ind < CH_SPACEDIM));
70 }
71 
72 #include "NamespaceFooter.H"
73 
74 #endif
IntVect size() const
size functions
Definition: Box.H:1803
#define CH_SPACEDIM
Definition: SPACE.H:51
#define CH_assert(cond)
Definition: CHArray.H:37
bool isSignVect(const IntVect &a_sign)
IntVect inversePermutation(const IntVect &a_permutation)
size_t FortranArrayIndex(IntVect a_iv, IntVect a_dims)
Definition: IndicesFunctions.H:18
bool isPermutationVect(const IntVect &a_permutation)
const IntVect & smallEnd() const
{ Accessors}
Definition: Box.H:1754
static const IntVect Zero
Definition: IntVect.H:654
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
bool inDimensionRange(int a_ind)
Definition: IndicesFunctions.H:67
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42