Skip to content

Commit a2c0720

Browse files
authored
[Type] Remove VecView class and update codebase to use Vec utilities instead (#6138)
1 parent 71cb8a4 commit a2c0720

5 files changed

Lines changed: 32 additions & 112 deletions

File tree

Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/ElementCorotationalFEMForceField.inl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
******************************************************************************/
2222
#pragma once
2323
#include <sofa/component/solidmechanics/fem/elastic/ElementCorotationalFEMForceField.h>
24-
#include <sofa/type/VecView.h>
2524
#include <sofa/component/solidmechanics/fem/elastic/impl/VectorTools.h>
2625
#include <sofa/core/behavior/BaseLocalForceFieldMatrix.h>
2726

@@ -84,6 +83,7 @@ void ElementCorotationalFEMForceField<DataTypes, ElementType>::computeElementsFo
8483
const sofa::simulation::Range<std::size_t>& range, const sofa::core::MechanicalParams* mparams,
8584
sofa::type::vector<ElementGradient>& elementForces, const sofa::VecCoord_t<DataTypes>& nodePositions)
8685
{
86+
static constexpr auto DIM = trait::spatial_dimensions;
8787
const auto& elements = trait::FiniteElement::getElementSequence(*this->l_topology);
8888
auto restPositionAccessor = this->mstate->readRestPositions();
8989
auto elementStiffness = sofa::helper::getReadAccessor(this->d_elementStiffness);
@@ -108,19 +108,20 @@ void ElementCorotationalFEMForceField<DataTypes, ElementType>::computeElementsFo
108108
typename trait::ElementDisplacement displacement(sofa::type::NOINIT);
109109
for (sofa::Size j = 0; j < trait::NumberOfNodesInElement; ++j)
110110
{
111-
sofa::type::VecView<trait::spatial_dimensions, sofa::Real_t<DataTypes>> transformedDisplacement(displacement, j * trait::spatial_dimensions);
112-
transformedDisplacement = elementRotation.multTranspose(elementNodesCoordinates[j] - t) - (restElementNodesCoordinates[j] - t0);
111+
displacement.setsub(j * DIM,
112+
elementRotation.multTranspose(elementNodesCoordinates[j] - t) - (restElementNodesCoordinates[j] - t0));
113113
}
114114

115115
const auto& stiffnessMatrix = elementStiffness[elementId];
116116

117117
auto& elementForce = elementForces[elementId];
118118
elementForce = stiffnessMatrix * displacement;
119119

120-
for (sofa::Size i = 0; i < trait::NumberOfNodesInElement; ++i)
120+
sofa::type::Vec<DIM, sofa::Real_t<DataTypes>> nodeForce { sofa::type::NOINIT };
121+
for (sofa::Size n = 0; n < trait::NumberOfNodesInElement; ++n)
121122
{
122-
sofa::type::VecView<trait::spatial_dimensions, sofa::Real_t<DataTypes>> nodeForce(elementForce, i * trait::spatial_dimensions);
123-
nodeForce = elementRotation * nodeForce;
123+
elementForce.getsub(n * DIM, nodeForce);
124+
elementForce.setsub(n * DIM, elementRotation * nodeForce);
124125
}
125126
}
126127
}
@@ -146,19 +147,19 @@ void ElementCorotationalFEMForceField<DataTypes, ElementType>::computeElementsFo
146147

147148
for (sofa::Size n = 0; n < trait::NumberOfNodesInElement; ++n)
148149
{
149-
sofa::type::VecView<trait::spatial_dimensions, sofa::Real_t<DataTypes>> rotated_dx(element_dx, n * trait::spatial_dimensions);
150-
rotated_dx = elementRotation.multTranspose(nodeDx[element[n]]);
150+
element_dx.setsub(n * trait::spatial_dimensions, elementRotation.multTranspose(nodeDx[element[n]]));
151151
}
152152

153153
const auto& stiffnessMatrix = elementStiffness[elementId];
154154

155155
auto& df = elementForcesDeriv[elementId];
156156
df = stiffnessMatrix * element_dx;
157157

158+
sofa::type::Vec<trait::spatial_dimensions, sofa::Real_t<DataTypes>> nodedForce { sofa::type::NOINIT };
158159
for (sofa::Size n = 0; n < trait::NumberOfNodesInElement; ++n)
159160
{
160-
sofa::type::VecView<trait::spatial_dimensions, sofa::Real_t<DataTypes>> nodedForce(df, n * trait::spatial_dimensions);
161-
nodedForce = elementRotation * nodedForce;
161+
df.getsub(n * trait::spatial_dimensions, nodedForce);
162+
df.setsub(n * trait::spatial_dimensions, elementRotation * nodedForce);
162163
}
163164
}
164165
}

Sofa/framework/Type/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ set(HEADER_FILES
5252
${SOFATYPESRC_ROOT}/vector_algebra.h
5353
${SOFATYPESRC_ROOT}/vector_algorithm.h
5454
${SOFATYPESRC_ROOT}/vector_device.h
55-
${SOFATYPESRC_ROOT}/VecView.h
5655
${SOFATYPESRC_ROOT}/VoigtNotation.h
5756
)
5857

Sofa/framework/Type/src/sofa/type/Vec.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,16 @@ class Vec
311311
m = this->elems[i];
312312
}
313313

314+
template <Size N2, std::enable_if_t<(N2 < N), bool> = true>
315+
void setsub(const Size i, const sofa::type::Vec<N2, ValueType>& v) noexcept
316+
{
317+
for (Size j = 0; j < N2; j++)
318+
{
319+
this->elems[j + i] = v[j];
320+
}
321+
}
322+
323+
314324
// LINEAR ALGEBRA
315325
constexpr Vec<N,ValueType> mulscalar(const ValueType f) const noexcept
316326
{

Sofa/framework/Type/src/sofa/type/VecView.h

Lines changed: 0 additions & 101 deletions
This file was deleted.

Sofa/framework/Type/test/VecTypes_test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,17 @@ TEST(VecTest, getSubScalar)
538538
EXPECT_EQ(scalar, 6.0);
539539
}
540540

541+
TEST(VecTest, setSub)
542+
{
543+
sofa::type::Vec<5, double> v(1.0, 2.0, 3.0, 4.0, 5.0);
544+
sofa::type::Vec<2, double> sub { 9., 8. };
545+
v.setsub(1, sub);
546+
EXPECT_EQ(v[0], 1.0);
547+
EXPECT_EQ(v[1], 9.0);
548+
EXPECT_EQ(v[2], 8.0);
549+
EXPECT_EQ(v[3], 4.0);
550+
}
551+
541552
TEST(VecTest, staticSize)
542553
{
543554
constexpr sofa::Size s = sofa::type::Vec<3, double>::static_size;

0 commit comments

Comments
 (0)