Chombo + EB  3.0
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 class 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.
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
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), | ((iv[4]?1:0)<<1), | ((iv[5]?1:0)<<2));
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), | ((iv[4]?1:0)<<1), | ((iv[5]?1:0)<<2));
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.
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.
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  Is the number calculated by numPts() representable in a long?
697 
698  */
699  bool numPtsOK () const;
700 
701  ///
702  /**
703  Return the volume, in indexing space, of region enclosed by this
704  Box. This is identical to volume(). Abort()s if the number
705  cannot be represented in a long.\\
706 
707  */
708  long numPts () const;
709 
710  ///
711  /**
712  Is the number calculated by volume() representable in a long?
713 
714  */
715  bool volumeOK () const;
716 
717  ///
718  /**
719  Return the volume, in indexing space, of region enclosed by this
720  Box. This is identical to numPts(). Abort()s if the number
721  cannot be represented in a long.\\
722 
723  */
724  long volume () const;
725 
726  ///
727  /**
728  Returns length of the longest side of this Box. The argument dir
729  is modified to give direction with longest side:
730  0...SpaceDim-1. Ignores type.
731 
732  */
733  int longside (int& dir) const;
734 
735  ///
736  /**
737  Returns length of the longest side of this Box. Ignores type.
738 
739  */
740  int longside () const;
741 
742  ///
743  /**
744  Returns length of shortest side of this Box. The argument dir is
745  modified to give direction with shortest side: 0...SpaceDim-1.
746  Ignores type.
747 
748  */
749  int shortside (int& dir) const;
750 
751  ///
752  /**
753  Returns length of the shortest side of this Box. Ignores type.
754 
755  */
756  int shortside () const;
757 
758  /// {\bf Comparison Functions}
759 
760  ///
761  /**
762  Returns true if this Box is empty.
763 
764  */
765  bool isEmpty () const;
766 
767  ///
768  /**
769  Returns true if this Box is not empty and all
770  sizes are right
771  */
772  bool ok() const;
773 
774  ///
775  /**
776  Returns true if argument is contained within this Box. An empty
777  Box does not contain and is not contained by any Box, including
778  itself.
779 
780  */
781  bool contains (const IntVect& p) const;
782 
783  ///
784  /**
785  Returns true if argument is contained within this Box. It is an
786  error if the Boxes have different types. An empty Box does not
787  contain any IntVect.
788 
789  */
790  bool contains (const Box& b) const;
791 
792  ///
793  /**
794  Returns true if this Box and the argument have non-null
795  intersections. It is an error if the Boxes have different types.
796  An empty Box does not intersect any Box, including itself.
797 
798  */
799  bool intersects (const Box& b) const;
800 
801  ///
802  /**
803  Returns true if this Box and the argument have non-null
804  intersections. It is an error if the Boxes have different types.
805  This routine does not perform the check to see if *this or b are
806  empty boxes. It is the callers responsibility to ensure that
807  this never happens. If you are unsure, the use the .intersects(..) routine.
808 
809  */
810  bool intersectsNotEmpty (const Box& b) const;
811 
812  ///
813  /**
814  Returns true if this Box and the argument are the same size, ie
815  translates of each other. It is an error if they have different
816  types.
817  */
818  bool sameSize (const Box& b) const;
819 
820  ///
821  /**
822  Returns true if this Box and the argument have same type.
823 
824  */
825  bool sameType (const Box &b) const;
826 
827  ///
828  /**
829  Returns true if this Box and the argument are identical,
830  including type.
831 
832  */
833  bool operator== (const Box& b) const;
834 
835  bool eq(const Box& b) const;
836  ///
837  /**
838  Returns true if this Box and the argument differ, including type.
839 
840  */
841  bool operator!= (const Box& b) const;
842 
843  bool neq(const Box& b) const;
844  ///
845  /**
846  Returns true if this Box is cell-centered in all indexing
847  directions.
848 
849  */
850  bool cellCentered () const;
851 
852  // following operators added Sept. 14, 1999. bvs
853  ///
854  /**
855  Returns true if this Box is lexigraphically less than rhs box.
856  All comparison is based on lower box corner. In the name of
857  coding efficiency, we do not handle the case where two boxes have
858  the same lower left corner. In DEBUG mode, this is checked for
859  with an assert.
860 
861  */
862  bool operator < (const Box& rhs) const;
863 
864  bool lt(const Box& rhs) const;
865 
866  /// {\bf Modification Functions}
867 
868  ///
869  /**
870  The assignment operator.
871 
872  */
873  Box& operator= (const Box& b);
874 
875  ///
876  /**
877  Redefine the lower corner of this Box. It is an error
878  if the specified corner is greater than the exisiting upper
879  corner of this Box.
880 
881  */
882  Box& setSmall (const IntVect& sm);
883 
884  ///
885  /**
886  Redefines the lower end of this Box in the specified coordinate
887  direction. It is an error if the specified value is greater than
888  the exisiting upper end of this Box. Directions are zero-based.
889  It is an error if not 0 <= dir < SpaceDim.
890 
891  */
892  Box& setSmall (int dir,
893  int sm_index);
894 
895  ///
896  /**
897  Redefines the upper corner of this Box. It is an error if the
898  specified corner is less than the exisiting lower corner of this
899  Box.
900 
901  */
902  Box& setBig (const IntVect& bg);
903 
904  ///
905  /**
906  Redefines the upper end of this Box in the specified coordinate
907  direction. It is an error if the specified value is less than the
908  exisiting lower end of this Box. Directions are zero-based. It
909  is an error if not 0 <= dir < SpaceDim.
910 
911  */
912  Box& setBig (int dir,
913  int bg_index);
914 
915  ///
916  /**
917  Set the entire range in a given direction, starting at sm_index
918  with length n_cells. It is an error if n_cells <= 0.
919 
920  */
921  Box& setRange (int dir,
922  int sm_index,
923  int n_cells = 1);
924 
925  /// centering type conversion functions
926 
927  ///
928  /**
929  Modifies this Box by converting from the current type into the
930  argument type. This may change the Box coordinates:\\
931 
932  type CELL -> NODE : increase coordinate by one on high end.\\
933 
934  type NODE -> CELL : reduce coordinate by one on high end.\\
935 
936  other type mappings make no change.
937 
938  */
939  Box& convert (IndexType typ);
940 
941  ///
942  /**
943  Modifies this Box by converting from the current type into the
944  argument type. This may change the Box coordinates:\\ type CELL
945  -> NODE : increase coordinate by one on high end.\\ type NODE ->
946  CELL : reduce coordinate by one on high end.\\ other type
947  mappings make no change. It is an error if typ is not
948  convertible to an IndexType.
949 
950  */
951  Box& convert (const IntVect& typ);
952 
953  ///
954  /**
955  Modifies this Box by converting from the current type into the
956  argument type. This may change the Box coordinates:\\
957 
958  type CELL -> NODE : increase coordinate by one on high end.\\
959 
960  type NODE -> CELL : reduce coordinate by one on high end.\\
961 
962  Other type mappings make no change. Directions are zero-based.
963  It is an error if not 0 <= dir < SpaceDim.
964 
965  */
966  Box& convert (int dir,
968 
969  ///
970  /**
971  Modifies this Box by converting it to NODE type in all
972  directions. This increases all components of the upper corner by
973  one. The Empty Box is not modified by this function except for
974  changing of type.
975 
976  */
977  Box& surroundingNodes ();
978 
979  ///
980  /**
981  Modifies this Box by converting it to NODE type in given
982  direction. This increases the component of the upper corner in
983  the given direction by one. Directions are zero-based. It is an
984  error if not 0 <= dir < SpaceDim. The Empty Box is not modified
985  by this function except for changing of type.
986 
987  */
988  Box& surroundingNodes (int dir);
989 
990  Box& surroundingNodes_int(int dir);
991  ///
992  /**
993  Returns a Box with NODE based coordinates in direction dir that
994  encloses the argument Box. NOTE: equivalent to
995  b.convert(dir,NODE). NOTE: error if b.type(dir) == NODE.
996  Directions are zero-based. It is an error if not 0 <= dir <
997  SpaceDim. The Empty Box is not modified by this function except
998  for changing of type.
999 
1000  */
1001  friend Box surroundingNodes (const Box& b,
1002  int dir);
1003 
1004  ///
1005  /**
1006  Returns a Box with NODE based coordinates in all directions that
1007  encloses argument Box. The upper corner of the return Box will
1008  be one more in all components than the upper corner of the
1009  argument Box. The Empty Box is not modified by this function
1010  except for changing of type.
1011 
1012  */
1013  friend Box surroundingNodes (const Box& b);
1014 
1015  ///
1016  /**
1017  Modifies this Box by converting it to CELL type in all directions.
1018  This decreases all components of the upper corner by one. The
1019  Empty Box is not modified by this function except for changing of
1020  type.
1021 
1022  */
1023  Box& enclosedCells ();
1024 
1025  ///
1026  /**
1027  Modifies this Box by converting it to CELL type in given
1028  direction. This decreases the component of the upper corner in
1029  the given direction by one. Directions are zero-based. It is an
1030  error if not 0 <= dir < SpaceDim. The Empty Box is not modified
1031  by this function except for changing of type.
1032 
1033  */
1034  Box& enclosedCells (int dir);
1035 
1036  Box& enclosedCells_int (int dir);
1037 
1038  ///
1039  /**
1040  Returns a Box with CELL based coordinates in direction dir that
1041  is enclosed by argument Box. NOTE: equivalent to
1042  b.convert(dir,CELL). NOTE: error if b.type(dir) == CELL.
1043  Directions are zero-based. It is an error if not 0 <= dir <
1044  SpaceDim. The Empty Box is not modified by this function except
1045  for changing of type.
1046 
1047  */
1048  friend Box enclosedCells (const Box& b,
1049  int dir);
1050 
1051  ///
1052  /**
1053  Returns a Box with CELL based coordinates in all directions that
1054  is enclosed by argument Box. The upper corner of the return Box
1055  will be one less in all components than the upper corner of the
1056  argument Box. The Empty Box is not modified by this function
1057  except for changing of type.
1058 
1059  */
1060  friend Box enclosedCells (const Box& b);
1061 
1062  /// shift functions
1063 
1064  ///
1065  /**
1066  Modifies this Box by shifting it nzones indexing positions in
1067  coordinate direction dir. Directions are zero-based. It is an
1068  error if not 0 <= dir < SpaceDim. The Empty Box is not modified
1069  by this function.
1070 
1071  */
1072  Box& shift (int dir,
1073  int nzones);
1074 
1075  ///
1076  /**
1077  Modifies this Box by shifting. Equivalent to
1078  b.shift(0,iv[0]).shift(1,iv[1]) .... The Empty Box is not
1079  modified by this function.
1080 
1081  */
1082  Box& shift (const IntVect& iv);
1083 
1084  Box& shift_intvect (const IntVect& iv);
1085 
1086  ///
1087  /**
1088  This member modifies this Box by shifting by "half" indices,
1089  thereby converting the Box from type CELL to NODE or vice-versa.
1090  b.shiftHalf(0,1) shifts b to the right by 1/2 cells.
1091  b.shiftHalf(1,-3) shifts b in the -j direction by 3/2 cells.
1092  NOTE: If num_halfs is EVEN the shift is num_halfs/2 full zones
1093  and hence will not change the type. This is: b.shifthalf(4) ==
1094  b.shift(2). Directions are zero-based. It is an error if not 0
1095  <= dir < SpaceDim. The Empty Box is not modified by this
1096  function except for changing of type.
1097 
1098  */
1099  Box& shiftHalf (int dir,
1100  int num_halfs);
1101 
1102  ///multiblock stuff.
1103  void convertOldToNew(const IntVect& a_permutation,
1104  const IntVect& a_sign,
1105  const IntVect& a_translation);
1106 
1107 
1108  ///multiblock stuff
1109  void convertNewToOld(const IntVect& a_permutation,
1110  const IntVect& a_sign,
1111  const IntVect& a_translation);
1112 
1113  ///
1114  /**
1115  Modifies this Box by shifting by half indices. Equivalent to
1116  b.shiftHalf(0,iv[0]).shiftHalf(1,iv[1]) ... The Empty Box is not
1117  modified by this function except for changing of type.
1118 
1119  */
1120  Box& shiftHalf (const IntVect& iv);
1121  Box& shiftHalf_intvect (const IntVect& iv);
1122 
1123  ///
1124  /**
1125  Modifies this Box by shifting it by given IntVect. The Empty Box
1126  is not modified by this function.
1127 
1128  */
1129  Box& operator+= (const IntVect& v);
1130 
1131  ///
1132  /**
1133  Returns a Box that is this Box shifted by the given IntVect. The
1134  Empty Box is not modified by this function.
1135 
1136  */
1137  Box operator+ (const IntVect& v) const;
1138 
1139  ///
1140  /**
1141  Modifies this Box by shifting it by given IntVect. The Empty Box
1142  is not modified by this function.
1143 
1144  */
1145  Box& operator-= (const IntVect& v);
1146 
1147  ///
1148  /**
1149  Returns a Box that is this Box shifted by the given IntVect. The
1150  Empty Box is not modified by this function.
1151 
1152  */
1153  Box operator- (const IntVect& v) const;
1154 
1155  /// neighbor box functions
1156 
1157  ///
1158  friend Box bdryBox(const Box& b,
1159  int dir,
1160  Side::LoHiSide a_sd,
1161  int len);
1162 
1163  ///
1164  /**
1165  Returns the edge-centered Box (in direction dir) defining the low
1166  side of the argument Box. The output Box will have the given
1167  length in the given direction. Directions are zero-based. It is
1168  an error if not 0 <= dir < SpaceDim. The neighbor of an Empty Box
1169  is an Empty Box of the appropriate type.
1170 
1171  */
1172  friend Box bdryLo (const Box& b,
1173  int dir,
1174  int len);
1175 
1176  ///
1177  /**
1178  Returns the edge-centered Box (in direction dir) defining the
1179  high side of the argument Box. The return Box will have the
1180  given length in the given direction. Directions are zero-based.
1181  It is an error if not 0 <= dir < SpaceDim. The neighbor of an
1182  Empty Box is an Empty Box of the appropriate type.
1183 
1184  */
1185  friend Box bdryHi (const Box& b,
1186  int dir,
1187  int len);
1188 
1189  ///
1190  /**
1191  Returns the cell centered Box of the given length adjacent to the
1192  argument Box on the low end along the given coordinate direction.
1193  The return Box is identical to the argument Box in the other
1194  directions. The return Box and the argument Box have an empty
1195  intersection. \\
1196 
1197  NOTE: len != 0. A negative length results in cells _inside_ the original box. \\
1198 
1199  NOTE: Box retval = adjCellLo(b,dir,len) is equivalent to the
1200  following set of operations: \\
1201 
1202  Box retval(b); \\
1203 
1204  retval.convert(dir,Box::CELL); \\
1205 
1206  retval.setrange(dir,retval.smallEnd(dir)-len,len); \\
1207 
1208  Directions are zero-based. It is an error if not 0 <= dir <
1209  SpaceDim. The neighbor of an Empty Box is an Empty Box of the
1210  appropriate type.
1211 
1212  */
1213  friend Box adjCellLo (const Box& b,
1214  int dir,
1215  int len);
1216 
1217  ///
1218  /**
1219  Returns the cell centered Box of the given length adjacent to the
1220  argument Box on the high end along the given coordinate
1221  direction. The return Box is identical to the argument Box in
1222  the other directions. The return Box and the argument Box have
1223  an empty intersection. \\
1224 
1225  NOTE: len != 0. A Negative length results in cells _inside_ the original box. \\
1226 
1227  NOTE: Box retval = adjCellHi(b,dir,len) is equivalent to the
1228  following set of operations: \\
1229 
1230  Box retval(b); \\
1231 
1232  retval.convert(dir,Box::CELL); \\
1233 
1234  retval.setrange(dir,retval.bigEnd(dir)+1,len);\\
1235 
1236  Directions are zero-based. It is an error if not 0 <= dir <
1237  SpaceDim. The neighbor of an Empty Box is an Empty Box of the
1238  appropriate type.
1239 
1240  */
1241  friend Box adjCellHi (const Box& b,
1242  int dir,
1243  int len);
1244 
1245  /// intersection functions
1246 
1247  ///
1248  /**
1249  Returns the Box that is intersection of this Box and the argument
1250  Box. Intersection is commutative. The Boxes MUST be of same
1251  type. The intersection of the Empty Box and any Box is the Empty
1252  Box.
1253 
1254  */
1255  Box operator& (const Box&) const;
1256 
1257  ///
1258  /**
1259  Modifies this Box by intersection with the argument Box. The
1260  Boxes MUST be of the same type. The intersection of the Empty
1261  Box and any Box is the Empty Box.
1262 
1263  */
1264  Box& operator&= (const Box&);
1265 
1266  ///
1267  friend Box adjCellBox (const Box& b,
1268  int dir,
1269  Side::LoHiSide a_side,
1270  int len);
1271  ///
1272  /**
1273  Modifies this Box to that of the minimum Box containing both this
1274  Box and the argument Box. Both Boxes must have identical type.
1275 
1276  */
1277  Box& minBox (const Box& b);
1278 
1279  ///
1280  /**
1281  Returns a Box that is the minimum Box containing both the
1282  argument Boxes. Both Boxes must have identical type.
1283 
1284  */
1285  friend Box minBox (const Box& b1,
1286  const Box& b2);
1287 
1288  /// grow functions
1289 
1290  ///
1291  /**
1292  Modifies this Box by growing it in all directions by given
1293  amount. The Empty Box is not modified by this function. NOTE:
1294  n_cell negative shrinks the Box by that number of cells. If
1295  shrinking produces an empty Box, the Box is transformed into the
1296  canonical Empty Box.
1297 
1298  */
1299  Box& grow (int i);
1300 
1301  ///
1302  /**
1303  Returns a Box that is the argument Box grown in all directions by
1304  given amount. The Empty Box is not modified by this function.
1305  NOTE: n_cell negative shrinks the Box by that number of cells.
1306  If shrinking produces an empty Box, the Box is transformed into
1307  the canonical Empty Box.
1308 
1309  */
1310  friend Box grow (const Box& b,
1311  int i);
1312 
1313  ///
1314  /**
1315  Modifies this Box by growing it in each direction by specified
1316  amount. The Empty Box is not modified by this function. NOTE:
1317  components of iv may be negative, which would shrink this Box. If
1318  shrinking produces an empty Box, the Box is transformed into the
1319  canonical Empty Box.
1320 
1321  */
1322  Box& grow (const IntVect& v);
1323 
1324  ///
1325  /**
1326  Returns a Box that is the argument Box grown in each
1327  direction by specified amount. The Empty Box is not modified by
1328  this function. NOTE: components of iv may be negative, which
1329  would return a shrunken Box. If shrinking produces an empty
1330  Box, the Box is transformed into the canonical Empty Box.
1331 
1332  */
1333  friend Box grow (const Box& b,
1334  const IntVect& v);
1335 
1336  ///
1337  /**
1338  Modifies this Box by growing it on the low and high end by n_cell
1339  cells in direction idir. The Empty Box is not modified by this
1340  function. NOTE: n_cell negative shrinks this Box by that number
1341  of cells. If shrinking produces an empty Box, the Box is
1342  transformed into the canonical Empty Box. Directions are
1343  zero-based. It is an error if not 0 <= dir < SpaceDim.
1344 
1345  */
1346  Box& grow (int idir,
1347  int n_cell);
1348 
1349  ///
1350  /**
1351  Modifies this Box by growing it on the low end by n_cell cells
1352  in direction idir. The Empty Box is not modified by this
1353  function. NOTE: n_cell negative shrinks this Box by that number
1354  of cells. If shrinking produces an empty Box, the Box is
1355  transformed into the canonical Empty Box. Directions are
1356  zero-based. It is an error if not 0 <= dir < SpaceDim.
1357 
1358  */
1359  Box& growLo (int idir,
1360  int n_cell=1);
1361 
1362  ///
1363  /**
1364  growLo if a_sd == Side::Lo \\
1365  growHi if a_sd= = Side::Hi
1366  */
1367  Box& growDir (int a_idir,
1368  const Side::LoHiSide& a_sd,
1369  int a_cell);
1370 
1371  ///
1372  /**
1373  Modifies this Box by growing it on the high end by n_cell cells
1374  in direction idir. The Empty Box is not modified by this
1375  function. NOTE: n_cell negative shrinks the Box by that number
1376  of cells. If shrinking produces an empty Box, the Box is
1377  transformed into the canonical Empty Box. Directions are
1378  zero-based. It is an error if not 0 <= dir < SpaceDim.
1379 
1380  */
1381  Box& growHi (int idir,
1382  int n_cell=1);
1383 
1384  /// refinement
1385 
1386  ///
1387  /**
1388  Modifies this Box by refining it by given (positive) refinement
1389  ratio. The Empty Box is not modified by this function. \\
1390 
1391  NOTE: if type(dir) = CELL centered: lo <- lo*ratio and hi <-
1392  (hi+1)*ratio - 1. \\
1393 
1394  NOTE: if type(dir) = NODE centered: lo <- lo*ratio and hi <-
1395  hi*ratio.
1396 
1397  */
1398  Box& refine (int refinement_ratio);
1399 
1400  ///
1401  /**
1402  Returns a Box that is the argument Box refined by given
1403  (positive) refinement ratio. The Empty Box is not modified by
1404  this function. \\
1405 
1406  NOTE: if type(dir) = CELL centered: lo <- lo*ratio and hi <-
1407  (hi+1)*ratio - 1.\\
1408 
1409  NOTE: if type(dir) = NODE centered: lo <- lo*ratio and hi <-
1410  hi*ratio.
1411 
1412  */
1413  friend Box refine (const Box& b,
1414  int refinement_ratio);
1415 
1416  ///
1417  /**
1418  Modifies this Box by refining it by given (positive) refinement
1419  ratio. The Empty Box is not modified by this function. \\
1420 
1421  NOTE: if type(dir) = CELL centered: lo <- lo*ratio and hi <-
1422  (hi+1)*ratio - 1.\\
1423 
1424  NOTE: if type(dir) = NODE centered: lo <- lo*ratio and hi <-
1425  hi*ratio.
1426 
1427  */
1428  Box& refine (const IntVect& refinement_ratio);
1429 
1430  ///
1431  /**
1432  Returns a Box that is the argument Box refined by given
1433  (positive) refinement ratio. The Empty Box is not modified by
1434  this function. \\
1435 
1436  NOTE: if type(dir) = CELL centered: lo <- lo*ratio and hi <-
1437  (hi+1)*ratio - 1.\\
1438 
1439  NOTE: if type(dir) = NODE centered: lo <- lo*ratio and hi <-
1440  hi*ratio.
1441 
1442  */
1443  friend Box refine (const Box& b,
1444  const IntVect& refinement_ratio);
1445 
1446  /// coarsening
1447 
1448  ///
1449  /**
1450  Modifies this Box by coarsening it by given (positive) refinement
1451  ratio. The Empty Box is not modified by this function. \\
1452 
1453  NOTE: if type(dir) = CELL centered: lo <- lo/ratio and hi <-
1454  hi/ratio.\\
1455 
1456  NOTE: if type(dir) = NODE centered: lo <- lo/ratio and hi <-
1457  hi/ratio + ((hi%ratio)==0 ? 0 : 1).\\
1458 
1459  That is, refinement of coarsened Box must contain the original
1460  Box.
1461 
1462  */
1463 
1464  Box& coarsen (int refinement_ratio);
1465 
1466  ///
1467  /**
1468  Returns a Box that is the argument Box coarsened by given
1469  (positive) refinement ratio. The Empty Box is not modified by
1470  this function. \\
1471 
1472  NOTE: if type(dir) = CELL centered: lo <- lo/ratio and hi <-
1473  hi/ratio.\\
1474 
1475  NOTE: if type(dir) = NODE centered: lo <- lo/ratio and hi <-
1476  hi/ratio + ((hi%ratio)==0 ? 0 : 1).\\
1477 
1478  That is, refinement of coarsened Box must contain the original
1479  Box.
1480 
1481  */
1482  friend Box coarsen (const Box& b,
1483  int refinement_ratio);
1484 
1485  ///
1486  /**
1487  Modifies this Box by coarsening by given (positive) refinement
1488  ratio. The Empty Box is not modified by this function. \\
1489 
1490  NOTE: if type(dir) = CELL centered: lo <- lo/ratio and hi <-
1491  hi/ratio.\\
1492 
1493  NOTE: if type(dir) = NODE centered: lo <- lo/ratio and hi <-
1494  hi/ratio + ((hi%ratio)==0 ? 0 : 1).\\
1495 
1496  That is, refinement of coarsened Box must contain the original
1497  Box.
1498 
1499  */
1500  Box& coarsen (const IntVect& refinement_ratio);
1501 
1502  ///
1503  /**
1504  Returns a Box that is the argument Box coarsened by given
1505  (positive) refinement ratio. The Empty Box is not modified by
1506  this function. \\
1507 
1508  NOTE: if type(dir) = CELL centered: lo <- lo/ratio and hi <-
1509  hi/ratio.\\
1510 
1511  NOTE: if type(dir) = NODE centered: lo <- lo/ratio and hi <-
1512  hi/ratio + ((hi%ratio)==0 ? 0 : 1).\\
1513 
1514  That is, refinement of coarsened Box must contain the original
1515  Box.
1516 
1517  */
1518  friend Box coarsen (const Box& b,
1519  const IntVect& refinement_ratio);
1520 
1521  // next(...) is out of favor. use BoxIterator.
1522  /*
1523  Step through the rectangle. It is a runtime error to give
1524  a point not inside rectangle. Iteration may not be efficient.
1525  */
1526  void next (IntVect &) const;
1527 
1528  /*
1529  Scan argument IntVect over object second arg is
1530  increment vector. Runtime error if IntVect is not
1531  contained in object Box. Iteration may not be efficient.
1532  */
1533  void next (IntVect& p,
1534  const int* shv) const;
1535 
1536  /// misc
1537 
1538  ///
1539  /**
1540  Chops the Box at the chop_pnt in the dir direction returns one
1541  Box, modifies the object Box. The union of the two is the
1542  original Box. The modified Box is the low end, the returned Box
1543  is the high end. If type(dir) = CELL, the Boxes are disjoint with
1544  the chop_pnt included in the high end (new Box). It is an ERROR
1545  if chop_pnt is the low end of the orig Box. If type(dir) = NODE,
1546  the chop_pnt is included in both Boxes but is the only point in
1547  common. It is also an error if the chop_pnt is an end node of
1548  the Box. Directions are zero-based. It is an error if not 0 <=
1549  dir < SpaceDim.
1550 
1551  */
1552  Box chop (int dir,
1553  int chop_pnt);
1554 
1555  /**
1556  Makes a_to a box that's the same as *this except that it's just one cell
1557  thick in the a_sliceSpec.direction-th direction, and its (one) coordinate
1558  in that direction is a_sliceSpec.position.
1559 
1560  If a_sliceSpec.position is outside the range of *this, and a_outofbounds
1561  isn't null, then we set *a_outofbounds to true, otherwise to false.
1562 
1563  It would be more natural to return a Box, than to set the value of a Box
1564  reference, but we do it this way to be consistent with BaseFab::degenerate()
1565  where we can't return an object because of the policy of disallowing copy
1566  constructors for heavyweight classes.
1567  */
1568  void degenerate( Box& a_to, const SliceSpec& a_sliceSpec,
1569  bool* a_outofbounds=0 ) const;
1570 
1571  ///{\bf I/O Functions}
1572 
1573  ///
1574  /**
1575  Write an ASCII representation to the ostream.
1576 
1577  */
1578  friend std::ostream& operator<< (std::ostream& os,
1579  const Box& bx);
1580 
1581  ///
1582  /**
1583  Read from istream.
1584 
1585  */
1586  friend std::istream& operator>> (std::istream& os,
1587  Box& bx);
1588 
1589  ///
1590  /**
1591  print to pout()
1592  */
1593  void p() const;
1594 
1595  ///
1596  /**
1597  Gives more detail than printOn. Useful for exiting due to an
1598  error.
1599 
1600  */
1601  void dumpOn (std::ostream& strm) const;
1602 
1603  /// {\bf Box Constants}
1604 
1605  ///
1606  /**
1607  This is a canonical empty Box of cell-centered type.
1608 
1609  */
1610  //static const Box Empty;
1611 
1612  // TheUnitBox is out of favor.
1613  /*
1614  This static member function returns a constant reference to
1615  an object of type Box representing the unit box in
1616  BL_SPACEDIM-dimensional space.
1617  */
1618 
1619  //static const Box& TheUnitBox ();
1620 
1621  //
1622  // Sets the 'len' element of the Box. Aborts on integer overflow.
1623  //
1624  void computeBoxLen ();
1625  void computeBoxLenNotEmpty();
1626 
1627  /** Doesn't print the IndexType, and uses square outer brackets. */
1628  static void setTempestOutputFormat( bool );
1629 
1630 protected:
1631  friend class HDF5Handle;
1632  //
1633  // A helper function for numPtsOK() and numPts().
1634  //
1635  bool numPtsOK (long& N) const;
1636  //
1637  // A helper function for volumeOK() and volume().
1638  //
1639  bool volumeOK (long& N) const;
1640 
1643  //IntVect len;
1645 
1647 };
1648 
1649 #include "NamespaceFooter.H"
1650 
1651 #include "BaseNamespaceHeader.H"
1652 
1653 #include "NamespaceVar.H"
1654 
1655 //Box specialization of linearSize
1656 template < >
1657 int linearSize(const CH_XDIR::Box& a_input);
1658 
1659 //Box specialization of linearIn
1660 template < >
1661 void linearIn(CH_XDIR::Box& a_outputT, const void* const a_inBuf);
1662 
1663 //Box specialization of linearOut
1664 template < >
1665 void linearOut(void* const a_outBuf, const CH_XDIR::Box& a_inputT);
1666 
1667 
1668 //Vector<Box> specialization
1669 template < >
1670 int linearSize(const Vector<CH_XDIR::Box>& a_input);
1671 template < >
1672 void linearIn(Vector<CH_XDIR::Box>& a_outputT, const void* const inBuf);
1673 template < >
1674 void linearOut(void* const a_outBuf, const Vector<CH_XDIR::Box>& a_inputT);
1675 
1676 //Vector<Vector<Box> > specialization
1677 template < >
1678 int linearSize(const Vector<Vector<CH_XDIR::Box> >& a_input);
1679 template < >
1680 void linearIn(Vector<Vector<CH_XDIR::Box> >& a_outputT, const void* const inBuf);
1681 template < >
1682 void linearOut(void* const a_outBuf, const Vector<Vector<CH_XDIR::Box> >& a_inputT);
1683 
1684 #include "BaseNamespaceFooter.H"
1685 #include "NamespaceHeader.H"
1686 
1687 // global function prototypes
1688 Box surroundingNodes (const Box& b,
1689  int dir);
1690 Box surroundingNodes (const Box& b);
1691 Box enclosedCells (const Box& b,
1692  int dir);
1693 Box enclosedCells (const Box& b);
1694 Box bdryBox(const Box& b,
1695  int dir,
1696  Side::LoHiSide a_sd,
1697  int len=1);
1698 Box bdryLo (const Box& b,
1699  int dir,
1700  int len=1);
1701 Box bdryHi (const Box& b,
1702  int dir,
1703  int len=1);
1704 Box adjCellLo (const Box& b,
1705  int dir,
1706  int len=1);
1707 Box adjCellHi (const Box& b,
1708  int dir,
1709  int len=1);
1710 Box minBox (const Box& b1,
1711  const Box& b2);
1712 Box coarsen (const Box& b,
1713  const IntVect& refinement_ratio);
1714 Box coarsen (const Box& b,
1715  int refinement_ratio);
1716 Box refine (const Box& b,
1717  const IntVect& refinement_ratio);
1718 Box refine (const Box& b,
1719  int refinement_ratio);
1720 
1721 //
1722 // Inlines.
1723 //
1724 
1725 #ifndef WRAPPER
1726 
1727 inline
1728 Box::Box (const Box& b)
1729  : smallend(b.smallend),
1730  bigend(b.bigend),
1731  btype(b.btype)
1732 {
1733 // D_EXPR6(len[0] = b.len[0],
1734 // len[1] = b.len[1],
1735 // len[2] = b.len[2]);
1736 }
1737 
1738 inline
1739 Box&
1741 {
1742  smallend = b.smallend;
1743  bigend = b.bigend;
1744  btype = b.btype;
1745 // D_EXPR6(len[0] = b.len[0],
1746 // len[1] = b.len[1],
1747 // len[2] = b.len[2]);
1748  return *this;
1749 }
1750 
1751 inline
1752 IntVect
1754 {
1755  IntVect retval;
1756  if (a_side == Side::Lo)
1757  retval = smallEnd();
1758  else
1759  retval = bigEnd();
1760  return retval;
1761 }
1762 
1763 inline
1764 const IntVect&
1766 {
1767  return smallend;
1768 }
1769 
1770 inline
1771 int
1772 Box::smallEnd (int dir) const
1773 {
1774  return smallend[dir];
1775 }
1776 
1777 inline
1778 const IntVect&
1779 Box::bigEnd () const
1780 {
1781  return bigend;
1782 }
1783 
1784 inline
1785 int
1786 Box::bigEnd (int dir) const
1787 {
1788  return bigend[dir];
1789 }
1790 
1791 inline
1792 IndexType
1793 Box::ixType () const
1794 {
1795  return btype;
1796 }
1797 
1798 inline
1799 IntVect
1800 Box::type () const
1801 {
1802  return btype.ixType();
1803 }
1804 
1805 inline
1807 Box::type (int dir) const
1808 {
1809  return btype.ixType(dir);
1810 }
1811 
1812 inline
1813 IntVect
1814 Box::size () const
1815 {
1816  return IntVect(D_DECL6(bigend[0]-smallend[0]+1,
1817  bigend[1]-smallend[1]+1,
1818  bigend[2]-smallend[2]+1,
1819  bigend[3]-smallend[3]+1,
1820  bigend[4]-smallend[4]+1,
1821  bigend[5]-smallend[5]+1));
1822 }
1823 
1824 inline
1825 int
1826 Box::size (int dir) const
1827 {
1828  // return len[dir];
1829  return bigend[dir]-smallend[dir]+1;
1830 }
1831 
1832 inline
1833 const int*
1834 Box::loVect () const
1835 {
1836  return smallend.getVect();
1837 }
1838 
1839 inline
1840 const int*
1841 Box::hiVect () const
1842 {
1843  return bigend.getVect();
1844 }
1845 
1846 inline
1847 const int*
1849 {
1850  return smallend.getVect();
1851 }
1852 
1853 inline
1854 bool
1856 {
1857  long ignore;
1858  return numPtsOK(ignore);
1859 }
1860 
1861 inline
1862 bool
1864 {
1865  // return numPts() == 0;
1866  return D_TERM6((bigend[0] < smallend[0]),
1867  || (bigend[1] < smallend[1]),
1868  || (bigend[2] < smallend[2]),
1869  || (bigend[3] < smallend[3]),
1870  || (bigend[4] < smallend[4]),
1871  || (bigend[5] < smallend[5]) );
1872 }
1873 
1874 inline
1875 bool
1876 Box::ok () const
1877 {
1878  // bool typ_ok = btype.ok();
1879  // bool len_ok = D_TERM6((len[0] == (bigend[0]-smallend[0]+1)),
1880  // && (len[1] == (bigend[1]-smallend[1]+1)),
1881  // && (len[2] == (bigend[2]-smallend[2]+1)));
1882  // return (bigend >= smallend) && len_ok && typ_ok;
1883  return (bigend >= smallend);
1884 }
1885 
1886 inline
1887 bool
1888 Box::contains (const IntVect& p) const
1889 {
1890 
1891  //return ( !isEmpty() && (p >= smallend && p <= bigend) );
1892  return (p >= smallend && p <= bigend);
1893 }
1894 
1895 inline
1896 bool
1897 Box::sameType (const Box &b) const
1898 {
1899  return btype == b.btype;
1900 }
1901 
1902 inline
1903 bool
1904 Box::contains (const Box& b) const
1905 {
1906  CH_assert(sameType(b));
1907  return ( b.isEmpty() ||
1908  (!isEmpty() && b.smallend >= smallend && b.bigend <= bigend) );
1909 }
1910 
1911 inline
1912 bool
1913 Box::sameSize (const Box& b) const
1914 {
1915  CH_assert(sameType(b));
1916  return D_TERM6(bigend[0] -smallend[0] == b.bigend[0]-b.smallend[0],
1917  && bigend[1] -smallend[1] == b.bigend[1]-b.smallend[1],
1918  && bigend[2] -smallend[2] == b.bigend[2]-b.smallend[2],
1919  && bigend[3] -smallend[3] == b.bigend[3]-b.smallend[3],
1920  && bigend[4] -smallend[4] == b.bigend[4]-b.smallend[4],
1921  && bigend[5] -smallend[5] == b.bigend[5]-b.smallend[5]);
1922 }
1923 
1924 inline
1925 bool
1926 Box::operator== (const Box& b) const
1927 {
1928  return smallend == b.smallend && bigend == b.bigend && b.btype == btype;
1929 }
1930 
1931 inline
1932 bool
1933 Box::operator!= (const Box& b) const
1934 {
1935  return !operator==(b);
1936 }
1937 
1938 inline
1939 bool
1941 {
1942  return !btype.any();
1943 }
1944 
1945 inline
1946 bool
1948 {
1949  return numPtsOK();
1950 }
1951 
1952 inline
1953 long
1954 Box::index (const IntVect& v) const
1955 {
1956  long result = v.vect[0]-smallend.vect[0];
1957 #if CH_SPACEDIM == 1
1958  // nothing more goes here
1959 #elif CH_SPACEDIM==2
1960  int len0=(bigend[0]-smallend[0]+1);
1961  result += len0*(v.vect[1]-smallend.vect[1]);
1962 #elif CH_SPACEDIM==3
1963  int len0=(bigend[0]-smallend[0]+1);
1964  int len1=(bigend[1]-smallend[1]+1);
1965  result += len0*(v.vect[1]-smallend.vect[1]
1966  +(v.vect[2]-smallend.vect[2])*len1);
1967 #elif CH_SPACEDIM==4
1968  int len0=(bigend[0]-smallend[0]+1);
1969  int len1=(bigend[1]-smallend[1]+1);
1970  int len2=(bigend[2]-smallend[2]+1);
1971  result += len0*((v.vect[1]-smallend.vect[1])
1972  +len1*((v.vect[2]-smallend.vect[2])
1973  +len2*(v.vect[3]-smallend[3])));
1974 #elif CH_SPACEDIM==5
1975  int len0=(bigend[0]-smallend[0]+1);
1976  int len1=(bigend[1]-smallend[1]+1);
1977  int len2=(bigend[2]-smallend[2]+1);
1978  int len3=(bigend[3]-smallend[3]+1);
1979  result += len0*(v.vect[1]-smallend.vect[1]
1980  +len1*(v.vect[2]-smallend.vect[2]
1981  +len2*(v.vect[3]-smallend[3]
1982  +len3*(v.vect[4]-smallend[4]))));
1983 #elif CH_SPACEDIM==6
1984  int len0=(bigend[0]-smallend[0]+1);
1985  int len1=(bigend[1]-smallend[1]+1);
1986  int len2=(bigend[2]-smallend[2]+1);
1987  int len3=(bigend[3]-smallend[3]+1);
1988  int len4=(bigend[4]-smallend[4]+1);
1989  result += len0*(v.vect[1]-smallend.vect[1]
1990  +len1*(v.vect[2]-smallend.vect[2]
1991  +len2*(v.vect[3]-smallend[3]
1992  +len3*(v.vect[4]-smallend[4]
1993  +len4*(v.vect[5]-smallend[5])))));
1994 
1995 #else
1996  DIM > 6 undefined!
1997 #endif
1998  return result;
1999 }
2000 
2001 inline
2002 void
2004 {
2005 // if (isEmpty())
2006 // {
2007 // len = IntVect::Zero;
2008 // }
2009 // else
2010 // {
2011 // D_EXPR6(len[0] = bigend[0]-smallend[0] + 1,
2012 // len[1] = bigend[1]-smallend[1] + 1,
2013 // len[2] = bigend[2]-smallend[2] + 1);
2014 // }
2015 }
2016 
2017 inline
2018 void
2020 {
2021 // D_EXPR6(len[0] = bigend[0]-smallend[0] + 1,
2022 // len[1] = bigend[1]-smallend[1] + 1,
2023 // len[2] = bigend[2]-smallend[2] + 1);
2024 }
2025 
2026 inline
2027 Box&
2029 {
2030  CH_assert (sm <= bigend);
2031 
2032  smallend = sm;
2033  computeBoxLen();
2034  return *this;
2035 }
2036 
2037 inline
2038 Box&
2039 Box::setSmall (int dir,
2040  int sm_index)
2041 {
2042  CH_assert (sm_index <= bigend[dir]);
2043 
2044  smallend.setVal(dir,sm_index);
2045  computeBoxLen();
2046  return *this;
2047 }
2048 
2049 inline
2050 Box&
2052 {
2053  CH_assert (bg >= smallend);
2054 
2055  bigend = bg;
2056  computeBoxLen();
2057  return *this;
2058 }
2059 
2060 inline
2061 Box&
2062 Box::setBig (int dir,
2063  int bg_index)
2064 {
2065  CH_assert (bg_index >= smallend[dir]);
2066 
2067  bigend.setVal(dir,bg_index);
2068  computeBoxLen();
2069  return *this;
2070 }
2071 
2072 inline
2073 Box&
2074 Box::setRange (int dir,
2075  int sm_index,
2076  int n_cells)
2077 {
2078  CH_assert (n_cells > 0);
2079 
2080  smallend.setVal(dir,sm_index);
2081  bigend.setVal(dir,sm_index+n_cells-1);
2082  computeBoxLen();
2083  return *this;
2084 }
2085 
2086 inline
2087 Box&
2088 Box::shift (int dir,
2089  int nzones)
2090 {
2091  if (!isEmpty())
2092  {
2093  smallend.shift(dir,nzones);
2094  bigend.shift(dir,nzones);
2095  }
2096  return *this;
2097 }
2098 
2099 inline
2100 Box&
2101 Box::shift (const IntVect& iv)
2102 {
2103  if (!isEmpty())
2104  {
2105  smallend.shift(iv);
2106  bigend.shift(iv);
2107  }
2108  return *this;
2109 }
2110 
2111 inline
2112 Box&
2113 Box::convert (const IntVect& typ)
2114 {
2115  CH_assert(typ >= IntVect::Zero && typ <= IntVect::Unit);
2116  if (!isEmpty())
2117  {
2118  IntVect shft(typ - btype.ixType());
2119  bigend += shft;
2120  }
2121  btype = IndexType(typ);
2122  computeBoxLen();
2123  return *this;
2124 }
2125 
2126 inline
2127 Box&
2129 {
2130  if (!(btype[dir]))
2131  {
2132  if (!isEmpty())
2133  {
2134  bigend.shift(dir,1);
2135  }
2136  //
2137  // Set dir'th bit to 1 = IndexType::NODE.
2138  //
2139  btype.set(dir);
2140  computeBoxLen();
2141  }
2142  return *this;
2143 }
2144 
2145 inline
2146 Box&
2148 {
2149  if (btype[dir])
2150  {
2151  if (!isEmpty())
2152  {
2153  bigend.shift(dir,-1);
2154  }
2155  //
2156  // Set dir'th bit to 0 = IndexType::CELL.
2157  //
2158  btype.unset(dir);
2159  computeBoxLen();
2160  }
2161  return *this;
2162 }
2163 
2164 inline
2165 Box
2167  int dir)
2168 {
2169  Box bx(b);
2170  return bx.surroundingNodes(dir);
2171 }
2172 
2173 inline
2174 Box
2176 {
2177  Box bx(b);
2178  return bx.surroundingNodes();
2179 }
2180 
2181 inline
2182 Box
2183 enclosedCells (const Box& b,
2184  int dir)
2185 {
2186  Box bx(b);
2187  return bx.enclosedCells(dir);
2188 }
2189 
2190 inline
2191 Box
2192 enclosedCells (const Box& b)
2193 {
2194  Box bx(b);
2195  return bx.enclosedCells();
2196 }
2197 
2198 inline
2199 Box&
2201 {
2202  if (!isEmpty())
2203  {
2204  smallend += v;
2205  bigend += v;
2206  }
2207  return *this;
2208 }
2209 
2210 inline
2211 Box
2212 Box::operator+ (const IntVect& v) const
2213 {
2214  if (isEmpty())
2215  {
2216  return(Box().convert(btype));
2217  }
2218  else
2219  {
2220  IntVect small(smallend);
2221  small += v;
2222  IntVect big(bigend);
2223  big += v;
2224  return Box(small,big,btype);
2225  }
2226 }
2227 
2228 inline
2229 Box&
2231 {
2232  if (!isEmpty())
2233  {
2234  smallend -= v;
2235  bigend -= v;
2236  }
2237  return *this;
2238 }
2239 
2240 inline
2241 bool
2242 Box::operator < (const Box& rhs) const
2243 {
2244  if (smallend == rhs.smallend) return bigend.lexLT(rhs.bigend);
2245  return(!isEmpty() && (rhs.isEmpty() || smallend.lexLT(rhs.smallend)));
2246 }
2247 
2248 inline
2249 Box
2250 Box::operator- (const IntVect& v) const
2251 {
2252  if (isEmpty())
2253  {
2254  return(Box().convert(btype));
2255  }
2256  else
2257  {
2258  IntVect small = smallend;
2259  small -= v;
2260  IntVect big = bigend;
2261  big -= v;
2262  return Box(small,big,btype);
2263  }
2264 }
2265 
2266 inline
2267 Box&
2268 Box::grow (int i)
2269 {
2270  if (!isEmpty())
2271  {
2272  smallend.diagShift(-i);
2273  bigend.diagShift(i);
2274  if (!(bigend >= smallend)) *this = Box().convert(btype);
2275  computeBoxLen();
2276  }
2277  return *this;
2278 }
2279 
2280 inline
2281 Box
2282 grow (const Box& b,
2283  int i)
2284 {
2285  if (b.isEmpty())
2286  {
2287  return Box().convert(b.btype);
2288  }
2289 
2290  IntVect small = diagShift(b.smallend,-i);
2291  IntVect big = diagShift(b.bigend,i);
2292  if (!(big >= small))
2293  {
2294  return Box().convert(b.btype);
2295  }
2296  return Box(small,big,b.btype);
2297 }
2298 
2299 inline
2300 Box&
2301 Box::grow (const IntVect& v)
2302 {
2303  if (!isEmpty())
2304  {
2305  smallend -= v;
2306  bigend += v;
2307  if (!(bigend >= smallend)) *this = Box().convert(btype);
2308  computeBoxLen();
2309  }
2310  return *this;
2311 }
2312 
2313 inline
2314 Box
2315 grow (const Box& b,
2316  const IntVect& v)
2317 {
2318  if (b.isEmpty())
2319  {
2320  return Box().convert(b.btype);
2321  }
2322  else
2323  {
2324  IntVect small = b.smallend - v;
2325  IntVect big = b.bigend + v;
2326  if (!(big >= small))
2327  {
2328  return Box().convert(b.btype);
2329  }
2330  else
2331  {
2332  return Box(small,big,b.btype);
2333  }
2334  }
2335 }
2336 
2337 inline
2338 Box&
2339 Box::grow (int idir,
2340  int n_cell)
2341 {
2342  if (!isEmpty())
2343  {
2344  smallend.shift(idir, -n_cell);
2345  bigend.shift(idir, n_cell);
2346  if (!(bigend >= smallend)) *this = Box().convert(btype);
2347  computeBoxLen();
2348  }
2349  return *this;
2350 }
2351 
2352 inline
2353 Box&
2354 Box::growLo (int idir,
2355  int n_cell)
2356 {
2357  if (!isEmpty())
2358  {
2359  smallend.shift(idir, -n_cell);
2360  if (!(bigend >= smallend)) *this = Box().convert(btype);
2361  computeBoxLen();
2362  }
2363  return *this;
2364 }
2365 
2366 inline
2367 Box&
2368 Box::growDir (int idir,
2369  const Side::LoHiSide& a_sd,
2370  int n_cell)
2371 {
2372  if (a_sd == Side::Lo)
2373  {
2374  growLo(idir, n_cell);
2375  }
2376  else
2377  {
2378  growHi(idir, n_cell);
2379  }
2380  return *this;
2381 }
2382 
2383 inline
2384 Box&
2385 Box::growHi (int idir,
2386  int n_cell)
2387 {
2388  if (!isEmpty())
2389  {
2390  bigend.shift(idir,n_cell);
2391  if (!(bigend >= smallend)) *this = Box().convert(btype);
2392  computeBoxLen();
2393  }
2394  return *this;
2395 }
2396 
2397 inline
2398 Box
2399 Box::operator& (const Box& rhs) const
2400 {
2401  Box lhs(*this);
2402  return lhs &= rhs;
2403 }
2404 
2405 #endif /* WRAPPER */
2406 
2407 #include "NamespaceFooter.H"
2408 #endif /*CH_BOX_H*/
#define D_DECL6(a, b, c, d, e, f)
Definition: CHArray.H:39
Definition: Box.H:52
Box & operator=(const Box &b)
{ Modification Functions}
Definition: Box.H:1740
Box & operator-=(const IntVect &v)
Definition: Box.H:2230
void unset(int dir)
Definition: Box.H:334
bool operator<(const Box &rhs) const
Definition: Box.H:2242
C::self_type operator-(const C &, const C &)
Definition: GenericArithmeticI.H:128
const int * getVect() const
Definition: IntVect.H:758
IntVect size() const
size functions
Definition: Box.H:1814
const int * hiVect() const
Definition: Box.H:1841
#define D_TERM6(a, b, c, d, e, f)
Definition: CHArray.H:40
bool operator!=(const Box &b) const
Definition: Box.H:1933
#define CH_SPACEDIM
Definition: SPACE.H:52
#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:1926
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:1848
bool cellCentered() const
Definition: Box.H:1940
bool sameSize(const Box &b) const
Definition: Box.H:1913
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:52
Box operator &(const Box &) const
intersection functions
friend std::ostream & operator<<(std::ostream &os, const IndexType &itype)
const int * loVect() const
Definition: Box.H:1834
void clear()
Definition: Box.H:355
IndexType btype
Definition: Box.H:1644
Definition: SliceSpec.H:42
void flip(int i)
Definition: Box.H:376
IndexTM< T, N > diagShift(const IndexTM< T, N > &a_p, T a_s)
Definition: IndexTMI.H:390
IntVect type() const
Definition: Box.H:1800
bool contains(const IntVect &p) const
Definition: Box.H:1888
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:2250
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:1753
void p() const
Box & enclosedCells()
void setVal(int i, int val)
Definition: IntVect.H:734
Box minBox(const Box &b1, const Box &b2)
void setType(int dir, CellIndex t)
Definition: Box.H:418
bool numPtsOK() const
Definition: Box.H:1855
const IntVect & bigEnd() const
Definition: Box.H:1779
C::self_type operator+(const C &, const C &)
Definition: GenericArithmeticI.H:124
IntVect & shift(int coord, int s)
Definition: IntVect.H:1086
IntVect bigend
Definition: Box.H:1642
Box & setSmall(const IntVect &sm)
Definition: Box.H:2028
IntVect ixType() const
Definition: Box.H:440
static const IntVect Unit
Definition: IntVect.H:632
Definition: Box.H:51
static IndexType TheNodeType()
const IntVect & smallEnd() const
{ Accessors}
Definition: Box.H:1765
Box surroundingNodes(const Box &b, int dir)
Definition: Box.H:2166
IndexType ixType() const
centering
Definition: Box.H:1793
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:2368
Box grow(const Box &b, int i)
Definition: Box.H:2282
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:2183
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:2074
IntVect smallend
Definition: Box.H:1641
static const IntVect Zero
Definition: IntVect.H:627
Box adjCellHi(const Box &b, int dir, int len=1)
bool sameType(const Box &b) const
Definition: Box.H:1897
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
IntVect & diagShift(int s)
Definition: IntVect.H:1104
long index(const IntVect &v) const
Definition: Box.H:1954
int linearSize(const CH_XDIR::Box &a_input)
void setall()
Definition: Box.H:348
static bool s_tempestOutputFormat
Definition: Box.H:1646
CellIndex ixType(int dir) const
Definition: Box.H:426
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:267
int vect[SpaceDim]
Definition: IntVect.H:655
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:2003
bool operator==(const IndexType &t) const
Definition: Box.H:383
Box & shift(int dir, int nzones)
shift functions
Definition: Box.H:2088
static unsigned char mask(int k)
Definition: Box.H:276
Box & operator+=(const IntVect &v)
Definition: Box.H:2200
bool cellCentered() const
Definition: Box.H:404
Box & grow(int i)
grow functions
Definition: Box.H:2268
Box & setBig(const IntVect &bg)
Definition: Box.H:2051
Box & growLo(int idir, int n_cell=1)
Definition: Box.H:2354
Box bdryHi(const Box &b, int dir, int len=1)
Box operator+(const IntVect &v) const
Definition: Box.H:2212
CellIndex
Definition: Box.H:49
IndexType & operator=(const IndexType &rhs)
Definition: Box.H:296
void computeBoxLenNotEmpty()
Definition: Box.H:2019
bool isEmpty() const
{ Comparison Functions}
Definition: Box.H:1863
bool ok() const
Definition: Box.H:1876
bool any() const
Definition: Box.H:362
Box bdryLo(const Box &b, int dir, int len=1)
~Box()
Definition: Box.H:483
bool operator<(const IndexType &t) const
Definition: Box.H:390
Box & growHi(int idir, int n_cell=1)
Definition: Box.H:2385
bool volumeOK() const
Definition: Box.H:1947
int operator[](int dir) const
Definition: Box.H:433
bool lexLT(const IntVect &s) const
Definition: IntVect.H:814