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
245 : };
246 :
247 : // These are used by MooseVariableData and MooseVariableDataFV
248 : enum GeometryType
249 : {
250 : Volume,
251 : Face
252 : };
253 :
254 : template <typename OutputType>
255 : struct ShapeType
256 : {
257 : typedef OutputType type;
258 : };
259 : template <>
260 : struct ShapeType<Eigen::Matrix<Real, Eigen::Dynamic, 1>>
261 : {
262 : typedef Real type;
263 : };
264 :
265 : template <typename OutputType>
266 : struct DOFType
267 : {
268 : typedef OutputType type;
269 : };
270 : template <>
271 : struct DOFType<RealVectorValue>
272 : {
273 : typedef Real type;
274 : };
275 : } // namespace Moose
276 :
277 : template <typename OutputType>
278 : struct OutputTools
279 : {
280 : typedef typename libMesh::TensorTools::IncrementRank<OutputType>::type OutputGradient;
281 : typedef typename libMesh::TensorTools::IncrementRank<OutputGradient>::type OutputSecond;
282 : typedef typename libMesh::TensorTools::DecrementRank<OutputType>::type OutputDivergence;
283 :
284 : typedef MooseArray<OutputType> VariableValue;
285 : typedef MooseArray<OutputGradient> VariableGradient;
286 : typedef MooseArray<OutputSecond> VariableSecond;
287 : typedef MooseArray<OutputType> VariableCurl;
288 : typedef MooseArray<OutputDivergence> VariableDivergence;
289 :
290 : typedef typename Moose::ShapeType<OutputType>::type OutputShape;
291 : typedef typename libMesh::TensorTools::IncrementRank<OutputShape>::type OutputShapeGradient;
292 : typedef typename libMesh::TensorTools::IncrementRank<OutputShapeGradient>::type OutputShapeSecond;
293 : typedef typename libMesh::TensorTools::DecrementRank<OutputShape>::type OutputShapeDivergence;
294 :
295 : typedef MooseArray<std::vector<OutputShape>> VariablePhiValue;
296 : typedef MooseArray<std::vector<OutputShapeGradient>> VariablePhiGradient;
297 : typedef MooseArray<std::vector<OutputShapeSecond>> VariablePhiSecond;
298 : typedef MooseArray<std::vector<OutputShape>> VariablePhiCurl;
299 : typedef MooseArray<std::vector<OutputShapeDivergence>> VariablePhiDivergence;
300 :
301 : typedef MooseArray<std::vector<OutputShape>> VariableTestValue;
302 : typedef MooseArray<std::vector<OutputShapeGradient>> VariableTestGradient;
303 : typedef MooseArray<std::vector<OutputShapeSecond>> VariableTestSecond;
304 : typedef MooseArray<std::vector<OutputShape>> VariableTestCurl;
305 : typedef MooseArray<std::vector<OutputShapeDivergence>> VariableTestDivergence;
306 :
307 : // DoF value type for the template class OutputType
308 : typedef typename Moose::DOFType<OutputType>::type OutputData;
309 : typedef MooseArray<OutputData> DoFValue;
310 : typedef OutputType OutputValue;
311 : };
312 :
313 : // types for standard variable
314 : typedef typename OutputTools<Real>::VariableValue VariableValue;
315 : typedef typename OutputTools<Real>::VariableGradient VariableGradient;
316 : typedef typename OutputTools<Real>::VariableSecond VariableSecond;
317 : typedef typename OutputTools<Real>::VariableCurl VariableCurl;
318 : typedef typename OutputTools<Real>::VariableDivergence VariableDivergence;
319 : typedef typename OutputTools<Real>::VariablePhiValue VariablePhiValue;
320 : typedef typename OutputTools<Real>::VariablePhiGradient VariablePhiGradient;
321 : typedef typename OutputTools<Real>::VariablePhiSecond VariablePhiSecond;
322 : typedef typename OutputTools<Real>::VariablePhiCurl VariablePhiCurl;
323 : typedef typename OutputTools<Real>::VariablePhiDivergence VariablePhiDivergence;
324 : typedef typename OutputTools<Real>::VariableTestValue VariableTestValue;
325 : typedef typename OutputTools<Real>::VariableTestGradient VariableTestGradient;
326 : typedef typename OutputTools<Real>::VariableTestSecond VariableTestSecond;
327 : typedef typename OutputTools<Real>::VariableTestCurl VariableTestCurl;
328 : typedef typename OutputTools<Real>::VariableTestDivergence VariableTestDivergence;
329 :
330 : // types for vector variable
331 : typedef typename OutputTools<RealVectorValue>::VariableValue VectorVariableValue;
332 : typedef typename OutputTools<RealVectorValue>::VariableGradient VectorVariableGradient;
333 : typedef typename OutputTools<RealVectorValue>::VariableSecond VectorVariableSecond;
334 : typedef typename OutputTools<RealVectorValue>::VariableCurl VectorVariableCurl;
335 : typedef typename OutputTools<RealVectorValue>::VariableDivergence VectorVariableDivergence;
336 : typedef typename OutputTools<RealVectorValue>::VariablePhiValue VectorVariablePhiValue;
337 : typedef typename OutputTools<RealVectorValue>::VariablePhiGradient VectorVariablePhiGradient;
338 : typedef typename OutputTools<RealVectorValue>::VariablePhiSecond VectorVariablePhiSecond;
339 : typedef typename OutputTools<RealVectorValue>::VariablePhiCurl VectorVariablePhiCurl;
340 : typedef typename OutputTools<RealVectorValue>::VariablePhiDivergence VectorVariablePhiDivergence;
341 : typedef typename OutputTools<RealVectorValue>::VariableTestValue VectorVariableTestValue;
342 : typedef typename OutputTools<RealVectorValue>::VariableTestGradient VectorVariableTestGradient;
343 : typedef typename OutputTools<RealVectorValue>::VariableTestSecond VectorVariableTestSecond;
344 : typedef typename OutputTools<RealVectorValue>::VariableTestCurl VectorVariableTestCurl;
345 : typedef typename OutputTools<RealVectorValue>::VariableTestDivergence VectorVariableTestDivergence;
346 :
347 : // types for array variable
348 : typedef typename OutputTools<RealEigenVector>::VariableValue ArrayVariableValue;
349 : typedef typename OutputTools<RealEigenVector>::VariableGradient ArrayVariableGradient;
350 : typedef typename OutputTools<RealEigenVector>::VariableSecond ArrayVariableSecond;
351 : typedef typename OutputTools<RealEigenVector>::VariableCurl ArrayVariableCurl;
352 : typedef typename OutputTools<RealEigenVector>::VariableDivergence ArrayVariableDivergence;
353 : typedef typename OutputTools<RealEigenVector>::VariablePhiValue ArrayVariablePhiValue;
354 : typedef typename OutputTools<RealEigenVector>::VariablePhiGradient ArrayVariablePhiGradient;
355 : typedef std::vector<std::vector<Eigen::Map<RealDIMValue>>> MappedArrayVariablePhiGradient;
356 : typedef typename OutputTools<RealEigenVector>::VariablePhiSecond ArrayVariablePhiSecond;
357 : typedef typename OutputTools<RealEigenVector>::VariablePhiCurl ArrayVariablePhiCurl;
358 : typedef typename OutputTools<RealEigenVector>::VariablePhiDivergence ArrayVariablePhiDivergence;
359 : typedef typename OutputTools<RealEigenVector>::VariableTestValue ArrayVariableTestValue;
360 : typedef typename OutputTools<RealEigenVector>::VariableTestGradient ArrayVariableTestGradient;
361 : typedef typename OutputTools<RealEigenVector>::VariableTestSecond ArrayVariableTestSecond;
362 : typedef typename OutputTools<RealEigenVector>::VariableTestCurl ArrayVariableTestCurl;
363 : typedef typename OutputTools<RealEigenVector>::VariableTestDivergence ArrayVariableTestDivergence;
364 :
365 : /**
366 : * AD typedefs
367 : */
368 : typedef libMesh::VectorValue<ADReal> ADRealVectorValue;
369 : typedef ADRealVectorValue ADRealGradient;
370 : typedef libMesh::VectorValue<ADReal> ADPoint;
371 : typedef libMesh::TensorValue<ADReal> ADRealTensorValue;
372 : typedef libMesh::DenseMatrix<ADReal> ADDenseMatrix;
373 : typedef libMesh::DenseVector<ADReal> ADDenseVector;
374 : typedef MooseArray<ADReal> ADVariableValue;
375 : typedef MooseArray<ADRealVectorValue> ADVariableGradient;
376 : typedef MooseArray<ADRealTensorValue> ADVariableSecond;
377 : typedef MooseArray<ADRealVectorValue> ADVectorVariableValue;
378 : typedef MooseArray<ADRealTensorValue> ADVectorVariableGradient;
379 : typedef MooseArray<libMesh::TypeNTensor<3, ADReal>> ADVectorVariableSecond;
380 : typedef MooseArray<ADRealVectorValue> ADVectorVariableCurl;
381 :
382 : namespace Moose
383 : {
384 :
385 : // type conversion from regular to AD
386 : template <typename T>
387 : struct ADType
388 : {
389 : // unless a specialization exists we assume there is no specific AD type
390 : typedef T type;
391 : };
392 :
393 : template <>
394 : struct ADType<Real>
395 : {
396 : typedef ADReal type;
397 : };
398 : template <>
399 : struct ADType<ChainedReal>
400 : {
401 : typedef ChainedADReal type;
402 : };
403 : template <>
404 : struct ADType<Point>
405 : {
406 : typedef ADPoint type;
407 : };
408 :
409 : template <>
410 : struct ADType<RealVectorValue>
411 : {
412 : typedef ADRealVectorValue type;
413 : };
414 : template <>
415 : struct ADType<RankTwoTensor>
416 : {
417 : typedef ADRankTwoTensor type;
418 : };
419 : template <>
420 : struct ADType<RankThreeTensor>
421 : {
422 : typedef ADRankThreeTensor type;
423 : };
424 : template <>
425 : struct ADType<RankFourTensor>
426 : {
427 : typedef ADRankFourTensor type;
428 : };
429 :
430 : template <>
431 : struct ADType<SymmetricRankTwoTensor>
432 : {
433 : typedef ADSymmetricRankTwoTensor type;
434 : };
435 : template <>
436 : struct ADType<SymmetricRankFourTensor>
437 : {
438 : typedef ADSymmetricRankFourTensor type;
439 : };
440 :
441 : template <template <typename T> class W, typename T>
442 : struct ADType<W<T>>
443 : {
444 : typedef W<typename ADType<T>::type> type;
445 : };
446 :
447 : template <typename T>
448 : struct ADType<std::vector<T, std::allocator<T>>>
449 : {
450 : typedef typename ADType<T>::type adT;
451 : typedef std::vector<adT, std::allocator<adT>> type;
452 : };
453 :
454 : template <typename T>
455 : struct ADType<std::list<T, std::allocator<T>>>
456 : {
457 : typedef typename ADType<T>::type adT;
458 : typedef std::list<adT, std::allocator<adT>> type;
459 : };
460 :
461 : template <typename T>
462 : struct ADType<std::set<T, std::less<T>, std::allocator<T>>>
463 : {
464 : typedef typename ADType<T>::type adT;
465 : typedef std::set<adT, std::less<adT>, std::allocator<adT>> type;
466 : };
467 :
468 : template <typename T>
469 : struct ADType<DenseVector<T>>
470 : {
471 : typedef DenseVector<typename ADType<T>::type> type;
472 : };
473 :
474 : template <typename T>
475 : struct ADType<DenseMatrix<T>>
476 : {
477 : typedef DenseMatrix<typename ADType<T>::type> type;
478 : };
479 :
480 : template <>
481 : struct ADType<RealEigenVector>
482 : {
483 : typedef RealEigenVector type;
484 : };
485 : template <>
486 : struct ADType<VariableValue>
487 : {
488 : typedef ADVariableValue type;
489 : };
490 : template <>
491 : struct ADType<VariableGradient>
492 : {
493 : typedef ADVariableGradient type;
494 : };
495 : template <>
496 : struct ADType<VariableSecond>
497 : {
498 : typedef ADVariableSecond type;
499 : };
500 :
501 : template <>
502 : struct ADType<ADReal>
503 : {
504 : typedef ADReal type;
505 : };
506 : template <>
507 : struct ADType<ChainedADReal>
508 : {
509 : typedef ChainedADReal type;
510 : };
511 : template <>
512 : struct ADType<ADRankTwoTensor>
513 : {
514 : typedef ADRankTwoTensor type;
515 : };
516 : template <>
517 : struct ADType<ADRankThreeTensor>
518 : {
519 : typedef ADRankThreeTensor type;
520 : };
521 : template <>
522 : struct ADType<ADRankFourTensor>
523 : {
524 : typedef ADRankFourTensor type;
525 : };
526 :
527 : template <>
528 : struct ADType<ADSymmetricRankTwoTensor>
529 : {
530 : typedef ADSymmetricRankTwoTensor type;
531 : };
532 : template <>
533 : struct ADType<ADSymmetricRankFourTensor>
534 : {
535 : typedef ADSymmetricRankFourTensor type;
536 : };
537 :
538 : template <>
539 : struct ADType<ADVariableValue>
540 : {
541 : typedef ADVariableValue type;
542 : };
543 : template <>
544 : struct ADType<ADVariableGradient>
545 : {
546 : typedef ADVariableGradient type;
547 : };
548 : template <>
549 : struct ADType<ADVariableSecond>
550 : {
551 : typedef ADVariableSecond type;
552 : };
553 :
554 : template <typename T>
555 : struct IsADType
556 : {
557 : static constexpr bool value = false;
558 : };
559 :
560 : template <>
561 : struct IsADType<ADReal>
562 : {
563 : static constexpr bool value = true;
564 : };
565 :
566 : template <>
567 : struct IsADType<ADPoint>
568 : {
569 : static constexpr bool value = true;
570 : };
571 :
572 : template <template <typename T, typename... Args> class W, typename T, typename... Args>
573 : struct IsADType<W<T, Args...>>
574 : {
575 : static constexpr bool value = IsADType<T>::value;
576 : };
577 :
578 : template <typename T, typename... Args>
579 : struct IsADType<MetaPhysicL::DualNumber<T, Args...>>
580 : {
581 : static constexpr bool value = true;
582 : };
583 :
584 : /**
585 : * This is a helper variable template for cases when we want to use a default compile-time
586 : * error with constexpr-based if conditions. The templating delays the triggering
587 : * of the static assertion until the template is instantiated.
588 : */
589 : template <class... Ts>
590 : constexpr std::false_type always_false{};
591 :
592 : } // namespace Moose
593 :
594 : /**
595 : * some AD typedefs for backwards compatibility
596 : */
597 : typedef ADRealVectorValue ADRealVectorValue;
598 : typedef ADRealTensorValue ADRealTensorValue;
599 : typedef ADRealGradient ADRealGradient;
600 :
601 : template <typename T>
602 : using ADTemplateVariableValue =
603 : typename OutputTools<typename Moose::ADType<T>::type>::VariableValue;
604 : template <typename T>
605 : using ADTemplateVariableGradient =
606 : typename OutputTools<typename Moose::ADType<T>::type>::VariableGradient;
607 : template <typename T>
608 : using ADTemplateVariableSecond =
609 : typename OutputTools<typename Moose::ADType<T>::type>::VariableSecond;
610 : template <typename T>
611 : using ADTemplateVariableCurl = typename OutputTools<typename Moose::ADType<T>::type>::VariableCurl;
612 :
613 : typedef VariableTestValue ADVariableTestValue;
614 : typedef VariableTestGradient ADVariableTestGradient;
615 : typedef VariableTestSecond ADVariableTestSecond;
616 : typedef VectorVariableTestValue ADVectorVariableTestValue;
617 : typedef VectorVariableTestGradient ADVectorVariableTestGradient;
618 : typedef VectorVariableTestSecond ADVectorVariableTestSecond;
619 :
620 : // We can use the non-ad version for test values because these don't depend on the mesh
621 : // displacements (unless the location of the quadrature points depend on the mesh displacements...)
622 : template <typename T>
623 : using ADTemplateVariableTestValue = typename OutputTools<T>::VariableTestValue;
624 : template <typename T>
625 : using ADTemplateVariablePhiValue = typename OutputTools<T>::VariablePhiValue;
626 :
627 : // We need to use the AD version for test gradients and seconds because these *do* depend on the
628 : // mesh displacements
629 : template <typename T>
630 : using ADTemplateVariableTestGradient =
631 : typename OutputTools<typename Moose::ADType<T>::type>::VariableTestGradient;
632 : template <typename T>
633 : using ADTemplateVariableTestSecond =
634 : typename OutputTools<typename Moose::ADType<T>::type>::VariableTestSecond;
635 : template <typename T>
636 : using ADTemplateVariablePhiGradient =
637 : typename OutputTools<typename Moose::ADType<T>::type>::VariablePhiGradient;
638 : using ADVariablePhiGradient = ADTemplateVariablePhiGradient<Real>;
639 :
640 : // Templated typed to support is_ad templated classes
641 : namespace Moose
642 : {
643 : template <typename T, bool is_ad>
644 : using GenericType = typename std::conditional<is_ad, typename ADType<T>::type, T>::type;
645 : }
646 :
647 : template <bool is_ad>
648 : using GenericReal = Moose::GenericType<Real, is_ad>;
649 : template <bool is_ad>
650 : using GenericChainedReal = Moose::GenericType<ChainedReal, is_ad>;
651 : template <bool is_ad>
652 : using GenericRealVectorValue = Moose::GenericType<RealVectorValue, is_ad>;
653 : template <bool is_ad>
654 : using GenericRealTensorValue = Moose::GenericType<RealTensorValue, is_ad>;
655 : template <bool is_ad>
656 : using GenericRankTwoTensor = Moose::GenericType<RankTwoTensor, is_ad>;
657 : template <bool is_ad>
658 : using GenericRankThreeTensor = Moose::GenericType<RankThreeTensor, is_ad>;
659 : template <bool is_ad>
660 : using GenericRankFourTensor = Moose::GenericType<RankFourTensor, is_ad>;
661 : template <bool is_ad>
662 : using GenericVariableValue = Moose::GenericType<VariableValue, is_ad>;
663 : template <bool is_ad>
664 : using GenericVectorVariableValue = Moose::GenericType<VectorVariableValue, is_ad>;
665 : template <bool is_ad>
666 : using GenericVariableGradient = Moose::GenericType<VariableGradient, is_ad>;
667 : template <bool is_ad>
668 : using GenericVariableSecond = Moose::GenericType<VariableSecond, is_ad>;
669 : template <bool is_ad>
670 : using GenericDenseVector = Moose::GenericType<DenseVector<Real>, is_ad>;
671 : template <bool is_ad>
672 : using GenericDenseMatrix = Moose::GenericType<DenseMatrix<Real>, is_ad>;
673 :
674 : namespace Moose
675 : {
676 : extern const processor_id_type INVALID_PROCESSOR_ID;
677 : extern const SubdomainID ANY_BLOCK_ID;
678 : extern const SubdomainID INVALID_BLOCK_ID;
679 : extern const BoundaryID ANY_BOUNDARY_ID;
680 : extern const BoundaryID INVALID_BOUNDARY_ID;
681 : extern const TagID INVALID_TAG_ID;
682 : extern const TagTypeID INVALID_TAG_TYPE_ID;
683 : const std::set<SubdomainID> EMPTY_BLOCK_IDS = {};
684 : const std::set<BoundaryID> EMPTY_BOUNDARY_IDS = {};
685 :
686 : /**
687 : * MaterialData types
688 : *
689 : * @see FEProblemBase, MaterialPropertyInterface
690 : */
691 : enum MaterialDataType
692 : {
693 : BLOCK_MATERIAL_DATA,
694 : BOUNDARY_MATERIAL_DATA,
695 : FACE_MATERIAL_DATA,
696 : NEIGHBOR_MATERIAL_DATA,
697 : INTERFACE_MATERIAL_DATA
698 : };
699 :
700 : /**
701 : * Flag for AuxKernel related execution type.
702 : */
703 : enum AuxGroup
704 : {
705 : PRE_IC = 0,
706 : PRE_AUX = 1,
707 : POST_AUX = 2,
708 : ALL = 3
709 : };
710 :
711 : /**
712 : * Framework-wide stuff
713 : */
714 : enum VarKindType
715 : {
716 : VAR_SOLVER,
717 : VAR_AUXILIARY,
718 : VAR_ANY
719 : };
720 :
721 : enum VarFieldType
722 : {
723 : VAR_FIELD_STANDARD,
724 : VAR_FIELD_SCALAR,
725 : VAR_FIELD_VECTOR,
726 : VAR_FIELD_ARRAY,
727 : VAR_FIELD_ANY
728 : };
729 :
730 : enum CouplingType
731 : {
732 : COUPLING_DIAG,
733 : COUPLING_FULL,
734 : COUPLING_CUSTOM
735 : };
736 :
737 : enum ConstraintSideType
738 : {
739 : SIDE_PRIMARY,
740 : SIDE_SECONDARY
741 : };
742 :
743 : enum DGResidualType
744 : {
745 : Element,
746 : Neighbor
747 : };
748 :
749 : enum DGJacobianType
750 : {
751 : ElementElement,
752 : ElementNeighbor,
753 : NeighborElement,
754 : NeighborNeighbor
755 : };
756 :
757 : enum ConstraintType
758 : {
759 : Secondary = Element,
760 : Primary = Neighbor
761 : };
762 :
763 : enum class ElementType : unsigned int
764 : {
765 : Element = DGResidualType::Element,
766 : Neighbor = DGResidualType::Neighbor,
767 : Lower = DGResidualType::Neighbor + 1
768 : };
769 :
770 : enum class MortarType : unsigned int
771 : {
772 : Secondary = static_cast<unsigned int>(Moose::ElementType::Element),
773 : Primary = static_cast<unsigned int>(Moose::ElementType::Neighbor),
774 : Lower = static_cast<unsigned int>(Moose::ElementType::Lower)
775 : };
776 :
777 : /**
778 : * The type of nonlinear computation being performed
779 : */
780 : enum class ComputeType
781 : {
782 : Residual,
783 : Jacobian,
784 : ResidualAndJacobian
785 : };
786 :
787 : /**
788 : * The filter type applied to a particular piece of "restartable" data. These filters
789 : * will be applied during deserialization to include or exclude data as appropriate.
790 : */
791 : enum class RESTARTABLE_FILTER : unsigned char
792 : {
793 : RECOVERABLE
794 : };
795 :
796 : enum ConstraintJacobianType
797 : {
798 : SecondarySecondary = ElementElement,
799 : SecondaryPrimary = ElementNeighbor,
800 : PrimarySecondary = NeighborElement,
801 : PrimaryPrimary = NeighborNeighbor,
802 : LowerLower,
803 : LowerSecondary,
804 : LowerPrimary,
805 : SecondaryLower,
806 : PrimaryLower
807 : };
808 :
809 : enum CoordinateSystemType : int
810 : {
811 : COORD_XYZ = 0,
812 : COORD_RZ,
813 : COORD_RSPHERICAL
814 : };
815 :
816 : /**
817 : * Preconditioning side
818 : */
819 : enum PCSideType
820 : {
821 : PCS_LEFT,
822 : PCS_RIGHT,
823 : PCS_SYMMETRIC,
824 : PCS_DEFAULT ///< Use whatever we have in PETSc
825 : };
826 :
827 : /**
828 : * Norm type for converge test
829 : */
830 : enum MooseKSPNormType
831 : {
832 : KSPN_NONE,
833 : KSPN_PRECONDITIONED,
834 : KSPN_UNPRECONDITIONED,
835 : KSPN_NATURAL,
836 : KSPN_DEFAULT ///< Use whatever we have in PETSc
837 : };
838 :
839 : /**
840 : * Type of the solve
841 : */
842 : enum SolveType
843 : {
844 : ST_PJFNK, ///< Preconditioned Jacobian-Free Newton Krylov
845 : ST_JFNK, ///< Jacobian-Free Newton Krylov
846 : ST_NEWTON, ///< Full Newton Solve
847 : ST_FD, ///< Use finite differences to compute Jacobian
848 : ST_LINEAR ///< Solving a linear problem
849 : };
850 :
851 : /**
852 : * Type of the eigen solve
853 : */
854 : enum EigenSolveType
855 : {
856 : EST_POWER, ///< Power / Inverse / RQI
857 : EST_ARNOLDI, ///< Arnoldi
858 : EST_KRYLOVSCHUR, ///< Krylov-Schur
859 : EST_JACOBI_DAVIDSON, ///< Jacobi-Davidson
860 : EST_NONLINEAR_POWER, ///< Nonlinear inverse power
861 : EST_NEWTON, ///< Newton-based eigensolver with an assembled Jacobian matrix (fully coupled by default)
862 : EST_PJFNK, ///< Preconditioned Jacobian-free Newton Krylov
863 : EST_PJFNKMO, ///< The same as PJFNK except that matrix-vector multiplication is employed to replace residual evaluation in linear solver
864 : EST_JFNK ///< Jacobian-free Newton Krylov
865 : };
866 :
867 : /**
868 : * Type of the eigen problem
869 : */
870 : enum EigenProblemType
871 : {
872 : EPT_HERMITIAN, ///< Hermitian
873 : EPT_NON_HERMITIAN, ///< Non-Hermitian
874 : EPT_GEN_HERMITIAN, ///< Generalized Hermitian
875 : EPT_GEN_INDEFINITE, ///< Generalized Hermitian indefinite
876 : EPT_GEN_NON_HERMITIAN, ///< Generalized Non-Hermitian
877 : EPT_POS_GEN_NON_HERMITIAN, ///< Generalized Non-Hermitian with positive (semi-)definite B
878 : EPT_SLEPC_DEFAULT ///< use whatever SLPEC has by default
879 : };
880 :
881 : /**
882 : * Which eigen pairs
883 : */
884 : enum WhichEigenPairs
885 : {
886 : WEP_LARGEST_MAGNITUDE, ///< largest magnitude
887 : WEP_SMALLEST_MAGNITUDE, ///< smallest magnitude
888 : WEP_LARGEST_REAL, ///< largest real
889 : WEP_SMALLEST_REAL, ///< smallest real
890 : WEP_LARGEST_IMAGINARY, ///< largest imaginary
891 : WEP_SMALLEST_IMAGINARY, ///< smallest imaginary
892 : WEP_TARGET_MAGNITUDE, ///< target magnitude
893 : WEP_TARGET_REAL, ///< target real
894 : WEP_TARGET_IMAGINARY, ///< target imaginary
895 : WEP_ALL_EIGENVALUES, ///< all eigenvalues
896 : WEP_SLEPC_DEFAULT ///< use whatever we have in SLEPC
897 : };
898 :
899 : /**
900 : * Time integrators
901 : */
902 : enum TimeIntegratorType
903 : {
904 : TI_IMPLICIT_EULER,
905 : TI_EXPLICIT_EULER,
906 : TI_CRANK_NICOLSON,
907 : TI_BDF2,
908 : TI_EXPLICIT_MIDPOINT,
909 : TI_LSTABLE_DIRK2,
910 : TI_EXPLICIT_TVD_RK_2,
911 : TI_NEWMARK_BETA
912 : };
913 :
914 : /**
915 : * Type of constraint formulation
916 : */
917 : enum ConstraintFormulationType
918 : {
919 : Penalty,
920 : Kinematic
921 : };
922 : /**
923 : * Type of the line search
924 : */
925 : enum LineSearchType
926 : {
927 : LS_INVALID, ///< means not set
928 : LS_DEFAULT,
929 : LS_NONE,
930 : LS_BASIC,
931 : LS_SHELL,
932 : LS_CONTACT,
933 : LS_PROJECT,
934 : LS_L2,
935 : LS_BT,
936 : LS_CP
937 : };
938 :
939 : /**
940 : * Type of the matrix-free finite-differencing parameter
941 : */
942 : enum MffdType
943 : {
944 : MFFD_INVALID, ///< means not set
945 : MFFD_WP,
946 : MFFD_DS
947 : };
948 :
949 : /**
950 : * Type of patch update strategy for modeling node-face constraints or contact
951 : */
952 : enum PatchUpdateType
953 : {
954 : Never,
955 : Always,
956 : Auto,
957 : Iteration
958 : };
959 :
960 : /**
961 : * Main types of Relationship Managers
962 : */
963 : enum class RelationshipManagerType : unsigned char
964 : {
965 : DEFAULT = 0,
966 : GEOMETRIC = 1 << 0,
967 : ALGEBRAIC = 1 << 1,
968 : COUPLING = 1 << 2
969 : };
970 :
971 : enum RMSystemType
972 : {
973 : NONLINEAR,
974 : AUXILIARY,
975 : NONE
976 : };
977 :
978 : enum VectorTagType
979 : {
980 : VECTOR_TAG_RESIDUAL = 0,
981 : VECTOR_TAG_SOLUTION = 1,
982 : VECTOR_TAG_ANY = 2
983 : };
984 :
985 : /**
986 : * The type for the callback to set RelationshipManager parameters
987 : */
988 : typedef std::function<void(const InputParameters &, InputParameters &)>
989 : RelationshipManagerInputParameterCallback;
990 :
991 : std::string stringify(const Moose::RelationshipManagerType & t);
992 : std::string stringify(const Moose::TimeIntegratorType & t);
993 : } // namespace Moose
994 :
995 : namespace libMesh
996 : {
997 : template <>
998 : inline void
999 0 : print_helper(std::ostream & os, const Moose::RelationshipManagerType * param)
1000 : {
1001 : // Specialization so that we don't print out unprintable characters
1002 0 : os << Moose::stringify(*param);
1003 0 : }
1004 :
1005 : // End of Moose Namespace
1006 : }
1007 :
1008 : template <>
1009 : struct enable_bitmask_operators<Moose::RelationshipManagerType>
1010 : {
1011 : static const bool enable = true;
1012 : };
1013 :
1014 : /**
1015 : * This Macro is used to generate std::string derived types useful for
1016 : * strong type checking and special handling in the GUI. It does not
1017 : * extend std::string in any way so it is generally "safe"
1018 : *
1019 : * Be sure to use the DerivativeStringToJSON macro for new types in
1020 : * MooseTypes.C to also define to_json for each
1021 : */
1022 : #define DerivativeStringClass(TheName) \
1023 : class TheName : public std::string \
1024 : { \
1025 : public: \
1026 : TheName() : std::string() {} \
1027 : TheName(const std::string & str) : std::string(str) {} \
1028 : TheName(const std::string & str, size_t pos, size_t n = npos) : std::string(str, pos, n) {} \
1029 : TheName(const char * s, size_t n) : std::string(s, n) {} \
1030 : TheName(const char * s) : std::string(s) {} \
1031 : TheName(size_t n, char c) : std::string(n, c) {} \
1032 : }; \
1033 : namespace nlohmann \
1034 : { \
1035 : template <> \
1036 : struct adl_serializer<TheName> \
1037 : { \
1038 : static void to_json(json & j, const TheName & v); \
1039 : }; \
1040 : } \
1041 : static_assert(true, "")
1042 :
1043 : // Instantiate new Types
1044 :
1045 : /// This type is for expected (i.e. input) file names or paths that your simulation needs.
1046 : /// If relative types are assigned to this type, they are replaced with an absolute path
1047 : /// that is relative to the context of the parameter (usually the input file).
1048 952494 : DerivativeStringClass(FileName);
1049 :
1050 : /// Similar to FileName but without an extension
1051 1357267 : DerivativeStringClass(FileNameNoExtension);
1052 :
1053 : /// This type is for expected filenames that should be relative and will not have their
1054 : /// values set to absolute paths like FileName
1055 0 : DerivativeStringClass(RelativeFileName);
1056 :
1057 : /// This type is for files used in the DataFileInterface, which enables searching of files
1058 : /// within the registered data directory
1059 44277 : DerivativeStringClass(DataFileName);
1060 :
1061 : /// This type is similar to "FileName", but is used to further filter file dialogs on known file mesh types
1062 439048 : DerivativeStringClass(MeshFileName);
1063 :
1064 : /// This type is similar to "FileName", but is used to further filter file dialogs on known matrix file types
1065 43239 : DerivativeStringClass(MatrixFileName);
1066 :
1067 : /// This type is for output file base
1068 151477 : DerivativeStringClass(OutFileBase);
1069 :
1070 : /// This type is used for objects that expect nonlinear variable names (i.e. Kernels, BCs)
1071 7032746 : DerivativeStringClass(NonlinearVariableName);
1072 :
1073 : /// This type is used for objects that expect linear variable names (i.e. LinearFVKernels, LinearFVBCs)
1074 162558 : DerivativeStringClass(LinearVariableName);
1075 :
1076 : /// This type is used for objects that expect linear or nonlinear solver variable names
1077 4595893 : DerivativeStringClass(SolverVariableName);
1078 :
1079 : /// This type is used for objects that expect Auxiliary variable names (i.e. AuxKernels, AuxBCs)
1080 2542552 : DerivativeStringClass(AuxVariableName);
1081 :
1082 : /// This type is used for objects that expect either Solver or Auxiliary Variables such as postprocessors
1083 3008697 : DerivativeStringClass(VariableName);
1084 :
1085 : /// This type is used for objects that expect Boundary Names/Ids read from or generated on the current mesh
1086 4289218 : DerivativeStringClass(BoundaryName);
1087 :
1088 : /// This type is similar to BoundaryName but is used for "blocks" or subdomains in the current mesh
1089 2163499 : DerivativeStringClass(SubdomainName);
1090 :
1091 : /// This type is used for objects that expect Postprocessor objects
1092 4095262 : DerivativeStringClass(PostprocessorName);
1093 :
1094 : /// This type is used for objects that expect VectorPostprocessor objects
1095 319620 : DerivativeStringClass(VectorPostprocessorName);
1096 :
1097 : /// This type is used for objects that expect MeshDivision objects
1098 218690 : DerivativeStringClass(MeshDivisionName);
1099 :
1100 : /// This type is used for objects that expect Moose Function objects
1101 5040846 : DerivativeStringClass(FunctionName);
1102 :
1103 : /// This type is used for objects that expect Moose Distribution objects
1104 16112 : DerivativeStringClass(DistributionName);
1105 :
1106 : /// This type is used for objects that expect Moose Sampler objects
1107 15888 : DerivativeStringClass(SamplerName);
1108 :
1109 : /// This type is used for objects that expect "UserObject" names
1110 926679 : DerivativeStringClass(UserObjectName);
1111 :
1112 : /// This type is used for objects that expect an Indicator object name
1113 31293 : DerivativeStringClass(IndicatorName);
1114 :
1115 : /// This type is used for objects that expect an Marker object name
1116 34158 : DerivativeStringClass(MarkerName);
1117 :
1118 : /// This type is used for objects that expect an MultiApp object name
1119 1084744 : DerivativeStringClass(MultiAppName);
1120 :
1121 : /// Used for objects the require Output object names
1122 4388742 : DerivativeStringClass(OutputName);
1123 :
1124 : /// Used for objects that expect MaterialProperty names
1125 57016172 : DerivativeStringClass(MaterialPropertyName);
1126 :
1127 : /// Used for objects that expect Moose::Functor names
1128 4056395 : DerivativeStringClass(MooseFunctorName);
1129 :
1130 : /// User for accessing Material objects
1131 44358 : DerivativeStringClass(MaterialName);
1132 :
1133 : /// Tag Name
1134 9904243 : DerivativeStringClass(TagName);
1135 :
1136 : /// Name of MeshGenerators
1137 1258745 : DerivativeStringClass(MeshGeneratorName);
1138 :
1139 : /// Name of extra element IDs
1140 58723 : DerivativeStringClass(ExtraElementIDName);
1141 :
1142 : /// Name of a Reporter Value, second argument to ReporterName (see Reporter.h)
1143 65976 : DerivativeStringClass(ReporterValueName);
1144 :
1145 : /// Name of a Component object
1146 364 : DerivativeStringClass(ComponentName);
1147 :
1148 : /// Name of a Physics object
1149 144 : DerivativeStringClass(PhysicsName);
1150 :
1151 : /// Name of a Positions object
1152 379690 : DerivativeStringClass(PositionsName);
1153 :
1154 : /// Name of a Times object
1155 1497099 : DerivativeStringClass(TimesName);
1156 :
1157 : /// Name of an Executor. Used for inputs to Executors
1158 29119 : DerivativeStringClass(ExecutorName);
1159 :
1160 : /// ParsedFunction/ParsedMaterial etc. FParser expression
1161 106070 : DerivativeStringClass(ParsedFunctionExpression);
1162 :
1163 : /// System name support of multiple nonlinear systems on the same mesh
1164 729323 : DerivativeStringClass(NonlinearSystemName);
1165 :
1166 : /// Name of a Convergence object
1167 1628534 : DerivativeStringClass(ConvergenceName);
1168 :
1169 : /// System name support of multiple linear systems on the same mesh
1170 35660 : DerivativeStringClass(LinearSystemName);
1171 :
1172 : /// Name of a system which either be linear or nonlinear
1173 1468711 : DerivativeStringClass(SolverSystemName);
1174 :
1175 : /// Command line argument, specialized to handle quotes in vector arguments
1176 3088 : DerivativeStringClass(CLIArgString);
1177 :
1178 : #ifdef MFEM_ENABLED
1179 : /**
1180 : * Coefficients used in input for MFEM residual objects
1181 : */
1182 : ///@{
1183 295743 : DerivativeStringClass(MFEMScalarCoefficientName);
1184 138768 : DerivativeStringClass(MFEMVectorCoefficientName);
1185 0 : DerivativeStringClass(MFEMMatrixCoefficientName);
1186 : ///@}
1187 : #endif
1188 : /**
1189 : * additional MOOSE typedefs
1190 : */
1191 : typedef std::vector<VariableName> CoupledName;
1192 : namespace Moose
1193 : {
1194 : extern const TagName SOLUTION_TAG;
1195 : extern const TagName OLD_SOLUTION_TAG;
1196 : extern const TagName OLDER_SOLUTION_TAG;
1197 : extern const TagName PREVIOUS_NL_SOLUTION_TAG;
1198 :
1199 : enum class FEBackend
1200 : {
1201 : LibMesh
1202 : #ifdef MOOSE_MFEM_ENABLED
1203 : ,
1204 : MFEM
1205 : #endif
1206 : };
1207 : }
1208 :
1209 : /// macros for adding Tensor index enums locally
1210 : #define usingTensorIndices(...) \
1211 : enum \
1212 : { \
1213 : __VA_ARGS__ \
1214 : }
|