Debian Codegraph @

dune/localfunctions/dualmortarbasis/dualpq1factory.hh

raw
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 // SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5 #ifndef DUNE_LOCALFUNCTIONS_DUAL_P1_Q1_FACTORY_HH
6 #define DUNE_LOCALFUNCTIONS_DUAL_P1_Q1_FACTORY_HH
7
8 #include <map>
9
10 #include <dune/localfunctions/common/virtualinterface.hh>
11 #include <dune/localfunctions/common/virtualwrappers.hh>
12
13 #include <dune/localfunctions/dualmortarbasis.hh>
14
15 namespace Dune {
16
17 template<class D, class R, int dim, bool faceDual=false>
18 class DualPQ1LocalFiniteElementCache
19 {
20 protected:
21 typedef Dune::DualP1LocalFiniteElement<D,R,dim,faceDual> DualP1;
22 typedef Dune::DualQ1LocalFiniteElement<D,R,dim,faceDual> DualQ1;
23 typedef typename DualP1::Traits::LocalBasisType::Traits T;
24 typedef Dune::LocalFiniteElementVirtualInterface<T> FE;
25 typedef std::map<Dune::GeometryType,FE*> FEMap;
26
27 public:
28 /** \brief Type of the finite elements stored in this cache */
29 typedef FE FiniteElementType;
30
31 ~DualPQ1LocalFiniteElementCache()
32 {
33 typename FEMap::iterator it = cache_.begin();
34 typename FEMap::iterator end = cache_.end();
35 for(; it!=end; ++it)
36 delete it->second;
37 }
38
39 //! create finite element for given GeometryType
40 static FE* create(const Dune::GeometryType& gt)
41 {
42 if (gt.isSimplex())
43 return new Dune::LocalFiniteElementVirtualImp<DualP1>(DualP1());
44 if (gt.isCube())
45 return new Dune::LocalFiniteElementVirtualImp<DualQ1>(DualQ1());
46 return 0;
47 }
48
49 //! Get local finite element for given GeometryType
50 const FiniteElementType& get(const Dune::GeometryType& gt) const
51 {
52 typename FEMap::const_iterator it = cache_.find(gt);
53 if (it==cache_.end())
54 {
55 FiniteElementType* fe = create(gt);
56
57 if (fe==0)
58 DUNE_THROW(Dune::NotImplemented,"No Dual P/Q1 like local finite element available for geometry type " << gt);
59
60 cache_[gt] = fe;
61 return *fe;
62 }
63 return *(it->second);
64 }
65
66 protected:
67 mutable FEMap cache_;
68 };
69
70 } // namespace Dune
71
72 #endif // DUNE_LOCALFUNCTIONS_DUAL_P1_Q1_FACTORY_HH