[dune-pdelab] [dune-pdelab-commit] dune-pdelab r1156 - branches/2.1snapshot/dune/pdelab/finiteelement
Christian Engwer
christi at uni-hd.de
Fri Feb 25 00:12:39 CET 2011
Hi Peter,
was it intended to commit the caches to the 2.1snapshot? I though we
wanted to add the new features to the trunk, to avoid possible side
effects.
Christian
On Thu, Feb 24, 2011 at 10:54:56PM +0100, peter at conan.iwr.uni-heidelberg.de wrote:
> Author: peter
> Date: Thu Feb 24 22:54:56 2011
> New Revision: 1156
> URL: http://svn.dune-project.org/websvn/listing.php?repname=dune-pdelab&path=/&rev=1156&sc=1
>
> Log:
> first implementation of a cache for basis function evaluations
>
> Added:
> branches/2.1snapshot/dune/pdelab/finiteelement/localbasiscache.hh
> Modified:
> branches/2.1snapshot/dune/pdelab/finiteelement/Makefile.am
>
> Modified: branches/2.1snapshot/dune/pdelab/finiteelement/Makefile.am
> ==============================================================================
> --- branches/2.1snapshot/dune/pdelab/finiteelement/Makefile.am Thu Feb 24 15:28:45 2011 (r1155)
> +++ branches/2.1snapshot/dune/pdelab/finiteelement/Makefile.am Thu Feb 24 22:54:56 2011 (r1156)
> @@ -1,5 +1,6 @@
> mydir = $(includedir)/dune/pdelab/finiteelement
> my_HEADERS = \
> - interfaceswitch.hh
> + interfaceswitch.hh \
> + localbasiscache.hh
>
> include $(top_srcdir)/am/global-rules
>
> Added: branches/2.1snapshot/dune/pdelab/finiteelement/localbasiscache.hh
> ==============================================================================
> --- /dev/null 00:00:00 1970 (empty, because file is newly added)
> +++ branches/2.1snapshot/dune/pdelab/finiteelement/localbasiscache.hh Thu Feb 24 22:54:56 2011 (r1156)
> @@ -0,0 +1,76 @@
> +// -*- tab-width: 4; indent-tabs-mode: nil -*-
> +#ifndef DUNE_PDELAB_LOCALBASISCACHE_HH
> +#define DUNE_PDELAB_LOCALBASISCACHE_HH
> +
> +#include<vector>
> +#include<map>
> +
> +#include<dune/common/exceptions.hh>
> +#include<dune/common/static_assert.hh>
> +
> +namespace Dune {
> + namespace PDELab {
> +
> + //! \brief store values of basis functions and gradients in a cache
> + template<class LocalBasisType>
> + class LocalBasisCache
> + {
> + typedef typename LocalBasisType::Traits::DomainFieldType DomainFieldType;
> + typedef typename LocalBasisType::Traits::DomainType DomainType;
> + typedef typename LocalBasisType::Traits::RangeType RangeType;
> + typedef typename LocalBasisType::Traits::JacobianType JacobianType;
> +
> + struct less_than
> + {
> + bool operator() (const DomainType& v1, const DomainType& v2) const
> + {
> + for (typename DomainType::size_type i=0; i<DomainType::size; i++)
> + {
> + if ( v1[i] < v2[i]-1e-5 ) return true; // is less than
> + if ( v1[i] > v2[i]+1e-5 ) return false; // is greater than
> + }
> + return false; // is equal
> + }
> + };
> +
> + typedef std::map<DomainType,std::vector<RangeType>,less_than> FunctionCache;
> + typedef std::map<DomainType,std::vector<JacobianType>,less_than> JacobianCache;
> +
> + public:
> +
> + //! \brief constructor
> + LocalBasisCache () {}
> +
> + //! evaluate basis functions at a point
> + const std::vector<RangeType>&
> + evaluateFunction (const DomainType& position, const LocalBasisType& localbasis) const
> + {
> + typename FunctionCache::iterator it = functioncache.find(position);
> + if (it!=functioncache.end()) return it->second;
> + std::vector<RangeType> values;
> + localbasis.evaluateFunction(position,values);
> + it = functioncache.insert(functioncache.begin(),std::pair<DomainType,std::vector<RangeType> >(position,values));
> + return it->second;
> + }
> +
> + //! evaluate Jacobians at a point
> + const std::vector<JacobianType>&
> + evaluateJacobian (const DomainType& position, const LocalBasisType& localbasis) const
> + {
> + typename JacobianCache::iterator it = jacobiancache.find(position);
> + if (it!=jacobiancache.end()) return it->second;
> + std::vector<JacobianType> values;
> + localbasis.evaluateJacobian(position,values);
> + it = jacobiancache.insert(jacobiancache.begin(),std::pair<DomainType,std::vector<JacobianType> >(position,values));
> + return it->second;
> + }
> +
> + private:
> + mutable FunctionCache functioncache;
> + mutable JacobianCache jacobiancache;
> + };
> +
> + }
> +}
> +
> +#endif
>
> _______________________________________________
> dune-pdelab-commit mailing list
> dune-pdelab-commit at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-pdelab-commit
>
More information about the dune-pdelab
mailing list