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 "FunctorChangeFunctorMaterial.h" 11 : 12 : registerMooseObject("MooseApp", FunctorChangeFunctorMaterial); 13 : registerMooseObject("MooseApp", ADFunctorChangeFunctorMaterial); 14 : 15 : template <bool is_ad> 16 : InputParameters 17 6247 : FunctorChangeFunctorMaterialTempl<is_ad>::validParams() 18 : { 19 6247 : InputParameters params = FunctorMaterial::validParams(); 20 18741 : params.set<ExecFlagEnum>("execute_on") = {EXEC_ALWAYS}; 21 : 22 24988 : params.addRequiredParam<MooseFunctorName>("functor", "Functor for which to compute the change"); 23 24988 : MooseEnum change_over("time_step nonlinear fixed_point"); 24 24988 : change_over.addDocumentation("time_step", "Over the time step"); 25 24988 : change_over.addDocumentation("nonlinear", "Over the nonlinear iteration"); 26 24988 : change_over.addDocumentation("fixed_point", "Over the MultiApp fixed point iteration"); 27 24988 : params.addRequiredParam<MooseEnum>( 28 : "change_over", change_over, "Interval over which to compute the change"); 29 24988 : params.addRequiredParam<bool>("take_absolute_value", 30 : "If true, take the absolute value of the change."); 31 24988 : params.addRequiredParam<std::string>("prop_name", 32 : "The name to give the functor material property"); 33 : 34 6247 : 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 12494 : return params; 39 12494 : } 40 : 41 : template <bool is_ad> 42 65 : FunctorChangeFunctorMaterialTempl<is_ad>::FunctorChangeFunctorMaterialTempl( 43 : const InputParameters & parameters) 44 : : FunctorMaterial(parameters), 45 65 : _functor(getFunctor<GenericReal<is_ad>>("functor")), 46 130 : _ref_state(referenceState(getParam<MooseEnum>("change_over"))), 47 130 : _take_absolute_value(getParam<bool>("take_absolute_value")), 48 195 : _prop_name(getParam<std::string>("prop_name")) 49 : { 50 : // Request the previous fixed point solution be saved for the relevant systems 51 195 : if (_fe_problem.hasAuxiliaryVariable(getParam<MooseFunctorName>("functor"))) 52 13 : _fe_problem.needsPreviousMultiAppFixedPointIterationAuxiliary(true); 53 195 : if (_fe_problem.hasSolverVariable(getParam<MooseFunctorName>("functor"))) 54 52 : _fe_problem.needsPreviousMultiAppFixedPointIterationSolution( 55 208 : true, _fe_problem.getSystem(getParam<MooseFunctorName>("functor")).number()); 56 : 57 65 : const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end()); 58 65 : addFunctorProperty<GenericReal<is_ad>>( 59 : _prop_name, 60 8146 : [this](const auto & r, const auto & t) -> GenericReal<is_ad> 61 : { 62 : mooseAssert(t == Moose::currentState(), 63 : "The functor properties defined by (AD)FunctorChangeFunctorMaterial objects " 64 : "may only be evaluated at the current state."); 65 : 66 8146 : const auto change = _functor(r, t) - _functor(r, _ref_state); 67 8146 : if (_take_absolute_value) 68 : { 69 : using std::abs; 70 0 : return abs(change); 71 : } 72 : else 73 8146 : return change; 74 8146 : }, 75 : clearance_schedule); 76 65 : } 77 : 78 : template <bool is_ad> 79 : Moose::StateArg 80 65 : FunctorChangeFunctorMaterialTempl<is_ad>::referenceState(const MooseEnum & change_over) const 81 : { 82 65 : if (change_over == "time_step") 83 13 : return Moose::oldState(); 84 52 : else if (change_over == "nonlinear") 85 : { 86 13 : _fe_problem.needSolutionState(1, Moose::SolutionIterationType::Nonlinear); 87 13 : return Moose::previousNonlinearState(); 88 : } 89 39 : else if (change_over == "fixed_point") 90 : { 91 39 : _fe_problem.needSolutionState(1, Moose::SolutionIterationType::FixedPoint); 92 39 : return Moose::previousFixedPointState(); 93 : } 94 : else 95 0 : mooseError("Invalid value"); 96 : } 97 : 98 : template class FunctorChangeFunctorMaterialTempl<false>; 99 : template class FunctorChangeFunctorMaterialTempl<true>;