https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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"
13#include "UserObject.h"
14
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
55Real
56FunctorIC::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
84RealGradient
85FunctorIC::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}
registerMooseObject("MooseApp", FunctorIC)
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object Note, if this is not block restricted,...
virtual bool blockRestricted() const
Returns true if this object has been restricted to a block.
bool hasPostprocessorValueByName(const PostprocessorName &name) const
Whether or not a Postprocessor value exists by a given name.
virtual bool hasVariable(const std::string &var_name) const override
Whether or not this problem has the variable.
virtual bool hasFunction(const std::string &name, const THREAD_ID tid=0)
Defines an initial condition using a functor.
Definition FunctorIC.h:19
static InputParameters validParams()
Definition FunctorIC.C:18
virtual RealGradient gradient(const Point &p) override
The value of the gradient at a point.
Definition FunctorIC.C:85
FunctorIC(const InputParameters &parameters)
Definition FunctorIC.C:31
const Moose::Functor< Real > & _functor
Function to evaluate to form the initial condition.
Definition FunctorIC.h:37
const Real _scaling
Scaling factor, to be able to use a functor with multiple ICs.
Definition FunctorIC.h:40
virtual Real value(const Point &p) override
The value of the variable at a point.
Definition FunctorIC.C:56
This is a template class that implements the workhorse compute and computeNodal methods.
const Node * _current_node
The current node if the point we are evaluating at also happens to be a node.
const Elem *const & _current_elem
The current element we are on will retrieving values at specific points in the domain.
MooseVariableField< T > & _var
The variable that this initial condition is acting upon.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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...
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.
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...
Definition MooseBase.h:471
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 ...
Definition MooseBase.h:457
virtual bool isNodalDefined() const =0
Is this variable defined at nodes.
An interface for accessing Moose::Functors for systems that do not care about automatic differentiati...
static InputParameters validParams()
bool parsesToReal(const std::string &input, Real *parsed_real)
Definition MooseUtils.C:100
StateArg currentState()
A structure that is used to evaluate Moose functors at an arbitrary physical point contained within a...
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.