Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
garth-wells committed Nov 7, 2024
1 parent dcd711e commit 9c97dc4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
62 changes: 31 additions & 31 deletions cpp/dolfinx/fem/FunctionSpace.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,6 @@

namespace dolfinx::fem
{
/// @brief Compute the physical value shape of an element for a mesh.
/// @param[in] element The element
/// @param[in] tdim Topological dimension
/// @param[in] gdim Geometric dimension
/// @return Physical valus shape
template <std::floating_point T>
std::vector<std::size_t>
compute_value_shape(const dolfinx::fem::FiniteElement<T>& element,
std::size_t tdim, std::size_t gdim)
{
std::vector<std::size_t> rvs = element.reference_value_shape();
std::vector<std::size_t> value_shape;
if (element.block_size() > 1)
{
value_shape = rvs;
}
else
{
for (std::size_t vs : rvs)
{
if (vs == tdim)
value_shape.push_back(gdim);
else
value_shape.push_back(vs);
}
}

return value_shape;
}

/// @brief This class represents a finite element function space defined
/// by a mesh, a finite element, and a local-to-global map of the
/// degrees-of-freedom.
Expand All @@ -70,7 +40,7 @@ class FunctionSpace
/// @param[in] mesh Mesh that the space is defined on.
/// @param[in] element Finite element for the space.
/// @param[in] dofmap Degree-of-freedom map for the space.
/// @param[in] value_shape Shape of the value space on the physical cell.
/// @param[in] value_shape The shape of the value space on the physical cell
FunctionSpace(std::shared_ptr<const mesh::Mesh<geometry_type>> mesh,
std::shared_ptr<const FiniteElement<geometry_type>> element,
std::shared_ptr<const DofMap> dofmap,
Expand Down Expand Up @@ -460,6 +430,36 @@ common_function_spaces(
return {spaces0, spaces1};
}

/// @brief Compute the physical value shape of an element for a mesh
/// @param[in] element The element
/// @param[in] tdim Topological dimension
/// @param[in] gdim Geometric dimension
/// @return Physical valus shape
template <std::floating_point T>
std::vector<std::size_t>
compute_value_shape(const dolfinx::fem::FiniteElement<T>& element,
std::size_t tdim, std::size_t gdim)
{
std::vector<std::size_t> rvs = element.reference_value_shape();
std::vector<std::size_t> value_shape(rvs.size());
if (element.block_size() > 1)
{
for (std::size_t i = 0; i < rvs.size(); ++i)
value_shape[i] = rvs[i];
}
else
{
for (std::size_t i = 0; i < rvs.size(); ++i)
{
if (rvs[i] == tdim)
value_shape[i] = gdim;
else
value_shape[i] = rvs[i];
}
}
return value_shape;
}

/// Type deduction
template <typename U, typename V, typename W, typename X>
FunctionSpace(U mesh, V element, W dofmap, X value_shape)
Expand Down
4 changes: 3 additions & 1 deletion cpp/dolfinx/fem/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ FunctionSpace<T> create_functionspace(
reorder_fn
= nullptr)
{
assert(e);
if (value_shape.has_value() and !e->reference_value_shape().empty())
{
throw std::runtime_error(
Expand All @@ -844,7 +845,7 @@ FunctionSpace<T> create_functionspace(
= !value_shape.has_value() and !e->reference_value_shape().empty()
? fem::compute_value_shape(*e, mesh->topology()->dim(),
mesh->geometry().dim())
: *value_shape;
: value_shape.value_or(std::vector<std::size_t>());

// Create UFC subdofmaps and compute offset
const int num_sub_elements = e->num_sub_elements();
Expand All @@ -871,6 +872,7 @@ FunctionSpace<T> create_functionspace(
assert(mesh->topology());
auto dofmap = std::make_shared<const DofMap>(create_dofmap(
mesh->comm(), layout, *mesh->topology(), permute_inv, reorder_fn));

return FunctionSpace(mesh, e, dofmap, _value_shape);
}

Expand Down

0 comments on commit 9c97dc4

Please sign in to comment.