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 "FunctorIC.h" 11 : #include "Function.h" 12 : #include "MooseFunctorArguments.h" 13 : #include "UserObject.h" 14 : 15 : registerMooseObject("MooseApp", FunctorIC); 16 : 17 : InputParameters 18 14731 : FunctorIC::validParams() 19 : { 20 14731 : InputParameters params = InitialCondition::validParams(); 21 14731 : params += NonADFunctorInterface::validParams(); 22 14731 : params.addRequiredParam<MooseFunctorName>("functor", "The initial condition functor."); 23 : 24 14731 : params.addClassDescription("An initial condition that uses a normal function of x, y, z to " 25 : "produce values (and optionally gradients) for a field variable."); 26 14731 : params.addParam<Real>("scaling_factor", 1, "Scaling factor to apply on the function"); 27 : 28 14731 : return params; 29 0 : } 30 : 31 171 : FunctorIC::FunctorIC(const InputParameters & parameters) 32 : : InitialCondition(parameters), 33 : NonADFunctorInterface(this), 34 171 : _functor(getFunctor<Real>("functor")), 35 342 : _scaling(getParam<Real>("scaling_factor")) 36 : { 37 : // Check supported and unsupported functors 38 171 : const auto & functor_name = getParam<MooseFunctorName>("functor"); 39 : // See https://github.com/idaholab/moose/issues/19396 for discussion of the functor restrictions. 40 : // Variables: need to be initialized before. we dont support this at the time 41 171 : if (_fe_problem.hasVariable(functor_name)) 42 4 : paramError("functor", 43 : "Initializing a variable with another variable is not supported at this time"); 44 : // Functions are supported 45 167 : else if (_fe_problem.hasFunction(functor_name) || MooseUtils::parsesToReal(functor_name)) 46 : { 47 : } 48 : // Functor materials: fairly high risk since they could depend on variables 49 : else 50 44 : paramInfo("functor", 51 : "Functor materials or postprocessors should not depend on variables if used in a " 52 : "FunctorIC"); 53 167 : } 54 : 55 : Real 56 207 : FunctorIC::value(const Point & p) 57 : { 58 : // TODO: This is because ICs are created before PPs. This would be nicer in an initialSetup of the 59 : // IC which do not currently exist 60 207 : mooseDoOnce( // PPs: need to execute before the ICs are 61 : const auto & functor_name = getParam<MooseFunctorName>("functor"); 62 : if (_fe_problem.hasPostprocessorValueByName(functor_name)) { 63 : if (!(_fe_problem.getUserObjectBase(functor_name).isParamValid("force_preic") && 64 : _fe_problem.getUserObjectBase(functor_name).getParam<bool>("force_preic"))) 65 : paramError("functor", 66 : "Functor is a postprocessor and does not have 'force_preic' set to true"); 67 : }); 68 : 69 : // Use nodes for nodal-defined variables, elements for the others 70 203 : if (_var.isNodalDefined()) 71 : { 72 176 : Moose::NodeArg node_arg = {_current_node, 73 176 : blockRestricted() ? &blockIDs() 74 176 : : &Moose::NodeArg::undefined_subdomain_connection}; 75 176 : return _scaling * _functor(node_arg, Moose::currentState()); 76 : } 77 : else 78 : { 79 27 : Moose::ElemPointArg elem_point = {_current_elem, p, false}; 80 27 : return _scaling * _functor(elem_point, Moose::currentState()); 81 : } 82 : } 83 : 84 : RealGradient 85 18 : FunctorIC::gradient(const Point & p) 86 : { 87 : // Use nodes for nodal-defined variables, elements for the others 88 18 : if (_var.isNodalDefined()) 89 : { 90 18 : Moose::NodeArg node_arg = {_current_node, 91 18 : blockRestricted() ? &blockIDs() 92 18 : : &Moose::NodeArg::undefined_subdomain_connection}; 93 18 : return _scaling * _functor.gradient(node_arg, Moose::currentState()); 94 : } 95 : else 96 : { 97 0 : Moose::ElemPointArg elem_point = {_current_elem, p, false}; 98 0 : return _scaling * _functor.gradient(elem_point, Moose::currentState()); 99 : } 100 : }