Skip to content

Commit

Permalink
refactor: Refactor LagrangeMultiplier constructor to initialize m_S_V…
Browse files Browse the repository at this point in the history
…ector efficiently
  • Loading branch information
gouarin committed Oct 2, 2024
1 parent 3596abb commit a8ec7c9
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions include/scopi/solvers/lagrange_multiplier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ namespace scopi

LagrangeMultiplier(const Contacts& contacts, double)
: base(contacts)
, m_S_Vector(xt::zeros<double>({contacts.size()}))
, m_local_work(xt::zeros<double>({contacts.size()}))
, m_global_work(xt::zeros<double>({3 * contacts.size()}))
{
m_S_Vector = xt::zeros<double>({size()});
m_local_work = xt::zeros<double>({size()});
m_global_work = xt::zeros<double>({3 * contacts.size()});
}

const auto& global2local(const xt::xtensor<double, 1>& x) const
Expand Down Expand Up @@ -216,8 +216,8 @@ namespace scopi

LagrangeMultiplier(const Contacts& contacts, double)
: base(contacts)
, m_S_Vector(xt::zeros<double>({contacts.size()}))
{
m_S_Vector = xt::zeros<double>({size()});
}

auto global2local(const xt::xtensor<double, 1>& x) const
Expand Down Expand Up @@ -284,8 +284,8 @@ namespace scopi

LagrangeMultiplier(const Contacts& contacts, [[maybe_unused]] double dt)
: base(contacts)
, m_S_Vector(xt::zeros<double>({contacts.size()}))
{
m_S_Vector = xt::zeros<double>({size()});
for (std::size_t i = 0, row = 0; i < this->m_contacts.size(); ++i, row += 3)
{
xt::view(m_S_Vector, xt::range(row, row + dim)) = this->m_contacts[i].sij * this->m_contacts[i].nij;
Expand Down Expand Up @@ -356,6 +356,7 @@ namespace scopi

LagrangeMultiplier(const Contacts& contacts, double dt) // cppcheck-suppress uninitMemberVar
: base(contacts)
, m_S_Vector(xt::zeros<double>({contacts.size()}))
{
m_size = 0;
for (std::size_t i = 0; i < this->m_contacts.size(); ++i)
Expand All @@ -376,7 +377,7 @@ namespace scopi
++m_size;
}
}
m_S_Vector = xt::zeros<double>({size()});

std::size_t row = 0;
for (std::size_t i = 0; i < this->m_contacts.size(); ++i)
{
Expand Down

0 comments on commit a8ec7c9

Please sign in to comment.