libMesh
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
libMesh::OptimizationSolver< T > Class Template Referenceabstract

This base class can be inherited from to provide interfaces to optimization solvers from different packages like PETSc/TAO and nlopt. More...

#include <optimization_solver.h>

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

Public Types

typedef OptimizationSystem sys_type
 The type of system. More...
 

Public Member Functions

 OptimizationSolver (sys_type &s)
 Constructor. More...
 
virtual ~OptimizationSolver ()
 Destructor. More...
 
bool initialized () const
 
virtual void clear ()
 Release all memory and clear data structures. More...
 
virtual void init ()=0
 Initialize data structures if not done so already. More...
 
virtual void solve ()=0
 Solves the optimization problem. More...
 
virtual void get_dual_variables ()
 Get the current values of dual variables associated with inequality and equality constraints. More...
 
virtual void print_converged_reason ()
 Prints a useful message about why the latest optimization solve con(di)verged. More...
 
virtual int get_converged_reason ()
 
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

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

Detailed Description

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

This base class can be inherited from to provide interfaces to optimization solvers from different packages like PETSc/TAO and nlopt.

Author
David Knezevic
Date
2015

Definition at line 61 of file 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::OptimizationSolver< T >::sys_type

The type of system.

Definition at line 68 of file optimization_solver.h.

Constructor & Destructor Documentation

◆ OptimizationSolver()

template<typename T >
libMesh::OptimizationSolver< T >::OptimizationSolver ( sys_type s)
explicit

Constructor.

Initializes Solver data structures

◆ ~OptimizationSolver()

template<typename T >
virtual libMesh::OptimizationSolver< T >::~OptimizationSolver ( )
virtual

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

Builds an OptimizationSolver using the package specified by solver_package.

◆ clear()

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

Release all memory and clear data structures.

Reimplemented in libMesh::NloptOptimizationSolver< T >, and libMesh::TaoOptimizationSolver< T >.

Definition at line 97 of file optimization_solver.h.

97 {}

◆ 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::OptimizationSolver< T >::get_converged_reason ( )
virtual
Returns
0, but derived classes should override this to return an appropriate integer convergence status value.

Most optimization solver packages return an integer status result of some kind. This interface assumes they can be coerced into an "int" type, which is usually safe since they are based on enumerations.

Reimplemented in libMesh::NloptOptimizationSolver< T >, and libMesh::TaoOptimizationSolver< T >.

Definition at line 132 of file optimization_solver.h.

132 { return 0; }

◆ get_dual_variables()

template<typename T >
virtual void libMesh::OptimizationSolver< 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 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.

◆ 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::OptimizationSolver< T >::init ( )
pure virtual

Initialize data structures if not done so already.

Implemented in libMesh::NloptOptimizationSolver< T >, and libMesh::TaoOptimizationSolver< T >.

◆ initialized()

template<typename T >
bool libMesh::OptimizationSolver< T >::initialized ( ) const
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::OptimizationSolver< T >::print_converged_reason ( )
virtual

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

Reimplemented in libMesh::NloptOptimizationSolver< T >, and libMesh::TaoOptimizationSolver< T >.

Definition at line 121 of file optimization_solver.h.

121 { libmesh_not_implemented(); }

◆ 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::OptimizationSolver< T >::solve ( )
pure virtual

Solves the optimization problem.

Implemented in libMesh::NloptOptimizationSolver< T >, and libMesh::TaoOptimizationSolver< T >.

◆ system() [1/2]

template<typename T >
const sys_type& libMesh::OptimizationSolver< T >::system ( ) const
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 ( )
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.

Member Data Documentation

◆ _communicator

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

◆ _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
protected

Flag indicating if the data structures have been initialized.

Definition at line 216 of file optimization_solver.h.

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

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

◆ _system

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

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

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

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

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

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

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

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

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

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

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

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

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: