Skip to content

Commit 226f4b6

Browse files
committed
Refactor TriangularShellForceField: Rename 'f_corotated' to 'd_corotated' and Add Draw Functionality
**Commit Message:** "Refactor TriangularShellForceField: Rename 'f_corotated' to 'd_corotated' and Add Draw Functionality" **Details:** - Renamed `f_corotated` to `d_corotated` across multiple files to improve consistency in naming conventions. - Fixed several minor spelling errors (e.g., "postions" to "positions"). - Added a `draw()` function to `TriangularShellForceField` for visual representation of shell triangle information, including arrows with customizable radii. - Minor code improvements in vector naming for clarity (`edgex` to `edge_x`, etc.).
1 parent a9d53c9 commit 226f4b6

5 files changed

Lines changed: 53 additions & 24 deletions

doc/code/html/_triangular_shell_force_field_8h_source.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@
302302
<div class="line"><a name="l00202"></a><span class="lineno"> 202</span>&#160; Data &lt;Real&gt; f_thickness;</div>
303303
<div class="line"><a name="l00203"></a><span class="lineno"> 203</span>&#160; Data &lt;sofa::helper::OptionsGroup&gt; f_membraneElement;</div>
304304
<div class="line"><a name="l00204"></a><span class="lineno"> 204</span>&#160; Data &lt;sofa::helper::OptionsGroup&gt; f_bendingElement;</div>
305-
<div class="line"><a name="l00205"></a><span class="lineno"> 205</span>&#160; Data&lt;bool&gt; f_corotated;</div>
305+
<div class="line"><a name="l00205"></a><span class="lineno"> 205</span>&#160; Data&lt;bool&gt; d_corotated;</div>
306306
<div class="line"><a name="l00206"></a><span class="lineno"> 206</span>&#160;</div>
307307
<div class="line"><a name="l00207"></a><span class="lineno"> 207</span>&#160; TRQSTriangleHandler* triangleHandler;</div>
308308
<div class="line"><a name="l00208"></a><span class="lineno"> 208</span>&#160;</div>

doc/code/html/classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field-members.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
<tr bgcolor="#f0f0f0"><td class="entry"><b>Displacement</b> typedef (defined in <a class="el" href="classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field.html">TriangularShellForceField&lt; DataTypes &gt;</a>)</td><td class="entry"><a class="el" href="classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field.html">TriangularShellForceField&lt; DataTypes &gt;</a></td><td class="entry"><span class="mlabel">protected</span></td></tr>
142142
<tr bgcolor="#f0f0f0"class="even"><td class="entry"><b>dktSD</b>(StrainDisplacement &amp;B, const TriangleInformation &amp;tinfo, const Real xi, const Real eta) (defined in <a class="el" href="classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field.html">TriangularShellForceField&lt; DataTypes &gt;</a>)</td><td class="entry"><a class="el" href="classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field.html">TriangularShellForceField&lt; DataTypes &gt;</a></td><td class="entry"><span class="mlabel">protected</span></td></tr>
143143
<tr bgcolor="#f0f0f0"><td class="entry"><b>f_bendingElement</b> (defined in <a class="el" href="classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field.html">TriangularShellForceField&lt; DataTypes &gt;</a>)</td><td class="entry"><a class="el" href="classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field.html">TriangularShellForceField&lt; DataTypes &gt;</a></td><td class="entry"></td></tr>
144-
<tr bgcolor="#f0f0f0"class="even"><td class="entry"><b>f_corotated</b> (defined in <a class="el" href="classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field.html">TriangularShellForceField&lt; DataTypes &gt;</a>)</td><td class="entry"><a class="el" href="classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field.html">TriangularShellForceField&lt; DataTypes &gt;</a></td><td class="entry"></td></tr>
144+
<tr bgcolor="#f0f0f0"class="even"><td class="entry"><b>d_corotated</b> (defined in <a class="el" href="classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field.html">TriangularShellForceField&lt; DataTypes &gt;</a>)</td><td class="entry"><a class="el" href="classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field.html">TriangularShellForceField&lt; DataTypes &gt;</a></td><td class="entry"></td></tr>
145145
<tr bgcolor="#f0f0f0"><td class="entry"><b>f_membraneElement</b> (defined in <a class="el" href="classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field.html">TriangularShellForceField&lt; DataTypes &gt;</a>)</td><td class="entry"><a class="el" href="classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field.html">TriangularShellForceField&lt; DataTypes &gt;</a></td><td class="entry"></td></tr>
146146
<tr bgcolor="#f0f0f0"class="even"><td class="entry"><b>f_poisson</b> (defined in <a class="el" href="classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field.html">TriangularShellForceField&lt; DataTypes &gt;</a>)</td><td class="entry"><a class="el" href="classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field.html">TriangularShellForceField&lt; DataTypes &gt;</a></td><td class="entry"></td></tr>
147147
<tr bgcolor="#f0f0f0"><td class="entry"><b>f_thickness</b> (defined in <a class="el" href="classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field.html">TriangularShellForceField&lt; DataTypes &gt;</a>)</td><td class="entry"><a class="el" href="classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field.html">TriangularShellForceField&lt; DataTypes &gt;</a></td><td class="entry"></td></tr>

