Skip to content

Commit

Permalink
More const fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
garth-wells committed Jun 9, 2024
1 parent 38869c3 commit db3a1d5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 41 deletions.
15 changes: 7 additions & 8 deletions cpp/Contact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ void compute_linked_cells(
} // namespace

dolfinx_contact::Contact::Contact(
const std::vector<std::shared_ptr<dolfinx::mesh::MeshTags<std::int32_t>>>&
markers,
const std::vector<
std::shared_ptr<const dolfinx::mesh::MeshTags<std::int32_t>>>& markers,
const dolfinx::graph::AdjacencyList<std::int32_t>& surfaces,
const std::vector<std::array<int, 2>>& contact_pairs,
std::shared_ptr<const dolfinx::mesh::Mesh<double>> mesh,
Expand Down Expand Up @@ -115,7 +115,7 @@ dolfinx_contact::Contact::Contact(
offsets.push_back(0);
for (std::size_t s = 0; s < markers.size(); ++s)
{
std::shared_ptr<dolfinx::mesh::MeshTags<int>> marker = markers[s];
std::shared_ptr<const dolfinx::mesh::MeshTags<int>> marker = markers[s];
std::span<const int> links = surfaces.links(int(s));
for (std::size_t i = 0; i < links.size(); ++i)
{
Expand All @@ -139,7 +139,7 @@ dolfinx_contact::Contact::Contact(
_quadrature_rule = std::make_shared<QuadratureRule>(
topology->cell_type(), q_deg, fdim, basix::quadrature::type::Default);
}
//------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------
std::pair<std::vector<double>, std::array<std::size_t, 3>>
dolfinx_contact::Contact::qp_phys(int surface) const
{
Expand All @@ -150,16 +150,15 @@ dolfinx_contact::Contact::qp_phys(int surface) const
std::array<std::size_t, 3> shape = {num_facets, num_q_points, gdim};
return {_qp_phys[surface], shape};
}
//------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------
std::size_t dolfinx_contact::Contact::coefficients_size(
bool meshtie,
std::shared_ptr<const dolfinx::fem::FunctionSpace<double>> V) const
bool meshtie, const dolfinx::fem::FunctionSpace<double>& V) const
{
// mesh data
const std::size_t gdim = _mesh->geometry().dim(); // geometrical dimension

// Extract function space data (assuming same test and trial space)
std::shared_ptr<const dolfinx::fem::DofMap> dofmap = V->dofmap();
std::shared_ptr<const dolfinx::fem::DofMap> dofmap = V.dofmap();
const std::size_t ndofs_cell = dofmap->cell_dofs(0).size();
const std::size_t bs = dofmap->bs();

Expand Down
10 changes: 5 additions & 5 deletions cpp/Contact.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class Contact
/// @param[in] V The functions space
/// @param[in] mode Contact detection algorithm for each pair
/// @param[in] q_deg The quadrature degree.
Contact(const std::vector<
std::shared_ptr<dolfinx::mesh::MeshTags<std::int32_t>>>& markers,
Contact(const std::vector<std::shared_ptr<
const dolfinx::mesh::MeshTags<std::int32_t>>>& markers,
const dolfinx::graph::AdjacencyList<std::int32_t>& surfaces,
const std::vector<std::array<int, 2>>& contact_pairs,
std::shared_ptr<const dolfinx::mesh::Mesh<double>> mesh,
Expand Down Expand Up @@ -92,9 +92,9 @@ class Contact
/// return size of coefficients vector per facet on s
/// @param[in] meshtie - Type of constraint,meshtie if true, unbiased contact
/// if false
std::size_t coefficients_size(
bool meshtie,
std::shared_ptr<const dolfinx::fem::FunctionSpace<double>> V) const;
std::size_t
coefficients_size(bool meshtie,
const dolfinx::fem::FunctionSpace<double>& V) const;

/// return distance map (adjacency map mapping quadrature points on surface
/// to closest facet on other surface)
Expand Down
29 changes: 15 additions & 14 deletions cpp/MeshTie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@

#include "MeshTie.h"

//-----------------------------------------------------------------------------
void dolfinx_contact::MeshTie::generate_kernel_data(
dolfinx_contact::Problem problem_type,
const dolfinx::fem::FunctionSpace<double>& V,
const std::map<std::string,
std::shared_ptr<dolfinx::fem::Function<double>>>&
std::shared_ptr<const dolfinx::fem::Function<double>>>&
coefficients,
double gamma, double theta)
{
std::vector<std::shared_ptr<dolfinx::fem::Function<double>>> coeff_list;
std::vector<std::shared_ptr<const dolfinx::fem::Function<double>>> coeff_list;
switch (problem_type)
{

Expand All @@ -32,9 +33,7 @@ void dolfinx_contact::MeshTie::generate_kernel_data(
dolfinx_contact::MeshTie::generate_meshtie_data_matrix_only(
problem_type, V, coeff_list, gamma, theta);
if (auto it = coefficients.find("u"); it != coefficients.end())
{
update_kernel_data(coefficients, problem_type);
}
break;
case Poisson:
if (auto it = coefficients.find("kdt"); it != coefficients.end())
Expand Down Expand Up @@ -73,11 +72,11 @@ void dolfinx_contact::MeshTie::generate_kernel_data(
throw std::invalid_argument("Problem type not implemented");
}
}

//-----------------------------------------------------------------------------
void dolfinx_contact::MeshTie::generate_meshtie_data_matrix_only(
dolfinx_contact::Problem problem_type,
const dolfinx::fem::FunctionSpace<double>& V,
std::vector<std::shared_ptr<dolfinx::fem::Function<double>>> coeffs,
std::vector<std::shared_ptr<const dolfinx::fem::Function<double>>> coeffs,
double gamma, double theta)
{
// mesh data
Expand Down Expand Up @@ -186,9 +185,10 @@ void dolfinx_contact::MeshTie::generate_meshtie_data_matrix_only(
}
}
}
//-----------------------------------------------------------------------------
void dolfinx_contact::MeshTie::update_kernel_data(
const std::map<std::string,
std::shared_ptr<dolfinx::fem::Function<double>>>&
std::shared_ptr<const dolfinx::fem::Function<double>>>&
coefficients,
dolfinx_contact::Problem problem_type)
{
Expand All @@ -201,7 +201,7 @@ void dolfinx_contact::MeshTie::update_kernel_data(
std::size_t offset0 = 0;
std::size_t offset1 = 0;

std::vector<std::shared_ptr<dolfinx::fem::Function<double>>> coeff_list;
std::vector<std::shared_ptr<const dolfinx::fem::Function<double>>> coeff_list;
switch (problem_type)
{
using enum dolfinx_contact::Problem;
Expand Down Expand Up @@ -273,7 +273,7 @@ void dolfinx_contact::MeshTie::update_kernel_data(
throw std::invalid_argument("Problem type not implemented");
}
}

//-----------------------------------------------------------------------------
void dolfinx_contact::MeshTie::update_function_data(
const dolfinx::fem::Function<double>& u,
std::vector<std::vector<double>>& coeffs, std::size_t offset0,
Expand Down Expand Up @@ -309,7 +309,7 @@ void dolfinx_contact::MeshTie::update_function_data(
}
}
}

//-----------------------------------------------------------------------------
void dolfinx_contact::MeshTie::update_gradient_data(
const dolfinx::fem::Function<double>& u,
std::vector<std::vector<double>>& coeffs, std::size_t offset0,
Expand Down Expand Up @@ -346,7 +346,7 @@ void dolfinx_contact::MeshTie::update_gradient_data(
}
}
}

//-----------------------------------------------------------------------------
void dolfinx_contact::MeshTie::generate_poisson_data_matrix_only(
const dolfinx::fem::FunctionSpace<double>& V,
const dolfinx::fem::Function<double>& kdt, double gamma, double theta)
Expand Down Expand Up @@ -432,7 +432,7 @@ void dolfinx_contact::MeshTie::generate_poisson_data_matrix_only(
}
}
}

//-----------------------------------------------------------------------------
void dolfinx_contact::MeshTie::assemble_vector(
std::span<PetscScalar> b, const dolfinx::fem::FunctionSpace<double>& V,
dolfinx_contact::Problem problem_type)
Expand Down Expand Up @@ -461,7 +461,7 @@ void dolfinx_contact::MeshTie::assemble_vector(
throw std::invalid_argument("Problem type not implemented");
}
}

//-----------------------------------------------------------------------------
void dolfinx_contact::MeshTie::assemble_matrix(
const mat_set_fn& mat_set, const dolfinx::fem::FunctionSpace<double>& V,
dolfinx_contact::Problem problem_type)
Expand All @@ -488,10 +488,11 @@ void dolfinx_contact::MeshTie::assemble_matrix(
throw std::invalid_argument("Problem type not implemented");
}
}

//-----------------------------------------------------------------------------
std::pair<std::vector<double>, std::size_t>
dolfinx_contact::MeshTie::coeffs(int pair)
{
std::vector<double>& coeffs = _coeffs[pair];
return {coeffs, _cstride};
}
//-----------------------------------------------------------------------------
13 changes: 7 additions & 6 deletions cpp/MeshTie.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ class MeshTie : public Contact
/// surface in surfaces->array() as a pair of connected surfaces
/// @param[in] V The functions space
/// @param[in] q_deg The quadrature degree.
MeshTie(const std::vector<
std::shared_ptr<dolfinx::mesh::MeshTags<std::int32_t>>>& markers,
MeshTie(const std::vector<std::shared_ptr<
const dolfinx::mesh::MeshTags<std::int32_t>>>& markers,
const dolfinx::graph::AdjacencyList<std::int32_t>& surfaces,
const std::vector<std::array<int, 2>>& connected_pairs,
std::shared_ptr<dolfinx::mesh::Mesh<double>> mesh, int q_deg = 3)
std::shared_ptr<const dolfinx::mesh::Mesh<double>> mesh,
int q_deg = 3)
: Contact::Contact(markers, surfaces, connected_pairs, mesh,
std::vector<ContactMode>(connected_pairs.size(),
ContactMode::ClosestPoint),
Expand Down Expand Up @@ -83,7 +84,7 @@ class MeshTie : public Contact
void generate_kernel_data(
Problem problem_type, const dolfinx::fem::FunctionSpace<double>& V,
const std::map<std::string,
std::shared_ptr<dolfinx::fem::Function<double>>>&
std::shared_ptr<const dolfinx::fem::Function<double>>>&
coefficients,
double gamma, double theta);

Expand All @@ -95,7 +96,7 @@ class MeshTie : public Contact
void generate_meshtie_data_matrix_only(
dolfinx_contact::Problem problem_type,
const dolfinx::fem::FunctionSpace<double>& V,
std::vector<std::shared_ptr<dolfinx::fem::Function<double>>> coeffs,
std::vector<std::shared_ptr<const dolfinx::fem::Function<double>>> coeffs,
double gamma, double theta);

/// Update data for vector assembly based on state
Expand All @@ -105,7 +106,7 @@ class MeshTie : public Contact
/// @param[in] problem_type - the type of equation, e.g. elasticity
void update_kernel_data(
const std::map<std::string,
std::shared_ptr<dolfinx::fem::Function<double>>>&
std::shared_ptr<const dolfinx::fem::Function<double>>>&
coefficients,
Problem problem_type);

Expand Down
18 changes: 10 additions & 8 deletions python/dolfinx_contact/wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ NB_MODULE(cpp, m)
nb::class_<dolfinx_contact::Contact>(m, "Contact", "Contact object")
.def(
nb::init<const std::vector<
std::shared_ptr<dolfinx::mesh::MeshTags<std::int32_t>>>&,
std::shared_ptr<const dolfinx::mesh::MeshTags<std::int32_t>>>&,
const dolfinx::graph::AdjacencyList<std::int32_t>&,
const std::vector<std::array<int, 2>>&,
std::shared_ptr<const dolfinx::mesh::Mesh<double>>,
Expand Down Expand Up @@ -374,13 +374,15 @@ NB_MODULE(cpp, m)

// Contact
nb::class_<dolfinx_contact::MeshTie>(m, "MeshTie", "meshtie object")
.def(nb::init<std::vector<
std::shared_ptr<dolfinx::mesh::MeshTags<std::int32_t>>>,
const dolfinx::graph::AdjacencyList<std::int32_t>&,
std::vector<std::array<int, 2>>,
std::shared_ptr<dolfinx::mesh::Mesh<double>>, const int>(),
nb::arg("markers"), nb::arg("surfaces"), nb::arg("contact_pairs"),
nb::arg("V"), nb::arg("quadrature_degree") = 3)
.def(
nb::init<
std::vector<
std::shared_ptr<const dolfinx::mesh::MeshTags<std::int32_t>>>,
const dolfinx::graph::AdjacencyList<std::int32_t>&,
std::vector<std::array<int, 2>>,
std::shared_ptr<const dolfinx::mesh::Mesh<double>>, const int>(),
nb::arg("markers"), nb::arg("surfaces"), nb::arg("contact_pairs"),
nb::arg("V"), nb::arg("quadrature_degree") = 3)
.def(
"coeffs",
[](dolfinx_contact::MeshTie& self, int pair)
Expand Down

0 comments on commit db3a1d5

Please sign in to comment.