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

« back to all changes in this revision

Viewing changes to dune/grid/uggrid/uggridgeometry.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:
1
3
#ifndef DUNE_UGGRIDGEOMETRY_HH
2
4
#define DUNE_UGGRIDGEOMETRY_HH
3
5
 
5
7
 * \brief The UGGridGeometry class and its specializations
6
8
 */
7
9
 
8
 
#include <dune/common/array.hh>
9
10
#include <dune/common/fmatrix.hh>
10
11
 
11
 
#include <dune/geometry/genericgeometry/geometry.hh>
12
 
 
13
 
#include "uggridrenumberer.hh"
 
12
#include <dune/geometry/multilineargeometry.hh>
14
13
 
15
14
namespace Dune {
16
15
 
17
16
 
18
 
  /** \brief Defines the geometry part of a mesh entity. 
 
17
  /** \brief Defines the geometry part of a mesh entity.
19
18
   * \ingroup UGGrid
20
19
 
21
 
  \tparam mydim Dimension of the corresponding reference element
22
 
  \tparam coorddim Each corner is a point with coorddim coordinates.
 
20
     \tparam mydim Dimension of the corresponding reference element
 
21
     \tparam coorddim Each corner is a point with coorddim coordinates.
23
22
 
24
 
  This version is actually used only for mydim==coorddim. The mydim<coorddim cases
25
 
  are in specializations below.
26
 
*/
27
 
template<int mydim, int coorddim, class GridImp>  
28
 
class UGGridGeometry : 
29
 
        public GeometryDefaultImplementation <mydim, coorddim, GridImp, UGGridGeometry>
30
 
 
23
     This version is actually used only for mydim==coorddim. The mydim<coorddim cases
 
24
     are in specializations below.
 
25
   */
 
26
  template<int mydim, int coorddim, class GridImp>
 
27
  class UGGridGeometry :
 
28
    public GeometryDefaultImplementation <mydim, coorddim, GridImp, UGGridGeometry>
 
29
  {
31
30
    typedef typename GridImp::ctype UGCtype;
32
31
 
33
32
    template <int codim_, int dim_, class GridImp_>
34
33
    friend class UGGridEntity;
35
34
 
36
 
public:
 
35
  public:
37
36
 
38
37
    /** \brief Default constructor
39
38
     */
40
39
    UGGridGeometry()
41
40
    {
42
 
          jacobianIsUpToDate_ = false;
43
 
          jacobianInverseIsUpToDate_ = false;
44
 
  }
 
41
      jacobianIsUpToDate_ = false;
 
42
      jacobianInverseIsUpToDate_ = false;
 
43
    }
45
44
 
46
 
    /** \brief Return the element type identifier 
 
45
    /** \brief Return the element type identifier
47
46
     *
48
47
     * UGGrid supports triangles and quadrilaterals in 2D, and
49
48
     * tetrahedra, pyramids, prisms, and hexahedra in 3D.
55
54
 
56
55
    //! return the number of corners of this element.
57
56
    int corners () const {
58
 
        return UG_NS<coorddim>::Corners_Of_Elem(target_);
 
57
      return UG_NS<coorddim>::Corners_Of_Elem(target_);
59
58
    }
60
59
 
61
 
    //! access to coordinates of corners. Index is the number of the corner 
 
60
    //! access to coordinates of corners. Index is the number of the corner
62
61
    FieldVector<UGCtype, coorddim> corner (int i) const;
63
62
 
64
 
    /** \brief Maps a local coordinate within reference element to 
 
63
    /** \brief Maps a local coordinate within reference element to
65
64
     * global coordinate in element  */
66
65
    FieldVector<UGCtype, coorddim> global (const FieldVector<UGCtype, mydim>& local) const;
67
 
  
68
 
