Skip to content

Commit

Permalink
Fix bug in create_functionspace (#3355)
Browse files Browse the repository at this point in the history
* Fix issue 3345

* Remove {}

* Update cpp/test/fem/functionspace.cpp

Co-authored-by: Jørgen Schartum Dokken <[email protected]>

* {} style

---------

Co-authored-by: Jørgen Schartum Dokken <[email protected]>
  • Loading branch information
schnellerhase and jorgensd authored Aug 27, 2024
1 parent 4d4a864 commit e93606b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cpp/dolfinx/fem/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,10 @@ FunctionSpace<T> 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(),
Expand Down
1 change: 1 addition & 0 deletions cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions cpp/test/fem/functionspace.cpp
Original file line number Diff line number Diff line change
@@ -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 <catch2/catch_test_macros.hpp>

#include <basix/finite-element.h>

#include <dolfinx/fem/FunctionSpace.h>
#include <dolfinx/fem/utils.h>
#include <dolfinx/mesh/Mesh.h>
#include <dolfinx/mesh/generation.h>

using namespace dolfinx;

TEST_CASE("Create Function Space (mismatch of elements)", "[functionspace]")
{
auto mesh = std::make_shared<mesh::Mesh<double>>(
dolfinx::mesh::create_rectangle<double>(
MPI_COMM_SELF, {{{0, 0}, {1, 1}}}, {1, 1}, mesh::CellType::triangle));

auto element = basix::create_element<double>(
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<double>(mesh, element, {}));
}

0 comments on commit e93606b

Please sign in to comment.