UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
BlendedXPBDCorotatedConstraints.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
5#include "ChaosStats.h"
10
11
12namespace Chaos::Softs
13{
14 template <typename T, typename ParticleType>
16 {
17
21 using Base::Measure;
22 using Base::DmInverse;
23 using Base::Lambda;
25
26 public:
27 //this one only accepts tetmesh input and mesh
29 const ParticleType& InParticles,
31 const bool bRecordMetricIn = true,
32 const T& EMesh = (T)10.0,
33 const T& NuMesh = (T).3,
34 const T& InZeta = (T)1.
35 )
37 {
38 if (Zeta < (T)0.)
39 {
40 Zeta = (T)0.;
41 }
42 if (Zeta > (T)1.)
43 {
44 Zeta = (T)1.;
45 }
46
47 C1Contribution.Init(TVec4<TVector<T, 3>>(TVector<T, 3>((T)0.)), InMesh.Num());
48 C2Contribution.Init(TVec4<TVector<T, 3>>(TVector<T, 3>((T)0.)), InMesh.Num());
49 }
50
51 //this one only accepts tetmesh input and mesh
53 const ParticleType& InParticles,
55 const TArray<T>& EMeshArray,
56 const T& NuMesh = (T).3,
57 const bool bRecordMetricIn = false,
58 const T& InZeta = (T)1.
59 )
61 {
62 if (Zeta < (T)0.)
63 {
64 Zeta = (T)0.;
65 }
66 if (Zeta > (T)1.)
67 {
68 Zeta = (T)1.;
69 }
70
71 C1Contribution.Init(TVec4<TVector<T, 3>>(TVector<T, 3>((T)0.)), InMesh.Num());
72 C2Contribution.Init(TVec4<TVector<T, 3>>(TVector<T, 3>((T)0.)), InMesh.Num());
73 }
74
76
77
78 virtual void ApplyInSerial(ParticleType& Particles, const T Dt, const int32 ElementIndex) const override
79 {
80 TVec4<TVector<T, 3>> PolarDelta = GetPolarDelta(Particles, Dt, ElementIndex);
81
82 for (int i = 0; i < 4; i++)
83 {
84 Particles.P(MeshConstraints[ElementIndex][i]) += PolarDelta[i];
85 }
86
87 TVec4<TVector<T, 3>> DetDelta = GetDeterminantDelta(Particles, Dt, ElementIndex);
88
89 for (int i = 0; i < 4; i++)
90 {
91 Particles.P(MeshConstraints[ElementIndex][i]) += DetDelta[i];
92 }
93 }
94
95 virtual void Init() const override
96 {
97 for (T& Lambdas : LambdaArray) { Lambdas = (T)0.; }
98 C1Contribution.Init(TVec4<TVector<T, 3>>(TVector<T, 3>((T)0.)), MeshConstraints.Num());
99 C2Contribution.Init(TVec4<TVector<T, 3>>(TVector<T, 3>((T)0.)), MeshConstraints.Num());
100 }
101
102 protected:
103
104 virtual TVec4<TVector<T, 3>> GetDeterminantDelta(const ParticleType& Particles, const T Dt, const int32 ElementIndex, const T Tol = (T)1e-3) const override
105 {
107
108 const PMatrix<T, 3, 3> Fe = Base::F(ElementIndex, Particles);
109 PMatrix<T, 3, 3> DmInvT = Base::ElementDmInv(ElementIndex).GetTransposed();
110
111 T J = Fe.Determinant();
112 if (J - (T)1. < Tol)
113 {
114 return TVec4<TVector<T, 3>>(TVector<T, 3>((T)0.));
115 }
116
118
119 T AlphaTilde = (T)2. / (Dt * Dt * Base::Lambda * Measure[ElementIndex]);
120
121 T DLambda = (1 - J) - AlphaTilde * LambdaArray[2 * ElementIndex + 1];
122
123 T Denom = AlphaTilde;
124 for (int i = 0; i < 4; i++)
125 {
126 for (int j = 0; j < 3; j++)
127 {
128 Denom += dC2[i][j] * Particles.InvM(MeshConstraints[ElementIndex][i]) * dC2[i][j];
129 }
130 }
131 DLambda /= Denom;
132 LambdaArray[2 * ElementIndex + 1] += DLambda;
134 for (int i = 0; i < 4; i++)
135 {
136 for (int j = 0; j < 3; j++)
137 {
138 Delta2[i][j] = Particles.InvM(MeshConstraints[ElementIndex][i]) * dC2[i][j] * DLambda;
139 }
140 }
142 for (int i = 0; i < 4; i++)
143 {
144 for (int j = 0; j < 3; j++)
145 {
146 Delta1[i][j] = Particles.InvM(MeshConstraints[ElementIndex][i])
147 * dC2[i][j] * LambdaArray[2 * ElementIndex + 1] - C2Contribution[ElementIndex][i][j];
148 }
149 }
151 for (int i = 0; i < 4; i++)
152 {
153 Delta[i] = Zeta * Delta1[i] + ((T)1. - Zeta) * Delta2[i];
154 }
155
156 for (int i = 0; i < 4; i++)
157 {
158 C2Contribution[ElementIndex][i] += Delta[i];
159 }
160
161 return Delta;
162 }
163
164
165
166 virtual TVec4<TVector<T, 3>> GetPolarDelta(const ParticleType& Particles, const T Dt, const int32 ElementIndex, const T Tol = (T)1e-3) const override
167 {
170 const PMatrix<T, 3, 3> Fe = Base::F(ElementIndex, Particles);
171
172 PMatrix<T, 3, 3> Re((T)0.), Se((T)0.);
173
175
176 T C1 = (T)0.;
177 for (int i = 0; i < 3; i++)
178 {
179 for (int j = 0; j < 3; j++)
180 {
181 C1 += FMath::Square((Fe - Re).GetAt(i, j));
182 }
183 }
184 C1 = FMath::Sqrt(C1);
185
186 if (C1 < Tol)
187 {
188 return TVec4<TVector<T, 3>>(TVector<T, 3>((T)0.));
189 }
190
191 PMatrix<T, 3, 3> DmInvT = Base::ElementDmInv(ElementIndex).GetTransposed();
192
194
195 T AlphaTilde = (T)1. / (Dt * Dt * Base::Mu * Measure[ElementIndex]);
196
197 T DLambda = -C1 - AlphaTilde * LambdaArray[2 * ElementIndex + 0];
198
199 T Denom = AlphaTilde;
200 for (int i = 0; i < 4; i++)
201 {
202 for (int j = 0; j < 3; j++)
203 {
204 Denom += dC1[i][j] * Particles.InvM(MeshConstraints[ElementIndex][i]) * dC1[i][j];
205 }
206 }
207 DLambda /= Denom;
208 LambdaArray[2 * ElementIndex + 0] += DLambda;
209
211 for (int i = 0; i < 4; i++)
212 {
213 for (int j = 0; j < 3; j++)
214 {
215 Delta2[i][j] = Particles.InvM(MeshConstraints[ElementIndex][i]) * dC1[i][j] * DLambda;
216 }
217 }
219 for (int i = 0; i < 4; i++)
220 {
221 for (int j = 0; j < 3; j++)
222 {
223 Delta1[i][j] = Particles.InvM(MeshConstraints[ElementIndex][i])
224 * dC1[i][j] * LambdaArray[2 * ElementIndex + 0] - C1Contribution[ElementIndex][i][j];
225 }
226 }
228 for (int i = 0; i < 4; i++)
229 {
230 Delta[i] = Zeta * Delta1[i] + ((T)1. - Zeta) * Delta2[i];
231 }
232
233 for (int i = 0; i < 4; i++)
234 {
235 C1Contribution[ElementIndex][i] += Delta[i];
236 }
237
238 return Delta;
239
240 }
241
242
243 private:
244
245 T Zeta;
246 mutable TArray<TVec4<TVector<T, 3>>> C1Contribution;
247 mutable TArray<TVec4<TVector<T, 3>>> C2Contribution;
248 };
249
250} // End namespace Chaos::Softs
251
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define SCOPE_CYCLE_COUNTER(Stat)
Definition Stats.h:650
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define TRACE_CPUPROFILER_EVENT_SCOPE(Name)
Definition CpuProfilerTrace.h:528
Definition Matrix.h:21
Definition BlendedXPBDCorotatedConstraints.h:16
virtual TVec4< TVector< T, 3 > > GetDeterminantDelta(const ParticleType &Particles, const T Dt, const int32 ElementIndex, const T Tol=(T) 1e-3) const override
Definition BlendedXPBDCorotatedConstraints.h:104
FBlendedXPBDCorotatedConstraints(const ParticleType &InParticles, const TArray< TVector< int32, 4 > > &InMesh, const TArray< T > &EMeshArray, const T &NuMesh=(T).3, const bool bRecordMetricIn=false, const T &InZeta=(T) 1.)
Definition BlendedXPBDCorotatedConstraints.h:52
virtual ~FBlendedXPBDCorotatedConstraints()
Definition BlendedXPBDCorotatedConstraints.h:75
FBlendedXPBDCorotatedConstraints(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 T &InZeta=(T) 1.)
Definition BlendedXPBDCorotatedConstraints.h:28
virtual void Init() const override
Definition BlendedXPBDCorotatedConstraints.h:95
virtual TVec4< TVector< T, 3 > > GetPolarDelta(const ParticleType &Particles, const T Dt, const int32 ElementIndex, const T Tol=(T) 1e-3) const override
Definition BlendedXPBDCorotatedConstraints.h:166
virtual void ApplyInSerial(ParticleType &Particles, const T Dt, const int32 ElementIndex) const override
Definition BlendedXPBDCorotatedConstraints.h:78
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
T Lambda
Definition XPBDCorotatedConstraints.h:645
TArray< T > DmInverse
Definition XPBDCorotatedConstraints.h:638
PMatrix< T, 3, 3 > F(const int e, const ParticleType &InParticles) const
Definition XPBDCorotatedConstraints.h:230
TVec4< TVector< T, 3 > > GetDeterminantGradient(const PMatrix< T, 3, 3 > &Fe, const PMatrix< T, 3, 3 > &DmInvT) const
Definition XPBDCorotatedConstraints.h:373
PMatrix< T, 3, 3 > ElementDmInv(const int e) const
Definition XPBDCorotatedConstraints.h:234
TVec4< TVector< T, 3 > > GetPolarGradient(const PMatrix< T, 3, 3 > &Fe, const PMatrix< T, 3, 3 > &Re, const PMatrix< T, 3, 3 > &DmInvT, const T C1) const
Definition XPBDCorotatedConstraints.h:341
T Mu
Definition XPBDCorotatedConstraints.h:644
bool bRecordMetric
Definition XPBDCorotatedConstraints.h:651
Definition Vector.h:41
int32 Num() const
Definition Vector.h:150
Definition Array.h:670
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
static constexpr UE_FORCEINLINE_HINT T Square(const T A)
Definition UnrealMathUtility.h:578