libMesh
optimization_solver.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 // C++ includes
21 
22 // Local Includes
23 #include "libmesh/optimization_solver.h"
24 #include "libmesh/tao_optimization_solver.h"
25 #include "libmesh/nlopt_optimization_solver.h"
26 
27 namespace libMesh
28 {
29 
30 template <typename T>
31 inline
33  ParallelObject(s),
34  objective_object(libmesh_nullptr),
35  gradient_object(libmesh_nullptr),
36  hessian_object(libmesh_nullptr),
37  equality_constraints_object(libmesh_nullptr),
38  equality_constraints_jacobian_object(libmesh_nullptr),
39  inequality_constraints_object(libmesh_nullptr),
40  inequality_constraints_jacobian_object(libmesh_nullptr),
41  lower_and_upper_bounds_object(libmesh_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>
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:
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:
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  libmesh_error_msg("We'll never get here!");
87 }
88 
89 
90 //------------------------------------------------------------------
91 // Explicit instantiations
92 template class OptimizationSolver<Number>;
93 
94 } // namespace libMesh
virtual ~OptimizationSolver()
Destructor.
This class provides an interface to the Tao optimization solvers.
virtual void clear()
Release all memory and clear data structures.
This class provides an interface to the NLopt optimization solvers.
static UniquePtr< OptimizationSolver< T > > build(sys_type &s, const SolverPackage solver_package=libMesh::default_solver_package())
Builds an OptimizationSolver using the package specified by solver_package.
SolverPackage
Defines an enum for various linear solver packages.
const class libmesh_nullptr_t libmesh_nullptr
The libMesh namespace provides an interface to certain functionality in the library.
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
bool _is_initialized
Flag that tells if init() has been called.
Definition: libmesh.C:255
This System subclass enables us to assemble an objective function, gradient, Hessian and bounds for o...
This class forms the base class for all other classes that are expected to be implemented in parallel...
OptimizationSolver(sys_type &s)
Constructor.
void libmesh_ignore(const T &)
This base class can be inherited from to provide interfaces to optimization solvers from different pa...