https://mooseframework.inl.gov
MultiApp.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 // MOOSE includes
11 #include "MultiApp.h"
12 
13 #include "AppFactory.h"
14 #include "AuxiliarySystem.h"
15 #include "DisplacedProblem.h"
16 #include "Console.h"
17 #include "Executioner.h"
18 #include "FEProblem.h"
19 #include "MooseMesh.h"
20 #include "MooseUtils.h"
21 #include "OutputWarehouse.h"
22 #include "SetupInterface.h"
23 #include "UserObject.h"
24 #include "CommandLine.h"
25 #include "Conversion.h"
26 #include "NonlinearSystemBase.h"
27 #include "DelimitedFileReader.h"
28 #include "MooseAppCoordTransform.h"
29 #include "MultiAppTransfer.h"
30 #include "Positions.h"
31 #include "Transient.h"
32 #include "Backup.h"
33 #include "Parser.h"
34 
35 #include "libmesh/mesh_tools.h"
36 #include "libmesh/numeric_vector.h"
37 
38 // C++ includes
39 #include <fstream>
40 #include <iomanip>
41 #include <iterator>
42 #include <algorithm>
43 
44 // Call to "uname"
45 #ifdef LIBMESH_HAVE_SYS_UTSNAME_H
46 #include <sys/utsname.h>
47 #endif
48 
51 {
53  params += SetupInterface::validParams();
54 
55  params.addParam<bool>("use_displaced_mesh",
56  false,
57  "Whether or not this object should use the "
58  "displaced mesh for computation. Note that "
59  "in the case this is true but no "
60  "displacements are provided in the Mesh block "
61  "the undisplaced mesh will still be used.");
62 
63  std::ostringstream app_types_strings;
64  for (const auto & name_bi_pair : AppFactory::instance().registeredObjects())
65  app_types_strings << name_bi_pair.first << " ";
66  MooseEnum app_types_options(app_types_strings.str(), "", true);
67 
68  // Dynamic loading
69  params.addParam<MooseEnum>("app_type",
70  app_types_options,
71  "The type of application to build (applications not "
72  "registered can be loaded with dynamic libraries. Parent "
73  "application type will be used if not provided.");
74  params.addParam<std::string>("library_path",
75  "",
76  "Path to search for dynamic libraries (please "
77  "avoid committing absolute paths in addition to "
78  "MOOSE_LIBRARY_PATH)");
79  params.addParam<std::string>(
80  "library_name",
81  "",
82  "The file name of the library (*.la file) that will be dynamically loaded.");
83  params.addParam<bool>("library_load_dependencies",
84  false,
85  "Tells MOOSE to manually load library dependencies. This should not be "
86  "necessary and is here for debugging/troubleshooting.");
87 
88  // Subapp positions
89  params.addParam<std::vector<Point>>(
90  "positions",
91  "The positions of the App locations. Each set of 3 values will represent a "
92  "Point. This and 'positions_file' cannot be both supplied. If this and "
93  "'positions_file'/'_objects' are not supplied, a single position (0,0,0) will be used");
94  params.addParam<std::vector<FileName>>("positions_file",
95  "Filename(s) that should be looked in for positions. Each"
96  " set of 3 values in that file will represent a Point. "
97  "This and 'positions(_objects)' cannot be both supplied");
98  params.addParam<std::vector<PositionsName>>("positions_objects",
99  "The name of a Positions object that will contain "
100  "the locations of the sub-apps created. This and "
101  "'positions(_file)' cannot be both supplied");
102  params.addParam<bool>(
103  "output_in_position",
104  false,
105  "If true this will cause the output from the MultiApp to be 'moved' by its position vector");
106  params.addParam<bool>(
107  "run_in_position",
108  false,
109  "If true this will cause the mesh from the MultiApp to be 'moved' by its position vector");
110 
111  params.addRequiredParam<std::vector<FileName>>(
112  "input_files",
113  "The input file for each App. If this parameter only contains one input file "
114  "it will be used for all of the Apps. When using 'positions_from_file' it is "
115  "also admissable to provide one input_file per file.");
116  params.addParam<Real>("bounding_box_inflation",
117  0.01,
118  "Relative amount to 'inflate' the bounding box of this MultiApp.");
119  params.addParam<Point>("bounding_box_padding",
120  RealVectorValue(),
121  "Additional padding added to the dimensions of the bounding box. The "
122  "values are added to the x, y and z dimension respectively.");
123 
124  params.addPrivateParam<MPI_Comm>("_mpi_comm");
125 
126  // Set the default execution time
127  params.set<ExecFlagEnum>("execute_on", true) = EXEC_TIMESTEP_BEGIN;
128  // Add the POST_ADAPTIVITY execution flag.
129 #ifdef LIBMESH_ENABLE_AMR
130  ExecFlagEnum & exec_enum = params.set<ExecFlagEnum>("execute_on");
132  params.setDocString("execute_on", exec_enum.getDocString());
133 #endif
134 
135  params.addParam<processor_id_type>("max_procs_per_app",
137  "Maximum number of processors to give to each App in this "
138  "MultiApp. Useful for restricting small solves to just a few "
139  "procs so they don't get spread out");
140  params.addParam<processor_id_type>("min_procs_per_app",
141  1,
142  "Minimum number of processors to give to each App in this "
143  "MultiApp. Useful for larger, distributed mesh solves.");
144  params.addParam<bool>(
145  "wait_for_first_app_init",
146  false,
147  "Create the first sub-application on rank 0, then MPI_Barrier before "
148  "creating the next N-1 apps (on all ranks). "
149  "This is only needed if your sub-application needs to perform some setup "
150  "actions in quiet, without other sub-applications working at the same time.");
151 
152  params.addParam<Real>("global_time_offset",
153  0,
154  "The time offset relative to the parent application for the purpose of "
155  "starting a subapp at a different time from the parent application. The "
156  "global time will be ahead by the offset specified here.");
157 
158  // Resetting subapps
159  params.addParam<std::vector<Real>>(
160  "reset_time",
161  {},
162  "The time(s) at which to reset Apps given by the 'reset_apps' parameter. "
163  "Resetting an App means that it is destroyed and recreated, possibly "
164  "modeling the insertion of 'new' material for that app.");
165  params.addParam<std::vector<unsigned int>>(
166  "reset_apps",
167  {},
168  "The Apps that will be reset when 'reset_time' is hit. These are the App "
169  "'numbers' starting with 0 corresponding to the order of the App positions. "
170  "Resetting an App means that it is destroyed and recreated, possibly modeling "
171  "the insertion of 'new' material for that app.");
172 
173  // Moving subapps
174  params.addParam<Real>(
175  "move_time",
177  "The time at which Apps designated by move_apps are moved to move_positions.");
178 
179  params.addParam<std::vector<unsigned int>>(
180  "move_apps",
181  {},
182  "Apps, designated by their 'numbers' starting with 0 corresponding to the order "
183  "of the App positions, to be moved at move_time to move_positions");
184  params.addParam<std::vector<Point>>(
185  "move_positions", {}, "The positions corresponding to each move_app.");
186 
187  params.addParam<std::vector<CLIArgString>>(
188  "cli_args",
189  {},
190  "Additional command line arguments to pass to the sub apps. If one set is provided the "
191  "arguments are applied to all, otherwise there must be a set for each sub app.");
192 
193  params.addParam<std::vector<FileName>>(
194  "cli_args_files",
195  "File names that should be looked in for additional command line arguments "
196  "to pass to the sub apps. Each line of a file is set to each sub app. If only "
197  "one line is provided, it will be applied to all sub apps.");
198 
199  // Fixed point iterations
200  params.addRangeCheckedParam<Real>("relaxation_factor",
201  1.0,
202  "relaxation_factor>0 & relaxation_factor<2",
203  "Fraction of newly computed value to keep."
204  "Set between 0 and 2.");
205  params.addDeprecatedParam<std::vector<std::string>>(
206  "relaxed_variables",
207  {},
208  "Use transformed_variables.",
209  "List of subapp variables to relax during Multiapp coupling iterations");
210  params.addParam<std::vector<std::string>>(
211  "transformed_variables",
212  {},
213  "List of subapp variables to use coupling algorithm on during Multiapp coupling iterations");
214  params.addParam<std::vector<PostprocessorName>>(
215  "transformed_postprocessors",
216  {},
217  "List of subapp postprocessors to use coupling "
218  "algorithm on during Multiapp coupling iterations");
219  params.addParam<bool>("keep_solution_during_restore",
220  false,
221  "This is useful when doing MultiApp coupling iterations. It takes the "
222  "final solution from the previous coupling iteration"
223  "and re-uses it as the initial guess for the next coupling iteration");
224  params.addParam<bool>("keep_aux_solution_during_restore",
225  false,
226  "This is useful when doing MultiApp coupling iterations. It takes the "
227  "final auxiliary solution from the previous coupling iteration"
228  "and re-uses it as the initial guess for the next coupling iteration");
229  params.addParam<bool>(
230  "no_restore",
231  false,
232  "True to turn off restore for this multiapp. This is useful when doing steady-state "
233  "Picard iterations where we want to use the solution of previous Picard iteration as the "
234  "initial guess of the current Picard iteration.");
235  params.addParam<unsigned int>(
236  "max_multiapp_level",
237  10,
238  "Integer set by user that will stop the simulation if the multiapp level "
239  "exceeds it. Useful for preventing infinite loops with multiapp simulations");
240 
241  params.addDeprecatedParam<bool>("clone_master_mesh",
242  false,
243  "True to clone parent app mesh and use it for this MultiApp.",
244  "clone_master_mesh is deprecated, use clone_parent_mesh instead");
245  params.addParam<bool>(
246  "clone_parent_mesh", false, "True to clone parent app mesh and use it for this MultiApp.");
247 
248  params.addPrivateParam<bool>("use_positions", true);
249  params.declareControllable("enable");
250  params.declareControllable("cli_args", {EXEC_PRE_MULTIAPP_SETUP});
251  params.registerBase("MultiApp");
252 
253  params.addParamNamesToGroup("use_displaced_mesh wait_for_first_app_init max_multiapp_level",
254  "Advanced");
255  params.addParamNamesToGroup("positions positions_file positions_objects run_in_position "
256  "output_in_position",
257  "Positions / transformations of the MultiApp frame of reference");
258  params.addParamNamesToGroup("min_procs_per_app max_procs_per_app", "Parallelism");
259  params.addParamNamesToGroup("reset_time reset_apps", "Reset MultiApp");
260  params.addParamNamesToGroup("move_time move_apps move_positions", "Timed move of MultiApps");
261  params.addParamNamesToGroup("relaxation_factor transformed_variables transformed_postprocessors "
262  "keep_solution_during_restore keep_aux_solution_during_restore "
263  "no_restore",
264  "Fixed point iteration");
265  params.addParamNamesToGroup("library_name library_path library_load_dependencies",
266  "Dynamic loading");
267  params.addParamNamesToGroup("cli_args cli_args_files", "Passing command line argument");
268  return params;
269 }
270 
272  : MooseObject(parameters),
273  SetupInterface(this),
274  Restartable(this, "MultiApps"),
275  PerfGraphInterface(this, std::string("MultiApp::") + _name),
276  _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
277  _app_type(isParamValid("app_type") ? std::string(getParam<MooseEnum>("app_type"))
278  : _fe_problem.getMooseApp().type()),
279  _use_positions(getParam<bool>("use_positions")),
280  _input_files(getParam<std::vector<FileName>>("input_files")),
281  _wait_for_first_app_init(getParam<bool>("wait_for_first_app_init")),
282  _total_num_apps(0),
283  _my_num_apps(0),
284  _first_local_app(0),
285  _orig_comm(_communicator.get()),
286  _my_communicator(),
287  _my_comm(_my_communicator.get()),
288  _my_rank(0),
289  _inflation(getParam<Real>("bounding_box_inflation")),
290  _bounding_box_padding(getParam<Point>("bounding_box_padding")),
291  _max_procs_per_app(getParam<processor_id_type>("max_procs_per_app")),
292  _min_procs_per_app(getParam<processor_id_type>("min_procs_per_app")),
293  _output_in_position(getParam<bool>("output_in_position")),
294  _global_time_offset(getParam<Real>("global_time_offset")),
295  _reset_times(getParam<std::vector<Real>>("reset_time")),
296  _reset_apps(getParam<std::vector<unsigned int>>("reset_apps")),
297  _reset_happened(false),
298  _move_time(getParam<Real>("move_time")),
299  _move_apps(getParam<std::vector<unsigned int>>("move_apps")),
300  _move_positions(getParam<std::vector<Point>>("move_positions")),
301  _move_happened(false),
302  _has_an_app(true),
303  _cli_args(getParam<std::vector<CLIArgString>>("cli_args")),
304  _keep_solution_during_restore(getParam<bool>("keep_solution_during_restore")),
305  _keep_aux_solution_during_restore(getParam<bool>("keep_aux_solution_during_restore")),
306  _no_restore(getParam<bool>("no_restore")),
307  _run_in_position(getParam<bool>("run_in_position")),
308  _sub_app_backups(declareRestartableDataWithContext<SubAppBackups>("sub_app_backups", this)),
309  _solve_step_timer(registerTimedSection("solveStep", 3, "Executing MultiApps", false)),
310  _init_timer(registerTimedSection("init", 3, "Initializing MultiApp")),
311  _backup_timer(registerTimedSection("backup", 3, "Backing Up MultiApp")),
312  _restore_timer(registerTimedSection("restore", 3, "Restoring MultiApp")),
313  _reset_timer(registerTimedSection("resetApp", 3, "Resetting MultiApp"))
314 {
315  if (parameters.isParamSetByUser("cli_args") && parameters.isParamValid("cli_args") &&
316  parameters.isParamValid("cli_args_files"))
317  paramError("cli_args",
318  "'cli_args' and 'cli_args_files' cannot be specified simultaneously in MultiApp ");
319 
320  if (!_use_positions && (isParamValid("positions") || isParamValid("positions_file") ||
321  isParamValid("positions_objects")))
322  paramError("use_positions",
323  "This MultiApps has been set to not use positions, "
324  "but a 'positions' parameter has been set.");
325 
326  if ((_reset_apps.size() > 0 && _reset_times.size() == 0) ||
327  (_reset_apps.size() == 0 && _reset_times.size() > 0))
328  mooseError("reset_time and reset_apps may only be specified together");
329 
330  // Check that the reset times are sorted by the user
331  auto sorted_times = _reset_times;
332  std::sort(sorted_times.begin(), sorted_times.end());
333  if (_reset_times.size() && _reset_times != sorted_times)
334  paramError("reset_time", "List of reset times must be sorted in increasing order");
335 }
336 
337 void
338 MultiApp::init(unsigned int num_apps, bool batch_mode)
339 {
340  auto config = rankConfig(
341  processor_id(), n_processors(), num_apps, _min_procs_per_app, _max_procs_per_app, batch_mode);
342  init(num_apps, config);
343 }
344 
345 void
346 MultiApp::init(unsigned int num_apps, const LocalRankConfig & config)
347 {
348  TIME_SECTION(_init_timer);
349 
350  _total_num_apps = num_apps;
351  _rank_config = config;
352  buildComm();
354 
355  _has_bounding_box.resize(_my_num_apps, false);
356  _reset_happened.resize(_reset_times.size(), false);
357  _bounding_box.resize(_my_num_apps);
358 
359  if ((_cli_args.size() > 1) && (_total_num_apps != _cli_args.size()))
360  paramError("cli_args",
361  "The number of items supplied must be 1 or equal to the number of sub apps.");
362 
363  // if cliArgs() != _cli_args, then cliArgs() was overridden and we need to check it
364  auto cla = cliArgs();
365  if (cla != std::vector<std::string>(_cli_args.begin(), _cli_args.end()))
366  {
367  if ((cla.size() > 1) && (_total_num_apps != cla.size()))
368  mooseError("The number of items supplied as command line argument to subapps must be 1 or "
369  "equal to the number of sub apps. Note: you use a multiapp that provides its own "
370  "command line parameters so the error is not in cli_args");
371  }
372 }
373 
374 void
376 {
377  if (_use_positions)
378  {
379  fillPositions();
380  init(_positions.size());
381  createApps();
382  }
383 }
384 
385 void
387 {
388  if (!_has_an_app)
389  return;
390 
391  TIME_SECTION("createApps", 2, "Instantiating Sub-Apps", false);
392 
393  // Read commandLine arguments that will be used when creating apps
395 
397 
398  _apps.resize(_my_num_apps);
399 
400  // If the user provided an unregistered app type, see if we can load it dynamically
401  if (!AppFactory::instance().isRegistered(_app_type))
403  getParam<std::string>("library_path"),
404  getParam<std::string>("library_name"),
405  getParam<bool>("library_load_dependencies"));
406 
407  bool rank_did_quiet_init = false;
408  unsigned int local_app = libMesh::invalid_uint;
410  {
411  if (hasLocalApp(0))
412  {
413  rank_did_quiet_init = true;
414  local_app = globalAppToLocal(0);
415  createLocalApp(local_app);
416  }
417 
418  MPI_Barrier(_orig_comm);
419  }
420 
421  for (unsigned int i = 0; i < _my_num_apps; i++)
422  {
423  if (rank_did_quiet_init && i == local_app)
424  continue;
425  createLocalApp(i);
426  }
427 }
428 
429 void
430 MultiApp::createLocalApp(const unsigned int i)
431 {
433 }
434 
435 void
437 {
438  if (!_use_positions)
439  // if not using positions, we create the sub-apps in initialSetup instead of right after
440  // construction of MultiApp
441  createApps();
442 }
443 
444 void
446 {
447  if (isParamValid("cli_args_files"))
448  {
449  _cli_args_from_file.clear();
450 
451  std::vector<FileName> cli_args_files = getParam<std::vector<FileName>>("cli_args_files");
452  std::vector<FileName> input_files = getParam<std::vector<FileName>>("input_files");
453 
454  // If we use parameter "cli_args_files", at least one file should be provided
455  if (!cli_args_files.size())
456  paramError("cli_args_files", "You need to provide at least one commandLine argument file ");
457 
458  // If we multiple input files, then we need to check if the number of input files
459  // match with the number of argument files
460  if (cli_args_files.size() != 1 && cli_args_files.size() != input_files.size())
461  paramError("cli_args_files",
462  "The number of commandLine argument files ",
463  cli_args_files.size(),
464  " for MultiApp ",
465  name(),
466  " must either be only one or match the number of input files ",
467  input_files.size());
468 
469  // Go through all argument files
470  std::vector<std::string> cli_args;
471  for (unsigned int p_file_it = 0; p_file_it < cli_args_files.size(); p_file_it++)
472  {
473  std::string cli_args_file = cli_args_files[p_file_it];
474  // Clear up
475  cli_args.clear();
476  // Read the file on the root processor then broadcast it
477  if (processor_id() == 0)
478  {
479  MooseUtils::checkFileReadable(cli_args_file);
480 
481  std::ifstream is(cli_args_file.c_str());
482  // Read by line rather than space separated like the cli_args parameter
483  std::string line;
484  while (std::getline(is, line))
485  cli_args.push_back(line);
486 
487  // We do not allow empty files
488  if (!cli_args.size())
489  paramError("cli_args_files",
490  "There is no commandLine argument in the commandLine argument file ",
491  cli_args_file);
492 
493  // If we have position files, we need to
494  // make sure the number of commandLine argument strings
495  // match with the number of positions
496  if (_npositions_inputfile.size())
497  {
498  auto num_positions = _npositions_inputfile[p_file_it];
499  // Check if the number of commandLine argument strings equal to
500  // the number of positions
501  if (cli_args.size() == 1)
502  for (MooseIndex(num_positions) num = 0; num < num_positions; num++)
503  _cli_args_from_file.push_back(cli_args.front());
504  else if (cli_args.size() == num_positions)
505  for (auto && cli_arg : cli_args)
506  _cli_args_from_file.push_back(cli_arg);
507  else if (cli_args.size() != num_positions)
508  paramError("cli_args_files",
509  "The number of commandLine argument strings ",
510  cli_args.size(),
511  " in the file ",
512  cli_args_file,
513  " must either be only one or match the number of positions ",
514  num_positions);
515  }
516  else
517  {
518  // If we do not have position files, we will check if the number of
519  // commandLine argument strings match with the total number of subapps
520  for (auto && cli_arg : cli_args)
521  _cli_args_from_file.push_back(cli_arg);
522  }
523  }
524  }
525 
526  // Broad cast all arguments to everyone
528  }
529 
530  if (_cli_args_from_file.size() && _cli_args_from_file.size() != 1 &&
532  mooseError(" The number of commandLine argument strings ",
533  _cli_args_from_file.size(),
534  " must either be only one or match the total "
535  "number of sub apps ",
537 
538  if (_cli_args_from_file.size() && cliArgs().size())
539  mooseError("Cannot set commandLine arguments from both input_file and external files");
540 }
541 
542 void
544 {
545  if (_move_apps.size() != _move_positions.size())
546  mooseError("The number of apps to move and the positions to move them to must be the same for "
547  "MultiApp ",
548  _name);
549 
550  if (isParamValid("positions") + isParamValid("positions_file") +
551  isParamValid("positions_objects") >
552  1)
553  mooseError("Only one 'positions' parameter may be specified");
554 
555  if (isParamValid("positions"))
556  {
557  _positions = getParam<std::vector<Point>>("positions");
558 
559  if (_positions.size() < _input_files.size())
560  mooseError("Not enough positions for the number of input files provided in MultiApp ",
561  name());
562  }
563  else if (isParamValid("positions_file"))
564  {
565  std::vector<FileName> positions_files = getParam<std::vector<FileName>>("positions_file");
566  std::vector<FileName> input_files = getParam<std::vector<FileName>>("input_files");
567 
568  if (input_files.size() != 1 && positions_files.size() != input_files.size())
569  mooseError("Number of input_files for MultiApp ",
570  name(),
571  " must either be only one or match the number of positions_file files");
572 
573  // Clear out the _input_files because we're going to rebuild it
574  if (input_files.size() != 1)
575  _input_files.clear();
576 
577  for (unsigned int p_file_it = 0; p_file_it < positions_files.size(); p_file_it++)
578  {
579  std::string positions_file = positions_files[p_file_it];
580  MooseUtils::DelimitedFileReader file(positions_file, &_communicator);
582  file.read();
583 
584  const std::vector<Point> & data = file.getDataAsPoints();
585  for (const auto & d : data)
586  _positions.push_back(d);
587 
588  // Save the number of positions for this input file
589  _npositions_inputfile.push_back(data.size());
590 
591  for (unsigned int i = 0; i < data.size(); ++i)
592  if (input_files.size() != 1)
593  _input_files.push_back(input_files[p_file_it]);
594  }
595  }
596  else if (isParamValid("positions_objects"))
597  {
598  const auto & positions_param_objs = getParam<std::vector<PositionsName>>("positions_objects");
599  const auto & input_files = getParam<std::vector<FileName>>("input_files");
600 
601  if (input_files.size() != 1 && positions_param_objs.size() != input_files.size())
602  mooseError("Number of input_files for MultiApp ",
603  name(),
604  " must either be only one or match the number of positions_objects specified");
605 
606  // Clear out the _input_files because we're going to rebuild it
607  if (input_files.size() != 1)
608  _input_files.clear();
609 
610  // Keeps track of where each positions object start in terms of subapp numbers
611  unsigned int offset = 0;
612 
613  for (const auto p_obj_it : index_range(positions_param_objs))
614  {
615  const std::string & positions_name = positions_param_objs[p_obj_it];
616  auto positions_obj = &_fe_problem.getPositionsObject(positions_name);
617 
618  const auto & data = positions_obj->getPositions(true);
619 
620  // Append all positions from this object
621  for (const auto & d : data)
622  _positions.push_back(d);
623 
624  // Save the number of positions for this input file
625  _npositions_inputfile.push_back(data.size());
626 
627  if (!positions_obj)
628  paramError("positions_objects",
629  "'" + positions_name + "' is not of the expected type. Should be a Positions");
630 
631  // Keep track of which positions is tied to what subapp
632  for (unsigned int i = 0; i < data.size(); ++i)
633  {
634  if (input_files.size() != 1)
635  _input_files.push_back(input_files[p_obj_it]);
636  _positions_objs.push_back(positions_obj);
637  _positions_index_offsets.push_back(offset);
638  }
639  offset += data.size();
640  }
641  }
642  else
643  {
644  _positions = {Point()};
645 
646  if (_positions.size() < _input_files.size())
647  mooseError("Not enough positions for the number of input files provided in MultiApp ",
648  name());
649  }
650 
651  mooseAssert(_input_files.size() == 1 || _positions.size() == _input_files.size(),
652  "Number of positions and input files are not the same!");
653 }
654 
655 void
656 MultiApp::preTransfer(Real /*dt*/, Real target_time)
657 {
658  // Get a transient executioner to get a user-set tolerance
659  Real timestep_tol = 1e-13;
660  if (dynamic_cast<TransientBase *>(_fe_problem.getMooseApp().getExecutioner()))
661  timestep_tol =
662  dynamic_cast<TransientBase *>(_fe_problem.getMooseApp().getExecutioner())->timestepTol();
663 
664  // Determination on whether we need to backup the app due to changes below
665  bool backup_apps = false;
666 
667  // First, see if any Apps need to be reset
668  for (unsigned int i = 0; i < _reset_times.size(); i++)
669  {
670  if (!_reset_happened[i] && (target_time + timestep_tol >= _reset_times[i]))
671  {
672  _reset_happened[i] = true;
673  if (_reset_apps.size() > 0)
674  for (auto & app : _reset_apps)
675  resetApp(app);
676 
677  // If we reset an application, then we delete the old objects, including the coordinate
678  // transformation classes. Consequently we need to reset the coordinate transformation classes
679  // in the associated transfer classes
680  for (auto * const transfer : _associated_transfers)
681  transfer->getAppInfo();
682 
683  // Similarly we need to transform the mesh again
684  if (_run_in_position)
685  for (const auto i : make_range(_my_num_apps))
686  {
687  auto app_ptr = _apps[i];
688  if (usingPositions())
689  app_ptr->getExecutioner()->feProblem().coordTransform().transformMesh(
690  app_ptr->getExecutioner()->feProblem().mesh(), _positions[_first_local_app + i]);
691  else
692  app_ptr->getExecutioner()->feProblem().coordTransform().transformMesh(
693  app_ptr->getExecutioner()->feProblem().mesh(), Point(0, 0, 0));
694  }
695 
696  // If the time step covers multiple reset times, set them all as having 'happened'
697  for (unsigned int j = i; j < _reset_times.size(); j++)
698  if (target_time + timestep_tol >= _reset_times[j])
699  _reset_happened[j] = true;
700 
701  // Backup in case the next solve fails
702  backup_apps = true;
703 
704  break;
705  }
706  }
707 
708  // Now move any apps that should be moved
709  if (_use_positions && !_move_happened && target_time + timestep_tol >= _move_time)
710  {
711  _move_happened = true;
712  for (unsigned int i = 0; i < _move_apps.size(); i++)
714 
715  // Backup in case the next solve fails
716  backup_apps = true;
717  }
718 
719  if (backup_apps)
720  backup();
721 }
722 
723 Executioner *
724 MultiApp::getExecutioner(unsigned int app)
725 {
726  if (!_has_an_app)
727  mooseError("No app for ", name(), " on processor ", _orig_rank);
728 
729  return _apps[globalAppToLocal(app)]->getExecutioner();
730 }
731 
732 void
734 {
735  for (const auto & app_ptr : _apps)
736  {
737  auto * executioner = app_ptr->getExecutioner();
738  mooseAssert(executioner, "Executioner is nullptr");
739 
740  executioner->feProblem().execute(EXEC_FINAL);
741  executioner->feProblem().outputStep(EXEC_FINAL);
742  }
743 }
744 
745 void
747 {
748  for (const auto & app_ptr : _apps)
749  {
750  auto * executioner = app_ptr->getExecutioner();
751  mooseAssert(executioner, "Executioner is nullptr");
752 
753  executioner->postExecute();
754  }
755 }
756 
757 void
759 {
760  TIME_SECTION(_backup_timer);
761 
763  _console << "Backed up MultiApp ... ";
764 
765  for (unsigned int i = 0; i < _my_num_apps; i++)
766  _sub_app_backups[i] = _apps[i]->backup();
767 
769  _console << name() << std::endl;
770 }
771 
772 void
773 MultiApp::restore(bool force)
774 {
775  TIME_SECTION(_restore_timer);
776 
777  if (force || needsRestoration())
778  {
779  // Must be restarting / recovering from main app so hold off on restoring
780  // Instead - the restore will happen in sub-apps' initialSetup()
781  // Note that _backups was already populated by dataLoad() in the main app
783  return;
784 
785  // We temporarily copy and store solutions for all subapps
787  {
789 
790  for (unsigned int i = 0; i < _my_num_apps; i++)
791  {
792  _end_solutions[i].resize(_apps[i]->getExecutioner()->feProblem().numSolverSystems());
793  for (unsigned int j = 0; j < _apps[i]->getExecutioner()->feProblem().numSolverSystems();
794  j++)
795  {
796  _end_solutions[i][j] = _apps[i]
797  ->getExecutioner()
798  ->feProblem()
799  .getSolverSystem(/*solver_sys=*/j)
800  .solution()
801  .clone();
802  }
803  auto & sub_multiapps =
804  _apps[i]->getExecutioner()->feProblem().getMultiAppWarehouse().getObjects();
805 
806  // multiapps of each subapp should do the same things
807  // It is implemented recursively
808  for (auto & multi_app : sub_multiapps)
809  multi_app->keepSolutionDuringRestore(_keep_solution_during_restore);
810  }
811  }
812 
813  // We temporarily copy and store solutions for all subapps
815  {
817 
818  for (unsigned int i = 0; i < _my_num_apps; i++)
819  _end_aux_solutions[i] =
821  }
822 
824  _console << "Restoring MultiApp ... ";
825 
826  for (unsigned int i = 0; i < _my_num_apps; i++)
827  {
828  _apps[i]->restore(std::move(_sub_app_backups[i]), false);
829  _sub_app_backups[i] = _apps[i]->finalizeRestore();
830  mooseAssert(_sub_app_backups[i], "Should have a backup");
831  }
832 
834  _console << name() << std::endl;
835 
836  // Now copy the latest solutions back for each subapp
838  {
839  for (unsigned int i = 0; i < _my_num_apps; i++)
840  {
841  for (unsigned int j = 0; j < _apps[i]->getExecutioner()->feProblem().numSolverSystems();
842  j++)
843  {
844  _apps[i]->getExecutioner()->feProblem().getSolverSystem(/*solver_sys=*/j).solution() =
845  *_end_solutions[i][j];
846 
847  // We need to synchronize solution so that local_solution has the right values
848  _apps[i]->getExecutioner()->feProblem().getSolverSystem(/*solver_sys=*/j).update();
849  }
850  }
851 
852  _end_solutions.clear();
853  }
854  // Now copy the latest auxiliary solutions back for each subapp
856  {
857  for (unsigned int i = 0; i < _my_num_apps; i++)
858  {
859  _apps[i]->getExecutioner()->feProblem().getAuxiliarySystem().solution() =
860  *_end_aux_solutions[i];
861 
862  // We need to synchronize solution so that local_solution has the right values
863  _apps[i]->getExecutioner()->feProblem().getAuxiliarySystem().update();
864  }
865 
866  _end_aux_solutions.clear();
867  }
868 
869  // Make sure the displaced mesh on the multiapp is up-to-date with displacement variables
870  for (const auto & app_ptr : _apps)
871  if (app_ptr->feProblem().getDisplacedProblem())
872  app_ptr->feProblem().getDisplacedProblem()->updateMesh();
873 
874  // If we are restoring due to a failed solve, make sure reset the solved state in the sub-apps
875  if (!getMooseApp().getExecutioner()->lastSolveConverged())
876  for (auto & app_ptr : _apps)
877  app_ptr->getExecutioner()->fixedPointSolve().clearFixedPointStatus();
878  }
879  else
880  {
881  for (unsigned int i = 0; i < _my_num_apps; i++)
882  {
883  for (auto & sub_app :
884  _apps[i]->getExecutioner()->feProblem().getMultiAppWarehouse().getObjects())
885  sub_app->restore(false);
886  }
887  }
888 }
889 
890 void
891 MultiApp::keepSolutionDuringRestore(bool keep_solution_during_restore)
892 {
893  if (_pars.isParamSetByUser("keep_solution_during_restore"))
894  paramError("keep_solution_during_restore",
895  "This parameter should only be provided in parent app");
896 
897  _keep_solution_during_restore = keep_solution_during_restore;
898 }
899 
900 void
901 MultiApp::transformBoundingBox(BoundingBox & box, const MultiAppCoordTransform & transform)
902 {
903  const Real min_x = box.first(0);
904  const Real max_x = box.second(0);
905  const Real min_y = box.first(1);
906  const Real max_y = box.second(1);
907  const Real min_z = box.first(2);
908  const Real max_z = box.second(2);
909 
910  std::array<Point, 8> box_corners = {{Point(min_x, min_y, min_z),
911  Point(max_x, min_y, min_z),
912  Point(min_x, max_y, min_z),
913  Point(max_x, max_y, min_z),
914  Point(min_x, min_y, max_z),
915  Point(max_x, min_y, max_z),
916  Point(min_x, max_y, max_z),
917  Point(max_x, max_y, max_z)}};
918 
919  // transform each corner
920  for (auto & corner : box_corners)
921  corner = transform(corner);
922 
923  // Create new bounding box
924  Point new_box_min = box_corners[0];
925  Point new_box_max = new_box_min;
926  for (const auto p : make_range(1, 8))
927  for (const auto d : make_range(Moose::dim))
928  {
929  const Point & pt = box_corners[p];
930  if (new_box_min(d) > pt(d))
931  new_box_min(d) = pt(d);
932 
933  if (new_box_max(d) < pt(d))
934  new_box_max(d) = pt(d);
935  }
936  box.first = new_box_min;
937  box.second = new_box_max;
938 }
939 
940 BoundingBox
941 MultiApp::getBoundingBox(unsigned int app,
942  bool displaced_mesh,
943  const MultiAppCoordTransform * const coord_transform)
944 {
945  if (!_has_an_app)
946  mooseError("No app for ", name(), " on processor ", _orig_rank);
947 
948  unsigned int local_app = globalAppToLocal(app);
949  FEProblemBase & fe_problem_base = _apps[local_app]->getExecutioner()->feProblem();
950  MooseMesh & mesh = (displaced_mesh && fe_problem_base.getDisplacedProblem().get() != NULL)
951  ? fe_problem_base.getDisplacedProblem()->mesh()
952  : fe_problem_base.mesh();
953 
954  {
956  if (displaced_mesh)
957  _bounding_box[local_app] = MeshTools::create_bounding_box(mesh);
958  else
959  {
960  if (!_has_bounding_box[local_app])
961  {
962  _bounding_box[local_app] = MeshTools::create_bounding_box(mesh);
963  _has_bounding_box[local_app] = true;
964  }
965  }
966  }
967  BoundingBox bbox = _bounding_box[local_app];
968 
969  Point min = bbox.min();
971  Point max = bbox.max();
973 
974  Point inflation_amount = (max - min) * _inflation;
975 
976  Point inflated_min = min - inflation_amount;
977  Point inflated_max = max + inflation_amount;
978 
979  Point shifted_min = inflated_min;
980  Point shifted_max = inflated_max;
981 
982  if ((!coord_transform || coord_transform->skipCoordinateCollapsing()) &&
983  fe_problem_base.getCoordSystem(*(mesh.meshSubdomains().begin())) == Moose::COORD_RZ)
984  {
985  // If the problem is RZ then we're going to invent a box that would cover the whole "3D" app
986  // FIXME: Assuming all subdomains are the same coordinate system type!
987  shifted_min(0) = -inflated_max(0);
988  shifted_min(1) = inflated_min(1);
989  shifted_min(2) = -inflated_max(0);
990 
991  shifted_max(0) = inflated_max(0);
992  shifted_max(1) = inflated_max(1);
993  shifted_max(2) = inflated_max(0);
994  }
995 
996  if (coord_transform)
997  {
998  BoundingBox transformed_bbox(shifted_min, shifted_max);
999  transformBoundingBox(transformed_bbox, *coord_transform);
1000  return transformed_bbox;
1001  }
1002  else
1003  {
1004  // This is where the app is located. We need to shift by this amount.
1005  Point p = position(app);
1006 
1007  // Shift them to the position they're supposed to be
1008  shifted_min += p;
1009  shifted_max += p;
1010  return BoundingBox(shifted_min, shifted_max);
1011  }
1012 }
1013 
1014 FEProblemBase &
1015 MultiApp::appProblemBase(unsigned int app)
1016 {
1017  if (!_has_an_app)
1018  mooseError("No app for ", name(), " on processor ", _orig_rank);
1019 
1020  unsigned int local_app = globalAppToLocal(app);
1021 
1022  return _apps[local_app]->getExecutioner()->feProblem();
1023 }
1024 
1025 FEProblem &
1026 MultiApp::appProblem(unsigned int app)
1027 {
1029  "MultiApp::appProblem() is deprecated, call MultiApp::appProblemBase() instead.\n");
1030  if (!_has_an_app)
1031  mooseError("No app for ", name(), " on processor ", _orig_rank);
1032 
1033  unsigned int local_app = globalAppToLocal(app);
1034 
1035  return dynamic_cast<FEProblem &>(_apps[local_app]->getExecutioner()->feProblem());
1036 }
1037 
1038 const UserObject &
1039 MultiApp::appUserObjectBase(unsigned int app, const std::string & name)
1040 {
1041  if (!_has_an_app)
1042  mooseError("No app for ", MultiApp::name(), " on processor ", _orig_rank);
1043 
1044  return appProblemBase(app).getUserObjectBase(name);
1045 }
1046 
1047 Real
1048 MultiApp::appPostprocessorValue(unsigned int app, const std::string & name)
1049 {
1050  if (!_has_an_app)
1051  mooseError("No app for ", MultiApp::name(), " on processor ", _orig_rank);
1052 
1054 }
1055 
1057 MultiApp::appTransferVector(unsigned int app, std::string var_name)
1058 {
1059  return *(appProblemBase(app).getSystem(var_name).solution);
1060 }
1061 
1062 bool
1064 {
1066 }
1067 
1068 bool
1069 MultiApp::hasLocalApp(unsigned int global_app) const
1070 {
1071  if (_has_an_app && global_app >= _first_local_app &&
1072  global_app <= _first_local_app + (_my_num_apps - 1))
1073  return true;
1074 
1075  return false;
1076 }
1077 
1078 MooseApp *
1079 MultiApp::localApp(unsigned int local_app)
1080 {
1081  mooseAssert(local_app < _apps.size(), "Index out of range: " + Moose::stringify(local_app));
1082  return _apps[local_app].get();
1083 }
1084 
1085 void
1086 MultiApp::resetApp(unsigned int global_app, Real time)
1087 {
1088  TIME_SECTION(_reset_timer);
1089 
1091 
1092  if (hasLocalApp(global_app))
1093  {
1094  unsigned int local_app = globalAppToLocal(global_app);
1095 
1096  // Extract the file numbers from the output, so that the numbering is maintained after reset
1097  std::map<std::string, unsigned int> m = _apps[local_app]->getOutputWarehouse().getFileNumbers();
1098 
1099  createApp(local_app, time);
1100 
1101  // Reset the file numbers of the newly reset apps
1102  _apps[local_app]->getOutputWarehouse().setFileNumbers(m);
1103  }
1104 }
1105 
1106 void
1107 MultiApp::moveApp(unsigned int global_app, Point p)
1108 {
1109  if (_use_positions)
1110  {
1111  _positions[global_app] = p;
1112 
1113  if (hasLocalApp(global_app))
1114  {
1115  unsigned int local_app = globalAppToLocal(global_app);
1116 
1117  if (_output_in_position)
1118  _apps[local_app]->setOutputPosition(p);
1119  if (_run_in_position)
1120  paramError("run_in_position", "Moving apps and running apps in position is not supported");
1121  }
1122  }
1123 }
1124 
1125 void
1127 {
1129  for (unsigned int i = 0; i < _apps.size(); i++)
1130  _apps[i]->setOutputPosition(_app.getOutputPosition() + _positions[_first_local_app + i]);
1131 }
1132 
1133 void
1134 MultiApp::createApp(unsigned int i, Real start_time)
1135 {
1136  // Delete the old app if we're resetting
1137  if (_apps[i])
1138  _apps[i].reset();
1139 
1140  // Define the app name
1141  const std::string multiapp_name = getMultiAppName(name(), _first_local_app + i, _total_num_apps);
1142  std::string full_name;
1143 
1144  // Only add parent name if the parent is not the main app
1145  if (_app.multiAppLevel() > 0)
1146  full_name = _app.name() + "_" + multiapp_name;
1147  else
1148  full_name = multiapp_name;
1149 
1151  app_params.set<FEProblemBase *>("_parent_fep") = &_fe_problem;
1152  app_params.set<std::unique_ptr<Backup> *>("_initial_backup") = &_sub_app_backups[i];
1153 
1154  // Build the CommandLine with the relevant options for this subapp and add the
1155  // cli args from the input file
1156  std::vector<std::string> input_cli_args;
1157  if (cliArgs().size() > 0 || _cli_args_from_file.size() > 0)
1158  input_cli_args = getCommandLineArgs(i);
1159  // This will mark all hit CLI command line parameters that are passed to subapps
1160  // as used within the parent app (_app)
1161  auto app_cli = _app.commandLine()->initSubAppCommandLine(name(), multiapp_name, input_cli_args);
1162  app_cli->parse();
1163 
1165  _console << COLOR_CYAN << "Creating MultiApp " << name() << " of type " << _app_type
1166  << " of level " << _app.multiAppLevel() + 1 << " and number " << _first_local_app + i
1167  << " on processor " << processor_id() << " with full name " << full_name
1168  << COLOR_DEFAULT << std::endl;
1169  app_params.set<unsigned int>("_multiapp_level") = _app.multiAppLevel() + 1;
1170  app_params.set<unsigned int>("_multiapp_number") = _first_local_app + i;
1171  app_params.set<const MooseMesh *>("_master_mesh") = &_fe_problem.mesh();
1172 #ifdef MOOSE_MFEM_ENABLED
1173  app_params.set<std::shared_ptr<mfem::Device>>("_mfem_device") =
1175  const auto & mfem_device_set = _app.getMFEMDevices(Moose::PassKey<MultiApp>());
1176  app_params.set<std::set<std::string>>("_mfem_devices") = mfem_device_set;
1177 #endif
1178  if (getParam<bool>("clone_master_mesh") || getParam<bool>("clone_parent_mesh"))
1179  {
1181  _console << COLOR_CYAN << "Cloned parent app mesh will be used for MultiApp " << name()
1182  << COLOR_DEFAULT << std::endl;
1183  app_params.set<bool>("_use_master_mesh") = true;
1185  if (displaced_problem)
1186  app_params.set<const MooseMesh *>("_master_displaced_mesh") = &displaced_problem->mesh();
1187  }
1188 
1189  // If only one input file was provided, use it for all the solves
1190  const auto input_index = _input_files.size() == 1 ? 0 : _first_local_app + i;
1191  const auto & input_file = _input_files[input_index];
1192 
1193  // create new parser tree for the application and parse
1194  auto parser = std::make_unique<Parser>(input_file);
1195  parser->setCommandLineParams(app_cli->buildHitParams());
1196  parser->parse();
1197 
1198  // Checks on app type
1199  const auto & app_type = parser->getAppType();
1200  if (app_type.empty() && _app_type.empty())
1201  mooseWarning("The application type is not specified for ",
1202  full_name,
1203  ". Please use [Application] block to specify the application type.");
1204  if (!app_type.empty() && app_type != _app_type && !AppFactory::instance().isRegistered(app_type))
1205  mooseError("In the ",
1206  full_name,
1207  ", '",
1208  app_type,
1209  "' is not a registered application. The registered application is named: '",
1210  _app_type,
1211  "'. Please double check the [Application] block to make sure the correct "
1212  "application is provided. \n");
1213 
1214  if (parser->getAppType().empty())
1215  parser->setAppType(_app_type);
1216 
1217  app_params.set<std::shared_ptr<Parser>>("_parser") = std::move(parser);
1218  app_params.set<std::shared_ptr<CommandLine>>("_command_line") = std::move(app_cli);
1219  _apps[i] = AppFactory::instance().create(_app_type, full_name, app_params, _my_comm);
1220  auto & app = _apps[i];
1221 
1222  app->setGlobalTimeOffset(start_time);
1223  app->setOutputFileNumbers(_app.getOutputWarehouse().getFileNumbers());
1224  app->setRestart(_app.isRestarting());
1225  app->setRecover(_app.isRecovering());
1226 
1227  if (_use_positions && getParam<bool>("output_in_position"))
1228  app->setOutputPosition(_app.getOutputPosition() + _positions[_first_local_app + i]);
1230  paramError("run_in_position",
1231  "Sub-apps are already displaced, so they are already output in position");
1232 
1233  // Update the MultiApp level for the app that was just created
1234  app->setupOptions();
1235  // if multiapp does not have file base in Outputs input block, output file base will
1236  // be empty here since setupOptions() does not set the default file base with the multiapp
1237  // input file name. Parent app will create the default file base for multiapp by taking the
1238  // output base of the parent app problem and appending the name of the multiapp plus a number to
1239  // it
1240  if (app->getOutputFileBase().empty())
1242  preRunInputFile();
1243  if (_app.multiAppLevel() > getParam<unsigned int>("max_multiapp_level"))
1244  mooseError("Maximum multiapp level has been reached. This is likely caused by an infinite loop "
1245  "in your multiapp system. If additional multiapp levels are needed, "
1246  "max_multiapp_level can be specified in the MuliApps block.");
1247 
1248  // Transfer coupling relaxation information to the subapps
1249  _apps[i]->fixedPointConfig().sub_relaxation_factor = getParam<Real>("relaxation_factor");
1250  _apps[i]->fixedPointConfig().sub_transformed_vars =
1251  getParam<std::vector<std::string>>("transformed_variables");
1252  // Handle deprecated parameter
1253  if (!parameters().isParamSetByAddParam("relaxed_variables"))
1254  _apps[i]->fixedPointConfig().sub_transformed_vars =
1255  getParam<std::vector<std::string>>("relaxed_variables");
1256  _apps[i]->fixedPointConfig().sub_transformed_pps =
1257  getParam<std::vector<PostprocessorName>>("transformed_postprocessors");
1258 
1259  app->runInputFile();
1260  auto fixed_point_solve = &(_apps[i]->getExecutioner()->fixedPointSolve());
1261  if (fixed_point_solve)
1262  fixed_point_solve->allocateStorage(false);
1263 
1264  // Transform the app mesh if requested
1265  if (_run_in_position)
1266  {
1267  if (usingPositions())
1268  app->getExecutioner()->feProblem().coordTransform().transformMesh(
1269  app->getExecutioner()->feProblem().mesh(), _positions[_first_local_app + i]);
1270  else
1271  app->getExecutioner()->feProblem().coordTransform().transformMesh(
1272  app->getExecutioner()->feProblem().mesh(), Point(0, 0, 0));
1273  }
1274 }
1275 
1276 std::vector<std::string>
1277 MultiApp::getCommandLineArgs(const unsigned int local_app)
1278 {
1279  const auto cla = cliArgs();
1280  auto cli_args_param = _cli_args_param;
1281  std::string combined_args;
1282 
1283  // Single set of args from cliArgs() to be provided to all apps
1284  if (cla.size() == 1)
1285  combined_args = cla[0];
1286  // Single "cli_args_files" file to be provided to all apps
1287  else if (_cli_args_from_file.size() == 1)
1288  {
1289  cli_args_param = "cli_args_files";
1290  combined_args = _cli_args_from_file[0];
1291  }
1292  // Unique set of args from cliArgs() to be provided to each app
1293  else if (cla.size())
1294  combined_args = cla[local_app + _first_local_app];
1295  // Unique set of args from "cli_args_files" to be provided to all apps
1296  else
1297  {
1298  cli_args_param = "cli_args_files";
1299  combined_args = _cli_args_from_file[local_app + _first_local_app];
1300  }
1301 
1302  // Remove all of the beginning and end whitespace so we can recognize truly empty
1303  combined_args = MooseUtils::trim(combined_args);
1304 
1305  // MooseUtils::split will return a single empty entry if there is nothing,
1306  // so exit early if we have nothing
1307  if (combined_args.empty())
1308  return {};
1309 
1310  // Split the argument into a vector of arguments, and make sure
1311  // that we don't have any empty arguments
1312  const auto args = MooseUtils::split(combined_args, ";");
1313  for (const auto & arg : args)
1314  {
1315  if (arg.empty())
1316  {
1317  const auto error = "An empty MultiApp command line argument was provided. Your "
1318  "combined command line string has a ';' with no argument after it.";
1319  if (cli_args_param)
1320  paramError(*cli_args_param, error);
1321  else
1322  mooseError(error);
1323  }
1324  }
1325 
1326  return args;
1327 }
1328 
1331  processor_id_type nprocs,
1332  dof_id_type napps,
1333  processor_id_type min_app_procs,
1334  processor_id_type max_app_procs,
1335  bool batch_mode)
1336 {
1337  if (min_app_procs > nprocs)
1338  mooseError("minimum number of procs per app is higher than the available number of procs");
1339  else if (min_app_procs > max_app_procs)
1340  mooseError("minimum number of procs per app must be lower than the max procs per app");
1341 
1342  mooseAssert(rank < nprocs, "rank must be smaller than the number of procs");
1343 
1344  // A "slot" is a group of procs/ranks that are grouped together to run a
1345  // single (sub)app/sim in parallel.
1346 
1347  const processor_id_type slot_size =
1348  std::max(std::min(cast_int<processor_id_type>(nprocs / napps), max_app_procs), min_app_procs);
1349  const processor_id_type nslots = std::min(
1350  nprocs / slot_size,
1351  cast_int<processor_id_type>(std::min(
1352  static_cast<dof_id_type>(std::numeric_limits<processor_id_type>::max()), napps)));
1353  mooseAssert(nprocs >= (nslots * slot_size),
1354  "Ensure that leftover procs is represented by an unsigned type");
1355  const processor_id_type leftover_procs = nprocs - nslots * slot_size;
1356  const dof_id_type apps_per_slot = napps / nslots;
1357  const dof_id_type leftover_apps = napps % nslots;
1358 
1359  std::vector<int> slot_for_rank(nprocs);
1360  processor_id_type slot = 0;
1361  processor_id_type procs_in_slot = 0;
1362  for (processor_id_type rankiter = 0; rankiter <= rank; rankiter++)
1363  {
1364  if (slot < nslots)
1365  slot_for_rank[rankiter] = cast_int<int>(slot);
1366  else
1367  slot_for_rank[rankiter] = -1;
1368  procs_in_slot++;
1369  // this slot keeps growing until we reach slot size plus possibly an extra
1370  // proc if there were any leftover from the slotization of nprocs - this
1371  // must also make sure we don't go over max app procs.
1372  if (procs_in_slot == slot_size + 1 * (slot < leftover_procs && slot_size < max_app_procs))
1373  {
1374  procs_in_slot = 0;
1375  slot++;
1376  }
1377  }
1378 
1379  if (slot_for_rank[rank] < 0)
1380  // ranks assigned a negative slot don't have any apps running on them.
1381  return {0, 0, 0, 0, false, 0};
1382  const processor_id_type slot_num = cast_int<processor_id_type>(slot_for_rank[rank]);
1383 
1384  const bool is_first_local_rank = rank == 0 || (slot_for_rank[rank - 1] != slot_for_rank[rank]);
1385  const dof_id_type n_local_apps = apps_per_slot + 1 * (slot_num < leftover_apps);
1386 
1387  processor_id_type my_first_rank = 0;
1388  for (processor_id_type rankiter = rank; rankiter > 0; rankiter--)
1389  if (slot_for_rank[rank] != slot_for_rank[rankiter])
1390  {
1391  my_first_rank = cast_int<processor_id_type>(slot_for_rank[rankiter + 1]);
1392  break;
1393  }
1394 
1395  dof_id_type app_index = 0;
1396  for (processor_id_type slot = 0; slot < slot_num; slot++)
1397  {
1398  const dof_id_type num_slot_apps = apps_per_slot + 1 * (slot < leftover_apps);
1399  app_index += num_slot_apps;
1400  }
1401 
1402  if (batch_mode)
1403  return {n_local_apps, app_index, 1, slot_num, is_first_local_rank, my_first_rank};
1404  return {n_local_apps, app_index, n_local_apps, app_index, is_first_local_rank, my_first_rank};
1405 }
1406 
1407 void
1409 {
1410  int ierr;
1411 
1412  ierr = MPI_Comm_size(_communicator.get(), &_orig_num_procs);
1413  mooseCheckMPIErr(ierr);
1414  ierr = MPI_Comm_rank(_communicator.get(), &_orig_rank);
1415  mooseCheckMPIErr(ierr);
1416 
1417 #ifdef LIBMESH_HAVE_SYS_UTSNAME_H
1418  struct utsname sysInfo;
1419  uname(&sysInfo);
1420  _node_name = sysInfo.nodename;
1421 #else
1422  _node_name = "Unknown";
1423 #endif
1424 
1425  int rank;
1426  ierr = MPI_Comm_rank(_communicator.get(), &rank);
1427  mooseCheckMPIErr(ierr);
1428 
1431 
1434  mooseError("Internal error, a processor has an undefined app.");
1435 
1436  if (_has_an_app)
1437  {
1439  ierr = MPI_Comm_rank(_my_comm, &_my_rank);
1440  mooseCheckMPIErr(ierr);
1441  }
1442  else
1443  {
1444  _communicator.split(MPI_UNDEFINED, rank, _my_communicator);
1445  _my_rank = 0;
1446  }
1447 }
1448 
1449 unsigned int
1450 MultiApp::globalAppToLocal(unsigned int global_app)
1451 {
1452  if (global_app >= _first_local_app && global_app <= _first_local_app + (_my_num_apps - 1))
1453  return global_app - _first_local_app;
1454 
1455  std::stringstream ss;
1456  ss << "Requesting app " << global_app << ", but processor " << processor_id() << " ";
1457  if (_my_num_apps == 0)
1458  ss << "does not own any apps";
1459  else if (_my_num_apps == 1)
1460  ss << "owns app " << _first_local_app;
1461  else
1462  ss << "owns apps " << _first_local_app << "-" << _first_local_app + (_my_num_apps - 1);
1463  ss << ".";
1464  mooseError("Invalid global_app!\n", ss.str());
1465  return 0;
1466 }
1467 
1468 void
1470 {
1471 }
1472 
1473 void
1475 {
1476  _associated_transfers.push_back(&transfer);
1477 }
1478 
1479 void
1481 {
1482  for (unsigned int i = 0; i < _my_num_apps; ++i)
1484 }
1485 
1486 std::vector<std::string>
1488 {
1489  // So that we can error out with paramError("cli_args", ...);
1490  _cli_args_param = "cli_args";
1491  return std::vector<std::string>(_cli_args.begin(), _cli_args.end());
1492 }
1493 
1494 void
1496 {
1497  const std::string multiapp_name =
1499  _apps[index]->setOutputFileBase(_app.getOutputFileBase() + "_" + multiapp_name);
1500 }
1501 
1502 std::string
1503 MultiApp::getMultiAppName(const std::string & base_name, dof_id_type index, dof_id_type total)
1504 {
1505  std::ostringstream multiapp_name;
1506  multiapp_name << base_name << std::setw(std::ceil(std::log10(total))) << std::setprecision(0)
1507  << std::setfill('0') << std::right << index;
1508  return multiapp_name.str();
1509 }
1510 
1511 const Point &
1512 MultiApp::position(unsigned int app) const
1513 {
1514  // If we're not using positions, it won't have changed
1515  if (_positions_objs.empty())
1516  return _positions[app];
1517  else
1518  // Find which Positions object is specifying it, and query a potentially updated value
1519  return _positions_objs[app]->getPosition(app - _positions_index_offsets[app], false);
1520 }
1521 
1522 void
1523 dataStore(std::ostream & stream, SubAppBackups & backups, void * context)
1524 {
1525  MultiApp * multi_app = static_cast<MultiApp *>(context);
1526  mooseAssert(multi_app, "Not set");
1527 
1528  multi_app->backup();
1529 
1530  dataStore(stream, static_cast<std::vector<std::unique_ptr<Backup>> &>(backups), nullptr);
1531 }
1532 
1533 void
1534 dataLoad(std::istream & stream, SubAppBackups & backups, void * context)
1535 {
1536  MultiApp * multi_app = static_cast<MultiApp *>(context);
1537  mooseAssert(multi_app, "Not set");
1538 
1539  dataLoad(stream, static_cast<std::vector<std::unique_ptr<Backup>> &>(backups), nullptr);
1540 
1541  multi_app->restore();
1542 }
bool isRegistered(const std::string &app_name) const
Returns a Boolean indicating whether an application type has been registered.
Definition: AppFactory.h:169
void keepSolutionDuringRestore(bool keep_solution_during_restore)
Preserve the solution from the previous simulation, and it is used as an initial guess for the next r...
Definition: MultiApp.C:891
bool hasLocalApp(unsigned int global_app) const
Whether or not the given global app number is on this processor.
Definition: MultiApp.C:1069
std::vector< unsigned int > _reset_apps
The apps to be reset.
Definition: MultiApp.h:571
const std::set< std::string > & getMFEMDevices(Moose::PassKey< MultiApp >) const
Get the configured MFEM devices.
Definition: MooseApp.h:1691
bool needsRestoration()
Whether or not this MultiApp should be restored at the beginning of each Picard iteration.
Definition: MultiApp.h:210
virtual libMesh::System & getSystem(const std::string &var_name) override
Returns the equation system containing the variable provided.
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
A class for creating restricted objects.
Definition: Restartable.h:28
MultiApp(const InputParameters &parameters)
Definition: MultiApp.C:271
std::vector< libMesh::BoundingBox > _bounding_box
This multi-app&#39;s bounding box.
Definition: MultiApp.h:547
const InputParameters & _pars
The object&#39;s parameters.
Definition: MooseBase.h:366
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
std::vector< const Positions * > _positions_objs
The positions of all of the apps, using the Positions system.
Definition: MultiApp.h:490
std::shared_ptr< DisplacedProblem > displaced_problem
const unsigned int invalid_uint
const std::string & _name
The name of this class.
Definition: MooseBase.h:363
virtual void restore(bool force=true)
Restore the state of every Sub App.
Definition: MultiApp.C:773
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:439
virtual void backup()
Save off the state of every Sub App.
Definition: MultiApp.C:758
bool verboseMultiApps() const
Whether or not to use verbose printing for MultiApps.
NumericVector< Number > & solution()
Definition: SystemBase.h:196
const bool _use_positions
Toggle use of "positions".
Definition: MultiApp.h:496
void setDocString(const std::string &name, const std::string &doc)
Set the doc string of a parameter.
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...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition: FEProblem.h:20
const std::vector< CLIArgString > & _cli_args
CommandLine arguments (controllable!)
Definition: MultiApp.h:592
std::vector< unsigned int > _npositions_inputfile
Number of positions for each input file.
Definition: MultiApp.h:505
void dataLoad(std::istream &stream, SubAppBackups &backups, void *context)
Definition: MultiApp.C:1534
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
void setupPositions()
Called just after construction to allow derived classes to set _positions and create sub-apps accordi...
Definition: MultiApp.C:375
std::shared_ptr< CommandLine > commandLine() const
Get the command line.
Definition: MooseApp.h:418
std::vector< unsigned int > _positions_index_offsets
The offsets, in case multiple Positions objects are specified.
Definition: MultiApp.h:492
const std::vector< Point > getDataAsPoints() const
Get the data in Point format.
Real _move_time
The time at which to move apps.
Definition: MultiApp.h:577
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
Real appPostprocessorValue(unsigned int app, const std::string &name)
Get a Postprocessor value for a specified global app.
Definition: MultiApp.C:1048
int _orig_rank
The mpi "rank" of this processor in the original communicator.
Definition: MultiApp.h:532
LocalRankConfig _rank_config
The app configuration resulting from calling init.
Definition: MultiApp.h:614
std::optional< std::string > _cli_args_param
The parameter that was used to set the command line args, if any.
Definition: MultiApp.h:634
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
std::string getOutputFileBase(bool for_non_moose_build_output=false) const
Get the output file base name.
Definition: MooseApp.C:1737
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1135
std::vector< std::shared_ptr< MooseApp > > _apps
Pointers to each of the Apps.
Definition: MultiApp.h:541
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
dof_id_type first_local_app_index
The (global) index of the first local app for this rank.
Definition: MultiApp.h:64
FEProblemBase & feProblem()
Return a reference to this Executioner&#39;s FEProblemBase instance.
Definition: Executioner.C:124
unsigned int multiAppLevel() const
The MultiApp Level.
Definition: MooseApp.h:809
virtual void parentOutputPositionChanged()
For apps outputting in position we need to change their output positions if their parent app moves...
Definition: MultiApp.C:1126
MeshBase & mesh
std::vector< Point > _move_positions
The new positions for the apps to be moved.
Definition: MultiApp.h:583
Base class for MOOSE-based applications.
Definition: MooseApp.h:103
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void dataStore(std::ostream &stream, SubAppBackups &backups, void *context)
Definition: MultiApp.C:1523
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:162
void addAvailableFlags(const ExecFlagType &flag, Args... flags)
Add additional execute_on flags to the list of possible flags.
Definition: ExecFlagEnum.h:82
const PerfID _restore_timer
Definition: MultiApp.h:629
virtual std::unique_ptr< NumericVector< Number > > clone() const =0
const Parallel::Communicator & _communicator
Real _inflation
Relative bounding box inflation.
Definition: MultiApp.h:550
FEProblemBase & _fe_problem
The FEProblemBase this MultiApp is part of.
Definition: MultiApp.h:482
bool isRestarting() const
Whether or not this is a "restart" calculation.
Definition: MooseApp.C:1880
const Positions & getPositionsObject(const std::string &name) const
Get the Positions object by its name.
virtual std::vector< std::string > getCommandLineArgs(const unsigned int local_app)
Definition: MultiApp.C:1277
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
processor_id_type _min_procs_per_app
Minimum number of processors to give to each app.
Definition: MultiApp.h:559
int _orig_num_procs
The number of processors in the original comm.
Definition: MultiApp.h:529
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition: MooseBase.h:87
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
const PerfID _backup_timer
Definition: MultiApp.h:628
auto max(const L &left, const R &right)
std::vector< std::string > split(const std::string &str, const std::string &delimiter, std::size_t max_count=std::numeric_limits< std::size_t >::max())
Python like split functions for strings.
Definition: MooseUtils.C:1031
std::vector< Real > _reset_times
The times at which to reset apps.
Definition: MultiApp.h:568
virtual void preTransfer(Real dt, Real target_time)
Gets called just before transfers are done to the MultiApp (Which is just before the MultiApp is solv...
Definition: MultiApp.C:656
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
void createApps()
Create the provided number of apps.
Definition: MultiApp.C:386
static std::unique_ptr< MooseApp > create(const std::string &app_type, const std::vector< std::string > &cli_args={})
Create an app with no input and command line arguments.
Definition: AppFactory.C:62
virtual libMesh::BoundingBox getBoundingBox(unsigned int app, bool displaced_mesh, const MultiAppCoordTransform *coord_transform=nullptr)
Get the BoundingBox for the mesh associated with app The bounding box will be shifted to be in the co...
Definition: MultiApp.C:941
uint8_t processor_id_type
void mooseWarning(Args &&... args) const
bool isParamSetByAddParam(const std::string &name) const
Returns whether or not the parameter was set due to addParam.
processor_id_type n_processors() const
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
const bool & _wait_for_first_app_init
Whether to create the first app on rank 0 while all other MPI ranks are idle.
Definition: MultiApp.h:502
const auto & registeredObjects() const
Returns a reference to the map from names to AppFactoryBuildInfo pointers.
Definition: AppFactory.h:164
static void transformBoundingBox(libMesh::BoundingBox &box, const MultiAppCoordTransform &transform)
Transform a bounding box according to the transformations in the provided coordinate transformation o...
Definition: MultiApp.C:901
virtual libMesh::NumericVector< libMesh::Number > & appTransferVector(unsigned int app, std::string var_name)
Get the vector to transfer to for this MultiApp.
Definition: MultiApp.C:1057
bool _keep_solution_during_restore
Flag indicates if or not restart from the latest solution.
Definition: MultiApp.h:598
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
std::map< std::string, unsigned int > getFileNumbers()
Extracts the file numbers from the output objects.
processor_id_type _max_procs_per_app
Maximum number of processors to give to each app.
Definition: MultiApp.h:556
virtual std::vector< std::string > cliArgs() const
function that provides cli_args to subapps
Definition: MultiApp.C:1487
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition: Moose.C:37
virtual void fillPositions()
must fill in _positions with the positions of the sub-aps
Definition: MultiApp.C:543
const ExecFlagType EXEC_PRE_MULTIAPP_SETUP
Definition: Moose.C:54
bool _move_happened
Whether or not the move has happened.
Definition: MultiApp.h:586
std::vector< MultiAppTransfer * > _associated_transfers
Transfers associated with this multiapp.
Definition: MultiApp.h:617
Helper class for holding Sub-app backups.
Definition: MultiApp.h:100
const PerfID _reset_timer
Definition: MultiApp.h:630
bool checkFileReadable(const std::string &filename, bool check_line_endings=false, bool throw_on_unreadable=true, bool check_for_git_lfs_pointer=true)
Checks to see if a file is readable (exists and permissions)
Definition: MooseUtils.C:254
std::string trim(const std::string &str, const std::string &white_space=" \\\)
Standard scripting language trim function.
std::vector< std::unique_ptr< NumericVector< Real > > > _end_aux_solutions
The auxiliary solution from the end of the previous solve, this is cloned from the auxiliary solution...
Definition: MultiApp.h:611
std::string _app_type
The type of application to build.
Definition: MultiApp.h:485
std::unique_ptr< NumericVector< Number > > solution
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:92
void split(int color, int key, Communicator &target) const
void mooseDeprecated(Args &&... args) const
FEProblemBase & appProblemBase(unsigned int app)
Get the FEProblemBase for the global app desired.
Definition: MultiApp.C:1015
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
PetscErrorCode PetscInt const PetscInt IS * is
std::vector< unsigned int > _move_apps
The apps to be moved.
Definition: MultiApp.h:580
Executioners are objects that do the actual work of solving your problem.
Definition: Executioner.h:30
Base class for transient executioners that use a FixedPointSolve solve object for multiapp-main app i...
Definition: TransientBase.h:27
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:357
void read()
Perform the actual data reading.
const std::vector< Point > & getPositions(bool initial) const
{ Getters for the positions vector for the desired dimension 1D will be the only one guaranteed to su...
Definition: Positions.C:116
void buildComm()
Create an MPI communicator suitable for each app.
Definition: MultiApp.C:1408
virtual void resetApp(unsigned int global_app, Real time=0.0)
"Reset" the App corresponding to the global App number passed in.
Definition: MultiApp.C:1086
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:64
AuxiliarySystem & getAuxiliarySystem()
static InputParameters validParams()
bool isFirstLocalRank() const
Definition: MultiApp.C:1063
Interface for objects interacting with the PerfGraph.
const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name, std::size_t t_index=0) const
Get a read-only reference to the value associated with a Postprocessor that exists.
unsigned int _total_num_apps
The total number of apps to simulate.
Definition: MultiApp.h:511
void skipCoordinateCollapsing(bool skip_coordinate_collapsing)
set whether coordinate collapsing operations should be skipped
LocalRankConfig rankConfig(processor_id_type rank, processor_id_type nprocs, dof_id_type napps, processor_id_type min_app_procs, processor_id_type max_app_procs, bool batch_mode)
Returns app partitioning information relevant to the given rank for a multiapp scenario with the give...
Definition: MultiApp.C:1330
Executioner * getExecutioner() const
Retrieve the Executioner for this App.
Definition: MooseApp.C:2196
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
Point getOutputPosition() const
Get the output position.
Definition: MooseApp.h:282
unsigned int _my_num_apps
The number of apps this object is involved in simulating.
Definition: MultiApp.h:514
static std::string getMultiAppName(const std::string &base_name, dof_id_type index, dof_id_type total)
Helper for constructing the name of the multiapp.
Definition: MultiApp.C:1503
std::string _node_name
Node Name.
Definition: MultiApp.h:535
static AppFactory & instance()
Get the instance of the AppFactory.
Definition: AppFactory.C:18
bool _has_an_app
Whether or not this processor as an App at all
Definition: MultiApp.h:589
libMesh::Parallel::Communicator _my_communicator
The communicator object that holds the MPI_Comm that we&#39;re going to use.
Definition: MultiApp.h:523
void createApp(unsigned int i, Real start_time)
Helper function for creating an App instance.
Definition: MultiApp.C:1134
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was set by the user.
bool usingPositions() const
Whether or not this MultiApp is using positions or its own way for constructing sub-apps.
Definition: MultiApp.h:363
const PerfID _init_timer
Definition: MultiApp.h:627
unsigned int _first_local_app
The number of the first app on this processor.
Definition: MultiApp.h:517
void addAssociatedTransfer(MultiAppTransfer &transfer)
Add a transfer that is associated with this multiapp.
Definition: MultiApp.C:1474
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual std::shared_ptr< const DisplacedProblem > getDisplacedProblem() const
MooseApp * localApp(unsigned int local_app)
Get the local MooseApp object.
Definition: MultiApp.C:1079
virtual void initialSetup() override
Method to be called in main-app initial setup for create sub-apps if using positions is false...
Definition: MultiApp.C:436
Utility class for reading delimited data (e.g., CSV data).
std::vector< std::vector< std::unique_ptr< libMesh::NumericVector< Real > > > > _end_solutions
The solution from the end of the previous solve, this is cloned from the Nonlinear solution during re...
Definition: MultiApp.h:608
Base class for all MultiAppTransfer objects.
bool is_first_local_rank
This is true if this rank is the primary/zero rank for a (sub)app slot.
Definition: MultiApp.h:71
FEProblem & appProblem(unsigned int app)
Get the FEProblem for the global app is part of.
Definition: MultiApp.C:1026
IntRange< T > make_range(T beg, T end)
SubAppBackups & _sub_app_backups
The cached subapp backups (passed from the parent app)
Definition: MultiApp.h:623
virtual MooseMesh & mesh() override
virtual void postExecute()
Method called at the end of the simulation (after finalize).
Definition: MultiApp.C:746
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:271
bool _keep_aux_solution_during_restore
Flag indicates if or not restart the auxiliary system from the latest auxiliary solution.
Definition: MultiApp.h:601
bool _output_in_position
Whether or not to move the output of the MultiApp into position.
Definition: MultiApp.h:562
std::vector< Point > _positions
The positions of all of the apps, using input constant vectors (to be deprecated) ...
Definition: MultiApp.h:488
virtual void finalize()
Method called towards the end of the simulation to execute on final.
Definition: MultiApp.C:733
void readCommandLineArguments()
Fill command line arguments for sub apps.
Definition: MultiApp.C:445
int _my_rank
The mpi "rank" of this processor in the sub communicator.
Definition: MultiApp.h:538
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
Moose::CoordinateSystemType getCoordSystem(SubdomainID sid) const
Definition: SubProblem.C:1283
dof_id_type num_local_apps
The number of (sub)apps that should/will be run locally on this rank.
Definition: MultiApp.h:58
virtual void createLocalApp(const unsigned int i)
Create the i-th local app.
Definition: MultiApp.C:430
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
std::vector< FileName > _input_files
The input file for each app&#39;s simulation.
Definition: MultiApp.h:499
Holds app partitioning information relevant to the a particular rank for a multiapp scenario...
Definition: MultiApp.h:46
virtual void preRunInputFile()
call back executed right before app->runInputFile()
Definition: MultiApp.C:1469
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseBase.h:199
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
InputParameters getValidParams(const std::string &name)
Get valid parameters for the object.
Definition: AppFactory.C:33
const UserObject & getUserObjectBase(const std::string &name, const THREAD_ID tid=0) const
Get the user object by its name.
Point _bounding_box_padding
Additional padding added to the bounding box, useful for 1D meshes.
Definition: MultiApp.h:553
const Real _global_time_offset
The offset time so the MultiApp local time relative to the global time.
Definition: MultiApp.h:565
void init(unsigned int num_apps, bool batch_mode=false)
Build communicators and reserve backups.
Definition: MultiApp.C:338
static InputParameters validParams()
Definition: MooseObject.C:25
const MPI_Comm & _orig_comm
The original comm handle.
Definition: MultiApp.h:520
static InputParameters validParams()
Definition: MultiApp.C:50
A MultiApp represents one or more MOOSE applications that are running simultaneously.
Definition: MultiApp.h:112
processor_id_type processor_id() const
void setAppOutputFileBase()
Sets all the app&#39;s output file bases.
Definition: MultiApp.C:1480
bool isRecovering() const
Whether or not this is a "recover" calculation.
Definition: MooseApp.C:1874
auto min(const L &left, const R &right)
std::shared_ptr< mfem::Device > getMFEMDevice(Moose::PassKey< MultiApp >)
Get the MFEM device object.
Definition: MooseApp.h:1086
MPI_Comm & _my_comm
The MPI communicator this object is going to use.
Definition: MultiApp.h:526
const ExecFlagType EXEC_FINAL
Definition: Moose.C:46
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
Declare the given parameters as controllable.
const bool _run_in_position
Whether to run the child apps with their meshes transformed with the coordinate transforms.
Definition: MultiApp.h:620
virtual void moveApp(unsigned int global_app, Point p)
Move the global_app to Point p.
Definition: MultiApp.C:1107
void ErrorVector unsigned int
virtual Executioner * getExecutioner(unsigned int app)
Definition: MultiApp.C:724
auto index_range(const T &sizable)
Base class for user-specific data.
Definition: UserObject.h:40
const Point & position(unsigned int app) const
The physical position of a global App number.
Definition: MultiApp.C:1512
OutputWarehouse & getOutputWarehouse()
Get the OutputWarehouse objects.
Definition: MooseApp.C:2515
std::vector< std::string > _cli_args_from_file
CommandLine arguments from files.
Definition: MultiApp.h:595
const UserObject & appUserObjectBase(unsigned int app, const std::string &name)
Get a UserObject base for a specific global app.
Definition: MultiApp.C:1039
const ExecFlagType EXEC_POST_ADAPTIVITY
Definition: Moose.C:58
uint8_t dof_id_type
unsigned int globalAppToLocal(unsigned int global_app)
Map a global App number to the local number.
Definition: MultiApp.C:1450
This class contains transformation information that only exists in a context in which there are multi...
void dynamicAppRegistration(const std::string &app_name, std::string library_path, const std::string &library_name, bool lib_load_deps)
Definition: MooseApp.C:2687
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
std::vector< bool > _reset_happened
Whether or not apps have been reset at each time.
Definition: MultiApp.h:574
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:30
std::vector< bool > _has_bounding_box
Flag if this multi-app computed its bounding box (valid only for non-displaced meshes) ...
Definition: MultiApp.h:544