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