~ubuntu-branches/ubuntu/vivid/dune-grid/vivid

« back to all changes in this revision

Viewing changes to dune/grid/onedgrid/onedgridgeometry.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_ONE_D_GEOMETRY_HH
2
4
#define DUNE_ONE_D_GEOMETRY_HH
3
5
 
 
6
#include <dune/geometry/axisalignedcubegeometry.hh>
 
7
 
4
8
#include <dune/grid/common/geometry.hh>
5
9
 
6
10
#include <dune/grid/onedgrid/onedgridentity.hh>
11
15
 
12
16
namespace Dune {
13
17
 
14
 
    // forward declaration
15
 
    template <int codim, int dim, class GridImp>
16
 
    class OneDGridEntity;
17
 
 
18
 
    /** \brief Unspecialized class.  Not used for anything */
19
 
    template<int mydim, int coorddim, class GridImp>
20
 
    class OneDGridGeometry;
21
 
 
22
 
template<class GridImp>  
23
 
class OneDGridGeometry <0, 1, GridImp> : 
24
 
        public GeometryDefaultImplementation <0, 1, GridImp,OneDGridGeometry>
25
 
26
 
    
 
18
  // forward declaration
 
19
  template <int codim, int dim, class GridImp>
 
20
  class OneDGridEntity;
 
21
 
 
22
  /** \brief Unspecialized class.  Not used for anything */
 
23
  template<int mydim, int coorddim, class GridImp>
 
24
  class OneDGridGeometry;
 
25
 
 
26
  template<class GridImp>
 
27
  class OneDGridGeometry <0, 1, GridImp> :
 
28
    public GeometryDefaultImplementation <0, 1, GridImp,OneDGridGeometry>
 
29
  {
 
30
 
27
31
    template <int codim_, int dim_, class GridImp_>
28
32
    friend class OneDGridEntity;
29
33
    template <int mydim_, int coorddim_, class GridImp_>
30
34
    friend class OneDGridGeometry;
31
35
 
32
 
public:
 
36
  public:
33
37
 
34
38
    OneDGridGeometry() : storeCoordsLocally_(false) {}
35
39
 
36
40
    //! return the element type identifier (vertex)
37
41
    GeometryType type () const {return GeometryType(0);}
38
42
 
39
 
    //! here we have always an affine geometry 
 
43
    //! here we have always an affine geometry
40
44
    bool affine() const { return true; }
41
45
 
42
46
    //! return the number of corners of this element (==1)
43
47
    int corners () const {return 1;}
44
48
 
45
 
    //! access to coordinates of corners. Index is the number of the corner 
46
 
    const FieldVector<typename GridImp::ctype, 1>& operator[] (int i) const {
47
 
        return (storeCoordsLocally_) ? pos_ : target_->pos_;
48
 
    }
49
 
 
50
49
    /** \brief access to coordinates of a corner */
51
50
    const FieldVector< typename GridImp::ctype, 1 > corner ( const int i ) const
52
51
    {
53
52
      return (storeCoordsLocally_ ? pos_ : target_->pos_);
54
53
    }
55
54
 
56
 
    /** \brief Maps a local coordinate within reference element to 
 
55
    /** \brief Maps a local coordinate within reference element to
57
56
     * global coordinate in element  */
58
57
    FieldVector<typename GridImp::ctype, 1> global (const FieldVector<typename GridImp::ctype, 0>& local) const {
59
 
        return (storeCoordsLocally_) ? pos_ : target_->pos_;
 
58
      return (storeCoordsLocally_) ? pos_ : target_->pos_;
60
59
    }
61
60
 
62
 
    /** \brief Maps a global coordinate within the element to a 
 
61
    /** \brief Maps a global coordinate within the element to a
63
62
     * local coordinate in its reference element */
64
63
    FieldVector<typename GridImp::ctype, 0> local (const FieldVector<typename GridImp::ctype, 1>& global) const {
65
 
        FieldVector<typename GridImp::ctype, 0> l;
66
 
        return l;
 
64
      FieldVector<typename GridImp::ctype, 0> l;
 
65
      return l;
67
66
    }
68
67
 
69
68
    /** \brief !!!
70
69
 
71
 
    This method really doesn't make much sense for a zero-dimensional
72
 
    object.  It always returns '1'.
73
 
    */
 
70
       This method really doesn't make much sense for a zero-dimensional
 
71
       object.  It always returns '1'.
 
72
     */
74
73
    typename GridImp::ctype integrationElement (const FieldVector<typename GridImp::ctype, 0>& local) const {
75
 
        return 1;
 
74
      return 1;
76
75
    }
77
76
 
78
77
    //! The Jacobian matrix of the mapping from the reference element to this element
84
83
 
85
84
    //! The Jacobian matrix of the mapping from the reference element to this element
86
85
    const FieldMatrix<typename GridImp::ctype,1,0>& jacobianInverseTransposed (const FieldVector<typename GridImp::ctype, 0>& local) const {
87
 
        return jacInverse_;
 
86
      return jacInverse_;
88
87
    }
89
88
 
90
89
    void setPosition(const typename GridImp::ctype& p) {
91
 
        storeCoordsLocally_ = true;
92
 
        pos_[0] = p;
 
90
      storeCoordsLocally_ = true;
 
91
      pos_[0] = p;
93
92
    }
94
93
 
95
94
    //private:
99
98
    FieldVector<typename GridImp::ctype,1> pos_;
100
99
 
101
100
    OneDEntityImp<0>* target_;
102
 
    
 
101
 
103
102
    FieldMatrix< typename GridImp::ctype, 0, 1 > jacTransposed_;
104
103
    FieldMatrix<typename GridImp::ctype,1,0> jacInverse_;
105
 
};
 
104
  };
