1#ifndef DUNE_COPASI_LOCAL_FINITE_ELEMENT_CACHE_HH
2#define DUNE_COPASI_LOCAL_FINITE_ELEMENT_CACHE_HH
4#include <dune-copasi-config.hh>
8#include <dune/geometry/quadraturerules.hh>
9#include <dune/geometry/referenceelements.hh>
11#include <dune/common/exceptions.hh>
12#include <dune/common/hash.hh>
26template<
class LocalBasisTraits>
29 using Domain =
typename LocalBasisTraits::DomainType;
30 using DomainField =
typename LocalBasisTraits::DomainFieldType;
31 static constexpr int dimDomain = LocalBasisTraits::dimDomain;
33 using Range =
typename LocalBasisTraits::RangeType;
34 using RangeField =
typename LocalBasisTraits::RangeFieldType;
35 using Jacobian =
typename LocalBasisTraits::JacobianType;
63 std::size_t
hash = 233;
93 const Dune::QuadratureRule<DomainField, dim>&
quad_rule,
107 const Dune::QuadratureRule<DomainField, dimDomain>&
quad_rule,
130 template<
int dim,
typename ProjQuad>
131 requires std::is_invocable_r_v<Domain, ProjQuad, FieldVector<DomainField, dim>>
133 const Dune::QuadratureRule<DomainField, dim>&
quad_rule,
149 auto rit = (_key ==
Key{}) ? _range.end() : _range.find(_key);
150 if (
rit != _range.end()) {
151 _bound_range =
rit->second.data();
156 auto jit = (_key ==
Key{}) ? _jacobian.end() : _jacobian.find(_key);
157 if (
jit != _jacobian.end()) {
158 _bound_jacobian =
jit->second.data();
170 assert(std::exchange(_bound_range,
nullptr));
171 assert(std::exchange(_bound_jacobian,
nullptr));
185 return { _bound_range + _fe_size *
position_id, _fe_size };
199 return { _bound_jacobian + _fe_size *
position_id, _fe_size };
205 auto [
it,
inserted] = _range.emplace(
key, std::vector<Range>{});
217 Jacobian* cache_jacobian(
const auto& basis,
222 auto [
it,
inserted] = _jacobian.emplace(
key, std::vector<Jacobian>{});
227 basis.evaluateJacobian(
projection(
quad.position()), _quad_jacobian);
235 std::size_t _fe_size = 0, _quad_size = 0;
236 Range
const* _bound_range =
nullptr;
237 Jacobian
const* _bound_jacobian =
nullptr;
238 std::unordered_map<Key, std::vector<Range>,
typename Key::Hash> _range;
239 std::unordered_map<Key, std::vector<Jacobian>,
typename Key::Hash> _jacobian;
240 std::vector<Range> _quad_range;
241 std::vector<Jacobian> _quad_jacobian;
This class describes a local basis cache.
Definition local_basis_cache.hh:28
void bind(const auto &finite_element, const Dune::QuadratureRule< DomainField, dimDomain > &quad_rule, bool force=false)
Binds a finite element to this cache.
Definition local_basis_cache.hh:106
std::span< const Jacobian > evaluateJacobian(std::size_t position_id) const
Evaluate jacobian with the bound finite element and quadrature rule.
Definition local_basis_cache.hh:195
LocalBasisCache()
Constructs a new instance with empty values.
Definition local_basis_cache.hh:75
void unbind() noexcept
Unbind finite element from this cache.
Definition local_basis_cache.hh:167
void bind(const auto &finite_element, const Dune::QuadratureRule< DomainField, dim > &quad_rule, ProjQuad &&quad_proj, bool force=false)
Binds a finite element to this cache.
Definition local_basis_cache.hh:132
Key key(const auto &finite_element, const Dune::QuadratureRule< DomainField, dim > &quad_rule, auto &&quad_proj) const noexcept
Key to match previews applications of this cache.
Definition local_basis_cache.hh:92
std::span< const Range > evaluateFunction(std::size_t position_id) const
Evaluate function with the bound finite element and quadrature rule.
Definition local_basis_cache.hh:181
Definition axis_names.hh:7
constexpr bool is_bitflags_v
Alias for Bitflag indicator.
Definition bit_flags.hh:24
Definition local_basis_cache.hh:57
std::size_t operator()(const Key &key) const
Definition local_basis_cache.hh:61
std::size_t result_type
Definition local_basis_cache.hh:59
Key for the local basis cache.
Definition local_basis_cache.hh:40
Domain _proj_id
Definition local_basis_cache.hh:52
void const * _quad_id
Definition local_basis_cache.hh:51
std::type_index _fem_id
Definition local_basis_cache.hh:50
bool operator==(const Key &) const =default
Key(std::type_index fem_id=typeid(void), void const *quad_id=nullptr, Domain proj_id={})
Definition local_basis_cache.hh:41