v0.16.3
Loading...
Searching...
No Matches
IncrementalOptimization.hpp
Go to the documentation of this file.
1/**
2 * @file IncrementalOptimization.hpp
3 * @brief Physics-independent incremental optimization API
4 *
5 * The orchestration in this file knows how to minimize an incremental
6 * potential whose state is obtained from a nested equilibrium solve. A
7 * concrete dissipation process supplies the control layout, conservative
8 * value and gradient, dissipation, acceptance checks, and commit operation
9 * through IncrementalOptimizationProblem.
10 */
11
12#ifndef MOFEM_INCREMENTAL_OPTIMIZATION_HPP
13#define MOFEM_INCREMENTAL_OPTIMIZATION_HPP
14
15#include <limits>
16
17namespace EshelbianPlasticity {
18
20
21/** Recoverable result of a fixed-control state solve. */
24 MoFEMErrorCode errorCode = 0;
25 double equilibriumNorm = std::numeric_limits<double>::max();
26};
27
28/** Result of one rollback-safe objective evaluation. */
31 double dissipativeValue = 0;
32 /** Null until the corresponding gradient has been requested. */
33 SmartPetscObj<Vec> smoothGradient;
34 SmartPetscObj<Vec> objectiveGradient;
35 double equilibriumNorm = std::numeric_limits<double>::max();
36 double smoothGradientNorm = std::numeric_limits<double>::max();
37 double objectiveGradientNorm = std::numeric_limits<double>::max();
39 MoFEMErrorCode stateSolveError = 0;
40 PetscInt stateSolveCount = 0;
41 /** True when the state and reduced-objective data were reused for the same
42 * control. */
43 bool cacheHit = false;
44};
45
47 std::function<MoFEMErrorCode(Vec, EquilibriumSolveReport &)>;
48
50
51/**
52 * Physics contract consumed by the generic incremental optimizer.
53 *
54 * Plasticity, cohesive fracture, and contact/friction implement this
55 * interface without adding their variables or constitutive assumptions to
56 * IncrementalOptimizationContext.
57 */
60
61 virtual std::string getName() const = 0;
62 virtual MoFEMErrorCode validate() = 0;
63
64 /** Parent DM containing every optimization-control field. */
65 virtual DM getControlDM() const = 0;
66
67 /** Create the problem's committed and candidate control vectors. */
68 virtual MoFEMErrorCode createControlData(
69 SmartPetscObj<Vec> &committed_control,
70 SmartPetscObj<Vec> &candidate_control) = 0;
71
72 /** Add physics-specific rows, columns, and elements to constraintDM. */
73 virtual MoFEMErrorCode configureConstraintDM(DM constraint_dm) = 0;
74
75 /** Set initial multipliers using constraint-DM row numbering. */
76 virtual MoFEMErrorCode
77 initialiseInequalityMultipliers(DM constraint_dm, Vec multipliers) = 0;
78
79 /** Define the zero-increment/reference point for a new load step. */
80 virtual MoFEMErrorCode initialiseReferenceControl(
81 Vec committed_control, Vec reference_control) = 0;
82
83 virtual MoFEMErrorCode solveState(Vec state,
84 EquilibriumSolveReport &report) = 0;
85 virtual MoFEMErrorCode restoreState(Vec state) = 0;
86 virtual MoFEMErrorCode evaluateConservativeValue(double &value) = 0;
87
88 /** Assemble the reduced conservative gradient. */
89 virtual MoFEMErrorCode
90 assembleConservativeGradient(Vec smooth_gradient) = 0;
91 virtual MoFEMErrorCode evaluateDissipation(Vec control, double &value) = 0;
92 virtual MoFEMErrorCode assembleObjectiveGradient(
93 Vec control, Vec smooth_gradient, Vec objective_gradient) = 0;
94 virtual MoFEMErrorCode evaluateInequalityConstraints(Vec control,
95 Vec constraints) = 0;
96 virtual MoFEMErrorCode assembleInequalityJacobian(
97 Vec control, Vec smooth_gradient, Mat jacobian) = 0;
98
99 /** Assemble a finite generalized row without a usable smooth gradient. */
100 virtual MoFEMErrorCode
102 Mat jacobian) = 0;
103
104 /** Physics-specific primal/dual checks using both DM layouts. */
105 virtual MoFEMErrorCode validateSolution(
106 DM constraint_dm, Vec control, Vec smooth_gradient,
107 Vec inequality_multipliers, PetscReal gradient_tolerance,
108 PetscReal constraint_tolerance, std::string &diagnostics) = 0;
109
110 /**
111 * Commit physics history and all next-step control vectors atomically.
112 * `solution` and `equilibrated_state` are read-only accepted inputs; a
113 * successful implementation may modify only physics history and the three
114 * control outputs.
115 */
116 virtual MoFEMErrorCode commit(Vec solution, Vec equilibrated_state,
117 Vec committed_control, Vec candidate_control,
118 Vec reference_control) = 0;
119};
120
121/**
122 * @brief Generic transaction/cache data; contains no constitutive state.
123 *
124 * Terminology used below:
125 *
126 * - **Control**: variables selected by TAO. For plasticity its tensor part is
127 * `Delta H^p`, the increment of `H^p = log(F^p)`, which is the logarithmic
128 * plastic strain in the symmetric, zero-plastic-spin model. Its scalar part
129 * is the epigraph coordinate `Delta kappa`; committed `kappa_n` remains in
130 * physics-owned mesh storage sharing the same field layout.
131 * - **Mechanical state**: equilibrium unknowns, such as displacement, solved
132 * at fixed control by the nested TS/SNES solve.
133 * - **Trial**: one control proposed by TAO and evaluated without changing
134 * committed material history.
135 * - **Rejected trial**: a trial for which the nested state solve fails or its
136 * residual exceeds `equilibriumTolerance`; its changes are discarded.
137 * - **Committed data**: the accepted rollback point and physics-owned material
138 * history; trial evaluations must not modify them.
139 * - **Rollback**: restore the accepted control and last converged mechanical
140 * state after rejecting a trial.
141 * - **Reference**: the zero-increment control at the beginning of a load step.
142 * - **Baseline**: the equilibrated state and conservative value at the
143 * reference control; the latter is subtracted to form the energy increment.
144 * - **Last valid state**: the most recent equilibrated trial state, used as the
145 * starting point for the next nested solve and as its recovery state.
146 * - **Cached evaluation**: results retained for an identical repeated control,
147 * avoiding another equilibrium solve.
148 * - **Commit**: after final validation, atomically update material history and
149 * make the accepted state the starting point of the next load step.
150 */
152 /** Physics-specific callbacks used by the generic optimiser. */
153 boost::shared_ptr<IncrementalOptimizationProblem> problem;
154
155 /** Last accepted control; source for rollback after a rejected trial. */
156 SmartPetscObj<Vec> committedControl;
157 /** Current TAO trial control, synchronized before physics evaluation. */
158 SmartPetscObj<Vec> candidateControl;
159 /** Reduced conservative gradient evaluated at candidateControl. */
160 SmartPetscObj<Vec> gradient;
161 /** Complete objective gradient, including local incremental resistance. */
162 SmartPetscObj<Vec> objectiveGradient;
163 /** Rectangular problem mapping controls to inequality constraints. */
164 SmartPetscObj<DM> constraintDM;
165 /** Values of the TAO inequalities, using the convention c_i >= 0. */
166 SmartPetscObj<Vec> inequalityConstraints;
167 /** Jacobian of the inequality map with respect to the control. */
168 SmartPetscObj<Mat> inequalityJacobian;
169
170 /** Mechanical state equilibrated for candidateControl. */
171 SmartPetscObj<Vec> equilibratedState;
172 /** Control defining zero increment at the start of the load step. */
173 SmartPetscObj<Vec> referenceControl;
174 /** Equilibrated-state snapshot corresponding to referenceControl. */
175 SmartPetscObj<Vec> baselineState;
176 /** Latest converged state, used to warm-start or restore trial solves. */
177 SmartPetscObj<Vec> lastValidState;
178 /** Control associated with cachedState and cachedEvaluation. */
179 SmartPetscObj<Vec> cachedControl;
180 /** Equilibrated state associated with cachedControl. */
181 SmartPetscObj<Vec> cachedState;
182 /** Conservative value at referenceControl, subtracted from the objective. */
184 /** Values and optional conservative gradient for cachedControl/cachedState.
185 * The complete objective gradient is a mutable TAO workspace, not cached. */
187
188 /** Fixed-control state solve callback. */
190 /** Number of nested equilibrium solves performed in this context. */
191 PetscInt stateSolveCount = 0;
192 /** Number of TAO trials rejected because equilibrium was not obtained. */
193 PetscInt rejectedTrialCount = 0;
194 /** Accumulated wall time spent in nested equilibrium solves. */
196 /** Accumulated wall time spent assembling conservative gradients. */
198 /** Maximum accepted residual norm from a nested equilibrium solve. */
199 double equilibriumTolerance = 1e-8;
200 /** Whether the reference objective value and state are initialized. */
201 bool baselineValid = false;
202 /** Whether cachedControl exactly identifies a reusable evaluation. */
203 bool cacheValid = false;
204
205 MoFEMErrorCode rollbackTrial();
206};
207
208boost::shared_ptr<IncrementalOptimizationContext>
210 boost::shared_ptr<IncrementalOptimizationProblem> problem,
211 SmartPetscObj<Vec> state);
212
213/** Equilibrate and evaluate values without assembling an adjoint. */
214MoFEMErrorCode evaluateIncrementalObjective(
215 const boost::shared_ptr<IncrementalOptimizationContext> &context,
216 Vec control, IncrementalObjectiveEvaluation &evaluation);
217
218/** Reuse the value transaction and assemble its conservative gradient. */
220 const boost::shared_ptr<IncrementalOptimizationContext> &context,
221 Vec control, IncrementalObjectiveEvaluation &evaluation);
222
223/** Objective/gradient transaction used by TAO and directional tests.
224 * A null objective_gradient requests only the objective value. */
226 const boost::shared_ptr<IncrementalOptimizationContext> &context,
227 Vec control, PetscReal &objective, Vec objective_gradient,
229
231 const boost::shared_ptr<IncrementalOptimizationContext> &context,
232 Vec control, Vec constraints);
233
234/** Assemble a constraint Jacobian from the matching objective transaction. */
236 const boost::shared_ptr<IncrementalOptimizationContext> &context,
237 Vec control, const IncrementalObjectiveEvaluation &evaluation,
238 Mat jacobian);
239
241 const boost::shared_ptr<IncrementalOptimizationContext> &context,
242 Vec control, Mat jacobian);
243
244/** Run the generic outer TAO solve and ask the problem to commit its state. */
246 const boost::shared_ptr<IncrementalOptimizationContext> &context,
247 Vec state);
248
249} // namespace EshelbianPlasticity
250
251#endif // MOFEM_INCREMENTAL_OPTIMIZATION_HPP
boost::shared_ptr< IncrementalOptimizationContext > context
boost::shared_ptr< IncrementalOptimizationContext > createIncrementalOptimizationContext(boost::shared_ptr< IncrementalOptimizationProblem > problem, SmartPetscObj< Vec > state)
std::function< MoFEMErrorCode(Vec, EquilibriumSolveReport &)> EquilibriumSolveFunction
MoFEMErrorCode solveIncrementalOptimizationTAO(const boost::shared_ptr< IncrementalOptimizationContext > &context, Vec state)
MoFEMErrorCode evaluateIncrementalObjectiveAndGradient(const boost::shared_ptr< IncrementalOptimizationContext > &context, Vec control, IncrementalObjectiveEvaluation &evaluation)
MoFEMErrorCode assembleIncrementalOptimizationInequalityJacobianFromEvaluation(const boost::shared_ptr< IncrementalOptimizationContext > &context, Vec control, const IncrementalObjectiveEvaluation &evaluation, Mat jacobian)
MoFEMErrorCode evaluateIncrementalOptimizationTAOObjectiveAndGradient(const boost::shared_ptr< IncrementalOptimizationContext > &context, Vec control, PetscReal &objective, Vec objective_gradient, IncrementalObjectiveEvaluation &evaluation)
MoFEMErrorCode evaluateIncrementalObjective(const boost::shared_ptr< IncrementalOptimizationContext > &context, Vec control, IncrementalObjectiveEvaluation &evaluation)
MoFEMErrorCode assembleIncrementalOptimizationInequalityJacobian(const boost::shared_ptr< IncrementalOptimizationContext > &context, Vec control, Mat jacobian)
MoFEMErrorCode evaluateIncrementalOptimizationInequalityConstraints(const boost::shared_ptr< IncrementalOptimizationContext > &context, Vec control, Vec constraints)
Generic transaction/cache data; contains no constitutive state.
boost::shared_ptr< IncrementalOptimizationProblem > problem
virtual MoFEMErrorCode assembleObjectiveGradient(Vec control, Vec smooth_gradient, Vec objective_gradient)=0
virtual MoFEMErrorCode commit(Vec solution, Vec equilibrated_state, Vec committed_control, Vec candidate_control, Vec reference_control)=0
virtual MoFEMErrorCode evaluateConservativeValue(double &value)=0
virtual MoFEMErrorCode initialiseReferenceControl(Vec committed_control, Vec reference_control)=0
virtual MoFEMErrorCode restoreState(Vec state)=0
virtual MoFEMErrorCode initialiseInequalityMultipliers(DM constraint_dm, Vec multipliers)=0
virtual MoFEMErrorCode evaluateDissipation(Vec control, double &value)=0
virtual MoFEMErrorCode assembleConservativeGradient(Vec smooth_gradient)=0
virtual MoFEMErrorCode configureConstraintDM(DM constraint_dm)=0
virtual MoFEMErrorCode createControlData(SmartPetscObj< Vec > &committed_control, SmartPetscObj< Vec > &candidate_control)=0
virtual MoFEMErrorCode assembleInequalityJacobianWithoutSmoothGradient(Vec control, Mat jacobian)=0
virtual MoFEMErrorCode validateSolution(DM constraint_dm, Vec control, Vec smooth_gradient, Vec inequality_multipliers, PetscReal gradient_tolerance, PetscReal constraint_tolerance, std::string &diagnostics)=0
virtual MoFEMErrorCode solveState(Vec state, EquilibriumSolveReport &report)=0
virtual MoFEMErrorCode evaluateInequalityConstraints(Vec control, Vec constraints)=0
virtual MoFEMErrorCode assembleInequalityJacobian(Vec control, Vec smooth_gradient, Mat jacobian)=0