forked from idaholab/moose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MooseApp.C
2434 lines (2084 loc) · 82.8 KB
/
MooseApp.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html
#ifdef HAVE_GPERFTOOLS
#include "gperftools/profiler.h"
#include "gperftools/heap-profiler.h"
#endif
// MOOSE includes
#include "MooseRevision.h"
#include "AppFactory.h"
#include "DisplacedProblem.h"
#include "NonlinearSystemBase.h"
#include "AuxiliarySystem.h"
#include "MooseSyntax.h"
#include "MooseInit.h"
#include "Executioner.h"
#include "PetscSupport.h"
#include "Conversion.h"
#include "CommandLine.h"
#include "InfixIterator.h"
#include "MultiApp.h"
#include "MeshGenerator.h"
#include "DependencyResolver.h"
#include "MooseUtils.h"
#include "MooseObjectAction.h"
#include "InputParameterWarehouse.h"
#include "SystemInfo.h"
#include "RestartableDataIO.h"
#include "MooseMesh.h"
#include "FileOutput.h"
#include "ConsoleUtils.h"
#include "JsonSyntaxTree.h"
#include "JsonInputFileFormatter.h"
#include "SONDefinitionFormatter.h"
#include "RelationshipManager.h"
#include "ProxyRelationshipManager.h"
#include "Registry.h"
#include "SerializerGuard.h"
#include "PerfGraphInterface.h" // For TIME_SECTION
#include "Attributes.h"
#include "MooseApp.h"
#include "CommonOutputAction.h"
// Regular expression includes
#include "pcrecpp.h"
#include "libmesh/exodusII_io.h"
#include "libmesh/mesh_refinement.h"
#include "libmesh/string_to_enum.h"
#include "libmesh/checkpoint_io.h"
#include "libmesh/mesh_base.h"
// System include for dynamic library methods
#ifdef LIBMESH_HAVE_DLOPEN
#include <dlfcn.h>
#include <sys/utsname.h> // utsname
#endif
// C++ includes
#include <numeric> // std::accumulate
#include <fstream>
#include <sys/types.h>
#include <unistd.h>
#include <cstdlib> // for system()
#include <chrono>
#include <thread>
#define QUOTE(macro) stringifyName(macro)
defineLegacyParams(MooseApp);
InputParameters
MooseApp::validParams()
{
InputParameters params = emptyInputParameters();
params.addCommandLineParam<bool>(
"display_version", "-v --version", false, "Print application version");
params.addCommandLineParam<std::vector<std::string>>(
"input_file",
"-i <input_files>",
"Specify one or multiple input files. Multiple files get merged into a single simulation "
"input.");
params.addCommandLineParam<std::string>(
"mesh_only",
"--mesh-only [mesh_file_name]",
"Setup and Output the input mesh only (Default: \"<input_file_name>_in.e\")");
params.addCommandLineParam<bool>("show_input",
"--show-input",
false,
"Shows the parsed input file before running the simulation.");
params.addCommandLineParam<bool>(
"show_outputs", "--show-outputs", false, "Shows the output execution time information.");
params.addCommandLineParam<bool>(
"show_controls", "--show-controls", false, "Shows the Control logic available and executed.");
params.addCommandLineParam<bool>(
"no_color", "--no-color", false, "Disable coloring of all Console outputs.");
params.addCommandLineParam<std::string>("color",
"--color [auto,on,off]",
"default-on",
"Whether to use color in console output (default 'on').");
params.addCommandLineParam<bool>("help", "-h --help", false, "Displays CLI usage statement.");
params.addCommandLineParam<bool>(
"minimal",
"--minimal",
false,
"Ignore input file and build a minimal application with Transient executioner.");
params.addCommandLineParam<std::string>(
"definition", "--definition", "Shows a SON style input definition dump for input validation");
params.addCommandLineParam<std::string>(
"dump", "--dump [search_string]", "Shows a dump of available input file syntax.");
params.addCommandLineParam<bool>(
"registry", "--registry", "Lists all known objects and actions.");
params.addCommandLineParam<bool>(
"registry_hit", "--registry-hit", "Lists all known objects and actions in hit format.");
params.addCommandLineParam<bool>(
"apptype", "--type", false, "Return the name of the application object.");
params.addCommandLineParam<std::string>(
"yaml", "--yaml", "Dumps input file syntax in YAML format.");
params.addCommandLineParam<std::string>(
"json", "--json", "Dumps input file syntax in JSON format.");
params.addCommandLineParam<bool>(
"syntax", "--syntax", false, "Dumps the associated Action syntax paths ONLY");
params.addCommandLineParam<bool>("run_tests", "--tests", false, "run all tests");
params.addCommandLineParam<bool>(
"copy_tests", "--copy-tests", false, "copy installed tests to an [appname]_tests dir");
params.addCommandLineParam<bool>(
"show_docs", "--docs", false, "print url/path to the documentation website");
params.addCommandLineParam<bool>("check_input",
"--check-input",
false,
"Check the input file (i.e. requires -i <filename>) and quit.");
params.addCommandLineParam<bool>(
"list_constructed_objects",
"--list-constructed-objects",
false,
"List all moose object type names constructed by the master app factory.");
params.addCommandLineParam<unsigned int>(
"n_threads", "--n-threads=<n>", 1, "Runs the specified number of threads per process");
params.addCommandLineParam<bool>(
"warn_unused", "-w --warn-unused", false, "Warn about unused input file options");
params.addCommandLineParam<bool>("error_unused",
"-e --error-unused",
false,
"Error when encountering unused input file options");
params.addCommandLineParam<bool>(
"error_override",
"-o --error-override",
false,
"Error when encountering overridden or parameters supplied multiple times");
params.addCommandLineParam<bool>(
"error_deprecated", "--error-deprecated", false, "Turn deprecated code messages into Errors");
params.addCommandLineParam<bool>(
"distributed_mesh",
"--distributed-mesh",
false,
"The libMesh Mesh underlying MooseMesh should always be a DistributedMesh");
params.addCommandLineParam<std::string>(
"split_mesh",
"--split-mesh [splits]",
"comma-separated list of numbers of chunks to split the mesh into");
params.addCommandLineParam<std::string>("split_file",
"--split-file [filename]",
"",
"optional name of split mesh file(s) to write/read");
params.addCommandLineParam<bool>(
"use_split", "--use-split", false, "use split distributed mesh files");
params.addCommandLineParam<unsigned int>(
"refinements",
"-r <n>",
0,
"Specify additional initial uniform refinements for automatic scaling");
params.addCommandLineParam<std::string>("recover",
"--recover [file_base]",
"Continue the calculation. If file_base is omitted then "
"the most recent recovery file will be utilized");
params.addCommandLineParam<std::string>("recoversuffix",
"--recoversuffix [suffix]",
"Use a different file extension, other than cpr, "
"for a recovery file");
params.addCommandLineParam<bool>("half_transient",
"--half-transient",
false,
"When true the simulation will only run half of "
"its specified transient (ie half the "
"timesteps). This is useful for testing "
"recovery and restart");
// No default on these two options, they must not both be valid
params.addCommandLineParam<bool>(
"trap_fpe",
"--trap-fpe",
"Enable Floating Point Exception handling in critical sections of "
"code. This is enabled automatically in DEBUG mode");
params.addCommandLineParam<bool>("no_trap_fpe",
"--no-trap-fpe",
"Disable Floating Point Exception handling in critical "
"sections of code when using DEBUG mode.");
params.addCommandLineParam<bool>("error", "--error", false, "Turn all warnings into errors");
params.addCommandLineParam<bool>(
"timing",
"-t --timing",
false,
"Enable all performance logging for timing purposes. This will disable all "
"screen output of performance logs for all Console objects.");
params.addCommandLineParam<bool>("no_timing",
"--no-timing",
false,
"Disabled performance logging. Overrides -t or --timing "
"if passed in conjunction with this flag");
params.addCommandLineParam<bool>(
"allow_test_objects", "--allow-test-objects", false, "Register test objects and syntax.");
// Options ignored by MOOSE but picked up by libMesh, these are here so that they are displayed in
// the application help
params.addCommandLineParam<bool>(
"keep_cout",
"--keep-cout",
false,
"Keep standard output from all processors when running in parallel");
params.addCommandLineParam<bool>(
"redirect_stdout",
"--redirect-stdout",
false,
"Keep standard output from all processors when running in parallel");
// Options for debugging
params.addCommandLineParam<std::string>("start_in_debugger",
"--start-in-debugger <debugger>",
"Start the application and attach a debugger. This will "
"launch xterm windows using the command you specify for "
"'debugger'");
params.addCommandLineParam<unsigned int>("stop_for_debugger",
"--stop-for-debugger [seconds]",
30,
"Pauses the application during startup for the "
"specified time to allow for connection of debuggers.");
params.addParam<bool>(
"automatic_automatic_scaling", false, "Whether to turn on automatic scaling by default.");
#ifdef HAVE_GPERFTOOLS
params.addCommandLineParam<std::string>(
"gperf_profiler_on",
"--gperf-profiler-on [ranks]",
"To generate profiling report only on comma-separated list of MPI ranks.");
#endif
params.addPrivateParam<std::string>("_app_name"); // the name passed to AppFactory::create
params.addPrivateParam<std::string>("_type");
params.addPrivateParam<int>("_argc");
params.addPrivateParam<char **>("_argv");
params.addPrivateParam<std::shared_ptr<CommandLine>>("_command_line");
params.addPrivateParam<std::shared_ptr<Parallel::Communicator>>("_comm");
params.addPrivateParam<unsigned int>("_multiapp_level");
params.addPrivateParam<unsigned int>("_multiapp_number");
params.addPrivateParam<const MooseMesh *>("_master_mesh");
params.addPrivateParam<const MooseMesh *>("_master_displaced_mesh");
params.addParam<bool>(
"use_legacy_material_output",
true,
"Set false to allow material properties to be output on INITIAL, not just TIMESTEP_END.");
return params;
}
MooseApp::MooseApp(InputParameters parameters)
: ConsoleStreamInterface(*this),
ParallelObject(*parameters.get<std::shared_ptr<Parallel::Communicator>>(
"_comm")), // Can't call getParam() before pars is set
_name(parameters.get<std::string>("_app_name")),
_pars(parameters),
_type(getParam<std::string>("_type")),
_comm(getParam<std::shared_ptr<Parallel::Communicator>>("_comm")),
_perf_graph(type() + " (" + name() + ')'),
_rank_map(*_comm, _perf_graph),
_file_base_set_by_user(false),
_output_position_set(false),
_start_time_set(false),
_start_time(0.0),
_global_time_offset(0.0),
_output_warehouse(*this),
_input_parameter_warehouse(new InputParameterWarehouse()),
_action_factory(*this),
_action_warehouse(*this, _syntax, _action_factory),
_parser(*this, _action_warehouse),
_use_nonlinear(true),
_use_eigen_value(false),
_enable_unused_check(WARN_UNUSED),
_factory(*this),
_error_overridden(false),
_ready_to_exit(false),
_initial_from_file(false),
_distributed_mesh_on_command_line(false),
_recover(false),
_restart(false),
_split_mesh(false),
_use_split(parameters.get<bool>("use_split")),
#ifdef DEBUG
_trap_fpe(true),
#else
_trap_fpe(false),
#endif
_restart_recover_suffix("cpr"),
_half_transient(false),
_check_input(getParam<bool>("check_input")),
_restartable_data(libMesh::n_threads()),
_multiapp_level(
isParamValid("_multiapp_level") ? parameters.get<unsigned int>("_multiapp_level") : 0),
_multiapp_number(
isParamValid("_multiapp_number") ? parameters.get<unsigned int>("_multiapp_number") : 0),
_master_mesh(isParamValid("_master_mesh") ? parameters.get<const MooseMesh *>("_master_mesh")
: nullptr),
_master_displaced_mesh(isParamValid("_master_displaced_mesh")
? parameters.get<const MooseMesh *>("_master_displaced_mesh")
: nullptr),
_setup_timer(_perf_graph.registerSection("MooseApp::setup", 2)),
_setup_options_timer(_perf_graph.registerSection("MooseApp::setupOptions", 5)),
_run_input_file_timer(_perf_graph.registerSection("MooseApp::runInputFile", 3)),
_execute_timer(_perf_graph.registerSection("MooseApp::execute", 2)),
_execute_executioner_timer(_perf_graph.registerSection("MooseApp::executeExecutioner", 3)),
_restore_timer(_perf_graph.registerSection("MooseApp::restore", 2)),
_run_timer(_perf_graph.registerSection("MooseApp::run", 3)),
_execute_mesh_generators_timer(
_perf_graph.registerSection("MooseApp::executeMeshGenerators", 1)),
_restore_cached_backup_timer(_perf_graph.registerSection("MooseApp::restoreCachedBackup", 2)),
_create_minimal_app_timer(_perf_graph.registerSection("MooseApp::createMinimalApp", 3)),
_automatic_automatic_scaling(getParam<bool>("automatic_automatic_scaling")),
_executing_mesh_generators(false),
_popped_final_mesh_generator(false)
{
#ifdef HAVE_GPERFTOOLS
if (isUltimateMaster())
{
bool has_cpu_profiling = false;
bool has_heap_profiling = false;
static std::string profile_file;
// For CPU profiling, users need to have environment 'MOOSE_PROFILE_BASE'
if (std::getenv("MOOSE_PROFILE_BASE"))
{
has_cpu_profiling = true;
profile_file = std::getenv("MOOSE_PROFILE_BASE") + std::to_string(_comm->rank()) + ".prof";
}
// For Heap profiling, users need to have 'MOOSE_HEAP_BASE'
if (std::getenv("MOOSE_HEAP_BASE"))
{
has_heap_profiling = true;
profile_file = std::getenv("MOOSE_HEAP_BASE") + std::to_string(_comm->rank());
}
if (has_cpu_profiling && has_heap_profiling)
mooseError("Can not do CPU and heap profiling together");
if (has_cpu_profiling || has_heap_profiling)
{
// create directory if needed
auto name = MooseUtils::splitFileName(profile_file);
if (!name.first.empty())
{
if (processor_id() == 0)
MooseUtils::makedirs(name.first.c_str());
_comm->barrier();
}
}
// turn on profiling only on selected ranks
if (isParamValid("gperf_profiler_on"))
{
auto rankstr = getParam<std::string>("gperf_profiler_on");
std::vector<processor_id_type> ranks;
bool success = MooseUtils::tokenizeAndConvert(rankstr, ranks, ", ");
if (!success)
mooseError("Invalid argument for --gperf-profiler-on: '", rankstr, "'");
for (auto & rank : ranks)
{
if (rank >= _comm->size())
mooseError("Invalid argument for --gperf-profiler-on: ",
rank,
" is greater than or equal to ",
_comm->size());
if (rank == _comm->rank())
{
_cpu_profiling = has_cpu_profiling;
_heap_profiling = has_heap_profiling;
}
}
}
else
{
_cpu_profiling = has_cpu_profiling;
_heap_profiling = has_heap_profiling;
}
if (_cpu_profiling)
if (!ProfilerStart(profile_file.c_str()))
mooseError("CPU profiler is not started properly");
if (_heap_profiling)
{
HeapProfilerStart(profile_file.c_str());
if (!IsHeapProfilerRunning())
mooseError("Heap profiler is not started properly");
}
}
#else
if (std::getenv("MOOSE_PROFILE_BASE") || std::getenv("MOOSE_HEAP_BASE"))
mooseError("gperftool is not available for CPU or heap profiling");
#endif
Registry::addKnownLabel(_type);
Moose::registerAll(_factory, _action_factory, _syntax);
_the_warehouse = libmesh_make_unique<TheWarehouse>();
_the_warehouse->registerAttribute<AttribMatrixTags>("matrix_tags", 0);
_the_warehouse->registerAttribute<AttribVectorTags>("vector_tags", 0);
_the_warehouse->registerAttribute<AttribExecOns>("exec_ons", 0);
_the_warehouse->registerAttribute<AttribSubdomains>("subdomains", 0);
_the_warehouse->registerAttribute<AttribBoundaries>("boundaries", 0);
_the_warehouse->registerAttribute<AttribThread>("thread", 0);
_the_warehouse->registerAttribute<AttribPreIC>("pre_ic", 0);
_the_warehouse->registerAttribute<AttribPreAux>("pre_aux", 0);
_the_warehouse->registerAttribute<AttribPostAux>("post_aux", 0);
_the_warehouse->registerAttribute<AttribName>("name", "dummy");
_the_warehouse->registerAttribute<AttribSystem>("system", "dummy");
_the_warehouse->registerAttribute<AttribVar>("variable", 0);
_the_warehouse->registerAttribute<AttribInterfaces>("interfaces", 0);
_the_warehouse->registerAttribute<AttribSysNum>("sys_num", libMesh::invalid_uint);
if (isParamValid("_argc") && isParamValid("_argv"))
{
int argc = getParam<int>("_argc");
char ** argv = getParam<char **>("_argv");
_sys_info = libmesh_make_unique<SystemInfo>(argc, argv);
}
if (isParamValid("_command_line"))
_command_line = getParam<std::shared_ptr<CommandLine>>("_command_line");
else
mooseError("Valid CommandLine object required");
if (_check_input && isParamValid("recover"))
mooseError("Cannot run --check-input with --recover. Recover files might not exist");
if (isParamValid("start_in_debugger") && _multiapp_level == 0)
{
auto command = getParam<std::string>("start_in_debugger");
Moose::out << "Starting in debugger using: " << command << std::endl;
auto hostname = MooseUtils::hostname();
std::stringstream command_stream;
// This will start XTerm and print out some info first... then run the debugger
command_stream << "xterm -e \"echo 'Rank: " << processor_id() << " Hostname: " << hostname
<< " PID: " << getpid() << "'; echo ''; ";
// Figure out how to run the debugger
if (command.find("lldb") != std::string::npos || command.find("gdb") != std::string::npos)
command_stream << command << " -p " << getpid();
else
mooseError("Unknown debugger: ",
command,
"\nIf this is truly what you meant then contact moose-users to have a discussion "
"about adding your debugger.");
// Finish up the command
command_stream << "\""
<< " & ";
std::string command_string = command_stream.str();
Moose::out << "Running: " << command_string << std::endl;
int ret = std::system(command_string.c_str());
libmesh_ignore(ret);
// Sleep to allow time for the debugger to attach
std::this_thread::sleep_for(std::chrono::seconds(10));
}
if (!parameters.isParamSetByAddParam("stop_for_debugger"))
{
Moose::out << "\nStopping for " << getParam<unsigned int>("stop_for_debugger")
<< " seconds to allow attachment from a debugger.\n";
Moose::out << "\nAll of the processes you can connect to:\n";
Moose::out << "rank - hostname - pid\n";
auto hostname = MooseUtils::hostname();
{
// The 'false' turns off the serialization warning
SerializerGuard sg(_communicator, false); // Guarantees that the processors print in order
Moose::err << processor_id() << " - " << hostname << " - " << getpid() << "\n";
}
Moose::out << "\nWaiting...\n" << std::endl;
// Sleep to allow time for the debugger to attach
std::this_thread::sleep_for(std::chrono::seconds(getParam<unsigned int>("stop_for_debugger")));
}
if (_master_mesh && _multiapp_level == 0)
mooseError("Mesh can be passed in only for sub-apps");
if (_master_displaced_mesh && !_master_mesh)
mooseError("_master_mesh should have been set when _master_displaced_mesh is set");
// Data specifically associated with the mesh (meta-data) that will read from the restart
// file early during the simulation setup so that they are available to Actions and other objects
// that need them during the setup process. Most of the restartable data isn't made available
// until all objects have been created and all Actions have been executed (i.e. initialSetup).
registerRestartableDataMapName(MooseApp::MESH_META_DATA, "mesh");
if (parameters.have_parameter<bool>("use_legacy_dirichlet_bc"))
mooseDeprecated("The parameter 'use_legacy_dirichlet_bc' is no longer valid.\n\n",
"All Dirichlet boundary conditions are preset by default.\n\n",
"Remove said parameter in ",
name(),
" to remove this deprecation warning.");
}
void
MooseApp::checkRegistryLabels()
{
Registry::checkLabels();
}
MooseApp::~MooseApp()
{
#ifdef HAVE_GPERFTOOLS
// CPU profiling stop
if (_cpu_profiling)
ProfilerStop();
// Heap profiling stop
if (_heap_profiling)
HeapProfilerStop();
#endif
_action_warehouse.clear();
_executioner.reset();
_the_warehouse.reset();
delete _input_parameter_warehouse;
#ifdef LIBMESH_HAVE_DLOPEN
// Close any open dynamic libraries
for (const auto & it : _lib_handles)
dlclose(it.second);
#endif
}
std::string
MooseApp::getFrameworkVersion() const
{
return MOOSE_VERSION;
}
std::string
MooseApp::getVersion() const
{
return MOOSE_VERSION;
}
std::string
MooseApp::getPrintableVersion() const
{
return getPrintableName() + " Version: " + getVersion();
}
void
MooseApp::setupOptions()
{
TIME_SECTION(_setup_options_timer);
// MOOSE was updated to have the ability to register execution flags in similar fashion as
// objects. However, this change requires all *App.C/h files to be updated with the new
// registerExecFlags method. To avoid breaking all applications the default MOOSE flags
// are added if nothing has been added to this point. In the future this could go away or
// perhaps be a warning.
if (_execute_flags.items().empty())
Moose::registerExecFlags(_factory);
// Print the header, this is as early as possible
std::string hdr(header() + "\n");
if (multiAppLevel() > 0)
MooseUtils::indentMessage(_name, hdr);
Moose::out << hdr << std::flush;
if (getParam<bool>("error_unused"))
setCheckUnusedFlag(true);
else if (getParam<bool>("warn_unused"))
setCheckUnusedFlag(false);
if (getParam<bool>("error_override"))
setErrorOverridden();
_distributed_mesh_on_command_line = getParam<bool>("distributed_mesh");
_half_transient = getParam<bool>("half_transient");
// The no_timing flag takes precedence over the timing flag.
if (getParam<bool>("no_timing"))
{
_pars.set<bool>("timing") = false;
_perf_graph.setActive(false);
}
if (isParamValid("trap_fpe") && isParamValid("no_trap_fpe"))
mooseError("Cannot use both \"--trap-fpe\" and \"--no-trap-fpe\" flags.");
if (isParamValid("trap_fpe"))
_trap_fpe = true;
else if (isParamValid("no_trap_fpe"))
_trap_fpe = false;
// Turn all warnings in MOOSE to errors (almost see next logic block)
Moose::_warnings_are_errors = getParam<bool>("error");
// Deprecated messages can be toggled to errors independently from everything else.
Moose::_deprecated_is_error = getParam<bool>("error_deprecated");
if (isUltimateMaster()) // makes sure coloring isn't reset incorrectly in multi-app settings
{
// Toggle the color console off
Moose::setColorConsole(true, true); // set default color condition
if (getParam<bool>("no_color"))
Moose::setColorConsole(false);
char * c_color = std::getenv("MOOSE_COLOR");
std::string color = "on";
if (c_color)
color = c_color;
if (getParam<std::string>("color") != "default-on")
color = getParam<std::string>("color");
if (color == "auto")
Moose::setColorConsole(true);
else if (color == "on")
Moose::setColorConsole(true, true);
else if (color == "off")
Moose::setColorConsole(false);
else
mooseWarning("ignoring invalid --color arg (want 'auto', 'on', or 'off')");
}
// this warning goes below --color processing to honor that setting for
// the warning. And below settings for warnings/error setup.
if (getParam<bool>("no_color"))
mooseDeprecated("The --no-color flag is deprecated. Use '--color off' instead.");
// If there's no threading model active, but the user asked for
// --n-threads > 1 on the command line, throw a mooseError. This is
// intended to prevent situations where the user has potentially
// built MOOSE incorrectly (neither TBB nor pthreads found) and is
// asking for multiple threads, not knowing that there will never be
// any threads launched.
#if !LIBMESH_USING_THREADS
if (libMesh::command_line_value("--n-threads", 1) > 1)
mooseError("You specified --n-threads > 1, but there is no threading model active!");
#endif
// Build a minimal running application, ignoring the input file.
if (getParam<bool>("minimal"))
createMinimalApp();
else if (getParam<bool>("display_version"))
{
Moose::perf_log.disable_logging();
Moose::out << getPrintableVersion() << std::endl;
_ready_to_exit = true;
return;
}
else if (getParam<bool>("help"))
{
Moose::perf_log.disable_logging();
_command_line->printUsage();
_ready_to_exit = true;
}
else if (isParamValid("dump"))
{
Moose::perf_log.disable_logging();
// Get command line argument following --dump on command line
std::string following_arg = getParam<std::string>("dump");
// The argument following --dump is a parameter search string,
// which can be empty.
std::string param_search;
if (!following_arg.empty() && (following_arg.find('-') != 0))
param_search = following_arg;
JsonSyntaxTree tree(param_search);
_parser.buildJsonSyntaxTree(tree);
JsonInputFileFormatter formatter;
Moose::out << "### START DUMP DATA ###\n"
<< formatter.toString(tree.getRoot()) << "\n### END DUMP DATA ###\n";
_ready_to_exit = true;
}
else if (isParamValid("registry"))
{
Moose::out << "Label\tType\tName\tClass\tFile\n";
auto & objmap = Registry::allObjects();
for (auto & entry : objmap)
{
for (auto & obj : entry.second)
{
std::string name = obj._name;
if (name.empty())
name = obj._alias;
if (name.empty())
name = obj._classname;
Moose::out << entry.first << "\tobject\t" << name << "\t" << obj._classname << "\t"
<< obj._file << "\n";
}
}
auto & actmap = Registry::allActions();
for (auto & entry : actmap)
{
for (auto & act : entry.second)
Moose::out << entry.first << "\taction\t" << act._name << "\t" << act._classname << "\t"
<< act._file << "\n";
}
_ready_to_exit = true;
}
else if (isParamValid("registry_hit"))
{
Moose::out << "### START REGISTRY DATA ###\n";
hit::Section root("");
auto sec = new hit::Section("registry");
root.addChild(sec);
auto objsec = new hit::Section("objects");
sec->addChild(objsec);
auto & objmap = Registry::allObjects();
for (auto & entry : objmap)
{
for (auto & obj : entry.second)
{
std::string name = obj._name;
if (name.empty())
name = obj._alias;
if (name.empty())
name = obj._classname;
auto ent = new hit::Section("entry");
objsec->addChild(ent);
ent->addChild(new hit::Field("label", hit::Field::Kind::String, entry.first));
ent->addChild(new hit::Field("type", hit::Field::Kind::String, "object"));
ent->addChild(new hit::Field("name", hit::Field::Kind::String, name));
ent->addChild(new hit::Field("class", hit::Field::Kind::String, obj._classname));
ent->addChild(new hit::Field("file", hit::Field::Kind::String, obj._file));
}
}
auto actsec = new hit::Section("actions");
sec->addChild(actsec);
auto & actmap = Registry::allActions();
for (auto & entry : actmap)
{
for (auto & act : entry.second)
{
auto ent = new hit::Section("entry");
actsec->addChild(ent);
ent->addChild(new hit::Field("label", hit::Field::Kind::String, entry.first));
ent->addChild(new hit::Field("type", hit::Field::Kind::String, "action"));
ent->addChild(new hit::Field("task", hit::Field::Kind::String, act._name));
ent->addChild(new hit::Field("class", hit::Field::Kind::String, act._classname));
ent->addChild(new hit::Field("file", hit::Field::Kind::String, act._file));
}
}
Moose::out << root.render();
Moose::out << "\n### END REGISTRY DATA ###\n";
_ready_to_exit = true;
}
else if (isParamValid("definition"))
{
Moose::perf_log.disable_logging();
JsonSyntaxTree tree("");
_parser.buildJsonSyntaxTree(tree);
SONDefinitionFormatter formatter;
Moose::out << formatter.toString(tree.getRoot()) << "\n";
_ready_to_exit = true;
}
else if (isParamValid("yaml"))
{
Moose::perf_log.disable_logging();
_parser.initSyntaxFormatter(Parser::YAML, true);
// Get command line argument following --yaml on command line
std::string yaml_following_arg = getParam<std::string>("yaml");
// If the argument following --yaml is non-existent or begins with
// a dash, call buildFullTree() with an empty string, otherwise
// pass the argument following --yaml.
if (yaml_following_arg.empty() || (yaml_following_arg.find('-') == 0))
_parser.buildFullTree("");
else
_parser.buildFullTree(yaml_following_arg);
_ready_to_exit = true;
}
else if (isParamValid("json"))
{
Moose::perf_log.disable_logging();
// Get command line argument following --json on command line
std::string json_following_arg = getParam<std::string>("json");
// The argument following --json is a parameter search string,
// which can be empty.
std::string search;
if (!json_following_arg.empty() && (json_following_arg.find('-') != 0))
search = json_following_arg;
JsonSyntaxTree tree(search);
_parser.buildJsonSyntaxTree(tree);
Moose::out << "**START JSON DATA**\n" << tree.getRoot().dump(2) << "\n**END JSON DATA**\n";
_ready_to_exit = true;
}
else if (getParam<bool>("syntax"))
{
Moose::perf_log.disable_logging();
std::multimap<std::string, Syntax::ActionInfo> syntax = _syntax.getAssociatedActions();
Moose::out << "**START SYNTAX DATA**\n";
for (const auto & it : syntax)
Moose::out << it.first << "\n";
Moose::out << "**END SYNTAX DATA**\n" << std::endl;
_ready_to_exit = true;
}
else if (getParam<bool>("apptype"))
{
Moose::perf_log.disable_logging();
Moose::out << "MooseApp Type: " << type() << std::endl;
_ready_to_exit = true;
}
else if (!_input_filenames.empty() ||
isParamValid("input_file")) // They already specified an input filename
{
if (_input_filenames.empty())
_input_filenames = getParam<std::vector<std::string>>("input_file");
if (isParamValid("recover"))
{
// We need to set the flag manually here since the recover parameter is a string type (takes
// an optional filename)
_recover = true;
// Get command line argument following --recover on command line
std::string recover_following_arg = getParam<std::string>("recover");
// If the argument following --recover is non-existent or begins with
// a dash then we are going to eventually find the newest recovery file to use
if (!(recover_following_arg.empty() || (recover_following_arg.find('-') == 0)))
_restart_recover_base = recover_following_arg;
}
// Optionally get command line argument following --recoversuffix
// on command line. Currently this argument applies to both
// recovery and restart files.
if (isParamValid("recoversuffix"))
{
_restart_recover_suffix = getParam<std::string>("recoversuffix");
}
_parser.parse(_input_filenames);
if (isParamValid("mesh_only"))
{
_syntax.registerTaskName("mesh_only", true);
_syntax.addDependency("mesh_only", "setup_mesh_complete");
_action_warehouse.setFinalTask("mesh_only");
}
else if (isParamValid("split_mesh"))
{
_split_mesh = true;
_syntax.registerTaskName("split_mesh", true);
_syntax.addDependency("split_mesh", "setup_mesh_complete");
_action_warehouse.setFinalTask("split_mesh");
}
_action_warehouse.build();
// Setup the AppFileBase for use by the Outputs or other systems that need output file info
{
// Extract the CommonOutputAction
const auto common_actions = _action_warehouse.getActions<CommonOutputAction>();
mooseAssert(common_actions.size() <= 1, "Should not be more than one CommonOutputAction");
const Action * common = common_actions.empty() ? nullptr : *common_actions.begin();
// If file_base is set in CommonOutputAction through parsing input, obtain the file_base
if (common && common->isParamValid("file_base"))
{
_output_file_base = common->getParam<std::string>("file_base");
_file_base_set_by_user = true;
}
else if (isUltimateMaster())
{
// if this app is a master, we use the first input file name as the default file base
std::string base = getInputFileName();
size_t pos = base.find_last_of('.');
_output_file_base = base.substr(0, pos);
// Note: we did not append "_out" in the file base here because we do not want to
// have it in between the input file name and the object name for Output/*
// syntax.
}
// default file base for multiapps is set by MultiApp
}
}
else /* The catch-all case for bad options or missing options, etc. */
{
Moose::perf_log.disable_logging();
if (_check_input)
mooseError("You specified --check-input, but did not provide an input file. Add -i "
"<inputfile> to your command line.");
_command_line->printUsage();
_ready_to_exit = true;
}
}
void
MooseApp::setInputFileName(const std::string & input_filename)
{
// for now we only permit single input to be set for multiapps
_input_filenames = {input_filename};
}
std::string
MooseApp::getOutputFileBase(bool for_non_moose_build_output) const
{
if (_file_base_set_by_user || for_non_moose_build_output || _multiapp_level)
return _output_file_base;
else
return _output_file_base + "_out";
}
void
MooseApp::runInputFile()
{
TIME_SECTION(_run_input_file_timer);
// If ready to exit has been set, then just return
if (_ready_to_exit)
return;
_action_warehouse.executeAllActions();
if (isParamValid("mesh_only") || isParamValid("split_mesh"))
_ready_to_exit = true;
else if (getParam<bool>("list_constructed_objects"))
{
// TODO: ask multiapps for their constructed objects
_ready_to_exit = true;
std::vector<std::string> obj_list = _factory.getConstructedObjects();
Moose::out << "**START OBJECT DATA**\n";
for (const auto & name : obj_list)
Moose::out << name << "\n";
Moose::out << "**END OBJECT DATA**\n" << std::endl;
}
}