OGS
LocalDOF.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <boost/mp11.hpp>
7
9
10namespace NumLib
11{
12template <typename ShapeFunction, int Dim>
14{
15};
16
17namespace detail
18{
19template <typename ShapeFunction>
20struct NumberOfDofs : std::integral_constant<unsigned, ShapeFunction::NPOINTS>
21{
22};
23
24template <typename ShapeFunction, int Dim>
26 : std::integral_constant<unsigned, ShapeFunction::NPOINTS * Dim>
27{
28};
29
30template <typename... Ns_t,
31 typename ElementDOFVector,
32 int... Offsets,
33 int... Sizes>
34auto localDOFImpl(ElementDOFVector const& x,
35 boost::mp11::mp_list_c<int, Offsets...>,
36 boost::mp11::mp_list_c<int, Sizes...>)
37{
38 static_assert(((Sizes > 0) && ...));
39 static_assert(((Offsets >= 0) && ...));
40
41 return std::tuple<Eigen::Map<typename MatrixPolicyType::VectorType<
42 NumberOfDofs<Ns_t>::value> const>...>{{x.data() + Offsets, Sizes}...};
43}
44} // namespace detail
45
55template <typename... Ns_t, typename ElementDOFVector>
56auto localDOF(ElementDOFVector const& x)
57{
58 using namespace boost::mp11;
59
60 static_assert(sizeof...(Ns_t) > 0);
61
62 using Sizes = mp_list_c<int, detail::NumberOfDofs<Ns_t>::value...>;
63 using Offsets =
64 mp_push_front<mp_pop_back<mp_partial_sum<Sizes, mp_int<0>, mp_plus>>,
65 mp_int<0>>;
66
67 assert((mp_back<Offsets>::value + mp_back<Sizes>::value == x.size()) &&
68 "The passed shape matrices require a different number of "
69 "d.o.f.s than present in the passed element d.o.f. vector.");
70
71 return detail::localDOFImpl<Ns_t...>(x, Offsets{}, Sizes{});
72}
73
74} // namespace NumLib
auto localDOFImpl(ElementDOFVector const &x, boost::mp11::mp_list_c< int, Offsets... >, boost::mp11::mp_list_c< int, Sizes... >)
Definition LocalDOF.h:34
auto localDOF(ElementDOFVector const &x)
Definition LocalDOF.h:56
typename ::detail::EigenMatrixType< N, 1 >::type VectorType