doc/code/html/classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
<tr class="memitem:a07b28156193cf0cc041d7804b89aa35f"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a07b28156193cf0cc041d7804b89aa35f"></a>
200200
Data&lt; sofa::helper::OptionsGroup &gt;&#160;</td><td class="memItemRight" valign="bottom"><b>f_bendingElement</b></td></tr>
201201
<tr class="memitem:ab7339bd86a9f9e86f7029116f7aad084"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ab7339bd86a9f9e86f7029116f7aad084"></a>
202-
Data&lt; bool &gt;&#160;</td><td class="memItemRight" valign="bottom"><b>f_corotated</b></td></tr>
202+
Data&lt; bool &gt;&#160;</td><td class="memItemRight" valign="bottom"><b>d_corotated</b></td></tr>
203203
<tr class="memitem:ae9b0dde66496005adde20f2a37e58eeb"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ae9b0dde66496005adde20f2a37e58eeb"></a>
204204
<a class="el" href="classsofa_1_1component_1_1forcefield_1_1_triangular_shell_force_field_1_1_t_r_q_s_triangle_handler.html">TRQSTriangleHandler</a> *&#160;</td><td class="memItemRight" valign="bottom"><b>triangleHandler</b></td></tr>
205205
</table><table class="memberdecls">

src/SofaShells/forcefield/TriangularShellForceField.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ using sofa::type::vector;
5959
using namespace sofa::core::topology;
6060
using namespace sofa::core::behavior;
6161

