GuardCellSizes.h 3.11 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
// -*- C++ -*-
/***************************************************************************
 *
 * The IPPL Framework
 * 
 *
 * Visit http://people.web.psi.ch/adelmann/ for more details
 *
 ***************************************************************************/

#ifndef GUARD_CELL_SIZES_H
#define GUARD_CELL_SIZES_H

// include files
#include "Index/NDIndex.h"

#include <iostream>

template<unsigned Dim>
class GuardCellSizes
{

public:

  GuardCellSizes()
  {
    for (unsigned d=0; d<Dim; ++d)
      Left[d] = Right[d] = 0;
  }
  GuardCellSizes(unsigned s);
  GuardCellSizes(unsigned *s);
  GuardCellSizes(unsigned l, unsigned r);
  GuardCellSizes(unsigned *l, unsigned *r);
34
  constexpr GuardCellSizes<Dim>(const GuardCellSizes<Dim>&) = default;
gsell's avatar
gsell committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
  GuardCellSizes<Dim>& operator=(const GuardCellSizes<Dim>& gc)
  {
    for (unsigned d=0; d<Dim; ++d) {
      Left[d]  = gc.Left[d];
      Right[d] = gc.Right[d];
    }
    return *this;
  }

  void set_Left(unsigned s);
  void set_Left(unsigned *s);
  void set_Left(unsigned d, unsigned *s);

  void set_Right(unsigned s);
  void set_Right(unsigned *s);
  void set_Right(unsigned d, unsigned *s);

  unsigned left(unsigned d) const { return Left[d]; }
  unsigned right(unsigned d) const { return Right[d]; }

  // Lexigraphic compare of two GuardCellSizes so we can
  // use them as a Key in a map.
  bool operator<(const GuardCellSizes<Dim>& r) const ;      
  bool operator==(const GuardCellSizes<Dim>& r) const;

private:

  unsigned Left[Dim];
  unsigned Right[Dim];

};

template<unsigned Dim>
inline NDIndex<Dim>
AddGuardCells(const NDIndex<Dim>& idx, const GuardCellSizes<Dim>& g)
{
  NDIndex<Dim> ret;
  for (unsigned int d=0; d<Dim; ++d)
    ret[d] = Index(idx[d].min() - g.left(d), idx[d].max() + g.right(d));
  return ret;
}


template<unsigned Dim>
// Lexigraphic compare of two GuardCellSizes so we can
// use them as a Key in a map.
inline bool 
GuardCellSizes<Dim>::operator<(const GuardCellSizes<Dim>& r) const 
{
  for (unsigned d=0; d<Dim; ++d) {
    if ( left(d) != r.left(d) )
      return ( left(d) < r.left(d) );
    if ( right(d) != r.right(d) )
      return ( right(d) < r.right(d) );
  }
  // If we get here they're equal.
  return false;
}

template<unsigned Dim>
inline bool 
GuardCellSizes<Dim>::operator==(const GuardCellSizes<Dim>& r) const 
{
  for (unsigned d=0; d<Dim; ++d) {
    if ( left(d) != r.left(d) )
      return false;
    if ( right(d) != r.right(d) )
      return false;
  }
  // If we get here they're equal.
  return true;
}

//////////////////////////////////////////////////////////////////////

template<unsigned Dim>
std::ostream& operator<<(std::ostream&,const GuardCellSizes<Dim>&);

//////////////////////////////////////////////////////////////////////

115
#include "Field/GuardCellSizes.hpp"
gsell's avatar
gsell committed
116 117 118 119 120 121 122 123

#endif // GUARD_CELL_SIZES_H

/***************************************************************************
 * $RCSfile: GuardCellSizes.h,v $   $Author: adelmann $
 * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:26 $
 * IPPL_VERSION_ID: $Id: GuardCellSizes.h,v 1.1.1.1 2003/01/23 07:40:26 adelmann Exp $ 
 ***************************************************************************/