Kill PQ1NodalBasis if possible
I would like to remove PQ1NodalBasis
. Its functionality is covered by PQkNodalBasis
, and IMO it is not really easier to understand than PQkNodalBasis
. Therefore is pedagogical value is limited.
As requested by @christi , I wrote a small benchmark program that compares the speed of the two implementations. It focuses on index access, because that is where the implementations differ most. When compiledpq-speed.cc with -O3 -funroll-loops -DNDEBUG
, I see a speed difference of about 10%.
~/dune/dune-functions/build-cmake/examples(master)> ./pq-speed
PQ1: 1.28215
PQk: 1.40096
PQ1: 1.27461
PQk: 1.39481
PQ1: 1.28128
PQk: 1.3949
I tried to fix this by introducing a separate code path for the first-order case in the method PQkNodeIndexSet::indices
:
--- a/dune/functions/functionspacebases/pqknodalbasis.hh
+++ b/dune/functions/functionspacebases/pqknodalbasis.hh
@@ -355,7 +355,9 @@ public:
// The dimension of the entity that the current dof is related to
auto dofDim = dim - localKey.codim();
- if (dofDim==0) { // vertex dof
+ // The test for k==1 is redundant, but having it here allows the compiler to conclude
+ // at compile-time that the dofDim==0 case is the only one that will ever happen.
+ if (k==1 || dofDim==0) { // vertex dof
*it = {{ (size_type)(gridIndexSet.subIndex(element,localKey.subEntity(),dim)) }};
continue;
}
This does seem to work. With this patch I get:
~/dune/dune-functions/build-cmake/examples(master)> ./pq-speed
PQ1: 1.29766
PQk: 1.27667
PQ1: 1.28519
PQk: 1.27641
PQ1: 1.2848
PQk: 1.26824
In fact, the PQk implementation is now faster than the PQ1 one. Now idea how to explain this.
Opinions?