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 () override
 Release all memory and clear data structures. More...
 
virtual void init () override
 Initialize data structures if not done so already. More...
 
nlopt_opt get_nlopt_object ()
 
virtual void solve () override
 Call the NLopt solver. More...
 
virtual void print_converged_reason () override
 Prints a useful message about why the latest optimization solve con(di)verged. More...
 
virtual int get_converged_reason () 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 std::unique_ptr< 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
 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

◆ Counts

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 117 of file reference_counter.h.

◆ sys_type

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

◆ NloptOptimizationSolver()

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

Constructor.

◆ ~NloptOptimizationSolver()

Destructor.

Member Function Documentation

◆ build()

template<typename T >
static std::unique_ptr<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.

◆ build_map()

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  }

◆ clear()

template<typename T >
virtual void libMesh::NloptOptimizationSolver< T >::clear ( )
overridevirtual

Release all memory and clear data structures.

Reimplemented from libMesh::OptimizationSolver< T >.

◆ comm()

const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inherited

◆ disable_print_counter_info()

static void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

◆ enable_print_counter_info()

static void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

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

◆ get_converged_reason()

template<typename T >
virtual int libMesh::NloptOptimizationSolver< T >::get_converged_reason ( )
overridevirtual
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 >.

◆ get_dual_variables()

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 114 of file optimization_solver.h.

115  { libmesh_not_implemented(); }

◆ get_info()

static std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

◆ get_iteration_count()

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.

127 { return _iteration_count; }
unsigned _iteration_count
Stores the current iteration index (incremented at each call of __libmesh_nlopt_objective).

◆ get_nlopt_object()

template<typename T >
nlopt_opt libMesh::NloptOptimizationSolver< T >::get_nlopt_object ( )
Returns
The raw NLopt object.

Definition at line 103 of file nlopt_optimization_solver.h.

References libMesh::NloptOptimizationSolver< T >::_opt, and libMesh::NloptOptimizationSolver< T >::init().

103 { this->init(); return _opt; }
nlopt_opt _opt
Optimization solver context.
virtual void init() override
Initialize data structures if not done so already.

◆ increment_constructor_count()

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 181 of file reference_counter.h.

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

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

182 {
183  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
184  std::pair<unsigned int, unsigned int> & p = _counts[name];
185 
186  p.first++;
187 }
std::string name(const ElemQuality q)
static Counts _counts
Actually holds the data.
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.

◆ increment_destructor_count()

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 194 of file reference_counter.h.

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

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

195 {
196  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
197  std::pair<unsigned int, unsigned int> & p = _counts[name];
198 
199  p.second++;
200 }
std::string name(const ElemQuality q)
static Counts _counts
Actually holds the data.
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.

◆ init()

template<typename T >
virtual void libMesh::NloptOptimizationSolver< T >::init ( )
overridevirtual

Initialize data structures if not done so already.

Implements libMesh::OptimizationSolver< T >.

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

◆ initialized()

template<typename T >
bool libMesh::OptimizationSolver< T >::initialized ( ) const
inherited
Returns
true if the data structures are initialized, false otherwise.

Definition at line 92 of file optimization_solver.h.

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

92 { return _is_initialized; }
bool _is_initialized
Flag indicating if the data structures have been initialized.

◆ n_objects()

static unsigned int libMesh::ReferenceCounter::n_objects ( )
staticinherited

Prints the number of outstanding (created, but not yet destroyed) objects.

Definition at line 83 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

84  { return _n_objects; }
static Threads::atomic< unsigned int > _n_objects
The number of objects.

◆ n_processors()

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::MeshBase::partition().

94  { return cast_int<processor_id_type>(_communicator.size()); }
processor_id_type size() const
Definition: communicator.h:175
const Parallel::Communicator & _communicator

◆ print_converged_reason()

template<typename T >
virtual void libMesh::NloptOptimizationSolver< T >::print_converged_reason ( )
overridevirtual

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

