3 #ifndef DUNE_LOCALFUNCTIONS_MONOMIAL_MONOMIALLOCALBASIS_HH 4 #define DUNE_LOCALFUNCTIONS_MONOMIAL_MONOMIALLOCALBASIS_HH 10 #include <dune/common/fmatrix.hh> 11 #include <dune/common/deprecated.hh> 13 #include "../common/localbasis.hh" 21 template<
int d,
int k>
53 template <
typename Traits>
55 std::vector<typename Traits::RangeType> &out;
57 unsigned int first_unused_index;
61 EvalAccess(std::vector<typename Traits::RangeType> &out_)
64 , first_unused_index(0)
69 assert(first_unused_index == out.size());
72 typename Traits::RangeFieldType &
operator[](
unsigned int index)
74 assert(index < out.size());
76 if(first_unused_index <= index)
77 first_unused_index = index+1;
84 template <
typename Traits>
86 std::vector<typename Traits::JacobianType> &out;
89 unsigned int first_unused_index;
95 : out(out_), row(row_)
97 , first_unused_index(0)
102 assert(first_unused_index == out.size());
105 typename Traits::RangeFieldType &
operator[](
unsigned int index)
107 assert(index < out.size());
109 if(first_unused_index <= index)
110 first_unused_index = index+1;
112 return out[index][0][row];
128 template <
typename Traits,
int c>
133 d = Traits::dimDomain - c
141 template <
typename Access>
143 const typename Traits::DomainType &in,
146 const std::array<int, Traits::dimDomain> &derivatives,
149 typename Traits::RangeFieldType prod,
158 for (
int e = bound; e >= 0; --e)
162 int newbound = bound - e;
163 if(e < derivatives[d])
165 eval(in, derivatives, 0, newbound, index, access);
168 for(
int i = e - derivatives[d] + 1; i <= e; ++i)
176 prod *
ipow(in[d], e-derivatives[d]) * coeff,
192 template <
typename Traits>
195 enum { d = Traits::dimDomain-1 };
197 template <
typename Access>
198 static void eval (
const typename Traits::DomainType &in,
199 const std::array<int, Traits::dimDomain> &derivatives,
200 typename Traits::RangeFieldType prod,
201 int bound,
int& index, Access &access)
203 if(bound < derivatives[d])
207 for(
int i = bound - derivatives[d] + 1; i <= bound; ++i)
209 prod *=
ipow(in[d], bound-derivatives[d]) * coeff;
211 access[index] = prod;
232 template<
class D,
class R,
unsigned int d,
unsigned int p,
unsigned diffOrder = p>
238 Dune::FieldMatrix<R,1,d>,diffOrder>
Traits;
248 std::vector<typename Traits::RangeType>& out)
const 250 DUNE_NO_DEPRECATED_BEGIN
251 evaluate<0>(std::array<int, 0>(), in, out);
252 DUNE_NO_DEPRECATED_END
260 inline void partial(
const std::array<unsigned int,d>& order,
262 std::vector<typename Traits::RangeType>& out)
const 264 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
269 evaluateFunction(in,out);
273 std::array<int,1> directions;
274 directions[0] = std::find(order.begin(), order.end(), 1)-order.begin();
275 DUNE_NO_DEPRECATED_BEGIN
276 evaluate<1>(directions, in, out);
277 DUNE_NO_DEPRECATED_END
282 std::array<int,2> directions;
283 unsigned int counter = 0;
284 auto nonconstOrder = order;
285 for (
unsigned int i=0; i<d; i++)
287 while (nonconstOrder[i])
289 directions[counter++] = i;
294 DUNE_NO_DEPRECATED_BEGIN
295 evaluate<2>(directions, in, out);
296 DUNE_NO_DEPRECATED_END
301 DUNE_THROW(NotImplemented,
"Desired derivative order is not implemented");
306 template<
unsigned int k>
307 inline void DUNE_DEPRECATED_MSG(
"Use method 'partial' instead!")
308 evaluate (const
std::array<
int,k>& directions,
309 const typename Traits::DomainType& in,
310 std::vector<typename Traits::RangeType>& out)
const 314 std::array<int, d> derivatives;
315 for(
unsigned int i = 0; i < d; ++i) derivatives[i] = 0;
316 for(
unsigned int i = 0; i < k; ++i) ++derivatives[directions[i]];
318 for(
unsigned int lp = 0; lp <= p; ++lp)
326 std::vector<typename Traits::JacobianType>& out)
const 329 std::array<int, d> derivatives;
330 for(
unsigned int i = 0; i < d; ++i)
332 for(
unsigned int i = 0; i < d; ++i)
337 for(
unsigned int lp = 0; lp <= p; ++lp)
352 #endif // DUNE_LOCALFUNCTIONS_MONOMIAL_MONOMIALLOCALBASIS_HH Access output vector of evaluateFunction() and evaluate()
Definition: monomiallocalbasis.hh:54
EvalAccess(std::vector< typename Traits::RangeType > &out_)
Definition: monomiallocalbasis.hh:61
static void eval(const typename Traits::DomainType &in, const std::array< int, Traits::dimDomain > &derivatives, typename Traits::RangeFieldType prod, int bound, int &index, Access &access)
Definition: monomiallocalbasis.hh:198
T ipow(T base, int exp)
Definition: monomiallocalbasis.hh:39
LocalBasisTraits< D, d, Dune::FieldVector< D, d >, R, 1, Dune::FieldVector< R, 1 >, Dune::FieldMatrix< R, 1, d >, diffOrder > Traits
export type traits for function signature
Definition: monomiallocalbasis.hh:238
Definition: brezzidouglasmarini1cube2dlocalbasis.hh:15
unsigned int size() const
number of shape functions
Definition: monomiallocalbasis.hh:241
Traits::RangeFieldType & operator[](unsigned int index)
Definition: monomiallocalbasis.hh:105
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: monomiallocalbasis.hh:247
void partial(const std::array< unsigned int, d > &order, const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate partial derivatives of any order of all shape functions.
Definition: monomiallocalbasis.hh:260
~EvalAccess()
Definition: monomiallocalbasis.hh:68
D DomainType
domain type
Definition: localbasis.hh:49
~JacobianAccess()
Definition: monomiallocalbasis.hh:101
Definition: monomiallocalbasis.hh:129
static void eval(const typename Traits::DomainType &in, const std::array< int, Traits::dimDomain > &derivatives, typename Traits::RangeFieldType prod, int bound, int &index, Access &access)
Definition: monomiallocalbasis.hh:142
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: monomiallocalbasis.hh:325
Definition: monomiallocalbasis.hh:22
Traits::RangeFieldType & operator[](unsigned int index)
Definition: monomiallocalbasis.hh:72
Constant shape function.
Definition: monomiallocalbasis.hh:233
JacobianAccess(std::vector< typename Traits::JacobianType > &out_, unsigned int row_)
Definition: monomiallocalbasis.hh:93
Access output vector of evaluateJacobian()
Definition: monomiallocalbasis.hh:85
Type traits for LocalBasisVirtualInterface.
Definition: localbasis.hh:37
unsigned int order() const
Polynomial order of the shape functions.
Definition: monomiallocalbasis.hh:344
Definition: monomiallocalbasis.hh:23