Make GeometryType constexpr
This merge request makes all eligible constructors and members of GeometryType constexpr
. I only skipped those functions for which it doesn't make sense (I/O) or is not possible for all supported compilers. The merge request also adds new static factory functions that do the same as the make...()
methods, but return a new GeometryType instead, which is much more useful in constexpr
context.
The main reason for wanting a GeometryType
that works in constexpr
context is some code in PDELab that returns the number of DOFs per GeometryType
. Being able to call that code constexpr
would make it possible to automatically deduce correct ISTL block sizes. Currently, we rely on the user to correctly set the block size, which leads to ugly, silent run time errors that are really hard to debug.
Merge request reports
Activity
459 return Cube(3); 460 } 461 462 //! Returns a GeometryType representing a simplex of dimension `dim`. 463 static constexpr GeometryType Simplex(unsigned int dim) 464 { 465 return GeometryType(0,dim,false); 466 } 467 468 //! Returns a GeometryType representing a hypercube of dimension `dim`. 469 static constexpr GeometryType Cube(unsigned int dim) 470 { 471 return GeometryType(((dim>1) ? ((1 << dim) - 1) : 0),dim,false); 472 } 473 474 //! Returns a GeometryType representing a singular of dimension `dim`. changed this line in version 4 of the diff
Yes, that works now. As to that construction, I don't know if those topologies were used in other contexts... @martin.nolte ?
394 408 /** @} */ 395 409 396 410 411 /** @name Factory functions */ 412 /*@{*/ 413 414 //! Returns a GeometryType representing a vertex. 415 static constexpr GeometryType Vertex() As I explained below, they seemed so constructor-like, just with different names. But I'm not overly attached to that detail, and I'll try and give @martin.nolte's idea of using constexpr variables in a namespace a spin.
changed this line in version 4 of the diff
@oliver.sander: These are the original construction structures. I have been thinking about getting rid of
Point
,Prism
,Pyramid
for quite some time, but it does not seem to be that easy. They are used in more places than I expected, especially in dune-localfunctions and dune-fem.Therefore, I'll try to answer the other way round: What you definitely want is the methods like
isPrism
as they allow switching over the construction type from the(topologyId, dim)
pair. Without these, the entire generic construction degenerates into bit-manipulation formalae that nobody wants to read or maintain.As a start, however, we should replace the structs like
PyramidTopology
, which only return the topologyId in a compile-time static manner. As they are implementation details, we can remove them without deprecation. I think this should go into a separate merge request, though.As for the actual MR: I do not see the advantage of
Dune::vertex
overDune::GeometryType::vertex
. I somehow do not like burning names likeDune::vertex
orDune::simplex
(which is unfortunately used by dune-alugrid, too).Moreover, why is a free-standing function better than a variable like
Dune::Partitions::border
? I imagine something along the lines ofDune::GeometryTypes::vertex
orDune::GeometryTypes::simplex(3)
, where the first is a variable while the second is a constexpr function, of course. This way, you can abbreviate your code byusing namespace Dune::GeometryTypes
without burning these names in theDune
namespace.Edited by Martin NolteHmm, it looks like my explanation wasn't entirely clear: I didn't put any new names into global namespaces, I just added
static constexpr
members that let you writeDune::GeometryType::Vertex()
. As @joe remarked, he doesn't like the uppercase. To me, they seemed a little like constructors with fancy names, that's why I capitalized them. But I actually like the idea of providing constants in a namespace. :-)@smuething: Oops, sorry. Seems like I messed up understanding the diff.
Edited by Martin NolteOK, I replaced the factory functions inside
GeometryType
with variables and free functions innamespace Dune::GeometryType
. The tests won't pass for now as this depends on dune-common!304 (merged).added 1 commit
- 1af9f005 - [doxygen] Add missing group directive for vertex variable