https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MaterialAuxBase.h
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#pragma once
11
12// MOOSE includes
13#include "AuxKernel.h"
14#include "Assembly.h"
15
16#include <unordered_set>
17
22template <typename T, bool is_ad, bool is_functor = false, typename RT = Real>
24{
25public:
27
33
35 using PropertyType = typename std::conditional<is_functor,
38
39protected:
40 virtual RT computeValue() override;
41
43 virtual void checkFullValue() {}
44
46 virtual RT getRealValue() = 0;
47
50
52 const unsigned int _selected_qp;
53
56
57private:
60
62 const Real _factor;
63
65 const RT _offset;
66
69};
70
71template <typename T, bool is_ad, bool is_functor, typename RT>
74{
76 if constexpr (is_functor)
77 params.addRequiredParam<MooseFunctorName>("functor", "The functor name.");
78 else
79 params.addRequiredParam<MaterialPropertyName>("property", "The material property name.");
80
81 params.addParam<Real>(
82 "factor", 1, "The factor by which to multiply your material property for visualization");
83 params.addParam<RT>("offset", 0, "The offset to add to your material property for visualization");
84
85 if constexpr (!is_functor)
86 {
87 params.addParam<unsigned int>(
88 "selected_qp",
89 "Evaluate the material property at a specified quadrature point. This only needs "
90 "to be used if you are interested in a particular quadrature point in each element. "
91 "Otherwise do not include this parameter in your input file.");
92 params.addParamNamesToGroup("selected_qp", "Advanced");
93 }
94
95 return params;
96}
97
98template <typename T, bool is_ad, bool is_functor, typename RT>
100 const InputParameters & parameters)
101 : AuxKernelTempl<RT>(parameters),
102 _prop(getPropertyHelper()),
103 _selected_qp(this->isParamValid("selected_qp")
104 ? this->template getParam<unsigned int>("selected_qp")
105 : libMesh::invalid_uint),
106 _factor(this->template getParam<Real>("factor")),
107 _offset(this->template getParam<RT>("offset")),
108 _current_subdomain_id(this->_assembly.currentSubdomainID())
109{
110}
111
112template <typename T, bool is_ad, bool is_functor, typename RT>
115{
116 if constexpr (is_functor)
117 return this->template getFunctor<Moose::GenericType<T, is_ad>>("functor");
118 else
119 return this->template getGenericMaterialProperty<T, is_ad>("property");
120}
121
122template <typename T, bool is_ad, bool is_functor, typename RT>
123RT
125{
126 // Functor Values
127 if constexpr (is_functor)
128 {
129 if (this->isNodal())
130 {
131 const std::set<SubdomainID> sub_id_set = {_current_subdomain_id};
132 const Moose::NodeArg node_arg{this->_current_node, &sub_id_set};
133 const auto state = this->determineState();
134 _full_value = _prop(node_arg, state);
135 }
136 else
137 {
138 const auto elem_arg = this->makeElemArg(this->_current_elem);
139 const auto state = this->determineState();
140 _full_value = _prop(elem_arg, state);
141 }
142 }
143 // Material Properties
144 else
145 {
146 if (_selected_qp != libMesh::invalid_uint)
147 {
148 if (_selected_qp >= this->_q_point.size())
149 {
150 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
151 this->paramError("selected_qp",
152 "Trying to evaluate qp ",
153 _selected_qp,
154 " but there are only ",
155 this->_q_point.size(),
156 " quadrature points in the element");
157 }
158 _full_value = _prop[_selected_qp];
159 }
160 else
161 _full_value = _prop[this->_qp];
162 }
163
164 checkFullValue();
165 return _factor * getRealValue() + _offset;
166}
167
168template <typename T = Real>
typename GenericMaterialPropertyStruct< T, is_ad >::type GenericMaterialProperty
void ErrorVector unsigned int
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
Definition AuxKernel.h:28
static InputParameters validParams()
Definition AuxKernel.C:27
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
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...
A base class for the various Material related AuxKernal objects.
const Real _factor
Multiplier for the material property.
Moose::GenericType< T, is_ad > _full_value
T Value evaluated from either the property or the functor.
const RT _offset
Value to be added to the material property.
virtual RT getRealValue()=0
Returns material property values at quadrature points.
const unsigned int _selected_qp
Evaluate at this quadrature point only.
virtual void checkFullValue()
Perform a sanity check on the retrieved value (e.g. to check dynamic sizes)
const SubdomainID & _current_subdomain_id
ID of the subdomain currently being iterated over.
const PropertyType & getPropertyHelper()
Helper function to retrieve the property or functor.
static InputParameters validParams()
const PropertyType & _prop
(Functor)Material property for this AuxKernel
virtual RT computeValue() override
Compute and return the value of the aux variable.
typename std::conditional< is_functor, Moose::Functor< Moose::GenericType< T, is_ad > >, GenericMaterialProperty< T, is_ad > >::type PropertyType
Functors really only work for Real and RealVectorValue for now :(.
MaterialAuxBaseTempl(const InputParameters &parameters)
Class constructor.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
const std::string & type() const
Get the type of this class.
Definition MooseBase.h:93
This is a wrapper that forwards calls to the implementation, which can be switched out at any time wi...
typename std::conditional< is_ad, typename ADType< T >::type, T >::type GenericType
Definition MooseTypes.h:694
spin_mutex spin_mtx
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
const unsigned int invalid_uint