Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into jhale/fix-windows-ci-…
Browse files Browse the repository at this point in the history
…late-2024
  • Loading branch information
jhale committed Nov 11, 2024
2 parents bf4e0b1 + 70cfbee commit 05db0a3
Show file tree
Hide file tree
Showing 28 changed files with 251 additions and 201 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
name: Lint
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
name: Build and test
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
Expand Down Expand Up @@ -209,8 +209,8 @@ jobs:
ctest -V -R demo -R serial
ctest -V -R demo -R mpi_2
- name: Install Python build dependencies
run: pip install -r python/build-requirements.txt
- name: Install Python build dependencies
run: pip install -r python/build-requirements.txt

- name: Build Python interface
run: |
Expand Down Expand Up @@ -282,15 +282,15 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: docs-cpp-doxygen
path: cpp/doc/html
retention-days: 2
path: cpp/doc/html
retention-days: 2
- name: Upload C++ Sphinx documentation artifact
uses: actions/upload-artifact@v4
with:
name: docs-cpp-sphinx
path: cpp/doc/build/html
retention-days: 2
path: cpp/doc/build/html
retention-days: 2

- name: Build Python interface documentation
run: |
cd python/doc
Expand All @@ -299,8 +299,8 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: docs-python
path: python/doc/build/html
retention-days: 2
path: python/doc/build/html
retention-days: 2