62-
/// This class can be overridden if needed for additionnal storage within template specializations.
62+
/// This class can be overridden if needed for additional storage within template specializations.
6363
template<class DataTypes>
6464
class TriangularShellForceFieldInternalData
6565
{
@@ -200,6 +200,7 @@ class TriangularShellForceField : public core::behavior::ForceField<DataTypes>
200200
void addForce(const sofa::core::MechanicalParams* /*mparams*/, DataVecDeriv& dataF, const DataVecCoord& dataX, const DataVecDeriv& /*dataV*/ ) override ;
201201
void addDForce(const sofa::core::MechanicalParams* /*mparams*/, DataVecDeriv& datadF, const DataVecDeriv& datadX ) override ;
202202
void addKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override;
203+
void draw(const core::visual::VisualParams* vparams) override;
203204

204205
SReal getPotentialEnergy(const sofa::core::MechanicalParams* /*mparams*/, const DataVecCoord& /*x*/) const override { return 0; }
205206

@@ -210,11 +211,12 @@ class TriangularShellForceField : public core::behavior::ForceField<DataTypes>
210211
Data <Real> d_thickness;
211212
Data <sofa::helper::OptionsGroup> d_membraneElement;
212213
Data <sofa::helper::OptionsGroup> d_bendingElement;
213-
Data<bool> f_corotated;
214+
Data<bool> d_corotated;
214215
Data<sofa::helper::OptionsGroup> d_measure;
215216
Data<type::vector<Real> > d_measuredValues;
216217
Data<bool> d_isShellveryThin;
217218
Data<bool> d_use_rest_position;
219+
Data<Real> d_arrow_radius;
218220

219221
TRQSTriangleHandler* triangleHandler;
220222

src/SofaShells/forcefield/TriangularShellForceField.inl

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <vector>
3939
#include <algorithm>
4040
#include <sofa/defaulttype/VecTypes.h>
41+
#include <sofa/core/visual/VisualParams.h>
4142
#include <assert.h>
4243
#include <map>
4344
#include <utility>
@@ -77,13 +78,14 @@ TriangularShellForceField<DataTypes>::TriangularShellForceField()
7778
, d_thickness(initData(&d_thickness,(Real)0.1,"thickness","Thickness of the plates"))
7879
, d_membraneElement(initData(&d_membraneElement, "membraneElement", "The membrane element to use"))
7980
, d_bendingElement(initData(&d_bendingElement, "bendingElement", "The bending plate element to use"))
80-
, f_corotated(initData(&f_corotated, true, "corotated", "Compute forces in corotational frame"))
81+
, d_corotated(initData(&d_corotated, true, "corotated", "Compute forces in corotational frame"))
8182
, d_measure(initData(&d_measure, "measure", "Compute the strain or stress"))
8283
, d_measuredValues(initData(&d_measuredValues, "measuredValues", "Measured values for stress or strain"))
83-
,d_isShellveryThin(initData(&d_isShellveryThin, false, "isShellveryThin", "This bool is to adapt "
84+
, d_isShellveryThin(initData(&d_isShellveryThin, false, "isShellveryThin", "This bool is to adapt "
8485
"computation in case we are using verry tiny(thickness) shell element"))
8586
, d_use_rest_position(initData(&d_use_rest_position, true, "use_rest_position", "Use the rest position inteat of using postion to update the restposition"))
8687
, triangleInfo(initData(&triangleInfo, "triangleInfo", "Internal triangle data"))
88+
, d_arrow_radius(initData(&d_arrow_radius, (Real)0.1, "arrow_radius", "the arrow radius"))
8789

8890
{
8991
d_membraneElement.beginEdit()->setNames(7,
@@ -410,7 +412,7 @@ void TriangularShellForceField<DataTypes>::initTriangle(const int i, const Index
410412
tinfo->restPositions[1] = x0[b].getCenter();
411413
tinfo->restPositions[2] = x0[c].getCenter();
412414

413-
if (f_corotated.getValue()) {
415+
if (d_corotated.getValue()) {
414416
// Center the element
415417
Vec3 center = (tinfo->restPositions[0] + tinfo->restPositions[1] +
416418
tinfo->restPositions[2])/3;
@@ -480,7 +482,7 @@ template <class DataTypes>
480482
void TriangularShellForceField<DataTypes>::computeRotation(Transformation& R, const VecCoord &x, const Index &a, const Index &b, const Index &c)
481483
{
482484

483-
if (!f_corotated.getValue()) {
485+
if (!d_corotated.getValue()) {
484486
// Return identity matrix
485487
R = Transformation(Vec3(1,0,0), Vec3(0,1,0), Vec3(0,0,1));
486488
return;
@@ -509,7 +511,7 @@ void TriangularShellForceField<DataTypes>::computeRotation(Transformation& R, co
509511
template <class DataTypes>
510512
void TriangularShellForceField<DataTypes>::computeRotation(Transformation& R, const type::fixed_array<Vec3, 3> &x)
511513
{
512-
if (!f_corotated.getValue()) {
514+
if (!d_corotated.getValue()) {
513515
// Return identity matrix
514516
R = Transformation(Vec3(1,0,0), Vec3(0,1,0), Vec3(0,0,1));
515517
return;
@@ -519,19 +521,19 @@ void TriangularShellForceField<DataTypes>::computeRotation(Transformation& R, co
519521
// Second vector in the plane of the two first edges
520522
// Third vector orthogonal to first and second
521523

522-
Vec3 edgex = x[1] - x[0];
523-
Vec3 edgey = x[2] - x[0];
524+
Vec3 edge_x = x[1] - x[0];
525+
Vec3 edge_y = x[2] - x[0];
524526

525-
Vec3 edgez = cross(edgex, edgey);
527+
Vec3 edge_z = cross(edge_x, edge_y);
526528

527-
edgey = cross(edgez, edgex);
529+
edge_y = cross(edge_z, edge_x);
528530

529-
edgex.normalize();
530-
edgey.normalize();
531-
edgez.normalize();
531+
edge_x.normalize();
532+
edge_y.normalize();
533+
edge_z.normalize();
532534

533-
R = Transformation(edgex, edgey, edgez);
534-
//Qframe.fromMatrix(Transformation(edgex, edgey, edgez));
535+
R = Transformation(edge_x, edge_y, edge_z);
536+
//Qframe.fromMatrix(Transformation(edge_x, edge_y, edge_z));
535537
}
536538

537539

@@ -563,14 +565,14 @@ void TriangularShellForceField<DataTypes>::computeMaterialStiffness()
563565
// Integrate through the shell thickness
564566
materialMatrixMembrane *= t;
565567
if (d_isShellveryThin.getValue())
566-
materialMatrixBending *= t*t/1.;
568+
materialMatrixBending *= t*t;
567569
else
568570
materialMatrixBending *= t*t*t / 12;
569571
}
570572

571573

572574
// -------------------------------------------------------------------------------------------------------------
573-
// --- Compute displacement vector D as the difference between current current position and initial position
575+
// --- Compute displacement vector D as the difference between current position and initial position
574576
// -------------------------------------------------------------------------------------------------------------
575577
template <class DataTypes>
576578
void TriangularShellForceField<DataTypes>::computeDisplacement(Displacement &Dm, Displacement &Db, const VecCoord &x, const Index elementIndex)
@@ -582,12 +584,12 @@ void TriangularShellForceField<DataTypes>::computeDisplacement(Displacement &Dm,
582584
Index b = tinfo->b;
583585
Index c = tinfo->c;
584586

585-
// Compute local (in-plane) postions
587+
// Compute local (in-plane) positions
586588
tinfo->deformedPositions[0] = x[a].getCenter();
587589
tinfo->deformedPositions[1] = x[b].getCenter();
588590
tinfo->deformedPositions[2] = x[c].getCenter();
589591

590-
if (f_corotated.getValue()) {
592+
if (d_corotated.getValue()) {
591593
Vec3 center = (tinfo->deformedPositions[0] + tinfo->deformedPositions[1] +
592594
tinfo->deformedPositions[2])/3;
593595

@@ -603,7 +605,7 @@ void TriangularShellForceField<DataTypes>::computeDisplacement(Displacement &Dm,
603605
tinfo->Q.fromMatrix(tinfo->R);
604606
#endif
605607

606-
// Compute local (in-plane) postions
608+
// Compute local (in-plane) positions
607609
tinfo->deformedPositions[0] = tinfo->R * tinfo->deformedPositions[0];
608610
tinfo->deformedPositions[1] = tinfo->R * tinfo->deformedPositions[1];
609611
tinfo->deformedPositions[2] = tinfo->R * tinfo->deformedPositions[2];
@@ -1274,6 +1276,31 @@ void TriangularShellForceField<DataTypes>::dktSD(StrainDisplacement &B, const Tr
12741276
B /= 2*tinfo.area;
12751277
}
12761278

1279+
template <class DataTypes>
1280+
void TriangularShellForceField<DataTypes>::draw(const core::visual::VisualParams* vparams){
1281+
// Draw arrows from using shell triangle info (tinfo.R) in the center of the triangle
1282+
1283+
int nbTriangles=_topology->getNbTriangles();
1284+
type::vector<TriangleInformation>& triangleInf = *(triangleInfo.beginEdit());
1285+
const Real radius = d_arrow_radius.getValue();
1286+
for (unsigned int i=0; i< nbTriangles; i++)
1287+
{
1288+
const TriangleInformation &tinfo = triangleInf[i];
1289+
Vec3 vx = tinfo.R * Vec3(1, 0, 0);
1290+
Vec3 vy = tinfo.R * Vec3(0, 1, 0);
1291+
Vec3 vz = tinfo.R * Vec3(0, 0, 1);
1292+
1293+
// compute the center of the triangle
1294+
Vec3 center = (tinfo.deformedPositions[0] + tinfo.deformedPositions[1] +
1295+
tinfo.deformedPositions[2])/3;
1296+
vparams->drawTool()->drawArrow(center, center + vx, radius, type::RGBAColor(1.0, 0.0, 0.0, 1.0));
1297+
vparams->drawTool()->drawArrow(center, center + vy, radius, type::RGBAColor(0.0, 1.0, 0.0, 1.0));
1298+
vparams->drawTool()->drawArrow(center, center + vz, radius, type::RGBAColor(0.0, 0.0, 1.0, 1.0));
1299+
}
1300+
triangleInfo.endEdit();
1301+
}
1302+
1303+
12771304
} // namespace forcefield
12781305

12791306
} // namespace component

0 commit comments

Comments
 (0)