[Dune] [Dune-Commit] dune-grid r7578 - trunk/dune/grid/genericgeometry

Martin Nolte nolte at mathematik.uni-freiburg.de
Tue Mar 29 17:04:34 CEST 2011


Hi Christian,

to be honest, I do not see the difference either. Previously, the overloaded
method std::abs was called. Now, I use a template to do the specialization
over the field type. Should not make a difference. It did, though.

In our example, the file matrixhelper.hh was included directly by config.h and
dune/localfunctions/utility.field.hh (which contains the overload for
amp::ampf) was included in dune/localfunctions/lagrange/lobattopointset.hh.
Then, when instantiating the MatrixHelper, it would not find std::abs for
amp::ampf while it does find the specialized template. Weird, isn't it?

You can reproduce this problem as follows
(1) use the outcommented std::abs instead of FieldHelper::abs in matrixhelper.hh.
(2) add '#define YASPGRID' and '#define GRIDDIM 2' before the include to
config.h in testgenericfem.cc
(3) compile testgenericfem

Best,

Martin

On 03/29/2011 04:34 PM, Christian Engwer wrote:
> Hi Martin,
> 
> I don't quite undestand, what happend here. How is the new
> construction different from the previous one? Can you enlight me?
> 
> Thanks
> Christian
> 
> On Tue, Mar 29, 2011 at 04:06:59PM +0200, mnolte at dune-project.org wrote:
>> Author: mnolte
>> Date: 2011-03-29 16:06:59 +0200 (Tue, 29 Mar 2011)
>> New Revision: 7578
>>
>> Modified:
>>    trunk/dune/grid/genericgeometry/matrixhelper.hh
>> Log:
>> fix a problem with method overloading
>>
>>
>> Modified: trunk/dune/grid/genericgeometry/matrixhelper.hh
>> ===================================================================
>> --- trunk/dune/grid/genericgeometry/matrixhelper.hh	2011-03-21 23:22:41 UTC (rev 7577)
>> +++ trunk/dune/grid/genericgeometry/matrixhelper.hh	2011-03-29 14:06:59 UTC (rev 7578)
>> @@ -1,6 +1,8 @@
>>  #ifndef DUNE_GENERICGEOMETRY_MATRIXHELPER_HH
>>  #define DUNE_GENERICGEOMETRY_MATRIXHELPER_HH
>>  
>> +#include <cmath>
>> +
>>  #include <dune/common/fvector.hh>
>>  #include <dune/common/fmatrix.hh>
>>  #include <dune/common/static_assert.hh>
>> @@ -11,11 +13,31 @@
>>    namespace GenericGeometry
>>    {
>>  
>> +    // FieldHelper
>> +    // -----------
>> +
>> +    template< class Field >
>> +    struct FieldHelper
>> +    {
>> +      static Field abs ( const Field &x ) { return std::abs( x ); }
>> +    };
>> +
>> +
>> +
>> +    // MatrixHelper
>> +    // ------------
>> +
>>      template< class Traits >
>>      struct MatrixHelper
>>      {
>> -      typedef typename Traits :: ctype FieldType;
>> +      typedef typename Traits::ctype FieldType;
>>  
>> +      static FieldType abs ( const FieldType &x )
>> +      {
>> +        //return std::abs( x );
>> +        return FieldHelper< FieldType >::abs( x );
>> +      }
>> +
>>        template< int m, int n >
>>        static void
>>        Ax ( const typename Traits :: template Matrix< m, n > :: type &A,
>> @@ -373,7 +395,7 @@
>>          if( (n == 2) && (m == 2) )
>>          {
>>            // Special implementation for 2x2 matrices: faster and more stable
>> -          return std::abs( A[ 0 ][ 0 ]*A[ 1 ][ 1 ] - A[ 1 ][ 0 ]*A[ 0 ][ 1 ] );
>> +          return abs( A[ 0 ][ 0 ]*A[ 1 ][ 1 ] - A[ 1 ][ 0 ]*A[ 0 ][ 1 ] );
>>          }
>>          else if( (n == 3) && (m == 3) )
>>          {
>> @@ -381,7 +403,7 @@
>>            const FieldType v0 = A[ 0 ][ 1 ] * A[ 1 ][ 2 ] - A[ 1 ][ 1 ] * A[ 0 ][ 2 ];
>>            const FieldType v1 = A[ 0 ][ 2 ] * A[ 1 ][ 0 ] - A[ 1 ][ 2 ] * A[ 0 ][ 0 ];
>>            const FieldType v2 = A[ 0 ][ 0 ] * A[ 1 ][ 1 ] - A[ 1 ][ 0 ] * A[ 0 ][ 1 ];
>> -          return std::abs( v0 * A[ 2 ][ 0 ] + v1 * A[ 2 ][ 1 ] + v2 * A[ 2 ][ 2 ] );
>> +          return abs( v0 * A[ 2 ][ 0 ] + v1 * A[ 2 ][ 1 ] + v2 * A[ 2 ][ 2 ] );
>>          }
>>          else if( n >= m )
>>          {
>> @@ -438,7 +460,7 @@
>>            ret[ 1 ][ 1 ] = A[ 0 ][ 0 ] * detInv;
>>            ret[ 1 ][ 0 ] = -A[ 1 ][ 0 ] * detInv;
>>            ret[ 0 ][ 1 ] = -A[ 0 ][ 1 ] * detInv;
>> -          return std::abs( det );
>> +          return abs( det );
>>          }
>>          else
>>          {
>> @@ -464,8 +486,8 @@
>>        }
>>      };
>>  
>> -  }
>> +  } // namespace GenericGeometry
>>    
>> -}
>> +} // namespace Dune
>>  
>>  #endif // #ifndef DUNE_GENERICGEOMETRY_MATRIXHELPER_HH
>>
>>
>> _______________________________________________
>> Dune-Commit mailing list
>> Dune-Commit at dune-project.org
>> http://lists.dune-project.org/mailman/listinfo/dune-commit
>>
> 
> _______________________________________________
> Dune mailing list
> Dune at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune

-- 
Martin Nolte <nolte at mathematik.uni-freiburg.de>

Universität Freiburg                                   phone: +49-761-203-5630
Abteilung für angewandte Mathematik                    fax:   +49-761-203-5632
Hermann-Herder-Straße 10
79104 Freiburg, Germany




More information about the Dune mailing list