https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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 <csignal>
18#include <limits>
19#include <memory>
20#include <set>
21#include <string>
22
23#define QUOTE(macro) stringifyName(macro)
24#define stringifyName(name) #name
25
26namespace libMesh
27{
28template <typename>
29class NumericVector;
30template <typename>
31class SparseMatrix;
32
33// This was deprecated in libMesh a year ago! It was obsolete 5 years
34// ago! How are 6 apps in CI still using it!?
35#ifdef LIBMESH_ENABLE_DEPRECATED
36template <typename T>
37using UniquePtr = std::unique_ptr<T>;
38#endif
39}
40
41class ActionFactory;
42class Factory;
43class MooseEnumItem;
44class ExecFlagEnum;
46
47namespace hit
48{
49class Node;
50}
51
56
62namespace Moose
63{
64static_assert(__cplusplus >= 201703L,
65 "MOOSE requires a C++17 compatible compiler (GCC >= 7.5.0, Clang >= 5.0.2). Please "
66 "update your compiler or, if compatible, add '-std=c++17' to your compiler flags "
67 "and try again. If using the MOOSE conda package, please attempt a MOOSE environment "
68 "update (using `mamba update moose-dev`). If this update is not successful, please "
69 "create a new MOOSE environment (see "
70 "https://mooseframework.inl.gov/getting_started/installation/"
71 "conda.html#uninstall-conda-moose-environment).");
72}
73
80#define parallel_if \
81 (cond) bool __local_bool__ = (cond); \
82 Parallel::max<bool>(__local_bool__); \
83 if (__local_bool__)
84
88#ifdef __bg__ // On Blue Gene Architectures there is no underscore
89#define FORTRAN_CALL(name) name
90#else // One underscore everywhere else
91#define FORTRAN_CALL(name) name##_
92#endif
93
101template <class M, class... Args>
102std::pair<typename M::iterator, bool>
103moose_try_emplace(M & m, const typename M::key_type & k, Args &&... args)
104{
105 auto it = m.lower_bound(k);
106 if (it == m.end() || m.key_comp()(k, it->first))
107 {
108 return {m.emplace_hint(it,
109 std::piecewise_construct,
110 std::forward_as_tuple(k),
111 std::forward_as_tuple(std::forward<Args>(args)...)),
112 true};
113 }
114 return {it, false};
115}
116
117// forward declarations
118class Syntax;
119class FEProblemBase;
120
121// Define MOOSE execution flags, this cannot be done in MooseTypes because the registration calls
122// must be in Moose.C to remain consistent with other registration calls.
124extern const ExecFlagType EXEC_NONE;
125extern const ExecFlagType EXEC_INITIAL;
127extern const ExecFlagType EXEC_LINEAR;
129extern const ExecFlagType EXEC_NONLINEAR;
130extern const ExecFlagType EXEC_POSTCHECK;
138extern const ExecFlagType EXEC_FINAL;
139extern const ExecFlagType EXEC_FORCED;
140extern const ExecFlagType EXEC_FAILED;
141extern const ExecFlagType EXEC_CUSTOM;
142extern const ExecFlagType EXEC_SUBDOMAIN;
146extern const ExecFlagType EXEC_TRANSFER;
147extern const ExecFlagType EXEC_PRE_KERNELS;
148extern const ExecFlagType EXEC_ALWAYS;
149#ifdef LIBMESH_ENABLE_AMR
151#endif
152
153namespace Moose
154{
155// MOOSE is not tested with LIBMESH_DIM != 3
156static_assert(LIBMESH_DIM == 3,
157 "MOOSE must be built with a libmesh library compiled without --enable-1D-only "
158 "or --enable-2D-only");
159
165static constexpr std::size_t dim = LIBMESH_DIM;
166
168inline constexpr std::size_t invalid_size_t = std::numeric_limits<std::size_t>::max();
169
174extern volatile std::sig_atomic_t interrupt_signal_number;
175
180extern bool show_multiple;
181
189
193extern bool _trap_fpe;
194
198extern bool _warnings_are_errors;
199
203extern bool _deprecated_is_error;
204
211extern bool _throw_on_error;
212
217extern bool _throw_on_warning;
218
225
229#define COLOR_BLACK (Moose::colorConsole() ? XTERM_BLACK : "")
230#define COLOR_RED (Moose::colorConsole() ? XTERM_RED : "")
231#define COLOR_GREEN (Moose::colorConsole() ? XTERM_GREEN : "")
232#define COLOR_YELLOW (Moose::colorConsole() ? XTERM_YELLOW : "")
233#define COLOR_BLUE (Moose::colorConsole() ? XTERM_BLUE : "")
234#define COLOR_MAGENTA (Moose::colorConsole() ? XTERM_MAGENTA : "")
235#define COLOR_CYAN (Moose::colorConsole() ? XTERM_CYAN : "")
236#define COLOR_WHITE (Moose::colorConsole() ? XTERM_WHITE : "")
237#define COLOR_DEFAULT (Moose::colorConsole() ? XTERM_DEFAULT : "")
238
240bool colorConsole();
241
244bool setColorConsole(bool use_color, bool force = false);
245
249using libMesh::err;
250using libMesh::out;
251
256void registerAll(Factory & f, ActionFactory & af, Syntax & s);
257
258void registerObjects(Factory & factory, const std::set<std::string> & obj_labels);
259void addActionTypes(Syntax & syntax);
260void registerActions(Syntax & syntax, ActionFactory & action_factory);
261void registerActions(Syntax & syntax,
262 ActionFactory & action_factory,
263 const std::set<std::string> & obj_labels);
264
265void associateSyntax(Syntax & syntax, ActionFactory & action_factory);
266
267void setSolverDefaults(FEProblemBase & problem);
268
273MPI_Comm swapLibMeshComm(MPI_Comm new_comm);
274
276{
277public:
280 ScopedCommSwapper(MPI_Comm new_comm) : _orig(swapLibMeshComm(new_comm)) {}
287
288private:
289 MPI_Comm _orig;
290};
291
298{
299public:
304
309 ScopedThrowOnError(const bool throw_on_error);
310
316
317private:
320};
321
328{
329public:
334
339 ScopedDeprecatedIsError(const bool deprecated_is_error);
340
346
347private:
350};
351
355std::string hitMessagePrefix(const hit::Node & node);
356
357// MOOSE Requires PETSc to run, this CPP check will cause a compile error if PETSc is not found
358#ifndef LIBMESH_HAVE_PETSC
359#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.
360#endif
361
362} // namespace Moose
363
364// If we are using MFEM, in addition to the checks we do as part of the build system in moose.mk,
365// we check at compile time if both MOOSE and MFEM were built in dbg mode or not
366#ifdef MOOSE_MFEM_ENABLED
367#include "libmesh/ignore_warnings.h"
368#include <mfem.hpp>
369#include "libmesh/restore_warnings.h"
370#ifdef MFEM_DEBUG
371static_assert(std::string_view(QUOTE(METHOD)) == "dbg",
372 "MFEM was built in dbg mode, but not MOOSE. Try reinstalling "
373 "MFEM using the scripts/update_and_rebuild_mfem.sh script.");
374#else
375static_assert(std::string_view(QUOTE(METHOD)) != "dbg",
376 "MOOSE was built in dbg mode, but not MFEM. Try reinstalling "
377 "MFEM using the scripts/update_and_rebuild_mfem.sh script.");
378#endif
379#endif
void MooseMatView(libMesh::SparseMatrix< libMesh::Number > &mat)
const ExecFlagType EXEC_FORCED
Definition Moose.C:49
const ExecFlagType EXEC_TRANSFER
Definition Moose.C:57
const ExecFlagType EXEC_PRE_MULTIAPP_SETUP
Definition Moose.C:56
const ExecFlagType EXEC_MULTIAPP_FIXED_POINT_END
Definition Moose.C:40
const ExecFlagType EXEC_MULTISYSTEM_FIXED_POINT_ITERATION_END
Definition Moose.C:46
const ExecFlagType EXEC_MULTIAPP_FIXED_POINT_CONVERGENCE
Definition Moose.C:44
const ExecFlagType EXEC_SUBDOMAIN
Definition Moose.C:52
const ExecFlagType EXEC_TIMESTEP_END
Definition Moose.C:36
void MooseVecView(libMesh::NumericVector< libMesh::Number > &vector)
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition Moose.C:37
const ExecFlagType EXEC_SAME_AS_MULTIAPP
Definition Moose.C:55
const ExecFlagType EXEC_POSTCHECK
Definition Moose.C:35
const ExecFlagType EXEC_ALWAYS
Definition Moose.C:53
const ExecFlagType EXEC_CUSTOM
Definition Moose.C:51
const ExecFlagType EXEC_MULTIAPP_FIXED_POINT_ITERATION_END
Definition Moose.C:38
const ExecFlagType EXEC_POST_ADAPTIVITY
Definition Moose.C:60
const ExecFlagType EXEC_LINEAR_CONVERGENCE
Definition Moose.C:32
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:103
const ExecFlagType EXEC_INITIAL
Definition Moose.C:30
const ExecFlagType EXEC_MULTIAPP_FIXED_POINT_BEGIN
Definition Moose.C:42
const ExecFlagType EXEC_LINEAR
Definition Moose.C:31
const ExecFlagType EXEC_PRE_KERNELS
Definition Moose.C:58
const ExecFlagType EXEC_NONLINEAR
Definition Moose.C:33
const ExecFlagType EXEC_FAILED
Definition Moose.C:50
const ExecFlagType EXEC_NONE
Definition Moose.C:29
const ExecFlagType EXEC_FINAL
Definition Moose.C:48
const ExecFlagType EXEC_NONLINEAR_CONVERGENCE
Definition Moose.C:34
const ExecFlagType EXEC_PRE_DISPLACE
Definition Moose.C:54
Specialized factory for generic Action System objects.
A MultiMooseEnum object to hold "execute_on" flags.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Generic factory class for build all sorts of objects.
Definition Factory.h:29
Class for containing MooseEnum item information.
This class provides an interface for common operations on field variables of both FE and FV types wit...
ScopedCommSwapper(MPI_Comm new_comm)
Swaps the current libmesh MPI communicator for new_comm.
Definition Moose.h:280
void forceSwap()
Forcibly swap the currently swapped-out communicator back in to libmesh.
Definition Moose.h:286
virtual ~ScopedCommSwapper()
Definition Moose.h:281
Scoped helper for setting Moose::_deprecated_is_error during this scope.
Definition Moose.h:328
~ScopedDeprecatedIsError()
Destructor, which sets Moose::_deprecated_is_error to what it was upon construction.
Definition Moose.C:877
ScopedDeprecatedIsError()
Default constructor, which sets Moose::_deprecated_is_error = true.
Definition Moose.C:875
const bool _deprecated_is_error_before
The value of Moose::_throw_on_error at construction.
Definition Moose.h:349
Scoped helper for setting Moose::_throw_on_error during this scope.
Definition Moose.h:298
~ScopedThrowOnError()
Destructor, which sets Moose::_throw_on_error to what it was upon construction.
Definition Moose.C:866
const bool _throw_on_error_before
The value of Moose::_throw_on_error at construction.
Definition Moose.h:319
ScopedThrowOnError()
Default constructor, which sets Moose::_throw_on_error = true.
Definition Moose.C:864
Holding syntax for parsing input files.
Definition Syntax.h:22
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
void setSolverDefaults(FEProblemBase &problem)
Definition Moose.C:828
bool _deprecated_is_error
Variable to toggle only deprecated warnings as errors.
Definition Moose.C:895
void registerObjects(Factory &factory, const std::set< std::string > &obj_labels)
Definition Moose.C:103
bool _throw_on_error
Variable to turn on exceptions during mooseError(), should only be used within MOOSE unit tests or wh...
Definition Moose.C:896
constexpr std::size_t invalid_size_t
Value for invalid size_t indices.
Definition Moose.h:168
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:899
void associateSyntax(Syntax &syntax, ActionFactory &action_factory)
Definition Moose.C:821
bool setColorConsole(bool use_color, bool force=false)
Turns color escape sequences on/off for info written to stdout.
Definition Moose.C:851
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:571
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition Moose.h:165
void registerAll(Factory &f, ActionFactory &af, Syntax &s)
Register objects that are in MOOSE.
Definition Moose.C:69
ExecFlagEnum execute_flags
Storage for the registered execute flags.
volatile std::sig_atomic_t 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:898
bool _throw_on_warning
Variable to turn on exceptions during mooseWarning(), should only be used in MOOSE unit tests.
Definition Moose.C:897
bool _warnings_are_errors
Variable to toggle any warning into an error (includes deprecated code warnings)
Definition Moose.C:894
bool colorConsole()
Returns whether Console coloring is turned on (default: true).
Definition Moose.C:845
void addActionTypes(Syntax &syntax)
Definition Moose.C:109
std::string hitMessagePrefix(const hit::Node &node)
Get the prefix to be associated with a hit node for a message.
Definition Moose.C:883
libMesh::PerfLog perf_log
Perflog to be used by applications.
MPI_Comm swapLibMeshComm(MPI_Comm new_comm)
Swap the libMesh MPI communicator out for ours.
Definition Moose.C:835
bool _trap_fpe
Variable indicating whether we will enable FPE trapping for this run.
Definition Moose.h:48
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
OStreamProxy out(std::cout)
OStreamProxy err(std::cerr)
std::unique_ptr< T > UniquePtr
Definition Moose.h:37