libMesh
optimization_solver.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 // Local Includes
21 #include "libmesh/optimization_solver.h"
22 #include "libmesh/tao_optimization_solver.h"
23 #include "libmesh/nlopt_optimization_solver.h"
24 #include "libmesh/auto_ptr.h" // libmesh_make_unique
25 #include "libmesh/enum_solver_package.h"
26 
27 namespace libMesh
28 {
29 
30 template <typename T>
31 inline
33  ParallelObject(s),
34  objective_object(nullptr),
35  gradient_object(nullptr),
36  hessian_object(nullptr),
37  equality_constraints_object(nullptr),
38  equality_constraints_jacobian_object(nullptr),
39  inequality_constraints_object(nullptr),
40  inequality_constraints_jacobian_object(nullptr),
41  lower_and_upper_bounds_object(nullptr),
42  max_objective_function_evaluations(500),
43  objective_function_relative_tolerance(1.e-4),
44  verbose(false),
45  _system(s),
46  _is_initialized (false)
47 {
48 }
49 
50 
51 
52 template <typename T>
53 inline
55 {
56  this->clear ();
57 }
58 
59 
60 template <typename T>
61 std::unique_ptr<OptimizationSolver<T>>
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 libmesh_make_unique<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 libmesh_make_unique<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 
86 
87 //------------------------------------------------------------------
88 // Explicit instantiations
89 template class OptimizationSolver<Number>;
90 
91 } // namespace libMesh
libMesh::OptimizationSystem
This System subclass enables us to assemble an objective function, gradient, Hessian and bounds for o...
Definition: optimization_system.h:43
libMesh::SolverPackage
SolverPackage
Defines an enum for various linear solver packages.
Definition: enum_solver_package.h:34
libMesh::OptimizationSolver::build
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.
Definition: optimization_solver.C:62
libMesh::PETSC_SOLVERS
Definition: enum_solver_package.h:36
libMesh::NLOPT_SOLVERS
Definition: enum_solver_package.h:41
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::OptimizationSolver
This base class can be inherited from to provide interfaces to optimization solvers from different pa...
Definition: optimization_solver.h:60
libMesh::libmesh_ignore
void libmesh_ignore(const Args &...)
Definition: libmesh_common.h:526
libMesh::OptimizationSolver::~OptimizationSolver
virtual ~OptimizationSolver()
Destructor.
Definition: optimization_solver.C:54
libMesh::OptimizationSolver::OptimizationSolver
OptimizationSolver(sys_type &s)
Constructor.
Definition: optimization_solver.C:32
libMesh::libMeshPrivateData::_is_initialized
bool _is_initialized
Flag that tells if init() has been called.
Definition: libmesh.C:246
libMesh::ParallelObject
An object whose state is distributed along a set of processors.
Definition: parallel_object.h:55