~ubuntu-branches/ubuntu/utopic/dune-grid/utopic-proposed

« back to all changes in this revision

Viewing changes to dune/grid/yaspgrid/yaspgridgeometry.hh

  • Committer: Package Import Robot
  • Author(s): Ansgar Burchardt
  • Date: 2014-02-14 10:49:16 UTC
  • mfrom: (1.3.1) (5.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20140214104916-2clchnny3eu7ks4w
Tags: 2.3.0-2
InstallĀ /usr/share/dune-grid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
2
// vi: set et ts=4 sw=2 sts=2:
 
3
#ifndef DUNE_GRID_YASPGRIDGEOMETRY_HH
 
4
#define DUNE_GRID_YASPGRIDGEOMETRY_HH
 
5
 
 
6
/** \file
 
7
 * \brief The YaspGeometry class and its specializations
 
8
 
 
9
   YaspGeometry realizes the concept of the geometric part of a mesh entity.
 
10
 
 
11
   We have specializations for dim == dimworld (elements) and dim == 0
 
12
   (vertices).  The general version implements dim == dimworld-1 (faces)
 
13
   and otherwise throws a GridError.
 
14
 */
 
15
 
 
16
namespace Dune {
 
17
 
 
18
  //! The general version can do any dimension, but constructors currently exist only for dim==dimworld-1
 
19
  template<int mydim,int cdim, class GridImp>
 
20
  class YaspGeometry : public AxisAlignedCubeGeometry<typename GridImp::ctype,mydim,cdim>
 
21
  {
 
22
  public:
 
23
    //! define type used for coordinates in grid module
 
24
    typedef typename GridImp::ctype ctype;
 
25
 
 
26
    //! default constructor
 
27
    YaspGeometry ()
 
28
      : AxisAlignedCubeGeometry<ctype,mydim,cdim>(FieldVector<ctype,cdim>(0),FieldVector<ctype,cdim>(0)) // anything
 
29
    {}
 
30
 
 
31
    //! constructor from midpoint and extension and missing direction number
 
32
    YaspGeometry (const FieldVector<ctype, cdim>& p, const FieldVector<ctype, cdim>& h, uint8_t& m)
 
33
      : AxisAlignedCubeGeometry<ctype,mydim,cdim>(FieldVector<ctype,cdim>(0),FieldVector<ctype,cdim>(0)) // anything
 
34
    {
 
35
      if (cdim!=mydim+1)
 
36
        DUNE_THROW(GridError, "This YaspGeometry constructor assumes cdim=mydim+1");
 
37
 
 
38
      FieldVector<ctype, cdim> lower = p;
 
39
      FieldVector<ctype, cdim> upper = p;
 
40
      lower.axpy(-0.5,h);
 
41
      upper.axpy( 0.5,h);
 
42
 
 
43
      lower[m] = upper[m] = p[m];
 
44
 
 
45
      std::bitset<cdim> axes((1<<cdim)-1);    // all bits set
 
46
      axes[m] = false; // except the one at 'missing'
 
47
 
 
48
      // set up base class
 
49
      static_cast< AxisAlignedCubeGeometry<ctype,mydim,cdim> & >( *this ) = AxisAlignedCubeGeometry<ctype,mydim,cdim>(lower, upper, axes);
 
50
    }
 
51
 
 
52
    //! copy constructor
 
53
    YaspGeometry (const YaspGeometry& other)
 
54
      : AxisAlignedCubeGeometry<ctype,mydim,cdim>(other)
 
55
    {}
 
56
 
 
57
    //! print function
 
58
    void print (std::ostream& s) const
 
59
    {
 
60
      s << "YaspGeometry<"<<mydim<<","<<cdim<< "> ";
 
61
      s << "midpoint";
 
62
      for (int i=0; i<cdim; i++)
 
63
        s << " " << 0.5*(this->lower_[i] + this->upper_[i]);
 
64
      s << " extension";
 
65
      for (int i=0; i<cdim; i++)
 
66
        s << " " << (this->upper_[i] - this->lower_[i]);
 
67
      s << " coordinates: " << this->axes_;
 
68
    }
 
69
 
 
70
  };
 
71
 
 
72
 
 
73
 
 
74
  //! specialize for dim=dimworld, i.e. a volume element
 
75
  template<int mydim, class GridImp>
 
76
  class YaspGeometry<mydim,mydim,GridImp> : public AxisAlignedCubeGeometry<typename GridImp::ctype,mydim,mydim>
 
77
  {
 
78
  public:
 
79
    typedef typename GridImp::ctype ctype;
 
80
 
 
81
    //! default constructor
 
82
    YaspGeometry ()
 
83
      : AxisAlignedCubeGeometry<ctype,mydim,mydim>(FieldVector<ctype,mydim>(0),FieldVector<ctype,mydim>(0)) // anything
 
84
    {}
 
85
 
 
86
    //! constructor from midpoint and extension
 
87
    YaspGeometry (const FieldVector<ctype, mydim>& p, const FieldVector<ctype, mydim>& h)
 
88
      : AxisAlignedCubeGeometry<ctype,mydim,mydim>(FieldVector<ctype,mydim>(0),FieldVector<ctype,mydim>(0)) // anything
 
89
    {
 
90
      FieldVector<ctype, mydim> lower = p;
 
91
      FieldVector<ctype, mydim> upper = p;
 
92
      lower.axpy(-0.5,h);
 
93
      upper.axpy( 0.5,h);
 
94
      // set up base class
 
95
      static_cast< AxisAlignedCubeGeometry<ctype,mydim,mydim> & >( *this ) = AxisAlignedCubeGeometry<ctype,mydim,mydim>(lower, upper);
 
96
    }
 
97
 
 
98
    //! copy constructor (skipping temporary variables)
 
99
    YaspGeometry (const YaspGeometry& other)
 
100
      : AxisAlignedCubeGeometry<ctype,mydim,mydim>(other)
 
101
    {}
 
102
 
 
103
    //! print function
 
104
    void print (std::ostream& s) const
 
105
    {
 
106
      s << "YaspGeometry<"<<mydim<<","<<mydim<< "> ";
 
107
      s << "midpoint";
 
108
      for (int i=0; i<mydim; i++)
 
109
        s << " " << 0.5 * (this->lower_[i] + this->upper_[i]);
 
110
      s << " extension";
 
111
      for (int i=0; i<mydim; i++)
 
112
        s << " " << (this->upper_[i] + this->lower_[i]);
 
113
    }
 
114
 
 
115
  };
 
116
 
 
117
  //! specialization for dim=0, this is a vertex
 
118
  template<int cdim, class GridImp>
 
119
  class YaspGeometry<0,cdim,GridImp> : public AxisAlignedCubeGeometry<typename GridImp::ctype,0,cdim>
 
120
  {
 
121
  public:
 
122
    typedef typename GridImp::ctype ctype;
 
123
 
 
124
    //! default constructor
 
125
    YaspGeometry ()
 
126
      : AxisAlignedCubeGeometry<typename GridImp::ctype,0,cdim>(FieldVector<ctype,cdim>(0)) // anything
 
127
    {}
 
128
 
 
129
    //! constructor
 
130
    explicit YaspGeometry ( const FieldVector< ctype, cdim > &p )
 
131
      : AxisAlignedCubeGeometry<typename GridImp::ctype,0,cdim>( p )
 
132
    {}
 
133
 
 
134
    YaspGeometry ( const FieldVector< ctype, cdim > &p, const FieldVector< ctype, cdim > &, uint8_t &)
 
135
      : AxisAlignedCubeGeometry<typename GridImp::ctype,0,cdim>( p )
 
136
    {}
 
137
 
 
138
    //! print function
 
139
    void print (std::ostream& s) const
 
140
    {
 
141
      s << "YaspGeometry<"<<0<<","<<cdim<< "> ";
 
142
      s << "position " << this->lower_;
 
143
    }
 
144
  };
 
145
 
 
146
  // operator<< for all YaspGeometrys
 
147
  template <int mydim, int cdim, class GridImp>
 
148
  inline
 
149
  std::ostream& operator<< (std::ostream& s, YaspGeometry<mydim,cdim,GridImp>& e)
 
150
  {
 
151
    e.print(s);
 
152
    return s;
 
153
  }
 
154
 
 
155
}  // namespace Dune
 
156
 
 
157
#endif // DUNE_GRID_YASPGRIDGEOMETRY_HH