https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
15template <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(
24 "time_step nonlinear fixed_point multiapp_fixed_point multisystem_fixed_point");
25 change_over.addDocumentation("time_step", "Over the time step");
26 change_over.addDocumentation("nonlinear", "Over the nonlinear iteration");
27 change_over.addDocumentation("multiapp_fixed_point", "Over the MultiApp fixed point iteration");
28 change_over.addDocumentation("multisystem_fixed_point",
29 "Over the multi-system fixed point iteration");
31 "change_over", change_over, "Interval over which to compute the change");
32 params.addRequiredParam<bool>("take_absolute_value",
33 "If true, take the absolute value of the change.");
34 params.addRequiredParam<std::string>("prop_name",
35 "The name to give the functor material property");
36
38 "Adds a functor material property that computes the change in a functor value over a time "
39 "step, fixed point iteration, or nonlinear iteration.");
40
41 return params;
42}
43
44template <bool is_ad>
46 const InputParameters & parameters)
47 : FunctorMaterial(parameters),
48 _functor(getFunctor<GenericReal<is_ad>>("functor")),
49 _ref_state(referenceState(getParam<MooseEnum>("change_over"))),
50 _take_absolute_value(getParam<bool>("take_absolute_value")),
51 _prop_name(getParam<std::string>("prop_name"))
52{
53 // Request the previous fixed point solution be saved for the relevant systems
54 const auto & change_over = getParam<MooseEnum>("change_over");
55 if (change_over == "multiapp_fixed_point" || change_over == "fixed_point")
56 {
57 if (_fe_problem.hasAuxiliaryVariable(getParam<MooseFunctorName>("functor")))
59 if (_fe_problem.hasSolverVariable(getParam<MooseFunctorName>("functor")))
61 true, _fe_problem.getSystem(getParam<MooseFunctorName>("functor")).number());
62 }
63 else if (change_over == "multisystem_fixed_point")
64 {
65 if (_fe_problem.hasAuxiliaryVariable(getParam<MooseFunctorName>("functor")))
67 if (_fe_problem.hasSolverVariable(getParam<MooseFunctorName>("functor")))
69 true, _fe_problem.getSystem(getParam<MooseFunctorName>("functor")).number());
70 }
71
72 if (change_over == "fixed_point")
74 "'change_over' option 'fixed_point' is deprecated; use 'multiapp_fixed_point' instead.");
75
76 const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end());
77 addFunctorProperty<GenericReal<is_ad>>(
79 [this](const auto & r, const auto & t) -> GenericReal<is_ad>
80 {
81 mooseAssert(t == Moose::currentState(),
82 "The functor properties defined by (AD)FunctorChangeFunctorMaterial objects "
83 "may only be evaluated at the current state.");
84
85 const auto change = _functor(r, t) - _functor(r, _ref_state);
87 {
88 using std::abs;
89 return abs(change);
90 }
91 else
92 return change;
93 },
94 clearance_schedule);
95}
96
97template <bool is_ad>
100{
101 if (change_over == "time_step")
102 return Moose::oldState();
103 else if (change_over == "nonlinear")
104 {
105 _fe_problem.needSolutionState(1, Moose::SolutionIterationType::Nonlinear);
107 }
108 else if (change_over == "multiapp_fixed_point" || change_over == "fixed_point")
109 {
110 _fe_problem.needSolutionState(1, Moose::SolutionIterationType::MultiAppFixedPoint);
112 }
113 else if (change_over == "multisystem_fixed_point")
114 {
115 _fe_problem.needSolutionState(1, Moose::SolutionIterationType::MultiSystemFixedPoint);
117 }
118 else
119 mooseError("Invalid value");
120}
121
registerMooseObject("MooseApp", FunctorChangeFunctorMaterial)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition MooseError.h:363
Moose::GenericType< Real, is_ad > GenericReal
Definition MooseTypes.h:698
const ExecFlagType EXEC_ALWAYS
Definition Moose.C:53
A MultiMooseEnum object to hold "execute_on" flags.
void needsPreviousMultiAppFixedPointIterationAuxiliary(bool state)
Set a flag that indicated that user required values for the previous multiapp fixed point iterate for...
void needsPreviousMultiSystemFixedPointIterationAuxiliary(bool state)
Set a flag that indicates that user requires values for the previous multi-system fixed point iterate...
bool hasSolverVariable(const std::string &var_name) const
void needsPreviousMultiAppFixedPointIterationSolution(bool needed, const unsigned int solver_sys_num)
Set a flag that indicated that user required values for the previous multiapp fixed point iterate for...
void needsPreviousMultiSystemFixedPointIterationSolution(bool needed, const unsigned int solver_sys_num)
Set a flag that indicates that user requires values for the previous multi-system fixed point iterate...
virtual libMesh::System & getSystem(const std::string &var_name) override
Returns the equation system containing the variable provided.
Adds a functor material property that computes the change in a functor value over a time step,...
Moose::StateArg referenceState(const MooseEnum &change_over) const
Returns the state argument to use for the reference value.
const Moose::StateArg _ref_state
Reference value state argument.
const std::string & _prop_name
Name to give functor material property.
const bool _take_absolute_value
If true, take the absolute value of the change.
FunctorChangeFunctorMaterialTempl(const InputParameters &parameters)
const Moose::Functor< GenericReal< is_ad > > & _functor
Functor for which to evaluate change.
FunctorMaterials compute functor material properties.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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...
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
FEProblemBase & _fe_problem
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
MooseEnumIterator end() const
MooseEnumIterator begin() const
Returns a begin/end iterator to all of the set values in the enum.
const ExecFlagEnum & _execute_enum
Execute settings for this object.
virtual bool hasAuxiliaryVariable(const std::string &var_name) const
Whether or not this problem has this auxiliary variable.
Definition SubProblem.C:812
unsigned int number() const
StateArg previousMultiSystemFixedPointState()
StateArg previousNonlinearState()
StateArg oldState()
StateArg currentState()
StateArg previousMultiAppFixedPointState()
State argument for evaluating functors.