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 "Moose.h"
13 : #include "ADReal.h"
14 : #include "EigenADReal.h"
15 : #include "ChainedReal.h"
16 : #include "ChainedADReal.h"
17 : #include "ADRankTwoTensorForward.h"
18 : #include "ADRankThreeTensorForward.h"
19 : #include "ADRankFourTensorForward.h"
20 : #include "ADSymmetricRankTwoTensorForward.h"
21 : #include "ADSymmetricRankFourTensorForward.h"
22 :
23 : // This is not strictly needed here, but it used to be included by ADReal.h
24 : // so developers relied heavily on it being already available
25 : #include "MooseError.h"
26 :
27 : #include "libmesh/libmesh.h"
28 : #include "libmesh/id_types.h"
29 : #include "libmesh/stored_range.h"
30 : #include "libmesh/petsc_macro.h"
31 : #include "libmesh/boundary_info.h"
32 : #include "libmesh/parameters.h"
33 : #include "libmesh/dense_vector.h"
34 : #include "libmesh/dense_matrix.h"
35 : #include "libmesh/int_range.h"
36 :
37 : // BOOST include
38 : #include "boost/bitmask_operators.h"
39 :
40 : #include "libmesh/ignore_warnings.h"
41 : #include "Eigen/Core"
42 : #include "libmesh/restore_warnings.h"
43 : #include "libmesh/tensor_tools.h"
44 :
45 : #include "metaphysicl/ct_types.h"
46 :
47 : #include <string>
48 : #include <vector>
49 : #include <memory>
50 : #include <type_traits>
51 : #include <functional>
52 :
53 : #if !defined(INCLUDE_NLOHMANN_JSON_HPP_) && !defined(MOOSE_NLOHMANN_INCLUDED)
54 : #undef INCLUDE_NLOHMANN_JSON_FWD_HPP_
55 : #include "nlohmann/json_fwd.h"
56 : #define MOOSE_NLOHMANN_INCLUDED
57 : #endif
58 :
59 : // DO NOT USE (Deprecated)
60 : #define MooseSharedPointer std::shared_ptr
61 : #define MooseSharedNamespace std
62 :
63 : /**
64 : * Macro for inferring the proper type of a normal loop index compatible
65 : * with the "auto" keyword.
66 : * Usage:
67 : * for (auto i = beginIndex(v); i < v.size(); ++i) // default index is zero
68 : * for (auto i = beginIndex(v, 1); i < v.size(); ++i) // index is supplied
69 : */
70 : // The multiple macros that you would need anyway [as per: Crazy Eddie (stack overflow)]
71 : #ifdef __clang__
72 : #pragma clang diagnostic push
73 : #pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
74 : #endif
75 :
76 : #define beginIndex_0() ERROR-- > "beginIndex() requires one or two arguments"
77 : #define beginIndex_1(A) decltype(A.size())(0)
78 : #define beginIndex_2(A, B) decltype(A.size())(B)
79 : #define beginIndex_3(A, B, C) ERROR-- > "beginIndex() requires one or two arguments"
80 : #define beginIndex_4(A, B, C, D) ERROR-- > "beginIndex() requires one or two arguments"
81 :
82 : // The interim macro that simply strips the excess and ends up with the required macro
83 : #define beginIndex_X(x, A, B, C, D, FUNC, ...) FUNC
84 :
85 : // The macro that the programmer uses
86 : #define beginIndex(...) \
87 : beginIndex_X(, \
88 : ##__VA_ARGS__, \
89 : beginIndex_4(__VA_ARGS__), \
90 : beginIndex_3(__VA_ARGS__), \
91 : beginIndex_2(__VA_ARGS__), \
92 : beginIndex_1(__VA_ARGS__), \
93 : beginIndex_0(__VA_ARGS__))
94 :
95 : /**
96 : * MooseIndex Macro for creating an index type of the right type for loops and other places where
97 : * type matching is important.
98 : * Usage:
99 : *
100 : * Type t;
101 : *
102 : * Container type:
103 : * for (MooseIndex(t) i = 0; i < t.size(); ++i)
104 : *
105 : * POD type:
106 : * for (MooseIndex(t) i = 0; i < t; ++i)
107 : */
108 : #define MooseIndex(type) decltype(_MooseIndex(type, 0))
109 :
110 : // SFINAE templates for type MooseIndex type selection
111 : template <typename T, typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
112 : typename std::remove_const<T>::type
113 : _MooseIndex(T, int)
114 : {
115 : }
116 :
117 : template <typename T>
118 : decltype(std::declval<T>().size())
119 : _MooseIndex(T &&, int)
120 : {
121 : }
122 :
123 : template <typename T>
124 : decltype("NOTE: MooseIndex only works with integers and objects with size()!")
125 : _MooseIndex(T, double) = delete;
126 :
127 : #ifdef __clang__
128 : #pragma clang diagnostic pop
129 : #endif
130 :
131 : /**
132 : * forward declarations
133 : */
134 : template <typename>
135 : class MooseArray;
136 : template <typename>
137 : class MaterialProperty;
138 : template <typename>
139 : class ADMaterialProperty;
140 : class InputParameters;
141 :
142 : namespace libMesh
143 : {
144 : typedef VectorValue<Real> RealVectorValue;
145 : typedef Eigen::Matrix<Real, Moose::dim, 1> RealDIMValue;
146 : typedef Eigen::Matrix<Real, Eigen::Dynamic, 1> RealEigenVector;
147 : typedef Eigen::Matrix<Real, Eigen::Dynamic, Moose::dim> RealVectorArrayValue;
148 : typedef Eigen::Matrix<Real, Eigen::Dynamic, Moose::dim * Moose::dim> RealTensorArrayValue;
149 : typedef Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic> RealEigenMatrix;
150 : typedef TensorValue<Real> RealTensorValue;
151 :
152 : namespace TensorTools
153 : {
154 : template <>
155 : struct IncrementRank<Eigen::Matrix<Real, Eigen::Dynamic, 1>>
156 : {
157 : typedef Eigen::Matrix<Real, Eigen::Dynamic, Moose::dim> type;
158 : };
159 :
160 : template <>
161 : struct IncrementRank<Eigen::Matrix<Real, Eigen::Dynamic, Moose::dim>>
162 : {
163 : typedef Eigen::Matrix<Real, Eigen::Dynamic, Moose::dim * Moose::dim> type;
164 : };
165 :
166 : template <>
167 : struct DecrementRank<Eigen::Matrix<Real, Eigen::Dynamic, Moose::dim>>
168 : {
169 : typedef Eigen::Matrix<Real, Eigen::Dynamic, 1> type;
170 : };
171 : }
172 : }
173 :
174 : // Common types defined in libMesh
175 : using libMesh::Gradient;
176 : using libMesh::RealGradient;
177 :
178 : // Bring these common types added to the libMesh namespace in this header
179 : // to global namespace
180 : using libMesh::DenseMatrix;
181 : using libMesh::DenseVector;
182 : using libMesh::RealDIMValue;
183 : using libMesh::RealEigenMatrix;
184 : using libMesh::RealEigenVector;
185 : using libMesh::RealTensorArrayValue;
186 : using libMesh::RealTensorValue;
187 : using libMesh::RealVectorArrayValue;
188 : using libMesh::RealVectorValue;
189 :
190 : namespace MetaPhysicL
191 : {
192 : template <typename U>
193 : struct ReplaceAlgebraicType<libMesh::RealEigenVector, U>
194 : {
195 : typedef U type;
196 : };
197 : }
198 :
199 : /**
200 : * various MOOSE typedefs
201 : */
202 : typedef Real PostprocessorValue;
203 : typedef std::vector<Real> VectorPostprocessorValue;
204 : typedef Real ScatterVectorPostprocessorValue;
205 : typedef boundary_id_type BoundaryID;
206 : typedef unsigned int InterfaceID;
207 : typedef subdomain_id_type SubdomainID;
208 : typedef unsigned int MooseObjectID;
209 : typedef unsigned int THREAD_ID;
210 : typedef unsigned int TagID;
211 : typedef unsigned int TagTypeID;
212 : typedef unsigned int PerfID;
213 : typedef unsigned int InvalidSolutionID;
214 : using RestartableDataMapName = std::string; // see MooseApp.h
215 :
216 : typedef libMesh::StoredRange<std::vector<dof_id_type>::iterator, dof_id_type> NodeIdRange;
217 : typedef libMesh::StoredRange<std::vector<const Elem *>::iterator, const Elem *>
218 : ConstElemPointerRange;
219 :
220 : namespace Moose
221 : {
222 :
223 : /// This is used for places where we initialize some qp-sized data structures
224 : /// that would end up being sized too small after the quadrature order gets
225 : /// bumped (dynamically in-sim). So for these cases, we just use this constant
226 : /// to size those data structures overly large to accommodate rather than come
227 : /// up with some overkill complex mechanism for dynamically resizing them.
228 : /// Eventually, we may need or implement that more sophisticated mechanism and
229 : /// will no longer need this.
230 : constexpr std::size_t constMaxQpsPerElem = 1000;
231 :
232 : // These are used by MooseVariableData and MooseVariableDataFV
233 : enum SolutionState : int
234 : {
235 : Current = 0,
236 : Old = 1,
237 : Older = 2,
238 : PreviousNL = -1
239 : };
240 :
241 : enum class SolutionIterationType : unsigned short
242 : {
243 : Time = 0,
244 : Nonlinear = 1,
245 : FixedPoint = 2
246 : };
247 :
248 : // These are used by MooseVariableData and MooseVariableDataFV
249 : enum GeometryType
250 : {
251 : Volume,
252 : Face
253 : };
254 :
255 : template <typename OutputType>
256 : struct ShapeType
257 : {
258 : typedef OutputType type;
259 : };
260 : template <>
261 : struct ShapeType<Eigen::Matrix<Real, Eigen::Dynamic, 1>>
262 : {
263 : typedef Real type;
264 : };
265 :
266 : template <typename OutputType>
267 : struct DOFType
268 : {
269 : typedef OutputType type;
270 : };
271 : template <>
272 : struct DOFType<RealVectorValue>
273 : {
274 : typedef Real type;
275 : };
276 : } // namespace Moose
277 :
278 : template <typename OutputType>
279 : struct OutputTools
280 : {
281 : typedef typename libMesh::TensorTools::IncrementRank<OutputType>::type OutputGradient;
282 : typedef typename libMesh::TensorTools::IncrementRank<OutputGradient>::type OutputSecond;
283 : typedef typename libMesh::TensorTools::DecrementRank<OutputType>::type OutputDivergence;
284 :
285 : typedef MooseArray<OutputType> VariableValue;
286 : typedef MooseArray<OutputGradient> VariableGradient;
287 : typedef MooseArray<OutputSecond> VariableSecond;
288 : typedef MooseArray<OutputType> VariableCurl;
289 : typedef MooseArray<OutputDivergence> VariableDivergence;
290 :
291 : typedef typename Moose::ShapeType<OutputType>::type OutputShape;
292 : typedef typename libMesh::TensorTools::IncrementRank<OutputShape>::type OutputShapeGradient;
293 : typedef typename libMesh::TensorTools::IncrementRank<OutputShapeGradient>::type OutputShapeSecond;
294 : typedef typename libMesh::TensorTools::DecrementRank<OutputShape>::type OutputShapeDivergence;
295 :
296 : typedef MooseArray<std::vector<OutputShape>> VariablePhiValue;
297 : typedef MooseArray<std::vector<OutputShapeGradient>> VariablePhiGradient;
298 : typedef MooseArray<std::vector<OutputShapeSecond>> VariablePhiSecond;
299 : typedef MooseArray<std::vector<OutputShape>> VariablePhiCurl;
300 : typedef MooseArray<std::vector<OutputShapeDivergence>> VariablePhiDivergence;
301 :
302 : typedef MooseArray<std::vector<OutputShape>> VariableTestValue;
303 : typedef MooseArray<std::vector<OutputShapeGradient>> VariableTestGradient;
304 : typedef MooseArray<std::vector<OutputShapeSecond>> VariableTestSecond;
305 : typedef MooseArray<std::vector<OutputShape>> VariableTestCurl;
306 : typedef MooseArray<std::vector<OutputShapeDivergence>> VariableTestDivergence;
307 :
308 : // DoF value type for the template class OutputType
309 : typedef typename Moose::DOFType<OutputType>::type OutputData;
310 : typedef MooseArray<OutputData> DoFValue;
311 : typedef OutputType OutputValue;
312 : };
313 :
314 : // types for standard variable
315 : typedef typename OutputTools<Real>::VariableValue VariableValue;
316 : typedef typename OutputTools<Real>::VariableGradient VariableGradient;
317 : typedef typename OutputTools<Real>::VariableSecond VariableSecond;
318 : typedef typename OutputTools<Real>::VariableCurl VariableCurl;
319 : typedef typename OutputTools<Real>::VariableDivergence VariableDivergence;
320 : typedef typename OutputTools<Real>::VariablePhiValue VariablePhiValue;
321 : typedef typename OutputTools<Real>::VariablePhiGradient VariablePhiGradient;
322 : typedef typename OutputTools<Real>::VariablePhiSecond VariablePhiSecond;
323 : typedef typename OutputTools<Real>::VariablePhiCurl VariablePhiCurl;
324 : typedef typename OutputTools<Real>::VariablePhiDivergence VariablePhiDivergence;
325 : typedef typename OutputTools<Real>::VariableTestValue VariableTestValue;
326 : typedef typename OutputTools<Real>::VariableTestGradient VariableTestGradient;
327 : typedef typename OutputTools<Real>::VariableTestSecond VariableTestSecond;
328 : typedef typename OutputTools<Real>::VariableTestCurl VariableTestCurl;
329 : typedef typename OutputTools<Real>::VariableTestDivergence VariableTestDivergence;
330 :
331 : // types for vector variable
332 : typedef typename OutputTools<RealVectorValue>::VariableValue VectorVariableValue;
333 : typedef typename OutputTools<RealVectorValue>::VariableGradient VectorVariableGradient;
334 : typedef typename OutputTools<RealVectorValue>::VariableSecond VectorVariableSecond;
335 : typedef typename OutputTools<RealVectorValue>::VariableCurl VectorVariableCurl;
336 : typedef typename OutputTools<RealVectorValue>::VariableDivergence VectorVariableDivergence;
337 : typedef typename OutputTools<RealVectorValue>::VariablePhiValue VectorVariablePhiValue;
338 : typedef typename OutputTools<RealVectorValue>::VariablePhiGradient VectorVariablePhiGradient;
339 : typedef typename OutputTools<RealVectorValue>::VariablePhiSecond VectorVariablePhiSecond;
340 : typedef typename OutputTools<RealVectorValue>::VariablePhiCurl VectorVariablePhiCurl;
341 : typedef typename OutputTools<RealVectorValue>::VariablePhiDivergence VectorVariablePhiDivergence;
342 : typedef typename OutputTools<RealVectorValue>::VariableTestValue VectorVariableTestValue;
343 : typedef typename OutputTools<RealVectorValue>::VariableTestGradient VectorVariableTestGradient;
344 : typedef typename OutputTools<RealVectorValue>::VariableTestSecond VectorVariableTestSecond;
345 : typedef typename OutputTools<RealVectorValue>::VariableTestCurl VectorVariableTestCurl;
346 : typedef typename OutputTools<RealVectorValue>::VariableTestDivergence VectorVariableTestDivergence;
347 :
348 : // types for array variable
349 : typedef typename OutputTools<RealEigenVector>::VariableValue ArrayVariableValue;
350 : typedef typename OutputTools<RealEigenVector>::VariableGradient ArrayVariableGradient;
351 : typedef typename OutputTools<RealEigenVector>::VariableSecond ArrayVariableSecond;
352 : typedef typename OutputTools<RealEigenVector>::VariableCurl ArrayVariableCurl;
353 : typedef typename OutputTools<RealEigenVector>::VariableDivergence ArrayVariableDivergence;
354 : typedef typename OutputTools<RealEigenVector>::VariablePhiValue ArrayVariablePhiValue;
355 : typedef typename OutputTools<RealEigenVector>::VariablePhiGradient ArrayVariablePhiGradient;
356 : typedef std::vector<std::vector<Eigen::Map<RealDIMValue>>> MappedArrayVariablePhiGradient;
357 : typedef typename OutputTools<RealEigenVector>::VariablePhiSecond ArrayVariablePhiSecond;
358 : typedef typename OutputTools<RealEigenVector>::VariablePhiCurl ArrayVariablePhiCurl;
359 : typedef typename OutputTools<RealEigenVector>::VariablePhiDivergence ArrayVariablePhiDivergence;
360 : typedef typename OutputTools<RealEigenVector>::VariableTestValue ArrayVariableTestValue;
361 : typedef typename OutputTools<RealEigenVector>::VariableTestGradient ArrayVariableTestGradient;
362 : typedef typename OutputTools<RealEigenVector>::VariableTestSecond ArrayVariableTestSecond;
363 : typedef typename OutputTools<RealEigenVector>::VariableTestCurl ArrayVariableTestCurl;
364 : typedef typename OutputTools<RealEigenVector>::VariableTestDivergence ArrayVariableTestDivergence;
365 :
366 : /**
367 : * AD typedefs
368 : */
369 : typedef libMesh::VectorValue<ADReal> ADRealVectorValue;
370 : typedef ADRealVectorValue ADRealGradient;
371 : typedef libMesh::VectorValue<ADReal> ADPoint;
372 : typedef libMesh::TensorValue<ADReal> ADRealTensorValue;
373 : typedef libMesh::DenseMatrix<ADReal> ADDenseMatrix;
374 : typedef libMesh::DenseVector<ADReal> ADDenseVector;
375 : typedef MooseArray<ADReal> ADVariableValue;
376 : typedef MooseArray<ADRealVectorValue> ADVariableGradient;
377 : typedef MooseArray<ADRealTensorValue> ADVariableSecond;
378 : typedef MooseArray<ADRealVectorValue> ADVectorVariableValue;
379 : typedef MooseArray<ADRealTensorValue> ADVectorVariableGradient;
380 : typedef MooseArray<libMesh::TypeNTensor<3, ADReal>> ADVectorVariableSecond;
381 : typedef MooseArray<ADRealVectorValue> ADVectorVariableCurl;
382 :
383 : namespace Moose
384 : {
385 :
386 : // type conversion from regular to AD
387 : template <typename T>
388 : struct ADType
389 : {
390 : // unless a specialization exists we assume there is no specific AD type
391 : typedef T type;
392 : };
393 :
394 : template <>
395 : struct ADType<Real>
396 : {
397 : typedef ADReal type;
398 : };
399 : template <>
400 : struct ADType<ChainedReal>
401 : {
402 : typedef ChainedADReal type;
403 : };
404 : template <>
405 : struct ADType<Point>
406 : {
407 : typedef ADPoint type;
408 : };
409 :
410 : template <>
411 : struct ADType<RealVectorValue>
412 : {
413 : typedef ADRealVectorValue type;
414 : };
415 : template <>
416 : struct ADType<RankTwoTensor>
417 : {
418 : typedef ADRankTwoTensor type;
419 : };
420 : template <>
421 : struct ADType<RankThreeTensor>
422 : {
423 : typedef ADRankThreeTensor type;
424 : };
425 : template <>
426 : struct ADType<RankFourTensor>
427 : {
428 : typedef ADRankFourTensor type;
429 : };
430 :
431 : template <>
432 : struct ADType<SymmetricRankTwoTensor>
433 : {
434 : typedef ADSymmetricRankTwoTensor type;
435 : };
436 : template <>
437 : struct ADType<SymmetricRankFourTensor>
438 : {
439 : typedef ADSymmetricRankFourTensor type;
440 : };
441 :
442 : template <template <typename T> class W, typename T>
443 : struct ADType<W<T>>
444 : {
445 : typedef W<typename ADType<T>::type> type;
446 : };
447 :
448 : template <typename T>
449 : struct ADType<std::vector<T, std::allocator<T>>>
450 : {
451 : typedef typename ADType<T>::type adT;
452 : typedef std::vector<adT, std::allocator<adT>> type;
453 : };
454 :
455 : template <typename T>
456 : struct ADType<std::list<T, std::allocator<T>>>
457 : {
458 : typedef typename ADType<T>::type adT;
459 : typedef std::list<adT, std::allocator<adT>> type;
460 : };
461 :
462 : template <typename T>
463 : struct ADType<std::set<T, std::less<T>, std::allocator<T>>>
464 : {
465 : typedef typename ADType<T>::type adT;
466 : typedef std::set<adT, std::less<adT>, std::allocator<adT>> type;
467 : };
468 :
469 : template <typename T>
470 : struct ADType<DenseVector<T>>
471 : {
472 : typedef DenseVector<typename ADType<T>::type> type;
473 : };
474 :
475 : template <typename T>
476 : struct ADType<DenseMatrix<T>>
477 : {
478 : typedef DenseMatrix<typename ADType<T>::type> type;
479 : };
480 :
481 : template <>
482 : struct ADType<RealEigenVector>
483 : {
484 : typedef RealEigenVector type;
485 : };
486 : template <>
487 : struct ADType<VariableValue>
488 : {
489 : typedef ADVariableValue type;
490 : };
491 : template <>
492 : struct ADType<VariableGradient>
493 : {
494 : typedef ADVariableGradient type;
495 : };
496 : template <>
497 : struct ADType<VariableSecond>
498 : {
499 : typedef ADVariableSecond type;
500 : };
501 :
502 : template <>
503 : struct ADType<ADReal>
504 : {
505 : typedef ADReal type;
506 : };
507 : template <>
508 : struct ADType<ChainedADReal>
509 : {
510 : typedef ChainedADReal type;
511 : };
512 : template <>
513 : struct ADType<ADRankTwoTensor>
514 : {
515 : typedef ADRankTwoTensor type;
516 : };
517 : template <>
518 : struct ADType<ADRankThreeTensor>
519 : {
520 : typedef ADRankThreeTensor type;
521 : };
522 : template <>
523 : struct ADType<ADRankFourTensor>
524 : {
525 : typedef ADRankFourTensor type;
526 : };
527 :
528 : template <>
529 : struct ADType<ADSymmetricRankTwoTensor>
530 : {
531 : typedef ADSymmetricRankTwoTensor type;
532 : };
533 : template <>
534 : struct ADType<ADSymmetricRankFourTensor>
535 : {
536 : typedef ADSymmetricRankFourTensor type;
537 : };
538 :
539 : template <>
540 : struct ADType<ADVariableValue>
541 : {
542 : typedef ADVariableValue type;
543 : };
544 : template <>
545 : struct ADType<ADVariableGradient>
546 : {
547 : typedef ADVariableGradient type;
548 : };
549 : template <>
550 : struct ADType<ADVariableSecond>
551 : {
552 : typedef ADVariableSecond type;
553 : };
554 :
555 : template <typename T>
556 : struct IsADType
557 : {
558 : static constexpr bool value = false;
559 : };
560 :
561 : template <>
562 : struct IsADType<ADReal>
563 : {
564 : static constexpr bool value = true;
565 : };
566 :
567 : template <>
568 : struct IsADType<ADPoint>
569 : {
570 : static constexpr bool value = true;
571 : };
572 :
573 : template <template <typename T, typename... Args> class W, typename T, typename... Args>
574 : struct IsADType<W<T, Args...>>
575 : {
576 : static constexpr bool value = IsADType<T>::value;
577 : };
578 :
579 : template <typename T, typename... Args>
580 : struct IsADType<MetaPhysicL::DualNumber<T, Args...>>
581 : {
582 : static constexpr bool value = true;
583 : };
584 :
585 : /**
586 : * This is a helper variable template for cases when we want to use a default compile-time
587 : * error with constexpr-based if conditions. The templating delays the triggering
588 : * of the static assertion until the template is instantiated.
589 : */
590 : template <class... Ts>
591 : constexpr std::false_type always_false{};
592 :
593 : } // namespace Moose
594 :
595 : /**
596 : * some AD typedefs for backwards compatibility
597 : */
598 : typedef ADRealVectorValue ADRealVectorValue;
599 : typedef ADRealTensorValue ADRealTensorValue;
600 : typedef ADRealGradient ADRealGradient;
601 :
602 : template <typename T>
603 : using ADTemplateVariableValue =
604 : typename OutputTools<typename Moose::ADType<T>::type>::VariableValue;
605 : template <typename T>
606 : using ADTemplateVariableGradient =
607 : typename OutputTools<typename Moose::ADType<T>::type>::VariableGradient;
608 : template <typename T>
609 : using ADTemplateVariableSecond =
610 : typename OutputTools<typename Moose::ADType<T>::type>::VariableSecond;
611 : template <typename T>
612 : using ADTemplateVariableCurl = typename OutputTools<typename Moose::ADType<T>::type>::VariableCurl;
613 :
614 : typedef VariableTestValue ADVariableTestValue;
615 : typedef VariableTestGradient ADVariableTestGradient;
616 : typedef VariableTestSecond ADVariableTestSecond;
617 : typedef VectorVariableTestValue ADVectorVariableTestValue;
618 : typedef VectorVariableTestGradient ADVectorVariableTestGradient;
619 : typedef VectorVariableTestSecond ADVectorVariableTestSecond;
620 :
621 : // We can use the non-ad version for test values because these don't depend on the mesh
622 : // displacements (unless the location of the quadrature points depend on the mesh displacements...)
623 : template <typename T>
624 : using ADTemplateVariableTestValue = typename OutputTools<T>::VariableTestValue;
625 : template <typename T>
626 : using ADTemplateVariablePhiValue = typename OutputTools<T>::VariablePhiValue;
627 :
628 : // We need to use the AD version for test gradients and seconds because these *do* depend on the
629 : // mesh displacements
630 : template <typename T>
631 : using ADTemplateVariableTestGradient =
632 : typename OutputTools<typename Moose::ADType<T>::type>::VariableTestGradient;
633 : template <typename T>
634 : using ADTemplateVariableTestSecond =
635 : typename OutputTools<typename Moose::ADType<T>::type>::VariableTestSecond;
636 : template <typename T>
637 : using ADTemplateVariablePhiGradient =
638 : typename OutputTools<typename Moose::ADType<T>::type>::VariablePhiGradient;
639 : using ADVariablePhiGradient = ADTemplateVariablePhiGradient<Real>;
640 :
641 : // Templated typed to support is_ad templated classes
642 : namespace Moose
643 : {
644 : template <typename T, bool is_ad>
645 : using GenericType = typename std::conditional<is_ad, typename ADType<T>::type, T>::type;
646 : }
647 :
648 : template <bool is_ad>
649 : using GenericReal = Moose::GenericType<Real, is_ad>;
650 : template <bool is_ad>
651 : using GenericChainedReal = Moose::GenericType<ChainedReal, is_ad>;
652 : template <bool is_ad>
653 : using GenericRealVectorValue = Moose::GenericType<RealVectorValue, is_ad>;
654 : template <bool is_ad>
655 : using GenericRealTensorValue = Moose::GenericType<RealTensorValue, is_ad>;
656 : template <bool is_ad>
657 : using GenericRankTwoTensor = Moose::GenericType<RankTwoTensor, is_ad>;
658 : template <bool is_ad>
659 : using GenericRankThreeTensor = Moose::GenericType<RankThreeTensor, is_ad>;
660 : template <bool is_ad>
661 : using GenericRankFourTensor = Moose::GenericType<RankFourTensor, is_ad>;
662 : template <bool is_ad>
663 : using GenericVariableValue = Moose::GenericType<VariableValue, is_ad>;
664 : template <bool is_ad>
665 : using GenericVectorVariableValue = Moose::GenericType<VectorVariableValue, is_ad>;
666 : template <bool is_ad>
667 : using GenericVariableGradient = Moose::GenericType<VariableGradient, is_ad>;
668 : template <bool is_ad>
669 : using GenericVariableSecond = Moose::GenericType<VariableSecond, is_ad>;
670 : template <bool is_ad>
671 : using GenericDenseVector = Moose::GenericType<DenseVector<Real>, is_ad>;
672 : template <bool is_ad>
673 : using GenericDenseMatrix = Moose::GenericType<DenseMatrix<Real>, is_ad>;
674 :
675 : namespace Moose
676 : {
677 : extern const processor_id_type INVALID_PROCESSOR_ID;
678 : extern const SubdomainID ANY_BLOCK_ID;
679 : extern const SubdomainID INVALID_BLOCK_ID;
680 : extern const BoundaryID ANY_BOUNDARY_ID;
681 : extern const BoundaryID INVALID_BOUNDARY_ID;
682 : extern const TagID INVALID_TAG_ID;
683 : extern const TagTypeID INVALID_TAG_TYPE_ID;
684 : const std::set<SubdomainID> EMPTY_BLOCK_IDS = {};
685 : const std::set<BoundaryID> EMPTY_BOUNDARY_IDS = {};
686 :
687 : /**
688 : * MaterialData types
689 : *
690 : * @see FEProblemBase, MaterialPropertyInterface
691 : */
692 : enum MaterialDataType
693 : {
694 : BLOCK_MATERIAL_DATA,
695 : BOUNDARY_MATERIAL_DATA,
696 : FACE_MATERIAL_DATA,
697 : NEIGHBOR_MATERIAL_DATA,
698 : INTERFACE_MATERIAL_DATA
699 : };
700 :
701 : /**
702 : * Flag for AuxKernel related execution type.
703 : */
704 : enum AuxGroup
705 : {
706 : PRE_IC = 0,
707 : PRE_AUX = 1,
708 : POST_AUX = 2,
709 : ALL = 3
710 : };
711 :
712 : /**
713 : * Framework-wide stuff
714 : */
715 : enum VarKindType
716 : {
717 : VAR_SOLVER,
718 : VAR_AUXILIARY,
719 : VAR_ANY
720 : };
721 :
722 : enum VarFieldType
723 : {
724 : VAR_FIELD_STANDARD,
725 : VAR_FIELD_SCALAR,
726 : VAR_FIELD_VECTOR,
727 : VAR_FIELD_ARRAY,
728 : VAR_FIELD_ANY
729 : };
730 :
731 : enum CouplingType
732 : {
733 : COUPLING_DIAG,
734 : COUPLING_FULL,
735 : COUPLING_CUSTOM
736 : };
737 :
738 : enum ConstraintSideType
739 : {
740 : SIDE_PRIMARY,
741 : SIDE_SECONDARY
742 : };
743 :
744 : enum DGResidualType
745 : {
746 : Element,
747 : Neighbor
748 : };
749 :
750 : enum DGJacobianType
751 : {
752 : ElementElement,
753 : ElementNeighbor,
754 : NeighborElement,
755 : NeighborNeighbor
756 : };
757 :
758 : enum ConstraintType
759 : {
760 : Secondary = Element,
761 : Primary = Neighbor
762 : };
763 :
764 : enum class ElementType : unsigned int
765 : {
766 : Element = DGResidualType::Element,
767 : Neighbor = DGResidualType::Neighbor,
768 : Lower = DGResidualType::Neighbor + 1
769 : };
770 :
771 : enum class MortarType : unsigned int
772 : {
773 : Secondary = static_cast<unsigned int>(Moose::ElementType::Element),
774 : Primary = static_cast<unsigned int>(Moose::ElementType::Neighbor),
775 : Lower = static_cast<unsigned int>(Moose::ElementType::Lower)
776 : };
777 :
778 : /**
779 : * The type of nonlinear computation being performed
780 : */
781 : enum class ComputeType
782 : {
783 : Residual,
784 : Jacobian,
785 : ResidualAndJacobian
786 : };
787 :
788 : /**
789 : * The filter type applied to a particular piece of "restartable" data. These filters
790 : * will be applied during deserialization to include or exclude data as appropriate.
791 : */
792 : enum class RESTARTABLE_FILTER : unsigned char
793 : {
794 : RECOVERABLE
795 : };
796 :
797 : enum ConstraintJacobianType
798 : {
799 : SecondarySecondary = ElementElement,
800 : SecondaryPrimary = ElementNeighbor,
801 : PrimarySecondary = NeighborElement,
802 : PrimaryPrimary = NeighborNeighbor,
803 : LowerLower,
804 : LowerSecondary,
805 : LowerPrimary,
806 : SecondaryLower,
807 : PrimaryLower
808 : };
809 :
810 : enum CoordinateSystemType : int
811 : {
812 : COORD_XYZ = 0,
813 : COORD_RZ,
814 : COORD_RSPHERICAL
815 : };
816 :
817 : /**
818 : * Preconditioning side
819 : */
820 : enum PCSideType
821 : {
822 : PCS_LEFT,
823 : PCS_RIGHT,
824 : PCS_SYMMETRIC,
825 : PCS_DEFAULT ///< Use whatever we have in PETSc
826 : };
827 :
828 : /**
829 : * Norm type for converge test
830 : */
831 : enum MooseKSPNormType
832 : {
833 : KSPN_NONE,
834 : KSPN_PRECONDITIONED,
835 : KSPN_UNPRECONDITIONED,
836 : KSPN_NATURAL,
837 : KSPN_DEFAULT ///< Use whatever we have in PETSc
838 : };
839 :
840 : /**
841 : * Type of the solve
842 : */
843 : enum SolveType
844 : {
845 : ST_PJFNK, ///< Preconditioned Jacobian-Free Newton Krylov
846 : ST_JFNK, ///< Jacobian-Free Newton Krylov
847 : ST_NEWTON, ///< Full Newton Solve
848 : ST_FD, ///< Use finite differences to compute Jacobian
849 : ST_LINEAR ///< Solving a linear problem
850 : };
851 :
852 : /**
853 : * Type of the eigen solve
854 : */
855 : enum EigenSolveType
856 : {
857 : EST_POWER, ///< Power / Inverse / RQI
858 : EST_ARNOLDI, ///< Arnoldi
859 : EST_KRYLOVSCHUR, ///< Krylov-Schur
860 : EST_JACOBI_DAVIDSON, ///< Jacobi-Davidson
861 : EST_NONLINEAR_POWER, ///< Nonlinear inverse power
862 : EST_NEWTON, ///< Newton-based eigensolver with an assembled Jacobian matrix (fully coupled by default)
863 : EST_PJFNK, ///< Preconditioned Jacobian-free Newton Krylov
864 : EST_PJFNKMO, ///< The same as PJFNK except that matrix-vector multiplication is employed to replace residual evaluation in linear solver
865 : EST_JFNK ///< Jacobian-free Newton Krylov
866 : };
867 :
868 : /**
869 : * Type of the eigen problem
870 : */
871 : enum EigenProblemType
872 : {
873 : EPT_HERMITIAN, ///< Hermitian
874 : EPT_NON_HERMITIAN, ///< Non-Hermitian
875 : EPT_GEN_HERMITIAN, ///< Generalized Hermitian
876 : EPT_GEN_INDEFINITE, ///< Generalized Hermitian indefinite
877 : EPT_GEN_NON_HERMITIAN, ///< Generalized Non-Hermitian
878 : EPT_POS_GEN_NON_HERMITIAN, ///< Generalized Non-Hermitian with positive (semi-)definite B
879 : EPT_SLEPC_DEFAULT ///< use whatever SLPEC has by default
880 : };
881 :
882 : /**
883 : * Which eigen pairs
884 : */
885 : enum WhichEigenPairs
886 : {
887 : WEP_LARGEST_MAGNITUDE, ///< largest magnitude
888 : WEP_SMALLEST_MAGNITUDE, ///< smallest magnitude
889 : WEP_LARGEST_REAL, ///< largest real
890 : WEP_SMALLEST_REAL, ///< smallest real
891 : WEP_LARGEST_IMAGINARY, ///< largest imaginary
892 : WEP_SMALLEST_IMAGINARY, ///< smallest imaginary
893 : WEP_TARGET_MAGNITUDE, ///< target magnitude
894 : WEP_TARGET_REAL, ///< target real
895 : WEP_TARGET_IMAGINARY, ///< target imaginary
896 : WEP_ALL_EIGENVALUES, ///< all eigenvalues
897 : WEP_SLEPC_DEFAULT ///< use whatever we have in SLEPC
898 : };
899 :
900 : /**
901 : * Time integrators
902 : */
903 : enum TimeIntegratorType
904 : {
905 : TI_IMPLICIT_EULER,
906 : TI_EXPLICIT_EULER,
907 : TI_CRANK_NICOLSON,
908 : TI_BDF2,
909 : TI_EXPLICIT_MIDPOINT,
910 : TI_LSTABLE_DIRK2,
911 : TI_EXPLICIT_TVD_RK_2,
912 : TI_NEWMARK_BETA
913 : };
914 :
915 : /**
916 : * Type of constraint formulation
917 : */
918 : enum ConstraintFormulationType
919 : {
920 : Penalty,
921 : Kinematic
922 : };
923 : /**
924 : * Type of the line search
925 : */
926 : enum LineSearchType
927 : {
928 : LS_INVALID, ///< means not set
929 : LS_DEFAULT,
930 : LS_NONE,
931 : LS_BASIC,
932 : LS_SHELL,
933 : LS_CONTACT,
934 : LS_PROJECT,
935 : LS_L2,
936 : LS_BT,
937 : LS_CP
938 : };
939 :
940 : /**
941 : * Type of the matrix-free finite-differencing parameter
942 : */
943 : enum MffdType
944 : {
945 : MFFD_INVALID, ///< means not set
946 : MFFD_WP,
947 : MFFD_DS
948 : };
949 :
950 : /**
951 : * Type of patch update strategy for modeling node-face constraints or contact
952 : */
953 : enum PatchUpdateType
954 : {
955 : Never,
956 : Always,
957 : Auto,
958 : Iteration
959 : };
960 :
961 : /**
962 : * Main types of Relationship Managers
963 : */
964 : enum class RelationshipManagerType : unsigned char
965 : {
966 : DEFAULT = 0,
967 : GEOMETRIC = 1 << 0,
968 : ALGEBRAIC = 1 << 1,
969 : COUPLING = 1 << 2
970 : };
971 :
972 : enum RMSystemType
973 : {
974 : NONLINEAR,
975 : AUXILIARY,
976 : NONE
977 : };
978 :
979 : enum VectorTagType
980 : {
981 : VECTOR_TAG_RESIDUAL = 0,
982 : VECTOR_TAG_SOLUTION = 1,
983 : VECTOR_TAG_ANY = 2
984 : };
985 :
986 : /**
987 : * The type for the callback to set RelationshipManager parameters
988 : */
989 : typedef std::function<void(const InputParameters &, InputParameters &)>
990 : RelationshipManagerInputParameterCallback;
991 :
992 : std::string stringify(const Moose::RelationshipManagerType & t);
993 : std::string stringify(const Moose::TimeIntegratorType & t);
994 : } // namespace Moose
995 :
996 : namespace libMesh
997 : {
998 : template <>
999 : inline void
1000 0 : print_helper(std::ostream & os, const Moose::RelationshipManagerType * param)
1001 : {
1002 : // Specialization so that we don't print out unprintable characters
1003 0 : os << Moose::stringify(*param);
1004 0 : }
1005 :
1006 : // End of Moose Namespace
1007 : }
1008 :
1009 : template <>
1010 : struct enable_bitmask_operators<Moose::RelationshipManagerType>
1011 : {
1012 : static const bool enable = true;
1013 : };
1014 :
1015 : /**
1016 : * This Macro is used to generate std::string derived types useful for
1017 : * strong type checking and special handling in the GUI. It does not
1018 : * extend std::string in any way so it is generally "safe"
1019 : *
1020 : * Be sure to use the DerivativeStringToJSON macro for new types in
1021 : * MooseTypes.C to also define to_json for each
1022 : */
1023 : #define DerivativeStringClass(TheName) \
1024 : class TheName : public std::string \
1025 : { \
1026 : public: \
1027 : TheName() : std::string() {} \
1028 : TheName(const std::string & str) : std::string(str) {} \
1029 : TheName(const std::string & str, size_t pos, size_t n = npos) : std::string(str, pos, n) {} \
1030 : TheName(const char * s, size_t n) : std::string(s, n) {} \
1031 : TheName(const char * s) : std::string(s) {} \
1032 : TheName(size_t n, char c) : std::string(n, c) {} \
1033 : }; \
1034 : namespace nlohmann \
1035 : { \
1036 : template <> \
1037 : struct adl_serializer<TheName> \
1038 : { \
1039 : static void to_json(json & j, const TheName & v); \
1040 : }; \
1041 : } \
1042 : static_assert(true, "")
1043 :
1044 : // Instantiate new Types
1045 :
1046 : /// This type is for expected (i.e. input) file names or paths that your simulation needs.
1047 : /// If relative types are assigned to this type, they are replaced with an absolute path
1048 : /// that is relative to the context of the parameter (usually the input file).
1049 1093090 : DerivativeStringClass(FileName);
1050 :
1051 : /// Similar to FileName but without an extension
1052 2117573 : DerivativeStringClass(FileNameNoExtension);
1053 :
1054 : /// This type is for expected filenames that should be relative and will not have their
1055 : /// values set to absolute paths like FileName
1056 0 : DerivativeStringClass(RelativeFileName);
1057 :
1058 : /// This type is for files used in the DataFileInterface, which enables searching of files
1059 : /// within the registered data directory
1060 44182 : DerivativeStringClass(DataFileName);
1061 :
1062 : /// This type is similar to "FileName", but is used to further filter file dialogs on known file mesh types
1063 480681 : DerivativeStringClass(MeshFileName);
1064 :
1065 : /// This type is similar to "FileName", but is used to further filter file dialogs on known matrix file types
1066 82444 : DerivativeStringClass(MatrixFileName);
1067 :
1068 : /// This type is for output file base
1069 165921 : DerivativeStringClass(OutFileBase);
1070 :
1071 : /// This type is used for objects that expect nonlinear variable names (i.e. Kernels, BCs)
1072 7158860 : DerivativeStringClass(NonlinearVariableName);
1073 :
1074 : /// This type is used for objects that expect linear variable names (i.e. LinearFVKernels, LinearFVBCs)
1075 181259 : DerivativeStringClass(LinearVariableName);
1076 :
1077 : /// This type is used for objects that expect linear or nonlinear solver variable names
1078 5056846 : DerivativeStringClass(SolverVariableName);
1079 :
1080 : /// This type is used for objects that expect Auxiliary variable names (i.e. AuxKernels, AuxBCs)
1081 2597383 : DerivativeStringClass(AuxVariableName);
1082 :
1083 : /// This type is used for objects that expect either Solver or Auxiliary Variables such as postprocessors
1084 3201619 : DerivativeStringClass(VariableName);
1085 :
1086 : /// This type is used for objects that expect Boundary Names/Ids read from or generated on the current mesh
1087 5720657 : DerivativeStringClass(BoundaryName);
1088 :
1089 : /// This type is similar to BoundaryName but is used for "blocks" or subdomains in the current mesh
1090 4574843 : DerivativeStringClass(SubdomainName);
1091 :
1092 : /// This type is used for objects that expect Postprocessor objects
1093 4871934 : DerivativeStringClass(PostprocessorName);
1094 :
1095 : /// This type is used for objects that expect VectorPostprocessor objects
1096 322329 : DerivativeStringClass(VectorPostprocessorName);
1097 :
1098 : /// This type is used for objects that expect MeshDivision objects
1099 223582 : DerivativeStringClass(MeshDivisionName);
1100 :
1101 : /// This type is used for objects that expect Moose Function objects
1102 5848632 : DerivativeStringClass(FunctionName);
1103 :
1104 : /// This type is used for objects that expect Moose Distribution objects
1105 16178 : DerivativeStringClass(DistributionName);
1106 :
1107 : /// This type is used for objects that expect Moose Sampler objects
1108 16060 : DerivativeStringClass(SamplerName);
1109 :
1110 : /// This type is used for objects that expect "UserObject" names
1111 936831 : DerivativeStringClass(UserObjectName);
1112 :
1113 : /// This type is used for objects that expect an Indicator object name
1114 31497 : DerivativeStringClass(IndicatorName);
1115 :
1116 : /// This type is used for objects that expect an Marker object name
1117 35994 : DerivativeStringClass(MarkerName);
1118 :
1119 : /// This type is used for objects that expect an MultiApp object name
1120 1098203 : DerivativeStringClass(MultiAppName);
1121 :
1122 : /// Used for objects the require Output object names
1123 10328387 : DerivativeStringClass(OutputName);
1124 :
1125 : /// Used for objects that expect MaterialProperty names
1126 94489717 : DerivativeStringClass(MaterialPropertyName);
1127 :
1128 : /// Used for objects that expect Moose::Functor names
1129 4331776 : DerivativeStringClass(MooseFunctorName);
1130 :
1131 : /// User for accessing Material objects
1132 44464 : DerivativeStringClass(MaterialName);
1133 :
1134 : /// Tag Name
1135 11946955 : DerivativeStringClass(TagName);
1136 :
1137 : /// Name of MeshGenerators
1138 1310089 : DerivativeStringClass(MeshGeneratorName);
1139 :
1140 : /// Name of extra element IDs
1141 58992 : DerivativeStringClass(ExtraElementIDName);
1142 :
1143 : /// Name of a Reporter Value, second argument to ReporterName (see Reporter.h)
1144 174447 : DerivativeStringClass(ReporterValueName);
1145 :
1146 : /// Name of a Component object
1147 386 : DerivativeStringClass(ComponentName);
1148 :
1149 : /// Name of a Physics object
1150 152 : DerivativeStringClass(PhysicsName);
1151 :
1152 : /// Name of a Positions object
1153 542085 : DerivativeStringClass(PositionsName);
1154 :
1155 : /// Name of a Times object
1156 1600320 : DerivativeStringClass(TimesName);
1157 :
1158 : /// Name of an Executor. Used for inputs to Executors
1159 29119 : DerivativeStringClass(ExecutorName);
1160 :
1161 : /// ParsedFunction/ParsedMaterial etc. FParser expression
1162 195803 : DerivativeStringClass(ParsedFunctionExpression);
1163 :
1164 : /// System name support of multiple nonlinear systems on the same mesh
1165 1680407 : DerivativeStringClass(NonlinearSystemName);
1166 :
1167 : /// Name of a Convergence object
1168 1928125 : DerivativeStringClass(ConvergenceName);
1169 :
1170 : /// System name support of multiple linear systems on the same mesh
1171 42564 : DerivativeStringClass(LinearSystemName);
1172 :
1173 : /// Name of a system which either be linear or nonlinear
1174 2594693 : DerivativeStringClass(SolverSystemName);
1175 :
1176 : /// Command line argument, specialized to handle quotes in vector arguments
1177 3340 : DerivativeStringClass(CLIArgString);
1178 :
1179 : #ifdef MOOSE_MFEM_ENABLED
1180 : /**
1181 : * Coefficients used in input for MFEM residual objects
1182 : */
1183 : ///@{
1184 656243 : DerivativeStringClass(MFEMScalarCoefficientName);
1185 269131 : DerivativeStringClass(MFEMVectorCoefficientName);
1186 0 : DerivativeStringClass(MFEMMatrixCoefficientName);
1187 : ///@}
1188 : #endif
1189 : /**
1190 : * additional MOOSE typedefs
1191 : */
1192 : typedef std::vector<VariableName> CoupledName;
1193 : namespace Moose
1194 : {
1195 : extern const TagName SOLUTION_TAG;
1196 : extern const TagName OLD_SOLUTION_TAG;
1197 : extern const TagName OLDER_SOLUTION_TAG;
1198 : extern const TagName PREVIOUS_NL_SOLUTION_TAG;
1199 : extern const TagName PREVIOUS_FP_SOLUTION_TAG;
1200 :
1201 : enum class FEBackend
1202 : {
1203 : LibMesh
1204 : #ifdef MOOSE_MFEM_ENABLED
1205 : ,
1206 : MFEM
1207 : #endif
1208 : };
1209 : }
1210 :
1211 : /// macros for adding Tensor index enums locally
1212 : #define usingTensorIndices(...) \
1213 : enum \
1214 : { \
1215 : __VA_ARGS__ \
1216 : }
|