Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
garth-wells committed Jun 9, 2024
1 parent 5a2e2c5 commit ac69084
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 22 deletions.
12 changes: 6 additions & 6 deletions cpp/Contact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ dolfinx_contact::Contact::pack_gap(int pair) const
std::array<std::size_t, 2> shape = _reference_contact_shape[pair];

const int q_gdim = quadrature_mesh->geometry().dim();
cmdspan3_t qp_span(_qp_phys[quadrature_mt].data(), num_facets, num_q_point,
q_gdim);
mdspan_t<const double, 3> qp_span(_qp_phys[quadrature_mt].data(), num_facets,
num_q_point, q_gdim);

// Get information about submesh geometry and topology
std::span<const double> x_g = geometry.x();
Expand Down Expand Up @@ -927,8 +927,8 @@ dolfinx_contact::Contact::pack_gap_plane(int pair, double g)
// FIXME: This does not work for prism meshes
std::size_t num_q_point
= _quadrature_rule->offset()[1] - _quadrature_rule->offset()[0];
cmdspan3_t qp_span(_qp_phys[quadrature_mt].data(), num_facets, num_q_point,
gdim);
mdspan_t<const double, 3> qp_span(_qp_phys[quadrature_mt].data(), num_facets,
num_q_point, gdim);
std::vector<PetscScalar> c(num_facets * num_q_point * gdim, 0.0);
const int cstride = (int)num_q_point * gdim;
for (std::size_t i = 0; i < num_facets; i++)
Expand Down Expand Up @@ -1349,8 +1349,8 @@ dolfinx_contact::Contact::pack_grad_test_functions(
const std::size_t num_q_points
= _quadrature_rule->offset()[1] - _quadrature_rule->offset()[0];
std::vector<double> q_points(std::size_t(num_q_points) * std::size_t(gdim));
cmdspan3_t qp_span(_qp_phys[quadrature_mt].data(), num_facets, num_q_points,
gdim);
mdspan_t<const double, 3> qp_span(_qp_phys[quadrature_mt].data(), num_facets,
num_q_points, gdim);

std::shared_ptr<const dolfinx::graph::AdjacencyList<int>> facet_map
= _submesh.facet_map();
Expand Down
9 changes: 6 additions & 3 deletions cpp/KernelData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ double dolfinx_contact::KernelData::compute_first_facet_jacobian(
full_basis, std::pair{1, (std::size_t)_tdim + 1},
_qp_offsets[facet_index], MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
0);
dolfinx_contact::cmdspan3_t ref_jacs(_ref_jacobians.data(), _jac_shape);
dolfinx_contact::mdspan_t<const double, 3> ref_jacs(_ref_jacobians.data(),
_jac_shape);
auto J_f = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
ref_jacs, (std::size_t)facet_index,
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
Expand All @@ -127,8 +128,10 @@ dolfinx_contact::KernelData::weights(std::size_t i) const
_qp_offsets[i + 1] - _qp_offsets[i]);
}
//-----------------------------------------------------------------------------
dolfinx_contact::cmdspan3_t dolfinx_contact::KernelData::ref_jacobians() const
dolfinx_contact::mdspan_t<const double, 3>
dolfinx_contact::KernelData::ref_jacobians() const
{
return dolfinx_contact::cmdspan3_t(_ref_jacobians.data(), _jac_shape);
return dolfinx_contact::mdspan_t<const double, 3>(_ref_jacobians.data(),
_jac_shape);
}
//-----------------------------------------------------------------------------
4 changes: 2 additions & 2 deletions cpp/KernelData.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class KernelData
auto dphi_fc = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
full_basis, std::pair{1, (std::size_t)_tdim + 1}, q_pos,
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent, 0);
cmdspan3_t ref_jacs(_ref_jacobians.data(), _jac_shape);
mdspan_t<const double, 3> ref_jacs(_ref_jacobians.data(), _jac_shape);
auto J_f = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
ref_jacs, (std::size_t)facet_index,
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
Expand Down Expand Up @@ -161,7 +161,7 @@ class KernelData
std::span<const double> weights(std::size_t i) const;

// return the reference jacobians
cmdspan3_t ref_jacobians() const;
mdspan_t<const double, 3> ref_jacobians() const;

