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