Blockstructured Adaptive Mesh Refinement in object-oriented C++
00001 #ifndef _included_IndexGridData2_h
00002 #define _included_IndexGridData2_h
00003
00010 #include <generic.h>
00011
00012 /*
00013 *************************************************************************
00014 * *
00015 * Define some looping constructs for GridData. Note that these will *
00016 * take either an array or a region as the second argument. *
00017 * *
00018 * Copy the region extents into a local constant integer to aid the *
00019 * compiler in doing some loop optimizations. *
00020 * *
00021 *************************************************************************
00022 */
00023
00024 #ifndef for_2
00025 #define for_2(i, j, r, s) { \
00026 const int name2(j,_L) = (((r).lower(1)+((r).lower(1)<0?-s(1)+1:s(1)-1))/s(1))*s(1); \
00027 const int name2(j,_U) = (r).upper(1); \
00028 const int name2(i,_L) = (((r).lower(0)+((r).lower(0)<0?-s(0)+1:s(0)-1))/s(0))*s(0); \
00029 const int name2(i,_U) = (r).upper(0); \
00030 const int name2(sj,_S) = (s(1)); \
00031 const int name2(si,_S) = (s(0)); \
00032 for (register int j = name2(j,_L); j <= name2(j,_U); j+=name2(sj,_S)) \
00033 for (register int i = name2(i,_L); i <= name2(i,_U); i+=name2(si,_S)) {
00034 #endif
00035
00036 #ifndef end_for
00037 #define end_for } }
00038 #endif
00039
00040 /*
00041 *************************************************************************
00042 * *
00043 * These macros provide simple access to ``fast indexing'' from C++. *
00044 * Current C++ compilers do not do a good job of optimizing C++ loops *
00045 * with array access. Using these macros should speed up loops by a *
00046 * factor of about three. Note that we still use the Fortran indexing *
00047 * convention. *
00048 * *
00049 * These macros should be used as follows: *
00050 * *
00051 * BeginFastIndex2(a, double); *
00052 * for_2(i, j, a) *
00053 * FastIndex2(a, i, j) = 0.0; *
00054 * end_for *
00055 * EndFastIndex2(a); *
00056 * *
00057 *************************************************************************
00058 */
00059
00060 #ifndef BeginFastIndex2
00061 #define BeginFastIndex2(a, b, d, type) { \
00062 const int name2(a,_B) = b.bottom(); \
00063 type *const name2(a,_D) = d; \
00064 const int name2(a,_e0) = b.extents(0); \
00065 const int name2(a,_s0) = b.stepsize(0); \
00066 const int name2(a,_s1) = b.stepsize(1)
00067 #define FastIndex2(a, i, j) \
00068 name2(a,_D)[name2(a,_B)+((i)/name2(a,_s0))+name2(a,_e0)*((j)/name2(a,_s1))]
00069 #define EndFastIndex2(a) }
00070 #endif
00071
00072 #endif
Quickstart Users Guide Programmers Reference Installation Examples Download
AMROC Main Home Contactlast update: 06/01/04