private:
std::uint32_t _gdim; // geometrical dimension
Expand Down
7 changes: 5 additions & 2 deletions cpp/QuadratureRule.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
namespace dolfinx_contact
{
namespace stdex = std::experimental;

template <typename T, std::size_t d, typename S = stdex::layout_stride>
using mdspan_t = MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
T, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, d>>;

using mdspan2_t = MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
double, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>>;
using cmdspan2_t = MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
const double, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>>;
using mdspan3_t = MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
double, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 3>>;
using cmdspan3_t = MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
const double, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 3>>;
using mdspan4_t = MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
double, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 4>>;
using cmdspan4_t = MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
Expand Down
2 changes: 1 addition & 1 deletion cpp/RayTracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ compute_ray(const dolfinx::mesh::Mesh<double>& mesh,
auto [ref_jac, jac_shape] = basix::cell::facet_jacobians<double>(basix_cell);
assert(tdim == jac_shape[1]);
assert(tdim - 1 == jac_shape[2]);
cmdspan3_t facet_jacobians(ref_jac.data(), jac_shape);
mdspan_t<const double, 3> facet_jacobians(ref_jac.data(), jac_shape);

// Get basix geometry information
std::pair<std::vector<double>, std::array<std::size_t, 2>> bgeometry
Expand Down
6 changes: 3 additions & 3 deletions cpp/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,9 +1035,9 @@ dolfinx_contact::compute_distance_map(
{
dolfinx_contact::mdspan3_t padded_qps(
padded_qpsb.data(), quadrature_facets.size() / 2, num_q_points, 3);
dolfinx_contact::cmdspan3_t qps(quadrature_points.data(),
quadrature_facets.size() / 2,
num_q_points, gdim);
dolfinx_contact::mdspan_t<const double, 3> qps(
quadrature_points.data(), quadrature_facets.size() / 2, num_q_points,
gdim);
for (std::size_t i = 0; i < qps.extent(0); ++i)
for (std::size_t j = 0; j < qps.extent(1); ++j)
for (std::size_t k = 0; k < qps.extent(2); ++k)
Expand Down
8 changes: 4 additions & 4 deletions cpp/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ compute_raytracing_map(const dolfinx::mesh::Mesh<double>& quadrature_mesh,
auto [ref_jac, jac_shape] = basix::cell::facet_jacobians<double>(basix_cell);
assert(tdim == jac_shape[1]);
assert(tdim - 1 == jac_shape[2]);
cmdspan3_t facet_jacobians(ref_jac.data(), jac_shape);
mdspan_t<const double, 3> facet_jacobians(ref_jac.data(), jac_shape);

// Get basix geometry information
std::pair<std::vector<double>, std::array<std::size_t, 2>> geometry
Expand Down Expand Up @@ -816,9 +816,9 @@ compute_raytracing_map(const dolfinx::mesh::Mesh<double>& quadrature_mesh,
std::vector<double> padded_qpsb(count_missing_matches * 3);
dolfinx_contact::mdspan2_t padded_qps(padded_qpsb.data(),
count_missing_matches, 3);
dolfinx_contact::cmdspan3_t qps(quadrature_points.data(),
quadrature_facets.size() / 2,
num_q_points, gdim);
dolfinx_contact::mdspan_t<const double, 3> qps(
quadrature_points.data(), quadrature_facets.size() / 2, num_q_points,
gdim);

// Retrieve remaining quadrature points
for (std::size_t j = 0; j < padded_qps.extent(0); ++j)
Expand Down
3 changes: 2 additions & 1 deletion python/dolfinx_contact/wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ NB_MODULE(cpp, m)
[](dolfinx_contact::Contact& self, int origin_meshtag, int facet)
{
auto [qp, qp_shape] = self.qp_phys(origin_meshtag);
dolfinx_contact::cmdspan3_t qp_span(qp.data(), qp_shape);
dolfinx_contact::mdspan_t<const double, 3> qp_span(qp.data(),
qp_shape);
std::vector<double> qp_vec(qp_shape[1] * qp_shape[2]);
for (std::size_t i = 0; i < qp_shape[1]; ++i)
for (std::size_t j = 0; j < qp_shape[2]; ++j)
Expand Down

0 comments on commit ac69084

Please sign in to comment.