libMesh
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
libMesh::TaoOptimizationSolver< T > Class Template Reference

This class provides an interface to the Tao optimization solvers. More...

#include <tao_optimization_solver.h>

Inheritance diagram for libMesh::TaoOptimizationSolver< T >:
[legend]

Public Types

typedef OptimizationSystem sys_type
 The type of system that we use in conjunction with this solver. More...
 

Public Member Functions

 TaoOptimizationSolver (sys_type &system)
 Constructor. More...
 
 ~TaoOptimizationSolver ()
 Destructor. More...
 
virtual void clear () libmesh_override
 Release all memory and clear data structures. More...
 
virtual void init () libmesh_override
 Initialize data structures if not done so already. More...
 
Tao tao ()
 
virtual void solve () libmesh_override
 Call the Tao solver. More...
 
virtual void get_dual_variables () libmesh_override
 Get the current values of dual variables associated with inequality and equality constraints. More...
 
virtual void print_converged_reason () libmesh_override
 Prints a useful message about why the latest optimization solve con(di)verged. More...
 
virtual int get_converged_reason () libmesh_override
 
bool initialized () const
 
const sys_typesystem () const
 
sys_typesystem ()
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static UniquePtr< OptimizationSolver< T > > build (sys_type &s, const SolverPackage solver_package=libMesh::default_solver_package())
 Builds an OptimizationSolver using the package specified by solver_package. More...
 
static std::string get_info ()
 Gets a string containing the reference information. More...
 
static void print_info (std::ostream &out=libMesh::out)
 Prints the reference information, by default to libMesh::out. More...
 
static unsigned int n_objects ()
 Prints the number of outstanding (created, but not yet destroyed) objects. More...
 
static void enable_print_counter_info ()
 Methods to enable/disable the reference counter output from print_info() More...
 
static void disable_print_counter_info ()
 

Public Attributes

OptimizationSystem::ComputeObjectiveobjective_object
 Object that computes the objective function f(X) at the input iterate X. More...
 
OptimizationSystem::ComputeGradientgradient_object
 Object that computes the gradient grad_f(X) of the objective function at the input iterate X. More...
 
OptimizationSystem::ComputeHessianhessian_object
 Object that computes the Hessian H_f(X) of the objective function at the input iterate X. More...
 
OptimizationSystem::ComputeEqualityConstraintsequality_constraints_object
 Object that computes the equality constraints vector C_eq(X). More...
 
OptimizationSystem::ComputeEqualityConstraintsJacobianequality_constraints_jacobian_object
 Object that computes the Jacobian of C_eq(X). More...
 
OptimizationSystem::ComputeInequalityConstraintsinequality_constraints_object
 Object that computes the inequality constraints vector C_ineq(X). More...
 
OptimizationSystem::ComputeInequalityConstraintsJacobianinequality_constraints_jacobian_object
 Object that computes the Jacobian of C_ineq(X). More...
 
OptimizationSystem::ComputeLowerAndUpperBoundslower_and_upper_bounds_object
 Object that computes the lower and upper bounds vectors. More...
 
unsigned int max_objective_function_evaluations
 Maximum number of objective function evaluations allowed. More...
 
Real objective_function_relative_tolerance
 Required change in objective function which signals convergence. More...
 
bool verbose
 Control how much is output from the OptimizationSolver as it's running. More...
 

Protected Types

typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 Data structure to log the information. More...
 

Protected Member Functions

void increment_constructor_count (const std::string &name)
 Increments the construction counter. More...
 
void increment_destructor_count (const std::string &name)
 Increments the destruction counter. More...
 

Protected Attributes

Tao _tao
 Optimization solver context. More...
 
TaoConvergedReason _reason
 Store the reason for Tao convergence/divergence for use even after _tao has been cleared. More...
 
sys_type_system
 A reference to the system we are solving. More...
 
bool _is_initialized
 Flag indicating if the data structures have been initialized. More...
 
const Parallel::Communicator_communicator
 

Static Protected Attributes

static Counts _counts
 Actually holds the data. More...
 
static Threads::atomic< unsigned int_n_objects
 The number of objects. More...
 
static Threads::spin_mutex _mutex
 Mutual exclusion object to enable thread-safe reference counting. More...
 
static bool _enable_print_counter = true
 Flag to control whether reference count information is printed when print_info is called. More...
 

Friends

PetscErrorCode __libmesh_tao_objective (Tao tao, Vec x, PetscReal *objective, void *ctx)
 
PetscErrorCode __libmesh_tao_gradient (Tao tao, Vec x, Vec g, void *ctx)
 
PetscErrorCode __libmesh_tao_hessian (Tao tao, Vec x, Mat h, Mat pc, void *ctx)
 
PetscErrorCode __libmesh_tao_equality_constraints (Tao tao, Vec x, Vec ce, void *ctx)
 
PetscErrorCode __libmesh_tao_equality_constraints_jacobian (Tao tao, Vec x, Mat J, Mat Jpre, void *ctx)
 
PetscErrorCode __libmesh_tao_inequality_constraints (Tao tao, Vec x, Vec cineq, void *ctx)
 
PetscErrorCode __libmesh_tao_inequality_constraints_jacobian (Tao tao, Vec x, Mat J, Mat Jpre, void *ctx)
 

Detailed Description

template<typename T>
class libMesh::TaoOptimizationSolver< T >

This class provides an interface to the Tao optimization solvers.

Author
David Knezevic
Date
2015

Definition at line 58 of file tao_optimization_solver.h.

Member Typedef Documentation

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > libMesh::ReferenceCounter::Counts
protectedinherited

Data structure to log the information.

The log is identified by the class name.

Definition at line 119 of file reference_counter.h.

template<typename T>
typedef OptimizationSystem libMesh::TaoOptimizationSolver< T >::sys_type

The type of system that we use in conjunction with this solver.

Definition at line 65 of file tao_optimization_solver.h.

Constructor & Destructor Documentation

template<typename T >
libMesh::TaoOptimizationSolver< T >::TaoOptimizationSolver ( sys_type system)
explicit

Constructor.

Initializes Tao data structures.

Definition at line 401 of file tao_optimization_solver.C.

401  :
402  OptimizationSolver<T>(system_in),
403  _reason(TAO_CONVERGED_USER) // Arbitrary initial value...
404 {
405 }
TaoConvergedReason _reason
Store the reason for Tao convergence/divergence for use even after _tao has been cleared.
template<typename T >
libMesh::TaoOptimizationSolver< T >::~TaoOptimizationSolver ( )

Destructor.

Definition at line 410 of file tao_optimization_solver.C.

References libMesh::TaoOptimizationSolver< T >::clear().

411 {
412  this->clear ();
413 }
virtual void clear() libmesh_override
Release all memory and clear data structures.

Member Function Documentation

template<typename T >
UniquePtr< OptimizationSolver< T > > libMesh::OptimizationSolver< T >::build ( sys_type s,
const SolverPackage  solver_package = libMesh::default_solver_package() 
)
staticinherited

Builds an OptimizationSolver using the package specified by solver_package.

Definition at line 62 of file optimization_solver.C.

References libMesh::libmesh_ignore(), libMesh::NLOPT_SOLVERS, and libMesh::PETSC_SOLVERS.

63 {
64  // Prevent unused variables warnings when Tao is not available
65  libmesh_ignore(s);
66 
67  // Build the appropriate solver
68  switch (solver_package)
69  {
70 
71 #if defined(LIBMESH_HAVE_PETSC_TAO) && !defined(LIBMESH_USE_COMPLEX_NUMBERS)
72  case PETSC_SOLVERS:
73  return UniquePtr<OptimizationSolver<T>>(new TaoOptimizationSolver<T>(s));
74 #endif // #if defined(LIBMESH_HAVE_PETSC_TAO) && !defined(LIBMESH_USE_COMPLEX_NUMBERS)
75 
76 #if defined(LIBMESH_HAVE_NLOPT) && !defined(LIBMESH_USE_COMPLEX_NUMBERS)
77  case NLOPT_SOLVERS:
78  return UniquePtr<OptimizationSolver<T>>(new NloptOptimizationSolver<T>(s));
79 #endif // #if defined(LIBMESH_HAVE_NLOPT) && !defined(LIBMESH_USE_COMPLEX_NUMBERS)
80 
81  default:
82  libmesh_error_msg("ERROR: Unrecognized solver package: " << solver_package);
83  }
84 
85  libmesh_error_msg("We'll never get here!");
86  return UniquePtr<OptimizationSolver<T>>();
87 }
void libmesh_ignore(const T &)
template<typename T >
void libMesh::TaoOptimizationSolver< T >::clear ( )
virtual

