Skip to content

Commit fe848ed

Browse files
authored
[src] Fix the logic when to start tearing and add fracture structure (#65)
* [src] Fix the logic when to start tearing * Backup work on new fracture path * clean PR
1 parent ec89592 commit fe848ed

6 files changed

Lines changed: 29 additions & 28 deletions

File tree

scenes/TearingEngine/SquareTissue_11_MiddlePressure .scn

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
<CGLinearSolver iterations="25" name="linear solver" tolerance="1.0e-9" threshold="1.0e-9" />
4040
<MeshGmshLoader name="meshLoader" filename="mesh/square3.msh" scale="10" createSubelements="true" />
4141

42-
<TriangleSetTopologyContainer name="Container" src="@meshLoader" fileTopology="" tags=" " />
42+
<TriangleSetTopologyContainer name="Container" src="@meshLoader" />
4343
<TriangleSetTopologyModifier name="Modifier" />
44-
<TriangleSetGeometryAlgorithms name="GeomAlgo" template="Vec3d" />
44+
<TriangleSetGeometryAlgorithms name="GeomAlgo" template="Vec3d" showEdgeIndices="1" showTriangleIndices="1" showIndicesScale="0.001"/>
4545

4646
<MechanicalObject name="Mo"/>
4747
<DiagonalMass massDensity="0.15" />
@@ -51,15 +51,15 @@
5151

5252
<BoxROI template="Vec3d" name="PullMiddle" box="4.9 4.95 0.1 5.1 5.1 0.1" drawBoxes="1"/>
5353
<!--<BoxROI template="Vec3d" name="PulledSide" box="-0.1 0.1 0.1 10.1 -0.1 -0.1" drawBoxes="1"/>-->
54-
<ConstantForceField name="CFF" indices="772" forces="0 -300 0" showArrowSize=".01" />
54+
<ConstantForceField name="CFF" indices="772" forces="0 -500 0" showArrowSize=".01" />
5555

5656
<TriangularFEMForceField name="FEM" youngModulus="300" poissonRatio="0.3" method="large" computePrincipalStress="true"/>
5757
<TriangularBendingSprings name="FEM-Bend" stiffness="300" damping="1.0" />
5858
<PlaneForceField normal="0 1 0" d="-30" stiffness="100000" showPlane="1" showPlaneSize="20"/>
5959

6060
<TriangleCollisionModel />
61-
<TearingEngine name="TearingEngine" input_position="@Mo.position" stressThreshold="0.1"
62-
step="20" nbFractureMax="40" showFracturePath="1"/>
61+
<TearingEngine name="TearingEngine" input_position="@Mo.position" stressThreshold="15.0"
62+
step="20" nbFractureMax="40" showFracturePath="1" showTearableCandidates="1" fractureMaxLength="1.0"/>
6363

6464
<Node >
6565
<OglModel name="Visual" color="gray" />
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
2.39377 7.2768 19.272
1+
5.18732 3.91825 1.3
22
-0.0438528 -0.046858 0.00673547 0.997916

src/Tearing/BaseTearingEngine.inl

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void BaseTearingEngine<DataTypes>::doUpdate()
162162
if (sofa::core::objectmodel::BaseObject::d_componentState.getValue() != sofa::core::objectmodel::ComponentState::Valid)
163163
return;
164164

165-
m_stepCounter++;
165+
166166

167167
if (d_ignoreTriangles.getValue())
168168
{
@@ -215,7 +215,6 @@ void BaseTearingEngine<DataTypes>::triangleOverThresholdPrincipalStress()
215215
candidate.clear();
216216
maxStress = 0;
217217
helper::WriteAccessor< Data<vector<Index>> >triangleToSkip(d_trianglesToIgnore);
218-
219218
m_maxStressTriangleIndex = InvalidID;
220219
for (unsigned int i = 0; i < triangleList.size(); i++)
221220
{
@@ -639,6 +638,9 @@ void BaseTearingEngine<DataTypes>::handleEvent(sofa::core::objectmodel::Event* e
639638
return; // We only launch computation at end of a simulation step
640639
}
641640

641+
if (m_tearingAlgo->getFractureNumber() > d_nbFractureMax.getValue())
642+
return;
643+
642644
computeFracturePath();
643645

644646
// Hack: we access one output value to force the engine to call doUpdate()
@@ -647,14 +649,9 @@ void BaseTearingEngine<DataTypes>::handleEvent(sofa::core::objectmodel::Event* e
647649

648650
// Perform fracture every d_stepModulo
649651
int step = d_stepModulo.getValue();
650-
if (step == 0) // interactive version
651-
{
652-
if (m_stepCounter > 200 && (m_tearingAlgo->getFractureNumber() < d_nbFractureMax.getValue())){
653-
algoFracturePath();
654-
}
655-
}
656-
else if (((m_stepCounter % step) == 0) && (m_tearingAlgo->getFractureNumber() < d_nbFractureMax.getValue()))
652+
if (m_stepCounter > step)
657653
{
654+
m_stepCounter = 0;
658655
algoFracturePath();
659656
}
660657
}

src/Tearing/TearingAlgorithms.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <sofa/component/topology/container/dynamic/TriangleSetTopologyModifier.h>
3030
#include <sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.h>
3131

32+
3233
namespace sofa::component
3334
{
3435
using sofa::component::topology::container::dynamic::TriangleSetTopologyModifier;
@@ -46,14 +47,14 @@ class TearingAlgorithms
4647
using Edge = sofa::core::topology::BaseMeshTopology::Edge;
4748
using Triangle = sofa::core::topology::BaseMeshTopology::Triangle;
4849
using VecIds = sofa::type::vector<Index>;
50+
4951

5052
TearingAlgorithms(sofa::core::topology::BaseMeshTopology* _topology,
5153
TriangleSetTopologyModifier* _modifier,
5254
TriangleSetGeometryAlgorithms<DataTypes>* _triangleGeo);
5355

5456
virtual ~TearingAlgorithms();
5557

56-
5758
/// <summary>
5859
/// compute fracture path intersection point and cut through them
5960
/// </summary>
@@ -158,6 +159,7 @@ class TearingAlgorithms
158159

159160
/// path created by algoFracturePath
160161
sofa::type::vector<Coord> m_fracturePath;
162+
161163
};
162164

163165

src/Tearing/TearingAlgorithms.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#pragma once
2525
#include <Tearing/TearingAlgorithms.h>
2626

27+
2728
namespace sofa::component
2829
{
2930

src/Tearing/TearingEngine.inl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,12 @@ inline bool TearingEngine<DataTypes>::computeIntersectionNeighborTriangle(Coord
9696
template<class DataTypes>
9797
inline bool TearingEngine<DataTypes>::computeEndPointsNeighboringTriangles(Coord Pa, Coord direction, Coord& Pb, Coord& Pc)
9898
{
99-
10099
bool t_b_ok = false;
101100
bool t_c_ok = false;
102101
//compute fracture direction perpendicular to the principal stress direction
103102
Coord fractureDirection;
104103
this->computeFractureDirection(direction, fractureDirection);
105104

106-
107105
Real norm_fractureDirection = fractureDirection.norm();
108106
Coord dir_b = 1.0 / norm_fractureDirection * fractureDirection;
109107

@@ -151,12 +149,6 @@ void TearingEngine<DataTypes>::algoFracturePath()
151149
Coord Pb;
152150
Coord Pc;
153151

154-
if (this->d_fractureMaxLength.getValue())
155-
this->computeEndPoints(Pa, principalStressDirection, Pb, Pc);
156-
else if (!(computeEndPointsNeighboringTriangles(Pa, principalStressDirection, Pb, Pc)))
157-
return;
158-
159-
160152
this->m_tearingAlgo->algoFracturePath(Pa, indexA, Pb, Pc, m_maxStressTriangleIndex, principalStressDirection, d_input_positions.getValue());
161153
m_maxStressTriangleIndex = InvalidID;
162154

@@ -168,7 +160,7 @@ void TearingEngine<DataTypes>::algoFracturePath()
168160
template <class DataTypes>
169161
void TearingEngine<DataTypes>::computeFracturePath()
170162
{
171-
if (!this->d_fractureMaxLength.getValue() && m_maxStressTriangleIndex != InvalidID)
163+
if (m_maxStressTriangleIndex != InvalidID)
172164
{
173165
//Recording the endpoints of the fracture segment
174166
helper::ReadAccessor< Data<VecCoord> > x(d_input_positions);
@@ -179,11 +171,20 @@ void TearingEngine<DataTypes>::computeFracturePath()
179171
Coord Pb, Pc;
180172
fractureSegmentEndpoints.clear();
181173

182-
if (computeEndPointsNeighboringTriangles(Pa, principalStressDirection, Pb, Pc))
174+
if (this->d_fractureMaxLength.getValue() == 0.0) {
175+
computeEndPointsNeighboringTriangles(Pa, principalStressDirection, Pb, Pc);
176+
}
177+
else
183178
{
184-
fractureSegmentEndpoints.push_back(Pb);
185-
fractureSegmentEndpoints.push_back(Pc);
179+
this->computeEndPoints(Pa, principalStressDirection, Pb, Pc);
186180
}
181+
182+
fractureSegmentEndpoints.push_back(Pb);
183+
fractureSegmentEndpoints.push_back(Pc);
184+
185+
this->m_stepCounter++;
186+
187+
//this->m_tearingAlgo->computeFracturePath(Pa, m_maxStressTriangleIndex, Pb, Pc);
187188
}
188189
}
189190

0 commit comments

Comments
 (0)