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 14703 : FunctorIC::validParams() 19 : { 20 14703 : InputParameters params = InitialCondition::validParams(); 21 14703 : params += NonADFunctorInterface::validParams(); 22 14703 : params.addRequiredParam<MooseFunctorName>("functor", "The initial condition functor."); 23 : 24 14703 : 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 14703 : params.addParam<Real>("scaling_factor", 1, "Scaling factor to apply on the function"); 27 : 28 14703 : return params; 29 0 : } 30 : 31 162 : FunctorIC::FunctorIC(const InputParameters & parameters) 32 : : InitialCondition(parameters), 33 : NonADFunctorInterface(this), 34 162 : _functor(getFunctor<Real>("functor")), 35 324 : _scaling(getParam<Real>("scaling_factor")) 36 : { 37 : // Check supported and unsupported functors 38 162 : 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 162 : 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 158 : 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 42 : paramInfo("functor", 51 : "Functor materials or postprocessors should not depend on variables if used in a " 52 : "FunctorIC"); 53 158 : } 54 : 55 : Real 56 186 : 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 186 : 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 182 : if (_var.isNodalDefined()) 71 : { 72 158 : Moose::NodeArg node_arg = {_current_node, 73 158 : blockRestricted() ? &blockIDs() 74 158 : : &Moose::NodeArg::undefined_subdomain_connection}; 75 158 : return _scaling * _functor(node_arg, Moose::currentState()); 76 : } 77 : else 78 : { 79 24 : Moose::ElemPointArg elem_point = {_current_elem, p, false}; 80 24 : return _scaling * _functor(elem_point, Moose::currentState()); 81 : } 82 : } 83 : 84 : RealGradient 85 16 : FunctorIC::gradient(const Point & p) 86 : { 87 : // Use nodes for nodal-defined variables, elements for the others 88 16 : if (_var.isNodalDefined()) 89 : { 90 16 : Moose::NodeArg node_arg = {_current_node, 91 16 : blockRestricted() ? &blockIDs() 92 16 : : &Moose::NodeArg::undefined_subdomain_connection}; 93 16 : 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 : }