www.mooseframework.org
MooseApp.C
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 // MOOSE includes
11 #include "MooseRevision.h"
12 #include "AppFactory.h"
13 #include "DisplacedProblem.h"
14 #include "NonlinearSystemBase.h"
15 #include "AuxiliarySystem.h"
16 #include "MooseSyntax.h"
17 #include "MooseInit.h"
18 #include "Executioner.h"
19 #include "PetscSupport.h"
20 #include "Conversion.h"
21 #include "CommandLine.h"
22 #include "InfixIterator.h"
23 #include "MultiApp.h"
24 #include "MeshModifier.h"
25 #include "MeshGenerator.h"
26 #include "DependencyResolver.h"
27 #include "MooseUtils.h"
28 #include "MooseObjectAction.h"
30 #include "SystemInfo.h"
31 #include "RestartableDataIO.h"
32 #include "MooseMesh.h"
33 #include "FileOutput.h"
34 #include "ConsoleUtils.h"
35 #include "JsonSyntaxTree.h"
36 #include "JsonInputFileFormatter.h"
37 #include "SONDefinitionFormatter.h"
38 #include "RelationshipManager.h"
39 #include "Registry.h"
40 #include "SerializerGuard.h"
41 #include "PerfGraphInterface.h" // For TIME_SECTIOn
42 #include "Attributes.h"
43 #include "MooseApp.h"
44 
45 // Regular expression includes
46 #include "pcrecpp.h"
47 
48 #include "libmesh/exodusII_io.h"
49 #include "libmesh/mesh_refinement.h"
50 #include "libmesh/string_to_enum.h"
51 #include "libmesh/checkpoint_io.h"
52 #include "libmesh/mesh_base.h"
53 
54 // System include for dynamic library methods
55 #include <dlfcn.h>
56 #include <sys/utsname.h> // utsname
57 
58 // C++ includes
59 #include <numeric> // std::accumulate
60 #include <fstream>
61 #include <sys/types.h>
62 #include <unistd.h>
63 #include <cstdlib> // for system()
64 #include <chrono>
65 #include <thread>
66 
67 #define QUOTE(macro) stringifyName(macro)
68 
69 template <>
72 {
74 
75  params.addCommandLineParam<bool>(
76  "display_version", "-v --version", false, "Print application version");
77  params.addCommandLineParam<std::string>("input_file", "-i <input_file>", "Specify an input file");
78  params.addCommandLineParam<std::string>(
79  "mesh_only",
80  "--mesh-only [mesh_file_name]",
81  "Setup and Output the input mesh only (Default: \"<input_file_name>_in.e\")");
82 
83  params.addCommandLineParam<bool>("show_input",
84  "--show-input",
85  false,
86  "Shows the parsed input file before running the simulation.");
87  params.addCommandLineParam<bool>(
88  "show_outputs", "--show-outputs", false, "Shows the output execution time information.");
89  params.addCommandLineParam<bool>(
90  "show_controls", "--show-controls", false, "Shows the Control logic available and executed.");
91 
92  params.addCommandLineParam<bool>(
93  "no_color", "--no-color", false, "Disable coloring of all Console outputs.");
94  params.addCommandLineParam<std::string>("color",
95  "--color [auto,on,off]",
96  "default-on",
97  "Whether to use color in console output (default 'on').");
98 
99  params.addCommandLineParam<bool>("help", "-h --help", false, "Displays CLI usage statement.");
100  params.addCommandLineParam<bool>(
101  "minimal",
102  "--minimal",
103  false,
104  "Ignore input file and build a minimal application with Transient executioner.");
105 
106  params.addCommandLineParam<std::string>(
107  "definition", "--definition", "Shows a SON style input definition dump for input validation");
108  params.addCommandLineParam<std::string>(
109  "dump", "--dump [search_string]", "Shows a dump of available input file syntax.");
110  params.addCommandLineParam<bool>(
111  "registry", "--registry", "Lists all known objects and actions.");
112  params.addCommandLineParam<bool>(
113  "registry_hit", "--registry-hit", "Lists all known objects and actions in hit format.");
114 
115  params.addCommandLineParam<bool>(
116  "apptype", "--type", false, "Return the name of the application object.");
117  params.addCommandLineParam<std::string>(
118  "yaml", "--yaml", "Dumps input file syntax in YAML format.");
119  params.addCommandLineParam<std::string>(
120  "json", "--json", "Dumps input file syntax in JSON format.");
121  params.addCommandLineParam<bool>(
122  "syntax", "--syntax", false, "Dumps the associated Action syntax paths ONLY");
123  params.addCommandLineParam<bool>("check_input",
124  "--check-input",
125  false,
126  "Check the input file (i.e. requires -i <filename>) and quit.");
127  params.addCommandLineParam<bool>(
128  "list_constructed_objects",
129  "--list-constructed-objects",
130  false,
131  "List all moose object type names constructed by the master app factory.");
132 
133  params.addCommandLineParam<unsigned int>(
134  "n_threads", "--n-threads=<n>", 1, "Runs the specified number of threads per process");
135 
136  params.addCommandLineParam<bool>(
137  "warn_unused", "-w --warn-unused", false, "Warn about unused input file options");
138  params.addCommandLineParam<bool>("error_unused",
139  "-e --error-unused",
140  false,
141  "Error when encountering unused input file options");
142  params.addCommandLineParam<bool>(
143  "error_override",
144  "-o --error-override",
145  false,
146  "Error when encountering overridden or parameters supplied multiple times");
147  params.addCommandLineParam<bool>(
148  "error_deprecated", "--error-deprecated", false, "Turn deprecated code messages into Errors");
149 
150  params.addCommandLineParam<bool>(
151  "distributed_mesh",
152  "--distributed-mesh",
153  false,
154  "The libMesh Mesh underlying MooseMesh should always be a DistributedMesh");
155 
156  params.addCommandLineParam<std::string>(
157  "split_mesh",
158  "--split-mesh [splits]",
159  "comma-separated list of numbers of chunks to split the mesh into");
160 
161  params.addCommandLineParam<std::string>("split_file",
162  "--split-file [filename]",
163  "",
164  "optional name of split mesh file(s) to write/read");
165 
166  params.addCommandLineParam<bool>(
167  "use_split", "--use-split", false, "use split distributed mesh files");
168 
169  params.addCommandLineParam<unsigned int>(
170  "refinements",
171  "-r <n>",
172  0,
173  "Specify additional initial uniform refinements for automatic scaling");
174 
175  params.addCommandLineParam<std::string>("recover",
176  "--recover [file_base]",
177  "Continue the calculation. If file_base is omitted then "
178  "the most recent recovery file will be utilized");
179 
180  params.addCommandLineParam<std::string>("recoversuffix",
181  "--recoversuffix [suffix]",
182  "Use a different file extension, other than cpr, "
183  "for a recovery file");
184 
185  params.addCommandLineParam<bool>("half_transient",
186  "--half-transient",
187  false,
188  "When true the simulation will only run half of "
189  "its specified transient (ie half the "
190  "timesteps). This is useful for testing "
191  "recovery and restart");
192 
193  // No default on these two options, they must not both be valid
194  params.addCommandLineParam<bool>(
195  "trap_fpe",
196  "--trap-fpe",
197  "Enable Floating Point Exception handling in critical sections of "
198  "code. This is enabled automatically in DEBUG mode");
199  params.addCommandLineParam<bool>("no_trap_fpe",
200  "--no-trap-fpe",
201  "Disable Floating Point Exception handling in critical "
202  "sections of code when using DEBUG mode.");
203 
204  params.addCommandLineParam<bool>("error", "--error", false, "Turn all warnings into errors");
205 
206  params.addCommandLineParam<bool>(
207  "timing",
208  "-t --timing",
209  false,
210  "Enable all performance logging for timing purposes. This will disable all "
211  "screen output of performance logs for all Console objects.");
212  params.addCommandLineParam<bool>("no_timing",
213  "--no-timing",
214  false,
215  "Disabled performance logging. Overrides -t or --timing "
216  "if passed in conjunction with this flag");
217 
218  params.addCommandLineParam<bool>(
219  "allow_test_objects", "--allow-test-objects", false, "Register test objects and syntax.");
220 
221  // Options ignored by MOOSE but picked up by libMesh, these are here so that they are displayed in
222  // the application help
223  params.addCommandLineParam<bool>(
224  "keep_cout",
225  "--keep-cout",
226  false,
227  "Keep standard output from all processors when running in parallel");
228  params.addCommandLineParam<bool>(
229  "redirect_stdout",
230  "--redirect-stdout",
231  false,
232  "Keep standard output from all processors when running in parallel");
233 
234  // Options for debugging
235  params.addCommandLineParam<std::string>("start_in_debugger",
236  "--start-in-debugger <debugger>",
237  "Start the application and attach a debugger. This will "
238  "launch xterm windows using the command you specify for "
239  "'debugger'");
240 
241  params.addCommandLineParam<unsigned int>("stop_for_debugger",
242  "--stop-for-debugger [seconds]",
243  30,
244  "Pauses the application during startup for the "
245  "specified time to allow for connection of debuggers.");
246 
247  params.addPrivateParam<std::string>("_app_name"); // the name passed to AppFactory::create
248  params.addPrivateParam<std::string>("_type");
249  params.addPrivateParam<int>("_argc");
250  params.addPrivateParam<char **>("_argv");
251  params.addPrivateParam<std::shared_ptr<CommandLine>>("_command_line");
252  params.addPrivateParam<std::shared_ptr<Parallel::Communicator>>("_comm");
253  params.addPrivateParam<unsigned int>("_multiapp_level");
254  params.addPrivateParam<unsigned int>("_multiapp_number");
255 
256  return params;
257 }
258 
260  : ConsoleStreamInterface(*this),
261  ParallelObject(*parameters.get<std::shared_ptr<Parallel::Communicator>>(
262  "_comm")), // Can't call getParam() before pars is set
263  _name(parameters.get<std::string>("_app_name")),
264  _pars(parameters),
265  _type(getParam<std::string>("_type")),
266  _comm(getParam<std::shared_ptr<Parallel::Communicator>>("_comm")),
267  _perf_graph(type() + " (" + name() + ')'),
268  _rank_map(*_comm, _perf_graph),
269  _output_position_set(false),
270  _start_time_set(false),
271  _start_time(0.0),
272  _global_time_offset(0.0),
273  _output_warehouse(*this),
274  _input_parameter_warehouse(new InputParameterWarehouse()),
275  _action_factory(*this),
276  _action_warehouse(*this, _syntax, _action_factory),
277  _parser(*this, _action_warehouse),
278  _use_nonlinear(true),
279  _use_eigen_value(false),
280  _enable_unused_check(WARN_UNUSED),
281  _factory(*this),
282  _error_overridden(false),
283  _ready_to_exit(false),
284  _initial_from_file(false),
285  _distributed_mesh_on_command_line(false),
286  _recover(false),
287  _restart(false),
288  _split_mesh(false),
289  _use_split(parameters.get<bool>("use_split")),
290 #ifdef DEBUG
291  _trap_fpe(true),
292 #else
293  _trap_fpe(false),
294 #endif
295  _recover_suffix("cpr"),
296  _half_transient(false),
297  _check_input(getParam<bool>("check_input")),
298  _restartable_data(libMesh::n_threads()),
299  _multiapp_level(
300  isParamValid("_multiapp_level") ? parameters.get<unsigned int>("_multiapp_level") : 0),
301  _multiapp_number(
302  isParamValid("_multiapp_number") ? parameters.get<unsigned int>("_multiapp_number") : 0),
303  _setup_timer(_perf_graph.registerSection("MooseApp::setup", 2)),
304  _setup_options_timer(_perf_graph.registerSection("MooseApp::setupOptions", 5)),
305  _run_input_file_timer(_perf_graph.registerSection("MooseApp::runInputFile", 3)),
306  _execute_timer(_perf_graph.registerSection("MooseApp::execute", 2)),
307  _execute_executioner_timer(_perf_graph.registerSection("MooseApp::executeExecutioner", 3)),
308  _restore_timer(_perf_graph.registerSection("MooseApp::restore", 2)),
309  _run_timer(_perf_graph.registerSection("MooseApp::run", 3)),
310  _execute_mesh_modifiers_timer(_perf_graph.registerSection("MooseApp::executeMeshModifiers", 1)),
311  _execute_mesh_generators_timer(
312  _perf_graph.registerSection("MooseApp::executeMeshGenerators", 1)),
313  _restore_cached_backup_timer(_perf_graph.registerSection("MooseApp::restoreCachedBackup", 2)),
314  _create_minimal_app_timer(_perf_graph.registerSection("MooseApp::createMinimalApp", 3))
315 {
318 
319  _the_warehouse = libmesh_make_unique<TheWarehouse>();
320  _the_warehouse->registerAttribute<AttribMatrixTags>("matrix_tags", 0);
321  _the_warehouse->registerAttribute<AttribVectorTags>("vector_tags", 0);
322  _the_warehouse->registerAttribute<AttribExecOns>("exec_ons", 0);
323  _the_warehouse->registerAttribute<AttribSubdomains>("subdomains", 0);
324  _the_warehouse->registerAttribute<AttribBoundaries>("boundaries", 0);
325  _the_warehouse->registerAttribute<AttribThread>("thread", 0);
326  _the_warehouse->registerAttribute<AttribPreIC>("pre_ic", 0);
327  _the_warehouse->registerAttribute<AttribPreAux>("pre_aux", 0);
328  _the_warehouse->registerAttribute<AttribName>("name", "dummy");
329  _the_warehouse->registerAttribute<AttribSystem>("system", "dummy");
330  _the_warehouse->registerAttribute<AttribVar>("variable", 0);
331  _the_warehouse->registerAttribute<AttribInterfaces>("interfaces", 0);
332 
333  if (isParamValid("_argc") && isParamValid("_argv"))
334  {
335  int argc = getParam<int>("_argc");
336  char ** argv = getParam<char **>("_argv");
337 
338  _sys_info = libmesh_make_unique<SystemInfo>(argc, argv);
339  }
340  if (isParamValid("_command_line"))
341  _command_line = getParam<std::shared_ptr<CommandLine>>("_command_line");
342  else
343  mooseError("Valid CommandLine object required");
344 
345  if (_check_input && isParamValid("recover"))
346  mooseError("Cannot run --check-input with --recover. Recover files might not exist");
347 
348  if (isParamValid("start_in_debugger") && _multiapp_level == 0)
349  {
350  auto command = getParam<std::string>("start_in_debugger");
351 
352  Moose::out << "Starting in debugger using: " << command << std::endl;
353 
355 
356  std::stringstream command_stream;
357 
358  // This will start XTerm and print out some info first... then run the debugger
359  command_stream << "xterm -e \"echo 'Rank: " << processor_id() << " Hostname: " << hostname
360  << " PID: " << getpid() << "'; echo ''; ";
361 
362  // Figure out how to run the debugger
363  if (command.find("lldb") != std::string::npos || command.find("gdb") != std::string::npos)
364  command_stream << command << " -p " << getpid();
365  else
366  mooseError("Unknown debugger: ",
367  command,
368  "\nIf this is truly what you meant then contact moose-users to have a discussion "
369  "about adding your debugger.");
370 
371  // Finish up the command
372  command_stream << "\""
373  << " & ";
374 
375  std::string command_string = command_stream.str();
376  Moose::out << "Running: " << command_string << std::endl;
377 
378  int ret = std::system(command_string.c_str());
379  libmesh_ignore(ret);
380 
381  // Sleep to allow time for the debugger to attach
382  std::this_thread::sleep_for(std::chrono::seconds(10));
383  }
384 
385  if (!parameters.isParamSetByAddParam("stop_for_debugger"))
386  {
387  Moose::out << "\nStopping for " << getParam<unsigned int>("stop_for_debugger")
388  << " seconds to allow attachment from a debugger.\n";
389 
390  Moose::out << "\nAll of the processes you can connect to:\n";
391  Moose::out << "rank - hostname - pid\n";
392 
394 
395  {
396  // The 'false' turns off the serialization warning
397  SerializerGuard sg(_communicator, false); // Guarantees that the processors print in order
398  Moose::err << processor_id() << " - " << hostname << " - " << getpid() << "\n";
399  }
400 
401  Moose::out << "\nWaiting...\n" << std::endl;
402 
403  // Sleep to allow time for the debugger to attach
404  std::this_thread::sleep_for(std::chrono::seconds(getParam<unsigned int>("stop_for_debugger")));
405  }
406 }
407 
408 void
410 {
412 }
413 
415 {
417  _executioner.reset();
418  _the_warehouse.reset();
419 
421 
422 #ifdef LIBMESH_HAVE_DLOPEN
423  // Close any open dynamic libraries
424  for (const auto & it : _lib_handles)
425  dlclose(it.second);
426 #endif
427 }
428 
429 std::string
431 {
432  return MOOSE_VERSION;
433 }
434 
435 std::string
437 {
438  return MOOSE_VERSION;
439 }
440 
441 std::string
443 {
444  return getPrintableName() + " Version: " + getVersion();
445 }
446 
447 void
449 {
450  TIME_SECTION(_setup_options_timer);
451 
452  // MOOSE was updated to have the ability to register execution flags in similar fashion as
453  // objects. However, this change requires all *App.C/h files to be updated with the new
454  // registerExecFlags method. To avoid breaking all applications the default MOOSE flags
455  // are added if nothing has been added to this point. In the future this could go away or
456  // perhaps be a warning.
457  if (_execute_flags.items().empty())
459 
460  // Print the header, this is as early as possible
461  std::string hdr(header() + "\n");
462  if (multiAppLevel() > 0)
464  Moose::out << hdr << std::flush;
465 
466  if (getParam<bool>("error_unused"))
467  setCheckUnusedFlag(true);
468  else if (getParam<bool>("warn_unused"))
469  setCheckUnusedFlag(false);
470 
471  if (getParam<bool>("error_override"))
473 
474  _distributed_mesh_on_command_line = getParam<bool>("distributed_mesh");
475 
476  _half_transient = getParam<bool>("half_transient");
477 
478  // The no_timing flag takes precedence over the timing flag.
479  if (getParam<bool>("no_timing"))
480  {
481  _pars.set<bool>("timing") = false;
482 
483  _perf_graph.setActive(false);
484  }
485 
486  if (isParamValid("trap_fpe") && isParamValid("no_trap_fpe"))
487  mooseError("Cannot use both \"--trap-fpe\" and \"--no-trap-fpe\" flags.");
488  if (isParamValid("trap_fpe"))
489  _trap_fpe = true;
490  else if (isParamValid("no_trap_fpe"))
491  _trap_fpe = false;
492 
493  // Turn all warnings in MOOSE to errors (almost see next logic block)
494  Moose::_warnings_are_errors = getParam<bool>("error");
495 
496  // Deprecated messages can be toggled to errors independently from everything else.
497  Moose::_deprecated_is_error = getParam<bool>("error_deprecated");
498 
499  if (isUltimateMaster()) // makes sure coloring isn't reset incorrectly in multi-app settings
500  {
501  // Toggle the color console off
502  Moose::setColorConsole(true, true); // set default color condition
503  if (getParam<bool>("no_color"))
504  Moose::setColorConsole(false);
505 
506  char * c_color = std::getenv("MOOSE_COLOR");
507  std::string color = "on";
508  if (c_color)
509  color = c_color;
510  if (getParam<std::string>("color") != "default-on")
511  color = getParam<std::string>("color");
512 
513  if (color == "auto")
515  else if (color == "on")
516  Moose::setColorConsole(true, true);
517  else if (color == "off")
518  Moose::setColorConsole(false);
519  else
520  mooseWarning("ignoring invalid --color arg (want 'auto', 'on', or 'off')");
521  }
522 
523  // this warning goes below --color processing to honor that setting for
524  // the warning. And below settings for warnings/error setup.
525  if (getParam<bool>("no_color"))
526  mooseDeprecated("The --no-color flag is deprecated. Use '--color off' instead.");
527 
528 // If there's no threading model active, but the user asked for
529 // --n-threads > 1 on the command line, throw a mooseError. This is
530 // intended to prevent situations where the user has potentially
531 // built MOOSE incorrectly (neither TBB nor pthreads found) and is
532 // asking for multiple threads, not knowing that there will never be
533 // any threads launched.
534 #if !LIBMESH_USING_THREADS
535  if (libMesh::command_line_value("--n-threads", 1) > 1)
536  mooseError("You specified --n-threads > 1, but there is no threading model active!");
537 #endif
538 
539  // Build a minimal running application, ignoring the input file.
540  if (getParam<bool>("minimal"))
542 
543  else if (getParam<bool>("display_version"))
544  {
545  Moose::perf_log.disable_logging();
546  Moose::out << getPrintableVersion() << std::endl;
547  _ready_to_exit = true;
548  return;
549  }
550  else if (getParam<bool>("help"))
551  {
552  Moose::perf_log.disable_logging();
553 
554  _command_line->printUsage();
555  _ready_to_exit = true;
556  }
557  else if (isParamValid("dump"))
558  {
559  Moose::perf_log.disable_logging();
560 
561  // Get command line argument following --dump on command line
562  std::string following_arg = getParam<std::string>("dump");
563 
564  // The argument following --dump is a parameter search string,
565  // which can be empty.
566  std::string param_search;
567  if (!following_arg.empty() && (following_arg.find('-') != 0))
568  param_search = following_arg;
569 
570  JsonSyntaxTree tree(param_search);
572  JsonInputFileFormatter formatter;
573  Moose::out << "### START DUMP DATA ###\n"
574  << formatter.toString(tree.getRoot()) << "\n### END DUMP DATA ###\n";
575  _ready_to_exit = true;
576  }
577  else if (isParamValid("registry"))
578  {
579  Moose::out << "Label\tType\tName\tClass\tFile\n";
580 
581  auto & objmap = Registry::allObjects();
582  for (auto & entry : objmap)
583  {
584  for (auto & obj : entry.second)
585  {
586  std::string name = obj._name;
587  if (name.empty())
588  name = obj._alias;
589  if (name.empty())
590  name = obj._classname;
591 
592  Moose::out << entry.first << "\tobject\t" << name << "\t" << obj._classname << "\t"
593  << obj._file << "\n";
594  }
595  }
596 
597  auto & actmap = Registry::allActions();
598  for (auto & entry : actmap)
599  {
600  for (auto & act : entry.second)
601  Moose::out << entry.first << "\taction\t" << act._name << "\t" << act._classname << "\t"
602  << act._file << "\n";
603  }
604 
605  _ready_to_exit = true;
606  }
607  else if (isParamValid("registry_hit"))
608  {
609  Moose::out << "### START REGISTRY DATA ###\n";
610 
611  hit::Section root("");
612  auto sec = new hit::Section("registry");
613  root.addChild(sec);
614  auto objsec = new hit::Section("objects");
615  sec->addChild(objsec);
616 
617  auto & objmap = Registry::allObjects();
618  for (auto & entry : objmap)
619  {
620  for (auto & obj : entry.second)
621  {
622  std::string name = obj._name;
623  if (name.empty())
624  name = obj._alias;
625  if (name.empty())
626  name = obj._classname;
627 
628  auto ent = new hit::Section("entry");
629  objsec->addChild(ent);
630  ent->addChild(new hit::Field("label", hit::Field::Kind::String, entry.first));
631  ent->addChild(new hit::Field("type", hit::Field::Kind::String, "object"));
632  ent->addChild(new hit::Field("name", hit::Field::Kind::String, name));
633  ent->addChild(new hit::Field("class", hit::Field::Kind::String, obj._classname));
634  ent->addChild(new hit::Field("file", hit::Field::Kind::String, obj._file));
635  }
636  }
637 
638  auto actsec = new hit::Section("actions");
639  sec->addChild(actsec);
640  auto & actmap = Registry::allActions();
641  for (auto & entry : actmap)
642  {
643  for (auto & act : entry.second)
644  {
645  auto ent = new hit::Section("entry");
646  actsec->addChild(ent);
647  ent->addChild(new hit::Field("label", hit::Field::Kind::String, entry.first));
648  ent->addChild(new hit::Field("type", hit::Field::Kind::String, "action"));
649  ent->addChild(new hit::Field("task", hit::Field::Kind::String, act._name));
650  ent->addChild(new hit::Field("class", hit::Field::Kind::String, act._classname));
651  ent->addChild(new hit::Field("file", hit::Field::Kind::String, act._file));
652  }
653  }
654 
655  Moose::out << root.render();
656 
657  Moose::out << "\n### END REGISTRY DATA ###\n";
658  _ready_to_exit = true;
659  }
660  else if (isParamValid("definition"))
661  {
662  Moose::perf_log.disable_logging();
663  JsonSyntaxTree tree("");
665  SONDefinitionFormatter formatter;
666  Moose::out << formatter.toString(tree.getRoot()) << "\n";
667  _ready_to_exit = true;
668  }
669  else if (isParamValid("yaml"))
670  {
671  Moose::perf_log.disable_logging();
672 
674 
675  // Get command line argument following --yaml on command line
676  std::string yaml_following_arg = getParam<std::string>("yaml");
677 
678  // If the argument following --yaml is non-existent or begins with
679  // a dash, call buildFullTree() with an empty string, otherwise
680  // pass the argument following --yaml.
681  if (yaml_following_arg.empty() || (yaml_following_arg.find('-') == 0))
683  else
684  _parser.buildFullTree(yaml_following_arg);
685 
686  _ready_to_exit = true;
687  }
688  else if (isParamValid("json"))
689  {
690  Moose::perf_log.disable_logging();
691 
692  // Get command line argument following --json on command line
693  std::string json_following_arg = getParam<std::string>("json");
694 
695  // The argument following --json is a parameter search string,
696  // which can be empty.
697  std::string search;
698  if (!json_following_arg.empty() && (json_following_arg.find('-') != 0))
699  search = json_following_arg;
700 
701  JsonSyntaxTree tree(search);
703 
704  Moose::out << "**START JSON DATA**\n" << tree.getRoot() << "\n**END JSON DATA**\n";
705  _ready_to_exit = true;
706  }
707  else if (getParam<bool>("syntax"))
708  {
709  Moose::perf_log.disable_logging();
710 
711  std::multimap<std::string, Syntax::ActionInfo> syntax = _syntax.getAssociatedActions();
712  Moose::out << "**START SYNTAX DATA**\n";
713  for (const auto & it : syntax)
714  Moose::out << it.first << "\n";
715  Moose::out << "**END SYNTAX DATA**\n" << std::endl;
716  _ready_to_exit = true;
717  }
718  else if (_input_filename != "" ||
719  isParamValid("input_file")) // They already specified an input filename
720  {
721  if (_input_filename == "")
722  _input_filename = getParam<std::string>("input_file");
723 
724  if (isParamValid("recover"))
725  {
726  // We need to set the flag manually here since the recover parameter is a string type (takes
727  // an optional filename)
728  _recover = true;
729 
730  // Get command line argument following --recover on command line
731  std::string recover_following_arg = getParam<std::string>("recover");
732 
733  // If the argument following --recover is non-existent or begins with
734  // a dash then we are going to eventually find the newest recovery file to use
735  if (!(recover_following_arg.empty() || (recover_following_arg.find('-') == 0)))
736  _recover_base = recover_following_arg;
737  }
738 
739  // Optionally get command line argument following --recoversuffix
740  // on command line. Currently this argument applies to both
741  // recovery and restart files.
742  if (isParamValid("recoversuffix"))
743  {
744  _recover_suffix = getParam<std::string>("recoversuffix");
745  }
746 
748 
749  if (isParamValid("mesh_only"))
750  {
751  _syntax.registerTaskName("mesh_only", true);
752  _syntax.addDependency("mesh_only", "setup_mesh_complete");
753  _action_warehouse.setFinalTask("mesh_only");
754  }
755  else if (isParamValid("split_mesh"))
756  {
757  _split_mesh = true;
758  _syntax.registerTaskName("split_mesh", true);
759  _syntax.addDependency("split_mesh", "setup_mesh_complete");
760  _action_warehouse.setFinalTask("split_mesh");
761  }
763  }
764  else if (getParam<bool>("apptype"))
765  {
766  Moose::perf_log.disable_logging();
767  Moose::out << "MooseApp Type: " << type() << std::endl;
768  _ready_to_exit = true;
769  }
770  else
771  {
772  Moose::perf_log.disable_logging();
773 
774  if (_check_input)
775  mooseError("You specified --check-input, but did not provide an input file. Add -i "
776  "<inputfile> to your command line.");
777 
778  _command_line->printUsage();
779  _ready_to_exit = true;
780  }
781 }
782 
783 void
784 MooseApp::setInputFileName(std::string input_filename)
785 {
786  _input_filename = input_filename;
787 }
788 
789 std::string
791 {
792  return _output_file_base;
793 }
794 
795 void
797 {
798  TIME_SECTION(_run_input_file_timer);
799 
800  // If ready to exit has been set, then just return
801  if (_ready_to_exit)
802  return;
803 
805 
806  if (isParamValid("mesh_only") || isParamValid("split_mesh"))
807  _ready_to_exit = true;
808  else if (getParam<bool>("list_constructed_objects"))
809  {
810  // TODO: ask multiapps for their constructed objects
811  _ready_to_exit = true;
812  std::vector<std::string> obj_list = _factory.getConstructedObjects();
813  Moose::out << "**START OBJECT DATA**\n";
814  for (const auto & name : obj_list)
815  Moose::out << name << "\n";
816  Moose::out << "**END OBJECT DATA**\n" << std::endl;
817  }
818 }
819 
820 void
822 {
823  bool warn = _enable_unused_check == WARN_UNUSED;
824  bool err = _enable_unused_check == ERROR_UNUSED;
825 
826  _parser.errorCheck(*_comm, warn, err);
827 
828  auto apps = _executioner->feProblem().getMultiAppWarehouse().getObjects();
829  for (auto app : apps)
830  for (unsigned int i = 0; i < app->numLocalApps(); i++)
831  app->localApp(i)->errorCheck();
832 }
833 
834 void
836 {
837  TIME_SECTION(_execute_executioner_timer);
838 
839  // If ready to exit has been set, then just return
840  if (_ready_to_exit)
841  return;
842 
843  // run the simulation
844  if (_executioner)
845  {
846 #ifdef LIBMESH_HAVE_PETSC
848 #endif
849 
850  _executioner->init();
851  errorCheck();
852  _executioner->execute();
853  }
854  else
855  mooseError("No executioner was specified (go fix your input file)");
856 }
857 
858 bool
860 {
861  return _recover;
862 }
863 
864 bool
866 {
867  return _restart;
868 }
869 
870 bool
872 {
873  return _split_mesh;
874 }
875 
876 bool
878 {
879  return _use_split;
880 }
881 
882 bool
884 {
885  return !_recover_base.empty();
886 }
887 
888 void
890 {
891  _recoverable_data.insert(name);
892 }
893 
894 std::shared_ptr<Backup>
896 {
897  mooseAssert(_executioner, "Executioner is nullptr");
898  FEProblemBase & fe_problem = _executioner->feProblem();
899 
900  RestartableDataIO rdio(fe_problem);
901  return rdio.createBackup();
902 }
903 
904 void
905 MooseApp::restore(std::shared_ptr<Backup> backup, bool for_restart)
906 {
907  TIME_SECTION(_restore_timer);
908 
909  mooseAssert(_executioner, "Executioner is nullptr");
910  FEProblemBase & fe_problem = _executioner->feProblem();
911 
912  RestartableDataIO rdio(fe_problem);
913  rdio.restoreBackup(backup, for_restart);
914 }
915 
916 void
917 MooseApp::setCheckUnusedFlag(bool warn_is_error)
918 {
925  if (_enable_unused_check != ERROR_UNUSED || warn_is_error)
926  _enable_unused_check = warn_is_error ? ERROR_UNUSED : WARN_UNUSED;
927  else
928  mooseInfo("Ignoring request to turn off or warn about unused parameters.\n");
929 }
930 
931 void
933 {
935 }
936 
937 void
939 {
940  _error_overridden = true;
941 }
942 
943 void
945 {
946  TIME_SECTION(_run_timer);
947 
948  try
949  {
950  TIME_SECTION(_setup_timer);
951  setupOptions();
952  runInputFile();
953  }
954  catch (std::exception & err)
955  {
956  mooseError(err.what());
957  }
958 
959  if (!_check_input)
960  {
961  TIME_SECTION(_execute_timer);
963  }
964  else
965  {
966  errorCheck();
967  // Output to stderr, so it is easier for peacock to get the result
968  Moose::err << "Syntax OK" << std::endl;
969  }
970 }
971 
972 void
974 {
975  _output_position_set = true;
976  _output_position = p;
978 
979  if (_executioner.get())
980  _executioner->parentOutputPositionChanged();
981 }
982 
983 std::list<std::string>
985 {
986  // Storage for the directory names
987  std::list<std::string> checkpoint_dirs;
988 
989  // Extract the CommonOutputAction
990  const auto & common_actions = _action_warehouse.getActionListByName("common_output");
991  mooseAssert(common_actions.size() == 1, "Should be only one common_output Action");
992 
993  const Action * common = *common_actions.begin();
994 
995  // If file_base is set in CommonOutputAction, add this file to the list of potential checkpoint
996  // files
997  if (common->isParamValid("file_base"))
998  checkpoint_dirs.push_back(common->getParam<std::string>("file_base") + "_cp");
999  // Case for normal application or master in a Multiapp setting
1000  else if (getOutputFileBase().empty())
1001  checkpoint_dirs.push_back(FileOutput::getOutputFileBase(*this, "_out_cp"));
1002  // Case for a sub app in a Multiapp setting
1003  else
1004  checkpoint_dirs.push_back(getOutputFileBase() + "_cp");
1005 
1006  // Add the directories from any existing checkpoint objects
1007  const auto & actions = _action_warehouse.getActionListByName("add_output");
1008  for (const auto & action : actions)
1009  {
1010  // Get the parameters from the MooseObjectAction
1011  MooseObjectAction * moose_object_action = dynamic_cast<MooseObjectAction *>(action);
1012  if (!moose_object_action)
1013  continue;
1014 
1015  const InputParameters & params = moose_object_action->getObjectParams();
1016 
1017  // Loop through the actions and add the necessary directories to the list to check
1018  if (moose_object_action->getParam<std::string>("type") == "Checkpoint")
1019  {
1020  if (params.isParamValid("file_base"))
1021  checkpoint_dirs.push_back(common->getParam<std::string>("file_base") + "_cp");
1022  else
1023  {
1024  std::ostringstream oss;
1025  oss << "_" << action->name() << "_cp";
1026  checkpoint_dirs.push_back(FileOutput::getOutputFileBase(*this, oss.str()));
1027  }
1028  }
1029  }
1030 
1031  return checkpoint_dirs;
1032 }
1033 
1034 std::list<std::string>
1036 {
1037  auto checkpoint_dirs = getCheckpointDirectories();
1038  return MooseUtils::getFilesInDirs(checkpoint_dirs);
1039 }
1040 
1041 void
1042 MooseApp::setStartTime(const Real time)
1043 {
1044  _start_time_set = true;
1045  _start_time = time;
1046 }
1047 
1048 std::string
1049 MooseApp::getFileName(bool stripLeadingPath) const
1050 {
1051  return _parser.getFileName(stripLeadingPath);
1052 }
1053 
1056 {
1057  return _output_warehouse;
1058 }
1059 
1060 std::string
1061 MooseApp::appNameToLibName(const std::string & app_name) const
1062 {
1063  std::string library_name(app_name);
1064 
1065  // Strip off the App part (should always be the last 3 letters of the name)
1066  size_t pos = library_name.find("App");
1067  if (pos != library_name.length() - 3)
1068  mooseError("Invalid application name: ", library_name);
1069  library_name.erase(pos);
1070 
1071  // Now get rid of the camel case, prepend lib, and append the method and suffix
1072  return std::string("lib") + MooseUtils::camelCaseToUnderscore(library_name) + '-' +
1073  QUOTE(METHOD) + ".la";
1074 }
1075 
1076 std::string
1077 MooseApp::libNameToAppName(const std::string & library_name) const
1078 {
1079  std::string app_name(library_name);
1080 
1081  // Strip off the leading "lib" and trailing ".la"
1082  if (pcrecpp::RE("lib(.+?)(?:-\\w+)?\\.la").Replace("\\1", &app_name) == 0)
1083  mooseError("Invalid library name: ", app_name);
1084 
1085  return MooseUtils::underscoreToCamelCase(app_name, true);
1086 }
1087 
1088 void
1090  std::unique_ptr<RestartableDataValue> data,
1091  THREAD_ID tid)
1092 {
1093  auto & restartable_data = _restartable_data[tid];
1094  auto insert_pair = moose_try_emplace(restartable_data, name, std::move(data));
1095 
1096  if (!insert_pair.second)
1097  mooseError("Attempted to declare restartable twice with the same name: ", name);
1098 }
1099 
1100 void
1101 MooseApp::dynamicAppRegistration(const std::string & app_name,
1102  std::string library_path,
1103  const std::string & library_name)
1104 {
1105 #ifdef LIBMESH_HAVE_DLOPEN
1106  Parameters params;
1107  params.set<std::string>("app_name") = app_name;
1108  params.set<RegistrationType>("reg_type") = APPLICATION;
1109  params.set<std::string>("registration_method") = app_name + "__registerApps";
1110  params.set<std::string>("library_path") = library_path;
1111  params.set<std::string>("library_name") = library_name;
1112 
1113  dynamicRegistration(params);
1114 
1115  // At this point the application should be registered so check it
1116  if (!AppFactory::instance().isRegistered(app_name))
1117  {
1118  std::ostringstream oss;
1119  std::set<std::string> paths = getLoadedLibraryPaths();
1120 
1121  oss << "Unable to locate library for \"" << app_name
1122  << "\".\nWe attempted to locate the library \"" << appNameToLibName(app_name)
1123  << "\" in the following paths:\n\t";
1124  std::copy(paths.begin(), paths.end(), infix_ostream_iterator<std::string>(oss, "\n\t"));
1125  oss << "\n\nMake sure you have compiled the library and either set the \"library_path\" "
1126  "variable "
1127  << "in your input file or exported \"MOOSE_LIBRARY_PATH\".\n"
1128  << "Compiled in debug mode to see the list of libraries checked for dynamic loading "
1129  "methods.";
1130  mooseError(oss.str());
1131  }
1132 #else
1133  mooseError("Dynamic Loading is either not supported or was not detected by libMesh configure.");
1134 #endif
1135 }
1136 
1137 void
1138 MooseApp::dynamicAllRegistration(const std::string & app_name,
1139  Factory * factory,
1140  ActionFactory * action_factory,
1141  Syntax * syntax,
1142  std::string library_path,
1143  const std::string & library_name)
1144 {
1145 #ifdef LIBMESH_HAVE_DLOPEN
1146  Parameters params;
1147  params.set<std::string>("app_name") = app_name;
1148  params.set<RegistrationType>("reg_type") = REGALL;
1149  params.set<std::string>("registration_method") = app_name + "__registerAll";
1150  params.set<std::string>("library_path") = library_path;
1151  params.set<std::string>("library_name") = library_name;
1152 
1153  params.set<Factory *>("factory") = factory;
1154  params.set<Syntax *>("syntax") = syntax;
1155  params.set<ActionFactory *>("action_factory") = action_factory;
1156 
1157  dynamicRegistration(params);
1158 #else
1159  mooseError("Dynamic Loading is either not supported or was not detected by libMesh configure.");
1160 #endif
1161 }
1162 
1163 void
1164 MooseApp::dynamicRegistration(const Parameters & params)
1165 {
1166  std::string library_name;
1167  // was library name provided by the user?
1168  if (params.get<std::string>("library_name").empty())
1169  library_name = appNameToLibName(params.get<std::string>("app_name"));
1170  else
1171  library_name = params.get<std::string>("library_name");
1172 
1173  // Create a vector of paths that we can search inside for libraries
1174  std::vector<std::string> paths;
1175 
1176  std::string library_path = params.get<std::string>("library_path");
1177 
1178  if (library_path != "")
1179  MooseUtils::tokenize(library_path, paths, 1, ":");
1180 
1181  char * moose_lib_path_env = std::getenv("MOOSE_LIBRARY_PATH");
1182  if (moose_lib_path_env)
1183  {
1184  std::string moose_lib_path(moose_lib_path_env);
1185  std::vector<std::string> tmp_paths;
1186 
1187  MooseUtils::tokenize(moose_lib_path, tmp_paths, 1, ":");
1188 
1189  // merge the two vectors together (all possible search paths)
1190  paths.insert(paths.end(), tmp_paths.begin(), tmp_paths.end());
1191  }
1192 
1193  // Attempt to dynamically load the library
1194  for (const auto & path : paths)
1195  if (MooseUtils::checkFileReadable(path + '/' + library_name, false, false))
1196  loadLibraryAndDependencies(path + '/' + library_name, params);
1197  else
1198  mooseWarning("Unable to open library file \"",
1199  path + '/' + library_name,
1200  "\". Double check for spelling errors.");
1201 }
1202 
1203 void
1204 MooseApp::loadLibraryAndDependencies(const std::string & library_filename,
1205  const Parameters & params)
1206 {
1207  std::string line;
1208  std::string dl_lib_filename;
1209 
1210  // This RE looks for absolute path libtool filenames (i.e. begins with a slash and ends with a
1211  // .la)
1212  pcrecpp::RE re_deps("(/\\S*\\.la)");
1213 
1214  std::ifstream handle(library_filename.c_str());
1215  if (handle.is_open())
1216  {
1217  while (std::getline(handle, line))
1218  {
1219  // Look for the system dependent dynamic library filename to open
1220  if (line.find("dlname=") != std::string::npos)
1221  // Magic numbers are computed from length of this string "dlname=' and line minus that
1222  // string plus quotes"
1223  dl_lib_filename = line.substr(8, line.size() - 9);
1224 
1225  if (line.find("dependency_libs=") != std::string::npos)
1226  {
1227  pcrecpp::StringPiece input(line);
1228  pcrecpp::StringPiece depend_library;
1229  while (re_deps.FindAndConsume(&input, &depend_library))
1230  // Recurse here to load dependent libraries in depth-first order
1231  loadLibraryAndDependencies(depend_library.as_string(), params);
1232 
1233  // There's only one line in the .la file containing the dependency libs so break after
1234  // finding it
1235  break;
1236  }
1237  }
1238  handle.close();
1239  }
1240 
1241  std::string registration_method_name = params.get<std::string>("registration_method");
1242  // Time to load the library, First see if we've already loaded this particular dynamic library
1243  if (_lib_handles.find(std::make_pair(library_filename, registration_method_name)) ==
1244  _lib_handles.end() && // make sure we haven't already loaded this library
1245  dl_lib_filename != "") // AND make sure we have a library name (we won't for static linkage)
1246  {
1247  std::pair<std::string, std::string> lib_name_parts =
1248  MooseUtils::splitFileName(library_filename);
1249 
1250  // Assemble the actual filename using the base path of the *.la file and the dl_lib_filename
1251  std::string dl_lib_full_path = lib_name_parts.first + '/' + dl_lib_filename;
1252 
1253  MooseUtils::checkFileReadable(dl_lib_full_path, false, /*throw_on_unreadable=*/true);
1254 
1255 #ifdef LIBMESH_HAVE_DLOPEN
1256  void * handle = dlopen(dl_lib_full_path.c_str(), RTLD_LAZY);
1257 #else
1258  void * handle = nullptr;
1259 #endif
1260 
1261  if (!handle)
1262  mooseError("The library file \"",
1263  dl_lib_full_path,
1264  "\" exists and has proper permissions, but cannot by dynamically loaded.\nThis "
1265  "generally means that the loader was unable to load one or more of the "
1266  "dependencies listed in the supplied library (see otool or ldd).\n");
1267 
1268 // get the pointer to the method in the library. The dlsym()
1269 // function returns a null pointer if the symbol cannot be found,
1270 // we also explicitly set the pointer to NULL if dlsym is not
1271 // available.
1272 #ifdef LIBMESH_HAVE_DLOPEN
1273  void * registration_method = dlsym(handle, registration_method_name.c_str());
1274 #else
1275  void * registration_method = nullptr;
1276 #endif
1277 
1278  if (!registration_method)
1279  {
1280 // We found a dynamic library that doesn't have a dynamic
1281 // registration method in it. This shouldn't be an error, so
1282 // we'll just move on.
1283 #ifdef DEBUG
1284  mooseWarning("Unable to find extern \"C\" method \"",
1285  registration_method_name,
1286  "\" in library: ",
1287  dl_lib_full_path,
1288  ".\n",
1289  "This doesn't necessarily indicate an error condition unless you believe that "
1290  "the method should exist in that library.\n");
1291 #endif
1292 
1293 #ifdef LIBMESH_HAVE_DLOPEN
1294  dlclose(handle);
1295 #endif
1296  }
1297  else // registration_method is valid!
1298  {
1299  // TODO: Look into cleaning this up
1300  switch (params.get<RegistrationType>("reg_type"))
1301  {
1302  case APPLICATION:
1303  {
1304  typedef void (*register_app_t)();
1305  register_app_t * reg_ptr = reinterpret_cast<register_app_t *>(&registration_method);
1306  (*reg_ptr)();
1307  break;
1308  }
1309  case REGALL:
1310  {
1311  typedef void (*register_app_t)(Factory *, ActionFactory *, Syntax *);
1312  register_app_t * reg_ptr = reinterpret_cast<register_app_t *>(&registration_method);
1313  (*reg_ptr)(params.get<Factory *>("factory"),
1314  params.get<ActionFactory *>("action_factory"),
1315  params.get<Syntax *>("syntax"));
1316  break;
1317  }
1318  default:
1319  mooseError("Unhandled RegistrationType");
1320  }
1321 
1322  // Store the handle so we can close it later
1323  _lib_handles.insert(
1324  std::make_pair(std::make_pair(library_filename, registration_method_name), handle));
1325  }
1326  }
1327 }
1328 
1329 std::set<std::string>
1331 {
1332  // Return the paths but not the open file handles
1333  std::set<std::string> paths;
1334  for (const auto & it : _lib_handles)
1335  paths.insert(it.first.first);
1336 
1337  return paths;
1338 }
1339 
1342 {
1344 }
1345 
1346 std::string
1348 {
1349  return std::string("");
1350 }
1351 
1352 void
1353 MooseApp::addMeshModifier(const std::string & modifier_name,
1354  const std::string & name,
1355  InputParameters parameters)
1356 {
1357  std::shared_ptr<MeshModifier> mesh_modifier =
1358  _factory.create<MeshModifier>(modifier_name, name, parameters);
1359 
1360  _mesh_modifiers.insert(std::make_pair(MooseUtils::shortName(name), mesh_modifier));
1361 }
1362 
1363 const MeshModifier &
1364 MooseApp::getMeshModifier(const std::string & name) const
1365 {
1366  return *_mesh_modifiers.find(MooseUtils::shortName(name))->second.get();
1367 }
1368 
1369 std::vector<std::string>
1371 {
1372  std::vector<std::string> names;
1373  for (auto & pair : _mesh_modifiers)
1374  names.push_back(pair.first);
1375  return names;
1376 }
1377 
1378 void
1380 {
1381  if (!_mesh_modifiers.empty())
1382  {
1383  TIME_SECTION(_execute_mesh_modifiers_timer);
1384 
1386 
1387  // Add all of the dependencies into the resolver and sort them
1388  for (const auto & it : _mesh_modifiers)
1389  {
1390  // Make sure an item with no dependencies comes out too!
1391  resolver.addItem(it.second);
1392 
1393  std::vector<std::string> & modifiers = it.second->getDependencies();
1394  for (const auto & depend_name : modifiers)
1395  {
1396  auto depend_it = _mesh_modifiers.find(depend_name);
1397 
1398  if (depend_it == _mesh_modifiers.end())
1399  mooseError("The MeshModifier \"",
1400  depend_name,
1401  "\" was not created, did you make a "
1402  "spelling mistake or forget to include it "
1403  "in your input file?");
1404 
1405  resolver.insertDependency(it.second, depend_it->second);
1406  }
1407  }
1408 
1409  const auto & ordered_modifiers = resolver.getSortedValues();
1410 
1411  if (ordered_modifiers.size())
1412  {
1413  MooseMesh * mesh = _action_warehouse.mesh().get();
1414  MooseMesh * displaced_mesh = _action_warehouse.displacedMesh().get();
1415 
1416  // Run the MeshModifiers in the proper order
1417  for (const auto & modifier : ordered_modifiers)
1418  modifier->modifyMesh(mesh, displaced_mesh);
1419 
1424  mesh->prepared(false);
1425  if (displaced_mesh)
1426  displaced_mesh->prepared(false);
1427  }
1428  }
1429 }
1430 
1431 void
1433 {
1434  _mesh_modifiers.clear();
1435 }
1436 
1437 void
1438 MooseApp::addMeshGenerator(const std::string & generator_name,
1439  const std::string & name,
1440  InputParameters parameters)
1441 {
1442  std::shared_ptr<MeshGenerator> mesh_generator =
1443  _factory.create<MeshGenerator>(generator_name, name, parameters);
1444 
1445  _mesh_generators.insert(std::make_pair(MooseUtils::shortName(name), mesh_generator));
1446 }
1447 
1448 const MeshGenerator &
1449 MooseApp::getMeshGenerator(const std::string & name) const
1450 {
1451  return *_mesh_generators.find(MooseUtils::shortName(name))->second.get();
1452 }
1453 
1454 std::vector<std::string>
1456 {
1457  std::vector<std::string> names;
1458  for (auto & pair : _mesh_generators)
1459  names.push_back(pair.first);
1460  return names;
1461 }
1462 
1463 std::unique_ptr<MeshBase> &
1464 MooseApp::getMeshGeneratorOutput(const std::string & name)
1465 {
1466  auto & outputs = _mesh_generator_outputs[name];
1467 
1468  outputs.push_back(nullptr);
1469 
1470  return outputs.back();
1471 }
1472 
1473 void
1475 {
1476  if (!_mesh_generators.empty())
1477  {
1478  TIME_SECTION(_execute_mesh_generators_timer);
1479 
1481 
1482  // Add all of the dependencies into the resolver and sort them
1483  for (const auto & it : _mesh_generators)
1484  {
1485  // Make sure an item with no dependencies comes out too!
1486  resolver.addItem(it.second);
1487 
1488  std::vector<std::string> & generators = it.second->getDependencies();
1489  for (const auto & depend_name : generators)
1490  {
1491  auto depend_it = _mesh_generators.find(depend_name);
1492 
1493  if (depend_it == _mesh_generators.end())
1494  mooseError("The MeshGenerator \"",
1495  depend_name,
1496  "\" was not created, did you make a "
1497  "spelling mistake or forget to include it "
1498  "in your input file?");
1499 
1500  resolver.insertDependency(it.second, depend_it->second);
1501  }
1502  }
1503 
1504  const auto & ordered_generators = resolver.getSortedValues();
1505 
1506  if (ordered_generators.size())
1507  {
1508  // Grab the outputs from the final generator so MeshGeneratorMesh can pick them up
1509  auto final_generator_name = ordered_generators.back()->name();
1510 
1511  _final_generated_meshes.emplace_back(&getMeshGeneratorOutput(final_generator_name));
1512 
1513  // Need to grab two if we're going to be making a displaced mesh
1515  _final_generated_meshes.emplace_back(&getMeshGeneratorOutput(final_generator_name));
1516 
1517  // Run the MeshGenerators in the proper order
1518  for (const auto & generator : ordered_generators)
1519  {
1520  auto name = generator->name();
1521 
1522  auto current_mesh = generator->generate();
1523 
1524  // Now we need to possibly give this mesh to downstream generators
1525  auto & outputs = _mesh_generator_outputs[name];
1526 
1527  if (outputs.size())
1528  {
1529  auto & first_output = *outputs.begin();
1530 
1531  first_output = std::move(current_mesh);
1532 
1533  const auto & copy_from = *first_output;
1534 
1535  auto output_it = ++outputs.begin();
1536 
1537  // For all of the rest we need to make a copy
1538  for (; output_it != outputs.end(); ++output_it)
1539  (*output_it) = copy_from.clone();
1540  }
1541  }
1542  }
1543  }
1544 }
1545 
1546 void
1548 {
1549  _mesh_generators.clear();
1550 }
1551 
1552 void
1553 MooseApp::setRestart(const bool & value)
1554 {
1555  _restart = value;
1556 
1557  std::shared_ptr<FEProblemBase> fe_problem = _action_warehouse.problemBase();
1558 }
1559 
1560 void
1561 MooseApp::setRecover(const bool & value)
1562 {
1563  _recover = value;
1564 }
1565 
1566 void
1567 MooseApp::setBackupObject(std::shared_ptr<Backup> backup)
1568 {
1570 }
1571 
1572 void
1574 {
1575  if (!_cached_backup.get())
1576  mooseError("No cached Backup to restore!");
1577 
1578  TIME_SECTION(_restore_cached_backup_timer);
1579 
1581 
1582  // Release our hold on this Backup
1583  _cached_backup.reset();
1584 }
1585 
1586 void
1588 {
1589  TIME_SECTION(_create_minimal_app_timer);
1590 
1591  // SetupMeshAction
1592  {
1593  // Build the Action parameters
1594  InputParameters action_params = _action_factory.getValidParams("SetupMeshAction");
1595  action_params.set<std::string>("type") = "GeneratedMesh";
1596 
1597  // Create The Action
1598  std::shared_ptr<MooseObjectAction> action = std::static_pointer_cast<MooseObjectAction>(
1599  _action_factory.create("SetupMeshAction", "Mesh", action_params));
1600 
1601  // Set the object parameters
1602  InputParameters & params = action->getObjectParams();
1603  params.set<MooseEnum>("dim") = "1";
1604  params.set<unsigned int>("nx") = 1;
1605 
1606  // Add Action to the warehouse
1608  }
1609 
1610  // Executioner
1611  {
1612  // Build the Action parameters
1613  InputParameters action_params = _action_factory.getValidParams("CreateExecutionerAction");
1614  action_params.set<std::string>("type") = "Transient";
1615 
1616  // Create the action
1617  std::shared_ptr<MooseObjectAction> action = std::static_pointer_cast<MooseObjectAction>(
1618  _action_factory.create("CreateExecutionerAction", "Executioner", action_params));
1619 
1620  // Set the object parameters
1621  InputParameters & params = action->getObjectParams();
1622  params.set<unsigned int>("num_steps") = 1;
1623  params.set<Real>("dt") = 1;
1624 
1625  // Add Action to the warehouse
1627  }
1628 
1629  // Problem
1630  {
1631  // Build the Action parameters
1632  InputParameters action_params = _action_factory.getValidParams("CreateProblemDefaultAction");
1633  action_params.set<bool>("_solve") = false;
1634 
1635  // Create the action
1636  std::shared_ptr<Action> action = std::static_pointer_cast<Action>(
1637  _action_factory.create("CreateProblemDefaultAction", "Problem", action_params));
1638 
1639  // Add Action to the warehouse
1641  }
1642 
1643  // Outputs
1644  {
1645  // Build the Action parameters
1646  InputParameters action_params = _action_factory.getValidParams("CommonOutputAction");
1647  action_params.set<bool>("console") = false;
1648 
1649  // Create action
1650  std::shared_ptr<Action> action =
1651  _action_factory.create("CommonOutputAction", "Outputs", action_params);
1652 
1653  // Add Action to the warehouse
1655  }
1656 
1658 }
1659 
1660 void
1662 {
1663  if (flag.id() == MooseEnumItem::INVALID_ID)
1664  {
1665  // It is desired that users when creating ExecFlagTypes should not worry about needing
1666  // to assign a name and an ID. However, the ExecFlagTypes created by users are global
1667  // constants and the ID to be assigned can't be known at construction time of this global
1668  // constant, it is only known when it is added to this object (ExecFlagEnum). Therefore,
1669  // this const cast allows the ID to be set after construction. This was the lesser of two
1670  // evils: const_cast or friend class with mutable members.
1671  ExecFlagType & non_const_flag = const_cast<ExecFlagType &>(flag);
1672  auto it = _execute_flags.find(flag.name());
1673  if (it != _execute_flags.items().end())
1674  non_const_flag.setID(it->id());
1675  else
1676  non_const_flag.setID(_execute_flags.getNextValidID());
1677  }
1679 }
1680 
1681 bool
1682 MooseApp::hasRelationshipManager(const std::string & name) const
1683 {
1684  return std::find_if(_relationship_managers.begin(),
1685  _relationship_managers.end(),
1686  [&name](const std::shared_ptr<RelationshipManager> & rm) {
1687  return rm->name() == name;
1688  }) != _relationship_managers.end();
1689 }
1690 
1691 bool
1692 MooseApp::addRelationshipManager(std::shared_ptr<RelationshipManager> relationship_manager)
1693 {
1694  // We don't need Geometric-only RelationshipManagers when we run with
1695  // ReplicatedMesh unless we are splitting the mesh.
1696  if (!_action_warehouse.mesh()->isDistributedMesh() && !_split_mesh &&
1697  (relationship_manager->isType(Moose::RelationshipManagerType::GEOMETRIC) &&
1698  !relationship_manager->isType(Moose::RelationshipManagerType::ALGEBRAIC)))
1699  return false;
1700 
1701  bool add = true;
1702  for (const auto & rm : _relationship_managers)
1703  {
1704  if (*rm == *relationship_manager)
1705  {
1706  add = false;
1707 
1708  auto & existing_for_whom = rm->forWhom();
1709 
1710  // Since the existing object is going to cover this one
1711  // Pass along who is needing it
1712  for (auto & fw : relationship_manager->forWhom())
1713  {
1714  if (std::find(existing_for_whom.begin(), existing_for_whom.end(), fw) ==
1715  existing_for_whom.end())
1716  rm->addForWhom(fw);
1717  }
1718 
1719  break;
1720  }
1721  }
1722 
1723  if (add)
1724  _relationship_managers.emplace_back(relationship_manager);
1725 
1726  // Inform the caller whether the object was added or not
1727  return add;
1728 }
1729 
1730 void
1732 {
1733  for (auto & rm : _relationship_managers)
1734  {
1735  if (rm->isType(rm_type))
1736  {
1737  // Will attach them later (during algebraic)
1738  if (rm_type == Moose::RelationshipManagerType::GEOMETRIC && !rm->attachGeometricEarly())
1739  continue;
1740 
1742  {
1743  // The problem is not built yet - so the ActionWarehouse currently owns the mesh
1744  auto & mesh = _action_warehouse.mesh();
1745 
1746  rm->init();
1747 
1748  if (rm->useDisplacedMesh() && _action_warehouse.displacedMesh())
1749  _action_warehouse.displacedMesh()->getMesh().add_ghosting_functor(*rm);
1750  else
1751  mesh->getMesh().add_ghosting_functor(*rm);
1752  }
1753 
1755  {
1756  // If it's also Geometric but didn't get attached early - then let's attach it now
1757  if (rm->isType(Moose::RelationshipManagerType::GEOMETRIC) && !rm->attachGeometricEarly())
1758  {
1759  // Now that the Problem is built we'll get the mesh from there
1760  auto & problem = _executioner->feProblem();
1761  auto & mesh = problem.mesh();
1762 
1763  rm->init();
1764 
1765  if (rm->useDisplacedMesh() && _action_warehouse.displacedMesh())
1766  _action_warehouse.displacedMesh()->getMesh().add_ghosting_functor(*rm);
1767  else
1768  mesh.getMesh().add_ghosting_functor(*rm);
1769  }
1770 
1771  auto & problem = _executioner->feProblem();
1772 
1773  // If it is not at all GEOMETRIC then it hasn't been inited
1775  rm->init();
1776 
1777  if (rm->useDisplacedMesh() && problem.getDisplacedProblem())
1778  {
1779  problem.getDisplacedProblem()->nlSys().dofMap().add_algebraic_ghosting_functor(*rm);
1780  problem.getDisplacedProblem()->auxSys().dofMap().add_algebraic_ghosting_functor(*rm);
1781  }
1782  else
1783  {
1784  problem.getNonlinearSystemBase().dofMap().add_algebraic_ghosting_functor(*rm);
1785  problem.getAuxiliarySystem().dofMap().add_algebraic_ghosting_functor(*rm);
1786  }
1787  }
1788  }
1789  }
1790 }
1791 
1792 std::vector<std::pair<std::string, std::string>>
1794 {
1795  std::vector<std::pair<std::string, std::string>> info_strings;
1796  info_strings.reserve(_relationship_managers.size());
1797 
1798  for (const auto & rm : _relationship_managers)
1799  {
1800  std::stringstream oss;
1801  oss << rm->getInfo();
1802 
1803  auto & for_whom = rm->forWhom();
1804 
1805  if (!for_whom.empty())
1806  {
1807  oss << " for ";
1808 
1809  std::copy(for_whom.begin(), for_whom.end(), infix_ostream_iterator<std::string>(oss, ", "));
1810  }
1811 
1812  info_strings.emplace_back(std::make_pair(Moose::stringify(rm->getType()), oss.str()));
1813  }
1814 
1815  // List the libMesh GhostingFunctors - Not that in libMesh all of the algebraic and coupling
1816  // Ghosting Functors are also attached to the mesh. This should catch them all.
1817  const auto & mesh = _action_warehouse.getMesh();
1818  if (mesh)
1819  {
1820  std::unordered_map<std::string, unsigned int> counts;
1821 
1822  for (auto & gf : as_range(mesh->getMesh().ghosting_functors_begin(),
1823  mesh->getMesh().ghosting_functors_end()))
1824  {
1825  const auto * gf_ptr = dynamic_cast<const RelationshipManager *>(gf);
1826  if (!gf_ptr)
1827  // Count how many occurances of the same Ghosting Functor types we are encountering
1828  counts[demangle(typeid(*gf).name())]++;
1829  }
1830 
1831  for (const auto pair : counts)
1832  info_strings.emplace_back(std::make_pair(
1833  "Default", pair.first + (pair.second > 1 ? " x " + std::to_string(pair.second) : "")));
1834  }
1835 
1836  return info_strings;
1837 }
std::list< std::string > getCheckpointFiles() const
Extract all possible checkpoint file names.
Definition: MooseApp.C:1035
void registerRecoverableData(std::string name)
NOTE: This is an internal function meant for MOOSE use only!
Definition: MooseApp.C:889
std::list< std::string > getCheckpointDirectories() const
Get all checkpoint directories.
Definition: MooseApp.C:984
int getNextValidID() const
Compute the next valid ID.
std::string getFileName(bool stripLeadingPath=true) const
Return the filename that was parsed.
Definition: MooseApp.C:1049
const std::string & name() const
Get the name of the object.
Definition: MooseApp.h:73
PerfID _run_timer
Definition: MooseApp.h:921
void setID(const int &id)
Method to change the ID of the item, but only if it is an INVALID_ID.
Definition: MooseEnumItem.C:81
virtual std::string getPrintableName() const
Get printable name of the application.
Definition: MooseApp.h:80
unsigned int _multiapp_level
Level of multiapp, the master is level 0. This used by the Console to indent output.
Definition: MooseApp.h:891
void setInputFileName(std::string input_file_name)
Set the input file name.
Definition: MooseApp.C:784
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
Definition: Factory.C:87
bool prepared() const
Setter/getter for the _is_prepared flag.
Definition: MooseMesh.C:2291
const std::string _type
The string representation of the type of this object as registered (see registerApp(AppName)) ...
Definition: MooseApp.h:728
Storage container for all InputParamter objects.
static const std::map< std::string, std::vector< RegistryEntry > > & allActions()
Returns a per-label keyed map of all Actions in the registry.
Definition: Registry.C:32
void tokenize(const std::string &str, std::vector< T > &elements, unsigned int min_len=1, const std::string &delims="/")
This function will split the passed in string on a set of delimiters appending the substrings to the ...
Definition: MooseUtils.h:532
virtual void setupOptions()
Setup options based on InputParameters.
Definition: MooseApp.C:448
std::string libNameToAppName(const std::string &library_name) const
Converts a library name to an application name:
Definition: MooseApp.C:1077
RelationshipManagerType
Main types of Relationship Managers.
Definition: MooseTypes.h:716
const std::string & name() const
Definition: MooseEnumItem.h:37
std::string getFrameworkVersion() const
Returns the framework version.
Definition: MooseApp.C:430
const std::multimap< std::string, ActionInfo > & getAssociatedActions() const
Return all Syntax to Action associations.
Definition: Syntax.C:310
RestartableDatas _restartable_data
Where the restartable data is held (indexed on tid)
Definition: MooseApp.h:876
std::vector< std::pair< std::string, std::string > > getRelationshipManagerInfo() const
Returns the Relationship managers info suitable for printing.
Definition: MooseApp.C:1793
bool _output_position_set
Whether or not an output position has been set for this app.
Definition: MooseApp.h:746
Generic factory class for build all sorts of objects.
Definition: Factory.h:153
static void checkLabels(const std::set< std::string > &known_labels={})
This runs error checking to make sure that all objects and actions in the registry have valid labels...
Definition: Registry.C:136
if(nl->nonlinearSolver() ->matvec &&nl->nonlinearSolver() ->residual_and_jacobian_object)
void addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
void addDependency(const std::string &task, const std::string &pre_req)
Method to insert a new task in the list of existing tasks at the specified location.
Definition: Syntax.C:55
std::unique_ptr< TheWarehouse > _the_warehouse
Definition: MooseApp.h:888
std::set< std::string > _recoverable_data
Data names that will only be read from the restart file during RECOVERY.
Definition: MooseApp.h:879
InputParameters getValidParams(const std::string &name)
Definition: ActionFactory.C:70
void setCheckUnusedFlag(bool warn_is_error=false)
Set a flag so that the parser will either warn or error when unused variables are seen after parsing ...
Definition: MooseApp.C:917
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
InputParameters & parameters()
Get the parameters of the object.
Definition: MooseApp.h:86
std::unique_ptr< MeshBase > & getMeshGeneratorOutput(const std::string &name)
Get a refernce to a pointer that will be the output of the MeshGenerator named name.
Definition: MooseApp.C:1464
bool _warnings_are_errors
Variable to toggle any warning into an error (includes deprecated code warnings)
Definition: Moose.C:570
static const int INVALID_ID
Definition: MooseEnumItem.h:24
InputParameterWarehouse & getInputParameterWarehouse()
Get the InputParameterWarehouse for MooseObjects.
Definition: MooseApp.C:1341
std::string toString(const moosecontrib::Json::Value &root)
Returns a string representation of the tree in input file format.
PerfID _run_input_file_timer
Definition: MooseApp.h:917
void dynamicRegistration(const Parameters &params)
Helper method for dynamic loading of objects.
Definition: MooseApp.C:1164
void registerTaskName(const std::string &task, bool should_auto_build=false)
Method to register a new task.
Definition: Syntax.C:20
std::shared_ptr< MooseMesh > & displacedMesh()
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:219
Class for doing restart.
const std::shared_ptr< MooseMesh > & getMesh() const
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: Action.h:224
PerfID _execute_mesh_generators_timer
Definition: MooseApp.h:923
PerfID _create_minimal_app_timer
Definition: MooseApp.h:925
void setFinalTask(const std::string &task)
void indentMessage(const std::string &prefix, std::string &message, const char *color=COLOR_CYAN)
Indents the supplied message given the prefix and color.
Definition: MooseUtils.C:431
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
virtual void run()
Run the application.
Definition: MooseApp.C:944
Real _start_time
The time at which to start the simulation.
Definition: MooseApp.h:755
std::list< std::string > getFilesInDirs(const std::list< std::string > &directory_list)
Retrieves the names of all of the files contained within the list of directories passed into the rout...
Definition: MooseUtils.C:485
const bool _use_split
Whether or not we are using a (pre-)split mesh (automatically DistributedMesh)
Definition: MooseApp.h:823
MeshModifiers are objects that can modify or add to an existing mesh.
Definition: MeshModifier.h:25
unsigned int multiAppLevel() const
The MultiApp Level.
Definition: MooseApp.h:517
static std::string getOutputFileBase(const MooseApp &app, std::string suffix="_out")
Returns the default output file base.
Definition: FileOutput.C:111
bool hasRelationshipManager(const std::string &name) const
Returns a Boolean indicating whether a RelationshipManater exists with the same name.
Definition: MooseApp.C:1682
PerfID _execute_timer
Definition: MooseApp.h:918
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
bool _check_input
true if we want to just check the input file
Definition: MooseApp.h:841
TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies.
Definition: Attributes.h:168
std::string getOutputFileBase() const
Override the selection of the output file base name.
Definition: MooseApp.C:790
bool isParamValid(const std::string &name) const
Definition: MooseApp.h:119
void addActionBlock(std::shared_ptr< Action > blk)
This method add an Action instance to the warehouse.
void addAvailableFlags(const ExecFlagType &flag, Args... flags)
Add additional execute_on flags to the list of possible flags.
Definition: ExecFlagEnum.h:84
Syntax _syntax
Syntax of the input file.
Definition: MooseApp.h:764
Syntax & syntax()
Definition: MooseApp.h:150
bool _trap_fpe
Whether or not FPE trapping should be turned on.
Definition: MooseApp.h:826
std::shared_ptr< Backup > _cached_backup
Cache for a Backup to use for restart / recovery.
Definition: MooseApp.h:909
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
void loadLibraryAndDependencies(const std::string &library_filename, const Parameters &params)
Recursively loads libraries and dependencies in the proper order to fully register a MOOSE applicatio...
Definition: MooseApp.C:1204
ActionWarehouse _action_warehouse
Where built actions are stored.
Definition: MooseApp.h:776
const std::list< Action * > & getActionListByName(const std::string &task) const
Retrieve a constant list of Action pointers associated with the passed in task.
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
bool isRestarting() const
Whether or not this is a "restart" calculation.
Definition: MooseApp.C:865
bool isSplitMesh() const
Whether or not this is a split mesh operation.
Definition: MooseApp.C:871
std::unique_ptr< SystemInfo > _sys_info
System Information.
Definition: MooseApp.h:791
This class produces a dump of the InputFileParameters in the Standard Object Notation (SON) format fo...
Holds the syntax in a Json::Value tree.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
void executeMeshModifiers()
Execute and clear the Mesh Modifiers data structure.
Definition: MooseApp.C:1379
bool _half_transient
Whether or not this simulation should only run half its transient (useful for testing recovery) ...
Definition: MooseApp.h:835
Base class for actions.
Definition: Action.h:35
std::string hostname()
Get the hostname the current process is running on.
Definition: MooseUtils.C:375
std::string toString(const JsonVal &root)
returns a string representation of the tree in input file format
InputParameters emptyInputParameters()
std::shared_ptr< FEProblemBase > & problemBase()
std::string camelCaseToUnderscore(const std::string &camel_case_name)
Function for converting a camel case name to a name containing underscores.
Definition: MooseUtils.C:319
std::string shortName(const std::string &name)
Function for stripping name after the file / in parser block.
Definition: MooseUtils.C:363
const std::vector< T > & getSortedValues()
This function also returns dependency resolved values but with a simpler single vector interface...
std::shared_ptr< MooseMesh > & mesh()
bool checkFileReadable(const std::string &filename, bool check_line_endings=false, bool throw_on_unreadable=true)
Checks to see if a file is readable (exists and permissions)
Definition: MooseUtils.C:146
virtual std::shared_ptr< Backup > backup()
Create a Backup from the current App.
Definition: MooseApp.C:895
Parser _parser
Parser for parsing the input file.
Definition: MooseApp.h:779
TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies.
Definition: Attributes.h:153
void mooseInfo(Args &&... args)
Emit an informational message with the given stringified, concatenated args.
Definition: MooseError.h:252
bool _start_time_set
Whether or not an start time has been set.
Definition: MooseApp.h:752
void initSyntaxFormatter(SyntaxFormatterType type, bool dump_mode)
Creates a syntax formatter for printing.
Definition: Parser.C:632
bool isParamSetByAddParam(const std::string &name) const
Returns whether or not the parameter was set due to addParam.
std::pair< std::string, std::string > splitFileName(std::string full_file)
Function for splitting path and filename.
Definition: MooseUtils.C:289
void restoreCachedBackup()
Restore from a cached backup.
Definition: MooseApp.C:1573
bool addRelationshipManager(std::shared_ptr< RelationshipManager > relationship_manager)
Transfers ownership of a RelationshipManager to the application for lifetime management.
Definition: MooseApp.C:1692
nl system()
void addMeshModifier(const std::string &modifier_name, const std::string &name, InputParameters parameters)
Add a mesh modifier that will act on the meshes in the system.
Definition: MooseApp.C:1353
const std::set< ExecFlagType > & items() const
Reference the all the available items.
Definition: ExecFlagEnum.h:73
InputParameters & getObjectParams()
Retreive the parameters of the object to be created by this action.
void setErrorOverridden()
Set a flag so that the parser will throw an error if overridden parameters are detected.
Definition: MooseApp.C:938
PerfID _execute_mesh_modifiers_timer
Definition: MooseApp.h:922
std::shared_ptr< CommandLine > _command_line
Command line object.
Definition: MooseApp.h:761
bool _restart
Whether or not this is a restart run.
Definition: MooseApp.h:817
void registerExecFlags(Factory &factory)
Definition: Moose.C:370
bool _deprecated_is_error
Variable to toggle only deprecated warnings as errors.
Definition: Moose.C:572
const moosecontrib::Json::Value & getRoot() const
Get the root of the tree.
void setStartTime(const Real time)
Set the starting time for the simulation.
Definition: MooseApp.C:1042
void addMeshGenerator(const std::string &generator_name, const std::string &name, InputParameters parameters)
Add a mesh generator that will act on the meshes in the system.
Definition: MooseApp.C:1438
void meshChanged()
Calls the meshChanged method for every output object.
void setActive(bool active)
Turn on or off timing.
Definition: PerfGraph.h:107
void executeMeshGenerators()
Execute and clear the Mesh Generators data structure.
Definition: MooseApp.C:1474
bool hasRecoverFileBase()
Return true if the recovery file base is set.
Definition: MooseApp.C:883
Specialized factory for generic Action System objects.
Definition: ActionFactory.h:64
An inteface for the _console for outputting to the Console object.
bool isUseSplit() const
Whether or not we are running with pre-split (distributed mesh)
Definition: MooseApp.C:877
std::shared_ptr< Executioner > _executioner
Pointer to the executioner of this run (typically build by actions)
Definition: MooseApp.h:782
InputParameterWarehouse * _input_parameter_warehouse
Input parameter storage structure (this is a raw pointer so the destruction time can be explicitly co...
Definition: MooseApp.h:770
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
PerfLog perf_log
Perflog to be used by applications.
ActionFactory _action_factory
The Factory responsible for building Actions.
Definition: MooseApp.h:773
std::vector< std::string > getMeshModifierNames() const
Get names of all mesh modifiers Note: This function should be called after all mesh modifiers are add...
Definition: MooseApp.C:1370
std::string underscoreToCamelCase(const std::string &underscore_name, bool leading_upper_case)
Function for converting an underscore name to a camel case name.
Definition: MooseUtils.C:331
void dynamicAppRegistration(const std::string &app_name, std::string library_path, const std::string &library_name)
Definition: MooseApp.C:1101
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
PerfID _setup_options_timer
Definition: MooseApp.h:916
PerfID _restore_timer
Definition: MooseApp.h:920
RegistrationType
Enumeration for holding the valid types of dynamic registrations allowed.
Definition: MooseApp.h:882
std::map< std::string, std::shared_ptr< MeshGenerator > > _mesh_generators
Holds the mesh generators until they have completed, then this structure is cleared.
Definition: MooseApp.h:900
enum MooseApp::UNUSED_CHECK _enable_unused_check
bool _recover
Whether or not this is a recovery run.
Definition: MooseApp.h:814
Point _output_position
The output position.
Definition: MooseApp.h:749
void clearMeshModifiers()
Clear all mesh modifers.
Definition: MooseApp.C:1432
InputParameters validParams< MooseApp >()
Definition: MooseApp.C:71
void registerRestartableData(std::string name, std::unique_ptr< RestartableDataValue > data, THREAD_ID tid)
Definition: MooseApp.C:1089
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:236
bool _error_overridden
Indicates whether warnings or errors are displayed when overridden parameters are detected...
Definition: MooseApp.h:804
virtual std::string getVersion() const
Returns the current version of the framework or application (default: framework version).
Definition: MooseApp.C:436
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:60
Class for storing and utilizing output objects.
std::string _input_filename
Input file name used.
Definition: MooseApp.h:740
PerfID _execute_executioner_timer
Definition: MooseApp.h:919
std::map< std::pair< std::string, std::string >, void * > _lib_handles
The library, registration method and the handle to the method.
Definition: MooseApp.h:846
PerfID _restore_cached_backup_timer
Definition: MooseApp.h:924
static AppFactory & instance()
Get the instance of the AppFactory.
Definition: AppFactory.C:17
This class produces produces a dump of the InputFileParameters that appears like the normal input fil...
void clearMeshGenerators()
Clear all mesh modifers.
Definition: MooseApp.C:1547
void setRestart(const bool &value)
Sets the restart/recover flags.
Definition: MooseApp.C:1553
const int & id() const
Return the numeric, name, or raw name.
Definition: MooseEnumItem.h:36
PerfGraph _perf_graph
The PerfGraph object for this applciation.
Definition: MooseApp.h:734
InputParameters _pars
Parameters of this object.
Definition: MooseApp.h:725
bool _trap_fpe
Variable indicating whether we will enable FPE trapping for this run.
const T & getParam(const std::string &name)
Retrieve a parameter for the object.
Definition: MooseApp.h:935
std::map< std::string, std::list< std::unique_ptr< MeshBase > > > _mesh_generator_outputs
Holds the output for each mesh generator - including duplicates needed downstream.
Definition: MooseApp.h:903
void addCommandLineParam(const std::string &name, const std::string &syntax, const std::string &doc_string)
MatType type
virtual void executeExecutioner()
Execute the Executioner that was built.
Definition: MooseApp.C:835
virtual void restore(std::shared_ptr< Backup > backup, bool for_restart=false)
Restore a Backup.
Definition: MooseApp.C:905
std::string _recover_base
The base name to recover from. If blank then we will find the newest recovery file.
Definition: MooseApp.h:829
std::vector< std::string > getMeshGeneratorNames() const
Get names of all mesh generators Note: This function should be called after all mesh generators are a...
Definition: MooseApp.C:1455
bool _distributed_mesh_on_command_line
This variable indicates that DistributedMesh should be used for the libMesh mesh underlying MooseMesh...
Definition: MooseApp.h:811
void setBackupObject(std::shared_ptr< Backup > backup)
Method for setting the backup object to be restored at a later time.
Definition: MooseApp.C:1567
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
PetscErrorCode petscSetupOutput(CommandLine *cmd_line)
Definition: PetscSupport.C:264
ExecFlagEnum _execute_flags
Execution flags for this App.
Definition: MooseApp.h:912
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:21
OutputWarehouse _output_warehouse
OutputWarehouse object for this App.
Definition: MooseApp.h:767
std::string _output_file_base
The output file basename.
Definition: MooseApp.h:743
const std::shared_ptr< Parallel::Communicator > _comm
The MPI communicator this App is going to use.
Definition: MooseApp.h:731
processor_id_type processor_id()
Definition: MooseApp.h:288
void build()
Builds all auto-buildable tasks.
void registerAll(Factory &f, ActionFactory &af, Syntax &s)
Register objects that are in MOOSE.
Definition: Moose.C:70
std::string getFileName(bool stripLeadingPath=true) const
Return the filename that was parsed.
Definition: Parser.C:290
void errorCheck(const Parallel::Communicator &comm, bool warn_unused, bool err_unused)
Definition: Parser.C:582
virtual void runInputFile()
Actually build everything in the input file.
Definition: MooseApp.C:796
bool setColorConsole(bool use_color, bool force=false)
Turns color escape sequences on/off for info written to stdout.
Definition: Moose.C:564
virtual std::string header() const
Returns a string to be printed at the beginning of a simulation.
Definition: MooseApp.C:1347
Holding syntax for parsing input files.
Definition: Syntax.h:20
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters parameters)
Definition: ActionFactory.C:41
std::vector< std::string > getConstructedObjects() const
Get a list of all constructed Moose Object types.
Definition: Factory.C:277
const MeshGenerator & getMeshGenerator(const std::string &name) const
Get a mesh generator with its name.
Definition: MooseApp.C:1449
void setOutputPosition(Point p)
Tell the app to output in a specific position.
Definition: MooseApp.C:973
Factory _factory
Definition: MooseApp.h:801
void addExecFlag(const ExecFlagType &flag)
WARNING: This is an internal method for MOOSE, if you need the add new ExecFlagTypes then use the reg...
Definition: MooseApp.C:1661
void executeAllActions()
This method loops over all actions in the warehouse and executes them.
void buildJsonSyntaxTree(JsonSyntaxTree &tree) const
Use MOOSE Factories to construct a parameter tree for documentation or echoing input.
Definition: Parser.C:649
MooseApp(InputParameters parameters)
Constructor is protected so that this object is constructed through the AppFactory object...
Definition: MooseApp.C:259
std::shared_ptr< Backup > createBackup()
Create a Backup for the current system.
std::string _name
The name of this object.
Definition: MooseApp.h:722
const std::string & type() const
Get the type of this object as a string.
Definition: MooseApp.h:93
void addItem(const T &value)
Add an independent item to the set.
virtual void checkRegistryLabels()
Definition: MooseApp.C:409
void attachRelationshipManagers(Moose::RelationshipManagerType rm_type)
Attach the relationship managers of the given type Note: Geometric relationship managers that are sup...
Definition: MooseApp.C:1731
void dynamicAllRegistration(const std::string &app_name, Factory *factory, ActionFactory *action_factory, Syntax *syntax, std::string library_path, const std::string &library_name)
Thes methods are called to register applications or objects on demand.
Definition: MooseApp.C:1138
const MeshModifier & getMeshModifier(const std::string &name) const
Get a mesh modifier with its name.
Definition: MooseApp.C:1364
std::map< std::string, std::shared_ptr< MeshModifier > > _mesh_modifiers
Holds the mesh modifiers until they have completed, then this structure is cleared.
Definition: MooseApp.h:897
std::string getPrintableVersion() const
Non-virtual method for printing out the version string in a consistent format.
Definition: MooseApp.C:442
bool isUltimateMaster()
Whether or not this app is the ultimate master app.
Definition: MooseApp.h:528
void createMinimalApp()
Method for creating the minimum required actions for an application (no input file) ...
Definition: MooseApp.C:1587
bool isRecovering() const
Whether or not this is a "recover" calculation.
Definition: MooseApp.C:859
static const std::map< std::string, std::vector< RegistryEntry > > & allObjects()
Returns a per-label keyed map of all MooseObjects in the registry.
Definition: Registry.C:27
bool _ready_to_exit
Definition: MooseApp.h:805
void setRecover(const bool &value)
Definition: MooseApp.C:1561
std::set< MooseEnumItem >::const_iterator find(const MooseEnumItem &other) const
Locate an item.
void clear()
This method deletes all of the Actions in the warehouse.
A scope guard that guarantees that whatever happens between when it gets created and when it is destr...
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:30
void disableCheckUnusedFlag()
Removes warnings and error checks for unrecognized variables in the input file.
Definition: MooseApp.C:932
PerfID _setup_timer
Timers.
Definition: MooseApp.h:915
std::string _recover_suffix
The file suffix to recover from. If blank then we will use "cpr" for binary CheckpointIO.
Definition: MooseApp.h:832
bool _split_mesh
Whether or not we are performing a split mesh operation (–split-mesh)
Definition: MooseApp.h:820
void parse(const std::string &input_filename)
Parse an input file consisting of hit syntax and setup objects in the MOOSE derived application...
Definition: Parser.C:482
void restoreBackup(std::shared_ptr< Backup > backup, bool for_restart=false)
Restore a Backup for the current system.
OutputWarehouse & getOutputWarehouse()
Get the OutputWarehouse objects.
Definition: MooseApp.C:1055
std::string appNameToLibName(const std::string &app_name) const
Converts an application name to a library name: Examples: AnimalApp -> libanimal-oprof.la (assuming METHOD=oprof) ThreeWordAnimalApp -> libthree_word_animal-dbg.la (assuming METHOD=dbg)
Definition: MooseApp.C:1061
static char addKnownLabel(const std::string &label)
addKnownLabel whitelists a label as valid for purposes of the checkLabels function.
Definition: Registry.C:159
void buildFullTree(const std::string &search_string)
Use MOOSE Factories to construct a full parse tree for documentation or echoing input.
Definition: Parser.C:767
virtual ~MooseApp()
Definition: MooseApp.C:414
std::list< std::unique_ptr< MeshBase > * > _final_generated_meshes
The final Mesh that is generated by the generators.
Definition: MooseApp.h:906
unsigned int THREAD_ID
Definition: MooseTypes.h:161
void errorCheck()
Runs post-initialization error checking that cannot be run correctly unless the simulation has been f...
Definition: MooseApp.C:821
std::set< std::string > getLoadedLibraryPaths() const
Return the loaded library filenames in a std::vector.
Definition: MooseApp.C:1330
std::vector< std::shared_ptr< RelationshipManager > > _relationship_managers
Definition: MooseApp.h:843
void insertDependency(const T &key, const T &value)
Insert a dependency pair - the first value or the "key" depends on the second value or the "value"...
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.