dune-grid  2.2.1
geometrycache.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALBERTA_GEOMETRYCACHE_HH
2 #define DUNE_ALBERTA_GEOMETRYCACHE_HH
3 
6 
7 #if HAVE_ALBERTA
8 
9 namespace Dune
10 {
11 
12  namespace Alberta
13  {
14 
15  // GeometryCache
16  // -------------
17 
18  template< int dim >
20  {
21  static const unsigned int flagIntegrationElement = (1 << 0);
22  static const unsigned int flagJacobianTransposed = (1 << 1);
23  static const unsigned int flagJacobianInverseTransposed = (1 << 2);
24 
25  public:
26  typedef FieldMatrix< Real, dimWorld, dim > Jacobian;
27  typedef FieldMatrix< Real, dim, dimWorld > JacobianTransposed;
28 
30  : flags_( 0 )
31  {}
32 
33  const Real &integrationElement ( const ALBERTA EL_INFO &elInfo )
34  {
35  if( (flags_ & flagIntegrationElement) == 0 )
36  {
37  integrationElement_ = std::abs( determinant( jacobianTransposed( elInfo ) ) );
38  assert( integrationElement_ > 1e-14 );
39  flags_ |= flagIntegrationElement;
40  }
41  return integrationElement_;
42  }
43 
44  const JacobianTransposed &jacobianTransposed ( const ALBERTA EL_INFO &elInfo )
45  {
46  if( (flags_ & flagJacobianTransposed) == 0 )
47  {
48  assert( (elInfo.fill_flag & FillFlags< dim >::coords) != 0 );
49  const GlobalVector &x = elInfo.coord[ 0 ];
50  for( int i = 0; i < dim; ++i )
51  {
52  const GlobalVector &y = elInfo.coord[ i+1 ];
53  for( int j = 0; j < dimWorld; ++j )
54  jacobianTransposed_[ i ][ j ] = y[ j ] - x[ j ];
55  }
56  flags_ |= flagJacobianTransposed;
57  }
58  return jacobianTransposed_;
59  }
60 
61  const Jacobian &jacobianInverseTransposed ( const ALBERTA EL_INFO &elInfo )
62  {
63  if( (flags_ & flagJacobianInverseTransposed) == 0 )
64  {
65  integrationElement_ = std::abs( invert( jacobianTransposed( elInfo ), jacobianInverseTransposed_ ) );
66  assert( integrationElement_ > 1e-14 );
67  flags_ |= flagIntegrationElement | flagJacobianInverseTransposed;
68  }
69  return jacobianInverseTransposed_;
70  }
71 
72  private:
73  unsigned int flags_;
74  Real integrationElement_;
75  FieldMatrix< Real, dim, dimWorld > jacobianTransposed_;
76  FieldMatrix< Real, dimWorld, dim > jacobianInverseTransposed_;
77  };
78 
79 
80 
81  // GeometryCacheProxy
82  // ------------------
83 
84  template< int dim >
86  {
87  typedef FieldMatrix< Real, dimWorld, dim > Jacobian;
88  typedef FieldMatrix< Real, dim, dimWorld > JacobianTransposed;
89 
90  GeometryCacheProxy ( GeometryCache< dim > &geometryCache, const ALBERTA EL_INFO &elInfo )
91  : geometryCache_( geometryCache ),
92  elInfo_( elInfo )
93  {}
94 
96  {
97  return geometryCache_.integrationElement( elInfo_ );
98  }
99 
101  {
102  return geometryCache_.jacobianTransposed( elInfo_ );
103  }
104 
106  {
107  return geometryCache_.jacobianInverseTransposed( elInfo_ );
108  }
109 
110  private:
111  GeometryCache< dim > &geometryCache_;
112  const ALBERTA EL_INFO &elInfo_;
113  };
114 
115  } // namespace Alberta
116 
117 } // namespace Dune
118 
119 #endif // #if HAVE_ALBERTA
120 
121 #endif // #ifndef DUNE_ALBERTA_GEOMETRYCACHE_HH