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.
22
23namespace superdex {
24
25/**
26 * @brief [Experimental] Controls whether force-saturation terms use a fitted quadratic Hessian
27 * independently for each saturation pathway.
28 *
29 * @details For each flag, `true` selects the fitted Hessian, which is more stable. `false` selects
30 * the exact analytical Hessian, which may converge faster but is less stable.
31 *
32 * @warning This is an experimental feature. It may be changed or removed in the future. Use at
33 * your own risk.
34 *
35 * @note When a flag is `false`, the solver will try first with the true Hessian for that pathway.
36 * If a Newton attempt fails, the solver retries with fitted Hessians for all pathways and keeps
37 * them for the rest of that nonlinear solve. With the exact contact-friction or joint-friction
38 * Hessian and a line search, it also switches to them when an iteration starts with an
39 * elasto-plastic contact or joint at or past reverse presliding yield. Each solve starts from
40 * these flags.
41 */
43 /** @brief Use fitted Hessian for contact-friction saturation. */
44 bool contactFriction = true;
45 /** @brief Use fitted Hessian for joint-friction saturation. */
46 bool jointFriction = false;
47 /** @brief Use fitted Hessian for constraint saturation. */
49
50 /** @brief Construct with all three flags set to `value`. */
51 static constexpr SaturationHessianParams All(bool value);
52
53 /** @brief Returns true iff all three flags are `true`. */
54 [[nodiscard]] constexpr bool AllTrue() const;
55
56#if MOCHI_LANGUAGE_CPP20
57 bool operator==(SaturationHessianParams const&) const = default;
58#endif
59
65};
66
67/**
68 * @brief [Experimental] Evaluation settings common to the full scene.
69 *
70 * @details They tune the evaluation of internal models (contact, constraints, etc).
71 *
72 * @warning This is an experimental feature. It may be changed or removed in the future. Use at
73 * your own risk.
74 */
76 /**
77 * @brief Use explicit normals (from stage-start kinematics) for the evaluation of friction.
78 *
79 * @details Whether to treat the colliding and collider normals explicitly (using stage-start
80 * kinematics) or implicitly (using current kinematics) for the evaluation of alignment and the
81 * friction plane.
82 *
83 * @note The SDF gradient for the normal collision force is always implicit.
84 * @note explicitNormals = true and implicitNormalForceForDissipation = false produces contact
85 * residuals that are the exact gradients of the contact merit. This improves convergence
86 * guarantees of the Newton solve, but may be less stable due to the explicit treatment.
87 * @note A differentiable scene requires explicitNormals = true.
88 */
89 bool explicitNormals = false;
90
91 /**
92 * @brief Fade friction coefficient based on normal alignment.
93 *
94 * @details When enabled, friction is scaled by (c - alignment) / (c + 1), where "alignment" is
95 * defined as the dot product between colliding and collider normals, and c is the alignment at
96 * which contact is disabled: @ref ContactParams::maxAlignmentNormals, or the top of its smoothing
97 * band (see @ref ContactParams::alignmentSmoothingFraction).
98 *
99 * @note For co-dimensional colliding actors with ambiguous normals, friction fading is disabled
100 * regardless of fadeFriction (normal alignment cannot be computed).
101 * @note fadeFriction = true adds a non-integrable term to the residual unless @ref
102 * explicitNormals = true.
103 *
104 * @see ContactParams::maxAlignmentNormals
105 */
106 bool fadeFriction = true;
107
108 /**
109 * @brief Treat the normal contact force implicitly (if true) or explicitly (if false) for
110 * dissipative contact terms.
111 *
112 * @note Implicit treatment improves stability (especially with high-order time integrators) but
113 * the resulting dissipative force is not integrable, hence it cannot be derived from an objective
114 * function. Merit-based line searches therefore count its work along each step instead of an
115 * energy (see @ref LineSearchType), and its force dresidual is non-symmetric (a symmetric
116 * approximation is used). With implicitNormalForceForDissipation = false, the distance used for
117 * the explicit normal force is approximate with @ref explicitNormals = false, but accurate with
118 * @ref explicitNormals = true.
119 * @note Dissipative contact terms include Coulomb friction, viscous friction, and normal viscous
120 * damping. Using an implicit normal force for normal damping can improve the accuracy of the
121 * effective coefficient of restitution at a given time step size.
122 * @note A differentiable scene requires implicitNormalForceForDissipation = false.
123 */
125
126 /**
127 * @brief Controls whether force-saturation terms use a fitted quadratic Hessian (more stable) or
128 * the exact analytical Hessian (faster convergence but less stable), independently for each
129 * saturation pathway.
130 *
131 * @note For any flag set to false, the solver will try first with the true Hessian. See
132 * @ref SaturationHessianParams for when it switches to fitted Hessians.
133 */
135
136 /**
137 * @brief Validate that the residual is the gradient of the objective by a directional
138 * finite-difference consistency check.
139 *
140 * @note This operation is expensive and should only be used for debugging.
141 */
142 bool consistencyResNorm = false;
143
144 /**
145 * @brief Step size for finite-difference consistency check.
146 */
148
149#if MOCHI_LANGUAGE_CPP20
150 bool operator==(ExperimentalEvalParams const&) const = default;
151#endif
152
161};
162
163} // namespace superdex
164
165#include "eval_params_inl.h"
#define MOCHI_STRUCT_END()
Definition reflection.h:333
#define MOCHI_FIELD(name)
Definition reflection.h:351
#define MOCHI_STRUCT_BEGIN(name)
Definition reflection.h:332
[Experimental] Evaluation settings common to the full scene.
Definition eval_params.h:75
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:89
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:42
bool jointFriction
Use fitted Hessian for joint-friction saturation.
Definition eval_params.h:46
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:44
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:48