https://mooseframework.inl.gov
Moose.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
13 #include "libmesh/perf_log.h"
14 #include "libmesh/libmesh_common.h"
15 #include "XTermConstants.h"
16 
17 #include <memory>
18 #include <set>
19 #include <string>
20 
21 namespace libMesh
22 {
23 template <typename>
24 class NumericVector;
25 template <typename>
26 class SparseMatrix;
27 
28 // This was deprecated in libMesh a year ago! It was obsolete 5 years
29 // ago! How are 6 apps in CI still using it!?
30 #ifdef LIBMESH_ENABLE_DEPRECATED
31 template <typename T>
32 using UniquePtr = std::unique_ptr<T>;
33 #endif
34 }
35 
36 class ActionFactory;
37 class Factory;
38 class MooseEnumItem;
39 class ExecFlagEnum;
41 
46 
52 namespace Moose
53 {
54 static_assert(__cplusplus >= 201703L,
55  "MOOSE requires a C++17 compatible compiler (GCC >= 7.5.0, Clang >= 5.0.2). Please "
56  "update your compiler or, if compatible, add '-std=c++17' to your compiler flags "
57  "and try again. If using the MOOSE conda package, please attempt a MOOSE environment "
58  "update (using `mamba update moose-dev`). If this update is not successful, please "
59  "create a new MOOSE environment (see "
60  "https://mooseframework.inl.gov/getting_started/installation/"
61  "conda.html#uninstall-conda-moose-environment).");
62 }
63 
70 #define parallel_if \
71  (cond) bool __local_bool__ = (cond); \
72  Parallel::max<bool>(__local_bool__); \
73  if (__local_bool__)
74 
78 #ifdef __bg__ // On Blue Gene Architectures there is no underscore
79 #define FORTRAN_CALL(name) name
80 #else // One underscore everywhere else
81 #define FORTRAN_CALL(name) name##_
82 #endif
83 
91 template <class M, class... Args>
92 std::pair<typename M::iterator, bool>
93 moose_try_emplace(M & m, const typename M::key_type & k, Args &&... args)
94 {
95  auto it = m.lower_bound(k);
96  if (it == m.end() || m.key_comp()(k, it->first))
97  {
98  return {m.emplace_hint(it,
99  std::piecewise_construct,
100  std::forward_as_tuple(k),
101  std::forward_as_tuple(std::forward<Args>(args)...)),
102  true};
103  }
104  return {it, false};
105 }
106 
107 // forward declarations
108 class Syntax;
109 class FEProblemBase;
110 
111 // Define MOOSE execution flags, this cannot be done in MooseTypes because the registration calls
112 // must be in Moose.C to remain consistent with other registration calls.
114 extern const ExecFlagType EXEC_NONE;
115 extern const ExecFlagType EXEC_INITIAL;
117 extern const ExecFlagType EXEC_LINEAR;
119 extern const ExecFlagType EXEC_NONLINEAR;
120 extern const ExecFlagType EXEC_POSTCHECK;
121 extern const ExecFlagType EXEC_TIMESTEP_END;
122 extern const ExecFlagType EXEC_TIMESTEP_BEGIN;
126 extern const ExecFlagType EXEC_FINAL;
127 extern const ExecFlagType EXEC_FORCED;
128 extern const ExecFlagType EXEC_FAILED;
129 extern const ExecFlagType EXEC_CUSTOM;
130 extern const ExecFlagType EXEC_SUBDOMAIN;
131 extern const ExecFlagType EXEC_PRE_DISPLACE;
134 extern const ExecFlagType EXEC_TRANSFER;
135 extern const ExecFlagType EXEC_PRE_KERNELS;
136 extern const ExecFlagType EXEC_ALWAYS;
137 #ifdef LIBMESH_ENABLE_AMR
139 #endif
140 
141 namespace Moose
142 {
143 // MOOSE is not tested with LIBMESH_DIM != 3
144 static_assert(LIBMESH_DIM == 3,
145  "MOOSE must be built with a libmesh library compiled without --enable-1D-only "
146  "or --enable-2D-only");
147 
153 static constexpr std::size_t dim = LIBMESH_DIM;
154 
159 extern int interrupt_signal_number;
160 
165 extern bool show_trace;
166 
171 extern bool show_multiple;
172 
180 
184 extern bool _trap_fpe;
185 
189 extern bool _warnings_are_errors;
190 
194 extern bool _deprecated_is_error;
195 
202 extern bool _throw_on_error;
203 
208 extern bool _throw_on_warning;
209 
216 
220 #define COLOR_BLACK (Moose::colorConsole() ? XTERM_BLACK : "")
221 #define COLOR_RED (Moose::colorConsole() ? XTERM_RED : "")
222 #define COLOR_GREEN (Moose::colorConsole() ? XTERM_GREEN : "")
223 #define COLOR_YELLOW (Moose::colorConsole() ? XTERM_YELLOW : "")
224 #define COLOR_BLUE (Moose::colorConsole() ? XTERM_BLUE : "")
225 #define COLOR_MAGENTA (Moose::colorConsole() ? XTERM_MAGENTA : "")
226 #define COLOR_CYAN (Moose::colorConsole() ? XTERM_CYAN : "")
227 #define COLOR_WHITE (Moose::colorConsole() ? XTERM_WHITE : "")
228 #define COLOR_DEFAULT (Moose::colorConsole() ? XTERM_DEFAULT : "")
229 
231 bool colorConsole();
232 
235 bool setColorConsole(bool use_color, bool force = false);
236 
240 using libMesh::err;
241 using libMesh::out;
242 
247 void registerAll(Factory & f, ActionFactory & af, Syntax & s);
248 
249 void registerObjects(Factory & factory, const std::set<std::string> & obj_labels);
250 void addActionTypes(Syntax & syntax);
251 void registerActions(Syntax & syntax, ActionFactory & action_factory);
252 void registerActions(Syntax & syntax,
253  ActionFactory & action_factory,
254  const std::set<std::string> & obj_labels);
255 
256 void associateSyntax(Syntax & syntax, ActionFactory & action_factory);
257 
258 void setSolverDefaults(FEProblemBase & problem);
259 
264 MPI_Comm swapLibMeshComm(MPI_Comm new_comm);
265 
267 {
268 public:
271  ScopedCommSwapper(MPI_Comm new_comm) : _orig(swapLibMeshComm(new_comm)) {}
278 
279 private:
280  MPI_Comm _orig;
281 };
282 
283 // MOOSE Requires PETSc to run, this CPP check will cause a compile error if PETSc is not found
284 #ifndef LIBMESH_HAVE_PETSC
285 #error PETSc has not been detected, please ensure your environment is set up properly then rerun the libmesh build script and try to compile MOOSE again.
286 #endif
287 
288 } // namespace Moose
const ExecFlagType EXEC_TRANSFER
Definition: Moose.C:51
bool show_trace
Set to true (the default) to print the stack trace with error and warning messages - false to omit it...
Definition: Moose.C:761
const ExecFlagType EXEC_FAILED
Definition: Moose.C:44
ScopedCommSwapper(MPI_Comm new_comm)
Swaps the current libmesh MPI communicator for new_comm.
Definition: Moose.h:271
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
bool colorConsole()
Returns whether Console coloring is turned on (default: true).
Definition: Moose.C:744
const ExecFlagType EXEC_NONLINEAR_CONVERGENCE
Definition: Moose.C:32
const ExecFlagType EXEC_CUSTOM
Definition: Moose.C:45
MPI_Comm swapLibMeshComm(MPI_Comm new_comm)
Swap the libMesh MPI communicator out for ours.
Definition: Moose.C:734
const ExecFlagType EXEC_FORCED
Definition: Moose.C:43
Generic factory class for build all sorts of objects.
Definition: Factory.h:28
void setSolverDefaults(FEProblemBase &problem)
Definition: Moose.C:727
const ExecFlagType EXEC_LINEAR_CONVERGENCE
Definition: Moose.C:30
bool _warnings_are_errors
Variable to toggle any warning into an error (includes deprecated code warnings)
Definition: Moose.C:756
void registerActions(Syntax &syntax, ActionFactory &action_factory)
Multiple Action class can be associated with a single input file section, in which case all associate...
Definition: Moose.C:484
const ExecFlagType EXEC_NONE
Definition: Moose.C:27
libMesh::PerfLog perf_log
Perflog to be used by applications.
void associateSyntax(Syntax &syntax, ActionFactory &action_factory)
Definition: Moose.C:720
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:153
const ExecFlagType EXEC_MULTIAPP_FIXED_POINT_END
Definition: Moose.C:36
This class provides an interface for common operations on field variables of both FE and FV types wit...
const ExecFlagType EXEC_TIMESTEP_END
Definition: Moose.C:34
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
const ExecFlagType EXEC_ALWAYS
Definition: Moose.C:47
std::pair< typename M::iterator, bool > moose_try_emplace(M &m, const typename M::key_type &k, Args &&... args)
Function to mirror the behavior of the C++17 std::map::try_emplace() method (no hint).
Definition: Moose.h:93
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
std::unique_ptr< T > UniquePtr
Definition: Moose.h:32
void MooseVecView(libMesh::NumericVector< libMesh::Number > &vector)
void forceSwap()
Forcibly swap the currently swapped-out communicator back in to libmesh.
Definition: Moose.h:277
bool _deprecated_is_error
Variable to toggle only deprecated warnings as errors.
Definition: Moose.C:757
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition: Moose.C:35
const ExecFlagType EXEC_PRE_MULTIAPP_SETUP
Definition: Moose.C:50
Specialized factory for generic Action System objects.
Definition: ActionFactory.h:50
virtual ~ScopedCommSwapper()
Definition: Moose.h:272
OStreamProxy err(std::cerr)
const ExecFlagType EXEC_LINEAR
Definition: Moose.C:29
const ExecFlagType EXEC_PRE_DISPLACE
Definition: Moose.C:48
const ExecFlagType EXEC_POSTCHECK
Definition: Moose.C:33
const ExecFlagType EXEC_NONLINEAR
Definition: Moose.C:31
void MooseMatView(libMesh::SparseMatrix< libMesh::Number > &mat)
bool _trap_fpe
Variable indicating whether we will enable FPE trapping for this run.
bool show_multiple
Set to false (the default) to display an error message only once for each error call code location (a...
Definition: Moose.C:762
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
const ExecFlagType EXEC_MULTIAPP_FIXED_POINT_BEGIN
Definition: Moose.C:38
bool _throw_on_warning
Variable to turn on exceptions during mooseWarning(), should only be used in MOOSE unit tests...
Definition: Moose.C:759
void registerAll(Factory &f, ActionFactory &af, Syntax &s)
Register objects that are in MOOSE.
Definition: Moose.C:63
void registerObjects(Factory &factory, const std::set< std::string > &obj_labels)
Definition: Moose.C:73
bool setColorConsole(bool use_color, bool force=false)
Turns color escape sequences on/off for info written to stdout.
Definition: Moose.C:750
Holding syntax for parsing input files.
Definition: Syntax.h:21
const ExecFlagType EXEC_SAME_AS_MULTIAPP
Definition: Moose.C:49
int interrupt_signal_number
Used by the signal handler to determine if we should write a checkpoint file out at any point during ...
Definition: Moose.C:760
const ExecFlagType EXEC_PRE_KERNELS
Definition: Moose.C:52
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
const ExecFlagType EXEC_SUBDOMAIN
Definition: Moose.C:46
const ExecFlagType EXEC_MULTIAPP_FIXED_POINT_CONVERGENCE
Definition: Moose.C:40
OStreamProxy out(std::cout)
bool _throw_on_error
Variable to turn on exceptions during mooseError(), should only be used within MOOSE unit tests or wh...
Definition: Moose.C:758
const ExecFlagType EXEC_FINAL
Definition: Moose.C:42
void addActionTypes(Syntax &syntax)
Definition: Moose.C:79
const ExecFlagType EXEC_POST_ADAPTIVITY
Definition: Moose.C:54
ExecFlagEnum execute_flags
Storage for the registered execute flags.
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:28