106
105
 
107
 
//**********************************************************************
108
 
//
109
 
// --OneDGridGeometry
110
 
  /** \brief Defines the geometry part of a mesh entity. 
 
106
  //**********************************************************************
 
107
  //
 
108
  // --OneDGridGeometry
 
109
  /** \brief Defines the geometry part of a mesh entity.
111
110
   * \ingroup OneDGrid
112
 
*/
113
 
template<int mydim, int coorddim, class GridImp>  
114
 
class OneDGridGeometry : 
115
 
public GeometryDefaultImplementation <mydim, coorddim, GridImp, OneDGridGeometry>
116
 
117
 
    template <int codim_, int dim_, class GridImp_>
118
 
    friend class OneDGridEntity;
119
 
 
120
 
    friend class OneDGrid;
121
 
 
122
 
    template <int cc_, int dim_, class GridImp_>
123
 
    friend class OneDGridSubEntityFactory;
124
 
 
125
 
    template <class GridImp_>
126
 
    friend class OneDGridLevelIntersectionIterator;
127
 
    template <class GridImp_>
128
 
    friend class OneDGridLeafIntersectionIterator;
129
 
 
130
 
public:
131
 
 
132
 
    OneDGridGeometry() : storeCoordsLocally_(false) {}
133
 
 
134
 
    //! here we have always an affine geometry 
135
 
    bool affine() const { return true; }
136
 
 
137
 
    /** \brief Return the element type identifier 
138
 
     *
139
 
     * OneDGrid obviously supports only lines
140
 
     */
141
 
    GeometryType type () const {return GeometryType(1);}
142
 
 
143
 
    //! return the number of corners of this element. Corners are numbered 0...n-1
144
 
    int corners () const {return 2;}
145
 
 
146
 
    //! access to coordinates of corners. Index is the number of the corner 
147
 
    const FieldVector<typename GridImp::ctype, coorddim>& operator[](int i) const {
148
 
        assert(i==0 || i==1);
149
 
        return (storeCoordsLocally_) ? pos_[i] : target_->vertex_[i]->pos_;
150
 
    }
151
 
 
152
 
    /** \brief access to coordinates of a corner */
153
 
    const FieldVector< typename GridImp::ctype, coorddim > corner ( const int i ) const
154
 
    {
155
 
      assert( (i == 0) || (i == 1) );
156
 
      return (storeCoordsLocally_ ? pos_[ i ] : target_->vertex_[ i ]->pos_);
157
 
    }
158
 
 
159
 
    /** \brief Maps a local coordinate within reference element to 
160
 
     * global coordinate in element  */
161
 
    FieldVector<typename GridImp::ctype, coorddim> global (const FieldVector<typename GridImp::ctype, mydim>& local) const {
162
 
        FieldVector<typename GridImp::ctype, coorddim> g;
163
 
        g[0] = (storeCoordsLocally_)
164
 
            ? pos_[0][0] * (1-local[0]) + pos_[1][0] * local[0]
165
 
            : target_->vertex_[0]->pos_[0] * (1-local[0]) + target_->vertex_[1]->pos_[0] * local[0];
166
 
        return g;
167
 
    }
