/
Parser.C
1991 lines (1788 loc) · 68.7 KB
/
Parser.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
// MOOSE includes
#include "MooseUtils.h"
#include "MooseInit.h"
#include "InputParameters.h"
#include "ActionFactory.h"
#include "Action.h"
#include "Factory.h"
#include "MooseObjectAction.h"
#include "ActionWarehouse.h"
#include "EmptyAction.h"
#include "FEProblem.h"
#include "MooseMesh.h"
#include "Executioner.h"
#include "MooseApp.h"
#include "MooseEnum.h"
#include "MultiMooseEnum.h"
#include "MultiApp.h"
#include "GlobalParamsAction.h"
#include "SyntaxTree.h"
#include "InputFileFormatter.h"
#include "YAMLFormatter.h"
#include "MooseTypes.h"
#include "CommandLine.h"
#include "JsonSyntaxTree.h"
#include "SystemInfo.h"
#include "MooseUtils.h"
#include "libmesh/parallel.h"
#include "libmesh/fparser.hh"
// Regular expression includes
#include "pcrecpp.h"
// C++ includes
#include <string>
#include <map>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cstdlib>
Parser::Parser(MooseApp & app, ActionWarehouse & action_wh)
: ConsoleStreamInterface(app),
_app(app),
_factory(app.getFactory()),
_action_wh(action_wh),
_action_factory(app.getActionFactory()),
_syntax(_action_wh.syntax()),
_syntax_formatter(nullptr),
_sections_read(false),
_current_params(nullptr),
_current_error_stream(nullptr)
{
}
Parser::~Parser() {}
bool
isSectionActive(std::string path, hit::Node * root)
{
hit::Node * n = root->find(path);
while (n)
{
hit::Node * section = n->parent();
if (section)
{
auto actives = section->find("active");
auto inactives = section->find("inactive");
// only check current level, not nested ones
if (actives && actives->type() == hit::NodeType::Field && actives->parent() == section)
{
auto vars = section->param<std::vector<std::string>>("active");
bool have_var = false;
for (auto & var : vars)
if (n->path() == hit::pathNorm(var))
have_var = true;
if (!have_var)
return false;
}
// only check current level, not nested ones
if (inactives && inactives->type() == hit::NodeType::Field && inactives->parent() == section)
{
auto vars = section->param<std::vector<std::string>>("inactive");
for (auto & var : vars)
if (n->path() == hit::pathNorm(var))
return false;
}
}
n = section;
}
return true;
}
class DupParamWalker : public hit::Walker
{
public:
DupParamWalker(std::string fname) : _fname(fname) {}
void walk(const std::string & fullpath, const std::string & /*nodepath*/, hit::Node * n) override
{
std::string prefix = n->type() == hit::NodeType::Field ? "parameter" : "section";
if (_have.count(fullpath) > 0)
{
auto existing = _have[fullpath];
if (_duplicates.count(fullpath) == 0)
{
errors.push_back(
hit::errormsg(_fname, existing, prefix, " '", fullpath, "' supplied multiple times"));
_duplicates.insert(fullpath);
}
errors.push_back(
hit::errormsg(_fname, n, prefix, " '", fullpath, "' supplied multiple times"));
}
_have[n->fullpath()] = n;
}
std::vector<std::string> errors;
private:
std::string _fname;
std::set<std::string> _duplicates;
std::map<std::string, hit::Node *> _have;
};
std::vector<std::string>
findSimilar(std::string param, std::vector<std::string> options)
{
std::vector<std::string> candidates;
if (options.size() == 0)
return candidates;
int mindist = MooseUtils::levenshteinDist(options[0], param);
for (auto & opt : options)
{
int dist = MooseUtils::levenshteinDist(opt, param);
// magic number heuristics to get similarity distance cutoff
int dist_cutoff = 1 + param.size() / 5;
if (dist > dist_cutoff || dist > mindist)
continue;
if (dist < mindist)
{
mindist = dist;
candidates.clear();
}
candidates.push_back(opt);
}
return candidates;
}
std::vector<std::string>
Parser::listValidParams(std::string & section_name)
{
bool dummy;
std::string registered_identifier = _syntax.isAssociated(section_name, &dummy);
auto iters = _syntax.getActions(registered_identifier);
std::vector<std::string> paramlist;
for (auto it = iters.first; it != iters.second; ++it)
{
auto params = _action_factory.getValidParams(it->second._action);
for (const auto & it : params)
paramlist.push_back(it.first);
}
return paramlist;
}
class UnusedWalker : public hit::Walker
{
public:
UnusedWalker(std::string fname, std::set<std::string> used, Parser & p)
: _fname(fname), _used(used), _parser(p)
{
}
void walk(const std::string & fullpath, const std::string & nodename, hit::Node * n) override
{
// the line() > 0 check allows us to skip nodes that were merged into this tree (i.e. CLI
// args) because their unused params are checked+reported independently of the ones in the
// main tree.
if (!_used.count(fullpath) && nodename != "active" && nodename != "inactive" &&
isSectionActive(fullpath, n->root()) && n->line() > 0)
{
auto section_name = fullpath.substr(0, fullpath.rfind("/"));
auto paramlist = _parser.listValidParams(section_name);
auto candidates = findSimilar(nodename, paramlist);
if (candidates.size() > 0)
errors.push_back(hit::errormsg(_fname,
n,
"unused parameter '",
fullpath,
"'\n",
" Did you mean '",
candidates[0],
"'?"));
else
errors.push_back(hit::errormsg(_fname, n, "unused parameter '", fullpath, "'"));
}
}
std::vector<std::string> errors;
private:
std::string _fname;
std::set<std::string> _used;
Parser & _parser;
};
class BadActiveWalker : public hit::Walker
{
public:
BadActiveWalker(std::string fname) : _fname(fname) {}
void walk(const std::string & /*fullpath*/,
const std::string & /*nodepath*/,
hit::Node * section) override
{
auto actives = section->find("active");
auto inactives = section->find("inactive");
if (actives && inactives && actives->type() == hit::NodeType::Field &&
inactives->type() == hit::NodeType::Field && actives->parent() == inactives->parent())
{
errors.push_back(hit::errormsg(
_fname, section, "'active' and 'inactive' parameters both provided in section"));
return;
}
// ensures we don't recheck deeper nesting levels
if (actives && actives->type() == hit::NodeType::Field && actives->parent() == section)
{
auto vars = section->param<std::vector<std::string>>("active");
std::string msg = "";
for (auto & var : vars)
{
if (!section->find(var))
msg += var + ", ";
}
if (msg.size() > 0)
{
msg = msg.substr(0, msg.size() - 2);
errors.push_back(hit::errormsg(_fname,
section,
"variables listed as active (",
msg,
") in section '",
section->fullpath(),
"' not found in input"));
}
}
// ensures we don't recheck deeper nesting levels
if (inactives && inactives->type() == hit::NodeType::Field && inactives->parent() == section)
{
auto vars = section->param<std::vector<std::string>>("inactive");
std::string msg = "";
for (auto & var : vars)
{
if (!section->find(var))
msg += var + ", ";
}
if (msg.size() > 0)
{
msg = msg.substr(0, msg.size() - 2);
errors.push_back(hit::errormsg(_fname,
section,
"variables listed as inactive (",
msg,
") in section '",
section->fullpath(),
"' not found in input"));
}
}
}
std::vector<std::string> errors;
private:
std::string _fname;
};
std::string
Parser::getFileName(bool stripLeadingPath) const
{
if (!stripLeadingPath)
return _input_filename;
std::string filename;
size_t pos = _input_filename.find_last_of('/');
if (pos != std::string::npos)
filename = _input_filename.substr(pos + 1);
else
filename = _input_filename;
return filename;
}
void
Parser::walkRaw(std::string /*fullpath*/, std::string /*nodepath*/, hit::Node * n)
{
InputParameters active_list_params = validParams<Action>();
InputParameters params = validParams<EmptyAction>();
std::string section_name = n->fullpath();
std::string curr_identifier = n->fullpath();
// Before we retrieve any actions or build any objects, make sure that the section they are in
// is active
if (!isSectionActive(curr_identifier, _root.get()))
return;
// Extract the block parameters before constructing the action
// There may be more than one Action registered for a given section in which case we need to
// build them all
bool is_parent;
std::string registered_identifier = _syntax.isAssociated(section_name, &is_parent);
// We need to retrieve a list of Actions associated with the current identifier
auto iters = _syntax.getActions(registered_identifier);
if (iters.first == iters.second)
{
_errmsg += hit::errormsg(getFileName(),
n,
"section '",
curr_identifier,
"' does not have an associated \"Action\".\nDid you misspell it?") +
"\n";
return;
}
for (auto it = iters.first; it != iters.second; ++it)
{
if (is_parent)
continue;
if (_syntax.isDeprecatedSyntax(registered_identifier))
mooseDeprecated(hit::errormsg(
getFileName(), n, _syntax.deprecatedActionSyntaxMessage(registered_identifier)));
params = _action_factory.getValidParams(it->second._action);
params.set<ActionWarehouse *>("awh") = &_action_wh;
extractParams(curr_identifier, params);
// Add the parsed syntax to the parameters object for consumption by the Action
params.set<std::string>("task") = it->second._task;
params.set<std::string>("registered_identifier") = registered_identifier;
params.blockLocation() = _input_filename + ":" + std::to_string(n->line());
params.blockFullpath() = n->fullpath();
// Create the Action
std::shared_ptr<Action> action_obj =
_action_factory.create(it->second._action, MooseUtils::shortName(curr_identifier), params);
{
// extract the MooseObject params if necessary
std::shared_ptr<MooseObjectAction> object_action =
std::dynamic_pointer_cast<MooseObjectAction>(action_obj);
if (object_action)
{
object_action->getObjectParams().blockLocation() = params.blockLocation();
object_action->getObjectParams().blockFullpath() = params.blockFullpath();
extractParams(curr_identifier, object_action->getObjectParams());
object_action->getObjectParams()
.set<std::vector<std::string>>("control_tags")
.push_back(MooseUtils::baseName(curr_identifier));
}
}
// add it to the warehouse
_action_wh.addActionBlock(action_obj);
}
}
void
Parser::walk(const std::string & fullpath, const std::string & nodepath, hit::Node * n)
{
// skip sections that were manually processed first.
for (auto & sec : _secs_need_first)
if (nodepath == sec)
return;
walkRaw(fullpath, nodepath, n);
}
std::string
Parser::hitCLIFilter(std::string appname, const std::vector<std::string> & argv)
{
std::string hit_text;
bool afterDoubleDash = false;
for (std::size_t i = 1; i < argv.size(); i++)
{
std::string arg(argv[i]);
// all args after a "--" are hit parameters
if (arg == "--")
{
afterDoubleDash = true;
continue;
} // otherwise try to guess if a hit params have started by looking for "=" and "/"
else if (arg.find("=", 0) != std::string::npos)
afterDoubleDash = true;
// skip over args that don't look like or are before hit parameters
if (!afterDoubleDash)
continue;
// skip arguments with no equals sign
if (arg.find("=", 0) == std::string::npos)
continue;
// skip cli flags (i.e. start with dash)
if (arg.find("-", 0) == 0)
continue;
if (appname == "main")
{
auto pos = arg.find(":", 0);
if (pos == 0) // trim leading colon
arg = arg.substr(pos + 1, arg.size() - pos - 1);
else if (pos != std::string::npos && pos < arg.find("=", 0)) // param is for non-main subapp
continue;
}
else // app we are loading is a multiapp subapp
{
std::string name;
std::string num;
pcrecpp::RE("(.*?)" // Match the multiapp name
"(\\d+)" // math the multiapp number
)
.FullMatch(appname, &name, &num);
auto pos = arg.find(":", 0);
if (pos == 0)
; // cli param is ":" prefixed meaning global for all main+subapps
else if (pos == std::string::npos) // param is for main app - skip
continue;
else if (arg.substr(0, pos) != appname &&
arg.substr(0, pos) != name) // param is for different multiapp - skip
{
_app.commandLine()->markHitParam(i);
continue;
}
arg = arg.substr(pos + 1, arg.size() - pos - 1); // trim off subapp name prefix
}
try
{
hit::check("CLI_ARG", arg);
hit_text += " " + arg;
// handle case where bash ate quotes around an empty string after the "="
if (arg.find("=", 0) == arg.size() - 1)
hit_text += "''";
_app.commandLine()->markHitParamUsed(i);
}
catch (hit::ParseError & err)
{
// bash might have eaten quotes around a hit string value or vector
// so try quoting after the "=" and reparse
auto quoted = arg;
auto pos = quoted.find("=", 0);
if (pos != std::string::npos)
quoted = arg.substr(0, pos + 1) + "'" + arg.substr(pos + 1, quoted.size() - pos) + "'";
try
{
hit::check("CLI_ARG", quoted);
hit_text += " " + quoted;
_app.commandLine()->markHitParamUsed(i);
}
catch (hit::ParseError & err)
{
mooseError("invalid hit in arg '", arg, "': ", err.what());
}
}
}
return hit_text;
}
void
Parser::parse(const std::string & input_filename)
{
// Save the filename
char abspath[PATH_MAX + 1];
realpath(input_filename.c_str(), abspath);
_input_filename = std::string(abspath);
// vector for initializing active blocks
std::vector<std::string> all = {"__all__"};
MooseUtils::checkFileReadable(_input_filename, true);
std::ifstream f(_input_filename);
std::string input((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
try
{
_root.reset(hit::parse(_input_filename, input));
auto cli_input = hitCLIFilter(_app.name(), _app.commandLine()->getArguments());
_cli_root.reset(hit::parse("CLI_ARGS", cli_input));
hit::explode(_cli_root.get());
hit::explode(_root.get());
hit::merge(_cli_root.get(), _root.get());
}
catch (hit::ParseError & err)
{
mooseError(err.what());
}
// expand ${bla} parameter values and mark/include variables used in expansions as "used". This
// MUST occur before parameter extraction - otherwise parameters will get wrong values.
hit::RawEvaler raw;
hit::EnvEvaler env;
hit::ReplaceEvaler repl;
FuncParseEvaler fparse_ev;
hit::BraceExpander exw(_input_filename);
exw.registerEvaler("raw", raw);
exw.registerEvaler("env", env);
exw.registerEvaler("fparse", fparse_ev);
exw.registerEvaler("replace", repl);
_root->walk(&exw);
for (auto & var : exw.used)
_extracted_vars.insert(var);
for (auto & msg : exw.errors)
_errmsg += msg + "\n";
// do as much error checking as early as possible so that errors are more useful instead
// of surprising and disconnected from what caused them.
DupParamWalker dw(_input_filename);
BadActiveWalker bw(_input_filename);
_root->walk(&dw, hit::NodeType::Field);
_root->walk(&bw, hit::NodeType::Section);
for (auto & msg : dw.errors)
_errmsg += msg + "\n";
for (auto & msg : bw.errors)
_errmsg += msg + "\n";
// There are a few order dependent actions that have to be built first in
// order for the parser and application to function properly:
//
// SetupDebugAction: This action can contain an option for monitoring the parser progress. It must
// be parsed first to capture all of the parsing output.
//
// GlobalParamsAction: This action is checked during the parameter extraction routines of all
// subsequent blocks. It must be parsed early since it must exist during
// subsequent parameter extraction.
//
// DynamicObjectRegistration: This action must be built before any MooseObjectActions are built.
// This is because we retrieve valid parameters from the Factory
// during parse time. Objects must be registered before
// validParameters can be retrieved.
auto syntax = _syntax.getSyntaxByAction("SetupDebugAction");
std::copy(syntax.begin(), syntax.end(), std::back_inserter(_secs_need_first));
syntax = _syntax.getSyntaxByAction("GlobalParamsAction");
std::copy(syntax.begin(), syntax.end(), std::back_inserter(_secs_need_first));
syntax = _syntax.getSyntaxByAction("DynamicObjectRegistrationAction");
std::copy(syntax.begin(), syntax.end(), std::back_inserter(_secs_need_first));
// walk all the sections extracting paramters from each into InputParameters objects
for (auto & sec : _secs_need_first)
{
auto n = _root->find(sec);
if (n)
walkRaw(n->parent()->fullpath(), n->path(), n);
}
_root->walk(this, hit::NodeType::Section);
if (_errmsg.size() > 0)
mooseError(_errmsg);
}
// Checks the input and the way it has been used and emits any errors/warnings.
// This has to be a separate function because for we don't know if some parameters were unused
// until all the multiapps/subapps have been fully initialized - which isn't complete until
// *after* all the other member functions on Parser have been run. So this is here to be
// externally called at the right time.
void
Parser::errorCheck(const Parallel::Communicator & comm, bool warn_unused, bool err_unused)
{
// this if guard is important in case the simulation was not configured via parsed input text -
// e.g. configured programatically.
if (!_root || !_cli_root)
return;
UnusedWalker uw(_input_filename, _extracted_vars, *this);
UnusedWalker uwcli("CLI_ARG", _extracted_vars, *this);
_root->walk(&uw);
_cli_root->walk(&uwcli);
auto cli = _app.commandLine();
if (warn_unused)
{
for (auto arg : cli->unused(comm))
_warnmsg += hit::errormsg("CLI_ARG",
nullptr,
"unused command line parameter '",
cli->getArguments()[arg],
"'") +
"\n";
for (auto & msg : uwcli.errors)
_warnmsg += msg + "\n";
for (auto & msg : uw.errors)
_warnmsg += msg + "\n";
}
else if (err_unused)
{
for (auto arg : cli->unused(comm))
_errmsg += hit::errormsg("CLI_ARG",
nullptr,
"unused command line parameter '",
cli->getArguments()[arg],
"'") +
"\n";
for (auto & msg : uwcli.errors)
_errmsg += msg + "\n";
for (auto & msg : uw.errors)
_errmsg += msg + "\n";
}
if (_warnmsg.size() > 0)
mooseUnused(_warnmsg);
if (_errmsg.size() > 0)
mooseError(_errmsg);
}
void
Parser::initSyntaxFormatter(SyntaxFormatterType type, bool dump_mode)
{
switch (type)
{
case INPUT_FILE:
_syntax_formatter = libmesh_make_unique<InputFileFormatter>(dump_mode);
break;
case YAML:
_syntax_formatter = libmesh_make_unique<YAMLFormatter>(dump_mode);
break;
default:
mooseError("Unrecognized Syntax Formatter requested");
break;
}
}
void
Parser::buildJsonSyntaxTree(JsonSyntaxTree & root) const
{
std::vector<std::pair<std::string, Syntax::ActionInfo>> all_names;
for (const auto & iter : _syntax.getAssociatedTypes())
root.addSyntaxType(iter.first, iter.second);
for (const auto & iter : _syntax.getAssociatedActions())
{
Syntax::ActionInfo act_info = iter.second;
/**
* If the task is nullptr that means we need to figure out which task goes with this syntax for
* the purpose of building the Moose Object part of the tree. We will figure this out by asking
* the ActionFactory for the registration info.
*/
if (act_info._task == "")
act_info._task = _action_factory.getTaskName(act_info._action);
all_names.push_back(std::make_pair(iter.first, act_info));
}
for (const auto & act_names : all_names)
{
const auto & act_info = act_names.second;
const std::string & action = act_info._action;
const std::string & task = act_info._task;
const std::string act_name = act_names.first;
InputParameters action_obj_params = _action_factory.getValidParams(action);
bool params_added = root.addParameters("",
act_name,
false,
action,
true,
&action_obj_params,
_syntax.getLineInfo(act_name, action, ""),
"");
if (params_added)
{
auto tasks = _action_factory.getTasksByAction(action);
for (auto & t : tasks)
{
auto info = _action_factory.getLineInfo(action, t);
root.addActionTask(act_name, action, t, info);
}
}
/**
* We need to see if this action is inherited from MooseObjectAction. If it is, then we will
* loop over all the Objects in MOOSE's Factory object to print them out if they have associated
* bases matching the current task.
*/
if (action_obj_params.have_parameter<bool>("isObjectAction") &&
action_obj_params.get<bool>("isObjectAction"))
{
for (registeredMooseObjectIterator moose_obj = _factory.registeredObjectsBegin();
moose_obj != _factory.registeredObjectsEnd();
++moose_obj)
{
InputParameters moose_obj_params = (moose_obj->second)();
// Now that we know that this is a MooseObjectAction we need to see if it has been
// restricted
// in any way by the user.
const std::vector<std::string> & buildable_types = action_obj_params.getBuildableTypes();
std::string moose_obj_name = moose_obj->first;
// See if the current Moose Object syntax belongs under this Action's block
if ((buildable_types.empty() || // Not restricted
std::find(buildable_types.begin(), buildable_types.end(), moose_obj->first) !=
buildable_types.end()) && // Restricted but found
moose_obj_params.have_parameter<std::string>("_moose_base") && // Has a registered base
_syntax.verifyMooseObjectTask(moose_obj_params.get<std::string>("_moose_base"),
task) && // and that base is associated
action_obj_params.mooseObjectSyntaxVisibility() && // and the Action says it's visible
moose_obj_name.find("<JACOBIAN>") ==
std::string::npos) // And it is not a Jacobian templated AD object
{
std::string name;
size_t pos = 0;
bool is_action_params = false;
bool is_type = false;
if (act_name[act_name.size() - 1] == '*')
{
pos = act_name.size();
if (!action_obj_params.collapseSyntaxNesting())
name = act_name.substr(0, pos - 1) + moose_obj_name;
else
{
name = act_name.substr(0, pos - 1) + "/<type>/" + moose_obj_name;
is_action_params = true;
}
}
else
{
name = act_name + "/<type>/" + moose_obj_name;
is_type = true;
}
moose_obj_params.set<std::string>("type") = moose_obj_name;
auto lineinfo = _factory.getLineInfo(moose_obj_name);
std::string classname = _factory.associatedClassName(moose_obj_name);
name = name.substr(0, name.find("<RESIDUAL>"));
moose_obj_name = moose_obj_name.substr(0, moose_obj_name.find("<RESIDUAL>"));
classname = classname.substr(0, classname.find("<RESIDUAL>"));
root.addParameters(act_name,
name,
is_type,
moose_obj_name,
is_action_params,
&moose_obj_params,
lineinfo,
classname);
}
}
}
}
root.addGlobal();
}
void
Parser::buildFullTree(const std::string & search_string)
{
std::vector<std::pair<std::string, Syntax::ActionInfo>> all_names;
for (const auto & iter : _syntax.getAssociatedActions())
{
Syntax::ActionInfo act_info = iter.second;
/**
* If the task is nullptr that means we need to figure out which task goes with this syntax for
* the purpose of building the Moose Object part of the tree. We will figure this out by asking
* the ActionFactory for the registration info.
*/
if (act_info._task == "")
act_info._task = _action_factory.getTaskName(act_info._action);
all_names.push_back(std::pair<std::string, Syntax::ActionInfo>(iter.first, act_info));
}
for (const auto & act_names : all_names)
{
InputParameters action_obj_params = _action_factory.getValidParams(act_names.second._action);
_syntax_formatter->insertNode(
act_names.first, act_names.second._action, true, &action_obj_params);
const std::string & task = act_names.second._task;
std::string act_name = act_names.first;
/**
* We need to see if this action is inherited from MooseObjectAction. If it is, then we will
* loop over all the Objects in MOOSE's Factory object to print them out if they have associated
* bases matching the current task.
*/
if (action_obj_params.have_parameter<bool>("isObjectAction") &&
action_obj_params.get<bool>("isObjectAction"))
{
for (registeredMooseObjectIterator moose_obj = _factory.registeredObjectsBegin();
moose_obj != _factory.registeredObjectsEnd();
++moose_obj)
{
InputParameters moose_obj_params = (moose_obj->second)();
/**
* Now that we know that this is a MooseObjectAction we need to see if it has been
* restricted in any way by the user.
*/
const std::vector<std::string> & buildable_types = action_obj_params.getBuildableTypes();
// See if the current Moose Object syntax belongs under this Action's block
if ((buildable_types.empty() || // Not restricted
std::find(buildable_types.begin(), buildable_types.end(), moose_obj->first) !=
buildable_types.end()) && // Restricted but found
moose_obj_params.have_parameter<std::string>("_moose_base") && // Has a registered base
_syntax.verifyMooseObjectTask(moose_obj_params.get<std::string>("_moose_base"),
task) && // and that base is associated
action_obj_params.mooseObjectSyntaxVisibility() && // and the Action says it's visible
moose_obj->first.find("<JACOBIAN>") ==
std::string::npos) // And it is not a Jacobian templated AD object
{
std::string name;
size_t pos = 0;
bool is_action_params = false;
if (act_name[act_name.size() - 1] == '*')
{
pos = act_name.size();
// Remove <RESIDUAL> append for AD objects
std::string obj_name = moose_obj->first;
removeSubstring(obj_name, "<RESIDUAL>");
if (!action_obj_params.collapseSyntaxNesting())
name = act_name.substr(0, pos - 1) + obj_name;
else
{
name = act_name.substr(0, pos - 1) + "/<type>/" + moose_obj->first;
is_action_params = true;
}
}
else
{
name = act_name + "/<type>/" + moose_obj->first;
}
moose_obj_params.set<std::string>("type") = moose_obj->first;
_syntax_formatter->insertNode(
name, moose_obj->first, is_action_params, &moose_obj_params);
}
}
}
}
// Do not change to _console, we need this printed to the stdout in all cases
Moose::out << _syntax_formatter->print(search_string) << std::flush;
}
/**************************************************************************************************
**************************************************************************************************
* Parameter Extraction Routines *
**************************************************************************************************
**************************************************************************************************/
using std::string;
// Template Specializations for retrieving special types from the input file
template <>
void Parser::setScalarParameter<RealVectorValue, RealVectorValue>(
const std::string & full_name,
const std::string & short_name,
InputParameters::Parameter<RealVectorValue> * param,
bool in_global,
GlobalParamsAction * global_block);
template <>
void Parser::setScalarParameter<Point, Point>(const std::string & full_name,
const std::string & short_name,
InputParameters::Parameter<Point> * param,
bool in_global,
GlobalParamsAction * global_block);
template <>
void Parser::setScalarParameter<RealEigenVector, RealEigenVector>(
const std::string & full_name,
const std::string & short_name,
InputParameters::Parameter<RealEigenVector> * param,
bool in_global,
GlobalParamsAction * global_block);
template <>
void Parser::setScalarParameter<RealEigenMatrix, RealEigenMatrix>(
const std::string & full_name,
const std::string & short_name,
InputParameters::Parameter<RealEigenMatrix> * param,
bool in_global,
GlobalParamsAction * global_block);
template <>
void Parser::setScalarParameter<PostprocessorName, PostprocessorName>(
const std::string & full_name,
const std::string & short_name,
InputParameters::Parameter<PostprocessorName> * param,
bool in_global,
GlobalParamsAction * global_block);
template <>
void Parser::setScalarParameter<MooseEnum, MooseEnum>(const std::string & full_name,
const std::string & short_name,
InputParameters::Parameter<MooseEnum> * param,
bool in_global,
GlobalParamsAction * global_block);
template <>
void Parser::setScalarParameter<MultiMooseEnum, MultiMooseEnum>(
const std::string & full_name,
const std::string & short_name,
InputParameters::Parameter<MultiMooseEnum> * param,
bool in_global,
GlobalParamsAction * global_block);
template <>
void Parser::setScalarParameter<ExecFlagEnum, ExecFlagEnum>(
const std::string & full_name,
const std::string & short_name,
InputParameters::Parameter<ExecFlagEnum> * param,
bool in_global,
GlobalParamsAction * global_block);
template <>
void Parser::setScalarParameter<RealTensorValue, RealTensorValue>(
const std::string & full_name,
const std::string & short_name,
InputParameters::Parameter<RealTensorValue> * param,
bool in_global,
GlobalParamsAction * global_block);
// Vectors
template <>
void Parser::setVectorParameter<RealVectorValue, RealVectorValue>(
const std::string & full_name,
const std::string & short_name,
InputParameters::Parameter<std::vector<RealVectorValue>> * param,
bool in_global,
GlobalParamsAction * global_block);
template <>
void
Parser::setVectorParameter<Point, Point>(const std::string & full_name,
const std::string & short_name,
InputParameters::Parameter<std::vector<Point>> * param,
bool in_global,
GlobalParamsAction * global_block);
template <>
void Parser::setVectorParameter<MooseEnum, MooseEnum>(
const std::string & full_name,
const std::string & short_name,
InputParameters::Parameter<std::vector<MooseEnum>> * param,
bool in_global,
GlobalParamsAction * global_block);
template <>
void Parser::setVectorParameter<VariableName, VariableName>(
const std::string & full_name,
const std::string & short_name,
InputParameters::Parameter<std::vector<VariableName>> * param,
bool in_global,
GlobalParamsAction * global_block);
void
Parser::extractParams(const std::string & prefix, InputParameters & p)
{
std::ostringstream error_stream;
static const std::string global_params_task = "set_global_params";
static const std::string global_params_block_name =
_syntax.getSyntaxByAction("GlobalParamsAction").front();
ActionIterator act_iter = _action_wh.actionBlocksWithActionBegin(global_params_task);
GlobalParamsAction * global_params_block = nullptr;
// We are grabbing only the first
if (act_iter != _action_wh.actionBlocksWithActionEnd(global_params_task))
global_params_block = dynamic_cast<GlobalParamsAction *>(*act_iter);
// Set a pointer to the current InputParameters object being parsed so that it can be referred
// to
// in the extraction routines
_current_params = &p;
_current_error_stream = &error_stream;
for (const auto & it : p)
{
if (p.shouldIgnore(it.first))
continue;
bool found = false;