Skip to content

Commit

Permalink
Linting and formatting prior to 0.8 (#3126)
Browse files Browse the repository at this point in the history
* cmake-format

* clang-format

* clang-format
  • Loading branch information
jhale committed Apr 15, 2024
1 parent e4b4466 commit 84d2f69
Show file tree
Hide file tree
Showing 35 changed files with 101 additions and 139 deletions.
4 changes: 3 additions & 1 deletion cpp/demo/biharmonic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ add_custom_command(

set(CMAKE_INCLUDE_CURRENT_DIR ON)

add_executable(${PROJECT_NAME} main.cpp ${CMAKE_CURRENT_BINARY_DIR}/biharmonic.c)
add_executable(
${PROJECT_NAME} main.cpp ${CMAKE_CURRENT_BINARY_DIR}/biharmonic.c
)
target_link_libraries(${PROJECT_NAME} dolfinx)

# Do not throw error for 'multi-line comments' (these are typical in rst which
Expand Down
6 changes: 3 additions & 3 deletions cpp/demo/custom_kernel/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ double assemble_vector1(const mesh::Geometry<T>& g, const fem::DofMap& dofmap,
{
la::Vector<T> b(dofmap.index_map, 1);
common::Timer timer("Assembler1 lambda (vector)");
fem::impl::assemble_cells<T, 1>([](auto, auto, auto, auto) {},
b.mutable_array(), g.dofmap(), g.x(), cells,
{dofmap.map(), 1, cells}, kernel, {}, {}, 0, {});
fem::impl::assemble_cells<T, 1>(
[](auto, auto, auto, auto) {}, b.mutable_array(), g.dofmap(), g.x(),
cells, {dofmap.map(), 1, cells}, kernel, {}, {}, 0, {});
b.scatter_rev(std::plus<T>());
return la::squared_norm(b);
}
Expand Down
4 changes: 3 additions & 1 deletion cpp/demo/hyperelasticity/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ else()

set(CMAKE_INCLUDE_CURRENT_DIR ON)

add_executable(${PROJECT_NAME} main.cpp ${CMAKE_CURRENT_BINARY_DIR}/hyperelasticity.c)
add_executable(
${PROJECT_NAME} main.cpp ${CMAKE_CURRENT_BINARY_DIR}/hyperelasticity.c
)
target_link_libraries(${PROJECT_NAME} dolfinx)

# Do not throw error for 'multi-line comments' (these are typical in rst which
Expand Down
11 changes: 5 additions & 6 deletions cpp/dolfinx/common/IndexMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,9 +962,8 @@ graph::AdjacencyList<int> IndexMap::index_to_dest_ranks() const
std::vector<std::pair<int, std::int64_t>> owner_to_ghost;
std::transform(_ghosts.begin(), _ghosts.end(), _owners.begin(),
std::back_inserter(owner_to_ghost),
[](auto idx, auto r) -> std::pair<int, std::int64_t> {
return {r, idx};
});
[](auto idx, auto r) -> std::pair<int, std::int64_t>
{ return {r, idx}; });
std::sort(owner_to_ghost.begin(), owner_to_ghost.end());

// Build send buffer (the second component of each pair in
Expand Down Expand Up @@ -1148,9 +1147,9 @@ graph::AdjacencyList<int> IndexMap::index_to_dest_ranks() const
auto it = idxpos_to_rank.begin();
for (std::size_t i = 0; i < _ghosts.size(); ++i)
{
auto it1 = std::find_if(
it, idxpos_to_rank.end(),
[i](auto x) { return x.first != static_cast<std::int32_t>(i); });
auto it1
= std::find_if(it, idxpos_to_rank.end(), [i](auto x)
{ return x.first != static_cast<std::int32_t>(i); });
offsets.push_back(offsets.back() + std::distance(it, it1));
it = it1;
}
Expand Down
6 changes: 3 additions & 3 deletions cpp/dolfinx/common/MPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,9 @@ distribute_from_postoffice(MPI_Comm comm, std::span<const std::int64_t> indices,
while (it != src_to_index.end())
{
src.push_back(std::get<0>(*it));
auto it1 = std::find_if(it, src_to_index.end(),
[r = src.back()](auto& idx)
{ return std::get<0>(idx) != r; });
auto it1
= std::find_if(it, src_to_index.end(), [r = src.back()](auto& idx)
{ return std::get<0>(idx) != r; });
num_items_per_src.push_back(std::distance(it, it1));
it = it1;
}
Expand Down
3 changes: 1 addition & 2 deletions cpp/dolfinx/common/Scatterer.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ class Scatterer
const std::array<std::int64_t, 2> range = map.local_range();
#ifndef NDEBUG
// Check that all received indice are within the owned range
std::for_each(recv_buffer.begin(), recv_buffer.end(),
[range](auto idx)
std::for_each(recv_buffer.begin(), recv_buffer.end(), [range](auto idx)
{ assert(idx >= range[0] and idx < range[1]); });
#endif

Expand Down
4 changes: 1 addition & 3 deletions cpp/dolfinx/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ sort_unique(const U& indices, const V& values)
using T = typename std::pair<typename U::value_type, typename V::value_type>;
std::vector<T> data(indices.size());
std::transform(indices.begin(), indices.end(), values.begin(), data.begin(),
[](auto& idx, auto& v) -> T {
return {idx, v};
});
[](auto& idx, auto& v) -> T { return {idx, v}; });

// Sort make unique
std::sort(data.begin(), data.end());
Expand Down
9 changes: 5 additions & 4 deletions cpp/dolfinx/fem/CoordinateElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ CoordinateElement<T>::CoordinateElement(
template <std::floating_point T>
CoordinateElement<T>::CoordinateElement(mesh::CellType celltype, int degree,
basix::element::lagrange_variant type)
: CoordinateElement(
std::make_shared<basix::FiniteElement<T>>(basix::create_element<T>(
basix::element::family::P, mesh::cell_type_to_basix_type(celltype),
degree, type, basix::element::dpc_variant::unset, false)))
: CoordinateElement(std::make_shared<basix::FiniteElement<T>>(
basix::create_element<T>(basix::element::family::P,
mesh::cell_type_to_basix_type(celltype),
degree, type,
basix::element::dpc_variant::unset, false)))
{
// Do nothing
}
Expand Down
1 change: 0 additions & 1 deletion cpp/dolfinx/fem/ElementDofLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ enum class CellType;
namespace dolfinx::fem
{


// TODO: For this class/concept to be robust, the topology of the
// reference cell needs to be defined.
//
Expand Down
5 changes: 2 additions & 3 deletions cpp/dolfinx/fem/assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ make_coefficients_span(const std::map<std::pair<IntegralType, int>,
using Key = typename std::remove_reference_t<decltype(coeffs)>::key_type;
std::map<Key, std::pair<std::span<const T>, int>> c;
std::transform(coeffs.cbegin(), coeffs.cend(), std::inserter(c, c.end()),
[](auto& e) -> typename decltype(c)::value_type {
return {e.first, {e.second.first, e.second.second}};
});
[](auto& e) -> typename decltype(c)::value_type
{ return {e.first, {e.second.first, e.second.second}}; });
return c;
}

Expand Down
3 changes: 1 addition & 2 deletions cpp/dolfinx/fem/discreteoperators.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ void interpolation_matrix(const FunctionSpace<U>& V0,
// Clamp values
std::transform(basis_derivatives_reference0_b.begin(),
basis_derivatives_reference0_b.end(),
basis_derivatives_reference0_b.begin(),
[atol = 1e-14](auto x)
basis_derivatives_reference0_b.begin(), [atol = 1e-14](auto x)
{ return std::abs(x) < atol ? 0.0 : x; });

// Create working arrays
Expand Down
6 changes: 3 additions & 3 deletions cpp/dolfinx/fem/dofmapbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,9 @@ std::pair<std::vector<std::int64_t>, std::vector<int>> get_global_indices(
std::pair<std::int64_t, std::pair<int64_t, int>> idx_old
= {local_new_to_global_old[d][i], {0, 0}};

auto it = std::lower_bound(
global_old_new.begin(), global_old_new.end(), idx_old,
[](auto& a, auto& b) { return a.first < b.first; });
auto it = std::lower_bound(global_old_new.begin(), global_old_new.end(),
idx_old, [](auto& a, auto& b)
{ return a.first < b.first; });
assert(it != global_old_new.end() and it->first == idx_old.first);

local_to_global_new[local_new_to_global_old[d][i + 1]] = it->second.first;
Expand Down
8 changes: 2 additions & 6 deletions cpp/dolfinx/fem/interpolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ class Function;
template <typename T>
concept MDSpan = requires(T x, std::size_t idx) {
x(idx, idx);
{
x.extent(0)
} -> std::integral;
{ x.extent(0) } -> std::integral;

{
x.extent(1)
} -> std::integral;
{ x.extent(1) } -> std::integral;
};

/// @brief Compute the evaluation points in the physical space at which
Expand Down
6 changes: 2 additions & 4 deletions cpp/dolfinx/fem/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ fem::compute_integration_domains(fem::IntegralType integral_type,
// Build permutation that sorts by meshtag value
std::vector<std::int32_t> perm(values1.size());
std::iota(perm.begin(), perm.end(), 0);
std::stable_sort(perm.begin(), perm.end(),
[&values1](auto p0, auto p1)
std::stable_sort(perm.begin(), perm.end(), [&values1](auto p0, auto p1)
{ return values1[p0] < values1[p1]; });

std::size_t shape = 1;
Expand All @@ -302,8 +301,7 @@ fem::compute_integration_domains(fem::IntegralType integral_type,
while (p0 != perm.end())
{
auto id0 = values1[*p0];
auto p1 = std::find_if_not(p0, perm.end(),
[id0, &values1](auto idx)
auto p1 = std::find_if_not(p0, perm.end(), [id0, &values1](auto idx)
{ return id0 == values1[idx]; });

std::vector<std::int32_t> data;
Expand Down
4 changes: 1 addition & 3 deletions cpp/dolfinx/fem/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -875,9 +875,7 @@ void pack(std::span<T> coeffs, std::int32_t cell, int bs, std::span<const T> v,
template <typename F>
concept FetchCells = requires(F&& f, std::span<const std::int32_t> v) {
requires std::invocable<F, std::span<const std::int32_t>>;
{
f(v)
} -> std::convertible_to<std::int32_t>;
{ f(v) } -> std::convertible_to<std::int32_t>;
};

/// @brief Pack a single coefficient for a set of active entities.
Expand Down
5 changes: 2 additions & 3 deletions cpp/dolfinx/geometry/BoundingBoxTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class BoundingBoxTree
/// each entity by.
BoundingBoxTree(const mesh::Mesh<T>& mesh, int tdim, T padding = 0)
: BoundingBoxTree::BoundingBoxTree(
mesh, tdim, range(mesh.topology_mutable(), tdim), padding)
mesh, tdim, range(mesh.topology_mutable(), tdim), padding)
{
// Do nothing
}
Expand Down Expand Up @@ -405,8 +405,7 @@ class BoundingBoxTree
for (std::size_t k = 0; k < 3; ++k)
s << _bbox_coordinates[6 * i + j * 3 + k] << " ";
if (j == 0)
s << "]->"
<< "[";
s << "]->" << "[";
}
s << "]\n";

Expand Down
6 changes: 3 additions & 3 deletions cpp/dolfinx/geometry/gjk.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ nearest_simplex(std::span<const T> s)
auto c = s.template subspan<6, 3>();
auto length = [](auto& x, auto& y)
{
return std::transform_reduce(
x.begin(), x.end(), y.begin(), 0.0, std::plus{},
[](auto x, auto y) { return (x - y) * (x - y); });
return std::transform_reduce(x.begin(), x.end(), y.begin(), 0.0,
std::plus{}, [](auto x, auto y)
{ return (x - y) * (x - y); });
};
const T ab2 = length(a, b);
const T ac2 = length(a, c);
Expand Down
5 changes: 2 additions & 3 deletions cpp/dolfinx/graph/partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,8 @@ graph::build::compute_ghost_indices(MPI_Comm comm,
std::transform(send_data.begin(), send_data.end(), new_recv.begin(),
old_to_new1.begin(),
[](auto idx_old, auto idx_new) ->
typename decltype(old_to_new1)::value_type {
return {idx_old, idx_new};
});
typename decltype(old_to_new1)::value_type
{ return {idx_old, idx_new}; });
std::sort(old_to_new1.begin(), old_to_new1.end());

std::vector<std::int64_t> ghost_global_indices(ghost_indices.size());
Expand Down
6 changes: 3 additions & 3 deletions cpp/dolfinx/graph/partitioners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ graph::AdjacencyList<int> compute_destination_ranks(
dest.push_back((*it)[0]);

// Find iterator to next destination rank and pack send data
auto it1 = std::find_if(it, node_to_dest.end(),
[r0 = dest.back()](auto& idx)
{ return idx[0] != r0; });
auto it1
= std::find_if(it, node_to_dest.end(), [r0 = dest.back()](auto& idx)
{ return idx[0] != r0; });
send_sizes.push_back(2 * std::distance(it, it1));
for (auto itx = it; itx != it1; ++itx)
{
Expand Down
11 changes: 5 additions & 6 deletions cpp/dolfinx/io/ADIOS2Writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,8 @@ class FidesWriter : public ADIOS2Writer

for (auto& v : _u)
{
std::visit(
[this](auto&& u) { impl_fides::write_data(*_io, *_engine, *u); }, v);
std::visit([this](auto&& u)
{ impl_fides::write_data(*_io, *_engine, *u); }, v);
}

_engine->EndStep();
Expand Down Expand Up @@ -1032,8 +1032,7 @@ class VTXWriter : public ADIOS2Writer
for (auto& v : _u)
{
std::visit([&](auto& u)
{ impl_vtx::vtx_write_data(*_io, *_engine, *u); },
v);
{ impl_vtx::vtx_write_data(*_io, *_engine, *u); }, v);
}
}
}
Expand Down Expand Up @@ -1067,8 +1066,8 @@ class VTXWriter : public ADIOS2Writer
// Write function data for each function to file
for (auto& v : _u)
{
std::visit(
[&](auto& u) { impl_vtx::vtx_write_data(*_io, *_engine, *u); }, v);
std::visit([&](auto& u)
{ impl_vtx::vtx_write_data(*_io, *_engine, *u); }, v);
}
}

Expand Down
12 changes: 6 additions & 6 deletions cpp/dolfinx/io/xdmf_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ xdmf_utils::distribute_entity_data(
while (it != perm.end())
{
dest.push_back(dest0[*it]);
auto it1 = std::find_if(it, perm.end(),
[&dest0, r = dest.back()](auto idx)
{ return dest0[idx] != r; });
auto it1
= std::find_if(it, perm.end(), [&dest0, r = dest.back()](auto idx)
{ return dest0[idx] != r; });
num_items_send.push_back(std::distance(it, it1));
it = it1;
}
Expand Down Expand Up @@ -403,9 +403,9 @@ xdmf_utils::distribute_entity_data(
while (it != dest_to_index.end())
{
dest.push_back(it->first);
auto it1 = std::find_if(it, dest_to_index.end(),
[r = dest.back()](auto idx)
{ return idx.first != r; });
auto it1
= std::find_if(it, dest_to_index.end(), [r = dest.back()](auto idx)
{ return idx.first != r; });
num_items_send.push_back(std::distance(it, it1));
it = it1;
}
Expand Down
3 changes: 1 addition & 2 deletions cpp/dolfinx/la/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,7 @@ auto norm(const V& x, Norm type = Norm::l2)
{
std::int32_t size_local = x.bs() * x.index_map()->size_local();
std::span<const T> data = x.array().subspan(0, size_local);
auto max_pos = std::max_element(data.begin(), data.end(),
[](T a, T b)
auto max_pos = std::max_element(data.begin(), data.end(), [](T a, T b)
{ return std::norm(a) < std::norm(b); });
auto local_linf = std::abs(*max_pos);
decltype(local_linf) linf = 0;
Expand Down
4 changes: 2 additions & 2 deletions cpp/dolfinx/mesh/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ template <typename U, typename V, typename W>
Geometry(std::shared_ptr<const common::IndexMap>, U,
const std::vector<fem::CoordinateElement<
typename std::remove_reference_t<typename V::value_type>>>&,
V, int, W)
-> Geometry<typename std::remove_cvref_t<typename V::value_type>>;
V, int,
W) -> Geometry<typename std::remove_cvref_t<typename V::value_type>>;
/// @endcond

/// @brief Build Geometry from input data.
Expand Down
4 changes: 2 additions & 2 deletions cpp/dolfinx/mesh/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ class Mesh
/// @cond
/// Template type deduction
template <typename V>
Mesh(MPI_Comm, std::shared_ptr<Topology>, V)
-> Mesh<typename std::remove_cvref_t<typename V::value_type>>;
Mesh(MPI_Comm, std::shared_ptr<Topology>,
V) -> Mesh<typename std::remove_cvref_t<typename V::value_type>>;
/// @endcond

} // namespace dolfinx::mesh
21 changes: 9 additions & 12 deletions cpp/dolfinx/mesh/Topology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ determine_sharing_ranks(MPI_Comm comm, std::span<const std::int64_t> indices)
while (it != indices_list.end())
{
// Find iterator to next different global index
auto it1 = std::find_if(it, indices_list.end(),
[idx0 = (*it)[0]](auto& idx)
{ return idx[0] != idx0; });
auto it1
= std::find_if(it, indices_list.end(), [idx0 = (*it)[0]](auto& idx)
{ return idx[0] != idx0; });

// Number of times index is repeated
std::size_t num = std::distance(it, it1);
Expand Down Expand Up @@ -541,9 +541,8 @@ std::vector<std::array<std::int64_t, 3>> exchange_ghost_indexing(
std::vector<std::pair<int, std::int64_t>> owner_to_ghost;
std::transform(map0.ghosts().begin(), map0.ghosts().end(),
map0.owners().begin(), std::back_inserter(owner_to_ghost),
[](auto idx, auto r) -> std::pair<int, std::int64_t> {
return {r, idx};
});
[](auto idx, auto r) -> std::pair<int, std::int64_t>
{ return {r, idx}; });
std::sort(owner_to_ghost.begin(), owner_to_ghost.end());

// Build send buffer (the second component of each pair in
Expand Down Expand Up @@ -1242,16 +1241,14 @@ Topology mesh::create_topology(
owned_vertices.begin(), owned_vertices.end(),
local_vertex_indices.begin(),
std::back_inserter(global_to_local_vertices),
[](auto idx0, auto idx1) -> std::pair<std::int64_t, std::int32_t> {
return {idx0, idx1};
});
[](auto idx0, auto idx1) -> std::pair<std::int64_t, std::int32_t>
{ return {idx0, idx1}; });
std::transform(
unowned_vertices.begin(), unowned_vertices.end(),
local_vertex_indices_unowned.begin(),
std::back_inserter(global_to_local_vertices),
[](auto idx0, auto idx1) -> std::pair<std::int64_t, std::int32_t> {
return {idx0, idx1};
});
[](auto idx0, auto idx1) -> std::pair<std::int64_t, std::int32_t>
{ return {idx0, idx1}; });
std::sort(global_to_local_vertices.begin(), global_to_local_vertices.end());

std::vector<std::vector<std::int32_t>> _cells_local_idx(cells.size());
Expand Down
Loading

0 comments on commit 84d2f69

Please sign in to comment.