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