p.Chaos.Cloth.MaxItCG
p.Chaos.Cloth.MaxItCG
#Overview
name: p.Chaos.Cloth.MaxItCG
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Max iter for CG [def: 50]
It is referenced in 8
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.Chaos.Cloth.MaxItCG is to control the maximum number of iterations for the Conjugate Gradient (CG) method used in cloth simulation within Unreal Engine’s Chaos physics system.
This setting variable is primarily used in the Chaos physics system, specifically in the cloth simulation module. It’s part of the Experimental Chaos runtime in Unreal Engine 5.
The value of this variable is set using an FAutoConsoleVariableRef, which allows it to be modified at runtime through the console. It’s initialized with a default value of 50.
The associated variable MaxItCG interacts directly with p.Chaos.Cloth.MaxItCG. They share the same value, with MaxItCG being the actual variable used in the code.
Developers should be aware that this variable affects the performance and accuracy of cloth simulations. A higher value may lead to more accurate results but at the cost of increased computation time.
Best practices when using this variable include:
- Balancing between performance and accuracy based on the specific needs of the game or application.
- Testing different values to find the optimal setting for your specific use case.
- Considering adjusting this value dynamically based on the scene complexity or performance requirements.
Regarding the associated variable MaxItCG:
The purpose of MaxItCG is to directly control the maximum number of iterations in the Conjugate Gradient solver used in various physics calculations, particularly in cloth simulation.
It’s used in multiple places within the Chaos physics system, including the GaussSeidelMainConstraint and PoissonSolve functions.
The value of MaxItCG is set by the console variable p.Chaos.Cloth.MaxItCG, allowing for runtime adjustments.
MaxItCG interacts with other variables like CGTol (Conjugate Gradient Tolerance) in the solver algorithms.
Developers should be aware that MaxItCG directly impacts the balance between simulation accuracy and performance. A higher value may provide more accurate results but increase computation time.
Best practices for using MaxItCG include:
- Adjusting it in tandem with CGTol for optimal solver performance.
- Profiling the performance impact of different MaxItCG values in your specific scenarios.
- Consider exposing this setting to technical artists or providing presets for different quality/performance targets.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Deformable/GaussSeidelMainConstraint.cpp:6
Scope (from outer to inner):
file
namespace Chaos::Softs
Source code excerpt:
int32 MaxItCG = 50;
FAutoConsoleVariableRef CVarClothMaxItCG(TEXT("p.Chaos.Cloth.MaxItCG"), MaxItCG, TEXT("Max iter for CG [def: 50]"));
FSolverReal CGTol = 1e-4f;
FAutoConsoleVariableRef CVarClothCGTol(TEXT("p.Chaos.Cloth.CGTol"), MaxItCG, TEXT("CG Tolerance [def: 1e-4]"));
template <typename T, typename ParticleType>
#Associated Variable and Callsites
This variable is associated with another variable named MaxItCG
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Deformable/GaussSeidelMainConstraint.cpp:1
Scope (from outer to inner):
file
namespace Chaos::Softs
Source code excerpt:
#include "Chaos/Deformable/GaussSeidelMainConstraint.h"
#include "Chaos/Math/Krylov.h"
namespace Chaos::Softs
{
int32 MaxItCG = 50;
FAutoConsoleVariableRef CVarClothMaxItCG(TEXT("p.Chaos.Cloth.MaxItCG"), MaxItCG, TEXT("Max iter for CG [def: 50]"));
FSolverReal CGTol = 1e-4f;
FAutoConsoleVariableRef CVarClothCGTol(TEXT("p.Chaos.Cloth.CGTol"), MaxItCG, TEXT("CG Tolerance [def: 1e-4]"));
template <typename T, typename ParticleType>
void FGaussSeidelMainConstraint<T, ParticleType>::AddStaticConstraints(const TArray<TArray<int32>>& ExtraConstraints, TArray<TArray<int32>>& ExtraIncidentElements, TArray<TArray<int32>>& ExtraIncidentElementsLocal)
{
if (!IsClean(ExtraConstraints, ExtraIncidentElements, ExtraIncidentElementsLocal))
{
ExtraIncidentElements = Chaos::Utilities::ComputeIncidentElements(ExtraConstraints, &ExtraIncidentElementsLocal);
}
int32 Offset = StaticConstraints.Num();
StaticConstraints += ExtraConstraints;
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Deformable/GaussSeidelMainConstraint.cpp:176
Scope (from outer to inner):
file
namespace Chaos::Softs
function void FGaussSeidelMainConstraint<T, ParticleType>::ApplyCG
Source code excerpt:
y[i] = FSolverVec3(0.f);
}
}
};
int32 max_it_cg = MaxItCG;
FSolverReal cg_tol = CGTol;
int32 MaxNewtonIt = 1;
for (int32 It = 0; It < MaxNewtonIt; It++)
{
const TArray<FSolverVec3> Residual = ComputeNewtonResiduals(Particles, Dt, false, nullptr);
auto multiply = [this, &ProjectBCs, &Dt, &Particles](TArray<FSolverVec3>& y, const TArray<FSolverVec3>& x)
{
TArray<FSolverVec3> XProj = x;
ProjectBCs(XProj);
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Deformable/GaussSeidelMainConstraint.cpp:208
Scope (from outer to inner):
file
namespace Chaos::Softs
function void FGaussSeidelMainConstraint<T, ParticleType>::ApplyCG
Source code excerpt:
};
TArray<FSolverVec3> Deltax;
Deltax.Init(FSolverVec3(0.f), Particles.Size());
Chaos::LanczosCG<FSolverReal>(multiply, Deltax, Residual, MaxItCG, CGTol, use_list.Get());
PhysicsParallelFor(Particles.Size(), [&Particles, &Deltax](const int32 i)
{
Particles.P(i) -= Deltax[i];
});
}
}
}
template class Chaos::Softs::FGaussSeidelMainConstraint<Chaos::Softs::FSolverReal, Chaos::Softs::FSolverParticles>;
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Public/Chaos/Math/Poisson.h:255
Scope (from outer to inner):
file
namespace Chaos
function void PoissonSolve
Source code excerpt:
template <class T, class TV, class TV_INT = FIntVector4, int d = 3>
void PoissonSolve(const TArray<int32>& InConstrainedNodes,
const TArray<T>& ConstrainedWeights,
const TArray<TV_INT>& Mesh,
const TArray<TV>& X,
const int32 MaxItCG,
const T CGTol,
TArray<T>& Weights)
{
TArray<T> De_inverse;
TArray<T> measure;
ComputeDeInverseAndElementMeasures(Mesh, X, De_inverse, measure);
TArray<TArray<int32>> IncidentElementsLocalIndex;
TArray<TArray<int32>> IncidentElements = Chaos::Utilities::ComputeIncidentElements<4>(Mesh, &IncidentElementsLocalIndex);
auto ProjectBCs = [&InConstrainedNodes] (TArray<T>& U)
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Public/Chaos/Math/Poisson.h:301
Scope (from outer to inner):
file
namespace Chaos
function void PoissonSolve
Source code excerpt:
MinusResidual.Init((T)0., Weights.Num());
MultiplyLaplacian(MinusResidual, InitialGuess);
TArray<T> MinusDw;
MinusDw.Init((T)0., Weights.Num());
Chaos::LanczosCG(MultiplyLaplacian, MinusDw, MinusResidual, MaxItCG, CGTol, false);
for (int32 i = 0; i < InitialGuess.Num(); i++)
{
Weights[i] = InitialGuess[i] - MinusDw[i];
}
}
template <class T, class TV_INT=FIntVector4, int d=3>
void
Laplacian(
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Public/Chaos/Math/Poisson.h:603
Scope (from outer to inner):
file
namespace Chaos
function void PoissonSolve
Source code excerpt:
// InConstrainedNodes is a list of flattened index nodes that are boundary conditions. ConstrainedWeights is a parallel array of the constrained values.
template<class TV, class T, bool NodalValues = false>
void PoissonSolve(const TArray<int32>& InConstrainedNodes,
const TArray<TV>& ConstrainedWeights,
const TUniformGrid<T, 3>& UniformGrid,
const int32 MaxItCG,
const TV CGTol,
TArray<TV>& Weights,
bool bCheckResidual = false,
int32 MinParallelBatchSize = 1000)
{
auto ProjectBCs = [&InConstrainedNodes](TArray<TV>& U)
{
for (int32 i = 0; i < InConstrainedNodes.Num(); i++)
{
U[InConstrainedNodes[i]] = (T)0.;
}
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Public/Chaos/Math/Poisson.h:640
Scope (from outer to inner):
file
namespace Chaos
function void PoissonSolve
Source code excerpt:
MinusResidual.Init((TV)0., Weights.Num());
MultiplyLaplacian(MinusResidual, InitialGuess);
TArray<TV> MinusDw;
MinusDw.Init((TV)0., Weights.Num());
Chaos::LanczosCG(MultiplyLaplacian, MinusDw, MinusResidual, MaxItCG, CGTol, bCheckResidual, MinParallelBatchSize);
for (int32 i = 0; i < InitialGuess.Num(); i++)
{
Weights[i] = InitialGuess[i] - MinusDw[i];
}
}
} // namespace Chaos