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 
759 // garbage thinking here. I've removed this function (bvs)
760 // Static initialization. Gotta make sure there are no static object
761 // definitions above here (except possibly stuff in headers). Otherwise,
762 // the danger is that some static object's constructor calls IntVect::Zero or
763 // IntVect::Unit -- the very things the following definition is supposed to
764 // initialize.
765 //
767 
768 #ifndef WRAPPER
769 //
770 // Inlines.
771 //
772 
773 // try uninitialized IntVect null construction for now.....
774 
775 // inline
776 // IntVect::IntVect ()
777 // {
778 // D_EXPR6(vect[0] = 0, vect[1] = 0, vect[2] = 0);
779 // }
780 
781 //template <> inline constexpr bool std::less<IntVect>::operator()(const IntVect& a, const IntVect& b) const { return a.lexLT(b);};
782 
783 inline
784 IntVect::IntVect (D_DECL6(int i, int j, int k,
785  int l, int m, int n))
786 {
787  D_EXPR6(vect[0] = i, vect[1] = j, vect[2] = k, vect[3] = l, vect[4] = m, vect[5] = n);
788 }
789 
790 inline
791 IntVect::IntVect (const int *a)
792 {
793  D_EXPR6(vect[0] = a[0], vect[1] = a[1], vect[2] = a[2],
794  vect[3] = a[3], vect[4] = a[4], vect[5] = a[5]);
795 }
796 
797 //inline
798 //IntVect::IntVect (const IntVect &iv)
799 //{
800  //D_EXPR6(vect[0]=iv.vect[0], vect[1]=iv.vect[1], vect[2]=iv.vect[2]);
801 // memcpy(vect, iv.vect, IntVectSize);
802 //}
803 
804 //inline
805 //IntVect&
806 //IntVect::operator= (const IntVect &iv)
807 //{
808 // D_EXPR6(vect[0]=iv.vect[0], vect[1]=iv.vect[1], vect[2]=iv.vect[2],
809 // vect[3]=iv.vect[3], vect[4]=iv.vect[4], vect[5]=iv.vect[5]);
810 // return *this;
811 //}
812 
813 inline
814 int&
816 {
817  CH_assert(i>=0 && i < SpaceDim);
818  return vect[i];
819 }
820 
821 inline
822 int
823 IntVect::operator[] (int i) const
824 {
825  CH_assert(i>=0 && i < SpaceDim);
826  return vect[i];
827 }
828 
829 inline
830 void
832  int val)
833 {
834  CH_assert(i >=0 && i < SpaceDim);
835  vect[i] = val;
836  // return *this;
837 }
838 
839 inline
840 const int*
842 {
843  return vect;
844 }
845 
846 inline
847 int*
849 {
850  return vect;
851 }
852 
853 inline
854 const int*
856 {
857  return vect;
858 }
859 
860 inline
861 bool
863 {
864  return D_TERM6(vect[0] == p[0], && vect[1] == p[1], && vect[2] == p[2],
865  && vect[3] == p[3], && vect[4] == p[4], && vect[5] == p[5]);
866 }
867 
868 inline
869 bool
871 {
872  return D_TERM6(vect[0] != p[0], || vect[1] != p[1], || vect[2] != p[2],
873  || vect[3] != p[3], || vect[4] != p[4], || vect[5] != p[5]);
874 }
875 
876 inline
877 bool
879 {
880  return D_TERM6(vect[0] < p[0], && vect[1] < p[1], && vect[2] < p[2],
881  && vect[3] < p[3], && vect[4] < p[4], && vect[5] < p[5]);
882 }
883 
884 inline
885 bool
887 {
888  return D_TERM6(vect[0] <= p[0], && vect[1] <= p[1], && vect[2] <= p[2],
889  && vect[3] <= p[3], && vect[4] <= p[4], && vect[5] <= p[5]);
890 }
891 
892 inline
893 bool
895 {
896  return D_TERM6(vect[0] > p[0], && vect[1] > p[1], && vect[2] > p[2],
897  && vect[3] > p[3], && vect[4] > p[4], && vect[5] > p[5]);
898 }
899 
900 inline
901 bool
903 {
904  return D_TERM6(vect[0] >= p[0], && vect[1] >= p[1], && vect[2] >= p[2],
905  && vect[3] >= p[3], && vect[4] >= p[4], && vect[5] >= p[5]);
906 }
907 
908 inline
909 bool
910 IntVect::lexLT (const IntVect &s) const
911 
912 {
913  if (vect[0] < s[0]) return true;
914 #if CH_SPACEDIM > 1
915  if (vect[0] > s[0]) return false;
916  if (vect[1] < s[1]) return true;
917 #endif
918 #if CH_SPACEDIM > 2
919  if (vect[1] > s[1]) return false;
920  if (vect[2] < s[2]) return true;
921 #endif
922 #if CH_SPACEDIM > 3
923  if (vect[2] > s[2]) return false;
924  if (vect[3] < s[3]) return true;
925 #endif
926 #if CH_SPACEDIM > 4
927  if (vect[3] > s[3]) return false;
928  if (vect[4] < s[4]) return true;
929 #endif
930 #if CH_SPACEDIM > 5
931  if (vect[4] > s[4]) return false;
932  if (vect[5] < s[5]) return true;
933 #endif
934 
935  return false;
936 }
937 
938 inline
939 bool
940 IntVect::lexGT (const IntVect& s) const
941 {
942  if (vect[0] > s[0]) return true;
943 #if CH_SPACEDIM > 1
944  if (vect[0] < s[0]) return false;
945  if (vect[1] > s[1]) return true;
946 #endif
947 #if CH_SPACEDIM > 2
948  if (vect[1] < s[1]) return false;
949  if (vect[2] > s[2]) return true;
950 #endif
951 #if CH_SPACEDIM > 3
952  if (vect[2] < s[2]) return false;
953  if (vect[3] > s[3]) return true;
954 #endif
955 #if CH_SPACEDIM > 4
956  if (vect[3] < s[3]) return false;
957  if (vect[4] > s[4]) return true;
958 #endif
959 #if CH_SPACEDIM > 5
960  if (vect[4] < s[4]) return false;
961  if (vect[5] > s[5]) return true;
962 #endif
963 
964  return false;
965 }
966 
967 inline
968 IntVect
970 {
971  return IntVect(*this);
972 }
973 
974 inline
975 IntVect
977 {
978  return IntVect(D_DECL6(-vect[0], -vect[1], -vect[2],
979  -vect[3], -vect[4], -vect[5] ));
980 }
981 
982 inline
983 int
984 IntVect::sum () const
985 {
986  return D_TERM6(vect[0], + vect[1], + vect[2],
987  + vect[3], + vect[4], + vect[5]);
988 }
989 
990 inline
991 int
992 IntVect::product () const
993 {
994  return D_TERM6(vect[0], * vect[1], * vect[2],
995  * vect[3], * vect[4], * vect[5]);
996 }
997 
998 inline
999 IntVect&
1001 {
1002  D_EXPR6(vect[0] += s, vect[1] += s, vect[2] += s,
1003  vect[3] += s, vect[4] += s, vect[5] += s);
1004  return *this;
1005 }
1006 
1007 inline
1008 IntVect&
1010 {
1011  D_EXPR6(vect[0] += p[0], vect[1] += p[1], vect[2] += p[2],
1012  vect[3] += p[3], vect[4] += p[4], vect[5] += p[5]);
1013  return *this;
1014 }
1015 
1016 inline
1017 IntVect&
1019 {
1020  D_EXPR6(vect[0] *= s, vect[1] *= s, vect[2] *= s,
1021  vect[3] *= s, vect[4] *= s, vect[5] *= s);
1022  return *this;
1023 }
1024 
1025 inline
1026 IntVect&
1028 {
1029  D_EXPR6(vect[0] *= p[0], vect[1] *= p[1], vect[2] *= p[2],
1030  vect[3] *= p[3], vect[4] *= p[4], vect[5] *= p[5]);
1031  return *this;
1032 }
1033 
1034 inline
1035 IntVect&
1037 {
1038  D_EXPR6(vect[0] /= s, vect[1] /= s, vect[2] /= s,
1039  vect[3] /= s, vect[4] /= s, vect[5] /= s);
1040  return *this;
1041 }
1042 
1043 inline
1044 IntVect&
1046 {
1047  D_EXPR6(vect[0] /= p[0], vect[1] /= p[1], vect[2] /= p[2],
1048  vect[3] /= p[3], vect[4] /= p[4], vect[5] /= p[5]);
1049  return *this;
1050 }
1051 
1052 inline
1053 IntVect&
1055 {
1056  D_EXPR6(vect[0] -= s, vect[1] -= s, vect[2] -= s,
1057  vect[3] -= s, vect[4] -= s, vect[5] -= s);
1058  return *this;
1059 }
1060 
1061 inline
1062 IntVect&
1064 {
1065  D_EXPR6(vect[0] -= p[0], vect[1] -= p[1], vect[2] -= p[2],
1066  vect[3] -= p[3], vect[4] -= p[4], vect[5] -= p[5]);
1067  return *this;
1068 }
1069 
1070 inline
1071 IntVect
1073 {
1074  return IntVect(D_DECL6(vect[0] + p[0], vect[1] + p[1], vect[2] + p[2],
1075  vect[3] + p[3], vect[4] + p[4], vect[5] + p[5]));
1076 }
1077 
1078 inline
1079 IntVect
1081 {
1082  return IntVect(D_DECL6(vect[0] + s, vect[1] + s, vect[2] + s,
1083  vect[3] + s, vect[4] + s, vect[5] + s));
1084 }
1085 
1086 inline
1087 IntVect
1089 {
1090  return IntVect(D_DECL6(vect[0] - p[0], vect[1] - p[1], vect[2] - p[2],
1091  vect[3] - p[3], vect[4] - p[4], vect[5] - p[5]));
1092 }
1093 
1094 inline
1095 IntVect
1097 {
1098  return IntVect(D_DECL6(vect[0] - s, vect[1] - s, vect[2] - s,
1099  vect[3] - s, vect[4] - s, vect[5] - s));
1100 }
1101 
1102 inline
1103 IntVect
1105 {
1106  return IntVect(D_DECL6(vect[0] * p[0], vect[1] * p[1], vect[2] * p[2],
1107  vect[3] * p[3], vect[4] * p[4], vect[5] * p[5]));
1108 }
1109 
1110 inline
1111 IntVect
1113 {
1114  return IntVect(D_DECL6(vect[0] * s, vect[1] * s, vect[2] * s,
1115  vect[3] * s, vect[4] * s, vect[5] * s));
1116 }
1117 
1118 inline
1119 IntVect
1121 {
1122  return IntVect(D_DECL6(vect[0] / p[0], vect[1] / p[1], vect[2] / p[2],
1123  vect[3] / p[3], vect[4] / p[4], vect[5] / p[5]));
1124 }
1125 
1126 inline
1127 IntVect
1129 {
1130  return IntVect(D_DECL6(vect[0] / s, vect[1] / s, vect[2] / s,
1131  vect[3] / s, vect[4] / s, vect[5] / s));
1132 }
1133 
1134 inline
1135 IntVect&
1137 {
1138  D_EXPR6(vect[0] = Min(vect[0], p.vect[0]),
1139  vect[1] = Min(vect[1], p.vect[1]),
1140  vect[2] = Min(vect[2], p.vect[2]),
1141  vect[3] = Min(vect[3], p.vect[3]),
1142  vect[4] = Min(vect[4], p.vect[4]),
1143  vect[5] = Min(vect[5], p.vect[5]));
1144  return *this;
1145 }
1146 
1147 inline
1148 IntVect&
1150 {
1151  D_EXPR6(vect[0] = Max(vect[0], p.vect[0]),
1152  vect[1] = Max(vect[1], p.vect[1]),
1153  vect[2] = Max(vect[2], p.vect[2]),
1154  vect[3] = Max(vect[3], p.vect[3]),
1155  vect[4] = Max(vect[4], p.vect[4]),
1156  vect[5] = Max(vect[5], p.vect[5]));
1157  return *this;
1158 }
1159 
1160 inline
1161 IntVect&
1163 {
1164  D_EXPR6(vect[0] *= s, vect[1] *= s, vect[2] *= s,
1165  vect[3] *= s, vect[4] *= s, vect[5] *= s);
1166  return *this;
1167 }
1168 
1169 inline
1170 IntVect&
1171 IntVect::reflect (int ref_ix,
1172  int idir)
1173 {
1174  CH_assert(idir >= 0 && idir < SpaceDim);
1175  vect[idir] = -vect[idir] + 2*ref_ix;
1176  return *this;
1177 }
1178 
1179 inline
1180 IntVect&
1181 IntVect::shift (int coord,
1182  int s)
1183 {
1184  CH_assert(coord >= 0 && coord < SpaceDim);
1185  vect[coord] += s;
1186  return *this;
1187 }
1188 
1189 inline
1190 IntVect&
1192 {
1193  *this += iv;
1194  return *this;
1195 }
1196 
1197 inline
1198 IntVect&
1200 {
1201  D_EXPR6(vect[0] += s, vect[1] += s, vect[2] += s,
1202  vect[3] += s, vect[4] += s, vect[5] += s);
1203  return *this;
1204 }
1205 
1206 inline
1207 IntVect
1209  const IntVect& p)
1210 {
1211  return IntVect(D_DECL6(p[0] + s, p[1] + s, p[2] + s,
1212  p[3] + s, p[4] + s, p[5] + s));
1213 }
1214 
1215 inline
1216 IntVect
1218  const IntVect& p)
1219 {
1220  return IntVect(D_DECL6(s - p[0], s - p[1], s - p[2],
1221  s - p[3], s - p[4], s - p[5]));
1222 }
1223 
1224 inline
1225 IntVect
1227  const IntVect& p)
1228 {
1229  return IntVect(D_DECL6(s * p[0], s * p[1], s * p[2],
1230  s * p[3], s * p[4], s * p[5]));
1231 }
1232 
1233 inline
1234 IntVect
1235 scale (const IntVect& p,
1236  int s)
1237 {
1238  return IntVect(D_DECL6(s * p[0], s * p[1], s * p[2],
1239  s * p[3], s * p[4], s * p[5]));
1240 }
1241 
1242 inline
1243 const IntVect
1244 absolute (const IntVect& p)
1245 {
1246  return IntVect(D_DECL6(abs(p[0]), abs(p[1]), abs(p[2]),
1247  abs(p[3]), abs(p[4]), abs(p[5])));
1248 }
1249 
1250 inline
1251 IntVect
1252 diagShift (const IntVect &p, int s)
1253 {
1254  return IntVect(D_DECL6(p[0] + s, p[1] + s, p[2] + s,
1255  p[3] + s, p[4] + s, p[5] + s));
1256 }
1257 
1258 inline
1259 IntVect
1260 min (const IntVect& p1,
1261  const IntVect& p2)
1262 {
1263  IntVect p(p1);
1264  return p.min(p2);
1265 }
1266 
1267 inline
1268 IntVect
1269 max (const IntVect& p1,
1270  const IntVect& p2)
1271 {
1272  IntVect p(p1);
1273  return p.max(p2);
1274 }
1275 
1276 inline
1277 IntVect
1278 BASISV (int dir)
1279 {
1280  CH_assert(dir >= 0 && dir < SpaceDim);
1281  IntVect tmp = IntVect::Zero ;
1282  tmp.vect[dir] = 1;
1283  return tmp;
1284 }
1285 
1286 inline
1287 IntVect
1288 reflect (const IntVect& a,
1289  int ref_ix,
1290  int idir)
1291 {
1292  CH_assert(idir >= 0 && idir < SpaceDim);
1293  IntVect b(a);
1294  b.vect[idir] = -b.vect[idir] + 2*ref_ix;
1295  return b;
1296 }
1297 
1298 inline
1299 IntVect
1300 coarsen (const IntVect& p,
1301  int s)
1302 {
1303  CH_assert(s > 0);
1304  return IntVect(
1305  D_DECL6((p.vect[0]<0) ? -abs(p.vect[0]+1)/s-1 : p.vect[0]/s ,
1306  (p.vect[1]<0) ? -abs(p.vect[1]+1)/s-1 : p.vect[1]/s ,
1307  (p.vect[2]<0) ? -abs(p.vect[2]+1)/s-1 : p.vect[2]/s ,
1308  (p.vect[3]<0) ? -abs(p.vect[3]+1)/s-1 : p.vect[3]/s ,
1309  (p.vect[4]<0) ? -abs(p.vect[4]+1)/s-1 : p.vect[4]/s ,
1310  (p.vect[5]<0) ? -abs(p.vect[5]+1)/s-1 : p.vect[5]/s ));
1311 }
1312 
1313 inline
1314 IntVect
1315 coarsen (const IntVect& p1,
1316  const IntVect& p2)
1317 {
1318  CH_assert(p2 > IntVect::Zero);
1319  return IntVect(
1320  D_DECL6(
1321  (p1.vect[0]<0)?-abs(p1.vect[0]+1)/p2.vect[0]-1:p1.vect[0]/p2.vect[0],
1322  (p1.vect[1]<0)?-abs(p1.vect[1]+1)/p2.vect[1]-1:p1.vect[1]/p2.vect[1],
1323  (p1.vect[2]<0)?-abs(p1.vect[2]+1)/p2.vect[2]-1:p1.vect[2]/p2.vect[2],
1324  (p1.vect[3]<0)?-abs(p1.vect[3]+1)/p2.vect[3]-1:p1.vect[3]/p2.vect[3],
1325  (p1.vect[4]<0)?-abs(p1.vect[4]+1)/p2.vect[4]-1:p1.vect[4]/p2.vect[4],
1326  (p1.vect[5]<0)?-abs(p1.vect[5]+1)/p2.vect[5]-1:p1.vect[5]/p2.vect[5])
1327  );
1328 }
1329 
1330 inline
1331 IntVect&
1333 {
1334  CH_assert(s > 0);
1335  for (int i = 0; i < SpaceDim; ++i)
1336  vect[i] = ((vect[i]<0) ? -abs(vect[i]+1)/s-1 : vect[i]/s);
1337  return *this;
1338 }
1339 
1340 inline
1341 IntVect&
1343 {
1344  CH_assert(p > IntVect::Zero);
1345  for (int i = 0; i <SpaceDim; ++i)
1346  {
1347  const int s = p.vect[i];
1348  vect[i] = ((vect[i]<0) ? -abs(vect[i]+1)/s-1 : vect[i]/s);
1349  }
1350  return *this;
1351 }
1352 
1353 inline uint64_t IntVect::hash(const IntVect& origin, const IntVect& blockingFactor) const
1354 {
1355 
1356  uint64_t answer = 0;
1357 #if CH_SPACEDIM >= 4
1358 //kind of a strawman hash function for higher dims. I doubt this is what Brian wants.
1359  for(int idir = 0; idir < CH_SPACEDIM; idir++)
1360  {
1361  int bfact = 1;
1362  for(int jdir = 0; jdir < idir; jdir++)
1363  {
1364  bfact *= blockingFactor[jdir];
1365  }
1366  answer += origin[idir]*bfact;
1367  }
1368 #else
1369  uint32_t z=0, y=0, x;
1370 #if CH_SPACEDIM > 2
1371  z = (vect[2]-origin[2])/blockingFactor[2];
1372 #endif
1373 #if CH_SPACEDIM > 1
1374  y = (vect[1]-origin[1])/blockingFactor[1];
1375 #endif
1376  x = (vect[0]-origin[0])/blockingFactor[0];
1377  answer = morton256_z[(z >> 16) & 0xFF ] | // we start by shifting the third byte, since we only look at the first 21 bits
1378  morton256_y[(y >> 16) & 0xFF ] |
1379  morton256_x[(x >> 16) & 0xFF ];
1380  answer = answer << 48 | morton256_z[(z >> 8) & 0xFF ] | // shifting second byte
1381  morton256_y[(y >> 8) & 0xFF ] |
1382  morton256_x[(x >> 8) & 0xFF ];
1383  answer = answer << 24 |
1384  morton256_z[(z) & 0xFF ] | // first byte
1385  morton256_y[(y) & 0xFF ] |
1386  morton256_x[(x) & 0xFF ];
1387 #endif
1388  return answer;
1389 }
1390 #endif /* WRAPPER */
1391 
1392 #include "NamespaceFooter.H"
1393 #endif
IntVect min(const IntVect &p1, const IntVect &p2)
Definition: IntVect.H:1260
IntVect & operator*=(int s)
Definition: IntVect.H:1018
#define D_DECL6(a, b, c, d, e, f)
Definition: CHArray.H:39
bool operator!=(const IntVect &p) const
Definition: IntVect.H:870
static const uint32_t morton256_y[256]
Definition: IntVect.H:712
IntVect & min(const IntVect &p)
Definition: IntVect.H:1136
#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:855
#define CH_assert(cond)
Definition: CHArray.H:37
IntVect & scale(int s)
Definition: IntVect.H:1162
IntVect operator+() const
Definition: IntVect.H:969
IntVect scale(const IntVect &p, int s)
Definition: IntVect.H:1235
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:1120
IntVect operator*(int s, const IntVect &p)
Definition: IntVect.H:1226
static int InitStatics()
static int s_dummyForIntVectH
Definition: IntVect.H:766
IntVect & operator/=(int s)
Definition: IntVect.H:1036
IntVect copy() const
Definition: IntVect.H:107
IntVect max(const IntVect &p1, const IntVect &p2)
Definition: IntVect.H:1269
IntVect BASISV(int dir)
Definition: IntVect.H:1278
IntVect & operator-=(int s)
Definition: IntVect.H:1054
int linearSize(const CH_XDIR::IntVect &a_iv)
functions for linearization
IntVect operator-() const
Definition: IntVect.H:976
bool lexGT(const IntVect &s) const
Definition: IntVect.H:940
IntVect diagShift(const IntVect &p, int s)
Definition: IntVect.H:1252
const int SpaceDim
Definition: SPACE.H:38
Definition: IndexTM.H:36
void setVal(int i, int val)
Definition: IntVect.H:831
int max() const
return the maximum value in the intvect
Definition: IntVect.H:475
IntVect coarsen(const IntVect &p, int s)
Definition: IntVect.H:1300
friend std::istream & operator>>(std::istream &os, IntVect &iv)
IntVect & shift(int coord, int s)
Definition: IntVect.H:1181
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:1171
IntVect & max(const IntVect &p)
Definition: IntVect.H:1149
void linearIn(CH_XDIR::IntVect &a_iv, const void *a_inBuf)
functions for linearization
bool lexLT(const IntVect &s) const
Definition: IntVect.H:910
IntVect & operator+=(int s)
Definition: IntVect.H:1000
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:886
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:1244
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
IntVect & diagShift(int s)
Definition: IntVect.H:1199
IntVect reflect(const IntVect &a, int ref_ix, int idir)
Definition: IntVect.H:1288
const IntVect absolute(const IntVect &p)
Definition: IntVect.H:1244
friend IntVect BASISV(int dir)
Definition: IntVect.H:1278
bool operator>(const IntVect &p) const
Definition: IntVect.H:894
Handle to a particular group in an HDF file.
Definition: CH_HDF5.H:292
int sum() const
Definition: IntVect.H:984
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:1353
static const uint32_t morton256_z[256]
Definition: IntVect.H:713
void p() const
IntVect operator-(int s, const IntVect &p)
Definition: IntVect.H:1217
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:878
IntVect operator*(const IntVect &p) const
Definition: IntVect.H:1104
const int * dataPtr() const
Definition: IntVect.H:841
IntVect & coarsen(const IntVect &p)
Definition: IntVect.H:1342
static const uint32_t morton256_x[256]
Definition: IntVect.H:711
IntVect operator+(int s, const IntVect &p)
Definition: IntVect.H:1208
bool operator==(const IntVect &p) const
Definition: IntVect.H:862
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:902
IntVect()
Definition: IntVect.H:67