00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011 #ifndef _INDICESTRANSFORMATION_H_
00012 #define _INDICESTRANSFORMATION_H_
00013
00014 #include <iostream>
00015 #include "IntVect.H"
00016 #include "RealVect.H"
00017 #include "BaseFab.H"
00018 #include "Tuple.H"
00019 #include "IndicesFunctions.H"
00020
00021 #include "NamespaceHeader.H"
00022
00023
00024
00025 class IndicesTransformation
00026 {
00027 public:
00028
00029
00030 IndicesTransformation();
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 IndicesTransformation(const IntVect& a_permutation,
00043 const IntVect& a_sign,
00044 const IntVect& a_translation);
00045
00046
00047
00048
00049
00050 void define(const IntVect& a_permutation,
00051 const IntVect& a_sign,
00052 const IntVect& a_translation);
00053
00054
00055
00056
00057
00058
00059 void defineFromSwap(int a_ind1,
00060 int a_ind2);
00061
00062
00063
00064
00065
00066 void defineFromTranslation(const IntVect& a_translation);
00067
00068
00069
00070
00071
00072
00073
00074
00075 void defineFromPivot(const IntVect& a_pivotOld,
00076 const IntVect& a_pivotNew,
00077 const IntVect& a_permutation,
00078 const IntVect& a_sign);
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 void defineFromFaces(const Box& a_srcBox,
00089 int a_srcDim,
00090 Side::LoHiSide a_srcSide,
00091 const Box& a_dstBox,
00092 int a_dstDim,
00093 Side::LoHiSide a_dstSide,
00094 const IntVect& a_sign = IntVect::Unit);
00095
00096
00097
00098
00099
00100 bool isDefined() const;
00101
00102 bool operator==(const IndicesTransformation& a_itOther) const;
00103
00104 bool operator!=(const IndicesTransformation& a_itOther) const;
00105
00106 friend std::ostream& operator<< (std::ostream& a_os,
00107 const IndicesTransformation& a_it);
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 IntVect transformFwd(const IntVect& a_ivOld) const;
00121
00122 IntVect transformBack(const IntVect& a_ivNew) const;
00123
00124 IntVect transform(const IntVect& a_iv, bool a_forward = true) const;
00125
00126
00127
00128
00129
00130 IntVect transformNode(const IntVect& a_iv) const;
00131
00132
00133
00134
00135
00136 RealVect transformMapped(const RealVect& a_pointOld,
00137 const RealVect& a_dxOld,
00138 const RealVect& a_dxNew) const;
00139
00140
00141
00142
00143
00144
00145 IntVect transformVectorFwd(const IntVect& a_vecOld) const;
00146
00147 IntVect transformVectorBack(const IntVect& a_vecNew) const;
00148
00149 IntVect transformVector(const IntVect& a_vec, bool a_forward = true) const;
00150
00151
00152
00153
00154
00155 IntVect transformWithType(const IntVect& a_iv,
00156 const IntVect& a_tp,
00157 bool a_forward = true) const;
00158
00159
00160
00161
00162
00163
00164
00165 IntVect transformType(const IntVect& a_tp, bool a_forward = true) const;
00166
00167
00168
00169
00170
00171 Box transformFwd(const Box& a_bxOld) const;
00172
00173 Box transformBack(const Box& a_bxNew) const;
00174
00175 Box transform(const Box& a_bx, bool a_forward = true) const;
00176
00177
00178
00179
00180
00181 template<typename T> void transformFwd(BaseFab<T>& a_dstFab,
00182 const BaseFab<T>& a_srcFab,
00183 const Box& a_srcBox,
00184 const Interval& a_dstIntvl,
00185 const Interval& a_srcIntvl) const
00186 {
00187 transform(a_dstFab, a_srcFab, a_srcBox,
00188 a_dstIntvl, a_srcIntvl, true);
00189 }
00190
00191
00192
00193
00194
00195 template<typename T> void transformBack(BaseFab<T>& a_dstFab,
00196 const BaseFab<T>& a_srcFab,
00197 const Box& a_srcBox,
00198 const Interval& a_dstIntvl,
00199 const Interval& a_srcIntvl) const
00200 {
00201 transform(a_dstFab, a_srcFab, a_srcBox,
00202 a_dstIntvl, a_srcIntvl, false);
00203 }
00204
00205
00206
00207
00208
00209 template<typename T> void transform(BaseFab<T>& a_dstFab,
00210 const BaseFab<T>& a_srcFab,
00211 const Box& a_srcBox,
00212 const Interval& a_dstIntvl,
00213 const Interval& a_srcIntvl,
00214 bool a_forward = true) const
00215 {
00216 #if 0
00217 CH_assert(a_srcFab.box().contains(a_srcBox));
00218 Box transformedBox = transform(a_srcBox, a_forward);
00219 CH_assert(a_dstFab.box().contains(transformedBox));
00220 IntVect tp = a_srcBox.type();
00221 int dstComp = a_dstIntvl.begin();
00222 int srcComp = a_srcIntvl.begin();
00223 int srcCompHi = a_srcIntvl.end();
00224 for (; srcComp <= srcCompHi; ++srcComp, ++dstComp)
00225 {
00226 for (BoxIterator bit(a_srcBox); bit.ok(); ++bit)
00227 {
00228 IntVect ivSrc = bit();
00229 IntVect ivDst = transformWithType(ivSrc, tp, a_forward);
00230 a_dstFab(ivDst, dstComp) =
00231 a_srcFab(ivSrc, srcComp);
00232 }
00233 }
00234 #else
00235
00236
00237 if (a_dstIntvl.size() == 0)
00238 {
00239 return;
00240 }
00241 if (a_srcBox.isEmpty())
00242 {
00243 return;
00244 }
00245 CH_assert(a_dstIntvl.size() == a_srcIntvl.size());
00246
00247 const Box& dstAllBox = a_dstFab.box();
00248 const Box& srcAllBox = a_srcFab.box();
00249 const IntVect& srcAllDims = srcAllBox.size();
00250 CH_assert(srcAllBox.contains(a_srcBox));
00251 const IntVect& srcType = a_srcBox.type();
00252
00253 Box dstSetBox = transform(a_srcBox, a_forward);
00254
00255 CH_assert(dstAllBox.contains(dstSetBox));
00256 const IntVect& srcSetLo = a_srcBox.smallEnd();
00257 const IntVect& srcSetDims = a_srcBox.size();
00258 IntVect dstSetLo = transformWithType(srcSetLo, srcType, a_forward);
00259 const size_t dstIndexLo =
00260 FortranArrayIndex(dstSetLo, dstAllBox);
00261 const size_t srcIndexLo =
00262 FortranArrayIndex(srcSetLo, srcAllBox);
00263
00264 Tuple<long long int, SpaceDim> srcInc, dstInc, srcAllInc;
00265 for (int idir = 0; idir < SpaceDim; idir++)
00266 {
00267 IntVect src1dir = srcSetLo + BASISV(idir);
00268 IntVect dst1dir = transformWithType(src1dir, srcType, a_forward);
00269 if ( ! (dstAllBox.contains(dst1dir)) )
00270 {
00271
00272 dstInc[idir] = 0;
00273 }
00274 else
00275 {
00276 size_t dstIndex1dirAll =
00277 FortranArrayIndex(dst1dir, dstAllBox);
00278
00279 if (dstIndex1dirAll >= dstIndexLo)
00280 {
00281 dstInc[idir] = dstIndex1dirAll - dstIndexLo;
00282 }
00283 else
00284 {
00285 dstInc[idir] = -(dstIndexLo - dstIndex1dirAll);
00286 }
00287 }
00288
00289 srcInc[idir] =
00290 FortranArrayIndex(BASISV(idir), srcAllDims);
00291 srcAllInc[idir] = srcInc[idir] * srcSetDims[idir];
00292 }
00293
00294 Tuple<size_t, SpaceDim> srcBegin, dstBegin, srcEnd;
00295 srcBegin[CH_SPACEDIM-1] = srcIndexLo;
00296 dstBegin[CH_SPACEDIM-1] = dstIndexLo;
00297
00298 size_t srcIndex, dstIndex;
00299
00300 for (int srcComp = a_srcIntvl.begin(), dstComp = a_dstIntvl.begin();
00301 srcComp <= a_srcIntvl.end();
00302 ++srcComp, ++dstComp)
00303 {
00304 Interval src1Intvl(srcComp, srcComp);
00305 Interval dst1Intvl(dstComp, dstComp);
00306 BaseFab<T> dst1Fab(dst1Intvl, a_dstFab);
00307 const BaseFab<T> src1Fab(src1Intvl, const_cast<BaseFab<T>&>(a_srcFab));
00308
00309 const T* src1Array = src1Fab.dataPtr();
00310 T* dst1Array = dst1Fab.dataPtr();
00311
00312 #if CH_SPACEDIM>5
00313 srcEnd[5] = srcBegin[5] + srcAllInc[5];
00314 for (srcBegin[4] = srcBegin[5], dstBegin[4] = dstBegin[5];
00315 srcBegin[4] < srcEnd[5];
00316 srcBegin[4] += srcInc[5], dstBegin[4] += dstInc[5])
00317 {
00318 #endif
00319 #if CH_SPACEDIM>4
00320 srcEnd[4] = srcBegin[4] + srcAllInc[4];
00321 for (srcBegin[3] = srcBegin[4], dstBegin[3] = dstBegin[4];
00322 srcBegin[3] < srcEnd[4];
00323 srcBegin[3] += srcInc[4], dstBegin[3] += dstInc[4])
00324 {
00325 #endif
00326 #if CH_SPACEDIM>3
00327 srcEnd[3] = srcBegin[3] + srcAllInc[3];
00328 for (srcBegin[2] = srcBegin[3], dstBegin[2] = dstBegin[3];
00329 srcBegin[2] < srcEnd[3];
00330 srcBegin[2] += srcInc[3], dstBegin[2] += dstInc[3])
00331 {
00332 #endif
00333 #if CH_SPACEDIM>2
00334 srcEnd[2] = srcBegin[2] + srcAllInc[2];
00335 for (srcBegin[1] = srcBegin[2], dstBegin[1] = dstBegin[2];
00336 srcBegin[1] < srcEnd[2];
00337 srcBegin[1] += srcInc[2], dstBegin[1] += dstInc[2])
00338 {
00339 #endif
00340 #if CH_SPACEDIM>1
00341 srcEnd[1] = srcBegin[1] + srcAllInc[1];
00342 for (srcBegin[0] = srcBegin[1], dstBegin[0] = dstBegin[1];
00343 srcBegin[0] < srcEnd[1];
00344 srcBegin[0] += srcInc[1], dstBegin[0] += dstInc[1])
00345 {
00346 #endif
00347 srcEnd[0] = srcBegin[0] + srcAllInc[0];
00348 for (srcIndex = srcBegin[0], dstIndex = dstBegin[0];
00349 srcIndex < srcEnd[0];
00350 srcIndex += srcInc[0], dstIndex += dstInc[0])
00351 {
00352 #ifndef NDEBUG
00353
00354
00355 CH_assert(srcIndex < srcAllBox.numPts());
00356 CH_assert(dstIndex < dstAllBox.numPts());
00357 #endif
00358 dst1Array[dstIndex] = src1Array[srcIndex];
00359 }
00360 #if CH_SPACEDIM>1
00361 }
00362 #endif
00363 #if CH_SPACEDIM>2
00364 }
00365 #endif
00366 #if CH_SPACEDIM>3
00367 }
00368 #endif
00369 #if CH_SPACEDIM>4
00370 }
00371 #endif
00372 #if CH_SPACEDIM>5
00373 }
00374 #endif
00375 }
00376 #endif
00377 }
00378
00379
00380
00381
00382
00383 IndicesTransformation inverse() const;
00384
00385
00386
00387
00388
00389
00390 IndicesTransformation compose(const IndicesTransformation& a_next) const;
00391
00392
00393
00394
00395
00396 IndicesTransformation coarsen(int a_refRatio) const;
00397
00398
00399
00400
00401
00402 IndicesTransformation refine(int a_refRatio) const;
00403
00404 static const IntVect NoPermutation;
00405
00406
00407
00408
00409
00410 static const IndicesTransformation Identity;
00411
00412
00413
00414
00415 static const IndicesTransformation Undefined;
00416
00417 IntVect getPermutation() const
00418 {
00419 return m_permutation;
00420 }
00421 IntVect getSign() const
00422 {
00423 return m_sign;
00424 }
00425 IntVect getTranslation() const
00426 {
00427 return m_translation;
00428 }
00429
00430
00431
00432
00433 static int InitStatics();
00434
00435 protected:
00436
00437
00438 IntVect m_permutation;
00439
00440
00441 IntVect m_sign;
00442
00443
00444 IntVect m_translation;
00445 };
00446
00447
00448
00449
00450
00451
00452
00453
00454 static int s_dummyForIndicesTransformationH = IndicesTransformation::InitStatics();
00455
00456 #include "NamespaceFooter.H"
00457
00458 #endif // include guard