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 : #pragma once
11 :
12 : #include "MooseFunctor.h"
13 : #include "libmesh/vector_value.h"
14 :
15 : using libMesh::VectorValue;
16 :
17 : namespace Moose
18 : {
19 : /**
20 : * A functor that returns a vector composed of its component functor evaluations
21 : */
22 : template <typename T>
23 : class VectorCompositeFunctor : public FunctorBase<VectorValue<T>>
24 : {
25 : public:
26 : template <typename U>
27 : using FunctorBase = FunctorBase<U>;
28 :
29 : using typename FunctorBase<VectorValue<T>>::ValueType;
30 : using typename FunctorBase<VectorValue<T>>::GradientType;
31 : using typename FunctorBase<VectorValue<T>>::DotType;
32 :
33 : /**
34 : * From xyz component constructor
35 : */
36 : VectorCompositeFunctor(const MooseFunctorName & name,
37 : const FunctorBase<T> & x_comp,
38 : const FunctorBase<T> & y_comp,
39 : const FunctorBase<T> & z_comp);
40 :
41 : /**
42 : * From xy component constructor
43 : */
44 : VectorCompositeFunctor(const MooseFunctorName & name,
45 : const FunctorBase<T> & x_comp,
46 : const FunctorBase<T> & y_comp);
47 :
48 : /**
49 : * From x component constructor
50 : */
51 : VectorCompositeFunctor(const MooseFunctorName & name, const FunctorBase<T> & x_comp);
52 :
53 0 : virtual bool hasBlocks(SubdomainID sub_id) const override
54 : {
55 0 : const bool ret = _x_comp.hasBlocks(sub_id);
56 0 : if (_has_y)
57 : mooseAssert(ret == _y_comp.hasBlocks(sub_id), "x and y block restriction don't agree");
58 0 : if (_has_z)
59 : mooseAssert(ret == _z_comp.hasBlocks(sub_id), "x and z block restriction don't agree");
60 0 : return ret;
61 : }
62 :
63 : bool supportsFaceArg() const override;
64 : bool supportsElemSideQpArg() const override;
65 :
66 : private:
67 : ValueType evaluate(const ElemArg & elem_arg, const StateArg & state) const override;
68 : ValueType evaluate(const FaceArg & face, const StateArg & state) const override;
69 : ValueType evaluate(const ElemQpArg & elem_qp, const StateArg & state) const override;
70 : ValueType evaluate(const ElemSideQpArg & elem_side_qp, const StateArg & state) const override;
71 : ValueType evaluate(const ElemPointArg & elem_point_arg, const StateArg & state) const override;
72 : ValueType evaluate(const NodeArg & node_arg, const StateArg & state) const override;
73 :
74 : using FunctorBase<VectorValue<T>>::evaluateGradient;
75 : GradientType evaluateGradient(const ElemArg & elem_arg, const StateArg & state) const override;
76 :
77 : using FunctorBase<VectorValue<T>>::evaluateDot;
78 : DotType evaluateDot(const FaceArg & face_arg, const StateArg & state) const override;
79 : DotType evaluateDot(const ElemArg & elem_arg, const StateArg & state) const override;
80 :
81 : /// Possible holder of constant-0 y-component functor. This will be allocated if the user only
82 : /// supplies one component functor during construction
83 : std::unique_ptr<ConstantFunctor<T>> _y_constant;
84 :
85 : /// Possible holder of constant-0 z-component functor. This will be allocated if the user only
86 : /// supplies two component functors during construction
87 : std::unique_ptr<ConstantFunctor<T>> _z_constant;
88 :
89 : /// The x-component functor
90 : const FunctorBase<T> & _x_comp;
91 : /// The y-component functor
92 : const FunctorBase<T> & _y_comp;
93 : /// The z-component functor
94 : const FunctorBase<T> & _z_comp;
95 :
96 : /// Whether the user supplied a y-functor
97 : const bool _has_y;
98 :
99 : /// Whether the user supplied a z-functor
100 : const bool _has_z;
101 : };
102 :
103 : template <typename T>
104 117 : VectorCompositeFunctor<T>::VectorCompositeFunctor(const MooseFunctorName & name,
105 : const FunctorBase<T> & x_comp,
106 : const FunctorBase<T> & y_comp,
107 : const FunctorBase<T> & z_comp)
108 : : FunctorBase<VectorValue<T>>(name),
109 117 : _x_comp(x_comp),
110 117 : _y_comp(y_comp),
111 117 : _z_comp(z_comp),
112 117 : _has_y(true),
113 234 : _has_z(true)
114 : {
115 234 : }
116 :
117 : template <typename T>
118 : VectorCompositeFunctor<T>::VectorCompositeFunctor(const MooseFunctorName & name,
119 : const FunctorBase<T> & x_comp,
120 : const FunctorBase<T> & y_comp)
121 : : FunctorBase<VectorValue<T>>(name),
122 : _z_constant(std::make_unique<ConstantFunctor>(T(0))),
123 : _x_comp(x_comp),
124 : _y_comp(y_comp),
125 : _z_comp(*_z_constant),
126 : _has_y(true),
127 : _has_z(false)
128 : {
129 : }
130 :
131 : template <typename T>
132 : VectorCompositeFunctor<T>::VectorCompositeFunctor(const MooseFunctorName & name,
133 : const FunctorBase<T> & x_comp)
134 : : FunctorBase<VectorValue<T>>(name),
135 : _y_constant(std::make_unique<ConstantFunctor>(T(0))),
136 : _z_constant(std::make_unique<ConstantFunctor>(T(0))),
137 : _x_comp(x_comp),
138 : _y_comp(*_y_constant),
139 : _z_comp(*_z_constant),
140 : _has_y(false),
141 : _has_z(false)
142 : {
143 : }
144 :
145 : template <typename T>
146 : bool
147 0 : VectorCompositeFunctor<T>::supportsFaceArg() const
148 : {
149 0 : if (!_x_comp.supportsFaceArg())
150 0 : return false;
151 0 : if (_has_y && !_y_comp.supportsFaceArg())
152 0 : return false;
153 0 : if (_has_z && !_z_comp.supportsFaceArg())
154 0 : return false;
155 0 : return true;
156 : }
157 :
158 : template <typename T>
159 : bool
160 0 : VectorCompositeFunctor<T>::supportsElemSideQpArg() const
161 : {
162 0 : if (!_x_comp.supportsElemSideQpArg())
163 0 : return false;
164 0 : if (_has_y && !_y_comp.supportsElemSideQpArg())
165 0 : return false;
166 0 : if (_has_z && !_z_comp.supportsElemSideQpArg())
167 0 : return false;
168 0 : return true;
169 : }
170 :
171 : template <typename T>
172 : typename VectorCompositeFunctor<T>::ValueType
173 14136 : VectorCompositeFunctor<T>::evaluate(const ElemArg & elem_arg, const StateArg & state) const
174 : {
175 14136 : return {_x_comp(elem_arg, state), _y_comp(elem_arg, state), _z_comp(elem_arg, state)};
176 : }
177 :
178 : template <typename T>
179 : typename VectorCompositeFunctor<T>::ValueType
180 0 : VectorCompositeFunctor<T>::evaluate(const FaceArg & face, const StateArg & state) const
181 : {
182 0 : return {_x_comp(face, state), _y_comp(face, state), _z_comp(face, state)};
183 : }
184 :
185 : template <typename T>
186 : typename VectorCompositeFunctor<T>::ValueType
187 0 : VectorCompositeFunctor<T>::evaluate(const ElemQpArg & elem_qp, const StateArg & state) const
188 : {
189 0 : return {_x_comp(elem_qp, state), _y_comp(elem_qp, state), _z_comp(elem_qp, state)};
190 : }
191 :
192 : template <typename T>
193 : typename VectorCompositeFunctor<T>::ValueType
194 0 : VectorCompositeFunctor<T>::evaluate(const ElemSideQpArg & elem_side_qp,
195 : const StateArg & state) const
196 : {
197 0 : return {_x_comp(elem_side_qp, state), _y_comp(elem_side_qp, state), _z_comp(elem_side_qp, state)};
198 : }
199 :
200 : template <typename T>
201 : typename VectorCompositeFunctor<T>::ValueType
202 0 : VectorCompositeFunctor<T>::evaluate(const ElemPointArg & elem_point_arg,
203 : const StateArg & state) const
204 : {
205 0 : return {_x_comp(elem_point_arg, state),
206 0 : _y_comp(elem_point_arg, state),
207 0 : _z_comp(elem_point_arg, state)};
208 : }
209 :
210 : template <typename T>
211 : typename VectorCompositeFunctor<T>::ValueType
212 0 : VectorCompositeFunctor<T>::evaluate(const NodeArg & node_arg, const StateArg & state) const
213 : {
214 0 : return {_x_comp(node_arg, state), _y_comp(node_arg, state), _z_comp(node_arg, state)};
215 : }
216 :
217 : template <typename T>
218 : typename VectorCompositeFunctor<T>::GradientType
219 6384 : VectorCompositeFunctor<T>::evaluateGradient(const ElemArg & elem_arg, const StateArg & state) const
220 : {
221 6384 : return {_x_comp.gradient(elem_arg, state),
222 6384 : _y_comp.gradient(elem_arg, state),
223 6384 : _z_comp.gradient(elem_arg, state)};
224 : }
225 :
226 : template <typename T>
227 : typename VectorCompositeFunctor<T>::DotType
228 0 : VectorCompositeFunctor<T>::evaluateDot(const FaceArg & face_arg, const StateArg & state) const
229 : {
230 0 : return {_x_comp.dot(face_arg, state), _y_comp.dot(face_arg, state), _z_comp.dot(face_arg, state)};
231 : }
232 :
233 : template <typename T>
234 : typename VectorCompositeFunctor<T>::DotType
235 0 : VectorCompositeFunctor<T>::evaluateDot(const ElemArg & elem_arg, const StateArg & state) const
236 : {
237 0 : return {_x_comp.dot(elem_arg, state), _y_comp.dot(elem_arg, state), _z_comp.dot(elem_arg, state)};
238 : }
239 : }
|