diff --git a/src/mesh/MeshVariant.hpp b/src/mesh/MeshVariant.hpp index bf3851a002ed795962a105c6b1bd79a8891568d1..7278878a9d7be440a179e913cb6491c5175d7094 100644 --- a/src/mesh/MeshVariant.hpp +++ b/src/mesh/MeshVariant.hpp @@ -1,10 +1,16 @@ #ifndef MESH_VARIANT_HPP #define MESH_VARIANT_HPP +#include <mesh/MeshTraits.hpp> +#include <utils/Demangle.hpp> +#include <utils/Exceptions.hpp> #include <utils/PugsMacros.hpp> +#include <rang.hpp> + #include <iostream> #include <memory> +#include <sstream> #include <variant> class IConnectivity; @@ -38,6 +44,16 @@ class MeshVariant PUGS_INLINE std::shared_ptr<const MeshType> get() const { + if (not std::holds_alternative<std::shared_ptr<const MeshType>>(this->m_p_mesh_variant)) { + std::ostringstream error_msg; + error_msg << "invalid mesh type type\n"; + error_msg << "- required " << rang::fgB::red << demangle<MeshType>() << rang::fg::reset << '\n'; + error_msg << "- contains " << rang::fgB::yellow + << std::visit([](auto&& p_mesh) -> std::string { return demangle<mesh_type_t<decltype(p_mesh)>>(); }, + this->m_p_mesh_variant) + << rang::fg::reset; + throw NormalError(error_msg.str()); + } return std::get<std::shared_ptr<const MeshType>>(m_p_mesh_variant); }