UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SoftsEvolutionLinearSystem.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
6
7namespace Chaos::Softs
8{
40
41// Assemble and solve the linear system generated by the force based solver in FEvolution.
42// Currently just supports using CG to solve the linear system generated by using newton's method with backward euler.
43// The matrix format and CG is controlled by BlockSparseLinearSystem.
45{
46public:
51 : Parameters(Other.Parameters)
52 , NumCompactIndices(Other.NumCompactIndices)
53 , CompactifiedIndices(MoveTemp(Other.CompactifiedIndices))
54 , RHS(MoveTemp(Other.RHS))
55 , Matrix(MoveTemp(Other.Matrix))
56 , bDfDxTimesVTerm(Other.bDfDxTimesVTerm)
57 {}
60 {
61 Parameters = Other.Parameters;
62 NumCompactIndices = Other.NumCompactIndices;
63 CompactifiedIndices = MoveTemp(Other.CompactifiedIndices);
64 RHS = MoveTemp(Other.RHS);
65 Matrix = MoveTemp(Other.Matrix);
66 bDfDxTimesVTerm = Other.bDfDxTimesVTerm;
67 return *this;
68 }
69
71
73
78
79 CHAOS_API void AddForce(const FSolverParticlesRange& Particles, const FSolverVec3& Force, int32 ParticleIndex, const FSolverReal Dt);
80
81 // Df1Dx2 is Derivative of F for ParticleIndex1 with respect to X of Particle2.
82 // Components of Df1Dx2 are Df1Dx2[j][i] = DF1_i / DX2_j
83 // This is consistent with UnrealMath which assumes row-major matrices and treats positions as row vectors (left multiply)
84 //
85 // We're assuming all forces are symmetric. This will add Df1Dfx2 and Df2Dfx1 = Df1Dfx2^T (and same for Df2Dv1 = Df1Dv2^T) when ParticleIndex1 != ParticleIndex2
87
88 bool Solve(FSolverParticlesRange& Particles, const FSolverReal Dt);
89
91 {
92 return LastSolveIterations;
93 }
94
96 {
97 return LastSolveError;
98 }
99
101 {
102 // we're currently just doing CG to solve the primal equations, so we need to be symmetric positive definite
103 return true;
104 }
105private:
106 void CalculateCompactIndices(const FSolverParticlesRange& Particles);
107
108 const FEvolutionLinearSystemSolverParameters* Parameters = nullptr;
109 int32 NumCompactIndices;
110 TArray<int32> CompactifiedIndices; // ParticleRangeIndex -> Dense array with kinematic points removed.
113 bool bDfDxTimesVTerm = false;
114
115 // Debug reporting
116 int32 LastSolveIterations = 0;
117 FSolverReal LastSolveError = (FSolverReal)0.;
118};
119
120} // End namespace Chaos::Softs
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
void Init()
Definition LockFreeList.h:4
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition Matrix.h:21
Definition SoftsEvolutionLinearSystem.h:45
FEvolutionLinearSystem(const FEvolutionLinearSystem &)=delete
CHAOS_API void AddSymmetricForceDerivative(const FSolverParticlesRange &Particles, const FSolverMatrix33 *const Df1Dx2, const FSolverMatrix33 *const Df1Dv2, int32 ParticleIndex1, int32 ParticleIndex2, const FSolverReal Dt)
Definition SoftsEvolutionLinearSystem.cpp:125
bool RequiresSPDForceDerivatives() const
Definition SoftsEvolutionLinearSystem.h:100
bool Solve(FSolverParticlesRange &Particles, const FSolverReal Dt)
Definition SoftsEvolutionLinearSystem.cpp:179
FEvolutionLinearSystem(FEvolutionLinearSystem &&Other)
Definition SoftsEvolutionLinearSystem.h:50
FSolverReal GetLastSolveError() const
Definition SoftsEvolutionLinearSystem.h:95
int32 GetLastSolveIterations() const
Definition SoftsEvolutionLinearSystem.h:90
FEvolutionLinearSystem & operator=(const FEvolutionLinearSystem &)=delete
FEvolutionLinearSystem & operator=(FEvolutionLinearSystem &&Other)
Definition SoftsEvolutionLinearSystem.h:59
void ReserveForParallelAdd(const int32 NumDiagonalEntries, const int32 NumOffDiagonalEntries)
Definition SoftsEvolutionLinearSystem.h:74
Definition SoftsSolverParticlesRange.h:12
Definition BlockSparseLinearSystem.h:11
void ReserveForParallelAdd(int32 NumDiagEntries, int32 NumOffDiagEntries)
Definition BlockSparseLinearSystem.cpp:165
Definition Array.h:670
Definition CollectionEmbeddedSpringConstraintFacade.cpp:6
FRealSingle FSolverReal
Definition PBDSoftsEvolutionFwd.h:31
Definition SoftsEvolutionLinearSystem.h:10
FEvolutionLinearSystemSolverParameters & operator=(FEvolutionLinearSystemSolverParameters &&)=default
int32 MaxNumCGIterations
Definition SoftsEvolutionLinearSystem.h:36
bool bCheckCGResidual
Definition SoftsEvolutionLinearSystem.h:38
static constexpr FSolverReal DefaultCGTolerance
Definition SoftsEvolutionLinearSystem.h:12
static constexpr bool bDefaultCheckCGResidual
Definition SoftsEvolutionLinearSystem.h:13
bool bDoQuasistatics
Definition SoftsEvolutionLinearSystem.h:34
FEvolutionLinearSystemSolverParameters(const FEvolutionLinearSystemSolverParameters &)=default
FEvolutionLinearSystemSolverParameters(FEvolutionLinearSystemSolverParameters &&)=default
FSolverReal CGResidualTolerance
Definition SoftsEvolutionLinearSystem.h:37
FEvolutionLinearSystemSolverParameters(bool bInDoQuasistatics, bool bInXPBDInitialGuess, int32 InMaxNumCGIterations, FSolverReal InCGResidualTolerance, bool bInCheckResidual)
Definition SoftsEvolutionLinearSystem.h:16
static constexpr int32 DefaultMaxNumCGIterations
Definition SoftsEvolutionLinearSystem.h:11
FEvolutionLinearSystemSolverParameters & operator=(const FEvolutionLinearSystemSolverParameters &)=default
bool bXPBDInitialGuess
Definition SoftsEvolutionLinearSystem.h:35