    /** \brief Maps a global coordinate within the element to a 
 
66
 
 
67
    /** \brief Maps a global coordinate within the element to a
69
68
     * local coordinate in its reference element */
70
69
    FieldVector<UGCtype, mydim> local (const FieldVector<UGCtype, coorddim>& global) const;
71
 
  
 
70
 
72
71
    /**
73
 
    Integration over a general element is done by integrating over the reference element
74
 
    and using the transformation from the reference element to the global element as follows:
75
 
    \f[\int\limits_{\Omega_e} f(x) dx = \int\limits_{\Omega_{ref}} f(g(l)) A(l) dl \f] where
76
 
    \f$g\f$ is the local to global mapping and \f$A(l)\f$ is the integration element. 
77
 
 
78
 
    For a general map \f$g(l)\f$ involves partial derivatives of the map (surface element of
79
 
    the first kind if \f$d=2,w=3\f$, determinant of the Jacobian of the transformation for
80
 
    \f$d=w\f$, \f$\|dg/dl\|\f$ for \f$d=1\f$).
81
 
 
82
 
    For linear elements, the derivatives of the map with respect to local coordinates
83
 
    do not depend on the local coordinates and are the same over the whole element.
84
 
 
85
 
    For a structured mesh where all edges are parallel to the coordinate axes, the 
86
 
    computation is the length, area or volume of the element is very simple to compute.
87
 
 
88
 
    Each grid module implements the integration element with optimal efficiency. This
89
 
    will directly translate in substantial savings in the computation of finite element
90
 
    stiffness matrices.
91
 
   */
 
72
       Integration over a general element is done by integrating over the reference element
 
73
       and using the transformation from the reference element to the global element as follows:
 
74
       \f[\int\limits_{\Omega_e} f(x) dx = \int\limits_{\Omega_{ref}} f(g(l)) A(l) dl \f] where
 
75
       \f$g\f$ is the local to global mapping and \f$A(l)\f$ is the integration element.
 
76
 
 
77
       For a general map \f$g(l)\f$ involves partial derivatives of the map (surface element of
 
78
       the first kind if \f$d=2,w=3\f$, determinant of the Jacobian of the transformation for
 
79
       \f$d=w\f$, \f$\|dg/dl\|\f$ for \f$d=1\f$).
 
80
 
 
81
       For linear elements, the derivatives of the map with respect to local coordinates
 
82
       do not depend on the local coordinates and are the same over the whole element.
 
83
 
 
84
       For a structured mesh where all edges are parallel to the coordinate axes, the
 
85
       computation is the length, area or volume of the element is very simple to compute.
 
86
 
 
87
       Each grid module implements the integration element with optimal efficiency. This
 
88
       will directly translate in substantial savings in the computation of finite element
 
89
       stiffness matrices.
 
90
     */
92
91
    UGCtype integrationElement (const FieldVector<UGCtype, mydim>& local) const;
93
92
 
94
93
    UGCtype volume() const {
95
 
        
96
 
        if (mydim==0)
97
 
            return 1;
98
 
 
99
 
        // coorddim*coorddim is an upper bound for the number of vertices
100
 
        UGCtype* cornerCoords[coorddim*coorddim];
101
 
        UG_NS<coorddim>::Corner_Coordinates(target_, cornerCoords);
102
 
        return UG_NS<coorddim>::Area_Of_Element(corners(), 
103
 
                                                const_cast<const double**>(cornerCoords));
 
94
 
 
95
      if (mydim==0)
 
96
        return 1;
 
97
 
 
98
      // coorddim*coorddim is an upper bound for the number of vertices
 
99
      UGCtype* cornerCoords[coorddim*coorddim];
 
100
      UG_NS<coorddim>::Corner_Coordinates(target_, cornerCoords);
 
101
      return UG_NS<coorddim>::Area_Of_Element(corners(),
 
102
                                              const_cast<const double**>(cornerCoords));
104
103
    }
105
104
 
106
105
    //! The inverse transpose of the Jacobian matrix of the mapping from the reference element to this element
109
108
    const FieldMatrix<UGCtype, mydim,coorddim>& jacobianTransposed (const FieldVector<UGCtype, mydim>& local) const;
110
109
 
111
110
 
112
 
private:
113
 
 
114
 
  /** \brief Init the element with a given UG element */
115
 
    void setToTarget(typename UG_NS<coorddim>::template Entity<coorddim-mydim>::T* target) 
116
 
  {
117
 
  target_ = target;
118
 
        jacobianIsUpToDate_ = false;
119
 
        jacobianInverseIsUpToDate_ = false;
120
 
  }
121
 
 
122
 
  //! The jacobian inverse transposed
123
 
  mutable FieldMatrix<UGCtype,coorddim,mydim> jac_inverse_;
124
 
  //! The jacobian transposed
125
 
  mutable FieldMatrix<UGCtype,mydim,coorddim> jac_;
 
111
  private:
 
112
 
 
113
    /** \brief Init the element with a given UG element */
 
114
    void setToTarget(typename UG_NS<coorddim>::template Entity<coorddim-mydim>::T* target)
 
115
    {
 
116
      target_ = target;
 
117
      jacobianIsUpToDate_ = false;
 
118
      jacobianInverseIsUpToDate_ = false;
 
119
    }
 
120
 
 
121
    //! The jacobian inverse transposed
 
122
    mutable FieldMatrix<UGCtype,coorddim,mydim> jac_inverse_;
 
123
    //! The jacobian transposed
 
124
    mutable FieldMatrix<UGCtype,mydim,coorddim> jac_;
126
125
 
127
126
    /** \brief For simplices the Jacobian matrix is a constant, hence it needs
128
127
        to be computed only once for each new element.  This can save some
130
129
    mutable bool jacobianInverseIsUpToDate_;
131
130
    mutable bool jacobianIsUpToDate_;
132
131
 
133
 
  // in element mode this points to the element we map to
134
 
  // in coord_mode this is the element whose reference element is mapped into the father's one
135
 
  typename UG_NS<coorddim>::template Entity<coorddim-mydim>::T* target_;
136
 
 
137
 
};
138
 
 
139
 
 
140
 
 
141
 
/****************************************************************/
142
 
/*                                                              */
143
 
/*       Specialization for faces in 3d                         */
144
 
/*                                                              */
145
 
/****************************************************************/
146
 
 
147
 
template<class GridImp>  
148
 
class UGGridGeometry<2, 3, GridImp> : 
149
 
