From e93606b62b51b748c8686406e128b04c6ac9fb87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20K=C3=BChner?= <56360279+schnellerhase@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:05:19 +0200 Subject: [PATCH] Fix bug in `create_functionspace` (#3355) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix issue 3345 * Remove {} * Update cpp/test/fem/functionspace.cpp Co-authored-by: Jørgen Schartum Dokken * {} style --------- Co-authored-by: Jørgen Schartum Dokken --- cpp/dolfinx/fem/utils.h | 4 ++++ cpp/test/CMakeLists.txt | 1 + cpp/test/fem/functionspace.cpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 cpp/test/fem/functionspace.cpp diff --git a/cpp/dolfinx/fem/utils.h b/cpp/dolfinx/fem/utils.h index 619a9e02d7c..7f79dfb00ef 100644 --- a/cpp/dolfinx/fem/utils.h +++ b/cpp/dolfinx/fem/utils.h @@ -775,6 +775,10 @@ FunctionSpace create_functionspace( "Cannot specify value shape for non-scalar base element."); } + if (mesh::cell_type_from_basix_type(e.cell_type()) + != mesh->topology()->cell_type()) + throw std::runtime_error("Cell type of element and mesh must match."); + std::size_t bs = value_shape.empty() ? 1 : std::accumulate(value_shape.begin(), value_shape.end(), diff --git a/cpp/test/CMakeLists.txt b/cpp/test/CMakeLists.txt index 53ece3f893f..e652537d80c 100644 --- a/cpp/test/CMakeLists.txt +++ b/cpp/test/CMakeLists.txt @@ -40,6 +40,7 @@ add_executable( common/sub_systems_manager.cpp common/index_map.cpp common/sort.cpp + fem/functionspace.cpp mesh/distributed_mesh.cpp common/CIFailure.cpp refinement/interval.cpp diff --git a/cpp/test/fem/functionspace.cpp b/cpp/test/fem/functionspace.cpp new file mode 100644 index 00000000000..faf3b7233dd --- /dev/null +++ b/cpp/test/fem/functionspace.cpp @@ -0,0 +1,30 @@ +// Copyright (C) 2024 Paul Kühner +// +// This file is part of DOLFINX (https://www.fenicsproject.org) +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include + +#include + +#include +#include +#include +#include + +using namespace dolfinx; + +TEST_CASE("Create Function Space (mismatch of elements)", "[functionspace]") +{ + auto mesh = std::make_shared>( + dolfinx::mesh::create_rectangle( + MPI_COMM_SELF, {{{0, 0}, {1, 1}}}, {1, 1}, mesh::CellType::triangle)); + + auto element = basix::create_element( + basix::element::family::P, basix::cell::type::interval, 1, + basix::element::lagrange_variant::unset, + basix::element::dpc_variant::unset, false); + + CHECK_THROWS(fem::create_functionspace(mesh, element, {})); +}