Chombo + EB  3.2
IntVect.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 _INTVECT_H_
12 #define _INTVECT_H_
13 
14 #include <cstddef>
15 #include <cstdlib>
16 #include <cstring>
17 #include <iostream>
18 #include "SPACE.H"
19 #include "Vector.H"
20 #include "IndexTM.H"
21 #include <cstdint>
22 #include "SPMD.H"
23 #include "Misc.H"
24 #include <functional>
25 
26 namespace BLfacade
27 {
28  class IntVect;
29 }
30 
31 #include "NamespaceHeader.H"
32 
33 
34 //template<typename T, int n>
35 //class IndexTM;
36 
37 class HDF5Handle;
38 
39 /// An integer Vector in SpaceDim-dimensional space
40 /**
41  The class IntVect is an implementation of an integer vector in a
42  SpaceDim-dimensional space. It represents a point in a discrete space.
43  IntVect values are accessed using the operator[] function, as for a normal
44  C++ array. In addition, the basic arithmetic operators have been overloaded
45  to implement scaling and translation operations.
46 */
47 
48 class IntVect
49 {
50 public:
51 
52  /**
53  \name Constructors and Accessors
54  */
55  /*@{*/
56 
57 
58  ///
59  /**
60  Construct an IntVect whose components are uninitialized.
61  */
62  inline
64  {}
65 
66  explicit IntVect( const Vector<int>& vi)
67  {
68  D_EXPR6(vect[0]=vi[0], vect[1]=vi[1], vect[2] = vi[2],
69  vect[3]=vi[3], vect[4]=vi[4], vect[5] = vi[5]);
70  }
71 
72  ///
73  /**
74  Destructor. Let the compiler build the default destructor (bvs)
75  */
76  //~IntVect()
77  // {}
78 
79  ///
80  /**
81  Construct an IntVect given the specific values for its
82  coordinates. D_DECL6 is a macro that sets the constructor to
83  take CH_SPACEDIM arguments.
84  */
85  explicit IntVect (D_DECL6(int i, int j, int k,
86  int l, int m, int n));
87 
88  ///
89  /**
90  Construct an IntVect setting the coordinates to the corresponding
91  values in the integer array <i>a</i>.
92  */
93  explicit IntVect (const int* a);
94 
95  ///
96  /**
97  The copy constructor. let compiler build default copy constructor (bvs)
98  */
99  // IntVect (const IntVect& rhs);
100 
101  IntVect (const IndexTM<int, CH_SPACEDIM>& a_tm);
102 
103  IntVect copy() const
104  {
105  return *this;
106  }
107  ///
108  /**
109  The assignment operator. Let compiler build default assign operator
110  */
111  // IntVect& operator= (const IntVect& rhs);
112 
113  ///
114  /**
115  Returns a modifiable lvalue reference to the <i>i</i>'th coordinate of the
116  IntVect.
117  */
118  inline
119  int& operator[] (int i);
120 
121  ///
122  /**
123  Returns the <i>i</i>'th coordinate of the IntVect.
124  */
125  inline
126  int operator[] (int i) const;
127 
128  ///
129  /**
130  Set <i>i</i>'th coordinate of IntVect to <i>val</i>.
131  */
132  void setVal (int i,
133  int val);
134 
135  /*@}*/
136 
137  /**
138  \name Data pointer functions
139  */
140  /*@{*/
141 
142  ///
143  /**
144  Returns a const pointer to an array of coordinates of the IntVect.
145  Useful for arguments to FORTRAN calls.
146  */
147  const int* getVect () const;
148 
149  ///
150  /**
151  Only for sending to Fortran
152  */
153  const int* dataPtr() const;
154 
155  ///
156  /**
157  Only for sending to Fortran
158  */
159  int* dataPtr();
160 
161  /*@}*/
162 
163  /**
164  \name Comparison Operators
165  */
166  /*@{*/
167 
168  ///
169  /**
170  Returns true if this IntVect is equivalent to argument IntVect. All
171  comparisons between analogous components must be satisfied.
172  */
173  bool operator== (const IntVect& p) const;
174 
175  ///
176  /**
177  Returns true if this IntVect is different from argument IntVect.
178  All comparisons between analogous components must be satisfied.
179  */
180  bool operator!= (const IntVect& p) const;
181 
182  ///
183  /**
184  Returns true if this IntVect is less than argument IntVect. All
185  comparisons between analogous components must be satisfied. Note
186  that, since the comparison is component-wise, it is possible for
187  an IntVect to be neither greater than, less than, nor equal to
188  another.
189  */
190  bool operator< (const IntVect& p) const;
191 
192  ///
193  /**
194  Returns true if this IntVect is less than or equal to argument
195  IntVect. All comparisons between analogous components must be
196  satisfied. Note that, since the comparison is component-wise, it
197  is possible for an IntVect to be neither greater than or equal
198  to, less than or equal to, nor equal to another.
199  */
200  bool operator<= (const IntVect& p) const;
201 
202  ///
203  /**
204  Returns true if this IntVect is greater than argument IntVect.
205  All comparisons between analogous components must be satisfied.
206  Note that, since the comparison is component-wise, it is possible
207  for an IntVect to be neither greater than, less than, nor equal
208  to another.
209  */
210  bool operator> (const IntVect& p) const;
211 
212  ///
213  /**
214  Returns true if this IntVect is greater than or equal to argument
215  IntVect. All comparisons between analogous components must be
216  satisfied. Note that, since the comparison is component-wise, it
217  is possible for an IntVect to be neither greater than or equal
218  to, less than or equal to, nor equal to another.
219  */
220 
221  bool operator>= (const IntVect& p) const;
222 
223  ///
224  /**
225  Returns true if this IntVect is lexically less than the argument.
226  An IntVect MUST BE either lexically less than, lexically greater
227  than, or equal to another IntVect.
228 
229  iv1 is lexically less than iv2 if:
230 
231  in 2-D:<br>
232  (iv1[0] < iv2[0]) || ((iv1[0] == iv2[0]) && (iv1[1] < iv2[1]));
233 
234  in 3-D:<br>
235  (iv1[0] < iv2[0]) || (iv1[0]==iv2[0] && ((iv1[1] < iv2[1] || ((iv1[1] == iv2[1]) && (iv1[2] < iv2[2])))));
236  */
237  bool lexLT (const IntVect& s) const;
238 
239  ///
240  /**
241  Returns true if this IntVect is lexically greater than the
242  argument. An IntVect MUST BE either lexically less than,
243  lexically greater than, or equal to another IntVect.
244 
245  iv1 is lexically less than iv2 if:
246 
247  in 2-D:<br>
248  (iv1[0] > iv2[0]) || ((iv1[0] == iv2[0]) && (iv1[1] > iv2[1]));
249 
250  in 3-D:<br>
251  (iv1[0] > iv2[0]) || (iv1[0]==iv2[0] && ((iv1[1] > iv2[1] || ((iv1[1] == iv2[1]) && (iv1[2] > iv2[2])))));
252  */
253  bool lexGT (const IntVect& s) const;
254 
255  /*@}*/
256 
257  /**
258  \name Unary operators
259  */
260  /*@{*/
261 
262  ///
263  /**
264  Unary plus -- for completeness.
265  */
266  IntVect operator+ () const;
267 
268  ///
269  /**
270  Unary minus -- negates all components of this IntVect.
271  */
272  IntVect operator- () const;
273 
274  ///
275  /**
276  Sum of all components of this IntVect.
277  */
278  int sum () const;
279 
280  ///
281  /**
282  Product of all components of this IntVect.
283  */
284  int product () const;
285 
286  /*@}*/
287 
288  /**
289  \name Addition operators
290  */
291  /*@{*/
292 
293  ///
294  /**
295  Modifies this IntVect by addition of a scalar to each component.
296  */
297  IntVect& operator+= (int s);
298 
299  ///
300  /**
301  Modifies this IntVect by component-wise addition with argument.
302  */
303  IntVect& operator+= (const IntVect& p);
304 
305  ///
306  /**
307  Returns component-wise sum of this IntVect and argument.
308  */
309  IntVect operator+ (const IntVect& p) const;
310 
311  ///
312  /**
313  Return an IntVect that is this IntVect with a scalar added to
314  each component.
315  */
316  IntVect operator+ (int s) const;
317 
318  ///
319  /**
320  Returns an IntVect that is an IntVect <i>p</i>
321  with a scalar <i>s</i> added to each component.
322  */
323  friend inline IntVect operator+ (int s,
324  const IntVect& p);
325 
326  /*@}*/
327 
328  /**
329  \name Subtraction operators
330  */
331  /*@{*/
332 
333  ///
334  /**
335  Modifies this IntVect by subtraction of a scalar from each
336  component.
337  */
338  IntVect& operator-= (int s);
339 
340  ///
341  /**
342  Modifies this IntVect by component-wise subtraction by argument.
343  */
344  IntVect& operator-= (const IntVect& p);
345 
346  ///
347  /**
348  Returns an IntVect that is this IntVect with <i>p</i> subtracted
349  from it component-wise.
350  */
351  IntVect operator- (const IntVect& p) const;
352 
353  ///
354  /**
355  Returns an IntVect that is this IntVect with a scalar <i>s</i> subtracted
356  from each component.
357  */
358  IntVect operator- (int s) const;
359 
360  ///
361  /**
362  Returns <i>s - p</i>.
363  */
364  friend inline IntVect operator- (int s,
365  const IntVect& p);
366 
367  /*@}*/
368 
369  /**
370  \name Multiplication operators
371  */
372  /*@{*/
373 
374  ///
375  /**
376  Modifies this IntVect by multiplication of each component by
377  a scalar.
378  */
379  IntVect& operator*= (int s);
380 
381  ///
382  /**
383  Modifies this IntVect by component-wise multiplication by argument.
384  */
385  IntVect& operator*= (const IntVect& p);
386 
387  ///
388  /**
389  Returns component-wise product of this IntVect with argument.
390  */
391  IntVect operator* (const IntVect& p) const;
392 
393  ///
394  /**
395  Returns an IntVect that is this IntVect with each component
396  multiplied by a scalar.
397  */
398  IntVect operator* (int s) const;
399 
400  ///
401  /**
402  Returns an IntVect that is an IntVect <i>p</i> with each component
403  multiplied by a scalar <i>s</i>.
404  */
405  friend inline IntVect operator* (int s,
406  const IntVect& p);
407 
408  /*@}*/
409 
410  /**
411  \name Division operators
412  */
413  /*@{*/
414 
415  ///
416  /**
417  Modifies this IntVect by division of each component by a scalar.
418  */
419  IntVect& operator/= (int s);
420 
421  ///
422  /**
423  Modifies this IntVect by component-wise division by IntVect
424  argument.
425  */
426  IntVect& operator/= (const IntVect& p);
427 
428  ///
429  /**
430  Returns component-wise quotient of this IntVect by argument.
431  */
432  IntVect operator/ (const IntVect& p) const;
433 
434  ///
435  /**
436  Returns an IntVect that is this IntVect with each component
437  divided by a scalar.
438  */
439  IntVect operator/ (int s) const;
440 
441  /*@}*/
442 
443  /**
444  \name Other arithmetic operators
445  */
446  /*@{*/
447 
448  ///
449  /**
450  Modifies this IntVect by taking component-wise min with IntVect
451  argument.
452  */
453  IntVect& min (const IntVect& p);
454 
455  ///
456  /**
457  Returns the IntVect that is the component-wise minimum of two
458  argument IntVects.
459  */
460  friend inline IntVect min (const IntVect& p1,
461  const IntVect& p2);
462 
463  ///
464  /**
465  Modifies this IntVect by taking component-wise max with IntVect
466  argument.
467  */
468  IntVect& max (const IntVect& p);
469 
470  ///return the maximum value in the intvect
471  int max() const
472  {
473  int retval = vect[0];
474  for(int idir = 1; idir < SpaceDim; idir++)
475  {
476  retval = Max(retval, vect[idir]);
477  }
478  return retval;
479  }
480 
481  ///return the minimum value in the intvect
482  int min() const
483  {
484  int retval = vect[0];
485  for(int idir = 1; idir < SpaceDim; idir++)
486  {
487  retval = Min(retval, vect[idir]);
488  }
489  return retval;
490  }
491 
492  ///
493  /**
494  Returns the IntVect that is the component-wise maximum of two
495  argument IntVects.
496  */
497  friend inline IntVect max (const IntVect& p1,
498  const IntVect& p2);
499 
500  ///
501  /**
502  Modifies this IntVect by multiplying each component by a scalar.
503  */
504  IntVect& scale (int s);
505 
506  ///
507  /**
508  Returns an IntVect obtained by multiplying each of the components
509  of the given IntVect by a scalar.
510  */
511  friend inline IntVect scale (const IntVect& p,
512  int s);
513 
514  /// Returns the componentwise absolute value of the given IntVect.
515  friend const IntVect absolute(const IntVect& p);
516 
517  ///
518  /**
519  Modifies IntVect by reflecting it in the plane defined by the
520  index <i>ref_ix</i> and with normal in the direction of <i>idir</i>.
521  Directions are based at zero.
522  */
523  IntVect& reflect (int ref_ix,
524  int idir);
525 
526  ///
527  /**
528  Returns an IntVect that is the reflection of the given IntVect in
529  the plane which passes through <i>ref_ix</i> and normal to the
530  coordinate direction idir.
531  */
532  friend inline IntVect reflect(const IntVect& a,
533  int ref_ix,
534  int idir);
535 
536  ///
537  /**
538  Modifies this IntVect by adding <i>s</i> to component in given coordinate
539  direction.
540  */
541  IntVect& shift (int coord,
542  int s);
543 
544  ///
545  /**
546  Modifies this IntVect by component-wise addition with IntVect
547  argument.
548  */
549  IntVect& shift (const IntVect& iv);
550 
551  ///
552  /**
553  Modifies this IntVect by adding a scalar <i>s</i> to each component.
554 
555  */
556  IntVect& diagShift (int s);
557 
558  ///
559  /**
560  Returns IntVect obtained by adding a scalar to each of the
561  components of the given IntVect.
562  */
563  friend inline IntVect diagShift (const IntVect& p,
564  int s);
565 
566  ///
567  /**
568  Modify IntVect by component-wise integer projection.
569  */
570  IntVect& coarsen (const IntVect& p);
571 
572  ///
573  /**
574  Modify IntVect by component-wise integer projection.
575  */
576  IntVect& coarsen (int p);
577 
578  ///
579  /**
580  Returns an IntVect that is the component-wise integer projection of
581  <i>p</i> by <i>s</i>.
582  */
583  friend inline IntVect coarsen (const IntVect& p,
584  int s);
585 
586  ///
587  /**
588  Returns an IntVect which is the component-wise integer projection
589  of IntVect <i>p1</i> by IntVect <i>p2</i>.
590  */
591  friend inline IntVect coarsen (const IntVect& p1,
592  const IntVect& p2);
593 
594  /*@}*/
595 
596  /**
597  \name I/O Functions
598  */
599  /*@{*/
600 
601  ///
602  /**
603  Print an IntVect to the ostream.
604  */
605  void printOn (std::ostream& os) const;
606 
607  ///
608  /**
609  Print an IntVect to the pout().
610  */
611  void p() const;
612 
613  ///
614  /**
615  Print an IntVect to the ostream a bit more verbosely.
616  */
617  void dumpOn (std::ostream& os) const;
618 
619  ///
620  /**
621  Print the IntVect to given output stream in ASCII.
622  */
623  friend std::ostream& operator<< (std::ostream& os,
624  const IntVect& iv);
625 
626  ///
627  /**
628  Read next IntVect from given input stream.
629  */
630  friend std::istream& operator>> (std::istream& os,
631  IntVect& iv);
632 
633  /*@}*/
634 
635  /**
636  \name Constants
637  */
638  /*@{*/
639 
640  ///
641  /**
642  Returns a basis vector in the given coordinate direction.<br>
643  In 3-D:
644  BASISV(0) == (1,0,0); BASISV(1) == (0,1,0); BASISV(2) == (0,0,1).<br>
645  In 2-D:
646  BASISV(0) == (1,0); BASISV(1) == (0,1).<br>
647  Note that the coordinate directions are based at zero.
648  */
649  friend inline IntVect BASISV (int dir);
650 
651  /**
652  This is an IntVect all of whose components are equal to zero.
653  */
654  static const IntVect Zero;
655 
656  /**
657  This is an IntVect all of whose components are equal to one.
658  */
659  static const IntVect Unit;
660 
661  /**
662  Initializes Zero and Unit.
663  */
664  static int InitStatics();
665 
666  /*@}*/
667 
668  static size_t io_offset;
669 
670  inline uint64_t hash(const IntVect& origin, const IntVect& blockingFactor) const;
671 
672 protected:
673  //
674  // Box is a friend of ours.
675  //
676  friend class Box;
677 
678  friend class HDF5Handle;
679  friend class VolIndex;
680  friend class FaceIndex;
681  friend class BLfacade::IntVect;
682 
683  /**
684  The individual components of this IntVect.
685  */
687 
688  /**
689  Number of bytes of storage used by this IntVect.
690  */
691  static const size_t IntVectSize;
692  static const uint32_t morton256_x[256];
693  static const uint32_t morton256_y[256];
694  static const uint32_t morton256_z[256];
695 
696 };
697 #include "NamespaceFooter.H"
698 
699 namespace std { template <> inline bool less<CH_XD::IntVect>::operator()(const CH_XD::IntVect& a, const CH_XD::IntVect& b) const { return a.lexLT(b);}
700 }
701 #include "BaseNamespaceHeader.H"
702 
703 #include "NamespaceVar.H"
704 
705 ///functions for linearization
706 template < >
707 int linearSize(const CH_XDIR::IntVect& a_iv);
708 
709 ///functions for linearization
710 template < >
711 void linearIn(CH_XDIR::IntVect& a_iv, const void* a_inBuf);
712 
713 ///functions for linearization
714 template < >
715 void linearOut(void* a_outBuf, const CH_XDIR::IntVect& a_iv);
716 
717 //Vector<IntVect> specialization
718 template < >
719 int linearSize(const Vector<CH_XDIR::IntVect>& a_input);
720 template < >
721 void linearIn(Vector<CH_XDIR::IntVect>& a_outputT, const void* const inBuf);
722 template < >
723 void linearOut(void* const a_outBuf, const Vector<CH_XDIR::IntVect>& a_inputT);
724 
725 //Vector<Vector<IntVect> > specialization
726 template < >
727 int linearSize(const Vector<Vector<CH_XDIR::IntVect> >& a_input);
728 template < >
729 void linearIn(Vector<Vector<CH_XDIR::IntVect> >& a_outputT, const void* const inBuf);
730 template < >
731 void linearOut(void* const a_outBuf, const Vector<Vector<CH_XDIR::IntVect> >& a_inputT);
732 
733 #include "BaseNamespaceFooter.H"
734 
735 #include "NamespaceHeader.H"
736 
737 
738 //
739 // Static initialization. Gotta make sure there are no static object
740 // definitions above here (except possibly stuff in headers). Otherwise,
741 // the danger is that some static object's constructor calls IntVect::Zero or
742 // IntVect::Unit -- the very things the following definition is supposed to
743 // initialize.
744 //
746 
747 #ifndef WRAPPER
748 //
749 // Inlines.
750 //
751 
752 // try uninitialized IntVect null construction for now.....
753 
754 // inline
755 // IntVect::IntVect ()
756 // {
757 // D_EXPR6(vect[0] = 0, vect[1] = 0, vect[2] = 0);
758 // }
759 
760 //template <> inline constexpr bool std::less<IntVect>::operator()(const IntVect& a, const IntVect& b) const { return a.lexLT(b);};
761 
762 inline
763 IntVect::IntVect (D_DECL6(int i, int j, int k,
764  int l, int m, int n))
765 {
766  D_EXPR6(vect[0] = i, vect[1] = j, vect[2] = k, vect[3] = l, vect[4] = m, vect[5] = n);
767 }
768 
769 inline
770 IntVect::IntVect (const int *a)
771 {
772  D_EXPR6(vect[0] = a[0], vect[1] = a[1], vect[2] = a[2],
773  vect[3] = a[3], vect[4] = a[4], vect[5] = a[5]);
774 }
775 
776 //inline
777 //IntVect::IntVect (const IntVect &iv)
778 //{
779  //D_EXPR6(vect[0]=iv.vect[0], vect[1]=iv.vect[1], vect[2]=iv.vect[2]);
780 // memcpy(vect, iv.vect, IntVectSize);
781 //}
782 
783 //inline
784 //IntVect&
785 //IntVect::operator= (const IntVect &iv)
786 //{
787 // D_EXPR6(vect[0]=iv.vect[0], vect[1]=iv.vect[1], vect[2]=iv.vect[2],
788 // vect[3]=iv.vect[3], vect[4]=iv.vect[4], vect[5]=iv.vect[5]);
789 // return *this;
790 //}
791 
792 inline
793 int&
795 {
796  CH_assert(i>=0 && i < SpaceDim);
797  return vect[i];
798 }
799 
800 inline
801 int
802 IntVect::operator[] (int i) const
803 {
804  CH_assert(i>=0 && i < SpaceDim);
805  return vect[i];
806 }
807 
808 inline
809 void
811  int val)
812 {
813  CH_assert(i >=0 && i < SpaceDim);
814  vect[i] = val;
815  // return *this;
816 }
817 
818 inline
819 const int*
821 {
822  return vect;
823 }
824 
825 inline
826 int*
828 {
829  return vect;
830 }
831 
832 inline
833 const int*
835 {
836  return vect;
837 }
838 
839 inline
840 bool
842 {
843  return D_TERM6(vect[0] == p[0], && vect[1] == p[1], && vect[2] == p[2],
844  && vect[3] == p[3], && vect[4] == p[4], && vect[5] == p[5]);
845 }
846 
847 inline
848 bool
850 {
851  return D_TERM6(vect[0] != p[0], || vect[1] != p[1], || vect[2] != p[2],
852  || vect[3] != p[3], || vect[4] != p[4], || vect[5] != p[5]);
853 }
854 
855 inline
856 bool
858 {
859  return D_TERM6(vect[0] < p[0], && vect[1] < p[1], && vect[2] < p[2],
860  && vect[3] < p[3], && vect[4] < p[4], && vect[5] < p[5]);
861 }
862 
863 inline
864 bool
866 {
867  return D_TERM6(vect[0] <= p[0], && vect[1] <= p[1], && vect[2] <= p[2],
868  && vect[3] <= p[3], && vect[4] <= p[4], && vect[5] <= p[5]);
869 }
870 
871 inline
872 bool
874 {
875  return D_TERM6(vect[0] > p[0], && vect[1] > p[1], && vect[2] > p[2],
876  && vect[3] > p[3], && vect[4] > p[4], && vect[5] > p[5]);
877 }
878 
879 inline
880 bool
882 {
883  return D_TERM6(vect[0] >= p[0], && vect[1] >= p[1], && vect[2] >= p[2],
884  && vect[3] >= p[3], && vect[4] >= p[4], && vect[5] >= p[5]);
885 }
886 
887 inline
888 bool
889 IntVect::lexLT (const IntVect &s) const
890 
891 {
892  if (vect[0] < s[0]) return true;
893 #if CH_SPACEDIM > 1
894  if (vect[0] > s[0]) return false;
895  if (vect[1] < s[1]) return true;
896 #endif
897 #if CH_SPACEDIM > 2
898  if (vect[1] > s[1]) return false;
899  if (vect[2] < s[2]) return true;
900 #endif
901 #if CH_SPACEDIM > 3
902  if (vect[2] > s[2]) return false;
903  if (vect[3] < s[3]) return true;
904 #endif
905 #if CH_SPACEDIM > 4
906  if (vect[3] > s[3]) return false;
907  if (vect[4] < s[4]) return true;
908 #endif
909 #if CH_SPACEDIM > 5
910  if (vect[4] > s[4]) return false;
911  if (vect[5] < s[5]) return true;
912 #endif
913 
914  return false;
915 }
916 
917 inline
918 bool
919 IntVect::lexGT (const IntVect& s) const
920 {
921  if (vect[0] > s[0]) return true;
922 #if CH_SPACEDIM > 1
923  if (vect[0] < s[0]) return false;
924  if (vect[1] > s[1]) return true;
925 #endif
926 #if CH_SPACEDIM > 2
927  if (vect[1] < s[1]) return false;
928  if (vect[2] > s[2]) return true;
929 #endif
930 #if CH_SPACEDIM > 3
931  if (vect[2] < s[2]) return false;
932  if (vect[3] > s[3]) return true;
933 #endif
934 #if CH_SPACEDIM > 4
935  if (vect[3] < s[3]) return false;
936  if (vect[4] > s[4]) return true;
937 #endif
938 #if CH_SPACEDIM > 5
939  if (vect[4] < s[4]) return false;
940  if (vect[5] > s[5]) return true;
941 #endif
942 
943  return false;
944 }
945 
946 inline
947 IntVect
949 {
950  return IntVect(*this);
951 }
952 
953 inline
954 IntVect
956 {
957  return IntVect(D_DECL6(-vect[0], -vect[1], -vect[2],
958  -vect[3], -vect[4], -vect[5] ));
959 }
960 
961 inline
962 int
963 IntVect::sum () const
964 {
965  return D_TERM6(vect[0], + vect[1], + vect[2],
966  + vect[3], + vect[4], + vect[5]);
967 }
968 
969 inline
970 int
971 IntVect::product () const
972 {
973  return D_TERM6(vect[0], * vect[1], * vect[2],
974  * vect[3], * vect[4], * vect[5]);
975 }
976 
977 inline
978 IntVect&
980 {
981  D_EXPR6(vect[0] += s, vect[1] += s, vect[2] += s,
982  vect[3] += s, vect[4] += s, vect[5] += s);
983  return *this;
984 }
985 
986 inline
987 IntVect&
989 {
990  D_EXPR6(vect[0] += p[0], vect[1] += p[1], vect[2] += p[2],
991  vect[3] += p[3], vect[4] += p[4], vect[5] += p[5]);
992  return *this;
993 }
994 
995 inline
996 IntVect&
998 {
999  D_EXPR6(vect[0] *= s, vect[1] *= s, vect[2] *= s,
1000  vect[3] *= s, vect[4] *= s, vect[5] *= s);
1001  return *this;
1002 }
1003 
1004 inline
1005 IntVect&
1007 {
1008  D_EXPR6(vect[0] *= p[0], vect[1] *= p[1], vect[2] *= p[2],
1009  vect[3] *= p[3], vect[4] *= p[4], vect[5] *= p[5]);
1010  return *this;
1011 }
1012 
1013 inline
1014 IntVect&
1016 {
1017  D_EXPR6(vect[0] /= s, vect[1] /= s, vect[2] /= s,
1018  vect[3] /= s, vect[4] /= s, vect[5] /= s);
1019  return *this;
1020 }
1021 
1022 inline
1023 IntVect&
1025 {
1026  D_EXPR6(vect[0] /= p[0], vect[1] /= p[1], vect[2] /= p[2],
1027  vect[3] /= p[3], vect[4] /= p[4], vect[5] /= p[5]);
1028  return *this;
1029 }
1030 
1031 inline
1032 IntVect&
1034 {
1035  D_EXPR6(vect[0] -= s, vect[1] -= s, vect[2] -= s,
1036  vect[3] -= s, vect[4] -= s, vect[5] -= s);
1037  return *this;
1038 }
1039 
1040 inline
1041 IntVect&
1043 {
1044  D_EXPR6(vect[0] -= p[0], vect[1] -= p[1], vect[2] -= p[2],
1045  vect[3] -= p[3], vect[4] -= p[4], vect[5] -= p[5]);
1046  return *this;
1047 }
1048 
1049 inline
1050 IntVect
1052 {
1053  return IntVect(D_DECL6(vect[0] + p[0], vect[1] + p[1], vect[2] + p[2],
1054  vect[3] + p[3], vect[4] + p[4], vect[5] + p[5]));
1055 }
1056 
1057 inline
1058 IntVect
1060 {
1061  return IntVect(D_DECL6(vect[0] + s, vect[1] + s, vect[2] + s,
1062  vect[3] + s, vect[4] + s, vect[5] + s));
1063 }
1064 
1065 inline
1066 IntVect
1068 {
1069  return IntVect(D_DECL6(vect[0] - p[0], vect[1] - p[1], vect[2] - p[2],
1070  vect[3] - p[3], vect[4] - p[4], vect[5] - p[5]));
1071 }
1072 
1073 inline
1074 IntVect
1076 {
1077  return IntVect(D_DECL6(vect[0] - s, vect[1] - s, vect[2] - s,
1078  vect[3] - s, vect[4] - s, vect[5] - s));
1079 }
1080 
1081 inline
1082 IntVect
1084 {
1085  return IntVect(D_DECL6(vect[0] * p[0], vect[1] * p[1], vect[2] * p[2],
1086  vect[3] * p[3], vect[4] * p[4], vect[5] * p[5]));
1087 }
1088 
1089 inline
1090 IntVect
1092 {
1093  return IntVect(D_DECL6(vect[0] * s, vect[1] * s, vect[2] * s,
1094  vect[3] * s, vect[4] * s, vect[5] * s));
1095 }
1096 
1097 inline
1098 IntVect
1100 {
1101  return IntVect(D_DECL6(vect[0] / p[0], vect[1] / p[1], vect[2] / p[2],
1102  vect[3] / p[3], vect[4] / p[4], vect[5] / p[5]));
1103 }
1104 
1105 inline
1106 IntVect
1108 {
1109  return IntVect(D_DECL6(vect[0] / s, vect[1] / s, vect[2] / s,
1110  vect[3] / s, vect[4] / s, vect[5] / s));
1111 }
1112 
1113 inline
1114 IntVect&
1116 {
1117  D_EXPR6(vect[0] = Min(vect[0], p.vect[0]),
1118  vect[1] = Min(vect[1], p.vect[1]),
1119  vect[2] = Min(vect[2], p.vect[2]),
1120  vect[3] = Min(vect[3], p.vect[3]),
1121  vect[4] = Min(vect[4], p.vect[4]),
1122  vect[5] = Min(vect[5], p.vect[5]));
1123  return *this;
1124 }
1125 
1126 inline
1127 IntVect&
1129 {
1130  D_EXPR6(vect[0] = Max(vect[0], p.vect[0]),
1131  vect[1] = Max(vect[1], p.vect[1]),
1132  vect[2] = Max(vect[2], p.vect[2]),
1133  vect[3] = Max(vect[3], p.vect[3]),
1134  vect[4] = Max(vect[4], p.vect[4]),
1135  vect[5] = Max(vect[5], p.vect[5]));
1136  return *this;
1137 }
1138 
1139 inline
1140 IntVect&
1142 {
1143  D_EXPR6(vect[0] *= s, vect[1] *= s, vect[2] *= s,
1144  vect[3] *= s, vect[4] *= s, vect[5] *= s);
1145  return *this;
1146 }
1147 
1148 inline
1149 IntVect&
1150 IntVect::reflect (int ref_ix,
1151  int idir)
1152 {
1153  CH_assert(idir >= 0 && idir < SpaceDim);
1154  vect[idir] = -vect[idir] + 2*ref_ix;
1155  return *this;
1156 }
1157 
1158 inline
1159 IntVect&
1160 IntVect::shift (int coord,
1161  int s)
1162 {
1163  CH_assert(coord >= 0 && coord < SpaceDim);
1164  vect[coord] += s;
1165  return *this;
1166 }
1167 
1168 inline
1169 IntVect&
1171 {
1172  *this += iv;
1173  return *this;
1174 }
1175 
1176 inline
1177 IntVect&
1179 {
1180  D_EXPR6(vect[0] += s, vect[1] += s, vect[2] += s,
1181  vect[3] += s, vect[4] += s, vect[5] += s);
1182  return *this;
1183 }
1184 
1185 inline
1186 IntVect
1188  const IntVect& p)
1189 {
1190  return IntVect(D_DECL6(p[0] + s, p[1] + s, p[2] + s,
1191  p[3] + s, p[4] + s, p[5] + s));
1192 }
1193 
1194 inline
1195 IntVect
1197  const IntVect& p)
1198 {
1199  return IntVect(D_DECL6(s - p[0], s - p[1], s - p[2],
1200  s - p[3], s - p[4], s - p[5]));
1201 }
1202 
1203 inline
1204 IntVect
1206  const IntVect& p)
1207 {
1208  return IntVect(D_DECL6(s * p[0], s * p[1], s * p[2],
1209  s * p[3], s * p[4], s * p[5]));
1210 }
1211 
1212 inline
1213 IntVect
1214 scale (const IntVect& p,
1215  int s)
1216 {
1217  return IntVect(D_DECL6(s * p[0], s * p[1], s * p[2],
1218  s * p[3], s * p[4], s * p[5]));
1219 }
1220 
1221 inline
1222 const IntVect
1223 absolute (const IntVect& p)
1224 {
1225  return IntVect(D_DECL6(abs(p[0]), abs(p[1]), abs(p[2]),
1226  abs(p[3]), abs(p[4]), abs(p[5])));
1227 }
1228 
1229 inline
1230 IntVect
1231 diagShift (const IntVect &p, int s)
1232 {
1233  return IntVect(D_DECL6(p[0] + s, p[1] + s, p[2] + s,
1234  p[3] + s, p[4] + s, p[5] + s));
1235 }
1236 
1237 inline
1238 IntVect
1239 min (const IntVect& p1,
1240  const IntVect& p2)
1241 {
1242  IntVect p(p1);
1243  return p.min(p2);
1244 }
1245 
1246 inline
1247 IntVect
1248 max (const IntVect& p1,
1249  const IntVect& p2)
1250 {
1251  IntVect p(p1);
1252  return p.max(p2);
1253 }
1254 
1255 inline
1256 IntVect
1257 BASISV (int dir)
1258 {
1259  CH_assert(dir >= 0 && dir < SpaceDim);
1260  IntVect tmp = IntVect::Zero ;
1261  tmp.vect[dir] = 1;
1262  return tmp;
1263 }
1264 
1265 inline
1266 IntVect
1267 reflect (const IntVect& a,
1268  int ref_ix,
1269  int idir)
1270 {
1271  CH_assert(idir >= 0 && idir < SpaceDim);
1272  IntVect b(a);
1273  b.vect[idir] = -b.vect[idir] + 2*ref_ix;
1274  return b;
1275 }
1276 
1277 inline
1278 IntVect
1279 coarsen (const IntVect& p,
1280  int s)
1281 {
1282  CH_assert(s > 0);
1283  return IntVect(
1284  D_DECL6((p.vect[0]<0) ? -abs(p.vect[0]+1)/s-1 : p.vect[0]/s ,
1285  (p.vect[1]<0) ? -abs(p.vect[1]+1)/s-1 : p.vect[1]/s ,
1286  (p.vect[2]<0) ? -abs(p.vect[2]+1)/s-1 : p.vect[2]/s ,
1287  (p.vect[3]<0) ? -abs(p.vect[3]+1)/s-1 : p.vect[3]/s ,
1288  (p.vect[4]<0) ? -abs(p.vect[4]+1)/s-1 : p.vect[4]/s ,
1289  (p.vect[5]<0) ? -abs(p.vect[5]+1)/s-1 : p.vect[5]/s ));
1290 }
1291 
1292 inline
1293 IntVect
1294 coarsen (const IntVect& p1,
1295  const IntVect& p2)
1296 {
1297  CH_assert(p2 > IntVect::Zero);
1298  return IntVect(
1299  D_DECL6(
1300  (p1.vect[0]<0)?-abs(p1.vect[0]+1)/p2.vect[0]-1:p1.vect[0]/p2.vect[0],
1301  (p1.vect[1]<0)?-abs(p1.vect[1]+1)/p2.vect[1]-1:p1.vect[1]/p2.vect[1],
1302  (p1.vect[2]<0)?-abs(p1.vect[2]+1)/p2.vect[2]-1:p1.vect[2]/p2.vect[2],
1303  (p1.vect[3]<0)?-abs(p1.vect[3]+1)/p2.vect[3]-1:p1.vect[3]/p2.vect[3],
1304  (p1.vect[4]<0)?-abs(p1.vect[4]+1)/p2.vect[4]-1:p1.vect[4]/p2.vect[4],
1305  (p1.vect[5]<0)?-abs(p1.vect[5]+1)/p2.vect[5]-1:p1.vect[5]/p2.vect[5])
1306  );
1307 }
1308 
1309 inline
1310 IntVect&
1312 {
1313  CH_assert(s > 0);
1314  for (int i = 0; i < SpaceDim; ++i)
1315  vect[i] = ((vect[i]<0) ? -abs(vect[i]+1)/s-1 : vect[i]/s);
1316  return *this;
1317 }
1318 
1319 inline
1320 IntVect&
1322 {
1323  CH_assert(p > IntVect::Zero);
1324  for (int i = 0; i <SpaceDim; ++i)
1325  {
1326  const int s = p.vect[i];
1327  vect[i] = ((vect[i]<0) ? -abs(vect[i]+1)/s-1 : vect[i]/s);
1328  }
1329  return *this;
1330 }
1331 
1332 inline uint64_t IntVect::hash(const IntVect& origin, const IntVect& blockingFactor) const
1333 {
1334 
1335  uint64_t answer = 0;
1336 #if CH_SPACEDIM >= 4
1337 //kind of a strawman hash function for higher dims. I doubt this is what Brian wants.
1338  for(int idir = 0; idir < CH_SPACEDIM; idir++)
1339  {
1340  int bfact = 1;
1341  for(int jdir = 0; jdir < idir; jdir++)
1342  {
1343  bfact *= blockingFactor[jdir];
1344  }
1345  answer += origin[idir]*bfact;
1346  }
1347 #else
1348  uint32_t z=0, y=0, x;
1349 #if CH_SPACEDIM > 2
1350  z = (vect[2]-origin[2])/blockingFactor[2];
1351 #endif
1352 #if CH_SPACEDIM > 1
1353  y = (vect[1]-origin[1])/blockingFactor[1];
1354 #endif
1355  x = (vect[0]-origin[0])/blockingFactor[0];
1356  answer = morton256_z[(z >> 16) & 0xFF ] | // we start by shifting the third byte, since we only look at the first 21 bits
1357  morton256_y[(y >> 16) & 0xFF ] |
1358  morton256_x[(x >> 16) & 0xFF ];
1359  answer = answer << 48 | morton256_z[(z >> 8) & 0xFF ] | // shifting second byte
1360  morton256_y[(y >> 8) & 0xFF ] |
1361  morton256_x[(x >> 8) & 0xFF ];
1362  answer = answer << 24 |
1363  morton256_z[(z) & 0xFF ] | // first byte
1364  morton256_y[(y) & 0xFF ] |
1365  morton256_x[(x) & 0xFF ];
1366 #endif
1367  return answer;
1368 }
1369 #endif /* WRAPPER */
1370 
1371 #include "NamespaceFooter.H"
1372 #endif
IntVect min(const IntVect &p1, const IntVect &p2)
Definition: IntVect.H:1239
IntVect & operator*=(int s)
Definition: IntVect.H:997
#define D_DECL6(a, b, c, d, e, f)
Definition: CHArray.H:39
bool operator!=(const IntVect &p) const
Definition: IntVect.H:849
static const uint32_t morton256_y[256]
Definition: IntVect.H:693
IntVect & min(const IntVect &p)
Definition: IntVect.H:1115
#define D_TERM6(a, b, c, d, e, f)
Definition: CHArray.H:40
static const size_t IntVectSize
Definition: IntVect.H:691
#define CH_SPACEDIM
Definition: SPACE.H:51
const int * getVect() const
Definition: IntVect.H:834
#define CH_assert(cond)
Definition: CHArray.H:37
IntVect & scale(int s)
Definition: IntVect.H:1141
IntVect operator+() const
Definition: IntVect.H:948
IntVect scale(const IntVect &p, int s)
Definition: IntVect.H:1214
static size_t io_offset
Definition: IntVect.H:668
Definition: FaceIndex.H:28
int product() const
Definition: CHArray.H:64
IntVect operator/(const IntVect &p) const
Definition: IntVect.H:1099
IntVect operator*(int s, const IntVect &p)
Definition: IntVect.H:1205
static int InitStatics()
static int s_dummyForIntVectH
Definition: IntVect.H:745
IntVect & operator/=(int s)
Definition: IntVect.H:1015
IntVect copy() const
Definition: IntVect.H:103
IntVect max(const IntVect &p1, const IntVect &p2)
Definition: IntVect.H:1248
IntVect BASISV(int dir)
Definition: IntVect.H:1257
IntVect & operator-=(int s)
Definition: IntVect.H:1033
int linearSize(const CH_XDIR::IntVect &a_iv)
functions for linearization
IntVect operator-() const
Definition: IntVect.H:955
bool lexGT(const IntVect &s) const
Definition: IntVect.H:919
IntVect diagShift(const IntVect &p, int s)
Definition: IntVect.H:1231
const int SpaceDim
Definition: SPACE.H:38
Definition: IndexTM.H:36
void setVal(int i, int val)
Definition: IntVect.H:810
int max() const
return the maximum value in the intvect
Definition: IntVect.H:471
IntVect coarsen(const IntVect &p, int s)
Definition: IntVect.H:1279
friend std::istream & operator>>(std::istream &os, IntVect &iv)
IntVect & shift(int coord, int s)
Definition: IntVect.H:1160
friend class BLfacade::IntVect
Definition: IntVect.H:681
static const IntVect Unit
Definition: IntVect.H:659
int vect[CH_SPACEDIM]
Definition: IntVect.H:686
friend std::ostream & operator<<(std::ostream &os, const IntVect &iv)
void linearOut(void *a_outBuf, const CH_XDIR::IntVect &a_iv)
functions for linearization
IntVect & reflect(int ref_ix, int idir)
Definition: IntVect.H:1150
IntVect & max(const IntVect &p)
Definition: IntVect.H:1128
void linearIn(CH_XDIR::IntVect &a_iv, const void *a_inBuf)
functions for linearization
bool lexLT(const IntVect &s) const
Definition: IntVect.H:889
IntVect & operator+=(int s)
Definition: IntVect.H:979
int & operator[](const int i)
Definition: CHArray.H:56
IntVect(const Vector< int > &vi)
Definition: IntVect.H:66
void dumpOn(std::ostream &os) const
bool operator<=(const IntVect &p) const
Definition: IntVect.H:865
static const IntVect Zero
Definition: IntVect.H:654
friend const IntVect absolute(const IntVect &p)
Returns the componentwise absolute value of the given IntVect.
Definition: IntVect.H:1223
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
IntVect & diagShift(int s)
Definition: IntVect.H:1178
IntVect reflect(const IntVect &a, int ref_ix, int idir)
Definition: IntVect.H:1267
const IntVect absolute(const IntVect &p)
Definition: IntVect.H:1223
friend IntVect BASISV(int dir)
Definition: IntVect.H:1257
bool operator>(const IntVect &p) const
Definition: IntVect.H:873
Handle to a particular group in an HDF file.
Definition: CH_HDF5.H:292
int sum() const
Definition: IntVect.H:963
T Min(const T &a_a, const T &a_b)
Definition: Misc.H:26
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
uint64_t hash(const IntVect &origin, const IntVect &blockingFactor) const
Definition: IntVect.H:1332
static const uint32_t morton256_z[256]
Definition: IntVect.H:694
void p() const
IntVect operator-(int s, const IntVect &p)
Definition: IntVect.H:1196
Volume of Fluid Index.
Definition: VolIndex.H:31
T Max(const T &a_a, const T &a_b)
Definition: Misc.H:39
bool operator<(const IntVect &p) const
Definition: IntVect.H:857
IntVect operator*(const IntVect &p) const
Definition: IntVect.H:1083
const int * dataPtr() const
Definition: IntVect.H:820
IntVect & coarsen(const IntVect &p)
Definition: IntVect.H:1321
static const uint32_t morton256_x[256]
Definition: IntVect.H:692
IntVect operator+(int s, const IntVect &p)
Definition: IntVect.H:1187
bool operator==(const IntVect &p) const
Definition: IntVect.H:841
int min() const
return the minimum value in the intvect
Definition: IntVect.H:482
void printOn(std::ostream &os) const
bool operator>=(const IntVect &p) const
Definition: IntVect.H:881
IntVect()
Definition: IntVect.H:63