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 : // MOOSE includes 11 : #include "CheckOutputAction.h" 12 : #include "Material.h" 13 : #include "MooseApp.h" 14 : #include "Console.h" 15 : #include "CommonOutputAction.h" 16 : #include "MooseVariableFEBase.h" 17 : #include "MooseVariableScalar.h" 18 : #include "AuxiliarySystem.h" 19 : #include "NonlinearSystemBase.h" 20 : 21 : registerMooseAction("MooseApp", CheckOutputAction, "check_output"); 22 : 23 : InputParameters 24 68545 : CheckOutputAction::validParams() 25 : { 26 68545 : InputParameters params = Action::validParams(); 27 68545 : return params; 28 : } 29 : 30 68545 : CheckOutputAction::CheckOutputAction(const InputParameters & params) : Action(params) {} 31 : 32 : void 33 62210 : CheckOutputAction::act() 34 : { 35 : // Perform the various output related checks 36 124420 : checkVariableOutput("add_variable"); 37 62210 : checkVariableOutput("add_aux_variable"); 38 62210 : checkMaterialOutput(); 39 62194 : checkConsoleOutput(); 40 62194 : checkPerfLogOutput(); 41 62194 : } 42 : 43 : void 44 124420 : CheckOutputAction::checkVariableOutput(const std::string & task) 45 : { 46 124420 : if (_problem.get() == nullptr) 47 0 : return; 48 : 49 124420 : if (task == "add_variable") 50 : { 51 123355 : for (const auto i : make_range(_problem->numNonlinearSystems())) 52 : { 53 61145 : const auto & field_vars = _problem->getNonlinearSystemBase(i).getVariables(/*tid =*/0); 54 121710 : for (const auto & var : field_vars) 55 : { 56 60565 : std::set<OutputName> outputs = var->getOutputs(); 57 60565 : _app.getOutputWarehouse().checkOutputs(outputs); 58 60565 : } 59 : 60 61145 : const auto & scalar_vars = _problem->getNonlinearSystemBase(i).getScalarVariables(/*tid =*/0); 61 62549 : for (const auto & var : scalar_vars) 62 : { 63 1404 : std::set<OutputName> outputs = var->getOutputs(); 64 1404 : _app.getOutputWarehouse().checkOutputs(outputs); 65 1404 : } 66 : } 67 : } 68 : 69 62210 : else if (task == "add_aux_variable") 70 : { 71 62210 : const auto & field_vars = _problem->getAuxiliarySystem().getVariables(/*tid =*/0); 72 155732 : for (const auto & var : field_vars) 73 : { 74 93522 : std::set<OutputName> outputs = var->getOutputs(); 75 93522 : _app.getOutputWarehouse().checkOutputs(outputs); 76 93522 : } 77 : 78 62210 : const auto & scalar_vars = _problem->getAuxiliarySystem().getScalarVariables(/*tid =*/0); 79 64003 : for (const auto & var : scalar_vars) 80 : { 81 1793 : std::set<OutputName> outputs = var->getOutputs(); 82 1793 : _app.getOutputWarehouse().checkOutputs(outputs); 83 1793 : } 84 : } 85 : } 86 : 87 : void 88 62210 : CheckOutputAction::checkMaterialOutput() 89 : { 90 : // Do nothing if _problem is NULL (this is the case for coupled problems) 91 : // Do not produce warning, you will get a warning from OutputAction 92 62210 : if (_problem.get() == NULL) 93 0 : return; 94 : 95 : // A complete list of all Material objects 96 62210 : const auto & materials = _problem->getMaterialWarehouse().getActiveObjects(); 97 : 98 : // TODO include boundary materials 99 : 100 : // Loop through each material object 101 76818 : for (const auto & mat : materials) 102 : { 103 : // Extract the names of the output objects to which the material properties will be exported 104 14624 : std::set<OutputName> outputs = mat->getOutputs(); 105 : 106 : // Check that the outputs exist, and that the output types support material output 107 14624 : _app.getOutputWarehouse().checkOutputs(outputs, /* supports_material_output = */ true); 108 14608 : } 109 : } 110 : 111 : void 112 62194 : CheckOutputAction::checkConsoleOutput() 113 : { 114 : // Warning if multiple Console objects are added with 'output_screen=true' in the input file 115 62194 : std::vector<Console *> console_ptrs = _app.getOutputWarehouse().getOutputs<Console>(); 116 62194 : unsigned int num_screen_outputs = 0; 117 124401 : for (const auto & console : console_ptrs) 118 186621 : if (console->getParam<bool>("output_screen")) 119 62207 : num_screen_outputs++; 120 : 121 62194 : if (num_screen_outputs > 1) 122 7 : mooseWarning("Multiple (", 123 : num_screen_outputs, 124 : ") Console output objects are writing to the " 125 : "screen, this will likely cause duplicate " 126 : "messages printed."); 127 62194 : } 128 : 129 : void 130 62194 : CheckOutputAction::checkPerfLogOutput() 131 : { 132 : 133 : // Search for the existence of a Console output object 134 62194 : bool has_console = false; 135 62194 : std::vector<Console *> ptrs = _app.getOutputWarehouse().getOutputs<Console>(); 136 62194 : for (const auto & console : ptrs) 137 186579 : if (console->getParam<bool>("output_screen")) 138 : { 139 62193 : has_console = true; 140 62193 : break; 141 : } 142 : 143 : // If a Console outputter is found then all the correct handling of performance logs are 144 : // handled within the object(s), so do nothing 145 62194 : if (!has_console) 146 1 : libMesh::perflog.disable_logging(); 147 62194 : }