| 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 |
|
| 6 |
#ifndef DUNE_LOCALFUNCTIONS_META_POWER_COEFFICIENTS_HH |
| 7 |
#define DUNE_LOCALFUNCTIONS_META_POWER_COEFFICIENTS_HH |
| 8 |
|
| 9 |
#include <cstddef> |
| 10 |
#include <vector> |
| 11 |
|
| 12 |
#include <dune/localfunctions/common/localkey.hh> |
| 13 |
|
| 14 |
namespace Dune { |
| 15 |
|
| 16 |
//! \brief Meta-coefficients turning a scalar coefficients into |
| 17 |
//! vector-valued coefficients |
| 18 |
/** |
| 19 |
* \ingroup LocalFunctionsImpl |
| 20 |
* \nosubgrouping |
| 21 |
* \implements CoefficientsInterface |
| 22 |
*/ |
| 23 |
class PowerCoefficients { |
| 24 |
std::vector<LocalKey> keys; |
| 25 |
|
| 26 |
public: |
| 27 |
//! Construct a PowerCoefficients object |
| 28 |
/** |
| 29 |
* \param backend The backend coefficients object to raise to a power. |
| 30 |
* \param power Power to raise the backend object to. |
| 31 |
* |
| 32 |
* The LocalKeys of the backend coefficients are copied into internal |
| 33 |
* storage. The index member of each LocalKey is modified to keep them |
| 34 |
* unique for instances of different power. |
| 35 |
*/ |
| 36 |
template<class Backend> |
| 37 |
PowerCoefficients(const Backend &backend, std::size_t power) : |
| 38 |
keys(backend.size()*power) |
| 39 |
{ |
| 40 |
for(std::size_t i = 0; i < backend.size(); ++i) { |
| 41 |
const LocalKey &k = backend.localKey(i); |
| 42 |
for(std::size_t d = 0; d < power; ++d) |
| 43 |
keys[i+d*backend.size()] = |
| 44 |
LocalKey(k.subEntity(), k.codim(), power*k.index() + d); |
| 45 |
} |
| 46 |
} |
| 47 |
//! number of coefficients |
| 48 |
inline std::size_t size() const { return keys.size(); } |
| 49 |
|
| 50 |
//! get i'th index |
| 51 |
inline const LocalKey& localKey(std::size_t i) const { return keys[i]; } |
| 52 |
}; |
| 53 |
|
| 54 |
} // namespace Dune |
| 55 |
|
| 56 |
#endif // DUNE_LOCALFUNCTIONS_META_POWER_COEFFICIENTS_HH |