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