Line | Branch | Exec | Source |
---|---|---|---|
1 | // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- | ||
2 | // vi: set et ts=4 sw=4 sts=4: | ||
3 | // | ||
4 | // SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder | ||
5 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
6 | // | ||
7 | /*! | ||
8 | * \file | ||
9 | * \ingroup Typetraits | ||
10 | * \brief Type traits to be used for detecting new interfaces related to local dofs | ||
11 | */ | ||
12 | #ifndef DUMUX_TYPETRAITS_LOCALDOFS__HH | ||
13 | #define DUMUX_TYPETRAITS_LOCALDOFS__HH | ||
14 | |||
15 | #include <type_traits> | ||
16 | #include <dune/common/std/type_traits.hh> | ||
17 | #include <dune/common/rangeutilities.hh> | ||
18 | |||
19 | #include <dumux/common/indextraits.hh> | ||
20 | #include <dumux/discretization/cvfe/localdof.hh> | ||
21 | |||
22 | namespace Dumux::Detail::LocalDofs { | ||
23 | |||
24 | //! helper struct detecting if a fvElementGeometry object has a numLocalDofs() function | ||
25 | template<class Imp> | ||
26 | using NumLocalDofsDetector = decltype( | ||
27 | std::declval<Imp>().numLocalDofs() | ||
28 | ); | ||
29 | |||
30 | template<typename FVElementGeometry> | ||
31 |
2/4✓ Branch 0 taken 2522976 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1128264 times.
✗ Branch 3 not taken.
|
22140238 | constexpr int numLocalDofs(const FVElementGeometry& fvGeometry) |
32 | { | ||
33 | if constexpr (Dune::Std::is_detected<NumLocalDofsDetector, FVElementGeometry>::value) | ||
34 | 1095402 | return fvGeometry.numLocalDofs(); | |
35 | else | ||
36 |
1/2✓ Branch 2 taken 36000 times.
✗ Branch 3 not taken.
|
14874973 | return fvGeometry.numScv(); |
37 | } | ||
38 | |||
39 | //! helper struct detecting if a fvElementGeometry object has maxNumElementDofs | ||
40 | template<class Imp> | ||
41 | using MaxNumElementDofs = decltype( Imp::maxNumElementDofs ); | ||
42 | |||
43 | template<typename FVElementGeometry> | ||
44 | constexpr int maxNumLocalDofs() | ||
45 | { | ||
46 | if constexpr (Dune::Std::is_detected<MaxNumElementDofs, FVElementGeometry>::value) | ||
47 | return FVElementGeometry::maxNumElementDofs; | ||
48 | else | ||
49 | return FVElementGeometry::maxNumElementScvs; | ||
50 | } | ||
51 | |||
52 | //! helper struct detecting if a class has a localDofIndex() function | ||
53 | template<class Imp> | ||
54 | using LocalDofIndexDetector = decltype( | ||
55 | std::declval<Imp>().localDofIndex() | ||
56 | ); | ||
57 | |||
58 | template<class ScvOrLocalDof> | ||
59 |
2/4✓ Branch 2 taken 37712 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 18528 times.
✗ Branch 7 not taken.
|
17272452 | inline auto index(const ScvOrLocalDof& scvOrLocalDof) |
60 | { | ||
61 | if constexpr (Dune::Std::is_detected<LocalDofIndexDetector, ScvOrLocalDof>::value) | ||
62 | return scvOrLocalDof.localDofIndex(); | ||
63 | else | ||
64 |
2/4✓ Branch 2 taken 37712 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 18528 times.
✗ Branch 7 not taken.
|
17272452 | return scvOrLocalDof.index(); |
65 | } | ||
66 | |||
67 | //! helper struct detecting if a fvElementGeometry object defines its own local dof type | ||
68 | template<class FVG> | ||
69 | using SpecifiesLocalDof = typename FVG::LocalDof; | ||
70 | |||
71 | template<class FVG> | ||
72 | using LocalDof_t = Dune::Std::detected_or_t< | ||
73 | Dumux::CVFE::LocalDof<typename IndexTraits<typename FVG::GridGeometry::GridView>::LocalIndex, | ||
74 | typename IndexTraits<typename FVG::GridGeometry::GridView>::GridIndex >, | ||
75 | SpecifiesLocalDof, | ||
76 | FVG | ||
77 | >; | ||
78 | |||
79 | //! helper struct detecting if a type corresponds to a local dof | ||
80 | template<class Imp> | ||
81 | constexpr inline bool isLocalDofType() | ||
82 | { | ||
83 | using LocalIndexType = std::decay_t<decltype(index(std::declval<Imp>()))>; | ||
84 | using GridIndexType = std::decay_t<decltype(std::declval<Imp>().dofIndex())>; | ||
85 | |||
86 | return std::is_base_of_v<Dumux::CVFE::LocalDof<LocalIndexType, GridIndexType>, Imp>; | ||
87 | } | ||
88 | |||
89 | } // end namespace Dumux::Detail::LocalDofs | ||
90 | |||
91 | #endif | ||
92 |