• Main Page
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

/export/development/ViennaGrid/release/ViennaGrid-1.0.0/viennagrid/algorithm/inner_prod.hpp

Go to the documentation of this file.
00001 #ifndef VIENNAGRID_ALGORITHM_INNERPROD_HPP
00002 #define VIENNAGRID_ALGORITHM_INNERPROD_HPP
00003 
00004 /* =======================================================================
00005    Copyright (c) 2011, Institute for Microelectronics,
00006                        Institute for Analysis and Scientific Computing,
00007                        TU Wien.
00008 
00009                             -----------------
00010                      ViennaGrid - The Vienna Grid Library
00011                             -----------------
00012 
00013    Authors:      Karl Rupp                           rupp@iue.tuwien.ac.at
00014                  Josef Weinbub                    weinbub@iue.tuwien.ac.at
00015                
00016    (A list of additional contributors can be found in the PDF manual)
00017 
00018    License:      MIT (X11), see file LICENSE in the base directory
00019 ======================================================================= */
00020 
00021 #include "viennagrid/forwards.h"
00022 #include "viennagrid/traits/point.hpp"
00023 #include "viennagrid/point.hpp"
00024 
00029 namespace viennagrid 
00030 {
00031 
00032   namespace detail
00033   {
00034     template <typename PointType,
00035               long dim = traits::dimension<PointType>::value>
00036     struct inner_prod_impl;
00037 
00038     //
00039     // 1d
00040     // 
00042     template <typename PointType>
00043     struct inner_prod_impl<PointType, 1>
00044     {
00045       typedef typename traits::value_type<PointType>::type    value_type;
00046 
00047       template <typename PointType2>
00048       static value_type apply(PointType const & p1,
00049                               PointType2 const & p2)
00050       {
00051         return p1[0] * p2[0];
00052       }
00053     };
00054     
00055     //
00056     // 2d
00057     // 
00059     template <typename PointType>
00060     struct inner_prod_impl<PointType, 2>
00061     {
00062       typedef typename traits::value_type<PointType>::type    value_type;
00063 
00064       template <typename PointType2>
00065       static value_type apply(PointType const & p1,
00066                               PointType2 const & p2)
00067       {
00068         return p1[0] * p2[0] + p1[1] * p2[1];
00069       }
00070     };
00071     
00072     //
00073     // 3d
00074     // 
00076     template <typename PointType>
00077     struct inner_prod_impl<PointType, 3>
00078     {
00079       typedef typename traits::value_type<PointType>::type    value_type;
00080 
00081       template <typename PointType2>
00082       static value_type apply(PointType const & p1,
00083                               PointType2 const & p2)
00084       {
00085         return p1[0] * p2[0] + p1[1] * p2[1] + p1[2] * p2[2];
00086       }
00087     };
00088   }
00089 
00091   template<typename PointType1, typename PointType2, typename CSystem1, typename CSystem2>
00092   typename traits::value_type<PointType1>::type
00093   inner_prod_impl(PointType1 const & p1, PointType2 const & p2, CSystem1 const &, CSystem2 const &)
00094   {
00095     typedef typename traits::value_type<PointType1>::type    value_type;
00096     typedef typename result_of::cartesian_point<PointType1>::type   CartesianPoint1;
00097     
00098     return detail::inner_prod_impl<CartesianPoint1>::apply(to_cartesian(p1), to_cartesian(p2));
00099   }
00100 
00102   template<typename PointType1, typename PointType2, long d>
00103   typename traits::value_type<PointType1>::type
00104   inner_prod_impl(PointType1 const & p1, PointType2 const & p2, cartesian_cs<d>, cartesian_cs<d>)
00105   {
00106     return detail::inner_prod_impl<PointType1>::apply(p1, p2);
00107   }
00108 
00114   template<typename PointType1, typename PointType2>
00115   typename traits::value_type<PointType1>::type
00116   inner_prod(PointType1 const & p1, PointType2 const & p2)
00117   {
00118     return inner_prod_impl(p1,
00119                            p2, 
00120                            typename traits::coordinate_system<PointType1>::type(),
00121                            typename traits::coordinate_system<PointType2>::type());
00122   }
00123 
00124 } 
00125 
00126 #endif

Generated on Wed Sep 14 2011 19:21:30 for ViennaGrid by  doxygen 1.7.1