LCOV - code coverage report
Current view: top level - src/solvers - optimization_solver.C (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4229 (6a9aeb) with base 727f46 Lines: 21 23 91.3 %
Date: 2025-08-19 19:27:09 Functions: 3 8 37.5 %
Legend: Lines: hit not hit

          Line data    Source code
       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
      34         142 : OptimizationSolver<T>::OptimizationSolver (sys_type & s) :
      35             :   ParallelObject(s),
      36         134 :   objective_object(nullptr),
      37         134 :   gradient_object(nullptr),
      38         134 :   hessian_object(nullptr),
      39         134 :   equality_constraints_object(nullptr),
      40         134 :   equality_constraints_jacobian_object(nullptr),
      41         134 :   inequality_constraints_object(nullptr),
      42         134 :   inequality_constraints_jacobian_object(nullptr),
      43         134 :   lower_and_upper_bounds_object(nullptr),
      44         134 :   max_objective_function_evaluations(500),
      45         134 :   objective_function_relative_tolerance(1.e-4),
      46         134 :   verbose(false),
      47         134 :   _system(s),
      48         142 :   _is_initialized (false)
      49             : {
      50         142 : }
      51             : 
      52             : 
      53             : 
      54             : template <typename T>
      55             : inline
      56         134 : OptimizationSolver<T>::~OptimizationSolver () = default;
      57             : 
      58             : 
      59             : 
      60             : template <typename T>
      61             : std::unique_ptr<OptimizationSolver<T>>
      62         142 : OptimizationSolver<T>::build(sys_type & s, const SolverPackage solver_package)
      63             : {
      64             :   // Prevent unused variables warnings when Tao is not available
      65           4 :   libmesh_ignore(s);
      66             : 
      67             :   // Build the appropriate solver
      68         142 :   switch (solver_package)
      69             :     {
      70             : 
      71             : #if defined(LIBMESH_HAVE_PETSC_TAO) && !defined(LIBMESH_USE_COMPLEX_NUMBERS)
      72         142 :     case PETSC_SOLVERS:
      73         142 :       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           0 :     default:
      82           0 :       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

Generated by: LCOV version 1.14