00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011 #ifndef _BOX_H_
00012 #define _BOX_H_
00013
00014 #ifdef NODEV
00015 #undef NODEV
00016 #endif
00017
00018 #include "SPACE.H"
00019
00020 #ifndef WRAPPER
00021 #include <iostream>
00022
00023 #include "IntVect.H"
00024 #include "Misc.H"
00025 #include "LoHiSide.H"
00026 #include "Vector.H"
00027 #include "SPMD.H"
00028 #include "NamespaceHeader.H"
00029
00030 class SliceSpec;
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 class IndexType
00042 {
00043 public:
00044
00045
00046
00047
00048
00049 enum CellIndex
00050 {
00051 CELL = 0,
00052 NODE = 1
00053 };
00054
00055
00056
00057
00058
00059
00060 IndexType ();
00061
00062
00063
00064
00065
00066
00067 IndexType (const IndexType& rhs);
00068
00069
00070
00071
00072
00073
00074 explicit IndexType (const IntVect& iv);
00075
00076
00077
00078
00079
00080
00081 IndexType& operator= (const IndexType& rhs);
00082
00083
00084
00085
00086
00087
00088 IndexType& operator= (const IntVect& iv);
00089
00090
00091
00092
00093
00094
00095
00096
00097 IndexType (D_DECL6(CellIndex i, CellIndex j, CellIndex k,
00098 CellIndex l, CellIndex m, CellIndex n));
00099
00100
00101
00102
00103
00104
00105 void set (int dir);
00106
00107
00108
00109
00110
00111
00112 void unset (int dir);
00113
00114
00115
00116
00117
00118
00119 bool test (int dir) const;
00120
00121
00122
00123
00124
00125
00126 void setall ();
00127
00128
00129
00130
00131
00132
00133 void clear ();
00134
00135
00136
00137
00138
00139
00140 bool any () const;
00141
00142
00143
00144
00145
00146
00147 bool ok () const;
00148
00149
00150
00151
00152
00153
00154
00155 void flip (int i);
00156
00157
00158
00159
00160
00161
00162 bool operator== (const IndexType& t) const;
00163
00164
00165
00166
00167
00168 bool operator<(const IndexType& t) const;
00169
00170
00171
00172
00173
00174
00175 bool operator!= (const IndexType& t) const;
00176
00177
00178
00179
00180
00181
00182 bool cellCentered () const;
00183
00184
00185
00186
00187
00188
00189 bool nodeCentered () const;
00190
00191
00192
00193
00194
00195
00196 void setType (int dir,
00197 CellIndex t);
00198
00199
00200
00201
00202
00203
00204 CellIndex ixType (int dir) const;
00205
00206
00207
00208
00209
00210
00211 int operator[] (int dir) const;
00212
00213
00214
00215
00216
00217
00218
00219 IntVect ixType () const;
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 static IndexType TheCellType ();
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 static IndexType TheNodeType ();
00240
00241
00242
00243
00244
00245
00246 friend std::ostream& operator<< (std::ostream& os,
00247 const IndexType& itype);
00248
00249
00250
00251
00252
00253
00254 friend std::istream& operator>> (std::istream& is,
00255 IndexType& itype);
00256 private:
00257
00258
00259
00260
00261 static unsigned char mask (int k);
00262
00263
00264
00265
00266 unsigned char itype;
00267 };
00268
00269
00270
00271
00272
00273
00274 inline
00275 unsigned char
00276 IndexType::mask (int k)
00277 {
00278 return 1<<k;
00279 }
00280
00281 inline
00282 IndexType::IndexType ()
00283 :
00284 itype(0)
00285 {
00286 }
00287
00288 inline
00289 IndexType::IndexType (const IndexType& bt)
00290 :
00291 itype(bt.itype)
00292 {
00293 }
00294
00295 inline
00296 IndexType& IndexType::operator= (const IndexType& bt)
00297 {
00298 itype = bt.itype;
00299 return *this;
00300 }
00301
00302 inline
00303 IndexType::IndexType (const IntVect& iv)
00304 {
00305 itype = D_TERM6((iv[0]?1:0), | ((iv[1]?1:0)<<1), | ((iv[2]?1:0)<<2),
00306 | (iv[3]?1:0), | ((iv[4]?1:0)<<1), | ((iv[5]?1:0)<<2));
00307 }
00308
00309 inline
00310 IndexType& IndexType::operator= (const IntVect& iv)
00311 {
00312 itype = D_TERM6((iv[0]?1:0), | ((iv[1]?1:0)<<1), | ((iv[2]?1:0)<<2),
00313 | (iv[3]?1:0), | ((iv[4]?1:0)<<1), | ((iv[5]?1:0)<<2));
00314 return *this;
00315 }
00316
00317 inline
00318 IndexType::IndexType (D_DECL6(CellIndex i, CellIndex j, CellIndex k,
00319 CellIndex l, CellIndex m, CellIndex n))
00320 {
00321 itype = D_TERM6(i, | (j<<1), | (k<<2),
00322 | (l<<3), | (m<<4), | (n<<5));
00323 }
00324
00325 inline
00326 void
00327 IndexType::set (int dir)
00328 {
00329 itype |= mask(dir);
00330 }
00331
00332 inline
00333 void
00334 IndexType::unset (int dir)
00335 {
00336 itype &= ~mask(dir);
00337 }
00338
00339 inline
00340 bool
00341 IndexType::test (int dir) const
00342 {
00343 return (itype & mask(dir)) != 0;
00344 }
00345
00346 inline
00347 void
00348 IndexType::setall ()
00349 {
00350 itype = (1 << CH_SPACEDIM) - 1;
00351 }
00352
00353 inline
00354 void
00355 IndexType::clear ()
00356 {
00357 itype = 0;
00358 }
00359
00360 inline
00361 bool
00362 IndexType::any () const
00363 {
00364 return itype != 0;
00365 }
00366
00367 inline
00368 bool
00369 IndexType::ok () const
00370 {
00371 return itype < (1 << CH_SPACEDIM);
00372 }
00373
00374 inline
00375 void
00376 IndexType::flip (int i)
00377 {
00378 itype ^= mask(i);
00379 }
00380
00381 inline
00382 bool
00383 IndexType::operator== (const IndexType& t) const
00384 {
00385 return t.itype == itype;
00386 }
00387
00388 inline
00389 bool
00390 IndexType::operator< (const IndexType& t) const
00391 {
00392 return itype < t.itype;
00393 }
00394
00395 inline
00396 bool
00397 IndexType::operator!= (const IndexType& t) const
00398 {
00399 return t.itype != itype;
00400 }
00401
00402 inline
00403 bool
00404 IndexType::cellCentered () const
00405 {
00406 return itype == 0;
00407 }
00408
00409 inline
00410 bool
00411 IndexType::nodeCentered () const
00412 {
00413 return itype == (1<<CH_SPACEDIM)-1;
00414 }
00415
00416 inline
00417 void
00418 IndexType::setType (int dir,
00419 CellIndex t)
00420 {
00421 t == CELL ? unset(dir) : set(dir);
00422 }
00423
00424 inline
00425 IndexType::CellIndex
00426 IndexType::ixType (int dir) const
00427 {
00428 return (CellIndex) ((itype & (1<<dir)) >> dir);
00429 }
00430
00431 inline
00432 int
00433 IndexType::operator[] (int dir) const
00434 {
00435 return test(dir);
00436 }
00437
00438 inline
00439 IntVect
00440 IndexType::ixType () const
00441 {
00442 return IntVect(D_DECL6(itype&1, (itype>>1)&1, (itype>>2)&1,
00443 (itype>>3)&1, (itype>>4)&1, (itype>>5)&1));
00444 }
00445
00446 #endif
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465 class Box
00466 {
00467 public:
00468
00469
00470
00471
00472
00473
00474
00475
00476 Box ();
00477
00478
00479
00480
00481
00482
00483 ~Box ()
00484 {}
00485
00486
00487
00488
00489
00490
00491
00492 Box (const IntVect& small,
00493 const IntVect& big);
00494
00495
00496
00497
00498
00499
00500
00501 void define(const IntVect& small, const IntVect& big);
00502
00503
00504
00505
00506
00507
00508
00509 Box (const IntVect& small,
00510 const int* vec_len);
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520 Box (const IntVect& small,
00521 const IntVect& big,
00522 const IntVect& typ);
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532 void define(const IntVect& small,
00533 const IntVect& big,
00534 const IntVect& typ);
00535
00536
00537
00538
00539
00540
00541
00542
00543 Box (const IntVect& small,
00544 const IntVect& big,
00545 const IndexType& t);
00546
00547
00548
00549
00550
00551
00552
00553
00554 void define(const IntVect& small,
00555 const IntVect& big,
00556 const IndexType& t);
00557
00558
00559
00560
00561
00562
00563 Box (const Box& b);
00564
00565 void define(const Box& b);
00566
00567 Box copy() const
00568 {
00569 return *this;
00570 }
00571
00572
00573
00574
00575
00576
00577
00578
00579 const IntVect& smallEnd () const;
00580
00581
00582
00583
00584
00585
00586 IntVect sideEnd(Side::LoHiSide a_side) const;
00587
00588
00589
00590
00591
00592
00593
00594
00595 int smallEnd (int dir) const;
00596
00597
00598
00599
00600
00601
00602 const IntVect& bigEnd () const;
00603
00604
00605
00606
00607
00608
00609
00610
00611 int bigEnd (int dir) const;
00612
00613
00614
00615
00616
00617
00618
00619
00620 const int* loVect () const;
00621
00622
00623
00624
00625
00626
00627
00628
00629 const int* hiVect () const;
00630
00631
00632
00633
00634
00635
00636
00637
00638 const int* getVect () const;
00639
00640
00641
00642
00643
00644
00645
00646
00647 long index (const IntVect& v) const;
00648
00649
00650
00651
00652
00653
00654
00655
00656 IndexType ixType () const;
00657
00658
00659
00660
00661
00662
00663 IntVect type () const;
00664
00665
00666
00667
00668
00669
00670
00671
00672 IndexType::CellIndex type (int dir) const;
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682 inline
00683 IntVect size () const;
00684
00685
00686
00687
00688
00689
00690
00691
00692 int size (int dir) const;
00693
00694
00695
00696
00697
00698
00699 bool numPtsOK () const;
00700
00701
00702
00703
00704
00705
00706
00707
00708 long numPts () const;
00709
00710
00711
00712
00713
00714
00715 bool volumeOK () const;
00716
00717
00718
00719
00720
00721
00722
00723
00724 long volume () const;
00725
00726
00727
00728
00729
00730
00731
00732
00733 int longside (int& dir) const;
00734
00735
00736
00737
00738
00739
00740 int longside () const;
00741
00742
00743
00744
00745
00746
00747
00748
00749 int shortside (int& dir) const;
00750
00751
00752
00753
00754
00755
00756 int shortside () const;
00757
00758
00759
00760
00761
00762
00763
00764
00765 bool isEmpty () const;
00766
00767
00768
00769
00770
00771
00772 bool ok() const;
00773
00774
00775
00776
00777
00778
00779
00780
00781 bool contains (const IntVect& p) const;
00782
00783
00784
00785
00786
00787
00788
00789
00790 bool contains (const Box& b) const;
00791
00792
00793
00794
00795
00796
00797
00798
00799 bool intersects (const Box& b) const;
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810 bool intersectsNotEmpty (const Box& b) const;
00811
00812
00813
00814
00815
00816
00817
00818 bool sameSize (const Box& b) const;
00819
00820
00821
00822
00823
00824
00825 bool sameType (const Box &b) const;
00826
00827
00828
00829
00830
00831
00832
00833 bool operator== (const Box& b) const;
00834
00835 bool eq(const Box& b) const;
00836
00837
00838
00839
00840
00841 bool operator!= (const Box& b) const;
00842
00843 bool neq(const Box& b) const;
00844
00845
00846
00847
00848
00849
00850 bool cellCentered () const;
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862 bool operator < (const Box& rhs) const;
00863
00864 bool lt(const Box& rhs) const;
00865
00866
00867
00868
00869
00870
00871
00872
00873 Box& operator= (const Box& b);
00874
00875
00876
00877
00878
00879
00880
00881
00882 Box& setSmall (const IntVect& sm);
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892 Box& setSmall (int dir,
00893 int sm_index);
00894
00895
00896
00897
00898
00899
00900
00901
00902 Box& setBig (const IntVect& bg);
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912 Box& setBig (int dir,
00913 int bg_index);
00914
00915
00916
00917
00918
00919
00920
00921 Box& setRange (int dir,
00922 int sm_index,
00923 int n_cells = 1);
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939 Box& convert (IndexType typ);
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951 Box& convert (const IntVect& typ);
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966 Box& convert (int dir,
00967 IndexType::CellIndex typ);
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977 Box& surroundingNodes ();
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988 Box& surroundingNodes (int dir);
00989
00990 Box& surroundingNodes_int(int dir);
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001 friend Box surroundingNodes (const Box& b,
01002 int dir);
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013 friend Box surroundingNodes (const Box& b);
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023 Box& enclosedCells ();
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034 Box& enclosedCells (int dir);
01035
01036 Box& enclosedCells_int (int dir);
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048 friend Box enclosedCells (const Box& b,
01049 int dir);
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060 friend Box enclosedCells (const Box& b);
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072 Box& shift (int dir,
01073 int nzones);
01074
01075
01076
01077
01078
01079
01080
01081
01082 Box& shift (const IntVect& iv);
01083
01084 Box& shift_intvect (const IntVect& iv);
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099 Box& shiftHalf (int dir,
01100 int num_halfs);
01101
01102
01103 void convertOldToNew(const IntVect& a_permutation,
01104 const IntVect& a_sign,
01105 const IntVect& a_translation);
01106
01107
01108
01109 void convertNewToOld(const IntVect& a_permutation,
01110 const IntVect& a_sign,
01111 const IntVect& a_translation);
01112
01113
01114
01115
01116
01117
01118
01119
01120 Box& shiftHalf (const IntVect& iv);
01121 Box& shiftHalf_intvect (const IntVect& iv);
01122
01123
01124
01125
01126
01127
01128
01129 Box& operator+= (const IntVect& v);
01130
01131
01132
01133
01134
01135
01136
01137 Box operator+ (const IntVect& v) const;
01138
01139
01140
01141
01142
01143
01144
01145 Box& operator-= (const IntVect& v);
01146
01147
01148
01149
01150
01151
01152
01153 Box operator- (const IntVect& v) const;
01154
01155
01156
01157
01158 friend Box bdryBox(const Box& b,
01159 int dir,
01160 Side::LoHiSide a_sd,
01161 int len);
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172 friend Box bdryLo (const Box& b,
01173 int dir,
01174 int len);
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185 friend Box bdryHi (const Box& b,
01186 int dir,
01187 int len);
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213 friend Box adjCellLo (const Box& b,
01214 int dir,
01215 int len);
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241 friend Box adjCellHi (const Box& b,
01242 int dir,
01243 int len);
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255 Box operator& (const Box&) const;
01256
01257
01258
01259
01260
01261
01262
01263
01264 Box& operator&= (const Box&);
01265
01266
01267 friend Box adjCellBox (const Box& b,
01268 int dir,
01269 Side::LoHiSide a_side,
01270 int len);
01271
01272
01273
01274
01275
01276
01277 Box& minBox (const Box& b);
01278
01279
01280
01281
01282
01283
01284
01285 friend Box minBox (const Box& b1,
01286 const Box& b2);
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299 Box& grow (int i);
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310 friend Box grow (const Box& b,
01311 int i);
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322 Box& grow (const IntVect& v);
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333 friend Box grow (const Box& b,
01334 const IntVect& v);
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346 Box& grow (int idir,
01347 int n_cell);
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359 Box& growLo (int idir,
01360 int n_cell=1);
01361
01362
01363
01364
01365
01366
01367 Box& growDir (int a_idir,
01368 const Side::LoHiSide& a_sd,
01369 int a_cell);
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381 Box& growHi (int idir,
01382 int n_cell=1);
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398 Box& refine (int refinement_ratio);
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413 friend Box refine (const Box& b,
01414 int refinement_ratio);
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428 Box& refine (const IntVect& refinement_ratio);
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443 friend Box refine (const Box& b,
01444 const IntVect& refinement_ratio);
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464 Box& coarsen (int refinement_ratio);
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482 friend Box coarsen (const Box& b,
01483 int refinement_ratio);
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500 Box& coarsen (const IntVect& refinement_ratio);
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518 friend Box coarsen (const Box& b,
01519 const IntVect& refinement_ratio);
01520
01521
01522
01523
01524
01525
01526 void next (IntVect &) const;
01527
01528
01529
01530
01531
01532
01533 void next (IntVect& p,
01534 const int* shv) const;
01535
01536
01537
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552 Box chop (int dir,
01553 int chop_pnt);
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568 void degenerate( Box& a_to, const SliceSpec& a_sliceSpec,
01569 bool* a_outofbounds=0 ) const;
01570
01571
01572
01573
01574
01575
01576
01577
01578 friend std::ostream& operator<< (std::ostream& os,
01579 const Box& bx);
01580
01581
01582
01583
01584
01585
01586 friend std::istream& operator>> (std::istream& os,
01587 Box& bx);
01588
01589
01590
01591
01592
01593 void p() const;
01594
01595
01596
01597
01598
01599
01600
01601 void dumpOn (std::ostream& strm) const;
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623
01624 void computeBoxLen ();
01625 void computeBoxLenNotEmpty();
01626
01627
01628 static void setTempestOutputFormat( bool );
01629
01630 protected:
01631 friend class HDF5Handle;
01632
01633
01634
01635 bool numPtsOK (long& N) const;
01636
01637
01638
01639 bool volumeOK (long& N) const;
01640
01641 IntVect smallend;
01642 IntVect bigend;
01643
01644 IndexType btype;
01645
01646 static bool s_tempestOutputFormat;
01647 };
01648
01649 #include "NamespaceFooter.H"
01650
01651 #include "BaseNamespaceHeader.H"
01652
01653 #include "NamespaceVar.H"
01654
01655
01656 template < >
01657 int linearSize(const CH_XDIR::Box& a_input);
01658
01659
01660 template < >
01661 void linearIn(CH_XDIR::Box& a_outputT, const void* const a_inBuf);
01662
01663
01664 template < >
01665 void linearOut(void* const a_outBuf, const CH_XDIR::Box& a_inputT);
01666
01667
01668
01669 template < >
01670 int linearSize(const Vector<CH_XDIR::Box>& a_input);
01671 template < >
01672 void linearIn(Vector<CH_XDIR::Box>& a_outputT, const void* const inBuf);
01673 template < >
01674 void linearOut(void* const a_outBuf, const Vector<CH_XDIR::Box>& a_inputT);
01675
01676
01677 template < >
01678 int linearSize(const Vector<Vector<CH_XDIR::Box> >& a_input);
01679 template < >
01680 void linearIn(Vector<Vector<CH_XDIR::Box> >& a_outputT, const void* const inBuf);
01681 template < >
01682 void linearOut(void* const a_outBuf, const Vector<Vector<CH_XDIR::Box> >& a_inputT);
01683
01684 #include "BaseNamespaceFooter.H"
01685 #include "NamespaceHeader.H"
01686
01687
01688 Box surroundingNodes (const Box& b,
01689 int dir);
01690 Box surroundingNodes (const Box& b);
01691 Box enclosedCells (const Box& b,
01692 int dir);
01693 Box enclosedCells (const Box& b);
01694 Box bdryBox(const Box& b,
01695 int dir,
01696 Side::LoHiSide a_sd,
01697 int len=1);
01698 Box bdryLo (const Box& b,
01699 int dir,
01700 int len=1);
01701 Box bdryHi (const Box& b,
01702 int dir,
01703 int len=1);
01704 Box adjCellLo (const Box& b,
01705 int dir,
01706 int len=1);
01707 Box adjCellHi (const Box& b,
01708 int dir,
01709 int len=1);
01710 Box minBox (const Box& b1,
01711 const Box& b2);
01712 Box coarsen (const Box& b,
01713 const IntVect& refinement_ratio);
01714 Box coarsen (const Box& b,
01715 int refinement_ratio);
01716 Box refine (const Box& b,
01717 const IntVect& refinement_ratio);
01718 Box refine (const Box& b,
01719 int refinement_ratio);
01720
01721
01722
01723
01724
01725 #ifndef WRAPPER
01726
01727 inline
01728 Box::Box (const Box& b)
01729 : smallend(b.smallend),
01730 bigend(b.bigend),
01731 btype(b.btype)
01732 {
01733
01734
01735
01736 }
01737
01738 inline
01739 Box&
01740 Box::operator= (const Box& b)
01741 {
01742 smallend = b.smallend;
01743 bigend = b.bigend;
01744 btype = b.btype;
01745
01746
01747
01748 return *this;
01749 }
01750
01751 inline
01752 IntVect
01753 Box::sideEnd(Side::LoHiSide a_side) const
01754 {
01755 IntVect retval;
01756 if (a_side == Side::Lo)
01757 retval = smallEnd();
01758 else
01759 retval = bigEnd();
01760 return retval;
01761 }
01762
01763 inline
01764 const IntVect&
01765 Box::smallEnd () const
01766 {
01767 return smallend;
01768 }
01769
01770 inline
01771 int
01772 Box::smallEnd (int dir) const
01773 {
01774 return smallend[dir];
01775 }
01776
01777 inline
01778 const IntVect&
01779 Box::bigEnd () const
01780 {
01781 return bigend;
01782 }
01783
01784 inline
01785 int
01786 Box::bigEnd (int dir) const
01787 {
01788 return bigend[dir];
01789 }
01790
01791 inline
01792 IndexType
01793 Box::ixType () const
01794 {
01795 return btype;
01796 }
01797
01798 inline
01799 IntVect
01800 Box::type () const
01801 {
01802 return btype.ixType();
01803 }
01804
01805 inline
01806 IndexType::CellIndex
01807 Box::type (int dir) const
01808 {
01809 return btype.ixType(dir);
01810 }
01811
01812 inline
01813 IntVect
01814 Box::size () const
01815 {
01816 return IntVect(D_DECL6(bigend[0]-smallend[0]+1,
01817 bigend[1]-smallend[1]+1,
01818 bigend[2]-smallend[2]+1,
01819 bigend[3]-smallend[3]+1,
01820 bigend[4]-smallend[4]+1,
01821 bigend[5]-smallend[5]+1));
01822 }
01823
01824 inline
01825 int
01826 Box::size (int dir) const
01827 {
01828
01829 return bigend[dir]-smallend[dir]+1;
01830 }
01831
01832 inline
01833 const int*
01834 Box::loVect () const
01835 {
01836 return smallend.getVect();
01837 }
01838
01839 inline
01840 const int*
01841 Box::hiVect () const
01842 {
01843 return bigend.getVect();
01844 }
01845
01846 inline
01847 const int*
01848 Box::getVect () const
01849 {
01850 return smallend.getVect();
01851 }
01852
01853 inline
01854 bool
01855 Box::numPtsOK () const
01856 {
01857 long ignore;
01858 return numPtsOK(ignore);
01859 }
01860
01861 inline
01862 bool
01863 Box::isEmpty () const
01864 {
01865
01866 return D_TERM6((bigend[0] < smallend[0]),
01867 || (bigend[1] < smallend[1]),
01868 || (bigend[2] < smallend[2]),
01869 || (bigend[3] < smallend[3]),
01870 || (bigend[4] < smallend[4]),
01871 || (bigend[5] < smallend[5]) );
01872 }
01873
01874 inline
01875 bool
01876 Box::ok () const
01877 {
01878
01879
01880
01881
01882
01883 return (bigend >= smallend);
01884 }
01885
01886 inline
01887 bool
01888 Box::contains (const IntVect& p) const
01889 {
01890
01891
01892 return (p >= smallend && p <= bigend);
01893 }
01894
01895 inline
01896 bool
01897 Box::sameType (const Box &b) const
01898 {
01899 return btype == b.btype;
01900 }
01901
01902 inline
01903 bool
01904 Box::contains (const Box& b) const
01905 {
01906 CH_assert(sameType(b));
01907 return ( b.isEmpty() ||
01908 (!isEmpty() && b.smallend >= smallend && b.bigend <= bigend) );
01909 }
01910
01911 inline
01912 bool
01913 Box::sameSize (const Box& b) const
01914 {
01915 CH_assert(sameType(b));
01916 return D_TERM6(bigend[0] -smallend[0] == b.bigend[0]-b.smallend[0],
01917 && bigend[1] -smallend[1] == b.bigend[1]-b.smallend[1],
01918 && bigend[2] -smallend[2] == b.bigend[2]-b.smallend[2],
01919 && bigend[3] -smallend[3] == b.bigend[3]-b.smallend[3],
01920 && bigend[4] -smallend[4] == b.bigend[4]-b.smallend[4],
01921 && bigend[5] -smallend[5] == b.bigend[5]-b.smallend[5]);
01922 }
01923
01924 inline
01925 bool
01926 Box::operator== (const Box& b) const
01927 {
01928 return smallend == b.smallend && bigend == b.bigend && b.btype == btype;
01929 }
01930
01931 inline
01932 bool
01933 Box::operator!= (const Box& b) const
01934 {
01935 return !operator==(b);
01936 }
01937
01938 inline
01939 bool
01940 Box::cellCentered () const
01941 {
01942 return !btype.any();
01943 }
01944
01945 inline
01946 bool
01947 Box::volumeOK () const
01948 {
01949 return numPtsOK();
01950 }
01951
01952 inline
01953 long
01954 Box::index (const IntVect& v) const
01955 {
01956 long result = v.vect[0]-smallend.vect[0];
01957 #if CH_SPACEDIM == 1
01958
01959 #elif CH_SPACEDIM==2
01960 int len0=(bigend[0]-smallend[0]+1);
01961 result += len0*(v.vect[1]-smallend.vect[1]);
01962 #elif CH_SPACEDIM==3
01963 int len0=(bigend[0]-smallend[0]+1);
01964 int len1=(bigend[1]-smallend[1]+1);
01965 result += len0*(v.vect[1]-smallend.vect[1]
01966 +(v.vect[2]-smallend.vect[2])*len1);
01967 #elif CH_SPACEDIM==4
01968 int len0=(bigend[0]-smallend[0]+1);
01969 int len1=(bigend[1]-smallend[1]+1);
01970 int len2=(bigend[2]-smallend[2]+1);
01971 result += len0*((v.vect[1]-smallend.vect[1])
01972 +len1*((v.vect[2]-smallend.vect[2])
01973 +len2*(v.vect[3]-smallend[3])));
01974 #elif CH_SPACEDIM==5
01975 int len0=(bigend[0]-smallend[0]+1);
01976 int len1=(bigend[1]-smallend[1]+1);
01977 int len2=(bigend[2]-smallend[2]+1);
01978 int len3=(bigend[3]-smallend[3]+1);
01979 result += len0*(v.vect[1]-smallend.vect[1]
01980 +len1*(v.vect[2]-smallend.vect[2]
01981 +len2*(v.vect[3]-smallend[3]
01982 +len3*(v.vect[4]-smallend[4]))));
01983 #elif CH_SPACEDIM==6
01984 int len0=(bigend[0]-smallend[0]+1);
01985 int len1=(bigend[1]-smallend[1]+1);
01986 int len2=(bigend[2]-smallend[2]+1);
01987 int len3=(bigend[3]-smallend[3]+1);
01988 int len4=(bigend[4]-smallend[4]+1);
01989 result += len0*(v.vect[1]-smallend.vect[1]
01990 +len1*(v.vect[2]-smallend.vect[2]
01991 +len2*(v.vect[3]-smallend[3]
01992 +len3*(v.vect[4]-smallend[4]
01993 +len4*(v.vect[5]-smallend[5])))));
01994
01995 #else
01996 DIM > 6 undefined!
01997 #endif
01998 return result;
01999 }
02000
02001 inline
02002 void
02003 Box::computeBoxLen ()
02004 {
02005
02006
02007
02008
02009
02010
02011
02012
02013
02014
02015 }
02016
02017 inline
02018 void
02019 Box::computeBoxLenNotEmpty()
02020 {
02021
02022
02023
02024 }
02025
02026 inline
02027 Box&
02028 Box::setSmall (const IntVect& sm)
02029 {
02030 CH_assert (sm <= bigend);
02031
02032 smallend = sm;
02033 computeBoxLen();
02034 return *this;
02035 }
02036
02037 inline
02038 Box&
02039 Box::setSmall (int dir,
02040 int sm_index)
02041 {
02042 CH_assert (sm_index <= bigend[dir]);
02043
02044 smallend.setVal(dir,sm_index);
02045 computeBoxLen();
02046 return *this;
02047 }
02048
02049 inline
02050 Box&
02051 Box::setBig (const IntVect& bg)
02052 {
02053 CH_assert (bg >= smallend);
02054
02055 bigend = bg;
02056 computeBoxLen();
02057 return *this;
02058 }
02059
02060 inline
02061 Box&
02062 Box::setBig (int dir,
02063 int bg_index)
02064 {
02065 CH_assert (bg_index >= smallend[dir]);
02066
02067 bigend.setVal(dir,bg_index);
02068 computeBoxLen();
02069 return *this;
02070 }
02071
02072 inline
02073 Box&
02074 Box::setRange (int dir,
02075 int sm_index,
02076 int n_cells)
02077 {
02078 CH_assert (n_cells > 0);
02079
02080 smallend.setVal(dir,sm_index);
02081 bigend.setVal(dir,sm_index+n_cells-1);
02082 computeBoxLen();
02083 return *this;
02084 }
02085
02086 inline
02087 Box&
02088 Box::shift (int dir,
02089 int nzones)
02090 {
02091 if (!isEmpty())
02092 {
02093 smallend.shift(dir,nzones);
02094 bigend.shift(dir,nzones);
02095 }
02096 return *this;
02097 }
02098
02099 inline
02100 Box&
02101 Box::shift (const IntVect& iv)
02102 {
02103 if (!isEmpty())
02104 {
02105 smallend.shift(iv);
02106 bigend.shift(iv);
02107 }
02108 return *this;
02109 }
02110
02111 inline
02112 Box&
02113 Box::convert (const IntVect& typ)
02114 {
02115 CH_assert(typ >= IntVect::Zero && typ <= IntVect::Unit);
02116 if (!isEmpty())
02117 {
02118 IntVect shft(typ - btype.ixType());
02119 bigend += shft;
02120 }
02121 btype = IndexType(typ);
02122 computeBoxLen();
02123 return *this;
02124 }
02125
02126 inline
02127 Box&
02128 Box::surroundingNodes (int dir)
02129 {
02130 if (!(btype[dir]))
02131 {
02132 if (!isEmpty())
02133 {
02134 bigend.shift(dir,1);
02135 }
02136
02137
02138
02139 btype.set(dir);
02140 computeBoxLen();
02141 }
02142 return *this;
02143 }
02144
02145 inline
02146 Box&
02147 Box::enclosedCells (int dir)
02148 {
02149 if (btype[dir])
02150 {
02151 if (!isEmpty())
02152 {
02153 bigend.shift(dir,-1);
02154 }
02155
02156
02157
02158 btype.unset(dir);
02159 computeBoxLen();
02160 }
02161 return *this;
02162 }
02163
02164 inline
02165 Box
02166 surroundingNodes (const Box& b,
02167 int dir)
02168 {
02169 Box bx(b);
02170 return bx.surroundingNodes(dir);
02171 }
02172
02173 inline
02174 Box
02175 surroundingNodes (const Box& b)
02176 {
02177 Box bx(b);
02178 return bx.surroundingNodes();
02179 }
02180
02181 inline
02182 Box
02183 enclosedCells (const Box& b,
02184 int dir)
02185 {
02186 Box bx(b);
02187 return bx.enclosedCells(dir);
02188 }
02189
02190 inline
02191 Box
02192 enclosedCells (const Box& b)
02193 {
02194 Box bx(b);
02195 return bx.enclosedCells();
02196 }
02197
02198 inline
02199 Box&
02200 Box::operator+= (const IntVect& v)
02201 {
02202 if (!isEmpty())
02203 {
02204 smallend += v;
02205 bigend += v;
02206 }
02207 return *this;
02208 }
02209
02210 inline
02211 Box
02212 Box::operator+ (const IntVect& v) const
02213 {
02214 if (isEmpty())
02215 {
02216 return(Box().convert(btype));
02217 }
02218 else
02219 {
02220 IntVect small(smallend);
02221 small += v;
02222 IntVect big(bigend);
02223 big += v;
02224 return Box(small,big,btype);
02225 }
02226 }
02227
02228 inline
02229 Box&
02230 Box::operator-= (const IntVect& v)
02231 {
02232 if (!isEmpty())
02233 {
02234 smallend -= v;
02235 bigend -= v;
02236 }
02237 return *this;
02238 }
02239
02240 inline
02241 bool
02242 Box::operator < (const Box& rhs) const
02243 {
02244 if (smallend == rhs.smallend) return bigend.lexLT(rhs.bigend);
02245 return(!isEmpty() && (rhs.isEmpty() || smallend.lexLT(rhs.smallend)));
02246 }
02247
02248 inline
02249 Box
02250 Box::operator- (const IntVect& v) const
02251 {
02252 if (isEmpty())
02253 {
02254 return(Box().convert(btype));
02255 }
02256 else
02257 {
02258 IntVect small = smallend;
02259 small -= v;
02260 IntVect big = bigend;
02261 big -= v;
02262 return Box(small,big,btype);
02263 }
02264 }
02265
02266 inline
02267 Box&
02268 Box::grow (int i)
02269 {
02270 if (!isEmpty())
02271 {
02272 smallend.diagShift(-i);
02273 bigend.diagShift(i);
02274 if (!(bigend >= smallend)) *this = Box().convert(btype);
02275 computeBoxLen();
02276 }
02277 return *this;
02278 }
02279
02280 inline
02281 Box
02282 grow (const Box& b,
02283 int i)
02284 {
02285 if (b.isEmpty())
02286 {
02287 return Box().convert(b.btype);
02288 }
02289
02290 IntVect small = diagShift(b.smallend,-i);
02291 IntVect big = diagShift(b.bigend,i);
02292 if (!(big >= small))
02293 {
02294 return Box().convert(b.btype);
02295 }
02296 return Box(small,big,b.btype);
02297 }
02298
02299 inline
02300 Box&
02301 Box::grow (const IntVect& v)
02302 {
02303 if (!isEmpty())
02304 {
02305 smallend -= v;
02306 bigend += v;
02307 if (!(bigend >= smallend)) *this = Box().convert(btype);
02308 computeBoxLen();
02309 }
02310 return *this;
02311 }
02312
02313 inline
02314 Box
02315 grow (const Box& b,
02316 const IntVect& v)
02317 {
02318 if (b.isEmpty())
02319 {
02320 return Box().convert(b.btype);
02321 }
02322 else
02323 {
02324 IntVect small = b.smallend - v;
02325 IntVect big = b.bigend + v;
02326 if (!(big >= small))
02327 {
02328 return Box().convert(b.btype);
02329 }
02330 else
02331 {
02332 return Box(small,big,b.btype);
02333 }
02334 }
02335 }
02336
02337 inline
02338 Box&
02339 Box::grow (int idir,
02340 int n_cell)
02341 {
02342 if (!isEmpty())
02343 {
02344 smallend.shift(idir, -n_cell);
02345 bigend.shift(idir, n_cell);
02346 if (!(bigend >= smallend)) *this = Box().convert(btype);
02347 computeBoxLen();
02348 }
02349 return *this;
02350 }
02351
02352 inline
02353 Box&
02354 Box::growLo (int idir,
02355 int n_cell)
02356 {
02357 if (!isEmpty())
02358 {
02359 smallend.shift(idir, -n_cell);
02360 if (!(bigend >= smallend)) *this = Box().convert(btype);
02361 computeBoxLen();
02362 }
02363 return *this;
02364 }
02365
02366 inline
02367 Box&
02368 Box::growDir (int idir,
02369 const Side::LoHiSide& a_sd,
02370 int n_cell)
02371 {
02372 if (a_sd == Side::Lo)
02373 {
02374 growLo(idir, n_cell);
02375 }
02376 else
02377 {
02378 growHi(idir, n_cell);
02379 }
02380 return *this;
02381 }
02382
02383 inline
02384 Box&
02385 Box::growHi (int idir,
02386 int n_cell)
02387 {
02388 if (!isEmpty())
02389 {
02390 bigend.shift(idir,n_cell);
02391 if (!(bigend >= smallend)) *this = Box().convert(btype);
02392 computeBoxLen();
02393 }
02394 return *this;
02395 }
02396
02397 inline
02398 Box
02399 Box::operator& (const Box& rhs) const
02400 {
02401 Box lhs(*this);
02402 return lhs &= rhs;
02403 }
02404
02405 #endif
02406
02407 #include "NamespaceFooter.H"
02408 #endif