    public GenericGeometry::BasicGeometry<2, GenericGeometry::DefaultGeometryTraits<typename GridImp::ctype,2,3> >
150
 
151
 
 
152
 
    template <int codim_, int dim_, class GridImp_>
153
 
    friend class UGGridEntity;
154
 
 
155
 
    template <class GridImp_>
156
 
    friend class UGGridIntersectionIterator;
157
 
 
158
 
    typedef typename GenericGeometry::BasicGeometry<2, GenericGeometry::DefaultGeometryTraits<typename GridImp::ctype,2,3> > Base;
159
 
 
160
 
public:
161
 
    static const int mydimension = 2;
162
 
    static const int coorddimension = 3;
163
 
 
164
 
    /** \brief Setup method with a geometry type and a set of corners
165
 
        \param coordinates The corner coordinates in DUNE numbering
166
 
    */
167
 
    void setup(const GeometryType& type, const std::vector<FieldVector<typename GridImp::ctype,3> >& coordinates)
168
 
    {
169
 
        // set up base class
170
 
        // Yes, a strange way, but the only way, as BasicGeometry doesn't have a setup method
171
 
        static_cast< Base & >( *this ) = Base( type, coordinates );
172
 
    }
173
 
 
174
 
};
175
 
 
176
 
 
177
 
/****************************************************************/
178
 
/*                                                              */
179
 
/*       Specialization for faces in 2d                         */
180
 
/*                                                              */
181
 
/****************************************************************/
182
 
 
183
 
template<class GridImp>  
184
 
class UGGridGeometry <1, 2, GridImp> : 
185
 
    public GenericGeometry::BasicGeometry<1, GenericGeometry::DefaultGeometryTraits<typename GridImp::ctype,1,2> >
186
 
187
 
    
188
 
    template <int codim_, int dim_, class GridImp_>
189
 
    friend class UGGridEntity;
190
 
 
191
 
    template <class GridImp_>
192
 
    friend class UGGridIntersectionIterator;
193
 
 
194
 
    typedef typename GenericGeometry::BasicGeometry<1, GenericGeometry::DefaultGeometryTraits<typename GridImp::ctype,1,2> > Base;
195
 
 
196
 
public:
197
 
    static const int mydimension = 1;
198
 
    static const int coorddimension = 2;
199
 
 
200
 
    /** \brief Constructor with a geometry type and a set of corners */
201
 
    void setup(const GeometryType& type, const std::vector<FieldVector<typename GridImp::ctype,2> >& coordinates)
202
 
    {
203
 
        // set up base class
204
 
        // Yes, a strange way, but the only way, as BasicGeometry doesn't have a setup method
205
 
        static_cast< Base & >( *this ) = Base( type, coordinates );
206
 
    }
207
 
 
208
 
};
 
132
    // in element mode this points to the element we map to
 
133
    // in coord_mode this is the element whose reference element is mapped into the father's one
 
134
    typename UG_NS<coorddim>::template Entity<coorddim-mydim>::T* target_;
 
135
 
 
136
  };
 
137
 
 
138
 
 
139
 
 
140
  /****************************************************************/
 
141
  /*                                                              */
 
142
  /*       Specialization for faces in 3d                         */
 
143
  /*                                                              */
 
144
  /****************************************************************/
 
145
 
 
146
  template<class GridImp>
 
147
  class UGGridGeometry<2, 3, GridImp> :
 
148
    public CachedMultiLinearGeometry<typename GridImp::ctype, 2, 3>
 
149
  {
 
150
  public:
 
151
 
 
152
    /** \brief Constructor from a given geometry type and a vector of corner coordinates */
 
153
    UGGridGeometry(const GeometryType& type, const std::vector<FieldVector<typename GridImp::ctype,3> >& coordinates)
 
154
      : CachedMultiLinearGeometry<typename GridImp::ctype, 2, 3>(type, coordinates)
 
155
    {}
 
156
 
 
157
  };
 
158
 
 
159
 
 
160
  /****************************************************************/
 
161
  /*                                                              */
 
162
  /*       Specialization for faces in 2d                         */
 
163
  /*                                                              */
 
164
  /****************************************************************/
 
165
 
 
166
  template<class GridImp>
 
167
  class UGGridGeometry <1, 2, GridImp> :
 
168
    public CachedMultiLinearGeometry<typename GridImp::ctype,1,2>
 
169
  {
 
170
  public:
 
171
 
 
172
    /** \brief Constructor from a given geometry type and a vector of corner coordinates */
 
173
    UGGridGeometry(const GeometryType& type, const std::vector<FieldVector<typename GridImp::ctype,2> >& coordinates)
 
174
      : CachedMultiLinearGeometry<typename GridImp::ctype, 1, 2>(type, coordinates)
 
175
    {}
 
176
 
 
177
  };
209
178
 
210
179
  namespace FacadeOptions
211
180
  {