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