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 <tuple>
13 :
14 : #include "Limiter.h"
15 : #include "FaceInfo.h"
16 : #include "MooseTypes.h"
17 : #include "libmesh/elem.h"
18 : #include "libmesh/point.h"
19 : #include "libmesh/quadrature.h"
20 :
21 : #include <set>
22 :
23 : namespace Moose
24 : {
25 : /**
26 : * A structure that is used to evaluate Moose functors logically at an element/cell center
27 : */
28 : struct ElemArg
29 : {
30 : const libMesh::Elem * elem;
31 : bool correct_skewness;
32 :
33 : /**
34 : * @returns The conceptual physical location of this data structure
35 : */
36 3019643 : Point getPoint() const { return elem->vertex_average(); }
37 :
38 : /**
39 : * friend function that allows this structure to be used as keys in ordered containers like sets
40 : * and maps
41 : */
42 0 : friend bool operator<(const ElemArg & l, const ElemArg & r)
43 : {
44 0 : return std::make_tuple(l.elem, l.correct_skewness) <
45 0 : std::make_tuple(r.elem, r.correct_skewness);
46 : }
47 : };
48 :
49 : /**
50 : * A structure that is used to evaluate Moose functors at an arbitrary physical point contained
51 : * within an element
52 : */
53 : struct ElemPointArg
54 : {
55 : const libMesh::Elem * elem;
56 : libMesh::Point point;
57 : bool correct_skewness;
58 :
59 : /**
60 : * @returns The conceptual physical location of this data structure
61 : */
62 786 : Point getPoint() const { return point; }
63 :
64 : /**
65 : * friend function that allows this structure to be used as keys in ordered containers like sets
66 : * and maps
67 : */
68 : friend bool operator<(const ElemPointArg & l, const ElemPointArg & r)
69 : {
70 : return std::make_tuple(l.elem, l.point, l.correct_skewness) <
71 : std::make_tuple(r.elem, r.point, r.correct_skewness);
72 : }
73 :
74 : /**
75 : * Make a \p ElemArg from our data
76 : */
77 71270 : ElemArg makeElem() const { return {elem, correct_skewness}; }
78 : };
79 :
80 : /**
81 : * Argument for requesting functor evaluation at quadrature point locations on an element side.
82 : * Data in the argument:
83 : * - The element
84 : * - The element side on which the quadrature points are located
85 : * - The quadrature point index, e.g. if there are \p n quadrature points, we are requesting the\n
86 : * evaluation of the i-th point
87 : * - The quadrature rule that can be used to initialize the functor on the given element and side
88 : */
89 : struct ElemSideQpArg
90 : {
91 : /// The element
92 : const libMesh::Elem * elem;
93 :
94 : /// The local side index
95 : unsigned int side;
96 :
97 : /// The quadrature point index
98 : unsigned int qp;
99 :
100 : /// The quadrature rule
101 : const libMesh::QBase * qrule;
102 :
103 : /// The physical location of the quadrature point
104 : Point point;
105 :
106 : /**
107 : * @returns The conceptual physical location of this data structure
108 : */
109 587053 : Point getPoint() const { return point; }
110 : };
111 :
112 : /**
113 : * State argument for evaluating functors. The iteration type indicates whether you want to evaluate
114 : * a functor based on some iterate state of a transient calculation, nonlinear solve, etc. The state
115 : * indicates which iterate of the iterate type we want to evaluate on. A state of 0 indicates
116 : * "current", e.g. the current time or the current nonlinear iteration (which should actually be
117 : * equivalent); a state of 1 indicates the most-recent "old" time or the most recent previous
118 : * nonlinear iteration, etc.
119 : */
120 :
121 : struct StateArg
122 : {
123 : /**
124 : * Prevent implicit conversions from boolean to avoid users accidentally constructing a time
125 : * argument when they meant to construct a skewness argument, etc.
126 : */
127 : StateArg(bool) = delete;
128 :
129 14 : StateArg(unsigned int state_in) : state(state_in), iteration_type(SolutionIterationType::Time) {}
130 :
131 15074285 : StateArg(unsigned int state_in, SolutionIterationType iteration_type_in)
132 15074285 : : state(state_in), iteration_type(iteration_type_in)
133 : {
134 15074285 : }
135 :
136 : bool operator==(const StateArg & other) const
137 : {
138 : return state == other.state && iteration_type == other.iteration_type;
139 : }
140 :
141 : /// The state. Zero represents the most recent state, so for any kind of iteration type, a zero
142 : /// state represents the current state, e.g. current solution
143 : /// One may represent the 'old' value (one before, in the iteration_type specified), and two an 'older' or two steps away state
144 : unsigned int state;
145 :
146 : /// The solution iteration type, e.g. time or nonlinear
147 : SolutionIterationType iteration_type;
148 :
149 : private:
150 83277791 : StateArg() : state(0), iteration_type(SolutionIterationType::Time) {}
151 :
152 : friend StateArg currentState();
153 : };
154 :
155 : inline StateArg
156 83277791 : currentState()
157 : {
158 83277791 : return {};
159 : }
160 :
161 : inline StateArg
162 14 : oldState()
163 : {
164 14 : return {(unsigned int)1};
165 : }
166 :
167 : inline StateArg
168 56134 : previousNonlinearState()
169 : {
170 56134 : return {(unsigned int)1, SolutionIterationType::Nonlinear};
171 : }
172 :
173 : inline StateArg
174 42 : previousFixedPointState()
175 : {
176 42 : return {(unsigned int)1, SolutionIterationType::FixedPoint};
177 : }
178 :
179 : /**
180 : * A structure defining a "face" evaluation calling argument for Moose functors
181 : */
182 : struct FaceArg
183 : {
184 : /// a face information object which defines our location in space
185 : const FaceInfo * fi;
186 :
187 : /// a limiter which defines how the functor evaluated on either side of the face should be
188 : /// interpolated to the face
189 : Moose::FV::LimiterType limiter_type;
190 :
191 : /// a boolean which states whether the face information element is upwind of the face
192 : bool elem_is_upwind;
193 :
194 : /// Whether to perform skew correction
195 : bool correct_skewness;
196 :
197 : /// A member that can be used to indicate whether there is a sidedness to this face. For example,
198 : /// a block restricted diffusion kernel may use this to specify that a diffusion coefficient
199 : /// should be evaluated on the elem side of the face, ignoring possible jumps in the diffusion
200 : /// coefficient between the elem and neighbor sides of the face. If this is null, then a functor
201 : /// that is itself block restricted may modify the value to indicate \emph its sidedness. If there
202 : /// is ever a mismatch between the specified sidedness of a physics object and the sidedness of a
203 : /// functor, then we will error
204 : /// If unspecified (nullptr), the evaluation will be two-sided, unless the functor is not defined
205 : /// on one side of the face.
206 : const libMesh::Elem * face_side;
207 :
208 : /// A member that can be used to define the instance in which the limiters are executed
209 : const Moose::StateArg * state_limiter;
210 :
211 : /**
212 : * @returns The conceptual physical location of this data structure
213 : */
214 1714920 : libMesh::Point getPoint() const { return fi->faceCentroid(); }
215 :
216 : /**
217 : * Make a \p ElemArg from our data using the face information element
218 : */
219 91873835 : ElemArg makeElem() const { return {&fi->elem(), correct_skewness}; }
220 :
221 : /**
222 : * Make a \p ElemArg from our data using the face information neighbor
223 : */
224 91873787 : ElemArg makeNeighbor() const { return {fi->neighborPtr(), correct_skewness}; }
225 :
226 : /**
227 : * friend function that allows this structure to be used as keys in ordered containers like sets
228 : * and maps
229 : */
230 0 : friend bool operator<(const FaceArg & l, const FaceArg & r)
231 : {
232 0 : return std::make_tuple(
233 0 : l.fi, l.limiter_type, l.elem_is_upwind, l.correct_skewness, l.face_side) <
234 0 : std::make_tuple(r.fi, r.limiter_type, r.elem_is_upwind, r.correct_skewness, r.face_side);
235 : }
236 : };
237 :
238 : struct NodeArg
239 : {
240 : /// The node which defines our location in space
241 : const libMesh::Node * node;
242 :
243 : /**
244 : * Indicates what subdomains this argument should be associated with. If a single subdomain is
245 : * given, then there is no ambiguity when this argument is used to evaluate functors at the
246 : * intersection of different blocks. If multiple subdomains are given at such an intersection
247 : * point, it is up to the functor whether it can be evaluated unambiguously, perform an average,
248 : * or error
249 : */
250 : const std::set<SubdomainID> * subdomain_ids;
251 :
252 170713 : libMesh::Point getPoint() const { return *node; }
253 :
254 : /// A static member that can be used when the connection of a node to subdomains is unknown.
255 : /// Functors may still be able to evaluate a NodeArg with this as the provided \p subdomain_ids
256 : /// if the functor has no "sidedness", e.g. like a H1 finite element family variable
257 : static const std::set<SubdomainID> undefined_subdomain_connection;
258 : };
259 :
260 : /**
261 : * Argument for requesting functor evaluation at a quadrature point location in an element. Data
262 : * in the argument:
263 : * - The element containing the quadrature point
264 : * - The quadrature point index, e.g. if there are \p n quadrature points, we are requesting the\n
265 : * evaluation of the i-th point
266 : * - The quadrature rule that can be used to initialize the functor on the given element
267 : */
268 : struct ElemQpArg
269 : {
270 : /// The element
271 : const libMesh::Elem * elem;
272 :
273 : /// The quadrature point index
274 : unsigned int qp;
275 :
276 : /// The quadrature rule
277 : const libMesh::QBase * qrule;
278 :
279 : /// The physical location of the quadrature point
280 : libMesh::Point point;
281 :
282 : /**
283 : * @returns The conceptual physical location of this data structure
284 : */
285 2654109 : libMesh::Point getPoint() const { return point; }
286 : };
287 : }
|