UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
XPBDCorotatedFiberConstraints.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
6#include "ChaosStats.h"
10
11//DECLARE_CYCLE_STAT(TEXT("Chaos XPBD Corotated Constraint"), STAT_XPBD_Spring, STATGROUP_Chaos);
12
13namespace Chaos::Softs
14{
15 template <typename T, typename ParticleType>
17 {
18
22 using Base::Measure;
23 using Base::DmInverse;
24
25 public:
26 //this one only accepts tetmesh input and mesh
28 const ParticleType& InParticles,
30 const bool bRecordMetricIn = true,
31 const T& EMesh = (T)10.0,
32 const T& NuMesh = (T).3,
33 const TVector<T, 3> InFiberDir = TVector<T, 3>((T)1., (T)0., (T)0.),
34 const T InSigmaMax = (T)3e5
35 )
37 {
38 LambdaArray.Init((T)0., 3 * MeshConstraints.Num());
39 }
40
42
43 TVector<T, 3> GetFiberDir() { return FiberDir; }
44
45 void SetActivation(const T AlphaIn) { AlphaActivation = AlphaIn; }
46
47 void SetTime(const float Time) const {
48 float FinalTime = 4.0f;
49 float CurrentTime = Time;
50 while (CurrentTime > FinalTime)
51 {
52 CurrentTime -= FinalTime;
53 }
54 AlphaActivation = (T)1. - (T)4. / FinalTime * FMath::Abs(CurrentTime - FinalTime / (T)2.);
55 }
56
57 virtual void ApplyInSerial(ParticleType& Particles, const T Dt, const int32 ElementIndex) const override
58 {
59 TVec4<TVector<T, 3>> PolarDelta = Base::GetPolarDelta(Particles, Dt, ElementIndex);
60
61 for (int i = 0; i < 4; i++)
62 {
63 Particles.P(MeshConstraints[ElementIndex][i]) += PolarDelta[i];
64 }
65
66 TVec4<TVector<T, 3>> DetDelta = Base::GetDeterminantDelta(Particles, Dt, ElementIndex);
67
68 for (int i = 0; i < 4; i++)
69 {
70 Particles.P(MeshConstraints[ElementIndex][i]) += DetDelta[i];
71 }
72
73 TVec4<TVector<T, 3>> FiberDelta = GetFiberDelta(Particles, Dt, ElementIndex);
74
75 for (int i = 0; i < 4; i++)
76 {
77 Particles.P(MeshConstraints[ElementIndex][i]) += FiberDelta[i];
78 }
79
80
81 }
82
83 TVec4<TVector<T, 3>> GetFiberGradient(const T dFpdL, const T dFadL,const T C3, const TVec4<TVector<T, 3>>& dLdX) const
84 {
85 T dC3dL = (T)0.5 * (dFpdL + AlphaActivation * dFadL);
86 if (C3 == 0)
87 {
88 return TVec4<TVector<T, 3>>(TVector<T, 3>((T)0.));
89 }
90 else
91 {
92 dC3dL /= C3;
93 }
94
96 for (int32 i = 0; i < 4; i++)
97 {
98 for (int32 j = 0; j < 3; j++)
99 {
100 dC3[i][j] = dC3dL * dLdX[i][j];
101 }
102 }
103
104 return dC3;
105
106 }
107
108
109 private:
110
111 TVec4<TVector<T, 3>> GetFiberDelta(const ParticleType& Particles, const T Dt, const int32 ElementIndex, const T Tol = 1e-3) const
112 {
113 const PMatrix<T, 3, 3> Fe = Base::F(ElementIndex, Particles);
114
115 PMatrix<T, 3, 3> Re((T)0.), Se((T)0.);
116
118
119 // l: fiber stretch, f = (vTCv)^(1/2)
120 TVector<T, 3> FeV = Fe.GetTransposed() * FiberDir;
121 TVector<T, 3> DmInverseV = Base::ElementDmInv(ElementIndex).GetTransposed() * FiberDir;
122 T L = FeV.Size();
124 for (int32 alpha = 0; alpha < 3; alpha++)
125 {
126 for (int32 s = 0; s < 3; s++)
127 {
128 dLdX[0][alpha] -= FeV[alpha] * DmInverseV[s] / L;
129 }
130
131 }
132 for (int32 ie = 1; ie < 4; ie++)
133 {
134 for (int32 alpha = 0; alpha < 3; alpha++)
135 {
136 dLdX[ie][alpha] = FeV[alpha] * DmInverseV[ie - 1] / L;
137 }
138 }
139
140 T LambdaOFL = (T)1.4;
141 T P1 = (T)0.05;
142 T P2 = (T)6.6;
143 T FpIntegral = (T)0.;
144 T FaIntegral = (T)0.;
145
146 T C3 = (T)0.;
147 T AlphaTilde = LambdaOFL / (SigmaMax * Dt * Dt * Measure[ElementIndex]);
148 T dFpdL = (T)0.;
149 T dFadL = (T)0.;
150
151 if (L > LambdaOFL)
152 {
153 FpIntegral = P1 * LambdaOFL / P2 * FMath::Exp(P2 * (L / LambdaOFL - (T)1.)) - P1 * (L - LambdaOFL);
154 dFpdL = P1 * FMath::Exp(P2 * (L / LambdaOFL - (T)1.)) - P1;
155 }
156 if (L > (T)0.4 * LambdaOFL && L < (T)0.6 * LambdaOFL)
157 {
158 FaIntegral = (T)3. * LambdaOFL * FMath::Pow((L / LambdaOFL - (T)0.4), 3);
159 dFadL = (T)9. * FMath::Pow((L / LambdaOFL - (T)0.4), 2);
160 }
161 else if (L >= (T)0.6 * LambdaOFL && L <= (T)1.4 * LambdaOFL)
162 {
163 FaIntegral = (T)3. * LambdaOFL * (T)0.008 + L - (T)4. / (T)3. * LambdaOFL * FMath::Pow(L / LambdaOFL - (T)1., 3) - (T)0.6 * LambdaOFL - (T)4. / (T)3. * LambdaOFL * FMath::Pow((T)0.4, 3);
164 dFadL = (T)1. - (T)4. * FMath::Pow(L / LambdaOFL - (T)1., 2);
165 }
166 else if (L > (T)1.4 * LambdaOFL && L <= (T)1.6 * LambdaOFL)
167 {
168 FaIntegral = (T)3. * LambdaOFL * (T)0.008 + (T)0.8 * LambdaOFL - (T)8. / (T)3. * LambdaOFL * FMath::Pow((T)0.4, 3) + (T)3. * LambdaOFL * FMath::Pow(L / LambdaOFL - (T)1.6, 3) + (T)3. * LambdaOFL * (T)0.008;
169 dFadL = (T)9. * FMath::Pow((L / LambdaOFL - (T)1.6), 2);
170
171 }
172 else if (L > (T)1.6 * LambdaOFL)
173 {
174 FaIntegral = (T)3. * LambdaOFL * (T)0.008 + (T)0.8 * LambdaOFL - (T)8. / (T)3. * LambdaOFL * FMath::Pow((T)0.4, 3) + (T)3. * LambdaOFL * (T)0.008;
175 dFadL = (T)0.;
176 }
177
178
179 C3 = FMath::Sqrt(FpIntegral + AlphaActivation * FaIntegral);
180
181
182 //T dC3dL = (T)0.5 * (dFpdL + AlphaActivation * dFadL);
183 //if (C3 == 0)
184 //{
185 // return TVec4<TVector<T, 3>>(TVector<T, 3>((T)0.));
186 //}
187 //else
188 //{
189 // dC3dL /= C3;
190 //}
191
193
194 //TVec4<TVector<T, 3>> dC3(TVector<T, 3>((T)0.));
195 //for (int32 i = 0; i < 4; i++)
196 //{
197 // for (int32 j = 0; j < 3; j++)
198 // {
199 // dC3[i][j] = dC3dL * dLdX[i][j];
200 // }
201 //}
202
203 T DLambda = -C3 - AlphaTilde * LambdaArray[2 * ElementIndex + 2];
204
205 T Denom = AlphaTilde;
206 for (int i = 0; i < 4; i++)
207 {
208 for (int j = 0; j < 3; j++)
209 {
210 Denom += dC3[i][j] * Particles.InvM(MeshConstraints[ElementIndex][i]) * dC3[i][j];
211 }
212 }
213 DLambda /= Denom;
214 LambdaArray[2 * ElementIndex + 2] += DLambda;
215 TVec4<TVector<T, 3>> Delta(TVector<T, 3>((T)0.));
216 for (int i = 0; i < 4; i++)
217 {
218 for (int j = 0; j < 3; j++)
219 {
220 Delta[i][j] = Particles.InvM(MeshConstraints[ElementIndex][i]) * dC3[i][j] * DLambda;
221 }
222 }
223 return Delta;
224
225
226
227 }
228
229 private:
230
231 //material constants calculated from E:
232 T SigmaMax;
233 mutable T AlphaActivation;
234 TVector<T, 3> FiberDir;
235
236 };
237
238} // End namespace Chaos::Softs
239
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition Matrix.h:21
Definition XPBDCorotatedConstraints.h:20
TArray< T > LambdaArray
Definition XPBDCorotatedConstraints.h:637
TArray< TVector< int32, 4 > > MeshConstraints
Definition XPBDCorotatedConstraints.h:654
TArray< T > Measure
Definition XPBDCorotatedConstraints.h:655
TArray< T > DmInverse
Definition XPBDCorotatedConstraints.h:638
PMatrix< T, 3, 3 > F(const int e, const ParticleType &InParticles) const
Definition XPBDCorotatedConstraints.h:230
virtual TVec4< TVector< T, 3 > > GetPolarDelta(const ParticleType &Particles, const T Dt, const int32 ElementIndex, const T Tol=(T) 1e-3) const
Definition XPBDCorotatedConstraints.h:558
PMatrix< T, 3, 3 > ElementDmInv(const int e) const
Definition XPBDCorotatedConstraints.h:234
virtual TVec4< TVector< T, 3 > > GetDeterminantDelta(const ParticleType &Particles, const T Dt, const int32 ElementIndex, const T Tol=(T) 1e-3) const
Definition XPBDCorotatedConstraints.h:494
Definition XPBDCorotatedFiberConstraints.h:17
virtual ~FXPBDCorotatedFiberConstraints()
Definition XPBDCorotatedFiberConstraints.h:41
virtual void ApplyInSerial(ParticleType &Particles, const T Dt, const int32 ElementIndex) const override
Definition XPBDCorotatedFiberConstraints.h:57
void SetTime(const float Time) const
Definition XPBDCorotatedFiberConstraints.h:47
void SetActivation(const T AlphaIn)
Definition XPBDCorotatedFiberConstraints.h:45
TVec4< TVector< T, 3 > > GetFiberGradient(const T dFpdL, const T dFadL, const T C3, const TVec4< TVector< T, 3 > > &dLdX) const
Definition XPBDCorotatedFiberConstraints.h:83
FXPBDCorotatedFiberConstraints(const ParticleType &InParticles, const TArray< TVector< int32, 4 > > &InMesh, const bool bRecordMetricIn=true, const T &EMesh=(T) 10.0, const T &NuMesh=(T).3, const TVector< T, 3 > InFiberDir=TVector< T, 3 >((T) 1.,(T) 0.,(T) 0.), const T InSigmaMax=(T) 3e5)
Definition XPBDCorotatedFiberConstraints.h:27
TVector< T, 3 > GetFiberDir()
Definition XPBDCorotatedFiberConstraints.h:43
FORCEINLINE T Size() const
Definition Vector.h:1055
Definition Vector.h:41
Definition Array.h:670
void Init(const ElementType &Element, SizeType Number)
Definition Array.h:3043
Definition CollectionEmbeddedSpringConstraintFacade.cpp:6
void PolarDecomposition(const PMatrix< T, 2, 2 > &A, GivensRotation< T > &R, PMatrix< T, 2, 2 > &S_Sym)
2x2 polar decomposition.
Definition ImplicitQRSVD.h:323