SuperDex Physics C++ API
Loading...
Searching...
No Matches
eval_params.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19// PLEASE DO NOT ADD OTHER INCLUDES HERE. This header is included in the mochi_physics public API.
23
24namespace superdex {
25
26/**
27 * @brief [Experimental] Controls whether force-saturation terms use a fitted quadratic Hessian
28 * independently for each saturation pathway.
29 *
30 * @details For each flag, `true` selects the fitted Hessian, which is more stable. `false` selects
31 * the exact analytical Hessian, which may converge faster but is less stable.
32 *
33 * @warning This is an experimental feature. It may be changed or removed in the future. Use at
34 * your own risk.
35 *
36 * @note When a flag is `false`, the solver will try first with the true Hessian for that pathway.
37 * If the Newton iteration fails to improve, all flags are set to `true` and the iteration is
38 * retried with fitted Hessians for all pathways.
39 */
41 /** @brief Use fitted Hessian for contact-friction saturation. */
42 bool contactFriction = true;
43 /** @brief Use fitted Hessian for joint-friction saturation. */
44 bool jointFriction = false;
45 /** @brief Use fitted Hessian for constraint saturation. */
47
48 /** @brief Construct with all three flags set to `value`. */
49 static constexpr SaturationHessianParams All(bool value);
50
51 /** @brief Returns true iff all three flags are `true`. */
52 [[nodiscard]] constexpr bool AllTrue() const;
53
54#if MOCHI_LANGUAGE_CPP20
55 bool operator==(SaturationHessianParams const&) const = default;
56#endif
57
63};
64
65/**
66 * @brief [Experimental] Evaluation settings common to the full scene.
67 *
68 * @details They tune the evaluation of internal models (contact, constraints, etc).
69 *
70 * @warning This is an experimental feature. It may be changed or removed in the future. Use at
71 * your own risk.
72 */
74 /**
75 * @brief Use explicit normals (from stage-start kinematics) for the evaluation of friction.
76 *
77 * @details Whether to treat the colliding and collider normals explicitly (using stage-start
78 * kinematics) or implicitly (using current kinematics) for the evaluation of alignment and the
79 * friction plane.
80 *
81 * @note The SDF gradient for the normal collision force is always implicit.
82 * @note explicitNormals = true and implicitNormalForceForDissipation = false produces contact
83 * residuals that are the exact gradients of the contact merit. This improves convergence
84 * guarantees of the Newton solve, but may be less stable due to the explicit treatment.
85 * @note A differentiable scene requires explicitNormals = true.
86 */
87 bool explicitNormals = false;
88
89 /**
90 * @brief Fade friction coefficient based on normal alignment.
91 *
92 * @details When enabled, friction is scaled by (maxAlignmentNormals - alignment) /
93 * (maxAlignmentNormals + 1), where "alignment" is defined as the dot product between colliding
94 * and collider normals.
95 *
96 * @note For co-dimensional colliding actors with ambiguous normals, friction fading is disabled
97 * regardless of fadeFriction (normal alignment cannot be computed).
98 * @note fadeFriction = true adds a non-integrable term to the residual unless @ref
99 * explicitNormals = true.
100 *
101 * @see ContactParams::maxAlignmentNormals
102 */
103 bool fadeFriction = true;
104
105 /**
106 * @brief Treat the normal contact force implicitly (if true) or explicitly (if false) for
107 * dissipative contact terms.
108 *
109 * @note Implicit treatment improves stability (especially with high-order time integrators) but
110 * the resulting dissipative force is not integrable, hence it cannot be derived from an
111 * objective function. This (a) may hurt convergence with an objective-based line search, and (b)
112 * makes the force dresidual non-symmetric (a symmetric approximation is used). With
113 * implicitNormalForceForDissipation = false, the distance used for the explicit normal force is
114 * approximate with @ref explicitNormals = false, but accurate with explicitNormals = true.
115 * @note Dissipative contact terms include Coulomb friction, viscous friction, and normal viscous
116 * damping. Using an implicit normal force for normal damping can improve the accuracy of the
117 * effective coefficient of restitution at a given time step size.
118 */
120
121 /**
122 * @brief Controls whether force-saturation terms use a fitted quadratic Hessian (more stable) or
123 * the exact analytical Hessian (faster convergence but less stable), independently for each
124 * saturation pathway.
125 *
126 * @note For any flag set to false, the solver will try first with the true Hessian. If it fails,
127 * it will retry with the fitted Hessian.
128 */
130
131 /**
132 * @brief Selects which Coulomb friction smoothing model to use.
133 *
134 * @details C1Regularized (default) preserves existing behavior exactly. CinfRegularized is an
135 * additional model that can be selected at runtime without affecting C1Regularized users.
136 */
138
139 /**
140 * @brief Validate that the residual is the gradient of the objective by a directional
141 * finite-difference consistency check.
142 *
143 * @note This operation is expensive and should only be used for debugging.
144 */
145 bool consistencyResNorm = false;
146
147 /**
148 * @brief Step size for finite-difference consistency check.
149 */
151
152#if MOCHI_LANGUAGE_CPP20
153 bool operator==(ExperimentalEvalParams const&) const = default;
154#endif
155
165};
166
167} // namespace superdex
168
169#include "eval_params_inl.h"
CoulombFrictionModel
Selects which Coulomb friction smoothing model to use.
@ Default
Default Coulomb friction model.
#define MOCHI_STRUCT_END()
Definition reflection.h:279
#define MOCHI_FIELD(name)
Definition reflection.h:293
#define MOCHI_STRUCT_BEGIN(name)
Definition reflection.h:278
[Experimental] Evaluation settings common to the full scene.
Definition eval_params.h:73
CoulombFrictionModel frictionModel
Selects which Coulomb friction smoothing model to use.
bool implicitNormalForceForDissipation
Treat the normal contact force implicitly (if true) or explicitly (if false) for dissipative contact ...
bool fadeFriction
Fade friction coefficient based on normal alignment.
SaturationHessianParams fittedSaturationHessian
Controls whether force-saturation terms use a fitted quadratic Hessian (more stable) or the exact ana...
bool explicitNormals
Use explicit normals (from stage-start kinematics) for the evaluation of friction.
Definition eval_params.h:87
real consistencyResNormStep
Step size for finite-difference consistency check.
bool operator==(ExperimentalEvalParams const &) const =default
bool consistencyResNorm
Validate that the residual is the gradient of the objective by a directional finite-difference consis...
[Experimental] Controls whether force-saturation terms use a fitted quadratic Hessian independently f...
Definition eval_params.h:40
bool jointFriction
Use fitted Hessian for joint-friction saturation.
Definition eval_params.h:44
bool operator==(SaturationHessianParams const &) const =default
constexpr bool AllTrue() const
Returns true iff all three flags are true.
bool contactFriction
Use fitted Hessian for contact-friction saturation.
Definition eval_params.h:42
static constexpr SaturationHessianParams All(bool value)
Construct with all three flags set to value.
bool constraintSaturation
Use fitted Hessian for constraint saturation.
Definition eval_params.h:46