LCOV - code coverage report
Current view: top level - src/neml2/utils - NEML2Utils.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: fa5e60 Lines: 23 36 63.9 %
Date: 2026-06-24 08:03:36 Functions: 4 5 80.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #include "NEML2Utils.h"
      11             : #include "SubProblem.h"
      12             : 
      13             : namespace NEML2Utils
      14             : {
      15             : #ifdef NEML2_ENABLED
      16             : 
      17             : std::string
      18          41 : stringify(MOOSEIOType type)
      19             : {
      20          41 :   switch (type)
      21             :   {
      22           0 :     case NEML2Utils::MOOSEIOType::TIME:
      23           0 :       return "TIME";
      24           0 :     case NEML2Utils::MOOSEIOType::SCALAR:
      25           0 :       return "SCALAR";
      26           0 :     case NEML2Utils::MOOSEIOType::FUNCTION:
      27           0 :       return "FUNCTION";
      28          25 :     case NEML2Utils::MOOSEIOType::VARIABLE:
      29          50 :       return "VARIABLE";
      30          16 :     case NEML2Utils::MOOSEIOType::MATERIAL:
      31          32 :       return "MATERIAL";
      32           0 :     default:
      33           0 :       mooseError("Unknown MOOSE IO type.");
      34             :   }
      35             : }
      36             : 
      37             : std::shared_ptr<neml2::Model>
      38          50 : getModel(neml2::Factory & factory, const std::string & name, neml2::Dtype dtype)
      39             : {
      40          50 :   const auto prev_dtype = neml2::get_default_dtype();
      41          50 :   neml2::set_default_dtype(dtype);
      42          50 :   auto model = factory.get_model(name);
      43          50 :   model->to(dtype);
      44          50 :   neml2::set_default_dtype(prev_dtype);
      45          50 :   return model;
      46           0 : }
      47             : #endif // NEML2_ENABLED
      48             : 
      49             : static const std::string missing_neml2 = "The `NEML2` library is required but not enabled. Refer "
      50             :                                          "to the documentation for guidance on how to enable it.";
      51             : 
      52             : bool
      53       43134 : shouldCompute(const SubProblem & problem)
      54             : {
      55             :   // NEML2 computes residual and Jacobian together at EXEC_LINEAR
      56             :   // There is no work to be done at EXEC_NONLINEAR **UNLESS** we are computing the Jacobian for
      57             :   // automatic scaling.
      58       43134 :   if (problem.computingScalingJacobian())
      59         108 :     return true;
      60             : 
      61       43026 :   if (problem.currentlyComputingResidualAndJacobian())
      62           0 :     return true;
      63             : 
      64       43026 :   if (problem.currentlyComputingJacobian())
      65       14756 :     return false;
      66             : 
      67       28270 :   return true;
      68             : }
      69             : 
      70             : std::string
      71           0 : docstring(const std::string & desc)
      72             : {
      73             : #ifndef NEML2_ENABLED
      74           0 :   return missing_neml2 + " (Original description: " + desc + ")";
      75             : #else
      76           0 :   return desc;
      77             : #endif
      78             : }
      79             : 
      80             : void
      81         286 : assertNEML2Enabled()
      82             : {
      83             : #ifndef NEML2_ENABLED
      84           3 :   mooseError(missing_neml2);
      85             : #endif
      86         283 : }
      87             : 
      88             : } // namespace NEML2Utils

Generated by: LCOV version 1.14