168
 
 
169
 
    /** \brief Maps a global coordinate within the element to a 
170
 
     * local coordinate in its reference element */
171
 
    FieldVector<typename GridImp::ctype, mydim> local (const FieldVector<typename GridImp::ctype, coorddim>& global) const {
172
 
        FieldVector<typename GridImp::ctype, mydim> l;
173
 
        if (storeCoordsLocally_) {
174
 
            l[0] = (global[0] - pos_[0][0]) / (pos_[1][0] - pos_[0][0]);
175
 
        } else {
176
 
            const typename GridImp::ctype& v0 = target_->vertex_[0]->pos_[0];
177
 
            const typename GridImp::ctype& v1 = target_->vertex_[1]->pos_[0];
178
 
            l[0] = (global[0] - v0) / (v1 - v0);
179
 
        }
180
 
        return l;
181
 
    }
182
 
    
183
 
    /** ???
184
111
   */
185
 
    typename GridImp::ctype integrationElement (const FieldVector<typename GridImp::ctype, mydim>& local) const {
186
 
        return (storeCoordsLocally_)
187
 
            ? pos_[1][0] - pos_[0][0]
188
 
            : target_->vertex_[1]->pos_[0] - target_->vertex_[0]->pos_[0];
189
 
    }
190
 
 
191
 
    //! The Jacobian matrix of the mapping from the reference element to this element
192
 
    const FieldMatrix< typename GridImp::ctype, mydim, mydim > &
193
 
    jacobianTransposed ( const FieldVector< typename GridImp::ctype, mydim > &local ) const
194
 
    {
195
 
      if( storeCoordsLocally_ )
196
 
        jacTransposed_[ 0 ][ 0 ] = (pos_[ 1 ][ 0 ] - pos_[ 0 ][ 0 ] );
197
 
      else
198
 
        jacTransposed_[ 0 ][ 0 ] = target_->vertex_[ 1 ]->pos_[ 0 ] - target_->vertex_[ 0 ]->pos_[ 0 ];
199
 
 
200
 
      return jacTransposed_;
201
 
    }
202
 
 
203
 
    //! The Jacobian matrix of the mapping from the reference element to this element
204
 
    const FieldMatrix<typename GridImp::ctype,mydim,mydim>& jacobianInverseTransposed (const FieldVector<typename GridImp::ctype, mydim>& local) const {
205
 
        if (storeCoordsLocally_)
206
 
            jacInverse_[0][0] = 1 / (pos_[1][0] - pos_[0][0]);
207
 
        else
208
 
            jacInverse_[0][0] = 1 / (target_->vertex_[1]->pos_[0] - target_->vertex_[0]->pos_[0]);
209
 
 
210
 
        return jacInverse_;
211
 
    }
212
 
 
213
 
    void setPositions(const typename GridImp::ctype& p1, const typename GridImp::ctype& p2) {
214
 
        storeCoordsLocally_ = true;
215
 
        pos_[0][0] = p1;
216
 
        pos_[1][0] = p2;
217
 
    }
218
 
 
219
 
    //private:
220
 
    OneDEntityImp<1>* target_;
221
 
 
222
 
    bool storeCoordsLocally_;
223
 
 
224
 
    // Stores the element corner positions if it is returned as geometryInFather
225
 
    FieldVector<typename GridImp::ctype,coorddim> pos_[2];
226
 
 
227
 
    //! jacobian transposed
228
 
    mutable FieldMatrix< typename GridImp::ctype, coorddim, coorddim > jacTransposed_;
229
 
    //! jacobian inverse
230
 
    mutable FieldMatrix<typename GridImp::ctype,coorddim,coorddim> jacInverse_;
231
 
 
232
 
};
 
112
  template<int mydim, int coorddim, class GridImp>
 
113
  class OneDGridGeometry :
 
114
    public AxisAlignedCubeGeometry<typename GridImp::ctype, mydim, coorddim>
 
115
  {
 
116
  public:
 
117
    OneDGridGeometry(const FieldVector<double,1>& left, const FieldVector<double,1>& right)
 
118
      : AxisAlignedCubeGeometry<typename GridImp::ctype, mydim, coorddim>(left,right)
 
119
    {}
 
120
  };
233
121
 
234
122
  namespace FacadeOptions
235
123
  {