LCOV - code coverage report
Current view: top level - src/solvers - nonlinear_solver.C (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4229 (6a9aeb) with base 727f46 Lines: 14 25 56.0 %
Date: 2025-08-19 19:27:09 Functions: 4 14 28.6 %
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/nonlinear_solver.h"
      22             : #include "libmesh/petsc_nonlinear_solver.h"
      23             : #include "libmesh/trilinos_nox_nonlinear_solver.h"
      24             : #include "libmesh/solver_configuration.h"
      25             : #include "libmesh/enum_solver_package.h"
      26             : 
      27             : // C++ Includes
      28             : #include <memory>
      29             : 
      30             : 
      31             : namespace libMesh
      32             : {
      33             : 
      34             : 
      35             : //------------------------------------------------------------------
      36             : // NonlinearSolver members
      37             : #if defined(LIBMESH_HAVE_PETSC) || defined(LIBMESH_TRILINOS_HAVE_NOX)
      38             : template <typename T>
      39             : std::unique_ptr<NonlinearSolver<T>>
      40        1470 : NonlinearSolver<T>::build(sys_type & s, const SolverPackage solver_package)
      41             : {
      42             :   // Build the appropriate solver
      43        1470 :   switch (solver_package)
      44             :     {
      45             : 
      46             : #ifdef LIBMESH_HAVE_PETSC
      47        1470 :     case PETSC_SOLVERS:
      48        1470 :       return std::make_unique<PetscNonlinearSolver<T>>(s);
      49             : #endif // LIBMESH_HAVE_PETSC
      50             : 
      51             : #if defined(LIBMESH_TRILINOS_HAVE_NOX) && defined(LIBMESH_TRILINOS_HAVE_EPETRA)
      52             :     case TRILINOS_SOLVERS:
      53             :       return std::make_unique<NoxNonlinearSolver<T>>(s);
      54             : #endif
      55             : 
      56           0 :     default:
      57           0 :       libmesh_error_msg("ERROR:  Unrecognized solver package: " << solver_package);
      58             :     }
      59             : }
      60             : 
      61             : #else // LIBMESH_HAVE_PETSC || LIBMESH_TRILINOS_HAVE_NOX
      62             : 
      63             : template <typename T>
      64             : std::unique_ptr<NonlinearSolver<T>>
      65           0 : NonlinearSolver<T>::build(sys_type &, const SolverPackage)
      66             : {
      67           0 :   libmesh_not_implemented_msg("ERROR: libMesh was compiled without nonlinear solver support");
      68             : }
      69             : #endif
      70             : 
      71             : 
      72             : template <typename T>
      73             : void
      74         280 : NonlinearSolver<T>::attach_preconditioner(Preconditioner<T> * preconditioner)
      75             : {
      76         280 :   libmesh_error_msg_if(this->_is_initialized, "Preconditioner must be attached before the solver is initialized!");
      77             : 
      78         280 :   _preconditioner = preconditioner;
      79         280 : }
      80             : 
      81             : template <typename T>
      82           0 : void NonlinearSolver<T>::set_solver_configuration(SolverConfiguration & solver_configuration)
      83             : {
      84           0 :   _solver_configuration = &solver_configuration;
      85           0 : }
      86             : 
      87             : template <typename T>
      88           0 : bool NonlinearSolver<T>::reuse_preconditioner() const
      89             : {
      90           0 :   libmesh_not_implemented();
      91             : }
      92             : 
      93             : template <typename T>
      94       29400 : void NonlinearSolver<T>::set_reuse_preconditioner(bool reuse)
      95             : {
      96       29400 :   _reuse_preconditioner = reuse;
      97       29400 : }
      98             : 
      99             : template <typename T>
     100           0 : unsigned int NonlinearSolver<T>::reuse_preconditioner_max_linear_its() const
     101             : {
     102           0 :   libmesh_not_implemented();
     103             : }
     104             : 
     105             : template <typename T>
     106       29400 : void NonlinearSolver<T>::set_reuse_preconditioner_max_linear_its(unsigned int i)
     107             : {
     108       29400 :   _reuse_preconditioner_max_linear_its = i;
     109       29400 : }
     110             : 
     111             : //------------------------------------------------------------------
     112             : // Explicit instantiations
     113             : template class LIBMESH_EXPORT NonlinearSolver<Number>;
     114             : 
     115             : } // namespace libMesh

Generated by: LCOV version 1.14