Chombo + EB  3.2
Box.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _BOX_H_
12 #define _BOX_H_
13 
14 #ifdef NODEV
15 #undef NODEV
16 #endif
17 
18 #include "SPACE.H"
19 
20 #ifndef WRAPPER
21 #include <iostream>
22 
23 #include "IntVect.H"
24 #include "Misc.H"
25 #include "LoHiSide.H"
26 #include "Vector.H"
27 #include "SPMD.H"
28 #include "NamespaceHeader.H"
29 
30 struct SliceSpec;
31 
32 /// Cell-Based or Node-Based Indices
33 /**
34 
35  The class IndexType defines an index as being cell based or node (face)
36  based in each of the CH_SPACEDIM directions. This class defines an
37  enumerated type CellIndex to be either CELL or NODE; i.e. each of the
38  CH_SPACEDIM dimensions must be either CELL or NODE.
39 */
40 
41 class IndexType
42 {
43 public:
44  ///
45  /**
46  The cell index type: one of CELL or NODE.
47 
48  */
49  enum CellIndex
50  {
51  CELL = 0,
52  NODE = 1
53  };
54 
55  ///
56  /**
57  The default constructor.
58 
59  */
60  IndexType ();
61 
62  ///
63  /**
64  The copy constructor. Let compiler build default copy constructor (bvs)
65 
66  */
67  // IndexType (const IndexType& rhs);
68 
69  ///
70  /**
71  Constructs an IndexType identical to an IntVect.
72 
73  */
74  explicit IndexType (const IntVect& iv);
75 
76  ///
77  /**
78  The assignment operator.
79 
80  */
81  IndexType& operator= (const IndexType& rhs);
82 
83  ///
84  /**
85  Another assignment operator.
86 
87  */
88  IndexType& operator= (const IntVect& iv);
89 
90  ///
91  /**
92  Constructs an IndexType given an explicit CellIndex for each
93  direction. D_DECL6 is a macro that sets the constructor to take
94  BL_SPACEDIM arguments.
95 
96  */
98  CellIndex l, CellIndex m, CellIndex n));
99 
100  ///
101  /**
102  Sets this IndexType to be NODE based in direction dir.
103 
104  */
105  void set (int dir);
106 
107  ///
108  /**
109  Sets this IndexType to be CELL based in direction dir.
110 
111  */
112  void unset (int dir);
113 
114  ///
115  /**
116  True if this IndexType is NODE based in direction dir.
117 
118  */
119  bool test (int dir) const;
120 
121  ///
122  /**
123  Set this IndexType to be NODE based in all directions.
124 
125  */
126  void setall ();
127 
128  ///
129  /**
130  Set this IndexType to be CELL based in all directions.
131 
132  */
133  void clear ();
134 
135  ///
136  /**
137  True if this IndexType is NODE based in any direction.
138 
139  */
140  bool any () const;
141 
142  ///
143  /**
144  True if this IndexType is valid.
145 
146  */
147  bool ok () const;
148 
149  ///
150  /**
151  Change this IndexType from CELL to NODE or NODE to CELL
152  in direction dir.
153 
154  */
155  void flip (int i);
156 
157  ///
158  /**
159  True if IndexTypes are identical.
160 
161  */
162  bool operator== (const IndexType& t) const;
163 
164  ///
165  /**
166  IndexTypes comparison.
167  */
168  bool operator<(const IndexType& t) const;
169 
170  ///
171  /**
172  True if IndexTypes are not identical.
173 
174  */
175  bool operator!= (const IndexType& t) const;
176 
177  ///
178  /**
179  True if this IndexType is CELL based in all directions.
180 
181  */
182  bool cellCentered () const;
183 
184  ///
185  /**
186  True if this IndexType is NODE based in all directions.
187 
188  */
189  bool nodeCentered () const;
190 
191  ///
192  /**
193  Set this IndexType to CellIndex type t in direction dir.
194 
195  */
196  void setType (int dir,
197  CellIndex t);
198 
199  ///
200  /**
201  Returns the CellIndex of this IndexType in direction dir.
202 
203  */
204  CellIndex ixType (int dir) const;
205 
206  ///
207  /**
208  Return an integer representing this IndexType in direction dir.
209 
210  */
211  int operator[] (int dir) const;
212 
213  ///
214  /**
215  Convert this IndexType to an IntVect via component-wise
216  conversion of enum CellIndex to int.
217 
218  */
219  IntVect ixType () const;
220 
221  ///
222  /**
223  This static member function returns an IndexType object all of
224  whose components are of value IndexType::CELL. It is provided as
225  a convenience to our users when defining a Box all of whose faces
226  should be of type IndexType::CELL.
227 
228  */
229  static IndexType TheCellType ();
230 
231  ///
232  /**
233  This static member function returns an IndexType object all of
234  whose components are of value IndexType::NODE. It is provided as
235  a convenience to our users when defining a Box all of whose faces
236  should be of type IndexType::NODE.
237 
238  */
239  static IndexType TheNodeType ();
240 
241  ///
242  /**
243  Write an IndexType to an ostream in ASCII.
244 
245  */
246  friend std::ostream& operator<< (std::ostream& os,
247  const IndexType& itype);
248 
249  ///
250  /**
251  Read an IndexType from an istream.
252 
253  */
254  friend std::istream& operator>> (std::istream& is,
255  IndexType& itype);
256 private:
257  //
258  // Returns 1<<k.
259  //
260  // static int mask (int k);
261  static unsigned char mask (int k);
262  //
263  // An integer holding the CellIndex in bits 0 - BL_SPACEDIM-1.
264  //
265  //unsigned int itype;
266  unsigned char itype;
267 };
268 
269 
270 //
271 // Inlines.
272 //
273 
274 inline
275 unsigned char
277 {
278  return 1<<k;
279 }
280 
281 inline
283  :
284  itype(0)
285 {
286 }
287 
288 //inline
289 //IndexType::IndexType (const IndexType& bt)
290 // :
291 // itype(bt.itype)
292 //{
293 //}
294 
295 inline
297 {
298  itype = bt.itype;
299  return *this;
300 }
301 
302 inline
304 {
305  itype = D_TERM6((iv[0]?1:0), | ((iv[1]?1:0)<<1), | ((iv[2]?1:0)<<2),
306  | ((iv[3]?1:0)<<3), | ((iv[4]?1:0)<<4), | ((iv[5]?1:0)<<5));
307 }
308 
309 inline
311 {
312  itype = D_TERM6((iv[0]?1:0), | ((iv[1]?1:0)<<1), | ((iv[2]?1:0)<<2),
313  | ((iv[3]?1:0)<<3), | ((iv[4]?1:0)<<4), | ((iv[5]?1:0)<<5));
314  return *this;
315 }
316 
317 inline
319  CellIndex l, CellIndex m, CellIndex n))
320 {
321  itype = D_TERM6(i, | (j<<1), | (k<<2),
322  | (l<<3), | (m<<4), | (n<<5));
323 }
324 
325 inline
326 void
327 IndexType::set (int dir)
328 {
329  itype |= mask(dir);
330 }
331 
332 inline
333 void
335 {
336  itype &= ~mask(dir);
337 }
338 
339 inline
340 bool
341 IndexType::test (int dir) const
342 {
343  return (itype & mask(dir)) != 0;
344 }
345 
346 inline
347 void
349 {
350  itype = (1 << CH_SPACEDIM) - 1;
351 }
352 
353 inline
354 void
356 {
357  itype = 0;
358 }
359 
360 inline
361 bool
363 {
364  return itype != 0;
365 }
366 
367 inline
368 bool
370 {
371  return itype < (1 << CH_SPACEDIM);
372 }
373 
374 inline
375 void
377 {
378  itype ^= mask(i);
379 }
380 
381 inline
382 bool
384 {
385  return t.itype == itype;
386 }
387 
388 inline
389 bool
391 {
392  return itype < t.itype;
393 }
394 
395 inline
396 bool
398 {
399  return t.itype != itype;
400 }
401 
402 inline
403 bool
405 {
406  return itype == 0;
407 }
408 
409 inline
410 bool
412 {
413  return itype == (1<<CH_SPACEDIM)-1;
414 }
415 
416 inline
417 void
419  CellIndex t)
420 {
421  t == CELL ? unset(dir) : set(dir);
422 }
423 
424 inline
426 IndexType::ixType (int dir) const
427 {
428  return (CellIndex) ((itype & (1<<dir)) >> dir);
429 }
430 
431 inline
432 int
434 {
435  return test(dir);
436 }
437 
438 inline
439 IntVect
441 {
442  return IntVect(D_DECL6(itype&1, (itype>>1)&1, (itype>>2)&1,
443  (itype>>3)&1, (itype>>4)&1, (itype>>5)&1));
444 }
445 
446 #endif /* WRAPPER */
447 
448 //
449 /// A Rectangular Domain on an Integer Lattice
450 /**
451 
452  A Box is an abstraction for defining discrete rectangular regions of
453  SpaceDim-dimensioned indexing space. Boxes have an IndexType, which
454  defines IndexType::CELL or IndexType::NODE based points for each
455  direction and a low and high IntVect which defines the lower and
456  upper corners of the Box. Boxes can exist in positive and negative
457  indexing space.
458 
459  Box is a dimension dependent class, so SpaceDim must be
460  defined as either 1, 2, or 3 when compiling.
461 
462  @ingroup chombo
463 */
464 
465 class Box
466 {
467 public:
468 
469  ///
470 
471  ///
472  /**
473  The default constructor. The constructed Box is empty.
474 
475  */
476  Box ();
477 
478  ///
479  /**
480  The destructor. Let the compiler build the default version (bvs)
481 
482  */
483  // ~Box ()
484  // {}
485 
486  ///
487  /**
488  Construct cell-centered type Box. It is an error if small is
489  greater than big.
490 
491  */
492  Box (const IntVect& small,
493  const IntVect& big);
494 
495  ///
496  /**
497  Modify cell-centered type Box. It is an error if small is
498  greater than big.
499 
500  */
501  void define(const IntVect& small, const IntVect& big);
502 
503  ///
504  /**
505  Construct Box with specified lengths. It is an error
506  if the lengths are negative.
507 
508  */
509  Box (const IntVect& small,
510  const int* vec_len);
511 
512  ///
513  /**
514  Construct Box with given type. small and big are expected to be
515  consistent with given type. It is an error if small is greater
516  than big. It is an error if typ is not convertible to an
517  IndexType.
518 
519  */
520  Box (const IntVect& small,
521  const IntVect& big,
522  const IntVect& typ);
523 
524  ///
525  /**
526  Modify Box with given type. small and big are expected to be
527  consistent with given type. It is an error if small is greater
528  than big. It is an error if typ is not convertible to an
529  IndexType.
530 
531  */
532  void define(const IntVect& small,
533  const IntVect& big,
534  const IntVect& typ);
535 
536  ///
537  /**
538  Construct Box with given type. small and big are expected to be
539  consistent with given type. It is an error if small is greater
540  than big.
541 
542  */
543  Box (const IntVect& small,
544  const IntVect& big,
545  const IndexType& t);
546 
547  ///
548  /**
549  Modify Box with given type. small and big are expected to be
550  consistent with given type. It is an error if small is greater
551  than big.
552 
553  */
554  void define(const IntVect& small,
555  const IntVect& big,
556  const IndexType& t);
557 
558  ///
559  /**
560  The copy constructor. Compiler can build default copy (bvs)
561 
562  */
563  // Box (const Box& b);
564 
565  void define(const Box& b);
566 
567  Box copy() const
568  {
569  return *this;
570  }
571 
572  /// {\bf Accessors}
573 
574  ///
575  /**
576  Returns the lower corner of this Box.
577 
578  */
579  const IntVect& smallEnd () const;
580 
581  ///
582  /**
583  return smallend if side is low,
584  bigend if side is high.
585  */
586  IntVect sideEnd(Side::LoHiSide a_side) const;
587 
588  ///
589  /**
590  Returns the coordinate of the low end of this Box in the given
591  direction. Directions are zero-based. It is an error if not 0
592  <= dir < SpaceDim.
593 
594  */
595  int smallEnd (int dir) const;
596 
597  ///
598  /**
599  Returns the upper corner of this Box.
600 
601  */
602  const IntVect& bigEnd () const;
603 
604  ///
605  /**
606  Returns the coordinate of the high end of this Box in the given
607  direction. Directions are zero-based. It is an error if not 0
608  <= dir < SpaceDim.
609 
610  */
611  int bigEnd (int dir) const;
612 
613  ///
614  /**
615  Returns a constant pointer to the array of low end coordinates.
616  Useful for calls to Fortran. It should not be used in any other
617  circumstances.
618 
619  */
620  const int* loVect () const;
621 
622  ///
623  /**
624  Returns a constant pointer the array of high end coordinates.
625  Useful for calls to Fortran. It should not be used in any other
626  circumstances.
627 
628  */
629  const int* hiVect () const;
630 
631  ///
632  /**
633  Returns a constant pointer to the array of coordinates in the
634  Box. Useful for calls to Fortran, but otherwise too dangerous
635  for use.
636 
637  */
638  const int* getVect () const;
639 
640  ///
641  /**
642  Returns offset of point from smallend; i.e. index(smallend) ->
643  0, bigend would return volume()-1. Is used in accessing
644  FArrayBox.
645 
646  */
647  long index (const IntVect& v) const;
648 
649  /// centering
650 
651  ///
652  /**
653  Return the indexing type of this Box.
654 
655  */
656  IndexType ixType () const;
657 
658  ///
659  /**
660  Return the indexing type of this Box.
661 
662  */
663  IntVect type () const;
664 
665  ///
666  /**
667  Return the indexing type of this Box in the specified direction.
668  Directions are zero-based. It is an error if not 0 <= dir <
669  SpaceDim.
670 
671  */
672  IndexType::CellIndex type (int dir) const;
673 
674  /// size functions
675 
676  ///
677  /**
678  Return an IntVect containing the size of this Box in each
679  coordinate direction.
680 
681  */
682  inline
683  IntVect size () const;
684 
685  ///
686  /**
687  Return the size of this Box in the specified coordinate
688  direction. Directions are zero-based. It is an error
689  if not 0 <= dir < SpaceDim.
690 
691  */
692  int size (int dir) const;
693 
694 
695  ///
696  /**
697  Return the volume, in indexing space, of region enclosed by this
698  Box. This is identical to volume().
699 
700  */
701  size_t numPts () const;
702 
703 
704  ///
705  /**
706  Return the volume, in indexing space, of region enclosed by this
707  Box. This is identical to numPts().
708 
709  */
710  size_t volume () const;
711 
712  ///
713  /**
714  Returns length of the longest side of this Box. The argument dir
715  is modified to give direction with longest side:
716  0...SpaceDim-1. Ignores type.
717 
718  */
719  int longside (int& dir) const;
720 
721  ///
722  /**
723  Returns length of the longest side of this Box. Ignores type.
724 
725  */
726  int longside () const;
727 
728  ///
729  /**
730  Returns length of shortest side of this Box. The argument dir is
731  modified to give direction with shortest side: 0...SpaceDim-1.
732  Ignores type.
733 
734  */
735  int shortside (int& dir) const;
736 
737  ///
738  /**
739  Returns length of the shortest side of this Box. Ignores type.
740 
741  */
742  int shortside () const;
743 
744  /// {\bf Comparison Functions}
745 
746  ///
747  /**
748  Returns true if this Box is empty.
749 
750  */
751  bool isEmpty () const;
752 
753  ///
754  /**
755  Returns true if this Box is not empty and all
756  sizes are right
757  */
758  bool ok() const;
759 
760  ///
761  /**
762  Returns true if argument is contained within this Box. An empty
763  Box does not contain and is not contained by any Box, including
764  itself.
765 
766  */
767  bool contains (const IntVect& p) const;
768 
769  ///
770  /**
771  Returns true if argument is contained within this Box. It is an
772  error if the Boxes have different types. An empty Box does not
773  contain any IntVect.
774 
775  */
776  bool contains (const Box& b) const;
777 
778  ///
779  /**
780  Returns true if this Box and the argument have non-null
781  intersections. It is an error if the Boxes have different types.
782  An empty Box does not intersect any Box, including itself.
783 
784  */
785  bool intersects (const Box& b) const;
786 
787  ///
788  /**
789  Returns true if this Box and the argument have non-null
790  intersections. It is an error if the Boxes have different types.
791  This routine does not perform the check to see if *this or b are
792  empty boxes. It is the callers responsibility to ensure that
793  this never happens. If you are unsure, the use the .intersects(..) routine.
794 
795  */
796  bool intersectsNotEmpty (const Box& b) const;
797 
798  ///
799  /**
800  Returns true if this Box and the argument are the same size, ie
801  translates of each other. It is an error if they have different
802  types.
803  */
804  bool sameSize (const Box& b) const;
805 
806  ///
807  /**
808  Returns true if this Box and the argument have same type.
809 
810  */
811  bool sameType (const Box &b) const;
812 
813  ///
814  /**
815  Returns true if this Box and the argument are identical,
816  including type.
817 
818  */
819  bool operator== (const Box& b) const;
820 
821  bool eq(const Box& b) const;
822  ///
823  /**
824  Returns true if this Box and the argument differ, including type.
825 
826  */
827  bool operator!= (const Box& b) const;
828 
829  bool neq(const Box& b) const;
830  ///
831  /**
832  Returns true if this Box is cell-centered in all indexing
833  directions.
834 
835  */
836  bool cellCentered () const;
837 
838  // following operators added Sept. 14, 1999. bvs
839  ///
840  /**
841  Returns true if this Box is lexigraphically less than rhs box.
842  All comparison is based on lower box corner. In the name of
843  coding efficiency, we do not handle the case where two boxes have
844  the same lower left corner. In DEBUG mode, this is checked for
845  with an assert.
846 
847  */
848  bool operator < (const Box& rhs) const;
849 
850  bool lt(const Box& rhs) const;
851 
852  /// {\bf Modification Functions}
853 
854  ///
855  /**
856  The assignment operator. Compiler can build default version for us (bvs)
857 
858  */
859  // Box& operator= (const Box& b);
860 
861  ///
862  /**
863  Redefine the lower corner of this Box. It is an error
864  if the specified corner is greater than the exisiting upper
865  corner of this Box.
866 
867  */
868  Box& setSmall (const IntVect& sm);
869 
870  ///
871  /**
872  Redefines the lower end of this Box in the specified coordinate
873  direction. It is an error if the specified value is greater than
874  the exisiting upper end of this Box. Directions are zero-based.
875  It is an error if not 0 <= dir < SpaceDim.
876 
877  */
878  Box& setSmall (int dir,
879  int sm_index);
880 
881  ///
882  /**
883  Redefines the upper corner of this Box. It is an error if the
884  specified corner is less than the exisiting lower corner of this
885  Box.
886 
887  */
888  Box& setBig (const IntVect& bg);
889 
890  ///
891  /**
892  Redefines the upper end of this Box in the specified coordinate
893  direction. It is an error if the specified value is less than the
894  exisiting lower end of this Box. Directions are zero-based. It
895  is an error if not 0 <= dir < SpaceDim.
896 
897  */
898  Box& setBig (int dir,
899  int bg_index);
900 
901  ///
902  /**
903  Set the entire range in a given direction, starting at sm_index
904  with length n_cells. It is an error if n_cells <= 0.
905 
906  */
907  Box& setRange (int dir,
908  int sm_index,
909  int n_cells = 1);
910 
911  /// centering type conversion functions
912 
913  ///
914  /**
915  Modifies this Box by converting from the current type into the
916  argument type. This may change the Box coordinates:\\
917 
918  type CELL -> NODE : increase coordinate by one on high end.\\
919 
920  type NODE -> CELL : reduce coordinate by one on high end.\\
921 
922  other type mappings make no change.
923 
924  */
925  Box& convert (IndexType typ);
926 
927  ///
928  /**
929  Modifies this Box by converting from the current type into the
930  argument type. This may change the Box coordinates:\\ type CELL
931  -> NODE : increase coordinate by one on high end.\\ type NODE ->
932  CELL : reduce coordinate by one on high end.\\ other type
933  mappings make no change. It is an error if typ is not
934  convertible to an IndexType.
935 
936  */
937  Box& convert (const IntVect& typ);
938 
939  ///
940  /**
941  Modifies this Box by converting from the current type into the
942  argument type. This may change the Box coordinates:\\
943 
944  type CELL -> NODE : increase coordinate by one on high end.\\
945 
946  type NODE -> CELL : reduce coordinate by one on high end.\\
947 
948  Other type mappings make no change. Directions are zero-based.
949  It is an error if not 0 <= dir < SpaceDim.
950 
951  */
952  Box& convert (int dir,
954 
955  ///
956  /**
957  Modifies this Box by converting it to NODE type in all
958  directions. This increases all components of the upper corner by
959  one. The Empty Box is not modified by this function except for
960  changing of type.
961 
962  */
963  Box& surroundingNodes ();
964 
965  ///
966  /**
967  Modifies this Box by converting it to NODE type in given
968  direction. This increases the component of the upper corner in
969  the given direction by one. Directions are zero-based. It is an
970  error if not 0 <= dir < SpaceDim. The Empty Box is not modified
971  by this function except for changing of type.
972 
973  */
974  Box& surroundingNodes (int dir);
975 
976  Box& surroundingNodes_int(int dir);
977  ///
978  /**
979  Returns a Box with NODE based coordinates in direction dir that
980  encloses the argument Box. NOTE: equivalent to
981  b.convert(dir,NODE). NOTE: error if b.type(dir) == NODE.
982  Directions are zero-based. It is an error if not 0 <= dir <
983  SpaceDim. The Empty Box is not modified by this function except
984  for changing of type.
985 
986  */
987  friend Box surroundingNodes (const Box& b,
988  int dir);
989 
990  ///
991  /**
992  Returns a Box with NODE based coordinates in all directions that
993  encloses argument Box. The upper corner of the return Box will
994  be one more in all components than the upper corner of the
995  argument Box. The Empty Box is not modified by this function
996  except for changing of type.
997 
998  */
999  friend Box surroundingNodes (const Box& b);
1000 
1001  ///
1002  /**
1003  Modifies this Box by converting it to CELL type in all directions.
1004  This decreases all components of the upper corner by one. The
1005  Empty Box is not modified by this function except for changing of
1006  type.
1007 
1008  */
1009  Box& enclosedCells ();
1010 
1011  ///
1012  /**
1013  Modifies this Box by converting it to CELL type in given
1014  direction. This decreases the component of the upper corner in
1015  the given direction by one. Directions are zero-based. It is an
1016  error if not 0 <= dir < SpaceDim. The Empty Box is not modified
1017  by this function except for changing of type.
1018 
1019  */
1020  Box& enclosedCells (int dir);
1021 
1022  Box& enclosedCells_int (int dir);
1023 
1024  ///
1025  /**
1026  Returns a Box with CELL based coordinates in direction dir that
1027  is enclosed by argument Box. NOTE: equivalent to
1028  b.convert(dir,CELL). NOTE: error if b.type(dir) == CELL.
1029  Directions are zero-based. It is an error if not 0 <= dir <
1030  SpaceDim. The Empty Box is not modified by this function except
1031  for changing of type.
1032 
1033  */
1034  friend Box enclosedCells (const Box& b,
1035  int dir);
1036 
1037  ///
1038  /**
1039  Returns a Box with CELL based coordinates in all directions that
1040  is enclosed by argument Box. The upper corner of the return Box
1041  will be one less in all components than the upper corner of the
1042  argument Box. The Empty Box is not modified by this function
1043  except for changing of type.
1044 
1045  */
1046  friend Box enclosedCells (const Box& b);
1047 
1048  /// shift functions
1049 
1050  ///
1051  /**
1052  Modifies this Box by shifting it nzones indexing positions in
1053  coordinate direction dir. Directions are zero-based. It is an
1054  error if not 0 <= dir < SpaceDim. The Empty Box is not modified
1055  by this function.
1056 
1057  */
1058  Box& shift (int dir,
1059  int nzones);
1060 
1061  ///
1062  /**
1063  Modifies this Box by shifting. Equivalent to
1064  b.shift(0,iv[0]).shift(1,iv[1]) .... The Empty Box is not
1065  modified by this function.
1066 
1067  */
1068  Box& shift (const IntVect& iv);
1069 
1070  Box& shift_intvect (const IntVect& iv);
1071 
1072  ///
1073  /**
1074  This member modifies this Box by shifting by "half" indices,
1075  thereby converting the Box from type CELL to NODE or vice-versa.
1076  b.shiftHalf(0,1) shifts b to the right by 1/2 cells.
1077  b.shiftHalf(1,-3) shifts b in the -j direction by 3/2 cells.
1078  NOTE: If num_halfs is EVEN the shift is num_halfs/2 full zones
1079  and hence will not change the type. This is: b.shifthalf(4) ==
1080  b.shift(2). Directions are zero-based. It is an error if not 0
1081  <= dir < SpaceDim. The Empty Box is not modified by this
1082  function except for changing of type.
1083 
1084  */
1085  Box& shiftHalf (int dir,
1086  int num_halfs);
1087 
1088  ///multiblock stuff.
1089  void convertOldToNew(const IntVect& a_permutation,
1090  const IntVect& a_sign,
1091  const IntVect& a_translation);
1092 
1093 
1094  ///multiblock stuff
1095  void convertNewToOld(const IntVect& a_permutation,
1096  const IntVect& a_sign,
1097  const IntVect& a_translation);
1098 
1099  ///
1100  /**
1101  Modifies this Box by shifting by half indices. Equivalent to
1102  b.shiftHalf(0,iv[0]).shiftHalf(1,iv[1]) ... The Empty Box is not
1103  modified by this function except for changing of type.
1104 
1105  */
1106  Box& shiftHalf (const IntVect& iv);
1107  Box& shiftHalf_intvect (const IntVect& iv);
1108 
1109  ///
1110  /**
1111  Modifies this Box by shifting it by given IntVect. The Empty Box
1112  is not modified by this function.
1113 
1114  */
1115  Box& operator+= (const IntVect& v);
1116 
1117  ///
1118  /**
1119  Returns a Box that is this Box shifted by the given IntVect. The
1120  Empty Box is not modified by this function.
1121 
1122  */
1123  Box operator+ (const IntVect& v) const;
1124 
1125  ///
1126  /**
1127  Modifies this Box by shifting it by given IntVect. The Empty Box
1128  is not modified by this function.
1129 
1130  */
1131  Box& operator-= (const IntVect& v);
1132 
1133  ///
1134  /**
1135  Returns a Box that is this Box shifted by the given IntVect. The
1136  Empty Box is not modified by this function.
1137 
1138  */
1139  Box operator- (const IntVect& v) const;
1140 
1141  /// neighbor box functions
1142 
1143  ///
1144  friend Box bdryBox(const Box& b,
1145  int dir,
1146  Side::LoHiSide a_sd,
1147  int len);
1148 
1149  ///
1150  /**
1151  Returns the edge-centered Box (in direction dir) defining the low
1152  side of the argument Box. The output Box will have the given
1153  length in the given direction. Directions are zero-based. It is
1154  an error if not 0 <= dir < SpaceDim. The neighbor of an Empty Box
1155  is an Empty Box of the appropriate type.
1156 
1157  */
1158  friend Box bdryLo (const Box& b,
1159  int dir,
1160  int len);
1161 
1162  ///
1163  /**
1164  Returns the edge-centered Box (in direction dir) defining the
1165  high side of the argument Box. The return Box will have the
1166  given length in the given direction. Directions are zero-based.
1167  It is an error if not 0 <= dir < SpaceDim. The neighbor of an
1168  Empty Box is an Empty Box of the appropriate type.
1169 
1170  */
1171  friend Box bdryHi (const Box& b,
1172  int dir,
1173  int len);
1174 
1175  ///
1176  /**
1177  Returns the cell centered Box of the given length adjacent to the
1178  argument Box on the low end along the given coordinate direction.
1179  The return Box is identical to the argument Box in the other
1180  directions. The return Box and the argument Box have an empty
1181  intersection. \\
1182 
1183  NOTE: len != 0. A negative length results in cells _inside_ the original box. \\
1184 
1185  NOTE: Box retval = adjCellLo(b,dir,len) is equivalent to the
1186  following set of operations: \\
1187 
1188  Box retval(b); \\
1189 
1190  retval.convert(dir,Box::CELL); \\
1191 
1192  retval.setrange(dir,retval.smallEnd(dir)-len,len); \\
1193 
1194  Directions are zero-based. It is an error if not 0 <= dir <
1195  SpaceDim. The neighbor of an Empty Box is an Empty Box of the
1196  appropriate type.
1197 
1198  */
1199  friend Box adjCellLo (const Box& b,
1200  int dir,
1201  int len);
1202 
1203  ///
1204  /**
1205  Returns the cell centered Box of the given length adjacent to the
1206  argument Box on the high end along the given coordinate
1207  direction. The return Box is identical to the argument Box in
1208  the other directions. The return Box and the argument Box have
1209  an empty intersection. \\
1210 
1211  NOTE: len != 0. A Negative length results in cells _inside_ the original box. \\
1212 
1213  NOTE: Box retval = adjCellHi(b,dir,len) is equivalent to the
1214  following set of operations: \\
1215 
1216  Box retval(b); \\
1217 
1218  retval.convert(dir,Box::CELL); \\
1219 
1220  retval.setrange(dir,retval.bigEnd(dir)+1,len);\\
1221 
1222  Directions are zero-based. It is an error if not 0 <= dir <
1223  SpaceDim. The neighbor of an Empty Box is an Empty Box of the
1224  appropriate type.
1225 
1226  */
1227  friend Box adjCellHi (const Box& b,
1228  int dir,
1229  int len);
1230 
1231  /// intersection functions
1232 
1233  ///
1234  /**
1235  Returns the Box that is intersection of this Box and the argument
1236  Box. Intersection is commutative. The Boxes MUST be of same
1237  type. The intersection of the Empty Box and any Box is the Empty
1238  Box.
1239 
1240  */
1241  Box operator& (const Box&) const;
1242 
1243  ///
1244  /**
1245  Modifies this Box by intersection with the argument Box. The
1246  Boxes MUST be of the same type. The intersection of the Empty
1247  Box and any Box is the Empty Box.
1248 
1249  */
1250  Box& operator&= (const Box&);
1251 
1252  ///
1253  friend Box adjCellBox (const Box& b,
1254  int dir,
1255  Side::LoHiSide a_side,
1256  int len);
1257  ///
1258  /**
1259  Modifies this Box to that of the minimum Box containing both this
1260  Box and the argument Box. Both Boxes must have identical type.
1261 
1262  */
1263  Box& minBox (const Box& b);
1264 
1265  ///
1266  /**
1267  Returns a Box that is the minimum Box containing both the
1268  argument Boxes. Both Boxes must have identical type.
1269 
1270  */
1271  friend Box minBox (const Box& b1,
1272  const Box& b2);
1273 
1274  /// grow functions
1275 
1276  ///
1277  /**
1278  Modifies this Box by growing it in all directions by given
1279  amount. The Empty Box is not modified by this function. NOTE:
1280  n_cell negative shrinks the Box by that number of cells. If
1281  shrinking produces an empty Box, the Box is transformed into the
1282  canonical Empty Box.
1283 
1284  */
1285  Box& grow (int i);
1286 
1287  ///
1288  /**
1289  Returns a Box that is the argument Box grown in all directions by
1290  given amount. The Empty Box is not modified by this function.
1291  NOTE: n_cell negative shrinks the Box by that number of cells.
1292  If shrinking produces an empty Box, the Box is transformed into
1293  the canonical Empty Box.
1294 
1295  */
1296  friend Box grow (const Box& b,
1297  int i);
1298 
1299  ///
1300  /**
1301  Modifies this Box by growing it in each direction by specified
1302  amount. The Empty Box is not modified by this function. NOTE:
1303  components of iv may be negative, which would shrink this Box. If
1304  shrinking produces an empty Box, the Box is transformed into the
1305  canonical Empty Box.
1306 
1307  */
1308  Box& grow (const IntVect& v);
1309 
1310  ///
1311  /**
1312  Returns a Box that is the argument Box grown in each
1313  direction by specified amount. The Empty Box is not modified by
1314  this function. NOTE: components of iv may be negative, which
1315  would return a shrunken Box. If shrinking produces an empty
1316  Box, the Box is transformed into the canonical Empty Box.
1317 
1318  */
1319  friend Box grow (const Box& b,
1320  const IntVect& v);
1321 
1322  ///
1323  /**
1324  Modifies this Box by growing it on the low and high end by n_cell
1325  cells in direction idir. The Empty Box is not modified by this
1326  function. NOTE: n_cell negative shrinks this Box by that number
1327  of cells. If shrinking produces an empty Box, the Box is
1328  transformed into the canonical Empty Box. Directions are
1329  zero-based. It is an error if not 0 <= dir < SpaceDim.
1330 
1331  */
1332  Box& grow (int idir,
1333  int n_cell);
1334 
1335  ///
1336  /**
1337  Modifies this Box by growing it on the low end by n_cell cells
1338  in direction idir. The Empty Box is not modified by this
1339  function. NOTE: n_cell negative shrinks this Box by that number
1340  of cells. If shrinking produces an empty Box, the Box is
1341  transformed into the canonical Empty Box. Directions are
1342  zero-based. It is an error if not 0 <= dir < SpaceDim.
1343 
1344  */
1345  Box& growLo (int idir,
1346  int n_cell=1);
1347 
1348  ///
1349  /**
1350  growLo if a_sd == Side::Lo \\
1351  growHi if a_sd= = Side::Hi
1352  */
1353  Box& growDir (int a_idir,
1354  const Side::LoHiSide& a_sd,
1355  int a_cell);
1356 
1357  ///
1358  /**
1359  Modifies this Box by growing it on the high end by n_cell cells
1360  in direction idir. The Empty Box is not modified by this
1361  function. NOTE: n_cell negative shrinks the Box by that number
1362  of cells. If shrinking produces an empty Box, the Box is
1363  transformed into the canonical Empty Box. Directions are
1364  zero-based. It is an error if not 0 <= dir < SpaceDim.
1365 
1366  */
1367  Box& growHi (int idir,
1368  int n_cell=1);
1369 
1370  /// refinement
1371 
1372  ///
1373  /**
1374  Modifies this Box by refining it by given (positive) refinement
1375  ratio. The Empty Box is not modified by this function. \\
1376 
1377  NOTE: if type(dir) = CELL centered: lo <- lo*ratio and hi <-
1378  (hi+1)*ratio - 1. \\
1379 
1380  NOTE: if type(dir) = NODE centered: lo <- lo*ratio and hi <-
1381  hi*ratio.
1382 
1383  */
1384  Box& refine (int refinement_ratio);
1385 
1386  ///
1387  /**
1388  Returns a Box that is the argument Box refined by given
1389  (positive) refinement ratio. The Empty Box is not modified by
1390  this function. \\
1391 
1392  NOTE: if type(dir) = CELL centered: lo <- lo*ratio and hi <-
1393  (hi+1)*ratio - 1.\\
1394 
1395  NOTE: if type(dir) = NODE centered: lo <- lo*ratio and hi <-
1396  hi*ratio.
1397 
1398  */
1399  friend Box refine (const Box& b,
1400  int refinement_ratio);
1401 
1402  ///
1403  /**
1404  Modifies this Box by refining it by given (positive) refinement
1405  ratio. The Empty Box is not modified by this function. \\
1406 
1407  NOTE: if type(dir) = CELL centered: lo <- lo*ratio and hi <-
1408  (hi+1)*ratio - 1.\\
1409 
1410  NOTE: if type(dir) = NODE centered: lo <- lo*ratio and hi <-
1411  hi*ratio.
1412 
1413  */
1414  Box& refine (const IntVect& refinement_ratio);
1415 
1416  ///
1417  /**
1418  Returns a Box that is the argument Box refined by given
1419  (positive) refinement ratio. The Empty Box is not modified by
1420  this function. \\
1421 
1422  NOTE: if type(dir) = CELL centered: lo <- lo*ratio and hi <-
1423  (hi+1)*ratio - 1.\\
1424 
1425  NOTE: if type(dir) = NODE centered: lo <- lo*ratio and hi <-
1426  hi*ratio.
1427 
1428  */
1429  friend Box refine (const Box& b,
1430  const IntVect& refinement_ratio);
1431 
1432  /// coarsening
1433 
1434  /*
1435  True if the if (refine(coarsen(int))) gets the same box back
1436  */
1437  bool coarsenable(int refrat) const
1438  {
1439  Box test = *this;
1440  test.coarsen(refrat);
1441  test.refine(refrat);
1442  return (test==*this);
1443  }
1444 
1445  ///
1446  /**
1447  Modifies this Box by coarsening it by given (positive) refinement
1448  ratio. The Empty Box is not modified by this function. \\
1449 
1450  NOTE: if type(dir) = CELL centered: lo <- lo/ratio and hi <-
1451  hi/ratio.\\
1452 
1453  NOTE: if type(dir) = NODE centered: lo <- lo/ratio and hi <-
1454  hi/ratio + ((hi%ratio)==0 ? 0 : 1).\\
1455 
1456  That is, refinement of coarsened Box must contain the original
1457  Box.
1458 
1459  */
1460 
1461  Box& coarsen (int refinement_ratio);
1462 
1463  ///
1464  /**
1465  Returns a Box that is the argument Box coarsened by given
1466  (positive) refinement ratio. The Empty Box is not modified by
1467  this function. \\
1468 
1469  NOTE: if type(dir) = CELL centered: lo <- lo/ratio and hi <-
1470  hi/ratio.\\
1471 
1472  NOTE: if type(dir) = NODE centered: lo <- lo/ratio and hi <-
1473  hi/ratio + ((hi%ratio)==0 ? 0 : 1).\\
1474 
1475  That is, refinement of coarsened Box must contain the original
1476  Box.
1477 
1478  */
1479  friend Box coarsen (const Box& b,
1480  int refinement_ratio);
1481 
1482  ///
1483  /**
1484  Modifies this Box by coarsening by given (positive) refinement
1485  ratio. The Empty Box is not modified by this function. \\
1486 
1487  NOTE: if type(dir) = CELL centered: lo <- lo/ratio and hi <-
1488  hi/ratio.\\
1489 
1490  NOTE: if type(dir) = NODE centered: lo <- lo/ratio and hi <-
1491  hi/ratio + ((hi%ratio)==0 ? 0 : 1).\\
1492 
1493  That is, refinement of coarsened Box must contain the original
1494  Box.
1495 
1496  */
1497  Box& coarsen (const IntVect& refinement_ratio);
1498 
1499  ///
1500  /**
1501  Returns a Box that is the argument Box coarsened by given
1502  (positive) refinement ratio. The Empty Box is not modified by
1503  this function. \\
1504 
1505  NOTE: if type(dir) = CELL centered: lo <- lo/ratio and hi <-
1506  hi/ratio.\\
1507 
1508  NOTE: if type(dir) = NODE centered: lo <- lo/ratio and hi <-
1509  hi/ratio + ((hi%ratio)==0 ? 0 : 1).\\
1510 
1511  That is, refinement of coarsened Box must contain the original
1512  Box.
1513 
1514  */
1515  friend Box coarsen (const Box& b,
1516  const IntVect& refinement_ratio);
1517 
1518  // next(...) is out of favor. use BoxIterator.
1519  /*
1520  Step through the rectangle. It is a runtime error to give
1521  a point not inside rectangle. Iteration may not be efficient.
1522  */
1523  void next (IntVect &) const;
1524 
1525  /*
1526  Scan argument IntVect over object second arg is
1527  increment vector. Runtime error if IntVect is not
1528  contained in object Box. Iteration may not be efficient.
1529  */
1530  void next (IntVect& p,
1531  const int* shv) const;
1532 
1533  /// misc
1534 
1535  ///
1536  /**
1537  Chops the Box at the chop_pnt in the dir direction returns one
1538  Box, modifies the object Box. The union of the two is the
1539  original Box. The modified Box is the low end, the returned Box
1540  is the high end. If type(dir) = CELL, the Boxes are disjoint with
1541  the chop_pnt included in the high end (new Box). It is an ERROR
1542  if chop_pnt is the low end of the orig Box. If type(dir) = NODE,
1543  the chop_pnt is included in both Boxes but is the only point in
1544  common. It is also an error if the chop_pnt is an end node of
1545  the Box. Directions are zero-based. It is an error if not 0 <=
1546  dir < SpaceDim.
1547 
1548  */
1549  Box chop (int dir,
1550  int chop_pnt);
1551 
1552  /**
1553  Makes a_to a box that's the same as *this except that it's just one cell
1554  thick in the a_sliceSpec.direction-th direction, and its (one) coordinate
1555  in that direction is a_sliceSpec.position.
1556 
1557  If a_sliceSpec.position is outside the range of *this, and a_outofbounds
1558  isn't null, then we set *a_outofbounds to true, otherwise to false.
1559 
1560  It would be more natural to return a Box, than to set the value of a Box
1561  reference, but we do it this way to be consistent with BaseFab::degenerate()
1562  where we can't return an object because of the policy of disallowing copy
1563  constructors for heavyweight classes.
1564  */
1565  void degenerate( Box& a_to, const SliceSpec& a_sliceSpec,
1566  bool* a_outofbounds=0 ) const;
1567 
1568  ///{\bf I/O Functions}
1569 
1570  ///
1571  /**
1572  Write an ASCII representation to the ostream.
1573 
1574  */
1575  friend std::ostream& operator<< (std::ostream& os,
1576  const Box& bx);
1577 
1578  ///
1579  /**
1580  Read from istream.
1581 
1582  */
1583  friend std::istream& operator>> (std::istream& os,
1584  Box& bx);
1585 
1586  ///
1587  /**
1588  print to pout()
1589  */
1590  void p() const;
1591 
1592  ///
1593  /**
1594  Gives more detail than printOn. Useful for exiting due to an
1595  error.
1596 
1597  */
1598  void dumpOn (std::ostream& strm) const;
1599 
1600  /// {\bf Box Constants}
1601 
1602  ///
1603  /**
1604  This is a canonical empty Box of cell-centered type.
1605 
1606  */
1607  //static const Box Empty;
1608 
1609  // TheUnitBox is out of favor.
1610  /*
1611  This static member function returns a constant reference to
1612  an object of type Box representing the unit box in
1613  BL_SPACEDIM-dimensional space.
1614  */
1615 
1616  //static const Box& TheUnitBox ();
1617 
1618  //
1619  // Sets the 'len' element of the Box. Aborts on integer overflow.
1620  //
1621  void computeBoxLen ();
1622  void computeBoxLenNotEmpty();
1623 
1624  /** Doesn't print the IndexType, and uses square outer brackets. */
1625  static void setTempestOutputFormat( bool );
1626 
1627 protected:
1628  friend class HDF5Handle;
1629 
1632  //IntVect len;
1634 
1636 };
1637 
1638 #include "NamespaceFooter.H"
1639 
1640 #include "BaseNamespaceHeader.H"
1641 
1642 #include "NamespaceVar.H"
1643 
1644 //Box specialization of linearSize
1645 template < >
1646 int linearSize(const CH_XDIR::Box& a_input);
1647 
1648 //Box specialization of linearIn
1649 template < >
1650 void linearIn(CH_XDIR::Box& a_outputT, const void* const a_inBuf);
1651 
1652 //Box specialization of linearOut
1653 template < >
1654 void linearOut(void* const a_outBuf, const CH_XDIR::Box& a_inputT);
1655 
1656 
1657 //Vector<Box> specialization
1658 template < >
1659 int linearSize(const Vector<CH_XDIR::Box>& a_input);
1660 template < >
1661 void linearIn(Vector<CH_XDIR::Box>& a_outputT, const void* const inBuf);
1662 template < >
1663 void linearOut(void* const a_outBuf, const Vector<CH_XDIR::Box>& a_inputT);
1664 
1665 //Vector<Vector<Box> > specialization
1666 template < >
1667 int linearSize(const Vector<Vector<CH_XDIR::Box> >& a_input);
1668 template < >
1669 void linearIn(Vector<Vector<CH_XDIR::Box> >& a_outputT, const void* const inBuf);
1670 template < >
1671 void linearOut(void* const a_outBuf, const Vector<Vector<CH_XDIR::Box> >& a_inputT);
1672 
1673 #include "BaseNamespaceFooter.H"
1674 #include "NamespaceHeader.H"
1675 
1676 // global function prototypes
1677 Box surroundingNodes (const Box& b,
1678  int dir);
1679 Box surroundingNodes (const Box& b);
1680 Box enclosedCells (const Box& b,
1681  int dir);
1682 Box enclosedCells (const Box& b);
1683 Box bdryBox(const Box& b,
1684  int dir,
1685  Side::LoHiSide a_sd,
1686  int len=1);
1687 Box bdryLo (const Box& b,
1688  int dir,
1689  int len=1);
1690 Box bdryHi (const Box& b,
1691  int dir,
1692  int len=1);
1693 Box adjCellLo (const Box& b,
1694  int dir,
1695  int len=1);
1696 Box adjCellHi (const Box& b,
1697  int dir,
1698  int len=1);
1699 Box minBox (const Box& b1,
1700  const Box& b2);
1701 Box coarsen (const Box& b,
1702  const IntVect& refinement_ratio);
1703 Box coarsen (const Box& b,
1704  int refinement_ratio);
1705 Box refine (const Box& b,
1706  const IntVect& refinement_ratio);
1707 Box refine (const Box& b,
1708  int refinement_ratio);
1709 
1710 //
1711 // Inlines.
1712 //
1713 
1714 #ifndef WRAPPER
1715 
1716 //inline
1717 //Box::Box (const Box& b)
1718 // : smallend(b.smallend),
1719 // bigend(b.bigend),
1720 // btype(b.btype)
1721 //{
1722 // D_EXPR6(len[0] = b.len[0],
1723 // len[1] = b.len[1],
1724 // len[2] = b.len[2]);
1725 //}
1726 
1727 //inline
1728 //Box&
1729 //Box::operator= (const Box& b)
1730 //{
1731 // smallend = b.smallend;
1732 // bigend = b.bigend;
1733 // btype = b.btype;
1734 // D_EXPR6(len[0] = b.len[0],
1735 // len[1] = b.len[1],
1736 // len[2] = b.len[2]);
1737 // return *this;
1738 //}
1739 
1740 inline
1741 IntVect
1743 {
1744  IntVect retval;
1745  if (a_side == Side::Lo)
1746  retval = smallEnd();
1747  else
1748  retval = bigEnd();
1749  return retval;
1750 }
1751 
1752 inline
1753 const IntVect&
1755 {
1756  return smallend;
1757 }
1758 
1759 inline
1760 int
1761 Box::smallEnd (int dir) const
1762 {
1763  return smallend[dir];
1764 }
1765 
1766 inline
1767 const IntVect&
1768 Box::bigEnd () const
1769 {
1770  return bigend;
1771 }
1772 
1773 inline
1774 int
1775 Box::bigEnd (int dir) const
1776 {
1777  return bigend[dir];
1778 }
1779 
1780 inline
1781 IndexType
1782 Box::ixType () const
1783 {
1784  return btype;
1785 }
1786 
1787 inline
1788 IntVect
1789 Box::type () const
1790 {
1791  return btype.ixType();
1792 }
1793 
1794 inline
1796 Box::type (int dir) const
1797 {
1798  return btype.ixType(dir);
1799 }
1800 
1801 inline
1802 IntVect
1803 Box::size () const
1804 {
1805  return IntVect(D_DECL6(bigend[0]-smallend[0]+1,
1806  bigend[1]-smallend[1]+1,
1807  bigend[2]-smallend[2]+1,
1808  bigend[3]-smallend[3]+1,
1809  bigend[4]-smallend[4]+1,
1810  bigend[5]-smallend[5]+1));
1811 }
1812 
1813 inline
1814 int
1815 Box::size (int dir) const
1816 {
1817  // return len[dir];
1818  return bigend[dir]-smallend[dir]+1;
1819 }
1820 
1821 inline
1822 const int*
1823 Box::loVect () const
1824 {
1825  return smallend.getVect();
1826 }
1827 
1828 inline
1829 const int*
1830 Box::hiVect () const
1831 {
1832  return bigend.getVect();
1833 }
1834 
1835 inline
1836 const int*
1838 {
1839  return smallend.getVect();
1840 }
1841 
1842 
1843 
1844 inline
1845 bool
1847 {
1848  // return numPts() == 0;
1849  return D_TERM6((bigend[0] < smallend[0]),
1850  || (bigend[1] < smallend[1]),
1851  || (bigend[2] < smallend[2]),
1852  || (bigend[3] < smallend[3]),
1853  || (bigend[4] < smallend[4]),
1854  || (bigend[5] < smallend[5]) );
1855 }
1856 
1857 inline
1858 bool
1859 Box::ok () const
1860 {
1861  // bool typ_ok = btype.ok();
1862  // bool len_ok = D_TERM6((len[0] == (bigend[0]-smallend[0]+1)),
1863  // && (len[1] == (bigend[1]-smallend[1]+1)),
1864  // && (len[2] == (bigend[2]-smallend[2]+1)));
1865  // return (bigend >= smallend) && len_ok && typ_ok;
1866  return (bigend >= smallend);
1867 }
1868 
1869 inline
1870 bool
1871 Box::contains (const IntVect& p) const
1872 {
1873 
1874  //return ( !isEmpty() && (p >= smallend && p <= bigend) );
1875  return (p >= smallend && p <= bigend);
1876 }
1877 
1878 inline
1879 bool
1880 Box::sameType (const Box &b) const
1881 {
1882  return btype == b.btype;
1883 }
1884 
1885 inline
1886 bool
1887 Box::contains (const Box& b) const
1888 {
1889  CH_assert(sameType(b));
1890  return ( b.isEmpty() ||
1891  (!isEmpty() && b.smallend >= smallend && b.bigend <= bigend) );
1892 }
1893 
1894 inline
1895 bool
1896 Box::sameSize (const Box& b) const
1897 {
1898  CH_assert(sameType(b));
1899  return D_TERM6(bigend[0] -smallend[0] == b.bigend[0]-b.smallend[0],
1900  && bigend[1] -smallend[1] == b.bigend[1]-b.smallend[1],
1901  && bigend[2] -smallend[2] == b.bigend[2]-b.smallend[2],
1902  && bigend[3] -smallend[3] == b.bigend[3]-b.smallend[3],
1903  && bigend[4] -smallend[4] == b.bigend[4]-b.smallend[4],
1904  && bigend[5] -smallend[5] == b.bigend[5]-b.smallend[5]);
1905 }
1906 
1907 inline
1908 bool
1909 Box::operator== (const Box& b) const
1910 {
1911  return smallend == b.smallend && bigend == b.bigend && b.btype == btype;
1912 }
1913 
1914 inline
1915 bool
1916 Box::operator!= (const Box& b) const
1917 {
1918  return !operator==(b);
1919 }
1920 
1921 inline
1922 bool
1924 {
1925  return !btype.any();
1926 }
1927 
1928 
1929 inline
1930 long
1931 Box::index (const IntVect& v) const
1932 {
1933  long result = v.vect[0]-smallend.vect[0];
1934 #if CH_SPACEDIM == 1
1935  // nothing more goes here
1936 #elif CH_SPACEDIM==2
1937  int len0=(bigend[0]-smallend[0]+1);
1938  result += len0*(v.vect[1]-smallend.vect[1]);
1939 #elif CH_SPACEDIM==3
1940  long int len0=(bigend[0]-smallend[0]+1);
1941  long int len1=(bigend[1]-smallend[1]+1);
1942  long int dif1= v.vect[1]-smallend.vect[1];
1943  long int dif2= v.vect[2]-smallend.vect[2];
1944  result += len0*(dif1
1945  + dif2*len1);
1946 #elif CH_SPACEDIM==4
1947  int len0=(bigend[0]-smallend[0]+1);
1948  int len1=(bigend[1]-smallend[1]+1);
1949  int len2=(bigend[2]-smallend[2]+1);
1950  result += len0*((v.vect[1]-smallend.vect[1])
1951  +len1*((v.vect[2]-smallend.vect[2])
1952  +len2*(v.vect[3]-smallend[3])));
1953 #elif CH_SPACEDIM==5
1954  int len0=(bigend[0]-smallend[0]+1);
1955  int len1=(bigend[1]-smallend[1]+1);
1956  int len2=(bigend[2]-smallend[2]+1);
1957  int len3=(bigend[3]-smallend[3]+1);
1958  result += len0*(v.vect[1]-smallend.vect[1]
1959  +len1*(v.vect[2]-smallend.vect[2]
1960  +len2*(v.vect[3]-smallend[3]
1961  +len3*(v.vect[4]-smallend[4]))));
1962 #elif CH_SPACEDIM==6
1963  int len0=(bigend[0]-smallend[0]+1);
1964  int len1=(bigend[1]-smallend[1]+1);
1965  int len2=(bigend[2]-smallend[2]+1);
1966  int len3=(bigend[3]-smallend[3]+1);
1967  int len4=(bigend[4]-smallend[4]+1);
1968  result += len0*(v.vect[1]-smallend.vect[1]
1969  +len1*(v.vect[2]-smallend.vect[2]
1970  +len2*(v.vect[3]-smallend[3]
1971  +len3*(v.vect[4]-smallend[4]
1972  +len4*(v.vect[5]-smallend[5])))));
1973 
1974 #else
1975  DIM > 6 undefined!
1976 #endif
1977  return result;
1978 }
1979 
1980 inline
1981 void
1983 {
1984 // if (isEmpty())
1985 // {
1986 // len = IntVect::Zero;
1987 // }
1988 // else
1989 // {
1990 // D_EXPR6(len[0] = bigend[0]-smallend[0] + 1,
1991 // len[1] = bigend[1]-smallend[1] + 1,
1992 // len[2] = bigend[2]-smallend[2] + 1);
1993 // }
1994 }
1995 
1996 inline
1997 void
1999 {
2000 // D_EXPR6(len[0] = bigend[0]-smallend[0] + 1,
2001 // len[1] = bigend[1]-smallend[1] + 1,
2002 // len[2] = bigend[2]-smallend[2] + 1);
2003 }
2004 
2005 inline
2006 Box&
2008 {
2009  CH_assert (sm <= bigend);
2010 
2011  smallend = sm;
2012  computeBoxLen();
2013  return *this;
2014 }
2015 
2016 inline
2017 Box&
2018 Box::setSmall (int dir,
2019  int sm_index)
2020 {
2021  CH_assert (sm_index <= bigend[dir]);
2022 
2023  smallend.setVal(dir,sm_index);
2024  computeBoxLen();
2025  return *this;
2026 }
2027 
2028 inline
2029 Box&
2031 {
2032  CH_assert (bg >= smallend);
2033 
2034  bigend = bg;
2035  computeBoxLen();
2036  return *this;
2037 }
2038 
2039 inline
2040 Box&
2041 Box::setBig (int dir,
2042  int bg_index)
2043 {
2044  CH_assert (bg_index >= smallend[dir]);
2045 
2046  bigend.setVal(dir,bg_index);
2047  computeBoxLen();
2048  return *this;
2049 }
2050 
2051 inline
2052 Box&
2053 Box::setRange (int dir,
2054  int sm_index,
2055  int n_cells)
2056 {
2057  CH_assert (n_cells > 0);
2058 
2059  smallend.setVal(dir,sm_index);
2060  bigend.setVal(dir,sm_index+n_cells-1);
2061  computeBoxLen();
2062  return *this;
2063 }
2064 
2065 inline
2066 Box&
2067 Box::shift (int dir,
2068  int nzones)
2069 {
2070  if (!isEmpty())
2071  {
2072  smallend.shift(dir,nzones);
2073  bigend.shift(dir,nzones);
2074  }
2075  return *this;
2076 }
2077 
2078 inline
2079 Box&
2080 Box::shift (const IntVect& iv)
2081 {
2082  if (!isEmpty())
2083  {
2084  smallend.shift(iv);
2085  bigend.shift(iv);
2086  }
2087  return *this;
2088 }
2089 
2090 inline
2091 Box&
2092 Box::convert (const IntVect& typ)
2093 {
2094  CH_assert(typ >= IntVect::Zero && typ <= IntVect::Unit);
2095  if (!isEmpty())
2096  {
2097  IntVect shft(typ - btype.ixType());
2098  bigend += shft;
2099  }
2100  btype = IndexType(typ);
2101  computeBoxLen();
2102  return *this;
2103 }
2104 
2105 inline
2106 Box&
2108 {
2109  if (!(btype[dir]))
2110  {
2111  if (!isEmpty())
2112  {
2113  bigend.shift(dir,1);
2114  }
2115  //
2116  // Set dir'th bit to 1 = IndexType::NODE.
2117  //
2118  btype.set(dir);
2119  computeBoxLen();
2120  }
2121  return *this;
2122 }
2123 
2124 inline
2125 Box&
2127 {
2128  if (btype[dir])
2129  {
2130  if (!isEmpty())
2131  {
2132  bigend.shift(dir,-1);
2133  }
2134  //
2135  // Set dir'th bit to 0 = IndexType::CELL.
2136  //
2137  btype.unset(dir);
2138  computeBoxLen();
2139  }
2140  return *this;
2141 }
2142 
2143 inline
2144 Box
2146  int dir)
2147 {
2148  Box bx(b);
2149  return bx.surroundingNodes(dir);
2150 }
2151 
2152 inline
2153 Box
2155 {
2156  Box bx(b);
2157  return bx.surroundingNodes();
2158 }
2159 
2160 inline
2161 Box
2162 enclosedCells (const Box& b,
2163  int dir)
2164 {
2165  Box bx(b);
2166  return bx.enclosedCells(dir);
2167 }
2168 
2169 inline
2170 Box
2171 enclosedCells (const Box& b)
2172 {
2173  Box bx(b);
2174  return bx.enclosedCells();
2175 }
2176 
2177 inline
2178 Box&
2180 {
2181  if (!isEmpty())
2182  {
2183  smallend += v;
2184  bigend += v;
2185  }
2186  return *this;
2187 }
2188 
2189 inline
2190 Box
2191 Box::operator+ (const IntVect& v) const
2192 {
2193  if (isEmpty())
2194  {
2195  return(Box().convert(btype));
2196  }
2197  else
2198  {
2199  IntVect small(smallend);
2200  small += v;
2201  IntVect big(bigend);
2202  big += v;
2203  return Box(small,big,btype);
2204  }
2205 }
2206 
2207 inline
2208 Box&
2210 {
2211  if (!isEmpty())
2212  {
2213  smallend -= v;
2214  bigend -= v;
2215  }
2216  return *this;
2217 }
2218 
2219 inline
2220 bool
2221 Box::operator < (const Box& rhs) const
2222 {
2223  if (smallend == rhs.smallend) return bigend.lexLT(rhs.bigend);
2224  return(!isEmpty() && (rhs.isEmpty() || smallend.lexLT(rhs.smallend)));
2225 }
2226 
2227 inline
2228 Box
2229 Box::operator- (const IntVect& v) const
2230 {
2231  if (isEmpty())
2232  {
2233  return(Box().convert(btype));
2234  }
2235  else
2236  {
2237  IntVect small = smallend;
2238  small -= v;
2239  IntVect big = bigend;
2240  big -= v;
2241  return Box(small,big,btype);
2242  }
2243 }
2244 
2245 inline
2246 Box&
2247 Box::grow (int i)
2248 {
2249  if (!isEmpty())
2250  {
2251  smallend.diagShift(-i);
2252  bigend.diagShift(i);
2253  if (!(bigend >= smallend)) *this = Box().convert(btype);
2254  computeBoxLen();
2255  }
2256  return *this;
2257 }
2258 
2259 inline
2260 Box
2261 grow (const Box& b,
2262  int i)
2263 {
2264  if (b.isEmpty())
2265  {
2266  return Box().convert(b.btype);
2267  }
2268 
2269  IntVect small = diagShift(b.smallend,-i);
2270  IntVect big = diagShift(b.bigend,i);
2271  if (!(big >= small))
2272  {
2273  return Box().convert(b.btype);
2274  }
2275  return Box(small,big,b.btype);
2276 }
2277 
2278 inline
2279 Box&
2280 Box::grow (const IntVect& v)
2281 {
2282  if (!isEmpty())
2283  {
2284  smallend -= v;
2285  bigend += v;
2286  if (!(bigend >= smallend)) *this = Box().convert(btype);
2287  computeBoxLen();
2288  }
2289  return *this;
2290 }
2291 
2292 inline
2293 Box
2294 grow (const Box& b,
2295  const IntVect& v)
2296 {
2297  if (b.isEmpty())
2298  {
2299  return Box().convert(b.btype);
2300  }
2301  else
2302  {
2303  IntVect small = b.smallend - v;
2304  IntVect big = b.bigend + v;
2305  if (!(big >= small))
2306  {
2307  return Box().convert(b.btype);
2308  }
2309  else
2310  {
2311  return Box(small,big,b.btype);
2312  }
2313  }
2314 }
2315 
2316 inline
2317 Box&
2318 Box::grow (int idir,
2319  int n_cell)
2320 {
2321  if (!isEmpty())
2322  {
2323  smallend.shift(idir, -n_cell);
2324  bigend.shift(idir, n_cell);
2325  if (!(bigend >= smallend)) *this = Box().convert(btype);
2326  computeBoxLen();
2327  }
2328  return *this;
2329 }
2330 
2331 inline
2332 Box&
2333 Box::growLo (int idir,
2334  int n_cell)
2335 {
2336  if (!isEmpty())
2337  {
2338  smallend.shift(idir, -n_cell);
2339  if (!(bigend >= smallend)) *this = Box().convert(btype);
2340  computeBoxLen();
2341  }
2342  return *this;
2343 }
2344 
2345 inline
2346 Box&
2347 Box::growDir (int idir,
2348  const Side::LoHiSide& a_sd,
2349  int n_cell)
2350 {
2351  if (a_sd == Side::Lo)
2352  {
2353  growLo(idir, n_cell);
2354  }
2355  else
2356  {
2357  growHi(idir, n_cell);
2358  }
2359  return *this;
2360 }
2361 
2362 inline
2363 Box&
2364 Box::growHi (int idir,
2365  int n_cell)
2366 {
2367  if (!isEmpty())
2368  {
2369  bigend.shift(idir,n_cell);
2370  if (!(bigend >= smallend)) *this = Box().convert(btype);
2371  computeBoxLen();
2372  }
2373  return *this;
2374 }
2375 
2376 inline
2377 Box
2378 Box::operator& (const Box& rhs) const
2379 {
2380  Box lhs(*this);
2381  return lhs &= rhs;
2382 }
2383 
2384 #endif /* WRAPPER */
2385 
2386 #include "NamespaceFooter.H"
2387 #endif /*CH_BOX_H*/
#define D_DECL6(a, b, c, d, e, f)
Definition: CHArray.H:39
Definition: Box.H:52
Box & coarsen(int refinement_ratio)
Box & operator-=(const IntVect &v)
Definition: Box.H:2209
void unset(int dir)
Definition: Box.H:334
bool operator<(const Box &rhs) const
Definition: Box.H:2221
Box & refine(int refinement_ratio)
refinement
C::self_type operator-(const C &, const C &)
Definition: GenericArithmeticI.H:124
IntVect size() const
size functions
Definition: Box.H:1803
const int * hiVect() const
Definition: Box.H:1830
#define D_TERM6(a, b, c, d, e, f)
Definition: CHArray.H:40
bool operator!=(const Box &b) const
Definition: Box.H:1916
#define CH_SPACEDIM
Definition: SPACE.H:51
#define CH_assert(cond)
Definition: CHArray.H:37
Box refine(const Box &b, const IntVect &refinement_ratio)
bool operator==(const Box &b) const
Definition: Box.H:1909
bool test(int dir) const
Definition: Box.H:341
friend std::istream & operator>>(std::istream &is, IndexType &itype)
const int * getVect() const
Definition: Box.H:1837
bool cellCentered() const
Definition: Box.H:1923
bool sameSize(const Box &b) const
Definition: Box.H:1896
bool operator!=(const IndexType &t) const
Definition: Box.H:397
Box coarsen(const Box &b, const IntVect &refinement_ratio)
one dimensional dynamic array
Definition: Vector.H:53
Box operator &(const Box &) const
intersection functions
friend std::ostream & operator<<(std::ostream &os, const IndexType &itype)
const int * loVect() const
Definition: Box.H:1823
void clear()
Definition: Box.H:355
IndexType btype
Definition: Box.H:1633
Definition: SliceSpec.H:41
void flip(int i)
Definition: Box.H:376
IndexTM< T, N > diagShift(const IndexTM< T, N > &a_p, T a_s)
Definition: IndexTMI.H:388
IntVect type() const
Definition: Box.H:1789
bool contains(const IntVect &p) const
Definition: Box.H:1871
IndexType()
Definition: Box.H:282
Box copy() const
Definition: Box.H:567
Box & surroundingNodes()
int isEmpty(const box2d *)
Box operator-(const IntVect &v) const
Definition: Box.H:2229
void linearOut(void *const a_outBuf, const CH_XDIR::Box &a_inputT)
bool ok() const
Definition: Box.H:369
IntVect sideEnd(Side::LoHiSide a_side) const
Definition: Box.H:1742
Box & enclosedCells()
Box minBox(const Box &b1, const Box &b2)
void setType(int dir, CellIndex t)
Definition: Box.H:418
const IntVect & bigEnd() const
Definition: Box.H:1768
C::self_type operator+(const C &, const C &)
Definition: GenericArithmeticI.H:120
IntVect bigend
Definition: Box.H:1631
Box & setSmall(const IntVect &sm)
{ Modification Functions}
Definition: Box.H:2007
IntVect ixType() const
Definition: Box.H:440
static const IntVect Unit
Definition: IntVect.H:659
Definition: Box.H:51
static IndexType TheNodeType()
const IntVect & smallEnd() const
{ Accessors}
Definition: Box.H:1754
int vect[CH_SPACEDIM]
Definition: IntVect.H:686
Box surroundingNodes(const Box &b, int dir)
Definition: Box.H:2145
IndexType ixType() const
centering
Definition: Box.H:1782
Box bdryBox(const Box &b, int dir, Side::LoHiSide a_sd, int len=1)
Box & growDir(int a_idir, const Side::LoHiSide &a_sd, int a_cell)
Definition: Box.H:2347
Box grow(const Box &b, int i)
Definition: Box.H:2261
Box adjCellLo(const Box &b, int dir, int len=1)
static IndexType TheCellType()
void linearIn(CH_XDIR::Box &a_outputT, const void *const a_inBuf)
Box enclosedCells(const Box &b, int dir)
Definition: Box.H:2162
LoHiSide
Definition: LoHiSide.H:27
void set(int dir)
Definition: Box.H:327
bool nodeCentered() const
Definition: Box.H:411
Box & setRange(int dir, int sm_index, int n_cells=1)
Definition: Box.H:2053
IntVect smallend
Definition: Box.H:1630
static const IntVect Zero
Definition: IntVect.H:654
Box adjCellHi(const Box &b, int dir, int len=1)
bool sameType(const Box &b) const
Definition: Box.H:1880
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
long index(const IntVect &v) const
Definition: Box.H:1931
int linearSize(const CH_XDIR::Box &a_input)
void setall()
Definition: Box.H:348
static bool s_tempestOutputFormat
Definition: Box.H:1635
unsigned char itype
Definition: Box.H:266
Box & convert(IndexType typ)
centering type conversion functions
Handle to a particular group in an HDF file.
Definition: CH_HDF5.H:294
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Definition: LoHiSide.H:30
Cell-Based or Node-Based Indices.
Definition: Box.H:41
void computeBoxLen()
{ Box Constants}
Definition: Box.H:1982
bool operator==(const IndexType &t) const
Definition: Box.H:383
Box & shift(int dir, int nzones)
shift functions
Definition: Box.H:2067
static unsigned char mask(int k)
Definition: Box.H:276
Box & operator+=(const IntVect &v)
Definition: Box.H:2179
bool cellCentered() const
Definition: Box.H:404
Box & grow(int i)
grow functions
Definition: Box.H:2247
Box & setBig(const IntVect &bg)
Definition: Box.H:2030
Box & growLo(int idir, int n_cell=1)
Definition: Box.H:2333
Box bdryHi(const Box &b, int dir, int len=1)
Box operator+(const IntVect &v) const
Definition: Box.H:2191
CellIndex
Definition: Box.H:49
bool coarsenable(int refrat) const
coarsening
Definition: Box.H:1437
IndexType & operator=(const IndexType &rhs)
Definition: Box.H:296
void computeBoxLenNotEmpty()
Definition: Box.H:1998
bool isEmpty() const
{ Comparison Functions}
Definition: Box.H:1846
bool ok() const
Definition: Box.H:1859
bool any() const
Definition: Box.H:362
Box bdryLo(const Box &b, int dir, int len=1)
bool operator<(const IndexType &t) const
Definition: Box.H:390
Box & growHi(int idir, int n_cell=1)
Definition: Box.H:2364
int operator[](int dir) const
Definition: Box.H:433