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

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

#include <nlopt_optimization_solver.h>

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

Public Types

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

Public Member Functions

 NloptOptimizationSolver (sys_type &system)
 Constructor. More...
 
 ~NloptOptimizationSolver ()
 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...
 
nlopt_opt get_nlopt_object ()
 
virtual void solve () libmesh_override
 Call the NLopt solver. 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
 
unsigned & get_iteration_count ()
 
bool initialized () const
 
virtual void get_dual_variables ()
 Get the current values of dual variables associated with inequality and equality constraints. More...
 
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

nlopt_opt _opt
 Optimization solver context. More...
 
nlopt_result _result
 Store the result (i.e. More...
 
unsigned _iteration_count
 Stores the current iteration index (incremented at each call of __libmesh_nlopt_objective). More...
 
double _constraints_tolerance
 NLopt requires us to specify a tolerance for the constraints. 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...
 

Static Private Member Functions

static std::map< std::string, nlopt_algorithm > build_map ()
 

Static Private Attributes

static std::map< std::string, nlopt_algorithm > _nlopt_algorithms = NloptOptimizationSolver<T>::build_map()
 

Friends

double __libmesh_nlopt_objective (unsigned n, const double *x, double *gradient, void *data)
 
void __libmesh_nlopt_equality_constraints (unsigned m, double *result, unsigned n, const double *x, double *gradient, void *data)
 
void __libmesh_nlopt_inequality_constraints (unsigned m, double *result, unsigned n, const double *x, double *gradient, void *data)
 

Detailed Description

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

This class provides an interface to the NLopt optimization solvers.

http://ab-initio.mit.edu/wiki/index.php/NLopt

Author
David Knezevic
John Peterson
Date
2015

Definition at line 70 of file nlopt_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::NloptOptimizationSolver< T >::sys_type

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

Definition at line 77 of file nlopt_optimization_solver.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 289 of file nlopt_optimization_solver.C.

290  :
291  OptimizationSolver<T>(system_in),
293  _result(NLOPT_SUCCESS),
294  _iteration_count(0),
296 {
297 }
double _constraints_tolerance
NLopt requires us to specify a tolerance for the constraints.
nlopt_opt _opt
Optimization solver context.
nlopt_result _result
Store the result (i.e.
const class libmesh_nullptr_t libmesh_nullptr
unsigned _iteration_count
Stores the current iteration index (incremented at each call of __libmesh_nlopt_objective).

Destructor.

Definition at line 302 of file nlopt_optimization_solver.C.

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

303 {
304  this->clear ();
305 }
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>
static std::map<std::string, nlopt_algorithm> libMesh::NloptOptimizationSolver< T >::build_map ( )
staticprivate

Definition at line 182 of file nlopt_optimization_solver.h.

183  {
184  std::map<std::string, nlopt_algorithm> ret;
185  ret["LD_SLSQP"] = NLOPT_LD_SLSQP;
186  ret["LD_MMA"] = NLOPT_LD_MMA;
187  ret["LD_CCSAQ"] = NLOPT_LD_CCSAQ;
188  ret["LD_LBFGS"] = NLOPT_LD_LBFGS;
189  ret["LD_LBFGS_NOCEDAL"] = NLOPT_LD_LBFGS_NOCEDAL;
190  ret["LD_TNEWTON"] = NLOPT_LD_TNEWTON;
191  ret["LD_TNEWTON_RESTART"] = NLOPT_LD_TNEWTON_RESTART;
192  ret["LD_TNEWTON_PRECOND"] = NLOPT_LD_TNEWTON_PRECOND;
193  ret["LD_TNEWTON_PRECOND_RESTART"] = NLOPT_LD_TNEWTON_PRECOND_RESTART;
194  ret["LD_AUGLAG"] = NLOPT_LD_AUGLAG;
195  ret["LD_VAR1"] = NLOPT_LD_VAR1;
196  ret["LD_VAR2"] = NLOPT_LD_VAR2;
197  ret["LN_COBYLA"] = NLOPT_LN_COBYLA;
198  ret["LN_BOBYQA"] = NLOPT_LN_BOBYQA;
199  ret["LN_PRAXIS"] = NLOPT_LN_PRAXIS;
200  ret["LN_NELDERMEAD"] = NLOPT_LN_NELDERMEAD;
201  ret["LN_SBPLX"] = NLOPT_LN_SBPLX;
202  ret["GN_ISRES"] = NLOPT_GN_ISRES;
203  return ret;
204  }
template<typename T >
void libMesh::NloptOptimizationSolver< T >::clear ( )
virtual

Release all memory and clear data structures.

Reimplemented from libMesh::OptimizationSolver< T >.

Definition at line 310 of file nlopt_optimization_solver.C.

References libMesh::OptimizationSolver< T >::_is_initialized, libMesh::NloptOptimizationSolver< T >::_opt, and libMesh::OptimizationSolver< T >::initialized().

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

311 {
312  if (this->initialized())
313  {
314  this->_is_initialized = false;
315 
316  nlopt_destroy(_opt);
317  }
318 }
nlopt_opt _opt
Optimization solver context.
bool _is_initialized
Flag indicating if the data structures have been initialized.
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::NloptOptimizationSolver< T >::get_converged_reason ( )
virtual
Returns
The currently-available (or most recently obtained, if the NLopt object has been destroyed) convergence reason. Refer to NLopt docs for the meaning of different the value.

Reimplemented from libMesh::OptimizationSolver< T >.

Definition at line 463 of file nlopt_optimization_solver.C.

References libMesh::NloptOptimizationSolver< T >::_result.

Referenced by libMesh::NloptOptimizationSolver< T >::get_nlopt_object(), and libMesh::NloptOptimizationSolver< T >::print_converged_reason().

464 {
465  return static_cast<int>(_result);
466 }
nlopt_result _result
Store the result (i.e.
template<typename T >
virtual void libMesh::OptimizationSolver< T >::get_dual_variables ( )
virtualinherited

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 in libMesh::TaoOptimizationSolver< T >.

Definition at line 105 of file optimization_solver.h.

106  { libmesh_not_implemented(); }
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.
template<typename T>
unsigned& libMesh::NloptOptimizationSolver< T >::get_iteration_count ( )
Returns
A writable reference to the current iteration count which can be incremented in the objective function.

Definition at line 127 of file nlopt_optimization_solver.h.

References libMesh::NloptOptimizationSolver< T >::_iteration_count.

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

127 { return _iteration_count; }
unsigned _iteration_count
Stores the current iteration index (incremented at each call of __libmesh_nlopt_objective).
template<typename T>
nlopt_opt libMesh::NloptOptimizationSolver< T >::get_nlopt_object ( )
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::NloptOptimizationSolver< T >::init ( )
virtual

Initialize data structures if not done so already.

Implements libMesh::OptimizationSolver< T >.

Definition at line 323 of file nlopt_optimization_solver.C.

References libMesh::OptimizationSolver< T >::_is_initialized, libMesh::NloptOptimizationSolver< T >::_nlopt_algorithms, libMesh::NloptOptimizationSolver< T >::_opt, libMesh::command_line_next(), libMesh::OptimizationSolver< T >::initialized(), and libMesh::on_command_line().

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

324 {
325  // Initialize the data structures if not done so already.
326  if (!this->initialized())
327  {
328  this->_is_initialized = true;
329 
330  // By default, use the LD_SLSQP solver
331  std::string nlopt_algorithm_name = "LD_SLSQP";
332 
333  if (libMesh::on_command_line("--nlopt-algorithm"))
334  nlopt_algorithm_name = libMesh::command_line_next ("--nlopt-algorithm",
335  nlopt_algorithm_name);
336 
337  // Convert string to an nlopt algorithm type
338  std::map<std::string, nlopt_algorithm>::iterator it =
339  _nlopt_algorithms.find(nlopt_algorithm_name);
340 
341  if (it == _nlopt_algorithms.end())
342  libmesh_error_msg("Invalid nlopt algorithm requested on command line: " \
343  << nlopt_algorithm_name);
344 
345  _opt = nlopt_create(it->second, this->system().solution->size());
346  }
347 }
nlopt_opt _opt
Optimization solver context.
T command_line_next(const std::string &, T)
Use GetPot&#39;s search()/next() functions to get following arguments from the command line...
Definition: libmesh.C:964
bool _is_initialized
Flag indicating if the data structures have been initialized.
bool on_command_line(const std::string &arg)
Definition: libmesh.C:921
static std::map< std::string, nlopt_algorithm > _nlopt_algorithms
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::NloptOptimizationSolver< 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 454 of file nlopt_optimization_solver.C.

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

Referenced by libMesh::NloptOptimizationSolver< T >::get_nlopt_object().

455 {
456  libMesh::out << "NLopt optimization solver convergence/divergence reason: "
457  << this->get_converged_reason() << std::endl;
458 }
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::NloptOptimizationSolver< T >::solve ( )
virtual

Call the NLopt solver.

Implements libMesh::OptimizationSolver< T >.

Definition at line 352 of file nlopt_optimization_solver.C.

References libMesh::NloptOptimizationSolver< T >::__libmesh_nlopt_equality_constraints, libMesh::NloptOptimizationSolver< T >::__libmesh_nlopt_inequality_constraints, libMesh::NloptOptimizationSolver< T >::__libmesh_nlopt_objective, libMesh::NloptOptimizationSolver< T >::_constraints_tolerance, libMesh::NloptOptimizationSolver< T >::_iteration_count, libMesh::NloptOptimizationSolver< T >::_opt, libMesh::NloptOptimizationSolver< T >::_result, libMesh::OptimizationSolver< T >::equality_constraints_object, libMesh::NloptOptimizationSolver< T >::get_iteration_count(), libMesh::System::get_vector(), ierr, libMesh::OptimizationSolver< T >::inequality_constraints_object, libMesh::NloptOptimizationSolver< T >::init(), libMesh::libmesh_assert(), libMesh::OptimizationSystem::ComputeLowerAndUpperBounds::lower_and_upper_bounds(), libMesh::OptimizationSolver< T >::lower_and_upper_bounds_object, libMesh::OptimizationSolver< T >::max_objective_function_evaluations, libMesh::OptimizationSolver< T >::objective_function_relative_tolerance, libMesh::OptimizationSolver< T >::objective_object, libMesh::out, libMesh::Real, libMesh::System::solution, libMesh::OptimizationSolver< T >::system(), and libMesh::x.

Referenced by libMesh::NloptOptimizationSolver< T >::get_nlopt_object().

353 {
354  LOG_SCOPE("solve()", "NloptOptimizationSolver");
355 
356  this->init ();
357 
358  unsigned int nlopt_size = this->system().solution->size();
359 
360  // We have to have an objective function
362 
363  // Set routine for objective and (optionally) gradient evaluation
364  {
365  nlopt_result ierr =
366  nlopt_set_min_objective(_opt,
368  this);
369  if (ierr < 0)
370  libmesh_error_msg("NLopt failed to set min objective: " << ierr);
371  }
372 
374  {
375  // Need to actually compute the bounds vectors first
377 
378  std::vector<Real> nlopt_lb(nlopt_size);
379  std::vector<Real> nlopt_ub(nlopt_size);
380  for (unsigned int i=0; i<nlopt_size; i++)
381  {
382  nlopt_lb[i] = this->system().get_vector("lower_bounds")(i);
383  nlopt_ub[i] = this->system().get_vector("upper_bounds")(i);
384  }
385 
386  nlopt_set_lower_bounds(_opt, &nlopt_lb[0]);
387  nlopt_set_upper_bounds(_opt, &nlopt_ub[0]);
388  }
389 
390  // If we have an equality constraints object, tell NLopt about it.
391  if (this->equality_constraints_object)
392  {
393  // NLopt requires a vector to specify the tolerance for each constraint.
394  // NLopt makes a copy of this vector internally, so it's safe for us to
395  // let it go out of scope.
396  std::vector<double> equality_constraints_tolerances(this->system().C_eq->size(),
398 
399  // It would be nice to call the C interface directly, at least it should return an error
400  // code we could parse... unfortunately, there does not seem to be a way to extract
401  // the underlying nlopt_opt object from the nlopt::opt class!
402  nlopt_result ierr =
403  nlopt_add_equality_mconstraint(_opt,
404  equality_constraints_tolerances.size(),
406  this,
407  &equality_constraints_tolerances[0]);
408 
409  if (ierr < 0)
410  libmesh_error_msg("NLopt failed to add equality constraint: " << ierr);
411  }
412 
413  // If we have an inequality constraints object, tell NLopt about it.
415  {
416  // NLopt requires a vector to specify the tolerance for each constraint
417  std::vector<double> inequality_constraints_tolerances(this->system().C_ineq->size(),
419 
420  nlopt_add_inequality_mconstraint(_opt,
421  inequality_constraints_tolerances.size(),
423  this,
424  &inequality_constraints_tolerances[0]);
425  }
426 
427  // Set a relative tolerance on the optimization parameters
428  nlopt_set_ftol_rel(_opt, this->objective_function_relative_tolerance);
429 
430  // Set the maximum number of allowed objective function evaluations
431  nlopt_set_maxeval(_opt, this->max_objective_function_evaluations);
432 
433  // Reset internal iteration counter
434  this->_iteration_count = 0;
435 
436  // Perform the optimization
437  std::vector<Real> x(nlopt_size);
438  Real min_val = 0.;
439  _result = nlopt_optimize(_opt, &x[0], &min_val);
440 
441  if (_result < 0)
442  libMesh::out << "NLopt failed!" << std::endl;
443  else
444  libMesh::out << "NLopt obtained optimal value: "
445  << min_val
446  << " in "
447  << this->get_iteration_count()
448  << " iterations."
449  << std::endl;
450 }
OptimizationSystem::ComputeObjective * objective_object
Object that computes the objective function f(X) at the input iterate X.
double _constraints_tolerance
NLopt requires us to specify a tolerance for the constraints.
nlopt_opt _opt
Optimization solver context.
nlopt_result _result
Store the result (i.e.
friend void __libmesh_nlopt_equality_constraints(unsigned m, double *result, unsigned n, const double *x, double *gradient, void *data)
Real objective_function_relative_tolerance
Required change in objective function which signals convergence.
friend void __libmesh_nlopt_inequality_constraints(unsigned m, double *result, unsigned n, const double *x, double *gradient, void *data)
unsigned _iteration_count
Stores the current iteration index (incremented at each call of __libmesh_nlopt_objective).
const sys_type & system() const
libmesh_assert(j)
OptimizationSystem::ComputeInequalityConstraints * inequality_constraints_object
Object that computes the inequality constraints vector C_ineq(X).
friend double __libmesh_nlopt_objective(unsigned n, const double *x, double *gradient, void *data)
PetscErrorCode Vec x
virtual void init() libmesh_override
Initialize data structures if not done so already.
unsigned int max_objective_function_evaluations
Maximum number of objective function evaluations allowed.
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").
OptimizationSystem::ComputeLowerAndUpperBounds * lower_and_upper_bounds_object
Object that computes the lower and upper bounds vectors.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
PetscErrorCode ierr
OStreamProxy out
OptimizationSystem::ComputeEqualityConstraints * equality_constraints_object
Object that computes the equality constraints vector C_eq(X).
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.

Friends And Related Function Documentation

template<typename T>
void __libmesh_nlopt_equality_constraints ( unsigned  m,
double *  result,
unsigned  n,
const double *  x,
double *  gradient,
void *  data 
)
friend

Definition at line 109 of file nlopt_optimization_solver.C.

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

115 {
116  LOG_SCOPE("equality_constraints()", "NloptOptimizationSolver");
117 
119 
120  // data should be a pointer to the solver (it was passed in as void *)
121  NloptOptimizationSolver<Number> * solver =
122  static_cast<NloptOptimizationSolver<Number> *> (data);
123 
124  OptimizationSystem & sys = solver->system();
125 
126  // We'll use current_local_solution below, so let's ensure that it's consistent
127  // with the vector x that was passed in.
128  if (sys.solution->size() != n)
129  libmesh_error_msg("Error: Input vector x has different length than sys.solution!");
130 
131  for (unsigned int i=sys.solution->first_local_index(); i<sys.solution->last_local_index(); i++)
132  sys.solution->set(i, x[i]);
133  sys.solution->close();
134 
135  // Impose constraints on the solution vector
136  sys.get_dof_map().enforce_constraints_exactly(sys);
137 
138  // Update sys.current_local_solution based on the solution vector
139  sys.update();
140 
141  // Call the user's equality constraints function if there is one.
142  OptimizationSystem::ComputeEqualityConstraints * eco = solver->equality_constraints_object;
143  if (eco)
144  {
145  eco->equality_constraints(*sys.current_local_solution,
146  *sys.C_eq,
147  sys);
148 
149  sys.C_eq->close();
150 
151  // Copy the values out of eq_constraints into 'result'.
152  // TODO: Even better would be if we could use 'result' directly
153  // as the storage of eq_constraints. Perhaps a serial-only
154  // NumericVector variant which supports this option?
155  for (unsigned i=0; i<m; ++i)
156  result[i] = (*sys.C_eq)(i);
157 
158  // If gradient != NULL, then the Jacobian matrix of the equality
159  // constraints has been requested. The incoming 'gradient'
160  // array is of length m*n and d(c_i)/d(x_j) = gradient[n*i+j].
161  if (gradient)
162  {
163  OptimizationSystem::ComputeEqualityConstraintsJacobian * eco_jac =
164  solver->equality_constraints_jacobian_object;
165 
166  if (eco_jac)
167  {
168  eco_jac->equality_constraints_jacobian(*sys.current_local_solution,
169  *sys.C_eq_jac,
170  sys);
171 
172  sys.C_eq_jac->close();
173 
174  // copy the Jacobian data to the gradient array
175  for (numeric_index_type i=0; i<m; i++)
176  {
177  std::set<numeric_index_type>::iterator it = sys.eq_constraint_jac_sparsity[i].begin();
178  std::set<numeric_index_type>::iterator it_end = sys.eq_constraint_jac_sparsity[i].end();
179  for ( ; it != it_end; ++it)
180  {
181  numeric_index_type dof_index = *it;
182  gradient[n*i+dof_index] = (*sys.C_eq_jac)(i,dof_index);
183  }
184  }
185  }
186  else
187  libmesh_error_msg("Jacobian function not defined in __libmesh_nlopt_equality_constraints");
188  }
189 
190  }
191  else
192  libmesh_error_msg("Constraints function not defined in __libmesh_nlopt_equality_constraints");
193 }
ImplicitSystem & sys
libmesh_assert(j)
PetscDiffSolver & solver
PetscErrorCode Vec x
dof_id_type numeric_index_type
Definition: id_types.h:92
UniquePtr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1523
IterBase * data
Ideally this private member data should have protected access.
template<typename T>
void __libmesh_nlopt_inequality_constraints ( unsigned  m,
double *  result,
unsigned  n,
const double *  x,
double *  gradient,
void *  data 
)
friend

Definition at line 196 of file nlopt_optimization_solver.C.

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

202 {
203  LOG_SCOPE("inequality_constraints()", "NloptOptimizationSolver");
204 
206 
207  // data should be a pointer to the solver (it was passed in as void *)
208  NloptOptimizationSolver<Number> * solver =
209  static_cast<NloptOptimizationSolver<Number> *> (data);
210 
211  OptimizationSystem & sys = solver->system();
212 
213  // We'll use current_local_solution below, so let's ensure that it's consistent
214  // with the vector x that was passed in.
215  if (sys.solution->size() != n)
216  libmesh_error_msg("Error: Input vector x has different length than sys.solution!");
217 
218  for (unsigned int i=sys.solution->first_local_index(); i<sys.solution->last_local_index(); i++)
219  sys.solution->set(i, x[i]);
220  sys.solution->close();
221 
222  // Impose constraints on the solution vector
223  sys.get_dof_map().enforce_constraints_exactly(sys);
224 
225  // Update sys.current_local_solution based on the solution vector
226  sys.update();
227 
228  // Call the user's inequality constraints function if there is one.
229  OptimizationSystem::ComputeInequalityConstraints * ineco = solver->inequality_constraints_object;
230  if (ineco)
231  {
232  ineco->inequality_constraints(*sys.current_local_solution,
233  *sys.C_ineq,
234  sys);
235 
236  sys.C_ineq->close();
237 
238  // Copy the values out of ineq_constraints into 'result'.
239  // TODO: Even better would be if we could use 'result' directly
240  // as the storage of ineq_constraints. Perhaps a serial-only
241  // NumericVector variant which supports this option?
242  for (unsigned i=0; i<m; ++i)
243  result[i] = (*sys.C_ineq)(i);
244 
245  // If gradient != NULL, then the Jacobian matrix of the equality
246  // constraints has been requested. The incoming 'gradient'
247  // array is of length m*n and d(c_i)/d(x_j) = gradient[n*i+j].
248  if (gradient)
249  {
250  OptimizationSystem::ComputeInequalityConstraintsJacobian * ineco_jac =
251  solver->inequality_constraints_jacobian_object;
252 
253  if (ineco_jac)
254  {
255  ineco_jac->inequality_constraints_jacobian(*sys.current_local_solution,
256  *sys.C_ineq_jac,
257  sys);
258 
259  sys.C_ineq_jac->close();
260 
261  // copy the Jacobian data to the gradient array
262  for (numeric_index_type i=0; i<m; i++)
263  {
264  std::set<numeric_index_type>::iterator it = sys.ineq_constraint_jac_sparsity[i].begin();
265  std::set<numeric_index_type>::iterator it_end = sys.ineq_constraint_jac_sparsity[i].end();
266  for ( ; it != it_end; ++it)
267  {
268  numeric_index_type dof_index = *it;
269  gradient[n*i+dof_index] = (*sys.C_ineq_jac)(i,dof_index);
270  }
271  }
272  }
273  else
274  libmesh_error_msg("Jacobian function not defined in __libmesh_nlopt_inequality_constraints");
275  }
276 
277  }
278  else
279  libmesh_error_msg("Constraints function not defined in __libmesh_nlopt_inequality_constraints");
280 }
ImplicitSystem & sys
libmesh_assert(j)
PetscDiffSolver & solver
PetscErrorCode Vec x
dof_id_type numeric_index_type
Definition: id_types.h:92
UniquePtr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1523
IterBase * data
Ideally this private member data should have protected access.
template<typename T>
double __libmesh_nlopt_objective ( unsigned  n,
const double *  x,
double *  gradient,
void *  data 
)
friend

Definition at line 36 of file nlopt_optimization_solver.C.

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

40 {
41  LOG_SCOPE("objective()", "NloptOptimizationSolver");
42 
43  // ctx should be a pointer to the solver (it was passed in as void *)
44  NloptOptimizationSolver<Number> * solver =
45  static_cast<NloptOptimizationSolver<Number> *> (data);
46 
47  OptimizationSystem & sys = solver->system();
48 
49  // We'll use current_local_solution below, so let's ensure that it's consistent
50  // with the vector x that was passed in.
51  for (unsigned int i=sys.solution->first_local_index();
52  i<sys.solution->last_local_index(); i++)
53  sys.solution->set(i, x[i]);
54 
55  // Make sure the solution vector is parallel-consistent
56  sys.solution->close();
57 
58  // Impose constraints on X
59  sys.get_dof_map().enforce_constraints_exactly(sys);
60 
61  // Update sys.current_local_solution based on X
62  sys.update();
63 
64  Real objective;
65  if (solver->objective_object != libmesh_nullptr)
66  {
67  objective =
68  solver->objective_object->objective(
69  *(sys.current_local_solution), sys);
70  }
71  else
72  {
73  libmesh_error_msg("Objective function not defined in __libmesh_nlopt_objective");
74  }
75 
76  // If the gradient has been requested, fill it in
77  if (gradient)
78  {
79  if (solver->gradient_object != libmesh_nullptr)
80  {
81  solver->gradient_object->gradient(
82  *(sys.current_local_solution), *(sys.rhs), sys);
83 
84  // we've filled up sys.rhs with the gradient data, now copy it
85  // to the nlopt data structure
86  libmesh_assert(sys.rhs->size() == n);
87 
88  std::vector<double> grad;
89  sys.rhs->localize_to_one(grad);
90  for (unsigned i=0; i<n; ++i)
91  gradient[i] = grad[i];
92  }
93  else
94  libmesh_error_msg("Gradient function not defined in __libmesh_nlopt_objective");
95  }
96 
97  // Increment the iteration count.
98  solver->get_iteration_count()++;
99 
100  // Possibly print the current value of the objective function
101  if (solver->verbose)
102  libMesh::out << objective << std::endl;
103 
104  return objective;
105 }
ImplicitSystem & sys
const class libmesh_nullptr_t libmesh_nullptr
libmesh_assert(j)
PetscDiffSolver & solver
PetscErrorCode Vec x
UniquePtr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1523
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
OStreamProxy out
IterBase * data
Ideally this private member data should have protected access.

Member Data Documentation

const Parallel::Communicator& libMesh::ParallelObject::_communicator
protectedinherited
template<typename T>
double libMesh::NloptOptimizationSolver< T >::_constraints_tolerance
protected

NLopt requires us to specify a tolerance for the constraints.

Definition at line 149 of file nlopt_optimization_solver.h.

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

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
template<typename T>
unsigned libMesh::NloptOptimizationSolver< T >::_iteration_count
protected

Stores the current iteration index (incremented at each call of __libmesh_nlopt_objective).

Definition at line 144 of file nlopt_optimization_solver.h.

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

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>
std::map< std::string, nlopt_algorithm > libMesh::NloptOptimizationSolver< T >::_nlopt_algorithms = NloptOptimizationSolver<T>::build_map()
staticprivate
template<typename T>
nlopt_opt libMesh::NloptOptimizationSolver< T >::_opt
protected
template<typename T>
nlopt_result libMesh::NloptOptimizationSolver< T >::_result
protected

Store the result (i.e.

convergence/divergence) for the most recent NLopt solve.

Definition at line 139 of file nlopt_optimization_solver.h.

Referenced by libMesh::NloptOptimizationSolver< T >::get_converged_reason(), and libMesh::NloptOptimizationSolver< 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 >
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: