https://mooseframework.inl.gov
FunctorIC.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 
10 #include "FunctorIC.h"
11 #include "Function.h"
12 #include "MooseFunctorArguments.h"
13 #include "UserObject.h"
14 
15 registerMooseObject("MooseApp", FunctorIC);
16 
19 {
22  params.addRequiredParam<MooseFunctorName>("functor", "The initial condition functor.");
23 
24  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  params.addParam<Real>("scaling_factor", 1, "Scaling factor to apply on the function");
27 
28  return params;
29 }
30 
32  : InitialCondition(parameters),
34  _functor(getFunctor<Real>("functor")),
35  _scaling(getParam<Real>("scaling_factor"))
36 {
37  // Check supported and unsupported functors
38  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  if (_fe_problem.hasVariable(functor_name))
42  paramError("functor",
43  "Initializing a variable with another variable is not supported at this time");
44  // Functions are supported
45  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  paramInfo("functor",
51  "Functor materials or postprocessors should not depend on variables if used in a "
52  "FunctorIC");
53 }
54 
55 Real
56 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  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  if (_var.isNodalDefined())
71  {
72  Moose::NodeArg node_arg = {_current_node,
75  return _scaling * _functor(node_arg, Moose::currentState());
76  }
77  else
78  {
79  Moose::ElemPointArg elem_point = {_current_elem, p, false};
80  return _scaling * _functor(elem_point, Moose::currentState());
81  }
82 }
83 
85 FunctorIC::gradient(const Point & p)
86 {
87  // Use nodes for nodal-defined variables, elements for the others
88  if (_var.isNodalDefined())
89  {
90  Moose::NodeArg node_arg = {_current_node,
93  return _scaling * _functor.gradient(node_arg, Moose::currentState());
94  }
95  else
96  {
97  Moose::ElemPointArg elem_point = {_current_elem, p, false};
98  return _scaling * _functor.gradient(elem_point, Moose::currentState());
99  }
100 }
An interface for accessing Moose::Functors for systems that do not care about automatic differentiati...
bool parsesToReal(const std::string &input)
Check if the input string can be parsed into a Real.
Definition: MooseUtils.C:89
virtual bool hasVariable(const std::string &var_name) const override
Whether or not this problem has the variable.
static const std::set< SubdomainID > undefined_subdomain_connection
A static member that can be used when the connection of a node to subdomains is unknown.
This is a template class that implements the workhorse compute and computeNodal methods.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
const Moose::Functor< Real > & _functor
Function to evaluate to form the initial condition.
Definition: FunctorIC.h:37
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object Note, if this is not block restricted, this function returns all mesh subdomain ids.
virtual bool blockRestricted() const
Returns true if this object has been restricted to a block.
A structure that is used to evaluate Moose functors at an arbitrary physical point contained within a...
registerMooseObject("MooseApp", FunctorIC)
MooseVariableField< T > & _var
The variable that this initial condition is acting upon.
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...
FunctorIC(const InputParameters &parameters)
Definition: FunctorIC.C:31
const Node * _current_node
The current node if the point we are evaluating at also happens to be a node.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
static InputParameters validParams()
Definition: FunctorIC.C:18
bool hasPostprocessorValueByName(const PostprocessorName &name) const
Whether or not a Postprocessor value exists by a given name.
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
virtual bool isNodalDefined() const =0
Is this variable defined at nodes.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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...
static InputParameters validParams()
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
const Elem *const & _current_elem
The current element we are on will retrieving values at specific points in the domain.
const UserObject & getUserObjectBase(const std::string &name, const THREAD_ID tid=0) const
Get the user object by its name.
virtual RealGradient gradient(const Point &p) override
The value of the gradient at a point.
Definition: FunctorIC.C:85
Defines an initial condition using a functor.
Definition: FunctorIC.h:18
const Real _scaling
Scaling factor, to be able to use a functor with multiple ICs.
Definition: FunctorIC.h:40
virtual bool hasFunction(const std::string &name, const THREAD_ID tid=0)
virtual Real value(const Point &p) override
The value of the variable at a point.
Definition: FunctorIC.C:56
void paramInfo(const std::string &param, Args... args) const
Emits an informational message prefixed with the file and line number of the given param (from the in...
StateArg currentState()