Reimplemented from libMesh::OptimizationSolver< T >.

◆ print_info()

static void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out)
staticinherited

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

◆ processor_id()

processor_id_type libMesh::ParallelObject::processor_id ( ) const
inherited

◆ solve()

template<typename T >
virtual void libMesh::NloptOptimizationSolver< T >::solve ( )
overridevirtual

Call the NLopt solver.

Implements libMesh::OptimizationSolver< T >.

◆ system() [1/2]

template<typename T >
const sys_type& libMesh::OptimizationSolver< T >::system ( ) const
inherited
Returns
A constant reference to the system we are using to define the optimization problem.

Definition at line 183 of file optimization_solver.h.

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

183 { return _system; }
sys_type & _system
A reference to the system we are solving.

◆ system() [2/2]

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 189 of file optimization_solver.h.

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

189 { return _system; }
sys_type & _system
A reference to the system we are solving.

Friends And Related Function Documentation

◆ __libmesh_nlopt_equality_constraints

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

◆ __libmesh_nlopt_inequality_constraints

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

◆ __libmesh_nlopt_objective

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

Member Data Documentation

◆ _communicator

const Parallel::Communicator& libMesh::ParallelObject::_communicator
protectedinherited

◆ _constraints_tolerance

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.

◆ _counts

Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited

◆ _enable_print_counter

bool libMesh::ReferenceCounter::_enable_print_counter
staticprotectedinherited

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

Definition at line 141 of file reference_counter.h.

◆ _is_initialized

template<typename T >
bool libMesh::OptimizationSolver< T >::_is_initialized
protectedinherited

Flag indicating if the data structures have been initialized.

Definition at line 216 of file optimization_solver.h.

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

◆ _iteration_count

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().

◆ _mutex

Threads::spin_mutex libMesh::ReferenceCounter::_mutex
staticprotectedinherited

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 135 of file reference_counter.h.

◆ _n_objects

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 130 of file reference_counter.h.

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

◆ _nlopt_algorithms

template<typename T >
std::map< std::string, nlopt_algorithm > libMesh::NloptOptimizationSolver< T >::_nlopt_algorithms = NloptOptimizationSolver<T>::build_map()
staticprivate

Definition at line 174 of file nlopt_optimization_solver.h.

◆ _opt

template<typename T >
nlopt_opt libMesh::NloptOptimizationSolver< T >::_opt
protected

Optimization solver context.

Definition at line 134 of file nlopt_optimization_solver.h.

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

◆ _result

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.

◆ _system

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

A reference to the system we are solving.

Definition at line 211 of file optimization_solver.h.

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

◆ equality_constraints_jacobian_object

template<typename T >
OptimizationSystem::ComputeEqualityConstraintsJacobian* libMesh::OptimizationSolver< T >::equality_constraints_jacobian_object
inherited

Object that computes the Jacobian of C_eq(X).

Definition at line 161 of file optimization_solver.h.

◆ equality_constraints_object

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 156 of file optimization_solver.h.

◆ gradient_object

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 144 of file optimization_solver.h.

◆ hessian_object

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 150 of file optimization_solver.h.

◆ inequality_constraints_jacobian_object

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

Object that computes the Jacobian of C_ineq(X).

Definition at line 172 of file optimization_solver.h.

◆ inequality_constraints_object

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 167 of file optimization_solver.h.

◆ lower_and_upper_bounds_object

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 177 of file optimization_solver.h.

◆ max_objective_function_evaluations

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

Maximum number of objective function evaluations allowed.

Definition at line 194 of file optimization_solver.h.

◆ objective_function_relative_tolerance

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

Required change in objective function which signals convergence.

Definition at line 199 of file optimization_solver.h.

◆ objective_object

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 138 of file optimization_solver.h.

◆ verbose

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

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

Definition at line 204 of file optimization_solver.h.


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