https://mooseframework.inl.gov
Loading...
Searching...
No Matches
VectorCompositeFunctor.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#include "MooseFunctor.h"
13#include "libmesh/vector_value.h"
14
15namespace Moose
16{
20template <typename T>
21class VectorCompositeFunctor : public FunctorBase<VectorValue<T>>
22{
23public:
24 template <typename U>
26
30
34 VectorCompositeFunctor(const MooseFunctorName & name,
35 const FunctorBase<T> & x_comp,
36 const FunctorBase<T> & y_comp,
37 const FunctorBase<T> & z_comp);
38
42 VectorCompositeFunctor(const MooseFunctorName & name,
43 const FunctorBase<T> & x_comp,
44 const FunctorBase<T> & y_comp);
45
49 VectorCompositeFunctor(const MooseFunctorName & name, const FunctorBase<T> & x_comp);
50
51 virtual bool hasBlocks(SubdomainID sub_id) const override
52 {
53 const bool ret = _x_comp.hasBlocks(sub_id);
54 if (_has_y)
55 mooseAssert(ret == _y_comp.hasBlocks(sub_id), "x and y block restriction don't agree");
56 if (_has_z)
57 mooseAssert(ret == _z_comp.hasBlocks(sub_id), "x and z block restriction don't agree");
58 return ret;
59 }
60
61 bool supportsFaceArg() const override;
62 bool supportsElemSideQpArg() const override;
63
64private:
65 ValueType evaluate(const ElemArg & elem_arg, const StateArg & state) const override;
66 ValueType evaluate(const FaceArg & face, const StateArg & state) const override;
67 ValueType evaluate(const ElemQpArg & elem_qp, const StateArg & state) const override;
68 ValueType evaluate(const ElemSideQpArg & elem_side_qp, const StateArg & state) const override;
69 ValueType evaluate(const ElemPointArg & elem_point_arg, const StateArg & state) const override;
70 ValueType evaluate(const NodeArg & node_arg, const StateArg & state) const override;
71
72 using FunctorBase<VectorValue<T>>::evaluateGradient;
73 GradientType evaluateGradient(const ElemArg & elem_arg, const StateArg & state) const override;
74
75 using FunctorBase<VectorValue<T>>::evaluateDot;
76 DotType evaluateDot(const FaceArg & face_arg, const StateArg & state) const override;
77 DotType evaluateDot(const ElemArg & elem_arg, const StateArg & state) const override;
78
81 std::unique_ptr<ConstantFunctor<T>> _y_constant;
82
85 std::unique_ptr<ConstantFunctor<T>> _z_constant;
86
93
95 const bool _has_y;
96
98 const bool _has_z;
99};
100
101template <typename T>
103 const FunctorBase<T> & x_comp,
104 const FunctorBase<T> & y_comp,
105 const FunctorBase<T> & z_comp)
106 : FunctorBase<VectorValue<T>>(name),
107 _x_comp(x_comp),
108 _y_comp(y_comp),
109 _z_comp(z_comp),
110 _has_y(true),
111 _has_z(true)
112{
113}
114
115template <typename T>
117 const FunctorBase<T> & x_comp,
118 const FunctorBase<T> & y_comp)
119 : FunctorBase<VectorValue<T>>(name),
120 _z_constant(std::make_unique<ConstantFunctor>(T(0))),
121 _x_comp(x_comp),
122 _y_comp(y_comp),
123 _z_comp(*_z_constant),
124 _has_y(true),
125 _has_z(false)
126{
127}
128
129template <typename T>
131 const FunctorBase<T> & x_comp)
132 : FunctorBase<VectorValue<T>>(name),
133 _y_constant(std::make_unique<ConstantFunctor>(T(0))),
134 _z_constant(std::make_unique<ConstantFunctor>(T(0))),
135 _x_comp(x_comp),
136 _y_comp(*_y_constant),
137 _z_comp(*_z_constant),
138 _has_y(false),
139 _has_z(false)
140{
141}
142
143template <typename T>
144bool
146{
147 if (!_x_comp.supportsFaceArg())
148 return false;
149 if (_has_y && !_y_comp.supportsFaceArg())
150 return false;
151 if (_has_z && !_z_comp.supportsFaceArg())
152 return false;
153 return true;
154}
155
156template <typename T>
157bool
159{
160 if (!_x_comp.supportsElemSideQpArg())
161 return false;
162 if (_has_y && !_y_comp.supportsElemSideQpArg())
163 return false;
164 if (_has_z && !_z_comp.supportsElemSideQpArg())
165 return false;
166 return true;
167}
168
169template <typename T>
171VectorCompositeFunctor<T>::evaluate(const ElemArg & elem_arg, const StateArg & state) const
172{
173 return {_x_comp(elem_arg, state), _y_comp(elem_arg, state), _z_comp(elem_arg, state)};
174}
175
176template <typename T>
178VectorCompositeFunctor<T>::evaluate(const FaceArg & face, const StateArg & state) const
179{
180 return {_x_comp(face, state), _y_comp(face, state), _z_comp(face, state)};
181}
182
183template <typename T>
185VectorCompositeFunctor<T>::evaluate(const ElemQpArg & elem_qp, const StateArg & state) const
186{
187 return {_x_comp(elem_qp, state), _y_comp(elem_qp, state), _z_comp(elem_qp, state)};
188}
189
190template <typename T>
193 const StateArg & state) const
194{
195 return {_x_comp(elem_side_qp, state), _y_comp(elem_side_qp, state), _z_comp(elem_side_qp, state)};
196}
197
198template <typename T>
201 const StateArg & state) const
202{
203 return {_x_comp(elem_point_arg, state),
204 _y_comp(elem_point_arg, state),
205 _z_comp(elem_point_arg, state)};
206}
207
208template <typename T>
210VectorCompositeFunctor<T>::evaluate(const NodeArg & node_arg, const StateArg & state) const
211{
212 return {_x_comp(node_arg, state), _y_comp(node_arg, state), _z_comp(node_arg, state)};
213}
214
215template <typename T>
218{
219 return {_x_comp.gradient(elem_arg, state),
220 _y_comp.gradient(elem_arg, state),
221 _z_comp.gradient(elem_arg, state)};
222}
223
224template <typename T>
226VectorCompositeFunctor<T>::evaluateDot(const FaceArg & face_arg, const StateArg & state) const
227{
228 return {_x_comp.dot(face_arg, state), _y_comp.dot(face_arg, state), _z_comp.dot(face_arg, state)};
229}
230
231template <typename T>
233VectorCompositeFunctor<T>::evaluateDot(const ElemArg & elem_arg, const StateArg & state) const
234{
235 return {_x_comp.dot(elem_arg, state), _y_comp.dot(elem_arg, state), _z_comp.dot(elem_arg, state)};
236}
237}
subdomain_id_type SubdomainID
Class template for creating constant functors.
Base class template for functor objects.
typename FunctorReturnType< VectorValue< T >, FunctorEvaluationKind::Gradient >::type GradientType
This rigmarole makes it so that a user can create functors that return containers (std::vector,...
A functor that returns a vector composed of its component functor evaluations.
const FunctorBase< T > & _y_comp
The y-component functor.
const FunctorBase< T > & _x_comp
The x-component functor.
std::unique_ptr< ConstantFunctor< T > > _z_constant
Possible holder of constant-0 z-component functor.
VectorCompositeFunctor(const MooseFunctorName &name, const FunctorBase< T > &x_comp, const FunctorBase< T > &y_comp, const FunctorBase< T > &z_comp)
From xyz component constructor.
bool supportsElemSideQpArg() const override
Whether this functor supports evaluation with ElemSideQpArg.
ValueType evaluate(const ElemArg &elem_arg, const StateArg &state) const override
Evaluate the functor with a given element.
std::unique_ptr< ConstantFunctor< T > > _y_constant
Possible holder of constant-0 y-component functor.
GradientType evaluateGradient(const ElemArg &elem_arg, const StateArg &state) const override
Evaluate the functor gradient with a given element.
virtual bool hasBlocks(SubdomainID sub_id) const override
Returns whether the functor is defined on this block.
const bool _has_y
Whether the user supplied a y-functor.
const FunctorBase< T > & _z_comp
The z-component functor.
DotType evaluateDot(const FaceArg &face_arg, const StateArg &state) const override
const bool _has_z
Whether the user supplied a z-functor.
bool supportsFaceArg() const override
Whether this functor supports evaluation with FaceArg.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
A structure that is used to evaluate Moose functors logically at an element/cell center.
A structure that is used to evaluate Moose functors at an arbitrary physical point contained within a...
Argument for requesting functor evaluation at a quadrature point location in an element.
Argument for requesting functor evaluation at quadrature point locations on an element side.
A structure defining a "face" evaluation calling argument for Moose functors.
State argument for evaluating functors.