Line data Source code
1 : //* This file is part of the MOOSE framework
2 : //* https://mooseframework.inl.gov
3 : //*
4 : //* All rights reserved, see COPYRIGHT for full restrictions
5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 : //*
7 : //* Licensed under LGPL 2.1, please see LICENSE for details
8 : //* https://www.gnu.org/licenses/lgpl-2.1.html
9 :
10 : // Standard includes
11 : #include <math.h>
12 :
13 : // MOOSE includes
14 : #include "AdvancedOutput.h"
15 : #include "DisplacedProblem.h"
16 : #include "FEProblem.h"
17 : #include "FileMesh.h"
18 : #include "FileOutput.h"
19 : #include "InfixIterator.h"
20 : #include "MooseApp.h"
21 : #include "MooseUtils.h"
22 : #include "MooseVariableFE.h"
23 : #include "Postprocessor.h"
24 : #include "Restartable.h"
25 : #include "VectorPostprocessor.h"
26 :
27 : #include "libmesh/fe_interface.h"
28 :
29 : using namespace libMesh;
30 :
31 : // A function, only available in this file, for adding the AdvancedOutput parameters. This is
32 : // used to eliminate code duplication between the difference specializations of the validParams
33 : // function.
34 : namespace
35 : {
36 : void
37 280337 : addAdvancedOutputParams(InputParameters & params)
38 : {
39 : // Hide/show variable output options
40 1121348 : params.addParam<std::vector<VariableName>>(
41 : "hide",
42 : {},
43 : "A list of the variables and postprocessors that should NOT be output to the Exodus "
44 : "file (may include Variables, ScalarVariables, and Postprocessor names).");
45 :
46 1121348 : params.addParam<std::vector<VariableName>>(
47 : "show",
48 : {},
49 : "A list of the variables and postprocessors that should be output to the Exodus file "
50 : "(may include Variables, ScalarVariables, and Postprocessor names).");
51 :
52 : // Enable output of PP/VPP to JSON
53 841011 : params.addParam<bool>(
54 560674 : "postprocessors_as_reporters", false, "Output Postprocessors values as Reporter values.");
55 841011 : params.addParam<bool>("vectorpostprocessors_as_reporters",
56 560674 : false,
57 : "Output VectorsPostprocessors vectors as Reporter values.");
58 :
59 : // Group for selecting the output
60 1121348 : params.addParamNamesToGroup("hide show", "Selection/restriction of output");
61 :
62 : // Group for converting outputs
63 1121348 : params.addParamNamesToGroup("postprocessors_as_reporters vectorpostprocessors_as_reporters",
64 : "Conversions before output");
65 :
66 : // **** DEPRECATED PARAMS ****
67 1401685 : params.addDeprecatedParam<bool>("output_postprocessors",
68 560674 : true,
69 : "Enable/disable the output of postprocessors",
70 : "'execute_postprocessors_on' has replaced this parameter");
71 1401685 : params.addDeprecatedParam<bool>("execute_vector_postprocessors",
72 560674 : true,
73 : "Enable/disable the output of vector postprocessors",
74 : "'execute_vector_postprocessors_on' has replaced this parameter");
75 1401685 : params.addDeprecatedParam<bool>("execute_system_information",
76 560674 : true,
77 : "Enable/disable the output of the simulation information",
78 : "'execute_system_information_on' has replaced this parameter");
79 1401685 : params.addDeprecatedParam<bool>("execute_elemental_variables",
80 560674 : true,
81 : "Enable/disable the output of elemental variables",
82 : "'execute_elemental_on' has replaced this parameter");
83 1401685 : params.addDeprecatedParam<bool>("execute_nodal_variables",
84 560674 : true,
85 : "Enable/disable the output of nodal variables",
86 : "'execute_nodal_on' has replaced this parameter");
87 1401685 : params.addDeprecatedParam<bool>("execute_scalar_variables",
88 841011 : true,
89 : "Enable/disable the output of aux scalar variables",
90 : "'execute_scalars_on' has replaced this parameter");
91 1121348 : params.addDeprecatedParam<bool>("execute_input",
92 560674 : true,
93 : "Enable/disable the output of input file information",
94 : "'execute_input_on' has replaced this parameter");
95 280337 : }
96 : }
97 :
98 : InputParameters
99 280337 : AdvancedOutput::validParams()
100 : {
101 : // Get the parameters from the parent object
102 280337 : InputParameters params = FileOutput::validParams();
103 280337 : addAdvancedOutputParams(params);
104 280337 : return params;
105 0 : }
106 :
107 : // Defines the output types to enable for the AdvancedOutput object
108 : MultiMooseEnum
109 398322 : AdvancedOutput::getOutputTypes()
110 : {
111 : return MultiMooseEnum("nodal=0 elemental=1 scalar=2 postprocessor=3 vector_postprocessor=4 "
112 796644 : "input=5 system_information=6 reporter=7");
113 : }
114 :
115 : // Enables the output types (see getOutputTypes) for an AdvancedOutput object
116 : InputParameters
117 398322 : AdvancedOutput::enableOutputTypes(const std::string & names)
118 : {
119 : // The parameters object that will be returned
120 398322 : InputParameters params = emptyInputParameters();
121 :
122 : // Get the MultiEnum of output types
123 398322 : MultiMooseEnum output_types = getOutputTypes();
124 :
125 : // Update the enum of output types to append
126 398322 : if (names.empty())
127 0 : output_types = output_types.getRawNames();
128 : else
129 398322 : output_types = names;
130 :
131 : // Add the parameters and return them
132 398322 : addValidParams(params, output_types);
133 796644 : return params;
134 398322 : }
135 :
136 : // Constructor
137 116292 : AdvancedOutput::AdvancedOutput(const InputParameters & parameters)
138 : : FileOutput(parameters),
139 190113 : _elemental_as_nodal(isParamValid("elemental_as_nodal") ? getParam<bool>("elemental_as_nodal")
140 : : false),
141 306396 : _scalar_as_nodal(isParamValid("scalar_as_nodal") ? getParam<bool>("scalar_as_nodal") : false),
142 116283 : _reporter_data(_problem_ptr->getReporterData()),
143 232566 : _last_execute_time(declareRecoverableData<std::map<std::string, Real>>("last_execute_time")),
144 232566 : _postprocessors_as_reporters(getParam<bool>("postprocessors_as_reporters")),
145 465141 : _vectorpostprocessors_as_reporters(getParam<bool>("vectorpostprocessors_as_reporters"))
146 : {
147 116283 : _is_advanced = true;
148 116283 : _advanced_execute_on = OutputOnWarehouse(_execute_on, parameters);
149 116283 : }
150 :
151 : void
152 112815 : AdvancedOutput::initialSetup()
153 : {
154 112815 : init();
155 112800 : }
156 :
157 : void
158 356453 : AdvancedOutput::init()
159 : {
160 : // Initialize the execution flags
161 2292605 : for (auto & [name, input] : _advanced_execute_on)
162 1936152 : initExecutionTypes(name, input);
163 :
164 : // Clear existing execute information lists
165 356453 : _execute_data.reset();
166 :
167 : // Initialize the available output
168 356453 : initAvailableLists();
169 :
170 : // Separate the hide/show list into components
171 1425794 : initShowHideLists(getParam<std::vector<VariableName>>("show"),
172 : getParam<std::vector<VariableName>>("hide"));
173 :
174 : // If 'elemental_as_nodal = true' the elemental variable names must be appended to the
175 : // nodal variable names. Thus, when libMesh::EquationSystem::build_solution_vector is called
176 : // it will create the correct nodal variable from the elemental
177 356444 : if (_elemental_as_nodal)
178 : {
179 3086 : OutputData & nodal = _execute_data["nodal"];
180 3086 : OutputData & elemental = _execute_data["elemental"];
181 1543 : nodal.show.insert(elemental.show.begin(), elemental.show.end());
182 1543 : nodal.hide.insert(elemental.hide.begin(), elemental.hide.end());
183 1543 : nodal.available.insert(elemental.available.begin(), elemental.available.end());
184 : }
185 :
186 : // Similarly as above, if 'scalar_as_nodal = true' append the elemental variable lists
187 356444 : if (_scalar_as_nodal)
188 : {
189 136 : OutputData & nodal = _execute_data["nodal"];
190 136 : OutputData & scalar = _execute_data["scalars"];
191 68 : nodal.show.insert(scalar.show.begin(), scalar.show.end());
192 68 : nodal.hide.insert(scalar.hide.begin(), scalar.hide.end());
193 68 : nodal.available.insert(scalar.available.begin(), scalar.available.end());
194 : }
195 :
196 : // Initialize the show/hide/output lists for each of the types of output
197 2495081 : for (auto & it : _execute_data)
198 2138643 : initOutputList(it.second);
199 356438 : }
200 :
201 112586 : AdvancedOutput::~AdvancedOutput() {}
202 :
203 : void
204 0 : AdvancedOutput::outputNodalVariables()
205 : {
206 0 : mooseError("Individual output of nodal variables is not support for the output object named '",
207 0 : name(),
208 : "'");
209 : }
210 :
211 : void
212 0 : AdvancedOutput::outputElementalVariables()
213 : {
214 0 : mooseError(
215 : "Individual output of elemental variables is not support for this output object named '",
216 0 : name(),
217 : "'");
218 : }
219 :
220 : void
221 0 : AdvancedOutput::outputPostprocessors()
222 : {
223 0 : mooseError("Individual output of postprocessors is not support for this output object named '",
224 0 : name(),
225 : "'");
226 : }
227 :
228 : void
229 0 : AdvancedOutput::outputVectorPostprocessors()
230 : {
231 0 : mooseError(
232 : "Individual output of VectorPostprocessors is not support for this output object named '",
233 0 : name(),
234 : "'");
235 : }
236 :
237 : void
238 0 : AdvancedOutput::outputScalarVariables()
239 : {
240 0 : mooseError(
241 0 : "Individual output of scalars is not support for this output object named '", name(), "'");
242 : }
243 :
244 : void
245 0 : AdvancedOutput::outputSystemInformation()
246 : {
247 0 : mooseError(
248 0 : "Output of system information is not support for this output object named '", name(), "'");
249 : }
250 :
251 : void
252 0 : AdvancedOutput::outputInput()
253 : {
254 0 : mooseError("Output of the input file information is not support for this output object named '",
255 0 : name(),
256 : "'");
257 : }
258 :
259 : void
260 0 : AdvancedOutput::outputReporters()
261 : {
262 0 : mooseError(
263 0 : "Output of the Reporter value(s) is not support for this output object named '", name(), "'");
264 : }
265 :
266 : bool
267 8348907 : AdvancedOutput::shouldOutput()
268 : {
269 8348907 : if (!checkFilename())
270 544 : return false;
271 :
272 8348363 : if (hasOutput(_current_execute_flag))
273 401162 : return true;
274 : else
275 7947201 : return Output::shouldOutput();
276 : }
277 :
278 : void
279 243638 : AdvancedOutput::output()
280 : {
281 243638 : const auto & type = _current_execute_flag;
282 :
283 : // (re)initialize the list of available items for output
284 243638 : init();
285 :
286 : // Call the various output types, if data exists
287 487276 : if (wantOutput("nodal", type))
288 : {
289 150231 : outputNodalVariables();
290 450693 : _last_execute_time["nodal"] = _time;
291 : }
292 :
293 487276 : if (wantOutput("elemental", type))
294 : {
295 34834 : outputElementalVariables();
296 104502 : _last_execute_time["elemental"] = _time;
297 : }
298 :
299 487276 : if (wantOutput("postprocessors", type))
300 : {
301 100376 : outputPostprocessors();
302 301128 : _last_execute_time["postprocessors"] = _time;
303 : }
304 :
305 487276 : if (wantOutput("vector_postprocessors", type))
306 : {
307 8165 : outputVectorPostprocessors();
308 24495 : _last_execute_time["vector_postprocessors"] = _time;
309 : }
310 :
311 487276 : if (wantOutput("scalars", type))
312 : {
313 13371 : outputScalarVariables();
314 40113 : _last_execute_time["scalars"] = _time;
315 : }
316 :
317 487276 : if (wantOutput("system_information", type))
318 : {
319 729 : outputSystemInformation();
320 2187 : _last_execute_time["system_information"] = _time;
321 : }
322 :
323 487276 : if (wantOutput("input", type))
324 : {
325 33736 : outputInput();
326 101208 : _last_execute_time["input"] = _time;
327 : }
328 :
329 487276 : if (wantOutput("reporters", type))
330 : {
331 4645 : outputReporters();
332 13935 : _last_execute_time["reporters"] = _time;
333 : }
334 243638 : }
335 :
336 : void
337 8109 : AdvancedOutput::clearLastExecuteTime()
338 : {
339 8109 : _last_execute_time.clear();
340 8109 : }
341 :
342 : bool
343 63574142 : AdvancedOutput::wantOutput(const std::string & name, const ExecFlagType & type)
344 : {
345 : // Ignore EXEC_FORCED for system information and input, there is no reason to force this
346 63574142 : if (type == EXEC_FORCED && (name == "system_information" || name == "input"))
347 8824 : return false;
348 :
349 : // Do not output if the 'none' is contained by the execute_on
350 189386622 : if (_advanced_execute_on.contains(name) && _advanced_execute_on[name].isValueSet("none"))
351 26360 : return false;
352 :
353 : // Data output flag, true if data exists to be output
354 63538958 : bool execute_data_flag = true;
355 :
356 : // Set flag to false, if the OutputData exists and the output variable list is empty
357 63538958 : std::map<std::string, OutputData>::const_iterator iter = _execute_data.find(name);
358 63538958 : if (iter != _execute_data.end() && iter->second.output.empty())
359 35133032 : execute_data_flag = false;
360 :
361 : // Set flag to false, if the OutputOnWarehouse DOES NOT contain an entry
362 63538958 : if (!_advanced_execute_on.contains(name))
363 654666 : execute_data_flag = false;
364 :
365 : // Force the output, if there is something to output and the time has not been output
366 63538958 : if (type == EXEC_FORCED && execute_data_flag && _last_execute_time[name] != _time)
367 2308 : return true;
368 :
369 : // Return true (output should occur) if three criteria are satisfied, else do not output:
370 : // (1) The execute_data_flag = true (i.e, there is data to output)
371 : // (2) The current output type is contained in the list of output execution types
372 : // (3) The current execution time is "final" or "forced" and the data has not already been
373 : // output
374 64530441 : if (execute_data_flag && _advanced_execute_on[name].isValueSet(type) &&
375 993791 : !(type == EXEC_FINAL && _last_execute_time[name] == _time))
376 992821 : return true;
377 : else
378 62543829 : return false;
379 : }
380 :
381 : bool
382 8348363 : AdvancedOutput::hasOutput(const ExecFlagType & type)
383 : {
384 : // If any of the component outputs are true, then there is some output to perform
385 53637340 : for (const auto & it : _advanced_execute_on)
386 45690139 : if (wantOutput(it.first, type))
387 401162 : return true;
388 :
389 : // There is nothing to output
390 7947201 : return false;
391 : }
392 :
393 : bool
394 36564 : AdvancedOutput::hasOutput()
395 : {
396 : // Test that variables exist for output AND that output execution flags are valid
397 58624 : for (const auto & it : _execute_data)
398 95188 : if (!(it.second).output.empty() && _advanced_execute_on.contains(it.first) &&
399 36564 : _advanced_execute_on[it.first].isValid())
400 36564 : return true;
401 :
402 : // Test execution flags for non-variable output
403 0 : if (_advanced_execute_on.contains("system_information") &&
404 0 : _advanced_execute_on["system_information"].isValid())
405 0 : return true;
406 0 : if (_advanced_execute_on.contains("input") && _advanced_execute_on["input"].isValid())
407 0 : return true;
408 :
409 0 : return false;
410 : }
411 :
412 : void
413 356453 : AdvancedOutput::initAvailableLists()
414 : {
415 : // Initialize Postprocessor list
416 : // This flag is set to true if any postprocessor has the 'outputs' parameter set, it is then used
417 : // to produce an warning if postprocessor output is disabled
418 356453 : if (!_postprocessors_as_reporters)
419 712723 : initPostprocessorOrVectorPostprocessorLists<Postprocessor>("postprocessors");
420 :
421 : // Initialize vector postprocessor list
422 : // This flag is set to true if any vector postprocessor has the 'outputs' parameter set, it is
423 : // then used
424 : // to produce an warning if vector postprocessor output is disabled
425 356450 : if (!_vectorpostprocessors_as_reporters)
426 712220 : initPostprocessorOrVectorPostprocessorLists<VectorPostprocessor>("vector_postprocessors");
427 :
428 : // Get a list of the available variables
429 356450 : std::vector<VariableName> variables = _problem_ptr->getVariableNames();
430 :
431 : // Loop through the variables and store the names in the correct available lists
432 1440466 : for (const auto & var_name : variables)
433 : {
434 1084016 : if (_problem_ptr->hasVariable(var_name))
435 : {
436 1058752 : MooseVariableFEBase & var = _problem_ptr->getVariable(
437 : 0, var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_ANY);
438 :
439 : // Skip if the 'outputs' parameter has been set to exclude this output
440 3176256 : if (var.isParamValid("outputs"))
441 : {
442 39932 : const auto & outputs = var.getParam<std::vector<OutputName>>("outputs");
443 39726 : if (outputs.size() && std::find(outputs.begin(), outputs.end(), name()) == outputs.end() &&
444 19760 : outputs[0] != "all")
445 19760 : continue;
446 : }
447 :
448 1038992 : const FEType type = var.feType();
449 2091205 : for (unsigned int i = 0; i < var.count(); ++i)
450 : {
451 1052213 : VariableName vname = var_name;
452 1052213 : if (var.isArray())
453 22320 : vname = var.arrayVariableComponent(i);
454 :
455 : // A note that if we have p-refinement we assume "worst-case" scenario that our constant
456 : // monomial/monomial-vec families have been refined and we can no longer write them as
457 : // elemental
458 1326467 : if (type.order == CONSTANT && !_problem_ptr->havePRefinement() &&
459 274254 : type.family != MONOMIAL_VEC)
460 820818 : _execute_data["elemental"].available.insert(vname);
461 778607 : else if (FEInterface::field_type(type) == TYPE_VECTOR)
462 : {
463 1016 : const auto geom_type = ((type.family == MONOMIAL_VEC) && (type.order == CONSTANT) &&
464 648 : !_problem_ptr->havePRefinement())
465 7273 : ? "elemental"
466 6257 : : "nodal";
467 6257 : switch (_es_ptr->get_mesh().spatial_dimension())
468 : {
469 346 : case 0:
470 : case 1:
471 692 : _execute_data[geom_type].available.insert(vname);
472 346 : break;
473 4427 : case 2:
474 8854 : _execute_data[geom_type].available.insert(vname + "_x");
475 8854 : _execute_data[geom_type].available.insert(vname + "_y");
476 4427 : break;
477 1484 : case 3:
478 2968 : _execute_data[geom_type].available.insert(vname + "_x");
479 2968 : _execute_data[geom_type].available.insert(vname + "_y");
480 2968 : _execute_data[geom_type].available.insert(vname + "_z");
481 1484 : break;
482 : }
483 : }
484 : else
485 2317050 : _execute_data["nodal"].available.insert(vname);
486 1052213 : }
487 : }
488 :
489 25264 : else if (_problem_ptr->hasScalarVariable(var_name))
490 75792 : _execute_data["scalars"].available.insert(var_name);
491 : }
492 :
493 : // Initialize Reporter name list
494 819822 : for (auto && r_name : _reporter_data.getReporterNames())
495 585229 : if ((_postprocessors_as_reporters || !r_name.isPostprocessor()) &&
496 121857 : (_vectorpostprocessors_as_reporters || !r_name.isVectorPostprocessor()))
497 450410 : _execute_data["reporters"].available.insert(r_name);
498 356450 : }
499 :
500 : void
501 1936152 : AdvancedOutput::initExecutionTypes(const std::string & name, ExecFlagEnum & input)
502 : {
503 : // Build the input parameter name
504 1936152 : std::string param_name = "execute_";
505 1936152 : param_name += name + "_on";
506 :
507 : // The parameters exists and has been set by the user
508 1936152 : if (_pars.have_parameter<ExecFlagEnum>(param_name) && isParamValid(param_name))
509 506517 : input = getParam<ExecFlagEnum>(param_name);
510 :
511 : // If the parameter does not exists; set it to a state where no valid entries exists so nothing
512 : // gets executed
513 1429635 : else if (!_pars.have_parameter<ExecFlagEnum>(param_name))
514 : {
515 0 : input = _execute_on;
516 0 : input.clearSetValues();
517 : }
518 1936152 : }
519 :
520 : void
521 356450 : AdvancedOutput::initShowHideLists(const std::vector<VariableName> & show,
522 : const std::vector<VariableName> & hide)
523 : {
524 :
525 : // Storage for user-supplied input that is unknown as a variable or postprocessor
526 356450 : std::set<std::string> unknown;
527 :
528 : // If a show hide/list exists, let the data warehouse know about it. This allows for the proper
529 : // handling of output lists (see initOutputList)
530 356450 : if (show.size() > 0)
531 2073 : _execute_data.setHasShowList(true);
532 :
533 : // Populate the show lists
534 359472 : for (const auto & var_name : show)
535 : {
536 3022 : if (_problem_ptr->hasVariable(var_name))
537 : {
538 1202 : MooseVariableFEBase & var = _problem_ptr->getVariable(
539 : 0, var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_ANY);
540 1202 : const FEType type = var.feType();
541 2404 : for (unsigned int i = 0; i < var.count(); ++i)
542 : {
543 1202 : VariableName vname = var_name;
544 1202 : if (var.isArray())
545 0 : vname = var.arrayVariableComponent(i);
546 :
547 1202 : if (type.order == CONSTANT)
548 387 : _execute_data["elemental"].show.insert(vname);
549 1073 : else if (FEInterface::field_type(type) == TYPE_VECTOR)
550 : {
551 : const auto geom_type =
552 0 : ((type.family == MONOMIAL_VEC) && (type.order == CONSTANT)) ? "elemental" : "nodal";
553 0 : switch (_es_ptr->get_mesh().spatial_dimension())
554 : {
555 0 : case 0:
556 : case 1:
557 0 : _execute_data[geom_type].show.insert(vname);
558 0 : break;
559 0 : case 2:
560 0 : _execute_data[geom_type].show.insert(vname + "_x");
561 0 : _execute_data[geom_type].show.insert(vname + "_y");
562 0 : break;
563 0 : case 3:
564 0 : _execute_data[geom_type].show.insert(vname + "_x");
565 0 : _execute_data[geom_type].show.insert(vname + "_y");
566 0 : _execute_data[geom_type].show.insert(vname + "_z");
567 0 : break;
568 : }
569 : }
570 : else
571 3219 : _execute_data["nodal"].show.insert(vname);
572 1202 : }
573 : }
574 1820 : else if (_problem_ptr->hasScalarVariable(var_name))
575 567 : _execute_data["scalars"].show.insert(var_name);
576 1631 : else if (hasPostprocessorByName(var_name))
577 4773 : _execute_data["postprocessors"].show.insert(var_name);
578 40 : else if (hasVectorPostprocessorByName(var_name))
579 102 : _execute_data["vector_postprocessors"].show.insert(var_name);
580 6 : else if ((var_name.find("/") != std::string::npos) &&
581 6 : (hasReporterValueByName(ReporterName(var_name))))
582 0 : _execute_data["reporters"].show.insert(var_name);
583 : else
584 6 : unknown.insert(var_name);
585 : }
586 :
587 : // Populate the hide lists
588 392446 : for (const auto & var_name : hide)
589 : {
590 35996 : if (_problem_ptr->hasVariable(var_name))
591 : {
592 33818 : MooseVariableFEBase & var = _problem_ptr->getVariable(
593 : 0, var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_ANY);
594 33818 : const FEType type = var.feType();
595 68508 : for (unsigned int i = 0; i < var.count(); ++i)
596 : {
597 34690 : VariableName vname = var_name;
598 34690 : if (var.isArray())
599 1744 : vname = var.arrayVariableComponent(i);
600 :
601 34690 : if (type.order == CONSTANT)
602 50853 : _execute_data["elemental"].hide.insert(vname);
603 17739 : else if (FEInterface::field_type(type) == TYPE_VECTOR)
604 : {
605 252 : switch (_es_ptr->get_mesh().spatial_dimension())
606 : {
607 68 : case 0:
608 : case 1:
609 136 : _execute_data["nodal"].hide.insert(vname);
610 68 : break;
611 184 : case 2:
612 368 : _execute_data["nodal"].hide.insert(vname + "_x");
613 368 : _execute_data["nodal"].hide.insert(vname + "_y");
614 184 : break;
615 0 : case 3:
616 0 : _execute_data["nodal"].hide.insert(vname + "_x");
617 0 : _execute_data["nodal"].hide.insert(vname + "_y");
618 0 : _execute_data["nodal"].hide.insert(vname + "_z");
619 0 : break;
620 : }
621 : }
622 : else
623 52461 : _execute_data["nodal"].hide.insert(vname);
624 34690 : }
625 : }
626 2178 : else if (_problem_ptr->hasScalarVariable(var_name))
627 4488 : _execute_data["scalars"].hide.insert(var_name);
628 682 : else if (hasPostprocessorByName(var_name))
629 2037 : _execute_data["postprocessors"].hide.insert(var_name);
630 3 : else if (hasVectorPostprocessorByName(var_name))
631 0 : _execute_data["vector_postprocessors"].hide.insert(var_name);
632 3 : else if ((var_name.find("/") != std::string::npos) &&
633 3 : (hasReporterValueByName(ReporterName(var_name))))
634 0 : _execute_data["reporters"].hide.insert(var_name);
635 :
636 : else
637 3 : unknown.insert(var_name);
638 : }
639 :
640 : // Error if an unknown variable or postprocessor is found
641 356450 : if (!unknown.empty())
642 : {
643 6 : std::ostringstream oss;
644 : oss << "Output(s) do not exist (must be variable, scalar, postprocessor, or vector "
645 6 : "postprocessor): ";
646 6 : std::copy(unknown.begin(), unknown.end(), infix_ostream_iterator<std::string>(oss, " "));
647 6 : mooseError(oss.str());
648 0 : }
649 356444 : }
650 :
651 : void
652 2138643 : AdvancedOutput::initOutputList(OutputData & data)
653 : {
654 : // References to the vectors of variable names
655 2138643 : std::set<std::string> & hide = data.hide;
656 2138643 : std::set<std::string> & show = data.show;
657 2138643 : std::set<std::string> & avail = data.available;
658 2138643 : std::set<std::string> & output = data.output;
659 :
660 : // Get the hide list from OutputInterface objects
661 2138643 : std::set<std::string> interface_hide_all_types;
662 2138643 : _app.getOutputWarehouse().buildInterfaceHideVariables(name(), interface_hide_all_types);
663 :
664 : // OutputInterface hide list includes all types; only include those that are available
665 2138643 : std::set<std::string> interface_hide;
666 2138643 : std::set_intersection(interface_hide_all_types.begin(),
667 : interface_hide_all_types.end(),
668 : avail.begin(),
669 : avail.end(),
670 : std::inserter(interface_hide, interface_hide.begin()));
671 :
672 : // Append to the hide list from OutputInterface objects
673 2138643 : hide.insert(interface_hide.begin(), interface_hide.end());
674 :
675 : // Both show and hide are empty and no show/hide settings were provided (show all available)
676 2138643 : if (!_execute_data.hasShowList() && hide.empty())
677 2080030 : output = avail;
678 :
679 : // Only hide is empty (show all the variables listed)
680 58613 : else if (_execute_data.hasShowList() && hide.empty())
681 12150 : output = show;
682 :
683 : // Only show is empty (show all except those hidden)
684 46463 : else if (!_execute_data.hasShowList() && !hide.empty())
685 46214 : std::set_difference(avail.begin(),
686 : avail.end(),
687 : hide.begin(),
688 : hide.end(),
689 : std::inserter(output, output.begin()));
690 :
691 : // Both hide and show are present (show all those listed)
692 : else // (_execute_data.hasShowList() && !hide.empty())
693 : {
694 : // Check if variables are in both, which is invalid
695 249 : std::vector<std::string> tmp;
696 249 : std::set_intersection(
697 : hide.begin(), hide.end(), show.begin(), show.end(), std::inserter(tmp, tmp.begin()));
698 249 : if (!tmp.empty())
699 : {
700 6 : std::ostringstream oss;
701 6 : oss << "Output(s) specified to be both shown and hidden: ";
702 6 : std::copy(tmp.begin(), tmp.end(), infix_ostream_iterator<std::string>(oss, " "));
703 6 : mooseError(oss.str());
704 0 : }
705 :
706 : // Define the output variable list
707 243 : output = show;
708 243 : }
709 2138637 : }
710 :
711 : void
712 398322 : AdvancedOutput::addValidParams(InputParameters & params, const MultiMooseEnum & types)
713 : {
714 398322 : ExecFlagEnum empty_execute_on = MooseUtils::getDefaultExecFlagEnum();
715 398322 : empty_execute_on.addAvailableFlags(EXEC_FAILED);
716 :
717 : // Nodal output
718 796644 : if (types.isValueSet("nodal"))
719 : {
720 316132 : params.addParam<ExecFlagEnum>(
721 : "execute_nodal_on", empty_execute_on, "Control the output of nodal variables");
722 316132 : params.addParamNamesToGroup("execute_nodal_on", "Selection/restriction of output");
723 : }
724 :
725 : // Elemental output
726 796644 : if (types.isValueSet("elemental"))
727 : {
728 316132 : params.addParam<ExecFlagEnum>(
729 : "execute_elemental_on", empty_execute_on, "Control the output of elemental variables");
730 316132 : params.addParamNamesToGroup("execute_elemental_on", "Selection/restriction of output");
731 :
732 : // Add material output control, which are output via elemental variables
733 237099 : params.addParam<bool>("output_material_properties",
734 158066 : false,
735 : "Flag indicating if material properties should be output");
736 316132 : params.addParam<std::vector<std::string>>(
737 : "show_material_properties",
738 : "List of material properties that should be written to the output");
739 316132 : params.addParamNamesToGroup("output_material_properties show_material_properties", "Materials");
740 :
741 : // Add mesh extra element id control, which are output via elemental variables
742 237099 : params.addParam<bool>(
743 : "output_extra_element_ids",
744 158066 : false,
745 : "Flag indicating if extra element ids defined on the mesh should be outputted");
746 316132 : params.addParam<std::vector<std::string>>(
747 : "extra_element_ids_to_output",
748 : "List of extra element ids defined on the mesh that should be written to the output.");
749 316132 : params.addParamNamesToGroup("output_extra_element_ids extra_element_ids_to_output", "Mesh");
750 : }
751 :
752 : // Scalar variable output
753 796644 : if (types.isValueSet("scalar"))
754 : {
755 1552192 : params.addParam<ExecFlagEnum>(
756 : "execute_scalars_on", empty_execute_on, "Control the output of scalar variables");
757 1552192 : params.addParamNamesToGroup("execute_scalars_on", "Selection/restriction of output");
758 : }
759 :
760 : // Nodal and scalar output
761 1353032 : if (types.isValueSet("nodal") && types.isValueSet("scalar"))
762 : {
763 316132 : params.addParam<bool>("scalar_as_nodal", false, "Output scalar variables as nodal");
764 316132 : params.addParamNamesToGroup("scalar_as_nodal", "Conversions before output");
765 : }
766 :
767 : // Elemental and nodal
768 1353032 : if (types.isValueSet("elemental") && types.isValueSet("nodal"))
769 : {
770 237099 : params.addParam<bool>(
771 158066 : "elemental_as_nodal", false, "Output elemental nonlinear variables as nodal");
772 316132 : params.addParamNamesToGroup("elemental_as_nodal", "Conversions before output");
773 : }
774 :
775 : // Postprocessors
776 796644 : if (types.isValueSet("postprocessor"))
777 : {
778 1552192 : params.addParam<ExecFlagEnum>(
779 : "execute_postprocessors_on", empty_execute_on, "Control of when postprocessors are output");
780 1552192 : params.addParamNamesToGroup("execute_postprocessors_on", "Selection/restriction of output");
781 : }
782 :
783 : // Vector Postprocessors
784 796644 : if (types.isValueSet("vector_postprocessor"))
785 : {
786 698416 : params.addParam<ExecFlagEnum>("execute_vector_postprocessors_on",
787 : empty_execute_on,
788 : "Enable/disable the output of VectorPostprocessors");
789 698416 : params.addParamNamesToGroup("execute_vector_postprocessors_on",
790 : "Selection/restriction of output");
791 : }
792 :
793 : // Reporters
794 796644 : if (types.isValueSet("reporter"))
795 : {
796 1030100 : params.addParam<ExecFlagEnum>(
797 : "execute_reporters_on", empty_execute_on, "Control of when Reporter values are output");
798 1030100 : params.addParamNamesToGroup("execute_reporters_on", "Selection/restriction of output");
799 : }
800 :
801 : // Input file
802 796644 : if (types.isValueSet("input"))
803 : {
804 866548 : params.addParam<ExecFlagEnum>(
805 : "execute_input_on", empty_execute_on, "Enable/disable the output of the input file");
806 866548 : params.addParamNamesToGroup("execute_input_on", "Selection/restriction of output");
807 : }
808 :
809 : // System Information
810 796644 : if (types.isValueSet("system_information"))
811 : {
812 564368 : params.addParam<ExecFlagEnum>("execute_system_information_on",
813 : empty_execute_on,
814 : "Control when the output of the simulation information occurs");
815 564368 : params.addParamNamesToGroup("execute_system_information_on", "Selection/restriction of output");
816 : }
817 398322 : }
818 :
819 : bool
820 71486 : AdvancedOutput::hasOutputHelper(const std::string & name)
821 : {
822 135273 : return !_execute_data[name].output.empty() && _advanced_execute_on.contains(name) &&
823 334333 : _advanced_execute_on[name].isValid() && !_advanced_execute_on[name].isValueSet("none");
824 : }
825 :
826 : bool
827 67593 : AdvancedOutput::hasNodalVariableOutput()
828 : {
829 135186 : return hasOutputHelper("nodal");
830 : }
831 :
832 : const std::set<std::string> &
833 302378 : AdvancedOutput::getNodalVariableOutput()
834 : {
835 907134 : return _execute_data["nodal"].output;
836 : }
837 :
838 : bool
839 3803 : AdvancedOutput::hasElementalVariableOutput()
840 : {
841 7606 : return hasOutputHelper("elemental");
842 : }
843 :
844 : const std::set<std::string> &
845 71584 : AdvancedOutput::getElementalVariableOutput()
846 : {
847 214752 : return _execute_data["elemental"].output;
848 : }
849 :
850 : bool
851 45 : AdvancedOutput::hasScalarOutput()
852 : {
853 90 : return hasOutputHelper("scalars");
854 : }
855 :
856 : const std::set<std::string> &
857 42649 : AdvancedOutput::getScalarOutput()
858 : {
859 127947 : return _execute_data["scalars"].output;
860 : }
861 :
862 : bool
863 45 : AdvancedOutput::hasPostprocessorOutput()
864 : {
865 90 : return hasOutputHelper("postprocessors");
866 : }
867 :
868 : const std::set<std::string> &
869 399490 : AdvancedOutput::getPostprocessorOutput()
870 : {
871 1198470 : return _execute_data["postprocessors"].output;
872 : }
873 :
874 : bool
875 0 : AdvancedOutput::hasVectorPostprocessorOutput()
876 : {
877 0 : return hasOutputHelper("vector_postprocessors");
878 : }
879 :
880 : const std::set<std::string> &
881 27079 : AdvancedOutput::getVectorPostprocessorOutput()
882 : {
883 81237 : return _execute_data["vector_postprocessors"].output;
884 : }
885 :
886 : bool
887 0 : AdvancedOutput::hasReporterOutput()
888 : {
889 0 : return hasOutputHelper("reporters");
890 : }
891 :
892 : const std::set<std::string> &
893 26185 : AdvancedOutput::getReporterOutput()
894 : {
895 78555 : return _execute_data["reporters"].output;
896 : }
897 :
898 : const OutputOnWarehouse &
899 46234 : AdvancedOutput::advancedExecuteOn() const
900 : {
901 46234 : return _advanced_execute_on;
902 : }
|