.. _program_listing_file_src_pcms_field_element_dispatch.h: Program Listing for File element_dispatch.h =========================================== |exhale_lsh| :ref:`Return to documentation for file ` (``src/pcms/field/element_dispatch.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #ifndef PCMS_FIELD_ELEMENT_DISPATCH_H #define PCMS_FIELD_ELEMENT_DISPATCH_H #include "pcms/utility/assert.h" #include #include namespace pcms::detail { // Runtime -> compile-time bridge for finite-element order. // // Turns a runtime Lagrange order into a compile-time std::integral_constant and // invokes the generic callable `f` with it, so the callee can instantiate // order-templated kernels (shape functions, DOF-per-element counts) without // scattering `if (order == ...)` branches through device code. This is the same // dispatch shape as MakeMeshFieldBackend's switch, factored out so both the // transfer integrators and the MeshField evaluator backend can share it. // // Supported orders: 0 (one DOF per element) and 1 (one DOF per vertex). Add a // case here when a higher-order element (P2, ...) lands; every consumer picks // it up at once. `f` must return the same type for every supported order. template auto DispatchByOrder(int order, F&& f) { switch (order) { case 0: return f(std::integral_constant{}); case 1: return f(std::integral_constant{}); default: throw pcms_error("DispatchByOrder: unsupported element order " + std::to_string(order)); } } } // namespace pcms::detail #endif // PCMS_FIELD_ELEMENT_DISPATCH_H