www.mooseframework.org
Moose.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "libmesh/perf_log.h"
13 #include "libmesh/libmesh_common.h"
14 #include "XTermConstants.h"
15 
16 #include <set>
17 #include <string>
18 
19 namespace libMesh
20 {
21 template <typename>
22 class NumericVector;
23 template <typename>
24 class SparseMatrix;
25 }
26 
27 using namespace libMesh;
28 
29 class ActionFactory;
30 class Factory;
31 class MooseEnumItem;
32 class ExecFlagEnum;
34 
35 void MooseVecView(NumericVector<Number> & vector);
37 
42 #ifndef LIBMESH_HAVE_CXX11
43 #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.
44 #endif
45 
52 #define parallel_if \
53  (cond) bool __local_bool__ = (cond); \
54  Parallel::max<bool>(__local_bool__); \
55  if (__local_bool__)
56 
60 #ifdef __bg__ // On Blue Gene Architectures there is no underscore
61 #define FORTRAN_CALL(name) name
62 #else // One underscore everywhere else
63 #define FORTRAN_CALL(name) name##_
64 #endif
65 
73 template <class M, class... Args>
74 std::pair<typename M::iterator, bool>
75 moose_try_emplace(M & m, const typename M::key_type & k, Args &&... args)
76 {
77  auto it = m.lower_bound(k);
78  if (it == m.end() || m.key_comp()(k, it->first))
79  {
80  return {m.emplace_hint(it,
81  std::piecewise_construct,
82  std::forward_as_tuple(k),
83  std::forward_as_tuple(std::forward<Args>(args)...)),
84  true};
85  }
86  return {it, false};
87 }
88 
89 // forward declarations
90 class Syntax;
91 class FEProblemBase;
92 
93 // Define MOOSE execution flags, this cannot be done in MooseTypes because the registration calls
94 // must be in Moose.C to remain consistent with other registration calls.
96 extern const ExecFlagType EXEC_NONE;
97 extern const ExecFlagType EXEC_INITIAL;
98 extern const ExecFlagType EXEC_LINEAR;
99 extern const ExecFlagType EXEC_NONLINEAR;
100 extern const ExecFlagType EXEC_TIMESTEP_END;
101 extern const ExecFlagType EXEC_TIMESTEP_BEGIN;
102 extern const ExecFlagType EXEC_FINAL;
103 extern const ExecFlagType EXEC_FORCED;
104 extern const ExecFlagType EXEC_FAILED;
105 extern const ExecFlagType EXEC_CUSTOM;
106 extern const ExecFlagType EXEC_SUBDOMAIN;
107 extern const ExecFlagType EXEC_PRE_DISPLACE;
110 extern const ExecFlagType EXEC_TRANSFER;
111 
112 namespace Moose
113 {
114 
119 extern PerfLog perf_log;
120 
124 extern bool _trap_fpe;
125 
129 extern bool _warnings_are_errors;
130 
134 extern bool _deprecated_is_error;
135 
140 extern bool _throw_on_error;
141 
148 
152 #define COLOR_BLACK (Moose::colorConsole() ? XTERM_BLACK : "")
153 #define COLOR_RED (Moose::colorConsole() ? XTERM_RED : "")
154 #define COLOR_GREEN (Moose::colorConsole() ? XTERM_GREEN : "")
155 #define COLOR_YELLOW (Moose::colorConsole() ? XTERM_YELLOW : "")
156 #define COLOR_BLUE (Moose::colorConsole() ? XTERM_BLUE : "")
157 #define COLOR_MAGENTA (Moose::colorConsole() ? XTERM_MAGENTA : "")
158 #define COLOR_CYAN (Moose::colorConsole() ? XTERM_CYAN : "")
159 #define COLOR_WHITE (Moose::colorConsole() ? XTERM_WHITE : "")
160 #define COLOR_DEFAULT (Moose::colorConsole() ? XTERM_DEFAULT : "")
161 
163 bool colorConsole();
164 
167 bool setColorConsole(bool use_color, bool force = false);
168 
172 using libMesh::err;
173 using libMesh::out;
174 
179 void registerAll(Factory & f, ActionFactory & af, Syntax & s);
180 
181 void registerObjects(Factory & factory);
182 void registerObjects(Factory & factory, const std::set<std::string> & obj_labels);
183 void addActionTypes(Syntax & syntax);
184 void registerActions(Syntax & syntax, ActionFactory & action_factory);
185 void registerActions(Syntax & syntax,
186  ActionFactory & action_factory,
187  const std::set<std::string> & obj_labels);
188 void registerExecFlags(Factory & factory);
189 
190 void associateSyntax(Syntax & syntax, ActionFactory & action_factory);
191 
192 void setSolverDefaults(FEProblemBase & problem);
193 
198 MPI_Comm swapLibMeshComm(MPI_Comm new_comm);
199 
201 {
202 public:
205  ScopedCommSwapper(MPI_Comm new_comm) : _orig(swapLibMeshComm(new_comm)) {}
206  virtual ~ScopedCommSwapper() { swapLibMeshComm(_orig); }
211  void forceSwap() { _orig = swapLibMeshComm(_orig); }
212 
213 private:
214  MPI_Comm _orig;
215 };
216 
217 // MOOSE Requires PETSc to run, this CPP check will cause a compile error if PETSc is not found
218 #ifndef LIBMESH_HAVE_PETSC
219 #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.
220 #endif
221 
222 } // namespace Moose
223 
const ExecFlagType EXEC_TRANSFER
const ExecFlagType EXEC_FAILED
ScopedCommSwapper(MPI_Comm new_comm)
Swaps the current libmesh MPI communicator for new_comm.
Definition: Moose.h:205
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:24
bool colorConsole()
Returns whether Console coloring is turned on (default: true).
Definition: Moose.C:558
const ExecFlagType EXEC_CUSTOM
MPI_Comm swapLibMeshComm(MPI_Comm new_comm)
Swap the libMesh MPI communicator out for ours.
Definition: Moose.C:546
const ExecFlagType EXEC_FORCED
Generic factory class for build all sorts of objects.
Definition: Factory.h:153
void setSolverDefaults(FEProblemBase &problem)
Definition: Moose.C:537
bool _warnings_are_errors
Variable to toggle any warning into an error (includes deprecated code warnings)
Definition: Moose.C:570
const ExecFlagType EXEC_NONE
void associateSyntax(Syntax &syntax, ActionFactory &action_factory)
Definition: Moose.C:530
void MooseVecView(NumericVector< Number > &vector)
Definition: Moose.C:51
const ExecFlagType EXEC_TIMESTEP_END
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
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:75
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
void forceSwap()
Forcibly swap the currently swapped-out communicator back in to libmesh.
Definition: Moose.h:211
void registerExecFlags(Factory &factory)
Definition: Moose.C:370
bool _deprecated_is_error
Variable to toggle only deprecated warnings as errors.
Definition: Moose.C:572
PetscInt m
const ExecFlagType EXEC_TIMESTEP_BEGIN
const ExecFlagType EXEC_PRE_MULTIAPP_SETUP
Specialized factory for generic Action System objects.
Definition: ActionFactory.h:64
PerfLog perf_log
Perflog to be used by applications.
virtual ~ScopedCommSwapper()
Definition: Moose.h:206
const ExecFlagType EXEC_LINEAR
const ExecFlagType EXEC_PRE_DISPLACE
const ExecFlagType EXEC_NONLINEAR
bool _trap_fpe
Variable indicating whether we will enable FPE trapping for this run.
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:21
PetscInt M
void registerAll(Factory &f, ActionFactory &af, Syntax &s)
Register objects that are in MOOSE.
Definition: Moose.C:70
void registerObjects(Factory &factory, const std::set< std::string > &obj_labels)
Definition: Moose.C:86
bool setColorConsole(bool use_color, bool force=false)
Turns color escape sequences on/off for info written to stdout.
Definition: Moose.C:564
Holding syntax for parsing input files.
Definition: Syntax.h:20
const ExecFlagType EXEC_SAME_AS_MULTIAPP
void MooseMatView(SparseMatrix< Number > &mat)
Definition: Moose.h:112
const ExecFlagType EXEC_SUBDOMAIN
void registerActions(Syntax &syntax, ActionFactory &action_factory, const std::set< std::string > &obj_labels)
Definition: Moose.C:359
bool _throw_on_error
Variable to turn on exceptions during mooseError() and mooseWarning(), should only be used with MOOSE...
Definition: Moose.C:574
const ExecFlagType EXEC_FINAL
void addActionTypes(Syntax &syntax)
Definition: Moose.C:92
ExecFlagEnum execute_flags
Storage for the registered execute flags.
const ExecFlagType EXEC_INITIAL