- name: Checkout FEniCS/docs
if: ${{ github.repository == 'FEniCS/dolfinx' && ( github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') ) }}
Expand Down
6 changes: 1 addition & 5 deletions cpp/doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -1007,11 +1007,7 @@ RECURSIVE = YES
# Note that relative paths are relative to the directory from which doxygen is
# run.

EXCLUDE = ../dolfinx/io/pugixml.hpp \
../dolfinx/io/pugixml.cpp \
../dolfinx/io/pugiconfig.hpp \
../dolfinx/common/loguru.hpp \
../dolfinx/common/loguru.cpp \
# EXCLUDE =

# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded
Expand Down
24 changes: 13 additions & 11 deletions cpp/dolfinx/common/Scatterer.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ class Scatterer

// Scale sizes and displacements by block size
{
auto rescale = [](auto& x, int bs) {
auto rescale = [](auto& x, int bs)
{
std::ranges::transform(x, x.begin(), [bs](auto e) { return e *= bs; });
};
rescale(_sizes_local, bs);
Expand Down Expand Up @@ -459,8 +460,8 @@ class Scatterer
/// @note This function is intended for advanced usage, and in
/// particular when using CUDA/device-aware MPI.
///
/// @tparam T The data type to send
/// @tparam F The pack function
/// @tparam T Data type to send.
/// @tparam F Pack function.
/// @param[in] remote_data Received data associated with the ghost
/// indices. The order follows the order of the ghost indices in the
/// IndexMap used to create the scatterer. The size equal to the
Expand Down Expand Up @@ -493,14 +494,15 @@ class Scatterer
type);
}

/// @brief End the reverse scatter communication, and unpack the received
/// local buffer into local data.
/// @brief End the reverse scatter communication, and unpack the
/// received local buffer into local data.
///
/// This function must be called after Scatterer::scatter_rev_begin.
/// The buffers passed to Scatterer::scatter_rev_begin must not be
/// modified until after the function has been called.
/// @param[in] local_buffer Working buffer. Same buffer should be used in
/// Scatterer::scatter_rev_begin.
///
/// @param[in] local_buffer Working buffer. Same buffer should be used
/// in Scatterer::scatter_rev_begin.
/// @param[out] local_data All data associated with owned indices.
/// Size is `size_local()` from the IndexMap used to create the
/// scatterer, multiplied by the block size. The data for each index
Expand Down Expand Up @@ -557,7 +559,7 @@ class Scatterer
}

/// @brief Size of buffer for local data (owned and shared) used in
/// forward and reverse communication
/// forward and reverse communication.
/// @return The required buffer size
std::int32_t local_buffer_size() const noexcept { return _local_inds.size(); }

Expand All @@ -569,9 +571,9 @@ class Scatterer
return _remote_inds.size();
}

/// Return a vector of local indices (owned) used to pack/unpack local data.
/// These indices are grouped by neighbor process (process for which an index
/// is a ghost).
/// Return a vector of local indices (owned) used to pack/unpack local
/// data. These indices are grouped by neighbor process (process for
/// which an index is a ghost).
const std::vector<std::int32_t>& local_indices() const noexcept
{
return _local_inds;
Expand Down
42 changes: 26 additions & 16 deletions cpp/dolfinx/fem/FiniteElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ FiniteElement<T>::FiniteElement(mesh::CellType cell_type,
std::size_t block_size, bool symmetric)
: _signature("Quadrature element " + std::to_string(pshape[0]) + " "
+ std::to_string(block_size)),
_space_dim(pshape[0] * block_size), _reference_value_shape({}),
_bs(block_size), _is_mixed(false), _symmetric(symmetric),
_needs_dof_permutations(false), _needs_dof_transformations(false),
_space_dim(pshape[0] * block_size),
_reference_value_shape(std::vector<std::size_t>{}), _bs(block_size),
_symmetric(symmetric), _needs_dof_permutations(false),
_needs_dof_transformations(false),
_entity_dofs(mesh::cell_dim(cell_type) + 1),
_entity_closure_dofs(mesh::cell_dim(cell_type) + 1),
_points(std::vector<T>(points.begin(), points.end()), pshape)
Expand All @@ -98,7 +99,6 @@ FiniteElement<T>::FiniteElement(const basix::FiniteElement<T>& element,
std::size_t block_size, bool symmetric)
: _space_dim(block_size * element.dim()),
_reference_value_shape(element.value_shape()), _bs(block_size),
_is_mixed(false),
_element(std::make_unique<basix::FiniteElement<T>>(element)),
_symmetric(symmetric),
_needs_dof_permutations(
Expand Down Expand Up @@ -139,11 +139,16 @@ FiniteElement<T>::FiniteElement(const basix::FiniteElement<T>& element,
template <std::floating_point T>
FiniteElement<T>::FiniteElement(
const std::vector<std::shared_ptr<const FiniteElement<T>>>& elements)
: _space_dim(0), _sub_elements(elements), _bs(1), _is_mixed(true),
_symmetric(false), _needs_dof_permutations(false),
_needs_dof_transformations(false)
: _space_dim(0), _sub_elements(elements),
_reference_value_shape(std::nullopt), _bs(1), _symmetric(false),
_needs_dof_permutations(false), _needs_dof_transformations(false)
{
std::size_t vsize = 0;
if (elements.size() < 2)
{
throw std::runtime_error("FiniteElement constructor for mixed elements "
"called with a single element.");
}

_signature = "Mixed element (";

const std::vector<std::vector<std::vector<int>>>& ed
Expand All @@ -159,7 +164,6 @@ FiniteElement<T>::FiniteElement(
int dof_offset = 0;
for (auto& e : elements)
{
vsize += e->reference_value_size();
_signature += e->signature() + ", ";

if (e->needs_dof_permutations())
Expand Down Expand Up @@ -191,7 +195,6 @@ FiniteElement<T>::FiniteElement(
}

_space_dim = dof_offset;
_reference_value_shape = {vsize};
_signature += ")";
}
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -226,10 +229,12 @@ int FiniteElement<T>::space_dimension() const noexcept
}
//-----------------------------------------------------------------------------
template <std::floating_point T>
std::span<const std::size_t>
FiniteElement<T>::reference_value_shape() const noexcept
std::span<const std::size_t> FiniteElement<T>::reference_value_shape() const
{
return _reference_value_shape;
if (_reference_value_shape)
return *_reference_value_shape;
else
throw std::runtime_error("Element does not have a reference_value_shape.");
}
//-----------------------------------------------------------------------------
template <std::floating_point T>
Expand All @@ -255,8 +260,13 @@ bool FiniteElement<T>::symmetric() const
template <std::floating_point T>
int FiniteElement<T>::reference_value_size() const
{
return std::accumulate(_reference_value_shape.begin(),
_reference_value_shape.end(), 1, std::multiplies{});
if (_reference_value_shape)
{
return std::accumulate(_reference_value_shape->begin(),
_reference_value_shape->end(), 1, std::multiplies{});
}
else
throw std::runtime_error("Element does not have a reference_value_shape.");
}
//-----------------------------------------------------------------------------
template <std::floating_point T>
Expand Down Expand Up @@ -292,7 +302,7 @@ int FiniteElement<T>::num_sub_elements() const noexcept
template <std::floating_point T>
bool FiniteElement<T>::is_mixed() const noexcept
{
return _is_mixed;
return !_reference_value_shape;
}
//-----------------------------------------------------------------------------
template <std::floating_point T>
Expand Down
46 changes: 28 additions & 18 deletions cpp/dolfinx/fem/FiniteElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <dolfinx/mesh/cell_types.h>
#include <functional>
#include <memory>
#include <optional>
#include <span>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -103,19 +104,32 @@ class FiniteElement
/// @return Dimension of the finite element space
int space_dimension() const noexcept;

/// Block size of the finite element function space. For
/// BlockedElements, this is the number of DOFs
/// colocated at each DOF point. For other elements, this is always 1.
/// @brief Block size of the finite element function space.
///
/// For BlockedElements, this is the number of DOFs colocated at each
/// DOF point. For other elements, this is always 1.
/// @return Block size of the finite element space
int block_size() const noexcept;

/// The value size, e.g. 1 for a scalar function, 2 for a 2D vector, 9
/// for a second-order tensor in 3D, for the reference element
/// @return The value size for the reference element
/// @brief Value size.
///
/// The value size is the product of the value shape, e.g. is is 1
/// for a scalar function, 2 for a 2D vector, 9 for a second-order
/// tensor in 3D.
/// @throws Exception is thrown for a mixed element as mixed elements
/// do not have a value shape.
/// @return The value size.
int reference_value_size() const;

/// The reference value shape
std::span<const std::size_t> reference_value_shape() const noexcept;
/// @brief Value shape.
///
/// The value shape described the shape of the finite element field,
/// e.g. {} for a scalar, {3, 3} for a tensor in 3D. Mixed elements do
/// not have a value shape.
/// @throws Exception is thrown for a mixed element as mixed elements
/// do not have a value shape.
/// @return The value shape.
std::span<const std::size_t> reference_value_shape() const;

/// The local DOFs associated with each subentity of the cell
const std::vector<std::vector<std::vector<int>>>&
Expand Down Expand Up @@ -324,9 +338,8 @@ class FiniteElement

if (!_sub_elements.empty())
{
if (_is_mixed)
if (!_reference_value_shape) // Mixed element
{
// Mixed element
std::vector<std::function<void(
std::span<U>, std::span<const std::uint32_t>, std::int32_t, int)>>
sub_element_fns;
Expand Down Expand Up @@ -426,11 +439,10 @@ class FiniteElement
// Do nothing
};
}
else if (_sub_elements.size() != 0)
else if (!_sub_elements.empty())
{
if (_is_mixed)
if (!_reference_value_shape) // Mixed element
{
// Mixed element
std::vector<std::function<void(
std::span<U>, std::span<const std::uint32_t>, std::int32_t, int)>>
sub_element_fns;
Expand Down Expand Up @@ -724,16 +736,14 @@ class FiniteElement
std::vector<std::shared_ptr<const FiniteElement<geometry_type>>>
_sub_elements;

// Dimension of each value space
std::vector<std::size_t> _reference_value_shape;
// Value space shape, e.g. {} for a scalar, {3, 3} for a tensor in 3D.
// For a mixed element it is std::nullopt.
std::optional<std::vector<std::size_t>> _reference_value_shape;

// Block size for BlockedElements. This gives the number of DOFs
// co-located at each dof 'point'.
int _bs;

// Indicate whether this is a mixed element
bool _is_mixed;

// Basix Element (nullptr for mixed elements)
std::unique_ptr<basix::FiniteElement<geometry_type>> _element;

Expand Down
3 changes: 2 additions & 1 deletion cpp/dolfinx/io/xdmf_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ xdmf_utils::distribute_entity_data(
std::vector<std::pair<int, std::int64_t>> dest_to_index;
std::ranges::transform(
indices, std::back_inserter(dest_to_index),
[size, num_nodes](auto n) {
[size, num_nodes](auto n)
{
return std::pair(dolfinx::MPI::index_owner(size, n, num_nodes), n);
});
std::ranges::sort(dest_to_index);
Expand Down
1 change: 0 additions & 1 deletion cpp/dolfinx/io/xdmf_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

namespace dolfinx
{

namespace fem
{
template <dolfinx::scalar T, std::floating_point U>
Expand Down
Loading

0 comments on commit 05db0a3

Please sign in to comment.