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 28665 : FunctorChangeFunctorMaterialTempl<is_ad>::validParams() 18 : { 19 28665 : InputParameters params = FunctorMaterial::validParams(); 20 85995 : params.set<ExecFlagEnum>("execute_on") = {EXEC_ALWAYS}; 21 : 22 114660 : params.addRequiredParam<MooseFunctorName>("functor", "Functor for which to compute the change"); 23 114660 : MooseEnum change_over("time_step nonlinear fixed_point"); 24 114660 : change_over.addDocumentation("time_step", "Over the time step"); 25 114660 : change_over.addDocumentation("nonlinear", "Over the nonlinear iteration"); 26 114660 : change_over.addDocumentation("fixed_point", "Over the MultiApp fixed point iteration"); 27 114660 : params.addRequiredParam<MooseEnum>( 28 : "change_over", change_over, "Interval over which to compute the change"); 29 114660 : params.addRequiredParam<bool>("take_absolute_value", 30 : "If true, take the absolute value of the change."); 31 114660 : params.addRequiredParam<std::string>("prop_name", 32 : "The name to give the functor material property"); 33 : 34 28665 : 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 57330 : return params; 39 57330 : } 40 : 41 : template <bool is_ad> 42 70 : FunctorChangeFunctorMaterialTempl<is_ad>::FunctorChangeFunctorMaterialTempl( 43 : const InputParameters & parameters) 44 : : FunctorMaterial(parameters), 45 70 : _functor(getFunctor<GenericReal<is_ad>>("functor")), 46 140 : _ref_state(referenceState(getParam<MooseEnum>("change_over"))), 47 140 : _take_absolute_value(getParam<bool>("take_absolute_value")), 48 210 : _prop_name(getParam<std::string>("prop_name")) 49 : { 50 70 : const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end()); 51 70 : addFunctorProperty<GenericReal<is_ad>>( 52 : _prop_name, 53 9164 : [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 9164 : const auto change = _functor(r, t) - _functor(r, _ref_state); 60 9164 : if (_take_absolute_value) 61 0 : return std::abs(change); 62 : else 63 9164 : return change; 64 9164 : }, 65 : clearance_schedule); 66 70 : } 67 : 68 : template <bool is_ad> 69 : Moose::StateArg 70 70 : FunctorChangeFunctorMaterialTempl<is_ad>::referenceState(const MooseEnum & change_over) const 71 : { 72 70 : if (change_over == "time_step") 73 14 : return Moose::oldState(); 74 56 : else if (change_over == "nonlinear") 75 : { 76 14 : _fe_problem.needSolutionState(1, Moose::SolutionIterationType::Nonlinear); 77 14 : return Moose::previousNonlinearState(); 78 : } 79 42 : else if (change_over == "fixed_point") 80 : { 81 42 : _fe_problem.needSolutionState(1, Moose::SolutionIterationType::FixedPoint); 82 42 : return Moose::previousFixedPointState(); 83 : } 84 : else 85 0 : mooseError("Invalid value"); 86 : } 87 : 88 : template class FunctorChangeFunctorMaterialTempl<false>; 89 : template class FunctorChangeFunctorMaterialTempl<true>;