https://mooseframework.inl.gov
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 
16 
17 namespace Moose
18 {
22 template <typename T>
23 class VectorCompositeFunctor : public FunctorBase<VectorValue<T>>
24 {
25 public:
26  template <typename U>
28 
32 
36  VectorCompositeFunctor(const MooseFunctorName & name,
37  const FunctorBase<T> & x_comp,
38  const FunctorBase<T> & y_comp,
39  const FunctorBase<T> & z_comp);
40 
44  VectorCompositeFunctor(const MooseFunctorName & name,
45  const FunctorBase<T> & x_comp,
46  const FunctorBase<T> & y_comp);
47 
51  VectorCompositeFunctor(const MooseFunctorName & name, const FunctorBase<T> & x_comp);
52 
53  virtual bool hasBlocks(SubdomainID sub_id) const override
54  {
55  const bool ret = _x_comp.hasBlocks(sub_id);
56  if (_has_y)
57  mooseAssert(ret == _y_comp.hasBlocks(sub_id), "x and y block restriction don't agree");
58  if (_has_z)
59  mooseAssert(ret == _z_comp.hasBlocks(sub_id), "x and z block restriction don't agree");
60  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 
75  GradientType evaluateGradient(const ElemArg & elem_arg, const StateArg & state) const override;
76 
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 
83  std::unique_ptr<ConstantFunctor<T>> _y_constant;
84 
87  std::unique_ptr<ConstantFunctor<T>> _z_constant;
88 
95 
97  const bool _has_y;
98 
100  const bool _has_z;
101 };
102 
103 template <typename T>
105  const FunctorBase<T> & x_comp,
106  const FunctorBase<T> & y_comp,
107  const FunctorBase<T> & z_comp)
109  _x_comp(x_comp),
110  _y_comp(y_comp),
111  _z_comp(z_comp),
112  _has_y(true),
113  _has_z(true)
114 {
115 }
116 
117 template <typename T>
119  const FunctorBase<T> & x_comp,
120  const FunctorBase<T> & y_comp)
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>
133  const FunctorBase<T> & x_comp)
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
148 {
149  if (!_x_comp.supportsFaceArg())
150  return false;
151  if (_has_y && !_y_comp.supportsFaceArg())
152  return false;
153  if (_has_z && !_z_comp.supportsFaceArg())
154  return false;
155  return true;
156 }
157 
158 template <typename T>
159 bool
161 {
162  if (!_x_comp.supportsElemSideQpArg())
163  return false;
164  if (_has_y && !_y_comp.supportsElemSideQpArg())
165  return false;
166  if (_has_z && !_z_comp.supportsElemSideQpArg())
167  return false;
168  return true;
169 }
170 
171 template <typename T>
173 VectorCompositeFunctor<T>::evaluate(const ElemArg & elem_arg, const StateArg & state) const
174 {
175  return {_x_comp(elem_arg, state), _y_comp(elem_arg, state), _z_comp(elem_arg, state)};
176 }
177 
178 template <typename T>
180 VectorCompositeFunctor<T>::evaluate(const FaceArg & face, const StateArg & state) const
181 {
182  return {_x_comp(face, state), _y_comp(face, state), _z_comp(face, state)};
183 }
184 
185 template <typename T>
187 VectorCompositeFunctor<T>::evaluate(const ElemQpArg & elem_qp, const StateArg & state) const
188 {
189  return {_x_comp(elem_qp, state), _y_comp(elem_qp, state), _z_comp(elem_qp, state)};
190 }
191 
192 template <typename T>
195  const StateArg & state) const
196 {
197  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>
203  const StateArg & state) const
204 {
205  return {_x_comp(elem_point_arg, state),
206  _y_comp(elem_point_arg, state),
207  _z_comp(elem_point_arg, state)};
208 }
209 
210 template <typename T>
212 VectorCompositeFunctor<T>::evaluate(const NodeArg & node_arg, const StateArg & state) const
213 {
214  return {_x_comp(node_arg, state), _y_comp(node_arg, state), _z_comp(node_arg, state)};
215 }
216 
217 template <typename T>
219 VectorCompositeFunctor<T>::evaluateGradient(const ElemArg & elem_arg, const StateArg & state) const
220 {
221  return {_x_comp.gradient(elem_arg, state),
222  _y_comp.gradient(elem_arg, state),
223  _z_comp.gradient(elem_arg, state)};
224 }
225 
226 template <typename T>
228 VectorCompositeFunctor<T>::evaluateDot(const FaceArg & face_arg, const StateArg & state) const
229 {
230  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>
235 VectorCompositeFunctor<T>::evaluateDot(const ElemArg & elem_arg, const StateArg & state) const
236 {
237  return {_x_comp.dot(elem_arg, state), _y_comp.dot(elem_arg, state), _z_comp.dot(elem_arg, state)};
238 }
239 }
std::string name(const ElemQuality q)
Base class template for functor objects.
Definition: MooseFunctor.h:137
A structure that is used to evaluate Moose functors at an arbitrary physical point contained within a...
bool supportsFaceArg() const override
Whether this functor supports evaluation with FaceArg.
typename FunctorReturnType< VectorValue< T >, FunctorEvaluationKind::Gradient >::type GradientType
This rigmarole makes it so that a user can create functors that return containers (std::vector...
Definition: MooseFunctor.h:149
virtual bool hasBlocks(SubdomainID sub_id) const override
Returns whether the functor is defined on this block.
GradientType evaluateGradient(const ElemArg &elem_arg, const StateArg &state) const override
Evaluate the functor gradient with a given element.
A structure defining a "face" evaluation calling argument for Moose functors.
std::unique_ptr< ConstantFunctor< T > > _y_constant
Possible holder of constant-0 y-component functor.
DotType evaluateDot(const FaceArg &face_arg, const StateArg &state) const override
ValueType evaluate(const ElemArg &elem_arg, const StateArg &state) const override
Evaluate the functor with a given element.
A structure that is used to evaluate Moose functors logically at an element/cell center.
A functor that returns a vector composed of its component functor evaluations.
Argument for requesting functor evaluation at a quadrature point location in an element.
Class template for creating constant functors.
bool supportsElemSideQpArg() const override
Whether this functor supports evaluation with ElemSideQpArg.
const FunctorBase< T > & _z_comp
The z-component functor.
const FunctorBase< T > & _y_comp
The y-component functor.
State argument for evaluating functors.
const bool _has_y
Whether the user supplied a y-functor.
std::unique_ptr< ConstantFunctor< T > > _z_constant
Possible holder of constant-0 z-component functor.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
const bool _has_z
Whether the user supplied a z-functor.
const FunctorBase< T > & _x_comp
The x-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.
Argument for requesting functor evaluation at quadrature point locations on an element side...