BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
linear_scalar_shapeset.hpp
1 // Copyright (C) 2011-2012 by the BEM++ Authors
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #ifndef fiber_linear_scalar_shapeset_hpp
22 #define fiber_linear_scalar_shapeset_hpp
23 
24 #include "../common/common.hpp"
25 
26 #include "basis.hpp"
27 
28 #include "basis_data.hpp"
29 #include "dune_basis_helper.hpp"
30 #include "CL/piecewise_linear_continuous_scalar_basis.cl.str"
31 
32 #include <dune/localfunctions/lagrange/p1/p1localbasis.hh>
33 #include <dune/localfunctions/lagrange/q1/q1localbasis.hh>
34 
35 namespace Fiber
36 {
37 
38 template <int elementVertexCount, typename CoordinateType, typename ValueType>
40 {
41 };
42 
43 // Line
44 template <typename CoordinateType, typename ValueType>
45 struct PiecewiseLinearContinuousScalarBasisTraits<2, CoordinateType, ValueType>
46 {
47 public:
48  typedef Dune::Q1LocalBasis<CoordinateType, ValueType, 1> DuneBasis;
49 };
50 
51 // Triangle
52 template <typename CoordinateType, typename ValueType>
53 struct PiecewiseLinearContinuousScalarBasisTraits<3, CoordinateType, ValueType>
54 {
55 public:
56  typedef Dune::P1LocalBasis<CoordinateType, ValueType, 2> DuneBasis;
57 };
58 
59 // Quadrilateral
60 template <typename CoordinateType, typename ValueType>
61 struct PiecewiseLinearContinuousScalarBasisTraits<4, CoordinateType, ValueType>
62 {
63 public:
64  typedef Dune::Q1LocalBasis<CoordinateType, ValueType, 2> DuneBasis;
65 };
66 
68 template <int elementVertexCount, typename ValueType>
69 class LinearScalarShapeset: public Basis<ValueType>
70 {
71 public:
72  typedef typename Basis<ValueType>::CoordinateType CoordinateType;
73 
74 private:
76  <elementVertexCount, CoordinateType, ValueType>::DuneBasis DuneBasis;
77 
78 public:
79  virtual int size() const {
80  DuneBasis basis;
81  return basis.size();
82  }
83 
84  virtual int order() const {
85  return 1;
86  }
87 
88  virtual void evaluate(size_t what,
89  const arma::Mat<CoordinateType>& points,
90  LocalDofIndex localDofIndex,
91  BasisData<ValueType>& data) const {
92  if (localDofIndex != ALL_DOFS &&
93  (localDofIndex < 0 || size() <= localDofIndex))
94  throw std::invalid_argument("LinearScalarShapeset::"
95  "evaluate(): Invalid localDofIndex");
96 
97  if (what & VALUES)
98  evaluateShapeFunctionsWithDune<CoordinateType, ValueType, DuneBasis>(
99  points, localDofIndex, data.values);
100  if (what & DERIVATIVES)
101  evaluateShapeFunctionDerivativesWithDune<CoordinateType, ValueType, DuneBasis>(
102  points, localDofIndex, data.derivatives);
103  }
104 
105  virtual std::pair<const char*,int> clCodeString (bool isTestShapeset) const {
106  static struct StrBuf {
107  std::pair<char*,int> str;
108  bool need_setup;
109  } test = {std::pair<char*,int>(NULL,0), true},
110  trial = {std::pair<char*,int>(NULL,0), true};
111 
112  StrBuf &buf = (isTestShapeset ? test : trial);
113  const char *modifier = (isTestShapeset ? "A" : "B");
114 
115  if (buf.need_setup) {
116  std::string funcName ("clBasisf");
117  std::string code (piecewise_linear_continuous_scalar_basis_cl,
118  piecewise_linear_continuous_scalar_basis_cl_len);
119  size_t len = funcName.size();
120  size_t n = code.find (funcName);
121  while (n != std::string::npos) {
122  code.insert (n+len, modifier);
123  n = code.find (funcName, n+len);
124  }
125  buf.str.second = code.size();
126  buf.str.first = new char[buf.str.second+1];
127  strcpy (buf.str.first, code.c_str());
128  buf.need_setup = false;
129  }
130  return buf.str;
131  }
132 
133 };
134 
135 } // namespace Fiber
136 
137 #endif
_4dArray< ValueType > derivatives
Derivatives of shape functions.
Definition: basis_data.hpp:59
virtual int order() const
Return the maximum polynomial order of shape functions.
Definition: linear_scalar_shapeset.hpp:84
virtual std::pair< const char *, int > clCodeString(bool isTestShapeset) const
Returns an OpenCL code snippet for shape function evaluation.
Definition: linear_scalar_shapeset.hpp:105
virtual int size() const
Return the number of shape functions.
Definition: linear_scalar_shapeset.hpp:79
_3dArray< ValueType > values
Values of shape functions.
Definition: basis_data.hpp:51
Definition: linear_scalar_shapeset.hpp:39
Collection of shape functions defined on a reference element.
Definition: basis.hpp:36
Storage of values and/or derivatives of shape functions.
Definition: basis_data.hpp:44
Shapeset composed of the linear nodal functions.
Definition: linear_scalar_shapeset.hpp:69
virtual void evaluate(size_t what, const arma::Mat< CoordinateType > &points, LocalDofIndex localDofIndex, BasisData< ValueType > &data) const
Evaluate the shape functions making up this shapeset and/or their derivatives at specified points...
Definition: linear_scalar_shapeset.hpp:88