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

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

#include <tao_optimization_solver.h>

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

Public Types

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

Public Member Functions

 TaoOptimizationSolver (sys_type &system)
 Constructor. More...
 
 ~TaoOptimizationSolver ()
 Destructor. More...
 
virtual void clear () override
 Release all memory and clear data structures. More...
 
virtual void init () override
 Initialize data structures if not done so already. More...
 
Tao tao ()
 
virtual void solve () override
 Call the Tao solver. More...
 
virtual void get_dual_variables () override
 Get the current values of dual variables associated with inequality and equality constraints. 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
 
bool initialized () const
 
const sys_typesystem () const
 
sys_typesystem ()
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static 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

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

Static Protected Attributes

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

Friends

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

Detailed Description

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

This class provides an interface to the Tao optimization solvers.

Author
David Knezevic
Date
2015

Definition at line 58 of file tao_optimization_solver.h.

Member Typedef Documentation

◆ 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::TaoOptimizationSolver< T >::sys_type

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

Definition at line 65 of file tao_optimization_solver.h.

Constructor & Destructor Documentation

◆ TaoOptimizationSolver()

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

Constructor.

Initializes Tao data structures.

◆ ~TaoOptimizationSolver()

template<typename T >
libMesh::TaoOptimizationSolver< T >::~TaoOptimizationSolver ( )

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.

◆ clear()

template<typename T >
virtual void libMesh::TaoOptimizationSolver< 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::TaoOptimizationSolver< T >::get_converged_reason ( )
overridevirtual
Returns
The currently-available (or most recently obtained, if the Tao object has been destroyed) convergence reason.

Refer to Tao docs for the meaning of different TaoConvergedReason.

Reimplemented from libMesh::OptimizationSolver< T >.

◆ get_dual_variables()

template<typename T >
virtual void libMesh::TaoOptimizationSolver< T >::get_dual_variables ( )
overridevirtual

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

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

Reimplemented from libMesh::OptimizationSolver< T >.

◆ 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::TaoOptimizationSolver< T >::init ( )
overridevirtual

Initialize data structures if not done so already.

Implements libMesh::OptimizationSolver< T >.

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

◆ 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::TaoOptimizationSolver< 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::TaoOptimizationSolver< T >::solve ( )
overridevirtual

Call the Tao 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.

◆ tao()

template<typename T >
Tao libMesh::TaoOptimizationSolver< T >::tao ( )
Returns
The raw PETSc Tao context pointer.

Definition at line 91 of file tao_optimization_solver.h.

References libMesh::TaoOptimizationSolver< T >::_tao, and libMesh::TaoOptimizationSolver< T >::init().

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

Friends And Related Function Documentation

◆ __libmesh_tao_equality_constraints

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

◆ __libmesh_tao_equality_constraints_jacobian

template<typename T >
PetscErrorCode __libmesh_tao_equality_constraints_jacobian ( Tao  tao,
Vec  x,
Mat  J,
Mat  Jpre,
void *  ctx 
)
friend

◆ __libmesh_tao_gradient

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

◆ __libmesh_tao_hessian

template<typename T >
PetscErrorCode __libmesh_tao_hessian ( Tao  tao,
Vec  x,
Mat  h,
Mat  pc,
void *  ctx 
)
friend

◆ __libmesh_tao_inequality_constraints

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

◆ __libmesh_tao_inequality_constraints_jacobian

template<typename T >
PetscErrorCode __libmesh_tao_inequality_constraints_jacobian ( Tao  tao,
Vec  x,
Mat  J,
Mat  Jpre,
void *  ctx 
)
friend

◆ __libmesh_tao_objective

template<typename T >
PetscErrorCode __libmesh_tao_objective ( Tao  tao,
Vec  x,
PetscReal *  objective,
void *  ctx 
)
friend

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

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

◆ _reason

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

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

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

Definition at line 136 of file tao_optimization_solver.h.

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

◆ _tao

template<typename T >
Tao libMesh::TaoOptimizationSolver< T >::_tao
protected

Optimization solver context.

Definition at line 124 of file tao_optimization_solver.h.

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

◆ 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: