22 "taontr taobntr taobncg taonls taobnls taobqnktr taontl taobntl taolmvm " 23 "taoblmvm taonm taobqnls taoowlqn taogpcg taobmrm taoalmm");
25 "tao_solver", tao_solver_enum,
"Tao solver to use for optimization.");
35 "solve_on", exec_enum,
"List of flags indicating when inner system solve should occur.");
37 "output_optimization_iterations",
39 "Use the time step as the current iteration for outputting optimization history.");
45 _my_comm(MPI_COMM_SELF),
47 _verbose(getParam<bool>(
"verbose")),
48 _output_opt_iters(getParam<bool>(
"output_optimization_iterations")),
53 mooseError(
"OptimizeSolve does not currently support threaded execution");
57 "moose", 27225,
"Outputting for transient executioners has not been implemented.");
63 TIME_SECTION(
"optimizeSolve", 1,
"Optimization Solve");
69 mooseError(
"No OptimizationReporter object found.");
91 #if PETSC_RELEASE_LESS_THAN(3, 21, 0) 147 #if !PETSC_VERSION_LESS_THAN(3, 15, 0) 151 #if PETSC_RELEASE_GREATER_EQUALS(3, 21, 0) 159 mooseError(
"ALMM is only compatible with PETSc versions above 3.14. ");
167 #if !PETSC_VERSION_LESS_THAN(3, 17, 0) 172 #if !PETSC_VERSION_LESS_THAN(3, 17, 0) 183 #if !PETSC_VERSION_LESS_THAN(3, 17, 0) 190 #if !PETSC_VERSION_LESS_THAN(3, 17, 0) 219 if (getParam<bool>(
"verbose"))
234 std::vector<double> & gnorm,
235 std::vector<int> & obj_iters,
236 std::vector<double> & cnorm,
237 std::vector<int> & grad_iters,
238 std::vector<double> & xdiff,
239 std::vector<int> & hess_iters,
240 std::vector<double> &
f,
241 std::vector<int> & tot_solves)
const 244 tot_iters.resize(num);
245 obj_iters.resize(num);
246 grad_iters.resize(num);
247 hess_iters.resize(num);
248 tot_solves.resize(num);
292 if (
auto steady = dynamic_cast<Steady *>(sub_app->getExecutioner(0)))
293 steady->setIterationNumberOutput((
unsigned int)its);
306 _console <<
"TAO SOLVER: iteration=" << its <<
"\tf=" <<
f <<
"\tgnorm=" << gnorm
307 <<
"\tcnorm=" << cnorm <<
"\txdiff=" << xdiff << std::endl;
313 TaoConvergedReason reason;
315 PetscReal
f, gnorm, cnorm, xdiff;
318 LibmeshPetscCallQ(TaoGetSolutionStatus(tao, &its, &
f, &gnorm, &cnorm, &xdiff, &reason));
333 solver->_parameters->swap(param);
335 (*objective) = solver->objectiveFunction();
336 solver->_parameters->swap(param);
342 Tao , Vec
x, Real * objective, Vec gradient,
void * ctx)
348 solver->_parameters->swap(param);
350 (*objective) = solver->objectiveFunction();
352 solver->gradientFunction(
grad);
353 solver->_parameters->swap(param);
359 Tao , Vec , Mat , Mat ,
void * ctx)
380 return solver->applyHessian(sbar, Hsbar);
396 TIME_SECTION(
"objectiveFunction", 2,
"Objective forward solve");
419 TIME_SECTION(
"gradientFunction", 2,
"Gradient adjoint solve");
438 TIME_SECTION(
"applyHessian", 2,
"Hessian forward/adjoint solve");
444 mooseError(
"Hessian based optimization algorithms require a sub-app with:\n" 445 " execute_on = HOMOGENEOUS_FORWARD");
452 mooseError(
"Homogeneous forward solve multiapp failed!");
506 Tao , Vec , Mat gradient_e, Mat ,
void * ctx)
534 Tao , Vec , Mat gradient_i, Mat ,
void * ctx)
virtual bool solve() override
Moose::PetscSupport::PetscOptions & getPetscOptions()
virtual void setMisfitToSimulatedValues()
Function to override misfit values with the simulated values from the matrix free hessian forward sol...
T & getUserObject(const std::string &name, unsigned int tid=0) const
Moose::PetscSupport::PetscOptions _petsc_options
virtual void computeInequalityConstraints(libMesh::PetscVector< Number > &ineqs_constraints) const
Function to compute the inequality constraints.
static InputParameters validParams()
Mat _gradient_e
Equality constraint gradient.
Real getLowerBound(dof_id_type i) const
const libMesh::Parallel::Communicator _my_comm
Communicator used for operations.
const ExecFlagType EXEC_NONE
Tao _tao
Tao optimization object.
static PetscErrorCode inequalityFunctionWrapper(Tao tao, Vec x, Vec ci, void *ctx)
FEProblemBase & feProblem()
dof_id_type getNumEqCons() const
Function to get the total number of equalities.
PetscErrorCode taoSolve()
Here is where we call tao and solve.
const ExecFlagType EXEC_HOMOGENEOUS_FORWARD
const ExecFlagType EXEC_FORWARD
PetscErrorCode taoALDestroy()
Used for destroying petsc structures when using the ALMM algorithm.
Vec _ce
Equality constraint vector.
Vec _ci
Inequality constraint vector.
ExecuteMooseObjectWarehouse< MultiApp > & getMultiAppWarehouse()
virtual void computeEqualityGradient(libMesh::PetscMatrix< Number > &gradient) const
Function to compute the gradient of the equality constraints/ This is the last call of the equality c...
bool hasUserObject(const std::string &name) const
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
Mat _gradient_i
Inequality constraint gradient.
std::vector< int > _hess_iterate_vec
Hessian solves per iteration.
static PetscErrorCode applyHessianWrapper(Mat H, Vec s, Vec Hs)
virtual dof_id_type getNumParams() const
Function to get the total number of parameters.
static PetscErrorCode variableBoundsWrapper(Tao, Vec xl, Vec xu, void *ctx)
static PetscErrorCode objectiveAndGradientFunctionWrapper(Tao tao, Vec x, Real *objective, Vec gradient, void *ctx)
OptimizeSolve(Executioner &ex)
Base class for optimization objects, implements routines for calculating misfit.
bool _verbose
control optimization executioner output
void setInitialCondition(libMesh::PetscVector< Number > ¶m)
Function to initialize petsc vectors from vpp data.
void mooseDocumentedError(const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
void getTaoSolutionStatus(std::vector< int > &tot_iters, std::vector< double > &gnorm, std::vector< int > &obj_iters, std::vector< double > &cnorm, std::vector< int > &grad_iters, std::vector< double > &xdiff, std::vector< int > &hess_iters, std::vector< double > &f, std::vector< int > &tot_solves) const
Record tao TaoGetSolutionStatus data for output by a reporter.
virtual void execute(const ExecFlagType &exec_type)
const std::vector< std::shared_ptr< MultiApp > > & getObjects(THREAD_ID tid=0) const
virtual PetscErrorCode applyHessian(libMesh::PetscVector< Number > &s, libMesh::PetscVector< Number > &Hs)
Hessian application routine.
const std::vector< double > x
Real f(Real x)
Test function for Brents method.
std::unique_ptr< libMesh::PetscVector< Number > > _parameters
Parameters (solution) given to TAO.
SolveObject * _inner_solve
const ExecFlagEnum & _solve_on
List of execute flags for when to solve the system.
OptimizationReporterBase * _obj_function
objective function defining objective, gradient, and hessian
virtual Real computeObjective()=0
Function to compute objective.
static PetscErrorCode monitor(Tao tao, void *ctx)
bool isValueSet(const std::string &value) const
void petscSetOptions(const PetscOptions &po, const SolverParams &solver_params, FEProblemBase *const problem=nullptr)
Executioner * getExecutioner() const
void backupMultiApps(ExecFlagType type)
virtual int & timeStep() const
std::vector< int > _grad_iterate_vec
gradient solves per iteration
std::string grad(const std::string &var)
std::vector< double > _f_vec
objective value per iteration
static PetscErrorCode inequalityGradientFunctionWrapper(Tao tao, Vec x, Mat gradient_i, Mat gradient_ipre, void *ctx)
const ExecFlagType EXEC_ADJOINT
TaoSolverEnum
Enum of tao solver types.
std::vector< int > _function_solve_vec
total solves per iteration
LibmeshPetscCallQ(DMShellGetContext(dm, &ctx))
virtual void set(const numeric_index_type i, const T value) override
virtual void computeInequalityGradient(libMesh::PetscMatrix< Number > &gradient) const
Function to compute the gradient of the inequality constraints/ This is the last call of the inequali...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Mat _hessian
Hessian (matrix) - usually a matrix-free representation.
virtual void computeGradient(libMesh::PetscVector< Number > &gradient) const
Function to compute gradient.
void restoreMultiApps(ExecFlagType type, bool force=false)
std::vector< double > _cnorm_vec
infeasibility norm per iteration
static PetscErrorCode equalityGradientFunctionWrapper(Tao tao, Vec x, Mat gradient_e, Mat gradient_epre, void *ctx)
IntRange< T > make_range(T beg, T end)
class infix_ostream_iterator if void
virtual void updateParameters(const libMesh::PetscVector< Number > &x)
Function to set parameters.
void mooseError(Args &&... args) const
SolverParams & solverParams(unsigned int solver_sys_num=0)
std::vector< double > _xdiff_vec
step length per iteration
std::vector< double > _gnorm_vec
gradient norm per iteration
enum OptimizeSolve::TaoSolverEnum _tao_solver_enum
const ConsoleStream _console
std::vector< int > _total_iterate_vec
total solves per iteration
bool execMultiApps(ExecFlagType type, bool auto_advance=true)
virtual bool isTransient() const override
bool hasMultiApps() const
Real getUpperBound(dof_id_type i) const
Upper and lower bounds for each parameter being controlled.
static PetscErrorCode hessianFunctionWrapper(Tao tao, Vec x, Mat hessian, Mat pc, void *ctx)
PetscFunctionReturn(LIBMESH_PETSC_SUCCESS)
SolverParams _solver_params
bool _output_opt_iters
Use time step as the iteration counter for purposes of outputting.
virtual void gradientFunction(libMesh::PetscVector< Number > &gradient)
Gradient routine.
virtual void computeEqualityConstraints(libMesh::PetscVector< Number > &eqs_constraints) const
Function to compute the equality constraints.
static PetscErrorCode equalityFunctionWrapper(Tao tao, Vec x, Vec ce, void *ctx)
solveObject to interface with Petsc Tao
PetscErrorCode taoALCreate()
Used for creating petsc structures when using the ALMM algorithm.
std::vector< int > _obj_iterate_vec
number of objective solves per iteration
void setTaoSolutionStatus(double f, int its, double gnorm, double cnorm, double xdiff)
output optimization iteration solve data
virtual Real objectiveFunction()
Objective routine.
virtual void outputStep(ExecFlagType type)
virtual PetscErrorCode variableBounds(Tao tao)
Bounds routine.
dof_id_type getNumInEqCons() const
Function to get the total number of inequalities.
static PetscErrorCode objectiveFunctionWrapper(Tao tao, Vec x, Real *objective, void *ctx)
dof_id_type _ndof
Number of parameters being optimized.