Release all memory and clear data structures.

Reimplemented from libMesh::OptimizationSolver< T >.

Definition at line 418 of file tao_optimization_solver.C.

References libMesh::OptimizationSolver< T >::_is_initialized, libMesh::TaoOptimizationSolver< T >::_tao, ierr, and libMesh::OptimizationSolver< T >::initialized().

Referenced by libMesh::TaoOptimizationSolver< T >::~TaoOptimizationSolver().

419 {
420  if (this->initialized())
421  {
422  this->_is_initialized = false;
423 
424  PetscErrorCode ierr=0;
425 
426  ierr = TaoDestroy(&_tao);
427  LIBMESH_CHKERR(ierr);
428  }
429 }
bool _is_initialized
Flag indicating if the data structures have been initialized.
Tao _tao
Optimization solver context.
PetscErrorCode ierr
const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inherited
Returns
A reference to the Parallel::Communicator object used by this mesh.

Definition at line 87 of file parallel_object.h.

References libMesh::ParallelObject::_communicator.

Referenced by libMesh::__libmesh_petsc_diff_solver_monitor(), libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::__libmesh_petsc_preconditioner_apply(), libMesh::__libmesh_petsc_snes_jacobian(), libMesh::__libmesh_petsc_snes_postcheck(), libMesh::__libmesh_petsc_snes_residual(), libMesh::__libmesh_tao_equality_constraints(), libMesh::__libmesh_tao_equality_constraints_jacobian(), libMesh::__libmesh_tao_gradient(), libMesh::__libmesh_tao_hessian(), libMesh::__libmesh_tao_inequality_constraints(), libMesh::__libmesh_tao_inequality_constraints_jacobian(), libMesh::__libmesh_tao_objective(), libMesh::MeshRefinement::_coarsen_elements(), libMesh::ExactSolution::_compute_error(), libMesh::ParmetisPartitioner::_do_repartition(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult_add(), libMesh::EquationSystems::_read_impl(), libMesh::MeshRefinement::_refine_elements(), libMesh::MeshRefinement::_smooth_flags(), add_cube_convex_hull_to_mesh(), libMesh::TransientRBConstruction::add_IC_to_RB_space(), libMesh::ImplicitSystem::add_matrix(), libMesh::RBConstruction::add_scaled_matrix_and_vector(), libMesh::System::add_vector(), libMesh::EigenSparseLinearSolver< T >::adjoint_solve(), libMesh::UnstructuredMesh::all_second_order(), libMesh::MeshTools::Modification::all_tri(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::TransientRBConstruction::allocate_data_structures(), libMesh::RBConstruction::allocate_data_structures(), libMesh::TransientRBConstruction::assemble_affine_expansion(), libMesh::FEMSystem::assemble_qoi(), libMesh::MeshCommunication::assign_global_indices(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::DofMap::attach_matrix(), libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort(), libMesh::Parallel::Sort< KeyType, IdxType >::binsort(), libMesh::MeshCommunication::broadcast(), libMesh::SparseMatrix< T >::build(), libMesh::MeshTools::Generation::build_extrusion(), libMesh::Parallel::Histogram< KeyType, IdxType >::build_histogram(), libMesh::PetscNonlinearSolver< T >::build_mat_null_space(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::MeshBase::cache_elem_dims(), libMesh::System::calculate_norm(), libMesh::DofMap::check_dirichlet_bcid_consistency(), libMesh::Parallel::Sort< KeyType, IdxType >::communicate_bins(), libMesh::RBConstruction::compute_Fq_representor_innerprods(), libMesh::RBConstruction::compute_max_error_bound(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::RBConstruction::compute_output_dual_innerprods(), libMesh::RBSCMConstruction::compute_SCM_bounds_on_training_set(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::MeshTools::create_bounding_box(), libMesh::MeshTools::create_nodal_bounding_box(), libMesh::MeshRefinement::create_parent_error_vector(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::MeshTools::create_subdomain_bounding_box(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), DMlibMeshFunction(), DMlibMeshJacobian(), DMlibMeshSetSystem_libMesh(), DMVariableBounds_libMesh(), libMesh::MeshRefinement::eliminate_unrefined_patches(), libMesh::RBEIMConstruction::enrich_RB_space(), libMesh::TransientRBConstruction::enrich_RB_space(), libMesh::RBConstruction::enrich_RB_space(), AssembleOptimization::equality_constraints(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::RBEIMConstruction::evaluate_mesh_function(), libMesh::MeshRefinement::flag_elements_by_elem_fraction(), libMesh::MeshRefinement::flag_elements_by_error_fraction(), libMesh::MeshRefinement::flag_elements_by_nelem_target(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::MeshfreeInterpolation::gather_remote_data(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::DofMap::get_info(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::EquationSystems::get_solution(), AssembleOptimization::inequality_constraints(), AssembleOptimization::inequality_constraints_jacobian(), libMesh::LocationMap< T >::init(), libMesh::TopologyMap::init(), libMesh::PetscDiffSolver::init(), libMesh::TimeSolver::init(), libMesh::TaoOptimizationSolver< T >::init(), libMesh::PetscNonlinearSolver< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::EigenSystem::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::ParmetisPartitioner::initialize(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), libMesh::RBEIMConstruction::initialize_rb_construction(), integrate_function(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_flags(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_p_levels(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::MeshTools::libmesh_assert_valid_unique_ids(), libMesh::MeshRefinement::limit_level_mismatch_at_edge(), libMesh::MeshRefinement::limit_level_mismatch_at_node(), libMesh::MeshRefinement::limit_overrefined_boundary(), libMesh::MeshRefinement::limit_underrefined_boundary(), main(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshCommunication::make_elems_parallel_consistent(), libMesh::MeshRefinement::make_flags_parallel_consistent(), libMesh::MeshCommunication::make_new_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_new_nodes_parallel_consistent(), libMesh::MeshCommunication::make_node_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_unique_ids_parallel_consistent(), libMesh::MeshCommunication::make_nodes_parallel_consistent(), libMesh::MeshCommunication::make_p_levels_parallel_consistent(), libMesh::MeshRefinement::make_refinement_compatible(), libMesh::TransientRBConstruction::mass_matrix_scaled_matvec(), libMesh::FEMSystem::mesh_position_set(), libMesh::MeshSerializer::MeshSerializer(), LinearElasticityWithContact::move_mesh(), libMesh::DistributedMesh::n_active_elem(), libMesh::MeshTools::n_active_levels(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::CondensedEigenSystem::n_global_non_condensed_dofs(), libMesh::MeshTools::n_levels(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::MeshTools::n_p_levels(), libMesh::BoundaryInfo::n_shellface_conds(), new_function_base(), libMesh::DistributedMesh::parallel_max_elem_id(), libMesh::DistributedMesh::parallel_max_node_id(), libMesh::ReplicatedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_n_elem(), libMesh::DistributedMesh::parallel_n_nodes(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::MeshTools::paranoid_n_levels(), libMesh::Partitioner::partition(), libMesh::MetisPartitioner::partition_range(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::MeshBase::prepare_for_use(), libMesh::SparseMatrix< T >::print(), FEMParameters::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), libMesh::RBConstruction::read_riesz_representors_from_files(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::MeshBase::recalculate_n_partitions(), libMesh::MeshCommunication::redistribute(), libMesh::MeshRefinement::refine_and_coarsen_elements(), libMesh::DistributedMesh::renumber_dof_objects(), LinearElasticityWithContact::residual_and_jacobian(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::TransientRBConstruction::set_error_temporal_data(), libMesh::RBEIMConstruction::set_explicit_sys_subvector(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Partitioner::set_parent_processor_ids(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), libMesh::MeshBase::subdomain_ids(), libMesh::BoundaryInfo::sync(), libMesh::Parallel::sync_element_data_by_parent_id(), libMesh::Parallel::sync_node_data_by_element_id(), libMesh::MeshRefinement::test_level_one(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), libMesh::MeshRefinement::test_unflagged(), PointLocatorTest::testLocator(), BoundaryInfoTest::testMesh(), SystemsTest::testProjectCubeWithMeshFunction(), libMesh::MeshTools::total_weight(), libMesh::MeshFunctionSolutionTransfer::transfer(), libMesh::MeshfreeSolutionTransfer::transfer(), libMesh::TransientRBConstruction::truth_assembly(), libMesh::RBConstruction::truth_assembly(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::TransientRBConstruction::update_RB_initial_condition_all_N(), libMesh::RBEIMConstruction::update_RB_system_matrices(), libMesh::TransientRBConstruction::update_RB_system_matrices(), libMesh::RBConstruction::update_RB_system_matrices(), libMesh::TransientRBConstruction::update_residual_terms(), libMesh::RBConstruction::update_residual_terms(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::RBEvaluation::write_out_vectors(), libMesh::TransientRBConstruction::write_riesz_representors_to_files(), libMesh::RBConstruction::write_riesz_representors_to_files(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::RBDataSerialization::RBEvaluationSerialization::write_to_file(), libMesh::RBDataSerialization::TransientRBEvaluationSerialization::write_to_file(), libMesh::RBDataSerialization::RBEIMEvaluationSerialization::write_to_file(), and libMesh::RBDataSerialization::RBSCMEvaluationSerialization::write_to_file().

88  { return _communicator; }
const Parallel::Communicator & _communicator
void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

Definition at line 107 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

Referenced by libMesh::LibMeshInit::LibMeshInit(), and libMesh::ReferenceCounter::n_objects().

108 {
109  _enable_print_counter = false;
110  return;
111 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...
void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

Methods to enable/disable the reference counter output from print_info()

Definition at line 101 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

Referenced by libMesh::ReferenceCounter::n_objects().

102 {
103  _enable_print_counter = true;
104  return;
105 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...
template<typename T >
int libMesh::TaoOptimizationSolver< T >::get_converged_reason ( )
virtual
Returns
The currently-available (or most recently obtained, if the Tao object has been destroyed) convergence reason.

Refer to Tao docs for the meaning of different TaoConvergedReason.

Reimplemented from libMesh::OptimizationSolver< T >.

Definition at line 623 of file tao_optimization_solver.C.

References libMesh::TaoOptimizationSolver< T >::_reason, libMesh::TaoOptimizationSolver< T >::_tao, ierr, and libMesh::OptimizationSolver< T >::initialized().

Referenced by libMesh::TaoOptimizationSolver< T >::print_converged_reason(), and libMesh::TaoOptimizationSolver< T >::tao().

624 {
625  PetscErrorCode ierr=0;
626 
627  if (this->initialized())
628  {
629  ierr = TaoGetConvergedReason(_tao, &_reason);
630  LIBMESH_CHKERR(ierr);
631  }
632 
633  return static_cast<int>(_reason);
634 }
Tao _tao
Optimization solver context.
TaoConvergedReason _reason
Store the reason for Tao convergence/divergence for use even after _tao has been cleared.
PetscErrorCode ierr
template<typename T >
void libMesh::TaoOptimizationSolver< T >::get_dual_variables ( )
virtual

Get the current values of dual variables associated with inequality and equality constraints.

The variables will be stored in _system.lambda_eq and _system.lambda_ineq.

Reimplemented from libMesh::OptimizationSolver< T >.

Definition at line 593 of file tao_optimization_solver.C.

References libMesh::TaoOptimizationSolver< T >::_tao, ierr, libMesh::OptimizationSystem::lambda_eq, libMesh::OptimizationSystem::lambda_ineq, and libMesh::OptimizationSolver< T >::system().

Referenced by libMesh::TaoOptimizationSolver< T >::tao().

594 {
595  LOG_SCOPE("get_dual_variables()", "TaoOptimizationSolver");
596 
597  PetscVector<T> * lambda_eq_petsc =
598  cast_ptr<PetscVector<T> *>(this->system().lambda_eq.get());
599  PetscVector<T> * lambda_ineq_petsc =
600  cast_ptr<PetscVector<T> *>(this->system().lambda_ineq.get());
601 
602  Vec lambda_eq_petsc_vec = lambda_eq_petsc->vec();
603  Vec lambda_ineq_petsc_vec = lambda_ineq_petsc->vec();
604 
605  PetscErrorCode ierr = 0;
606  ierr = TaoGetDualVariables(_tao,
607  &lambda_eq_petsc_vec,
608  &lambda_ineq_petsc_vec);
609  LIBMESH_CHKERR(ierr);
610 }
UniquePtr< NumericVector< Number > > lambda_ineq
const sys_type & system() const
UniquePtr< NumericVector< Number > > lambda_eq
Vectors to store the dual variables associated with equality and inequality constraints.
Tao _tao
Optimization solver context.
PetscErrorCode ierr
std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

Definition at line 47 of file reference_counter.C.

References libMesh::ReferenceCounter::_counts, and libMesh::Quality::name().

Referenced by libMesh::ReferenceCounter::print_info().

48 {
49 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
50 
51  std::ostringstream oss;
52 
53  oss << '\n'
54  << " ---------------------------------------------------------------------------- \n"
55  << "| Reference count information |\n"
56  << " ---------------------------------------------------------------------------- \n";
57 
58  for (Counts::iterator it = _counts.begin();
59  it != _counts.end(); ++it)
60  {
61  const std::string name(it->first);
62  const unsigned int creations = it->second.first;
63  const unsigned int destructions = it->second.second;
64 
65  oss << "| " << name << " reference count information:\n"
66  << "| Creations: " << creations << '\n'
67  << "| Destructions: " << destructions << '\n';
68  }
69 
70  oss << " ---------------------------------------------------------------------------- \n";
71 
72  return oss.str();
73 
74 #else
75 
76  return "";
77 
78 #endif
79 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
static Counts _counts
Actually holds the data.
void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
protectedinherited

Increments the construction counter.

Should be called in the constructor of any derived class that will be reference counted.

Definition at line 185 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCounter::n_objects(), and libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

186 {
187  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
188  std::pair<unsigned int, unsigned int> & p = _counts[name];
189 
190  p.first++;
191 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition: threads.C:29
static Counts _counts
Actually holds the data.
void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
protectedinherited

Increments the destruction counter.

Should be called in the destructor of any derived class that will be reference counted.

Definition at line 198 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCounter::n_objects(), and libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

199 {
200  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
201  std::pair<unsigned int, unsigned int> & p = _counts[name];
202 
203  p.second++;
204 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition: threads.C:29
static Counts _counts
Actually holds the data.
template<typename T >
void libMesh::TaoOptimizationSolver< T >::init ( )
virtual

Initialize data structures if not done so already.

Implements libMesh::OptimizationSolver< T >.

Definition at line 434 of file tao_optimization_solver.C.

References libMesh::OptimizationSolver< T >::_is_initialized, libMesh::TaoOptimizationSolver< T >::_tao, libMesh::ParallelObject::comm(), ierr, and libMesh::OptimizationSolver< T >::initialized().

Referenced by libMesh::TaoOptimizationSolver< T >::solve(), and libMesh::TaoOptimizationSolver< T >::tao().

435 {
436  // Initialize the data structures if not done so already.
437  if (!this->initialized())
438  {
439  this->_is_initialized = true;
440 
441  PetscErrorCode ierr=0;
442 
443  ierr = TaoCreate(this->comm().get(),&_tao);
444  LIBMESH_CHKERR(ierr);
445  }
446 }
bool _is_initialized
Flag indicating if the data structures have been initialized.
Tao _tao
Optimization solver context.
PetscErrorCode ierr
const Parallel::Communicator & comm() const
template<typename T >
bool libMesh::OptimizationSolver< T >::initialized ( ) const
inherited
static unsigned int libMesh::ReferenceCounter::n_objects ( )
staticinherited
processor_id_type libMesh::ParallelObject::n_processors ( ) const
inherited
Returns
The number of processors in the group.

Definition at line 93 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::size().

Referenced by libMesh::ParmetisPartitioner::_do_repartition(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::DistributedMesh::add_elem(), libMesh::DistributedMesh::add_node(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::AztecLinearSolver< T >::AztecLinearSolver(), libMesh::MeshCommunication::broadcast(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::DistributedMesh::clear(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::UnstructuredMesh::create_pid_mesh(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DistributedMesh::DistributedMesh(), libMesh::EnsightIO::EnsightIO(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::MeshBase::get_info(), libMesh::EquationSystems::get_solution(), libMesh::SystemSubsetBySubdomain::init(), libMesh::ParmetisPartitioner::initialize(), libMesh::Nemesis_IO_Helper::initialize(), libMesh::DistributedMesh::insert_elem(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::DofMap::local_variable_indices(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshBase::n_active_elem_on_proc(), libMesh::MeshBase::n_elem_on_proc(), libMesh::MeshBase::n_nodes_on_proc(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::Partitioner::partition(), libMesh::MeshBase::partition(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::PetscLinearSolver< T >::PetscLinearSolver(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::SparseMatrix< T >::print(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::CheckpointIO::read_connectivity(), libMesh::XdrIO::read_header(), libMesh::CheckpointIO::read_nodes(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::Partitioner::repartition(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), WriteVecAndScalar::testWrite(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().

94  { return cast_int<processor_id_type>(_communicator.size()); }
unsigned int size() const
Definition: parallel.h:726
const Parallel::Communicator & _communicator
template<typename T >
void libMesh::TaoOptimizationSolver< T >::print_converged_reason ( )
virtual

Prints a useful message about why the latest optimization solve con(di)verged.

Reimplemented from libMesh::OptimizationSolver< T >.

Definition at line 614 of file tao_optimization_solver.C.

References libMesh::TaoOptimizationSolver< T >::get_converged_reason(), and libMesh::out.

Referenced by libMesh::TaoOptimizationSolver< T >::tao().

615 {
616  libMesh::out << "Tao optimization solver convergence/divergence reason: "
617  << TaoConvergedReasons[this->get_converged_reason()] << std::endl;
618 }
virtual int get_converged_reason() libmesh_override
OStreamProxy out
void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out)
staticinherited

Prints the reference information, by default to libMesh::out.

Definition at line 88 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter, and libMesh::ReferenceCounter::get_info().

Referenced by libMesh::LibMeshInit::LibMeshInit().

89 {
91  out_stream << ReferenceCounter::get_info();
92 }
static std::string get_info()
Gets a string containing the reference information.
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...
processor_id_type libMesh::ParallelObject::processor_id ( ) const
inherited
Returns
The rank of this processor in the group.

Definition at line 99 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::rank().

Referenced by libMesh::BoundaryInfo::_find_id_maps(), libMesh::EquationSystems::_read_impl(), libMesh::DistributedMesh::add_elem(), libMesh::BoundaryInfo::add_elements(), libMesh::DofMap::add_neighbors_to_send_list(), libMesh::DistributedMesh::add_node(), libMesh::MeshRefinement::add_node(), libMesh::MeshTools::Modification::all_tri(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::MeshCommunication::broadcast(), libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::Nemesis_IO_Helper::build_element_and_node_maps(), libMesh::ParmetisPartitioner::build_graph(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::DofMap::build_sparsity(), libMesh::DistributedMesh::clear(), libMesh::ExodusII_IO_Helper::close(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::compute_communication_map_parameters(), libMesh::Nemesis_IO_Helper::compute_internal_and_border_elems_and_internal_nodes(), libMesh::RBConstruction::compute_max_error_bound(), libMesh::Nemesis_IO_Helper::compute_node_communication_maps(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::ExodusII_IO_Helper::create(), libMesh::DistributedMesh::delete_elem(), libMesh::DistributedMesh::delete_node(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DistributedMesh::DistributedMesh(), libMesh::EnsightIO::EnsightIO(), libMesh::RBEIMConstruction::evaluate_mesh_function(), libMesh::MeshFunction::find_element(), libMesh::MeshFunction::find_elements(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::Nemesis_IO_Helper::get_cmap_params(), libMesh::Nemesis_IO_Helper::get_eb_info_global(), libMesh::Nemesis_IO_Helper::get_elem_cmap(), libMesh::Nemesis_IO_Helper::get_elem_map(), libMesh::MeshBase::get_info(), libMesh::DofMap::get_info(), libMesh::Nemesis_IO_Helper::get_init_global(), libMesh::Nemesis_IO_Helper::get_init_info(), libMesh::Nemesis_IO_Helper::get_loadbal_param(), libMesh::Nemesis_IO_Helper::get_node_cmap(), libMesh::Nemesis_IO_Helper::get_node_map(), libMesh::Nemesis_IO_Helper::get_ns_param_global(), libMesh::EquationSystems::get_solution(), libMesh::Nemesis_IO_Helper::get_ss_param_global(), libMesh::SparsityPattern::Build::handle_vi_vj(), libMesh::SystemSubsetBySubdomain::init(), HeatSystem::init_data(), libMesh::ParmetisPartitioner::initialize(), libMesh::ExodusII_IO_Helper::initialize(), libMesh::ExodusII_IO_Helper::initialize_element_variables(), libMesh::ExodusII_IO_Helper::initialize_global_variables(), libMesh::ExodusII_IO_Helper::initialize_nodal_variables(), libMesh::DistributedMesh::insert_elem(), libMesh::DofMap::is_evaluable(), libMesh::SparsityPattern::Build::join(), libMesh::TransientRBEvaluation::legacy_write_offline_data_to_files(), libMesh::RBEIMEvaluation::legacy_write_offline_data_to_files(), libMesh::RBEvaluation::legacy_write_offline_data_to_files(), libMesh::RBSCMEvaluation::legacy_write_offline_data_to_files(), libMesh::RBEIMEvaluation::legacy_write_out_interpolation_points_elem(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DofMap::local_variable_indices(), main(), libMesh::MeshRefinement::make_coarsening_compatible(), AugmentSparsityOnInterface::mesh_reinit(), libMesh::MeshBase::n_active_local_elem(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::System::n_local_dofs(), libMesh::MeshBase::n_local_elem(), libMesh::MeshBase::n_local_nodes(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::BoundaryInfo::n_shellface_conds(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::MetisPartitioner::partition_range(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::SparseMatrix< T >::print(), libMesh::NumericVector< T >::print_global(), libMesh::Nemesis_IO_Helper::put_cmap_params(), libMesh::Nemesis_IO_Helper::put_elem_cmap(), libMesh::Nemesis_IO_Helper::put_elem_map(), libMesh::Nemesis_IO_Helper::put_loadbal_param(), libMesh::Nemesis_IO_Helper::put_node_cmap(), libMesh::Nemesis_IO_Helper::put_node_map(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::ExodusII_IO_Helper::read_elem_num_map(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::ExodusII_IO_Helper::read_node_num_map(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), libMesh::RBConstruction::read_riesz_representors_from_files(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::LaplaceMeshSmoother::smooth(), DefaultCouplingTest::testCoupling(), PointNeighborCouplingTest::testCoupling(), BoundaryInfoTest::testShellFaceConstraints(), WriteVecAndScalar::testWrite(), libMesh::MeshTools::total_weight(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::Parallel::Packing< Node * >::unpack(), libMesh::Parallel::Packing< Elem * >::unpack(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::DTKAdapter::update_variable_values(), libMesh::MeshTools::weight(), libMesh::NameBasedIO::write(), libMesh::CheckpointIO::write(), libMesh::XdrIO::write(), libMesh::EquationSystems::write(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO::write_element_data(), libMesh::ExodusII_IO_Helper::write_element_values(), libMesh::ExodusII_IO_Helper::write_elements(), libMesh::ExodusII_IO::write_global_data(), libMesh::ExodusII_IO_Helper::write_global_values(), libMesh::ExodusII_IO::write_information_records(), libMesh::ExodusII_IO_Helper::write_information_records(), libMesh::ExodusII_IO_Helper::write_nodal_coordinates(), libMesh::UCDIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::ExodusII_IO_Helper::write_nodal_values(), libMesh::Nemesis_IO_Helper::write_nodesets(), libMesh::ExodusII_IO_Helper::write_nodesets(), libMesh::RBEvaluation::write_out_vectors(), write_output_solvedata(), libMesh::RBConstruction::write_riesz_representors_to_files(), libMesh::XdrIO::write_serialized_bc_names(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::Nemesis_IO_Helper::write_sidesets(), libMesh::ExodusII_IO_Helper::write_sidesets(), libMesh::ExodusII_IO::write_timestep(), and libMesh::ExodusII_IO_Helper::write_timestep().

100  { return cast_int<processor_id_type>(_communicator.rank()); }
const Parallel::Communicator & _communicator
unsigned int rank() const
Definition: parallel.h:724
template<typename T >
void libMesh::TaoOptimizationSolver< T >::solve ( )
virtual

Call the Tao solver.

Implements libMesh::OptimizationSolver< T >.

Definition at line 449 of file tao_optimization_solver.C.

References libMesh::TaoOptimizationSolver< T >::__libmesh_tao_equality_constraints, libMesh::TaoOptimizationSolver< T >::__libmesh_tao_equality_constraints_jacobian, libMesh::TaoOptimizationSolver< T >::__libmesh_tao_gradient, libMesh::TaoOptimizationSolver< T >::__libmesh_tao_hessian, libMesh::TaoOptimizationSolver< T >::__libmesh_tao_inequality_constraints, libMesh::TaoOptimizationSolver< T >::__libmesh_tao_inequality_constraints_jacobian, libMesh::TaoOptimizationSolver< T >::__libmesh_tao_objective, libMesh::TaoOptimizationSolver< T >::_reason, libMesh::TaoOptimizationSolver< T >::_tao, libMesh::OptimizationSystem::C_eq, libMesh::OptimizationSystem::C_eq_jac, libMesh::OptimizationSystem::C_ineq, libMesh::OptimizationSystem::C_ineq_jac, libMesh::OptimizationSolver< T >::equality_constraints_jacobian_object, libMesh::OptimizationSolver< T >::equality_constraints_object, libMesh::System::get_vector(), libMesh::OptimizationSolver< T >::gradient_object, libMesh::OptimizationSolver< T >::hessian_object, ierr, libMesh::OptimizationSolver< T >::inequality_constraints_jacobian_object, libMesh::OptimizationSolver< T >::inequality_constraints_object, libMesh::TaoOptimizationSolver< T >::init(), libMesh::libmesh_assert(), libMesh::OptimizationSystem::ComputeLowerAndUpperBounds::lower_and_upper_bounds(), libMesh::OptimizationSolver< T >::lower_and_upper_bounds_object, libMesh::ImplicitSystem::matrix, libMesh::OptimizationSolver< T >::max_objective_function_evaluations, libMesh::OptimizationSolver< T >::objective_function_relative_tolerance, libMesh::OptimizationSolver< T >::objective_object, libMesh::System::solution, libMesh::OptimizationSolver< T >::system(), and libMesh::x.

Referenced by libMesh::TaoOptimizationSolver< T >::tao().

450 {
451  LOG_SCOPE("solve()", "TaoOptimizationSolver");
452 
453  this->init ();
454 
455  this->system().solution->zero();
456 
457  PetscMatrix<T> * hessian = cast_ptr<PetscMatrix<T> *>(this->system().matrix);
458  // PetscVector<T> * gradient = cast_ptr<PetscVector<T> *>(this->system().rhs);
459  PetscVector<T> * x = cast_ptr<PetscVector<T> *>(this->system().solution.get());
460  PetscVector<T> * ceq = cast_ptr<PetscVector<T> *>(this->system().C_eq.get());
461  PetscMatrix<T> * ceq_jac = cast_ptr<PetscMatrix<T> *>(this->system().C_eq_jac.get());
462  PetscVector<T> * cineq = cast_ptr<PetscVector<T> *>(this->system().C_ineq.get());
463  PetscMatrix<T> * cineq_jac = cast_ptr<PetscMatrix<T> *>(this->system().C_ineq_jac.get());
464  PetscVector<T> * lb = cast_ptr<PetscVector<T> *>(&this->system().get_vector("lower_bounds"));
465  PetscVector<T> * ub = cast_ptr<PetscVector<T> *>(&this->system().get_vector("upper_bounds"));
466 
467  // Set the starting guess to zero.
468  x->zero();
469 
470  PetscErrorCode ierr = 0;
471 
472  // Workaround for bug where TaoSetFromOptions *reset*
473  // programmatically set tolerance and max. function evaluation
474  // values when "-tao_type ipm" was specified on the command line: we
475  // call TaoSetFromOptions twice (both before and after setting
476  // custom options programmatically)
477  ierr = TaoSetFromOptions(_tao);
478  LIBMESH_CHKERR(ierr);
479 
480  // Set convergence tolerances
481  // f(X) - f(X*) (estimated) <= fatol
482  // |f(X) - f(X*)| (estimated) / |f(X)| <= frtol
483  // ||g(X)|| <= gatol
484  // ||g(X)|| / |f(X)| <= grtol
485  // ||g(X)|| / ||g(X0)|| <= gttol
486  // Command line equivalents: -tao_fatol, -tao_frtol, -tao_gatol, -tao_grtol, -tao_gttol
487  ierr = TaoSetTolerances(_tao,
488 #if PETSC_RELEASE_LESS_THAN(3,7,0)
489  // Releases up to 3.X.Y had fatol and frtol, after that they were removed.
490  // Hopefully we'll be able to know X and Y soon. Guessing at 3.7.0.
491  /*fatol=*/PETSC_DEFAULT,
492  /*frtol=*/PETSC_DEFAULT,
493 #endif
494  /*gatol=*/PETSC_DEFAULT,
496  /*gttol=*/PETSC_DEFAULT);
497  LIBMESH_CHKERR(ierr);
498 
499  // Set the max-allowed number of objective function evaluations
500  // Command line equivalent: -tao_max_funcs
501  ierr = TaoSetMaximumFunctionEvaluations(_tao, this->max_objective_function_evaluations);
502  LIBMESH_CHKERR(ierr);
503 
504  // Set the max-allowed number of optimization iterations.
505  // Command line equivalent: -tao_max_it
506  // Not implemented for now as it seems fairly similar to
507  // ierr = TaoSetMaximumIterations(_tao, 4);
508  // LIBMESH_CHKERR(ierr);
509 
510  // Set solution vec and an initial guess
511  ierr = TaoSetInitialVector(_tao, x->vec());
512  LIBMESH_CHKERR(ierr);
513 
514  // We have to have an objective function
516 
517  // Set routines for objective, gradient, hessian evaluation
518  ierr = TaoSetObjectiveRoutine(_tao, __libmesh_tao_objective, this);
519  LIBMESH_CHKERR(ierr);
520 
521  if (this->gradient_object)
522  {
523  ierr = TaoSetGradientRoutine(_tao, __libmesh_tao_gradient, this);
524  LIBMESH_CHKERR(ierr);
525  }
526 
527  if (this->hessian_object)
528  {
529  ierr = TaoSetHessianRoutine(_tao, hessian->mat(), hessian->mat(), __libmesh_tao_hessian, this);
530  LIBMESH_CHKERR(ierr);
531  }
532 
534  {
535  // Need to actually compute the bounds vectors first
537 
538  ierr = TaoSetVariableBounds(_tao,
539  lb->vec(),
540  ub->vec());
541  LIBMESH_CHKERR(ierr);
542  }
543 
544  if (this->equality_constraints_object)
545  {
546  ierr = TaoSetEqualityConstraintsRoutine(_tao, ceq->vec(), __libmesh_tao_equality_constraints, this);
547  LIBMESH_CHKERR(ierr);
548  }
549 
551  {
552  ierr = TaoSetJacobianEqualityRoutine(_tao,
553  ceq_jac->mat(),
554  ceq_jac->mat(),
556  this);
557  LIBMESH_CHKERR(ierr);
558  }
559 
560  // Optionally set inequality constraints
562  {
563  ierr = TaoSetInequalityConstraintsRoutine(_tao, cineq->vec(), __libmesh_tao_inequality_constraints, this);
564  LIBMESH_CHKERR(ierr);
565  }
566 
567  // Optionally set inequality constraints Jacobian
569  {
570  ierr = TaoSetJacobianInequalityRoutine(_tao,
571  cineq_jac->mat(),
572  cineq_jac->mat(),
574  this);
575  LIBMESH_CHKERR(ierr);
576  }
577 
578  // Check for Tao command line options
579  ierr = TaoSetFromOptions(_tao);
580  LIBMESH_CHKERR(ierr);
581 
582  // Perform the optimization
583  ierr = TaoSolve(_tao);
584  LIBMESH_CHKERR(ierr);
585 
586  // Store the convergence/divergence reason
587  ierr = TaoGetConvergedReason(_tao, &_reason);
588  LIBMESH_CHKERR(ierr);
589 }
OptimizationSystem::ComputeObjective * objective_object
Object that computes the objective function f(X) at the input iterate X.
friend PetscErrorCode __libmesh_tao_inequality_constraints(Tao tao, Vec x, Vec cineq, void *ctx)
friend PetscErrorCode __libmesh_tao_hessian(Tao tao, Vec x, Mat h, Mat pc, void *ctx)
Real objective_function_relative_tolerance
Required change in objective function which signals convergence.
virtual void init() libmesh_override
Initialize data structures if not done so already.
friend PetscErrorCode __libmesh_tao_equality_constraints(Tao tao, Vec x, Vec ce, void *ctx)
OptimizationSystem::ComputeGradient * gradient_object
Object that computes the gradient grad_f(X) of the objective function at the input iterate X...
const sys_type & system() const
OptimizationSystem::ComputeHessian * hessian_object
Object that computes the Hessian H_f(X) of the objective function at the input iterate X...
friend PetscErrorCode __libmesh_tao_equality_constraints_jacobian(Tao tao, Vec x, Mat J, Mat Jpre, void *ctx)
libmesh_assert(j)
OptimizationSystem::ComputeInequalityConstraints * inequality_constraints_object
Object that computes the inequality constraints vector C_ineq(X).
PetscErrorCode Vec x
OptimizationSystem::ComputeEqualityConstraintsJacobian * equality_constraints_jacobian_object
Object that computes the Jacobian of C_eq(X).
Tao _tao
Optimization solver context.
friend PetscErrorCode __libmesh_tao_inequality_constraints_jacobian(Tao tao, Vec x, Mat J, Mat Jpre, void *ctx)
friend PetscErrorCode __libmesh_tao_objective(Tao tao, Vec x, PetscReal *objective, void *ctx)
unsigned int max_objective_function_evaluations
Maximum number of objective function evaluations allowed.
UniquePtr< SparseMatrix< Number > > C_eq_jac
The sparse matrix that stores the Jacobian of C_eq.
friend PetscErrorCode __libmesh_tao_gradient(Tao tao, Vec x, Vec g, void *ctx)
UniquePtr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1523
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:794
virtual void lower_and_upper_bounds(sys_type &S)=0
This function should update the following two vectors: this->get_vector("lower_bounds"), this->get_vector("upper_bounds").
TaoConvergedReason _reason
Store the reason for Tao convergence/divergence for use even after _tao has been cleared.
OptimizationSystem::ComputeLowerAndUpperBounds * lower_and_upper_bounds_object
Object that computes the lower and upper bounds vectors.
PetscErrorCode ierr
SparseMatrix< Number > * matrix
The system matrix.
UniquePtr< NumericVector< Number > > C_eq
The vector that stores equality constraints.
OptimizationSystem::ComputeInequalityConstraintsJacobian * inequality_constraints_jacobian_object
Object that computes the Jacobian of C_ineq(X).
UniquePtr< SparseMatrix< Number > > C_ineq_jac
The sparse matrix that stores the Jacobian of C_ineq.
OptimizationSystem::ComputeEqualityConstraints * equality_constraints_object
Object that computes the equality constraints vector C_eq(X).
UniquePtr< NumericVector< Number > > C_ineq
The vector that stores inequality constraints.
template<typename T >
const sys_type& libMesh::OptimizationSolver< T >::system ( ) const
inherited
template<typename T >
sys_type& libMesh::OptimizationSolver< T >::system ( )
inherited
Returns
A writable reference to the system we are using to define the optimization problem.

Definition at line 180 of file optimization_solver.h.

References libMesh::OptimizationSolver< T >::_system.

180 { return _system; }
sys_type & _system
A reference to the system we are solving.
template<typename T>
Tao libMesh::TaoOptimizationSolver< T >::tao ( )

Friends And Related Function Documentation

template<typename T>
PetscErrorCode __libmesh_tao_equality_constraints ( Tao  tao,
Vec  x,
Vec  ce,
void *  ctx 
)
friend

Definition at line 198 of file tao_optimization_solver.C.

Referenced by libMesh::TaoOptimizationSolver< T >::solve().

199  {
200  LOG_SCOPE("equality_constraints()", "TaoOptimizationSolver");
201 
202  PetscErrorCode ierr = 0;
203 
204  libmesh_assert(x);
205  libmesh_assert(ce);
207 
208  // ctx should be a pointer to the solver (it was passed in as void *)
209  TaoOptimizationSolver<Number> * solver =
210  static_cast<TaoOptimizationSolver<Number> *> (ctx);
211 
212  OptimizationSystem & sys = solver->system();
213 
214  // We'll use current_local_solution below, so let's ensure that it's consistent
215  // with the vector x that was passed in.
216  PetscVector<Number> & X_sys = *cast_ptr<PetscVector<Number> *>(sys.solution.get());
217  PetscVector<Number> X(x, sys.comm());
218 
219  // Perform a swap so that sys.solution points to X
220  X.swap(X_sys);
221  // Impose constraints on X
223  // Update sys.current_local_solution based on X
224  sys.update();
225  // Swap back
226  X.swap(X_sys);
227 
228  // We'll also pass the constraints vector ce into the assembly routine
229  // so let's make a PETSc vector for that too.
230  PetscVector<Number> eq_constraints(ce, sys.comm());
231 
232  // Clear the gradient prior to assembly
233  eq_constraints.zero();
234 
235  if (solver->equality_constraints_object != libmesh_nullptr)
236  solver->equality_constraints_object->equality_constraints(*(sys.current_local_solution), eq_constraints, sys);
237  else
238  libmesh_error_msg("Constraints function not defined in __libmesh_tao_equality_constraints");
239 
240  eq_constraints.close();
241 
242  return ierr;
243  }
ImplicitSystem & sys
const class libmesh_nullptr_t libmesh_nullptr
libmesh_assert(j)
PetscDiffSolver & solver
PetscErrorCode Vec x
const DofMap & get_dof_map() const
Definition: system.h:2030
PetscErrorCode Vec Mat Mat void * ctx
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=libmesh_nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Definition: dof_map.h:1816
PetscErrorCode ierr
template<typename T>
PetscErrorCode __libmesh_tao_equality_constraints_jacobian ( Tao  tao,
Vec  x,
Mat  J,
Mat  Jpre,
void *  ctx 
)
friend

Definition at line 249 of file tao_optimization_solver.C.

Referenced by libMesh::TaoOptimizationSolver< T >::solve().

250  {
251  LOG_SCOPE("equality_constraints_jacobian()", "TaoOptimizationSolver");
252 
253  PetscErrorCode ierr = 0;
254 
255  libmesh_assert(x);
256  libmesh_assert(J);
257  libmesh_assert(Jpre);
258 
259  // ctx should be a pointer to the solver (it was passed in as void *)
260  TaoOptimizationSolver<Number> * solver =
261  static_cast<TaoOptimizationSolver<Number> *> (ctx);
262 
263  OptimizationSystem & sys = solver->system();
264 
265  // We'll use current_local_solution below, so let's ensure that it's consistent
266  // with the vector x that was passed in.
267  PetscVector<Number> & X_sys = *cast_ptr<PetscVector<Number> *>(sys.solution.get());
268  PetscVector<Number> X(x, sys.comm());
269 
270  // Perform a swap so that sys.solution points to X
271  X.swap(X_sys);
272  // Impose constraints on X
274  // Update sys.current_local_solution based on X
275  sys.update();
276  // Swap back
277  X.swap(X_sys);
278 
279  // Let's also wrap J and Jpre in PetscMatrix objects for convenience
280  PetscMatrix<Number> J_petsc(J, sys.comm());
281  PetscMatrix<Number> Jpre_petsc(Jpre, sys.comm());
282 
283  if (solver->equality_constraints_jacobian_object != libmesh_nullptr)
284  solver->equality_constraints_jacobian_object->equality_constraints_jacobian(*(sys.current_local_solution), J_petsc, sys);
285  else
286  libmesh_error_msg("Constraints function not defined in __libmesh_tao_equality_constraints_jacobian");
287 
288  J_petsc.close();
289  Jpre_petsc.close();
290 
291  return ierr;
292  }
ImplicitSystem & sys
const class libmesh_nullptr_t libmesh_nullptr
libmesh_assert(j)
PetscDiffSolver & solver
PetscErrorCode Vec x
const DofMap & get_dof_map() const
Definition: system.h:2030
PetscErrorCode Vec Mat Mat void * ctx
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=libmesh_nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Definition: dof_map.h:1816
PetscErrorCode ierr
template<typename T>
PetscErrorCode __libmesh_tao_gradient ( Tao  tao,
Vec  x,
Vec  g,
void *  ctx 
)
friend

Definition at line 92 of file tao_optimization_solver.C.

Referenced by libMesh::TaoOptimizationSolver< T >::solve().

93  {
94  LOG_SCOPE("gradient()", "TaoOptimizationSolver");
95 
96  PetscErrorCode ierr = 0;
97 
99  libmesh_assert(g);
101 
102  // ctx should be a pointer to the solver (it was passed in as void *)
103  TaoOptimizationSolver<Number> * solver =
104  static_cast<TaoOptimizationSolver<Number> *> (ctx);
105 
106  OptimizationSystem & sys = solver->system();
107 
108  // We'll use current_local_solution below, so let's ensure that it's consistent
109  // with the vector x that was passed in.
110  PetscVector<Number> & X_sys = *cast_ptr<PetscVector<Number> *>(sys.solution.get());
111  PetscVector<Number> X(x, sys.comm());
112 
113  // Perform a swap so that sys.solution points to X
114  X.swap(X_sys);
115  // Impose constraints on X
117  // Update sys.current_local_solution based on X
118  sys.update();
119  // Swap back
120  X.swap(X_sys);
121 
122  // We'll also pass the gradient in to the assembly routine
123  // so let's make a PETSc vector for that too.
124  PetscVector<Number> gradient(g, sys.comm());
125 
126  // Clear the gradient prior to assembly
127  gradient.zero();
128 
129  if (solver->gradient_object != libmesh_nullptr)
130  solver->gradient_object->gradient(*(sys.current_local_solution), gradient, sys);
131  else
132  libmesh_error_msg("Gradient function not defined in __libmesh_tao_gradient");
133 
134  gradient.close();
135 
136  return ierr;
137  }
ImplicitSystem & sys
const class libmesh_nullptr_t libmesh_nullptr
libmesh_assert(j)
PetscDiffSolver & solver
PetscErrorCode Vec x
const DofMap & get_dof_map() const
Definition: system.h:2030
PetscErrorCode Vec Mat Mat void * ctx
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=libmesh_nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Definition: dof_map.h:1816
PetscErrorCode ierr
template<typename T>
PetscErrorCode __libmesh_tao_hessian ( Tao  tao,
Vec  x,
Mat  h,
Mat  pc,
void *  ctx 
)
friend

Definition at line 142 of file tao_optimization_solver.C.

Referenced by libMesh::TaoOptimizationSolver< T >::solve().

143  {
144  LOG_SCOPE("hessian()", "TaoOptimizationSolver");
145 
146  PetscErrorCode ierr = 0;
147 
148  libmesh_assert(x);
149  libmesh_assert(h);
152 
153  // ctx should be a pointer to the solver (it was passed in as void *)
154  TaoOptimizationSolver<Number> * solver =
155  static_cast<TaoOptimizationSolver<Number> *> (ctx);
156 
157  OptimizationSystem & sys = solver->system();
158 
159  // We'll use current_local_solution below, so let's ensure that it's consistent
160  // with the vector x that was passed in.
161  PetscVector<Number> & X_sys = *cast_ptr<PetscVector<Number> *>(sys.solution.get());
162  PetscVector<Number> X(x, sys.comm());
163 
164  // Perform a swap so that sys.solution points to X
165  X.swap(X_sys);
166  // Impose constraints on X
168  // Update sys.current_local_solution based on X
169  sys.update();
170  // Swap back
171  X.swap(X_sys);
172 
173  // Let's also wrap pc and h in PetscMatrix objects for convenience
174  PetscMatrix<Number> PC(pc, sys.comm());
175  PetscMatrix<Number> hessian(h, sys.comm());
176  PC.attach_dof_map(sys.get_dof_map());
177  hessian.attach_dof_map(sys.get_dof_map());
178 
179  if (solver->hessian_object != libmesh_nullptr)
180  {
181  // Following PetscNonlinearSolver by passing in PC. It's not clear
182  // why we pass in PC and not hessian though?
183  solver->hessian_object->hessian(*(sys.current_local_solution), PC, sys);
184  }
185  else
186  libmesh_error_msg("Hessian function not defined in __libmesh_tao_hessian");
187 
188  PC.close();
189  hessian.close();
190 
191  return ierr;
192  }
ImplicitSystem & sys
const class libmesh_nullptr_t libmesh_nullptr
PetscErrorCode Vec Mat Mat pc
libmesh_assert(j)
PetscDiffSolver & solver
PetscErrorCode Vec x
const DofMap & get_dof_map() const
Definition: system.h:2030
PetscErrorCode Vec Mat Mat void * ctx
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=libmesh_nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Definition: dof_map.h:1816
PetscErrorCode ierr
template<typename T>
PetscErrorCode __libmesh_tao_inequality_constraints ( Tao  tao,
Vec  x,
Vec  cineq,
void *  ctx 
)
friend

Definition at line 297 of file tao_optimization_solver.C.

Referenced by libMesh::TaoOptimizationSolver< T >::solve().

298  {
299  LOG_SCOPE("inequality_constraints()", "TaoOptimizationSolver");
300 
301  PetscErrorCode ierr = 0;
302 
303  libmesh_assert(x);
304  libmesh_assert(cineq);
306 
307  // ctx should be a pointer to the solver (it was passed in as void *)
308  TaoOptimizationSolver<Number> * solver =
309  static_cast<TaoOptimizationSolver<Number> *> (ctx);
310 
311  OptimizationSystem & sys = solver->system();
312 
313  // We'll use current_local_solution below, so let's ensure that it's consistent
314  // with the vector x that was passed in.
315  PetscVector<Number> & X_sys = *cast_ptr<PetscVector<Number> *>(sys.solution.get());
316  PetscVector<Number> X(x, sys.comm());
317 
318  // Perform a swap so that sys.solution points to X
319  X.swap(X_sys);
320  // Impose constraints on X
322  // Update sys.current_local_solution based on X
323  sys.update();
324  // Swap back
325  X.swap(X_sys);
326 
327  // We'll also pass the constraints vector ce into the assembly routine
328  // so let's make a PETSc vector for that too.
329  PetscVector<Number> ineq_constraints(cineq, sys.comm());
330 
331  // Clear the gradient prior to assembly
332  ineq_constraints.zero();
333 
334  if (solver->inequality_constraints_object != libmesh_nullptr)
335  solver->inequality_constraints_object->inequality_constraints(*(sys.current_local_solution), ineq_constraints, sys);
336  else
337  libmesh_error_msg("Constraints function not defined in __libmesh_tao_inequality_constraints");
338 
339  ineq_constraints.close();
340 
341  return ierr;
342  }
ImplicitSystem & sys
const class libmesh_nullptr_t libmesh_nullptr
libmesh_assert(j)
PetscDiffSolver & solver
PetscErrorCode Vec x
const DofMap & get_dof_map() const
Definition: system.h:2030
PetscErrorCode Vec Mat Mat void * ctx
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=libmesh_nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Definition: dof_map.h:1816
PetscErrorCode ierr
template<typename T>
PetscErrorCode __libmesh_tao_inequality_constraints_jacobian ( Tao  tao,
Vec  x,
Mat  J,
Mat  Jpre,
void *  ctx 
)
friend

Definition at line 348 of file tao_optimization_solver.C.

Referenced by libMesh::TaoOptimizationSolver< T >::solve().

349  {
350  LOG_SCOPE("inequality_constraints_jacobian()", "TaoOptimizationSolver");
351 
352  PetscErrorCode ierr = 0;
353 
354  libmesh_assert(x);
355  libmesh_assert(J);
356  libmesh_assert(Jpre);
357 
358  // ctx should be a pointer to the solver (it was passed in as void *)
359  TaoOptimizationSolver<Number> * solver =
360  static_cast<TaoOptimizationSolver<Number> *> (ctx);
361 
362  OptimizationSystem & sys = solver->system();
363 
364  // We'll use current_local_solution below, so let's ensure that it's consistent
365  // with the vector x that was passed in.
366  PetscVector<Number> & X_sys = *cast_ptr<PetscVector<Number> *>(sys.solution.get());
367  PetscVector<Number> X(x, sys.comm());
368 
369  // Perform a swap so that sys.solution points to X
370  X.swap(X_sys);
371  // Impose constraints on X
373  // Update sys.current_local_solution based on X
374  sys.update();
375  // Swap back
376  X.swap(X_sys);
377 
378  // Let's also wrap J and Jpre in PetscMatrix objects for convenience
379  PetscMatrix<Number> J_petsc(J, sys.comm());
380  PetscMatrix<Number> Jpre_petsc(Jpre, sys.comm());
381 
382  if (solver->inequality_constraints_jacobian_object != libmesh_nullptr)
383  solver->inequality_constraints_jacobian_object->inequality_constraints_jacobian(*(sys.current_local_solution), J_petsc, sys);
384  else
385  libmesh_error_msg("Constraints function not defined in __libmesh_tao_inequality_constraints_jacobian");
386 
387  J_petsc.close();
388  Jpre_petsc.close();
389 
390  return ierr;
391  }
ImplicitSystem & sys
const class libmesh_nullptr_t libmesh_nullptr
libmesh_assert(j)
PetscDiffSolver & solver
PetscErrorCode Vec x
const DofMap & get_dof_map() const
Definition: system.h:2030
PetscErrorCode Vec Mat Mat void * ctx
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=libmesh_nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Definition: dof_map.h:1816
PetscErrorCode ierr
template<typename T>
PetscErrorCode __libmesh_tao_objective ( Tao  tao,
Vec  x,
PetscReal *  objective,
void *  ctx 
)
friend

Definition at line 49 of file tao_optimization_solver.C.

Referenced by libMesh::TaoOptimizationSolver< T >::solve().

50  {
51  LOG_SCOPE("objective()", "TaoOptimizationSolver");
52 
53  PetscErrorCode ierr = 0;
54 
56  libmesh_assert(objective);
58 
59  // ctx should be a pointer to the solver (it was passed in as void *)
60  TaoOptimizationSolver<Number> * solver =
61  static_cast<TaoOptimizationSolver<Number> *> (ctx);
62 
63  OptimizationSystem & sys = solver->system();
64 
65  // We'll use current_local_solution below, so let's ensure that it's consistent
66  // with the vector x that was passed in.
67  PetscVector<Number> & X_sys = *cast_ptr<PetscVector<Number> *>(sys.solution.get());
68  PetscVector<Number> X(x, sys.comm());
69 
70  // Perform a swap so that sys.solution points to X
71  X.swap(X_sys);
72  // Impose constraints on X
74  // Update sys.current_local_solution based on X
75  sys.update();
76  // Swap back
77  X.swap(X_sys);
78 
79  if (solver->objective_object != libmesh_nullptr)
80  (*objective) = solver->objective_object->objective(*(sys.current_local_solution), sys);
81  else
82  libmesh_error_msg("Objective function not defined in __libmesh_tao_objective");
83 
84  return ierr;
85  }
ImplicitSystem & sys
const class libmesh_nullptr_t libmesh_nullptr
libmesh_assert(j)
PetscDiffSolver & solver
PetscErrorCode Vec x
const DofMap & get_dof_map() const
Definition: system.h:2030
PetscErrorCode Vec Mat Mat void * ctx
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=libmesh_nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Definition: dof_map.h:1816
PetscErrorCode ierr

Member Data Documentation

const Parallel::Communicator& libMesh::ParallelObject::_communicator
protectedinherited
ReferenceCounter::Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited
bool libMesh::ReferenceCounter::_enable_print_counter = true
staticprotectedinherited

Flag to control whether reference count information is printed when print_info is called.

Definition at line 143 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::disable_print_counter_info(), libMesh::ReferenceCounter::enable_print_counter_info(), and libMesh::ReferenceCounter::print_info().

template<typename T >
bool libMesh::OptimizationSolver< T >::_is_initialized
protectedinherited
Threads::spin_mutex libMesh::ReferenceCounter::_mutex
staticprotectedinherited

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 137 of file reference_counter.h.

Threads::atomic< unsigned int > libMesh::ReferenceCounter::_n_objects
staticprotectedinherited

The number of objects.

Print the reference count information when the number returns to 0.

Definition at line 132 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::n_objects(), libMesh::ReferenceCounter::ReferenceCounter(), and libMesh::ReferenceCounter::~ReferenceCounter().

template<typename T>
TaoConvergedReason libMesh::TaoOptimizationSolver< T >::_reason
protected

Store the reason for Tao convergence/divergence for use even after _tao has been cleared.

Note
print_converged_reason() will always try to get the current reason with TaoGetConvergedReason(), but if the Tao object has already been cleared, it will fall back on this stored value. This value is therefore necessarily not cleared by the clear() function.

Definition at line 136 of file tao_optimization_solver.h.

Referenced by libMesh::TaoOptimizationSolver< T >::get_converged_reason(), and libMesh::TaoOptimizationSolver< T >::solve().

template<typename T >
sys_type& libMesh::OptimizationSolver< T >::_system
protectedinherited

A reference to the system we are solving.

Definition at line 202 of file optimization_solver.h.

Referenced by libMesh::OptimizationSolver< T >::system().

template<typename T>
Tao libMesh::TaoOptimizationSolver< T >::_tao
protected
template<typename T >
OptimizationSystem::ComputeEqualityConstraintsJacobian* libMesh::OptimizationSolver< T >::equality_constraints_jacobian_object
inherited
template<typename T >
OptimizationSystem::ComputeEqualityConstraints* libMesh::OptimizationSolver< T >::equality_constraints_object
inherited

Object that computes the equality constraints vector C_eq(X).

This will lead to the constraints C_eq(X) = 0 being imposed.

Definition at line 147 of file optimization_solver.h.

Referenced by libMesh::__libmesh_nlopt_equality_constraints(), libMesh::__libmesh_tao_equality_constraints(), libMesh::TaoOptimizationSolver< T >::solve(), and libMesh::NloptOptimizationSolver< T >::solve().

template<typename T >
OptimizationSystem::ComputeGradient* libMesh::OptimizationSolver< T >::gradient_object
inherited

Object that computes the gradient grad_f(X) of the objective function at the input iterate X.

Definition at line 135 of file optimization_solver.h.

Referenced by libMesh::__libmesh_nlopt_objective(), libMesh::__libmesh_tao_gradient(), and libMesh::TaoOptimizationSolver< T >::solve().

template<typename T >
OptimizationSystem::ComputeHessian* libMesh::OptimizationSolver< T >::hessian_object
inherited

Object that computes the Hessian H_f(X) of the objective function at the input iterate X.

Definition at line 141 of file optimization_solver.h.

Referenced by libMesh::__libmesh_tao_hessian(), and libMesh::TaoOptimizationSolver< T >::solve().

template<typename T >
OptimizationSystem::ComputeInequalityConstraintsJacobian* libMesh::OptimizationSolver< T >::inequality_constraints_jacobian_object
inherited
template<typename T >
OptimizationSystem::ComputeInequalityConstraints* libMesh::OptimizationSolver< T >::inequality_constraints_object
inherited

Object that computes the inequality constraints vector C_ineq(X).

This will lead to the constraints C_ineq(X) >= 0 being imposed.

Definition at line 158 of file optimization_solver.h.

Referenced by libMesh::__libmesh_nlopt_inequality_constraints(), libMesh::__libmesh_tao_inequality_constraints(), libMesh::TaoOptimizationSolver< T >::solve(), and libMesh::NloptOptimizationSolver< T >::solve().

template<typename T >
OptimizationSystem::ComputeLowerAndUpperBounds* libMesh::OptimizationSolver< T >::lower_and_upper_bounds_object
inherited

Object that computes the lower and upper bounds vectors.

Definition at line 168 of file optimization_solver.h.

Referenced by libMesh::TaoOptimizationSolver< T >::solve(), and libMesh::NloptOptimizationSolver< T >::solve().

template<typename T >
unsigned int libMesh::OptimizationSolver< T >::max_objective_function_evaluations
inherited

Maximum number of objective function evaluations allowed.

Definition at line 185 of file optimization_solver.h.

Referenced by libMesh::TaoOptimizationSolver< T >::solve(), and libMesh::NloptOptimizationSolver< T >::solve().

template<typename T >
Real libMesh::OptimizationSolver< T >::objective_function_relative_tolerance
inherited

Required change in objective function which signals convergence.

Definition at line 190 of file optimization_solver.h.

Referenced by libMesh::TaoOptimizationSolver< T >::solve(), and libMesh::NloptOptimizationSolver< T >::solve().

template<typename T >
OptimizationSystem::ComputeObjective* libMesh::OptimizationSolver< T >::objective_object
inherited

Object that computes the objective function f(X) at the input iterate X.

Definition at line 129 of file optimization_solver.h.

Referenced by libMesh::__libmesh_nlopt_objective(), libMesh::__libmesh_tao_objective(), libMesh::TaoOptimizationSolver< T >::solve(), and libMesh::NloptOptimizationSolver< T >::solve().

template<typename T >
bool libMesh::OptimizationSolver< T >::verbose
inherited

Control how much is output from the OptimizationSolver as it's running.

Definition at line 195 of file optimization_solver.h.

Referenced by libMesh::__libmesh_nlopt_objective().


The documentation for this class was generated from the following files: