forked from idaholab/moose
/
MooseApp.h
1430 lines (1199 loc) · 46.9 KB
/
MooseApp.h
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
#pragma once
// MOOSE includes
#include "Moose.h"
#include "Parser.h"
#include "ActionWarehouse.h"
#include "Factory.h"
#include "ActionFactory.h"
#include "OutputWarehouse.h"
#include "RestartableData.h"
#include "ConsoleStreamInterface.h"
#include "PerfGraph.h"
#include "PerfGraphInterface.h"
#include "TheWarehouse.h"
#include "RankMap.h"
#include "MeshGeneratorSystem.h"
#include "libmesh/parallel_object.h"
#include "libmesh/mesh_base.h"
#include "libmesh/point.h"
// C++ includes
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <typeindex>
// Forward declarations
class Executioner;
class Executor;
class NullExecutor;
class Backup;
class FEProblemBase;
class InputParameterWarehouse;
class SystemInfo;
class CommandLine;
class RelationshipManager;
class SolutionInvalidity;
namespace libMesh
{
class ExodusII_IO;
}
/**
* Base class for MOOSE-based applications
*
* This generic class for application provides:
* - parsing command line arguments,
* - parsing an input file,
* - executing the simulation
*
* Each application should register its own objects and register its own special syntax
*/
class MooseApp : public ConsoleStreamInterface,
public PerfGraphInterface,
public libMesh::ParallelObject
{
public:
/**
* Stores configuration options relating to the fixed-point solving
* capability. This is used for communicating input-file-based config from
* the MultiApp object/syntax to the execution (e.g. executor) system.
*/
struct FixedPointConfig
{
FixedPointConfig() : sub_relaxation_factor(1.0) {}
/// relaxation factor to be used for a MultiApp's subapps.
Real sub_relaxation_factor;
/// The names of variables to transform for fixed point solve algorithms (e.g. secant, etc.).
std::vector<std::string> sub_transformed_vars;
/// The names of postprocessors to transform for fixed point solve algorithms (e.g. secant, etc.).
std::vector<PostprocessorName> sub_transformed_pps;
};
static const RestartableDataMapName MESH_META_DATA;
static InputParameters validParams();
virtual ~MooseApp();
TheWarehouse & theWarehouse() { return *_the_warehouse; }
/**
* Get the name of the object. In the case of MooseApp, the name of the object is *NOT* the name
* of the application. It's the name of the created application which is usually "main". If you
* have subapps, then each individual subapp will have a unique name which typically comes from
* the input file (e.g. sub0, sub1, etc...).
* @return The name of the object
*/
const std::string & name() const { return _name; }
/**
* Get printable name of the application.
*/
virtual std::string getPrintableName() const { return "Application"; }
virtual std::string appBinaryName() const
{
auto name = Moose::getExecutableName();
name = name.substr(0, name.find_last_of("-"));
if (name.find_first_of("/") != std::string::npos)
name = name.substr(name.find_first_of("/") + 1, std::string::npos);
return name;
}
/**
* Get the parameters of the object
* @return The parameters of the object
*/
InputParameters & parameters() { return _pars; }
/**
* Get the type of this object as a string. This is a string version of the class name (e.g.
* MooseTestApp).
* @return The the type of the object
*/
const std::string & type() const { return _type; }
/**
* The RankMap is a useful object for determining how the processes
* are laid out on the physical nodes of the cluster
*/
const RankMap & rankMap() { return _rank_map; }
/**
* Get the PerfGraph for this app
*/
PerfGraph & perfGraph() { return _perf_graph; }
/**
* Get the SolutionInvalidity for this app
*/
SolutionInvalidity & solutionInvalidity() { return _solution_invalidity; }
///@{
/**
* Retrieve a parameter for the object
* @param name The name of the parameter
* @return The value of the parameter
*/
template <typename T>
const T & getParam(const std::string & name);
template <typename T>
const T & getParam(const std::string & name) const;
///@}
/**
* Retrieve a renamed parameter for the object. This helper makes sure we
* check both names before erroring, and that only one parameter is passed to avoid
* silent errors
* @param old_name the old name for the parameter
* @param new_name the new name for the parameter
*/
template <typename T>
const T & getRenamedParam(const std::string & old_name, const std::string & new_name) const;
inline bool isParamValid(const std::string & name) const { return _pars.isParamValid(name); }
inline bool isParamSetByUser(const std::string & nm) const { return _pars.isParamSetByUser(nm); }
/**
* Run the application
*/
virtual void run();
/**
* Returns the framework version.
*/
std::string getFrameworkVersion() const;
/**
* Returns the current version of the framework or application (default: framework version).
*/
virtual std::string getVersion() const;
/**
* Non-virtual method for printing out the version string in a consistent format.
*/
std::string getPrintableVersion() const;
/**
* Setup options based on InputParameters.
*/
virtual void setupOptions();
/**
* Return a writable reference to the ActionWarehouse associated with this app
*/
ActionWarehouse & actionWarehouse() { return _action_warehouse; }
/**
* Return a const reference to the ActionWarehouse associated with this app
*/
const ActionWarehouse & actionWarehouse() const { return _action_warehouse; }
/**
* Returns a writable reference to the parser
*/
Parser & parser() { return _parser; }
/**
* Returns a writable reference to the syntax object.
*/
Syntax & syntax() { return _syntax; }
/**
* Set the input file name.
*/
void setInputFileName(const std::string & input_file_name);
/**
* Returns the input file name that was set with setInputFileName
*/
std::string getInputFileName() const
{
return _input_filenames.empty() ? "" : _input_filenames.back();
}
/**
* Override the selection of the output file base name.
* Note: This method is supposed to be called by MultiApp only.
*/
void setOutputFileBase(const std::string & output_file_base);
/**
* Get the output file base name.
* @param for_non_moose_build_output True for getting the file base for outputs generated with
* Outputs/[outputname] input syntax.
* @return The file base name used by output objects
* Note: for_non_moose_build_output does not affect the returned value when this is a subapp.
* for_non_moose_build_output also does not affect the returned value when Outputs/file_base
* parameter is available. When for_non_moose_build_output does affect the returned value,
* i.e. master without Outputs/file_base, the suffix _out is removed.
*/
std::string getOutputFileBase(bool for_non_moose_build_output = false) const;
/**
* Tell the app to output in a specific position.
*/
void setOutputPosition(const Point & p);
/**
* Get all checkpoint directories
* @return A Set of checkpoint directories
*/
std::list<std::string> getCheckpointDirectories() const;
/**
* Extract all possible checkpoint file names
* @return A Set of checkpoint filenames
*/
std::list<std::string> getCheckpointFiles() const;
/**
* Whether or not an output position has been set.
* @return True if it has
*/
bool hasOutputPosition() const { return _output_position_set; }
/**
* Get the output position.
* @return The position offset for the output.
*/
Point getOutputPosition() const { return _output_position; }
/**
* Set the starting time for the simulation. This will override any choice
* made in the input file.
*
* @param time The start time for the simulation.
*/
void setStartTime(Real time);
/**
* @return Whether or not a start time has been programmatically set using setStartTime()
*/
bool hasStartTime() const { return _start_time_set; }
/**
* @return The start time
*/
Real getStartTime() const { return _start_time; }
/**
* Each App has it's own local time. The "global" time of the whole problem might be
* different. This offset is how far off the local App time is from the global time.
*/
void setGlobalTimeOffset(Real offset) { _global_time_offset = offset; }
/**
* Each App has it's own local time. The "global" time of the whole problem might be
* different. This offset is how far off the local App time is from the global time.
*/
Real getGlobalTimeOffset() const { return _global_time_offset; }
/**
* Return the primary (first) filename that was parsed
* Note: When stripLeadingPath is false, this function returns the same name as
* getInputFileName() method when the input file is not a link.
*/
std::string getFileName(bool stripLeadingPath = true) const;
/**
* Set a flag so that the parser will throw an error if overridden parameters are detected
*/
void setErrorOverridden();
/**
* Removes warnings and error checks for unrecognized variables in the input file
*/
void disableCheckUnusedFlag();
/**
* Retrieve the Executioner for this App
*/
Executioner * getExecutioner() const;
Executor * getExecutor() const { return _executor.get(); }
NullExecutor * getNullExecutor() const { return _null_executor.get(); }
bool useExecutor() const { return _use_executor; }
FEProblemBase & feProblem() const;
/**
* Set the Executioner for this App
*/
void setExecutioner(std::shared_ptr<Executioner> && executioner) { _executioner = executioner; }
void setExecutor(std::shared_ptr<Executor> && executor) { _executor = executor; }
void
addExecutor(const std::string & type, const std::string & name, const InputParameters & params);
/**
* Adds the parameters for an Executor to the list of parameters. This is done
* so that the Executors can be created in _exactly_ the correct order.
*/
void addExecutorParams(const std::string & type,
const std::string & name,
const InputParameters & params);
private:
/**
* Internal function used to recursively create the executor objects.
*
* Called by createExecutors
*
* @param current_executor_name The name of the executor currently needing to be built
* @param possible_roots The names of executors that are currently candidates for being the root
*/
void recursivelyCreateExecutors(const std::string & current_executor_name,
std::list<std::string> & possible_roots,
std::list<std::string> & current_branch);
public:
/**
* After adding all of the Executor Params - this function will actually cause all of them to be
* built
*/
void createExecutors();
/**
* Get an Executor
*
* @param name The name of the Executor
* @param fail_if_not_found Whether or not to fail if the executor doesn't exist. If this is
* false then this function will return a NullExecutor
*/
Executor & getExecutor(const std::string & name, bool fail_if_not_found = true);
/**
* This info is stored here because we need a "globalish" place to put it in
* order to allow communication between a multiapp and solver-specific
* internals (i.e. relating to fixed-point inner loops like picard, etc.)
* for handling subapp-specific modifications necessary for those solve
* processes.
*/
FixedPointConfig & fixedPointConfig() { return _fixed_point_config; }
/**
* Returns a writable Boolean indicating whether this app will use a Nonlinear or Eigen System.
*/
bool & useNonlinear() { return _use_nonlinear; }
/**
* Returns a writable Boolean indicating whether this app will use an eigenvalue executioner.
*/
bool & useEigenvalue() { return _use_eigen_value; }
/**
* Retrieve a writable reference to the Factory associated with this App.
*/
Factory & getFactory() { return _factory; }
/**
* Retrieve a writable reference to the ActionFactory associated with this App.
*/
ActionFactory & getActionFactory() { return _action_factory; }
/**
* Returns the MPI processor ID of the current processor.
*/
processor_id_type processor_id() const { return _comm->rank(); }
/**
* Get the command line
* @return The reference to the command line object
* Setup options based on InputParameters.
*/
std::shared_ptr<CommandLine> commandLine() const { return _command_line; }
/**
* Set the flag to indicate whether or not we need to use a separate Exodus reader to read the
* mesh BEFORE we create the mesh.
*/
void setExodusFileRestart(bool flag) { _initial_from_file = flag; }
/**
* Whether or not we need to use a separate Exodus reader to read the mesh BEFORE we create the
* mesh.
*/
bool getExodusFileRestart() const { return _initial_from_file; }
/**
* Set the Exodus reader to restart variables from an Exodus mesh file
*/
void setExReaderForRestart(std::shared_ptr<ExodusII_IO> && exreader) { _ex_reader = exreader; }
/**
* Get the Exodus reader to restart variables from an Exodus mesh file
*/
ExodusII_IO * getExReaderForRestart() const { return _ex_reader.get(); }
/**
* Actually build everything in the input file.
*/
virtual void runInputFile();
/**
* Execute the Executioner that was built.
*/
virtual void executeExecutioner();
/**
* Returns true if the user specified --distributed-mesh (or
* --parallel-mesh, for backwards compatibility) on the command line
* and false otherwise.
*/
bool getDistributedMeshOnCommandLine() const { return _distributed_mesh_on_command_line; }
/**
* Whether or not this is a "recover" calculation. More specifically whether this simulation has
* been recovered with something like the \p --recover command line argument. Note that this will
* never return true when \p isRestarting is true
*/
bool isRecovering() const;
/**
* Whether or not this is a "restart" calculation. More specifically whether this has been
* restarted using the \p Problem/restart_file_base parameter. Note that this will only return
* true when doing \emph checkpoint restart. This will be false if doing \emph exodus restart.
* Finally this will never return true when \p isRecovering is true
*/
bool isRestarting() const;
/**
* Whether or not this is a split mesh operation.
*/
bool isSplitMesh() const;
///@{
/**
* Return true if the recovery file base is set
*/
bool hasRestartRecoverFileBase() const;
bool hasRecoverFileBase() const;
///@}
///@{
/**
* The file_base for the recovery file.
*/
std::string getRestartRecoverFileBase() const { return _restart_recover_base; }
std::string getRecoverFileBase() const
{
mooseDeprecated("MooseApp::getRecoverFileBase is deprecated, use "
"MooseApp::getRestartRecoverFileBase() instead.");
return _restart_recover_base;
}
///@}
/**
* mutator for recover_base (set by RecoverBaseAction)
*/
void setRestartRecoverFileBase(const std::string & file_base)
{
if (file_base.empty())
_restart_recover_base = MooseUtils::getLatestAppCheckpointFileBase(getCheckpointFiles());
else
_restart_recover_base = file_base;
}
/**
* The suffix for the recovery file.
*/
std::string getRestartRecoverFileSuffix() const { return _restart_recover_suffix; }
/**
* mutator for recover_suffix
*/
void setRestartRecoverFileSuffix(const std::string & file_suffix)
{
_restart_recover_suffix = file_suffix;
}
/**
* Whether or not this simulation should only run half its transient (useful for testing
* recovery)
*/
bool halfTransient() const { return _half_transient; }
/**
* Store a map of outputter names and file numbers
* The MultiApp system requires this to get the file numbering to propagate down through the
* Multiapps.
* @param numbers Map of outputter names and file numbers
*
* @see MultiApp TransientMultiApp OutputWarehouse
*/
void setOutputFileNumbers(const std::map<std::string, unsigned int> & numbers)
{
_output_file_numbers = numbers;
}
/**
* Store a map of outputter names and file numbers
* The MultiApp system requires this to get the file numbering to propogate down through the
* multiapps.
*
* @see MultiApp TransientMultiApp
*/
const std::map<std::string, unsigned int> & getOutputFileNumbers() const
{
return _output_file_numbers;
}
/**
* Get the OutputWarehouse objects
*/
OutputWarehouse & getOutputWarehouse();
/**
* Get SystemInfo object
* @return A pointer to the SystemInformation object
*/
const SystemInfo * getSystemInfo() const { return _sys_info.get(); }
///@{
/**
* Thes methods are called to register applications or objects on demand. This method
* attempts to load a dynamic library and register it when it is needed. Throws an error if
* no suitable library is found that contains the app_name in question.
*/
void dynamicAllRegistration(const std::string & app_name,
Factory * factory,
ActionFactory * action_factory,
Syntax * syntax,
std::string library_path,
const std::string & library_name);
void dynamicAppRegistration(const std::string & app_name,
std::string library_path,
const std::string & library_name);
///@}
/**
* Converts an application name to a library name:
* Examples:
* AnimalApp -> libanimal-oprof.la (assuming METHOD=oprof)
* ThreeWordAnimalApp -> libthree_word_animal-dbg.la (assuming METHOD=dbg)
*/
std::string appNameToLibName(const std::string & app_name) const;
/**
* Converts a library name to an application name:
*/
std::string libNameToAppName(const std::string & library_name) const;
/**
* Return the loaded library filenames in a std::set
*/
std::set<std::string> getLoadedLibraryPaths() const;
/**
* Get the InputParameterWarehouse for MooseObjects
*/
InputParameterWarehouse & getInputParameterWarehouse();
/*
* Register a piece of restartable data. This is data that will get
* written / read to / from a restart file.
*
* @param name The full (unique) name.
* @param data The actual data object.
* @param tid The thread id of the object. Use 0 if the object is not threaded.
* @param read_only Restrict the data for read-only
* @param metaname (optional) register the data to the meta data storage (tid must be 0)
*/
RestartableDataValue & registerRestartableData(const std::string & name,
std::unique_ptr<RestartableDataValue> data,
THREAD_ID tid,
bool read_only,
const RestartableDataMapName & metaname = "");
/*
* Check if a restartable meta data exists or not.
*
* @param name The full (unique) name.
* @param metaname The name to the meta data storage
*/
bool hasRestartableMetaData(const std::string & name,
const RestartableDataMapName & metaname) const;
/*
* Retrieve restartable meta data from restartable data map
*
* @param name The full (unique) name.
* @param metaname The name to the meta data storage
* @return A reference to the restartable meta data value
*/
RestartableDataValue & getRestartableMetaData(const std::string & name,
const RestartableDataMapName & metaname,
THREAD_ID tid) const;
/**
* Return reference to the restartable data object
* @return A const reference to the restartable data object
*/
const RestartableDataMaps & getRestartableData() const { return _restartable_data; }
/**
* Return a reference to restartable data for the specific type flag.
*/
const RestartableDataMap & getRestartableDataMap(const RestartableDataMapName & name) const;
/**
* Reserve a location for storing custom RestartableDataMap objects.
*
* This should be called in the constructor of an application.
*
* @param name A key to use for accessing the data object
* @param suffix The suffix to use when appending to checkpoint output, if not supplied the
* given name is used to generate the suffix (MyMetaData -> _mymetadata)
*/
void registerRestartableDataMapName(const RestartableDataMapName & name, std::string suffix = "");
/**
* Return a reference to the recoverable data object
* @return A const reference to the recoverable data
*/
const DataNames & getRecoverableData() const { return _recoverable_data_names; }
/**
* Create a Backup from the current App. A Backup contains all the data necessary to be able to
* restore the state of an App.
*
* This method should be overridden in external or MOOSE-wrapped applications.
*/
virtual std::shared_ptr<Backup> backup();
/**
* Restore a Backup. This sets the App's state.
*
* @param backup The Backup holding the data for the app
* @param for_restart Whether this restoration is explicitly for the first restoration of restart
* data.
*
* This method should be overridden in external or MOOSE-wrapped applications.
*/
virtual void restore(std::shared_ptr<Backup> backup, bool for_restart = false);
/**
* Returns a string to be printed at the beginning of a simulation
*/
virtual std::string header() const;
/**
* The MultiApp Level
* @return The current number of levels from the master app
*/
unsigned int multiAppLevel() const { return _multiapp_level; }
/**
* The MultiApp number
* @return The numbering in all the sub-apps on the same level
*/
unsigned int multiAppNumber() const { return _multiapp_number; }
/**
* Whether or not this app is the ultimate master app. (ie level == 0)
*/
bool isUltimateMaster() const { return !_multiapp_level; }
/**
* Returns a pointer to the master mesh
*/
const MooseMesh * masterMesh() const { return _master_mesh; }
/**
* Returns a pointer to the master displaced mesh
*/
const MooseMesh * masterDisplacedMesh() const { return _master_displaced_mesh; }
/**
* Gets the system that manages the MeshGenerators
*/
MeshGeneratorSystem & getMeshGeneratorSystem() { return _mesh_generator_system; }
/**
* Add a mesh generator that will act on the meshes in the system
*
* @param type The type of MeshGenerator
* @param name The name of the MeshGenerator
* @param params The params used to construct the MeshGenerator
*
* See MeshGeneratorSystem::addMeshGenerator()
*/
void addMeshGenerator(const std::string & type,
const std::string & name,
const InputParameters & params)
{
_mesh_generator_system.addMeshGenerator(type, name, params);
}
/**
* @returns Whether or not a mesh generator exists with the name \p name.
*/
bool hasMeshGenerator(const MeshGeneratorName & name) const
{
return _mesh_generator_system.hasMeshGenerator(name);
}
/**
* @returns The MeshGenerator with the name \p name.
*/
const MeshGenerator & getMeshGenerator(const std::string & name) const
{
return _mesh_generator_system.getMeshGenerator(name);
}
/**
* @returns The final mesh generated by the mesh generator system
*/
std::unique_ptr<MeshBase> getMeshGeneratorMesh()
{
return _mesh_generator_system.getSavedMesh(_mesh_generator_system.mainMeshGeneratorName());
}
/**
* @returns The names of all mesh generators
*
* See MeshGeneratorSystem::getMeshGeneratorNames()
*/
std::vector<std::string> getMeshGeneratorNames() const
{
return _mesh_generator_system.getMeshGeneratorNames();
}
/**
* Append a mesh generator that will act on the final mesh generator in the system
*
* @param type The type of MeshGenerator
* @param name The name of the MeshGenerator
* @param params The params used to construct the MeshGenerator
*
* See MeshGeneratorSystem::appendMeshGenerator()
*/
const MeshGenerator &
appendMeshGenerator(const std::string & type, const std::string & name, InputParameters params)
{
return _mesh_generator_system.appendMeshGenerator(type, name, params);
}
/**
* Whether this app is constructing mesh generators
*
* This is virtual to allow MooseUnitApp to override it so that we can
* construct MeshGenerators in unit tests
*/
virtual bool constructingMeshGenerators() const;
///@{
/**
* Sets the restart/recover flags
* @param state The state to set the flag to
*/
void setRestart(bool value);
void setRecover(bool value);
///@}
/// Returns whether the Application is running in check input mode
bool checkInput() const { return _check_input; }
/// Returns whether FPE trapping is turned on (either because of debug or user requested)
bool getFPTrapFlag() const { return _trap_fpe; }
/**
* Returns a Boolean indicating whether a RelationshipManater exists with the same name.
*/
bool hasRelationshipManager(const std::string & name) const;
/**
* Transfers ownership of a RelationshipManager to the application for lifetime management.
* The RelationshipManager will NOT be duplicately added if an equivalent RelationshipManager
* is already active. In that case, it's possible that the object will be destroyed if the
* reference count drops to zero.
*/
bool addRelationshipManager(std::shared_ptr<RelationshipManager> relationship_manager);
private:
/**
* Purge this relationship manager from meshes and DofMaps and finally from us. This method is
* private because only this object knows when we should remove relationship managers: when we are
* adding relationship managers to this object's storage, we perform an operator>= comparison
* between our existing RMs and the RM we are trying to add. If any comparison returns true, we do
* not add the new RM because the comparison indicates that we would gain no new coverage.
* However, if no comparison return true, then we add the new RM and we turn the comparison
* around! Consequently if our new RM is >= than any of our preexisting RMs, we remove those
* preexisting RMs using this method
*/
void removeRelationshipManager(std::shared_ptr<RelationshipManager> relationship_manager);
public:
/**
* Attach the relationship managers of the given type
* Note: Geometric relationship managers that are supposed to be attached late
* will be attached when Algebraic are attached.
*/
void attachRelationshipManagers(Moose::RelationshipManagerType rm_type,
bool attach_geometric_rm_final = false);
/**
* Attach geometric relationship managers to the given \p MeshBase object. This API is designed to
* work with \p MeshGenerators which are executed at the very beginning of a simulation. No
* attempt will be made to add relationship managers to a displaced mesh, because it doesn't exist
* yet.
*/
void attachRelationshipManagers(MeshBase & mesh, MooseMesh & moose_mesh);
/**
* Retrieve the relationship managers
*/
const std::vector<std::shared_ptr<RelationshipManager>> & getReleationshipManagers();
/**
* Returns the Relationship managers info suitable for printing.
*/
std::vector<std::pair<std::string, std::string>> getRelationshipManagerInfo() const;
/**
* Return the app level ExecFlagEnum, this contains all the available flags for the app.
*/
const ExecFlagEnum & getExecuteOnEnum() const { return _execute_flags; }
/**
* Method for setting the backup object to be restored at a later time. This method is called
* during simulation restart or recover before the application is completely setup. The backup
* object set here, will be restored when needed by a call to restoreCachedBackup().
*
* @param backup The Backup holding the data for the app.
*/
void setBackupObject(std::shared_ptr<Backup> backup);
/**
* Whether to enable automatic scaling by default
*/
bool defaultAutomaticScaling() const { return _automatic_automatic_scaling; }
// Return the communicator for this application
const std::shared_ptr<Parallel::Communicator> getCommunicator() const { return _comm; }
/**
* Return the container of relationship managers
*/
const std::set<std::shared_ptr<RelationshipManager>> & relationshipManagers() const
{
return _relationship_managers;
}
/**
* Function to check the integrity of the restartable meta data structure
*/
void checkMetaDataIntegrity() const;
///@{
/**
* Iterator based access to the extra RestartableDataMap objects; see Checkpoint.C for use case.
*
* These are MOOSE internal functions and should not be used otherwise.
*/
std::unordered_map<RestartableDataMapName,
std::pair<RestartableDataMap, std::string>>::const_iterator
getRestartableDataMapBegin() const
{
return _restartable_meta_data.begin();
}
std::unordered_map<RestartableDataMapName,
std::pair<RestartableDataMap, std::string>>::const_iterator
getRestartableDataMapEnd() const
{
return _restartable_meta_data.end();
}
///@}
/**
* Whether this application should by default error on Jacobian nonzero reallocations. The
* application level setting can always be overridden by setting the \p
* error_on_jacobian_nonzero_reallocation parameter in the \p Problem block of the input file
*/
virtual bool errorOnJacobianNonzeroReallocation() const { return false; }
/**
* Registers an interface object for accessing with getInterfaceObjects.
*
* This should be called within the constructor of the interface in interest.
*/
template <class T>
void registerInterfaceObject(T & interface);
/**
* Gets the registered interface objects for a given interface.
*
* For this to work, the interface must register itself using registerInterfaceObject.
*/
template <class T>
const std::vector<T *> & getInterfaceObjects() const;
static void addAppParam(InputParameters & params);
protected:
/**
* Whether or not this MooseApp has cached a Backup to use for restart / recovery
*/
bool hasCachedBackup() const { return _cached_backup.get(); }
/**
* Restore from a cached backup
*/
void restoreCachedBackup();
/**
* Helper method for dynamic loading of objects
*/
void dynamicRegistration(const Parameters & params);
/**
* Recursively loads libraries and dependencies in the proper order to fully register a
* MOOSE application that may have several dependencies. REQUIRES: dynamic linking loader support.
*/
void loadLibraryAndDependencies(const std::string & library_filename, const Parameters & params);
/// Constructor is protected so that this object is constructed through the AppFactory object
MooseApp(InputParameters parameters);
/**
* NOTE: This is an internal function meant for MOOSE use only!
*
* Register a piece of restartable data that will be used in a filter in/out during
* deserialization. Note however that this data will always be written to the restart file.
*
* @param name The full (unique) name.
* @param filter The filter name where to direct the name
*/
void registerRestartableNameWithFilter(const std::string & name,
Moose::RESTARTABLE_FILTER filter);
/**
* Runs post-initialization error checking that cannot be run correctly unless the simulation
* has been fully set up and initialized.
*/
void errorCheck();
/// The name of this object
const std::string _name;
/// Parameters of this object
InputParameters _pars;
/// The string representation of the type of this object as registered (see registerApp(AppName))
const std::string _type;
/// The MPI communicator this App is going to use
const std::shared_ptr<Parallel::Communicator> _comm;