www.mooseframework.org
Moose.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef MOOSE_H
16 #define MOOSE_H
17 
18 #include "libmesh/perf_log.h"
19 #include "libmesh/libmesh_common.h"
20 #include "XTermConstants.h"
21 
22 #include <string>
23 
24 using namespace libMesh;
25 
26 class ActionFactory;
27 class Factory;
28 
33 #ifndef LIBMESH_HAVE_CXX11
34 #error MOOSE requires a C++11 compatible compiler (GCC >= 4.8.4, Clang >= 3.4.0, Intel >= 20130607). Please update your compiler and try again.
35 #endif
36 
43 #define parallel_if \
44  (cond) bool __local_bool__ = (cond); \
45  Parallel::max<bool>(__local_bool__); \
46  if (__local_bool__)
47 
51 #ifdef __bg__ // On Blue Gene Architectures there is no underscore
52 #define FORTRAN_CALL(name) name
53 #else // One underscore everywhere else
54 #define FORTRAN_CALL(name) name##_
55 #endif
56 
64 template <class M, class... Args>
65 std::pair<typename M::iterator, bool>
66 moose_try_emplace(M & m, const typename M::key_type & k, Args &&... args)
67 {
68  auto it = m.lower_bound(k);
69  if (it == m.end() || m.key_comp()(k, it->first))
70  {
71  return {m.emplace_hint(it,
72  std::piecewise_construct,
73  std::forward_as_tuple(k),
74  std::forward_as_tuple(std::forward<Args>(args)...)),
75  true};
76  }
77  return {it, false};
78 }
79 
80 // forward declarations
81 class Syntax;
82 class FEProblemBase;
83 
84 namespace Moose
85 {
86 
91 extern PerfLog perf_log;
92 
96 extern bool _trap_fpe;
97 
101 extern bool _warnings_are_errors;
102 
106 extern bool _deprecated_is_error;
107 
112 extern bool _throw_on_error;
113 
117 #define COLOR_BLACK (Moose::colorConsole() ? XTERM_BLACK : "")
118 #define COLOR_RED (Moose::colorConsole() ? XTERM_RED : "")
119 #define COLOR_GREEN (Moose::colorConsole() ? XTERM_GREEN : "")
120 #define COLOR_YELLOW (Moose::colorConsole() ? XTERM_YELLOW : "")
121 #define COLOR_BLUE (Moose::colorConsole() ? XTERM_BLUE : "")
122 #define COLOR_MAGENTA (Moose::colorConsole() ? XTERM_MAGENTA : "")
123 #define COLOR_CYAN (Moose::colorConsole() ? XTERM_CYAN : "")
124 #define COLOR_WHITE (Moose::colorConsole() ? XTERM_WHITE : "")
125 #define COLOR_DEFAULT (Moose::colorConsole() ? XTERM_DEFAULT : "")
126 
128 bool colorConsole();
129 
132 bool setColorConsole(bool use_color, bool force = false);
133 
137 using libMesh::out;
138 using libMesh::err;
139 
143 void registerObjects(Factory & factory);
144 void addActionTypes(Syntax & syntax);
145 void registerActions(Syntax & syntax, ActionFactory & action_factory);
146 
147 void setSolverDefaults(FEProblemBase & problem);
148 
153 MPI_Comm swapLibMeshComm(MPI_Comm new_comm);
154 
156 {
157 public:
160  ScopedCommSwapper(MPI_Comm new_comm) : _orig(swapLibMeshComm(new_comm)) {}
161  virtual ~ScopedCommSwapper() { swapLibMeshComm(_orig); }
166  void forceSwap() { _orig = swapLibMeshComm(_orig); }
167 private:
168  MPI_Comm _orig;
169 };
170 
171 void enableFPE(bool on = true);
172 
173 // MOOSE Requires PETSc to run, this CPP check will cause a compile error if PETSc is not found
174 #ifndef LIBMESH_HAVE_PETSC
175 #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.
176 #endif
177 
178 } // namespace Moose
179 
180 #endif /* MOOSE_H */
ScopedCommSwapper(MPI_Comm new_comm)
Swaps the current libmesh MPI communicator for new_comm.
Definition: Moose.h:160
bool colorConsole()
Returns whether Console coloring is turned on (default: true).
Definition: Moose.C:1270
MPI_Comm swapLibMeshComm(MPI_Comm new_comm)
Swap the libMesh MPI communicator out for ours.
Definition: Moose.C:1242
Generic factory class for build all sorts of objects.
Definition: Factory.h:152
void setSolverDefaults(FEProblemBase &problem)
Definition: Moose.C:1233
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:66
bool _warnings_are_errors
Variable to toggle any warning into an error (includes deprecated code warnings)
Definition: Moose.C:1282
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:1122
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
void registerObjects(Factory &factory)
Register objects that are in MOOSE.
Definition: Moose.C:488
void forceSwap()
Forcibly swap the currently swapped-out communicator back in to libmesh.
Definition: Moose.h:166
bool _deprecated_is_error
Variable to toggle only deprecated warnings as errors.
Definition: Moose.C:1284
PetscInt m
Specialized factory for generic Action System objects.
Definition: ActionFactory.h:70
PerfLog perf_log
Perflog to be used by applications.
virtual ~ScopedCommSwapper()
Definition: Moose.h:161
bool _trap_fpe
Variable indicating whether we will enable FPE trapping for this run.
Definition: Moose.C:1262
PetscInt M
bool setColorConsole(bool use_color, bool force=false)
Turns color escape sequences on/off for info written to stdout.
Definition: Moose.C:1276
Holding syntax for parsing input files.
Definition: Syntax.h:26
Definition: Moose.h:84
bool _throw_on_error
Variable to turn on exceptions during mooseError() and mooseWarning(), should only be used with MOOSE...
Definition: Moose.C:1286
void enableFPE(bool on=true)
Definition: Moose.C:1252
void addActionTypes(Syntax &syntax)
Definition: Moose.C:890