https://mooseframework.inl.gov
FunctorChangeFunctorMaterial.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 
11 
14 
15 template <bool is_ad>
18 {
20  params.set<ExecFlagEnum>("execute_on") = {EXEC_ALWAYS};
21 
22  params.addRequiredParam<MooseFunctorName>("functor", "Functor for which to compute the change");
23  MooseEnum change_over("time_step nonlinear fixed_point");
24  change_over.addDocumentation("time_step", "Over the time step");
25  change_over.addDocumentation("nonlinear", "Over the nonlinear iteration");
26  change_over.addDocumentation("fixed_point", "Over the MultiApp fixed point iteration");
28  "change_over", change_over, "Interval over which to compute the change");
29  params.addRequiredParam<bool>("take_absolute_value",
30  "If true, take the absolute value of the change.");
31  params.addRequiredParam<std::string>("prop_name",
32  "The name to give the functor material property");
33 
34  params.addClassDescription(
35  "Adds a functor material property that computes the change in a functor value over a time "
36  "step, fixed point iteration, or nonlinear iteration.");
37 
38  return params;
39 }
40 
41 template <bool is_ad>
43  const InputParameters & parameters)
44  : FunctorMaterial(parameters),
45  _functor(getFunctor<GenericReal<is_ad>>("functor")),
46  _ref_state(referenceState(getParam<MooseEnum>("change_over"))),
47  _take_absolute_value(getParam<bool>("take_absolute_value")),
48  _prop_name(getParam<std::string>("prop_name"))
49 {
50  const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end());
51  addFunctorProperty<GenericReal<is_ad>>(
52  _prop_name,
53  [this](const auto & r, const auto & t) -> GenericReal<is_ad>
54  {
55  mooseAssert(t == Moose::currentState(),
56  "The functor properties defined by (AD)FunctorChangeFunctorMaterial objects "
57  "may only be evaluated at the current state.");
58 
59  const auto change = _functor(r, t) - _functor(r, _ref_state);
61  return std::abs(change);
62  else
63  return change;
64  },
65  clearance_schedule);
66 }
67 
68 template <bool is_ad>
71 {
72  if (change_over == "time_step")
73  return Moose::oldState();
74  else if (change_over == "nonlinear")
75  {
76  _fe_problem.needSolutionState(1, Moose::SolutionIterationType::Nonlinear);
78  }
79  else if (change_over == "fixed_point")
80  {
81  _fe_problem.needSolutionState(1, Moose::SolutionIterationType::FixedPoint);
83  }
84  else
85  mooseError("Invalid value");
86 }
87 
const Moose::Functor< GenericReal< is_ad > > & _functor
Functor for which to evaluate change.
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
Definition: EigenADReal.h:42
Moose::GenericType< Real, is_ad > GenericReal
Definition: MooseTypes.h:649
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
StateArg oldState()
static InputParameters validParams()
MooseEnumIterator begin() const
Returns a begin/end iterator to all of the set values in the enum.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
StateArg previousFixedPointState()
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
registerMooseObject("MooseApp", FunctorChangeFunctorMaterial)
MooseEnumIterator end() const
const ExecFlagType EXEC_ALWAYS
Definition: Moose.C:49
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
FunctorMaterials compute functor material properties.
FunctorChangeFunctorMaterialTempl(const InputParameters &parameters)
Moose::StateArg referenceState(const MooseEnum &change_over) const
Returns the state argument to use for the reference value.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
const ExecFlagEnum & _execute_enum
Execute settings for this object.
Adds a functor material property that computes the change in a functor value over a time step...
const Moose::StateArg _ref_state
Reference value state argument.
const std::string & _prop_name
Name to give functor material property.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
State argument for evaluating functors.
const bool _take_absolute_value
If true, take the absolute value of the change.
StateArg previousNonlinearState()
StateArg currentState()