libMesh
optimization_solver.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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/enum_solver_package.h"
25 
26 // C++ Includes
27 #include <memory>
28 
29 namespace libMesh
30 {
31 
32 template <typename T>
33 inline
35  ParallelObject(s),
36  objective_object(nullptr),
37  gradient_object(nullptr),
38  hessian_object(nullptr),
39  equality_constraints_object(nullptr),
40  equality_constraints_jacobian_object(nullptr),
41  inequality_constraints_object(nullptr),
42  inequality_constraints_jacobian_object(nullptr),
43  lower_and_upper_bounds_object(nullptr),
44  max_objective_function_evaluations(500),
45  objective_function_relative_tolerance(1.e-4),
46  verbose(false),
47  _system(s),
48  _is_initialized (false)
49 {
50 }
51 
52 
53 
54 template <typename T>
55 inline
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 std::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 std::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 LIBMESH_EXPORT OptimizationSolver<Number>;
90 
91 } // namespace libMesh
virtual ~OptimizationSolver()
Destructor.
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.
The libMesh namespace provides an interface to certain functionality in the library.
void libmesh_ignore(const Args &...)
bool _is_initialized
Flag that tells if init() has been called.
Definition: libmesh.C:257
This System subclass enables us to assemble an objective function, gradient, Hessian and bounds for o...
An object whose state is distributed along a set of processors.
OptimizationSolver(sys_type &s)
Constructor.
This base class can be inherited from to provide interfaces to optimization solvers from different pa...
SolverPackage
Defines an enum for various linear solver packages.