https://mooseframework.inl.gov
Loading...
Searching...
No Matches
NEML2Utils.C
Go to the documentation of this file.
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
13namespace NEML2Utils
14{
15#ifdef NEML2_ENABLED
16
17std::string
19{
20 switch (type)
21 {
23 return "TIME";
25 return "SCALAR";
27 return "FUNCTION";
29 return "VARIABLE";
31 return "MATERIAL";
32 default:
33 mooseError("Unknown MOOSE IO type.");
34 }
35}
36
37std::shared_ptr<neml2::Model>
38getModel(neml2::Factory & factory, const std::string & name, neml2::Dtype dtype)
39{
40 const auto prev_dtype = neml2::get_default_dtype();
41 neml2::set_default_dtype(dtype);
42 auto model = factory.get_model(name);
43 model->to(dtype);
44 neml2::set_default_dtype(prev_dtype);
45 return model;
46}
47#endif // NEML2_ENABLED
48
49static 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
52bool
53shouldCompute(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 if (problem.computingScalingJacobian())
59 return true;
60
62 return true;
63
64 if (problem.currentlyComputingJacobian())
65 return false;
66
67 return true;
68}
69
70std::string
71docstring(const std::string & desc)
72{
73#ifndef NEML2_ENABLED
74 return missing_neml2 + " (Original description: " + desc + ")";
75#else
76 return desc;
77#endif
78}
79
80void
82{
83#ifndef NEML2_ENABLED
85#endif
86}
87
88} // namespace NEML2Utils
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Generic class for solving transient nonlinear problems.
Definition SubProblem.h:79
virtual bool computingScalingJacobian() const =0
Getter for whether we're computing the scaling jacobian.
const bool & currentlyComputingJacobian() const
Returns true if the problem is in the process of computing the Jacobian.
Definition SubProblem.h:692
const bool & currentlyComputingResidualAndJacobian() const
Returns true if the problem is in the process of computing the residual and the Jacobian.
std::shared_ptr< neml2::Model > getModel(neml2::Factory &factory, const std::string &name, neml2::Dtype dtype=neml2::kFloat64)
Get the NEML2 Model.
Definition NEML2Utils.C:38
std::string docstring(const std::string &desc)
Augment docstring if NEML2 is not enabled.
Definition NEML2Utils.C:71
static const std::string missing_neml2
Definition NEML2Utils.C:49
bool shouldCompute(const SubProblem &)
Determine whether the NEML2 material model should be evaluated.
Definition NEML2Utils.C:53
void assertNEML2Enabled()
Assert that NEML2 is enabled.
Definition NEML2Utils.C:81
std::string stringify(MOOSEIOType type)
Definition NEML2Utils.C:18