00001 #ifdef CH_LANG_CC 00002 /* 00003 * _______ __ 00004 * / ___/ / ___ __ _ / / ___ 00005 * / /__/ _ \/ _ \/ V \/ _ \/ _ \ 00006 * \___/_//_/\___/_/_/_/_.__/\___/ 00007 * Please refer to Copyright.txt, in Chombo's root directory. 00008 */ 00009 #endif 00010 00011 #ifndef _INDICESFUNCTIONS_H_ 00012 #define _INDICESFUNCTIONS_H_ 00013 00014 #include "Box.H" 00015 00016 #include "NamespaceHeader.H" 00017 00018 inline size_t FortranArrayIndex(IntVect a_iv, 00019 IntVect a_dims) 00020 { 00021 CH_assert(a_iv >= IntVect::Zero); 00022 CH_assert(a_dims >= IntVect::Zero); 00023 // Fortran array order: last dimension changes most slowly. 00024 size_t ind = a_iv[CH_SPACEDIM-1]; 00025 for (int idir = CH_SPACEDIM-2; idir >= 0; idir--) 00026 { 00027 ind *= a_dims[idir]; 00028 ind += a_iv[idir]; 00029 } 00030 return ind; 00031 } 00032 00033 inline size_t FortranArrayIndex(IntVect a_iv, 00034 Box a_bx) 00035 { 00036 IntVect dims = a_bx.size(); 00037 IntVect offset = a_iv - a_bx.smallEnd(); 00038 return FortranArrayIndex(offset, dims); 00039 } 00040 00041 inline IntVect FortranArrayIndex(size_t a_ind, 00042 IntVect a_dims) 00043 { 00044 IntVect iv; 00045 // Fortran array order: first dimension changes fastest 00046 size_t indRemaining = a_ind; 00047 for (int idir = 0; idir < CH_SPACEDIM-1; idir++) 00048 { 00049 iv[idir] = indRemaining % a_dims[idir]; 00050 indRemaining -= iv[idir]; 00051 indRemaining /= a_dims[idir]; 00052 } 00053 iv[CH_SPACEDIM-1] = indRemaining; 00054 return iv; 00055 } 00056 00057 // Return inverse permutation of a_permutation. 00058 IntVect inversePermutation(const IntVect& a_permutation); 00059 00060 // Test whether the IntVect represents a legal permutation of dimensions. 00061 bool isPermutationVect(const IntVect& a_permutation); 00062 00063 // Test whether the IntVect represents a legal sign vector. 00064 bool isSignVect(const IntVect& a_sign); 00065 00066 // Test whether the index is within the range of dimensions. 00067 inline bool inDimensionRange(int a_ind) 00068 { 00069 return ((a_ind >= 0) && (a_ind < CH_SPACEDIM)); 00070 } 00071 00072 #include "NamespaceFooter.H" 00073 00074 #endif