00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011 #ifndef _INTVECT_H_
00012 #define _INTVECT_H_
00013
00014 #include <cstddef>
00015 #include <cstdlib>
00016 #include <cstring>
00017 #include <iostream>
00018 #include "SPACE.H"
00019 #include "Vector.H"
00020 #include "IndexTM.H"
00021 #include "Misc.H"
00022
00023 namespace BLfacade
00024 {
00025 class IntVect;
00026 }
00027
00028 #include "NamespaceHeader.H"
00029
00030
00031
00032
00033
00034 class HDF5Handle;
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 class IntVect
00046 {
00047 public:
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 IntVect()
00059 {}
00060
00061 explicit IntVect( const Vector<int>& vi)
00062 {
00063 D_EXPR6(vect[0]=vi[0], vect[1]=vi[1], vect[2] = vi[2],
00064 vect[3]=vi[3], vect[4]=vi[4], vect[5] = vi[5]);
00065 }
00066
00067
00068
00069
00070
00071 ~IntVect()
00072 {}
00073
00074
00075
00076
00077
00078
00079
00080 explicit IntVect (D_DECL6(int i, int j, int k,
00081 int l, int m, int n));
00082
00083
00084
00085
00086
00087
00088 explicit IntVect (const int* a);
00089
00090
00091
00092
00093
00094 IntVect (const IntVect& rhs);
00095
00096 IntVect (const IndexTM<int, CH_SPACEDIM>& a_tm);
00097
00098 IntVect copy() const
00099 {
00100 return *this;
00101 }
00102
00103
00104
00105
00106 IntVect& operator= (const IntVect& rhs);
00107
00108
00109
00110
00111
00112
00113 inline
00114 int& operator[] (int i);
00115
00116
00117
00118
00119
00120 inline
00121 int operator[] (int i) const;
00122
00123
00124
00125
00126
00127 void setVal (int i,
00128 int val);
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 const int* getVect () const;
00143
00144
00145
00146
00147
00148 const int* dataPtr() const;
00149
00150
00151
00152
00153
00154 int* dataPtr();
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 bool operator== (const IntVect& p) const;
00169
00170
00171
00172
00173
00174
00175 bool operator!= (const IntVect& p) const;
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 bool operator< (const IntVect& p) const;
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 bool operator<= (const IntVect& p) const;
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 bool operator> (const IntVect& p) const;
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 bool operator>= (const IntVect& p) const;
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 bool lexLT (const IntVect& s) const;
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 bool lexGT (const IntVect& s) const;
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 IntVect operator+ () const;
00262
00263
00264
00265
00266
00267 IntVect operator- () const;
00268
00269
00270
00271
00272
00273 int sum () const;
00274
00275
00276
00277
00278
00279 int product () const;
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292 IntVect& operator+= (int s);
00293
00294
00295
00296
00297
00298 IntVect& operator+= (const IntVect& p);
00299
00300
00301
00302
00303
00304 IntVect operator+ (const IntVect& p) const;
00305
00306
00307
00308
00309
00310
00311 IntVect operator+ (int s) const;
00312
00313
00314
00315
00316
00317
00318 friend inline IntVect operator+ (int s,
00319 const IntVect& p);
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 IntVect& operator-= (int s);
00334
00335
00336
00337
00338
00339 IntVect& operator-= (const IntVect& p);
00340
00341
00342
00343
00344
00345
00346 IntVect operator- (const IntVect& p) const;
00347
00348
00349
00350
00351
00352
00353 IntVect operator- (int s) const;
00354
00355
00356
00357
00358
00359 friend inline IntVect operator- (int s,
00360 const IntVect& p);
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374 IntVect& operator*= (int s);
00375
00376
00377
00378
00379
00380 IntVect& operator*= (const IntVect& p);
00381
00382
00383
00384
00385
00386 IntVect operator* (const IntVect& p) const;
00387
00388
00389
00390
00391
00392
00393 IntVect operator* (int s) const;
00394
00395
00396
00397
00398
00399
00400 friend inline IntVect operator* (int s,
00401 const IntVect& p);
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414 IntVect& operator/= (int s);
00415
00416
00417
00418
00419
00420
00421 IntVect& operator/= (const IntVect& p);
00422
00423
00424
00425
00426
00427 IntVect operator/ (const IntVect& p) const;
00428
00429
00430
00431
00432
00433
00434 IntVect operator/ (int s) const;
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448 IntVect& min (const IntVect& p);
00449
00450
00451
00452
00453
00454
00455 friend inline IntVect min (const IntVect& p1,
00456 const IntVect& p2);
00457
00458
00459
00460
00461
00462
00463 IntVect& max (const IntVect& p);
00464
00465
00466
00467
00468
00469
00470 friend inline IntVect max (const IntVect& p1,
00471 const IntVect& p2);
00472
00473
00474
00475
00476
00477 IntVect& scale (int s);
00478
00479
00480
00481
00482
00483
00484 friend inline IntVect scale (const IntVect& p,
00485 int s);
00486
00487
00488 friend const IntVect absolute(const IntVect& p);
00489
00490
00491
00492
00493
00494
00495
00496 IntVect& reflect (int ref_ix,
00497 int idir);
00498
00499
00500
00501
00502
00503
00504
00505 friend inline IntVect reflect(const IntVect& a,
00506 int ref_ix,
00507 int idir);
00508
00509
00510
00511
00512
00513
00514 IntVect& shift (int coord,
00515 int s);
00516
00517
00518
00519
00520
00521
00522 IntVect& shift (const IntVect& iv);
00523
00524
00525
00526
00527
00528
00529 IntVect& diagShift (int s);
00530
00531
00532
00533
00534
00535
00536 friend inline IntVect diagShift (const IntVect& p,
00537 int s);
00538
00539
00540
00541
00542
00543 IntVect& coarsen (const IntVect& p);
00544
00545
00546
00547
00548
00549 IntVect& coarsen (int p);
00550
00551
00552
00553
00554
00555
00556 friend inline IntVect coarsen (const IntVect& p,
00557 int s);
00558
00559
00560
00561
00562
00563
00564 friend inline IntVect coarsen (const IntVect& p1,
00565 const IntVect& p2);
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578 void printOn (std::ostream& os) const;
00579
00580
00581
00582
00583
00584 void p() const;
00585
00586
00587
00588
00589
00590 void dumpOn (std::ostream& os) const;
00591
00592
00593
00594
00595
00596 friend std::ostream& operator<< (std::ostream& os,
00597 const IntVect& iv);
00598
00599
00600
00601
00602
00603 friend std::istream& operator>> (std::istream& os,
00604 IntVect& iv);
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622 friend inline IntVect BASISV (int dir);
00623
00624
00625
00626
00627 static const IntVect Zero;
00628
00629
00630
00631
00632 static const IntVect Unit;
00633
00634
00635
00636
00637 static int InitStatics();
00638
00639
00640
00641 protected:
00642
00643
00644
00645 friend class Box;
00646
00647 friend class HDF5Handle;
00648 friend class VolIndex;
00649 friend class FaceIndex;
00650 friend class BLfacade::IntVect;
00651
00652
00653
00654
00655 int vect[SpaceDim];
00656
00657
00658
00659
00660 static const size_t IntVectSize;
00661 };
00662
00663
00664
00665
00666
00667
00668
00669
00670 static int s_dummyForIntVectH = IntVect::InitStatics();
00671
00672
00673 #ifndef WRAPPER
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686 inline
00687 IntVect::IntVect (D_DECL6(int i, int j, int k,
00688 int l, int m, int n))
00689 {
00690 D_EXPR6(vect[0] = i, vect[1] = j, vect[2] = k, vect[3] = l, vect[4] = m, vect[5] = n);
00691 }
00692
00693 inline
00694 IntVect::IntVect (const int *a)
00695 {
00696 D_EXPR6(vect[0] = a[0], vect[1] = a[1], vect[2] = a[2],
00697 vect[3] = a[3], vect[4] = a[4], vect[5] = a[5]);
00698 }
00699
00700 inline
00701 IntVect::IntVect (const IntVect &iv)
00702 {
00703
00704 memcpy(vect, iv.vect, IntVectSize);
00705 }
00706
00707 inline
00708 IntVect&
00709 IntVect::operator= (const IntVect &iv)
00710 {
00711 D_EXPR6(vect[0]=iv.vect[0], vect[1]=iv.vect[1], vect[2]=iv.vect[2],
00712 vect[3]=iv.vect[3], vect[4]=iv.vect[4], vect[5]=iv.vect[5]);
00713 return *this;
00714 }
00715
00716 inline
00717 int&
00718 IntVect::operator[] (int i)
00719 {
00720 CH_assert(i>=0 && i < SpaceDim);
00721 return vect[i];
00722 }
00723
00724 inline
00725 int
00726 IntVect::operator[] (int i) const
00727 {
00728 CH_assert(i>=0 && i < SpaceDim);
00729 return vect[i];
00730 }
00731
00732 inline
00733 void
00734 IntVect::setVal (int i,
00735 int val)
00736 {
00737 CH_assert(i >=0 && i < SpaceDim);
00738 vect[i] = val;
00739
00740 }
00741
00742 inline
00743 const int*
00744 IntVect::dataPtr() const
00745 {
00746 return vect;
00747 }
00748
00749 inline
00750 int*
00751 IntVect::dataPtr()
00752 {
00753 return vect;
00754 }
00755
00756 inline
00757 const int*
00758 IntVect::getVect () const
00759 {
00760 return vect;
00761 }
00762
00763 inline
00764 bool
00765 IntVect::operator== (const IntVect& p) const
00766 {
00767 return D_TERM6(vect[0] == p[0], && vect[1] == p[1], && vect[2] == p[2],
00768 && vect[3] == p[3], && vect[4] == p[4], && vect[5] == p[5]);
00769 }
00770
00771 inline
00772 bool
00773 IntVect::operator!= (const IntVect& p) const
00774 {
00775 return D_TERM6(vect[0] != p[0], || vect[1] != p[1], || vect[2] != p[2],
00776 || vect[3] != p[3], || vect[4] != p[4], || vect[5] != p[5]);
00777 }
00778
00779 inline
00780 bool
00781 IntVect::operator< (const IntVect& p) const
00782 {
00783 return D_TERM6(vect[0] < p[0], && vect[1] < p[1], && vect[2] < p[2],
00784 && vect[3] < p[3], && vect[4] < p[4], && vect[5] < p[5]);
00785 }
00786
00787 inline
00788 bool
00789 IntVect::operator<= (const IntVect& p) const
00790 {
00791 return D_TERM6(vect[0] <= p[0], && vect[1] <= p[1], && vect[2] <= p[2],
00792 && vect[3] <= p[3], && vect[4] <= p[4], && vect[5] <= p[5]);
00793 }
00794
00795
00796 inline
00797 bool
00798 IntVect::operator> (const IntVect& p) const
00799 {
00800 return D_TERM6(vect[0] > p[0], && vect[1] > p[1], && vect[2] > p[2],
00801 && vect[3] > p[3], && vect[4] > p[4], && vect[5] > p[5]);
00802 }
00803
00804 inline
00805 bool
00806 IntVect::operator>= (const IntVect& p) const
00807 {
00808 return D_TERM6(vect[0] >= p[0], && vect[1] >= p[1], && vect[2] >= p[2],
00809 && vect[3] >= p[3], && vect[4] >= p[4], && vect[5] >= p[5]);
00810 }
00811
00812 inline
00813 bool
00814 IntVect::lexLT (const IntVect &s) const
00815
00816 {
00817 if (vect[0] < s[0]) return true;
00818 #if CH_SPACEDIM > 1
00819 if (vect[0] > s[0]) return false;
00820 if (vect[1] < s[1]) return true;
00821 #endif
00822 #if CH_SPACEDIM > 2
00823 if (vect[1] > s[1]) return false;
00824 if (vect[2] < s[2]) return true;
00825 #endif
00826 #if CH_SPACEDIM > 3
00827 if (vect[2] > s[2]) return false;
00828 if (vect[3] < s[3]) return true;
00829 #endif
00830 #if CH_SPACEDIM > 4
00831 if (vect[3] > s[3]) return false;
00832 if (vect[4] < s[4]) return true;
00833 #endif
00834 #if CH_SPACEDIM > 5
00835 if (vect[4] > s[4]) return false;
00836 if (vect[5] < s[5]) return true;
00837 #endif
00838
00839 return false;
00840 }
00841
00842
00843 inline
00844 bool
00845 IntVect::lexGT (const IntVect& s) const
00846 {
00847 if (vect[0] > s[0]) return true;
00848 #if CH_SPACEDIM > 1
00849 if (vect[0] < s[0]) return false;
00850 if (vect[1] > s[1]) return true;
00851 #endif
00852 #if CH_SPACEDIM > 2
00853 if (vect[1] < s[1]) return false;
00854 if (vect[2] > s[2]) return true;
00855 #endif
00856 #if CH_SPACEDIM > 3
00857 if (vect[2] < s[2]) return false;
00858 if (vect[3] > s[3]) return true;
00859 #endif
00860 #if CH_SPACEDIM > 4
00861 if (vect[3] < s[3]) return false;
00862 if (vect[4] > s[4]) return true;
00863 #endif
00864 #if CH_SPACEDIM > 5
00865 if (vect[4] < s[4]) return false;
00866 if (vect[5] > s[5]) return true;
00867 #endif
00868
00869 return false;
00870 }
00871
00872 inline
00873 IntVect
00874 IntVect::operator+ () const
00875 {
00876 return IntVect(*this);
00877 }
00878
00879 inline
00880 IntVect
00881 IntVect::operator- () const
00882 {
00883 return IntVect(D_DECL6(-vect[0], -vect[1], -vect[2],
00884 -vect[3], -vect[4], -vect[5] ));
00885 }
00886
00887 inline
00888 int
00889 IntVect::sum () const
00890 {
00891 return D_TERM6(vect[0], + vect[1], + vect[2],
00892 + vect[3], + vect[4], + vect[5]);
00893 }
00894
00895 inline
00896 int
00897 IntVect::product () const
00898 {
00899 return D_TERM6(vect[0], * vect[1], * vect[2],
00900 * vect[3], * vect[4], * vect[5]);
00901 }
00902
00903 inline
00904 IntVect&
00905 IntVect::operator+= (int s)
00906 {
00907 D_EXPR6(vect[0] += s, vect[1] += s, vect[2] += s,
00908 vect[3] += s, vect[4] += s, vect[5] += s);
00909 return *this;
00910 }
00911
00912 inline
00913 IntVect&
00914 IntVect::operator+= (const IntVect& p)
00915 {
00916 D_EXPR6(vect[0] += p[0], vect[1] += p[1], vect[2] += p[2],
00917 vect[3] += p[3], vect[4] += p[4], vect[5] += p[5]);
00918 return *this;
00919 }
00920
00921 inline
00922 IntVect&
00923 IntVect::operator*= (int s)
00924 {
00925 D_EXPR6(vect[0] *= s, vect[1] *= s, vect[2] *= s,
00926 vect[3] *= s, vect[4] *= s, vect[5] *= s);
00927 return *this;
00928 }
00929
00930 inline
00931 IntVect&
00932 IntVect::operator*= (const IntVect &p)
00933 {
00934 D_EXPR6(vect[0] *= p[0], vect[1] *= p[1], vect[2] *= p[2],
00935 vect[3] *= p[3], vect[4] *= p[4], vect[5] *= p[5]);
00936 return *this;
00937 }
00938
00939 inline
00940 IntVect&
00941 IntVect::operator/= (int s)
00942 {
00943 D_EXPR6(vect[0] /= s, vect[1] /= s, vect[2] /= s,
00944 vect[3] /= s, vect[4] /= s, vect[5] /= s);
00945 return *this;
00946 }
00947
00948 inline
00949 IntVect&
00950 IntVect::operator/= (const IntVect& p)
00951 {
00952 D_EXPR6(vect[0] /= p[0], vect[1] /= p[1], vect[2] /= p[2],
00953 vect[3] /= p[3], vect[4] /= p[4], vect[5] /= p[5]);
00954 return *this;
00955 }
00956
00957 inline
00958 IntVect&
00959 IntVect::operator-= (int s)
00960 {
00961 D_EXPR6(vect[0] -= s, vect[1] -= s, vect[2] -= s,
00962 vect[3] -= s, vect[4] -= s, vect[5] -= s);
00963 return *this;
00964 }
00965
00966 inline
00967 IntVect&
00968 IntVect::operator-= (const IntVect& p)
00969 {
00970 D_EXPR6(vect[0] -= p[0], vect[1] -= p[1], vect[2] -= p[2],
00971 vect[3] -= p[3], vect[4] -= p[4], vect[5] -= p[5]);
00972 return *this;
00973 }
00974
00975 inline
00976 IntVect
00977 IntVect::operator+ (const IntVect& p) const
00978 {
00979 return IntVect(D_DECL6(vect[0] + p[0], vect[1] + p[1], vect[2] + p[2],
00980 vect[3] + p[3], vect[4] + p[4], vect[5] + p[5]));
00981 }
00982
00983 inline
00984 IntVect
00985 IntVect::operator+ (int s) const
00986 {
00987 return IntVect(D_DECL6(vect[0] + s, vect[1] + s, vect[2] + s,
00988 vect[3] + s, vect[4] + s, vect[5] + s));
00989 }
00990
00991 inline
00992 IntVect
00993 IntVect::operator- (const IntVect& p) const
00994 {
00995 return IntVect(D_DECL6(vect[0] - p[0], vect[1] - p[1], vect[2] - p[2],
00996 vect[3] - p[3], vect[4] - p[4], vect[5] - p[5]));
00997 }
00998
00999 inline
01000 IntVect
01001 IntVect::operator- (int s) const
01002 {
01003 return IntVect(D_DECL6(vect[0] - s, vect[1] - s, vect[2] - s,
01004 vect[3] - s, vect[4] - s, vect[5] - s));
01005 }
01006
01007 inline
01008 IntVect
01009 IntVect::operator* (const IntVect& p) const
01010 {
01011 return IntVect(D_DECL6(vect[0] * p[0], vect[1] * p[1], vect[2] * p[2],
01012 vect[3] * p[3], vect[4] * p[4], vect[5] * p[5]));
01013 }
01014
01015 inline
01016 IntVect
01017 IntVect::operator* (int s) const
01018 {
01019 return IntVect(D_DECL6(vect[0] * s, vect[1] * s, vect[2] * s,
01020 vect[3] * s, vect[4] * s, vect[5] * s));
01021 }
01022
01023 inline
01024 IntVect
01025 IntVect::operator/ (const IntVect& p) const
01026 {
01027 return IntVect(D_DECL6(vect[0] / p[0], vect[1] / p[1], vect[2] / p[2],
01028 vect[3] / p[3], vect[4] / p[4], vect[5] / p[5]));
01029 }
01030
01031 inline
01032 IntVect
01033 IntVect::operator/ (int s) const
01034 {
01035 return IntVect(D_DECL6(vect[0] / s, vect[1] / s, vect[2] / s,
01036 vect[3] / s, vect[4] / s, vect[5] / s));
01037 }
01038
01039 inline
01040 IntVect&
01041 IntVect::min (const IntVect& p)
01042 {
01043 D_EXPR6(vect[0] = Min(vect[0], p.vect[0]),
01044 vect[1] = Min(vect[1], p.vect[1]),
01045 vect[2] = Min(vect[2], p.vect[2]),
01046 vect[3] = Min(vect[3], p.vect[3]),
01047 vect[4] = Min(vect[4], p.vect[4]),
01048 vect[5] = Min(vect[5], p.vect[5]));
01049 return *this;
01050 }
01051
01052 inline
01053 IntVect&
01054 IntVect::max (const IntVect& p)
01055 {
01056 D_EXPR6(vect[0] = Max(vect[0], p.vect[0]),
01057 vect[1] = Max(vect[1], p.vect[1]),
01058 vect[2] = Max(vect[2], p.vect[2]),
01059 vect[3] = Max(vect[3], p.vect[3]),
01060 vect[4] = Max(vect[4], p.vect[4]),
01061 vect[5] = Max(vect[5], p.vect[5]));
01062 return *this;
01063 }
01064
01065 inline
01066 IntVect&
01067 IntVect::scale (int s)
01068 {
01069 D_EXPR6(vect[0] *= s, vect[1] *= s, vect[2] *= s,
01070 vect[3] *= s, vect[4] *= s, vect[5] *= s);
01071 return *this;
01072 }
01073
01074 inline
01075 IntVect&
01076 IntVect::reflect (int ref_ix,
01077 int idir)
01078 {
01079 CH_assert(idir >= 0 && idir < SpaceDim);
01080 vect[idir] = -vect[idir] + 2*ref_ix;
01081 return *this;
01082 }
01083
01084 inline
01085 IntVect&
01086 IntVect::shift (int coord,
01087 int s)
01088 {
01089 CH_assert(coord >= 0 && coord < SpaceDim);
01090 vect[coord] += s;
01091 return *this;
01092 }
01093
01094 inline
01095 IntVect&
01096 IntVect::shift (const IntVect& iv)
01097 {
01098 *this += iv;
01099 return *this;
01100 }
01101
01102 inline
01103 IntVect&
01104 IntVect::diagShift (int s)
01105 {
01106 D_EXPR6(vect[0] += s, vect[1] += s, vect[2] += s,
01107 vect[3] += s, vect[4] += s, vect[5] += s);
01108 return *this;
01109 }
01110
01111 inline
01112 IntVect
01113 operator+ (int s,
01114 const IntVect& p)
01115 {
01116 return IntVect(D_DECL6(p[0] + s, p[1] + s, p[2] + s,
01117 p[3] + s, p[4] + s, p[5] + s));
01118 }
01119
01120 inline
01121 IntVect
01122 operator- (int s,
01123 const IntVect& p)
01124 {
01125 return IntVect(D_DECL6(s - p[0], s - p[1], s - p[2],
01126 s - p[3], s - p[4], s - p[5]));
01127 }
01128
01129 inline
01130 IntVect
01131 operator* (int s,
01132 const IntVect& p)
01133 {
01134 return IntVect(D_DECL6(s * p[0], s * p[1], s * p[2],
01135 s * p[3], s * p[4], s * p[5]));
01136 }
01137
01138 inline
01139 IntVect
01140 scale (const IntVect& p,
01141 int s)
01142 {
01143 return IntVect(D_DECL6(s * p[0], s * p[1], s * p[2],
01144 s * p[3], s * p[4], s * p[5]));
01145 }
01146
01147 inline
01148 const IntVect
01149 absolute (const IntVect& p)
01150 {
01151 return IntVect(D_DECL6(abs(p[0]), abs(p[1]), abs(p[2]),
01152 abs(p[3]), abs(p[4]), abs(p[5])));
01153 }
01154
01155 inline
01156 IntVect
01157 diagShift (const IntVect &p, int s)
01158 {
01159 return IntVect(D_DECL6(p[0] + s, p[1] + s, p[2] + s,
01160 p[3] + s, p[4] + s, p[5] + s));
01161 }
01162
01163 inline
01164 IntVect
01165 min (const IntVect& p1,
01166 const IntVect& p2)
01167 {
01168 IntVect p(p1);
01169 return p.min(p2);
01170 }
01171
01172 inline
01173 IntVect
01174 max (const IntVect& p1,
01175 const IntVect& p2)
01176 {
01177 IntVect p(p1);
01178 return p.max(p2);
01179 }
01180
01181 inline
01182 IntVect
01183 BASISV (int dir)
01184 {
01185 CH_assert(dir >= 0 && dir < SpaceDim);
01186 IntVect tmp = IntVect::Zero ;
01187 tmp.vect[dir] = 1;
01188 return tmp;
01189 }
01190
01191 inline
01192 IntVect
01193 reflect (const IntVect& a,
01194 int ref_ix,
01195 int idir)
01196 {
01197 CH_assert(idir >= 0 && idir < SpaceDim);
01198 IntVect b(a);
01199 b.vect[idir] = -b.vect[idir] + 2*ref_ix;
01200 return b;
01201 }
01202
01203 inline
01204 IntVect
01205 coarsen (const IntVect& p,
01206 int s)
01207 {
01208 CH_assert(s > 0);
01209 return IntVect(
01210 D_DECL6((p.vect[0]<0) ? -abs(p.vect[0]+1)/s-1 : p.vect[0]/s ,
01211 (p.vect[1]<0) ? -abs(p.vect[1]+1)/s-1 : p.vect[1]/s ,
01212 (p.vect[2]<0) ? -abs(p.vect[2]+1)/s-1 : p.vect[2]/s ,
01213 (p.vect[3]<0) ? -abs(p.vect[3]+1)/s-1 : p.vect[3]/s ,
01214 (p.vect[4]<0) ? -abs(p.vect[4]+1)/s-1 : p.vect[4]/s ,
01215 (p.vect[5]<0) ? -abs(p.vect[5]+1)/s-1 : p.vect[5]/s ));
01216 }
01217
01218 inline
01219 IntVect
01220 coarsen (const IntVect& p1,
01221 const IntVect& p2)
01222 {
01223 CH_assert(p2 > IntVect::Zero);
01224 return IntVect(
01225 D_DECL6(
01226 (p1.vect[0]<0)?-abs(p1.vect[0]+1)/p2.vect[0]-1:p1.vect[0]/p2.vect[0],
01227 (p1.vect[1]<0)?-abs(p1.vect[1]+1)/p2.vect[1]-1:p1.vect[1]/p2.vect[1],
01228 (p1.vect[2]<0)?-abs(p1.vect[2]+1)/p2.vect[2]-1:p1.vect[2]/p2.vect[2],
01229 (p1.vect[3]<0)?-abs(p1.vect[3]+1)/p2.vect[3]-1:p1.vect[3]/p2.vect[3],
01230 (p1.vect[4]<0)?-abs(p1.vect[4]+1)/p2.vect[4]-1:p1.vect[4]/p2.vect[4],
01231 (p1.vect[5]<0)?-abs(p1.vect[5]+1)/p2.vect[5]-1:p1.vect[5]/p2.vect[5])
01232 );
01233 }
01234
01235 inline
01236 IntVect&
01237 IntVect::coarsen (int s)
01238 {
01239 CH_assert(s > 0);
01240 for (int i = 0; i < SpaceDim; ++i)
01241 vect[i] = ((vect[i]<0) ? -abs(vect[i]+1)/s-1 : vect[i]/s);
01242 return *this;
01243 }
01244
01245 inline
01246 IntVect&
01247 IntVect::coarsen (const IntVect& p)
01248 {
01249 CH_assert(p > IntVect::Zero);
01250 for (int i = 0; i <SpaceDim; ++i)
01251 {
01252 const int s = p.vect[i];
01253 vect[i] = ((vect[i]<0) ? -abs(vect[i]+1)/s-1 : vect[i]/s);
01254 }
01255 return *this;
01256 }
01257
01258 #endif
01259
01260 #include "NamespaceFooter.H"
01261 #endif