optimization_solver.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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
24 #include "libmesh/auto_ptr.h" // libmesh_make_unique
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
static std::unique_ptr< OptimizationSolver< T > > build(sys_type &s, const SolverPackage solver_package=libMesh::default_solver_package())
void libmesh_ignore(const Args &...)
An object whose state is distributed along a set of processors.