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 67646 : CheckOutputAction::validParams() 25 : { 26 67646 : InputParameters params = Action::validParams(); 27 67646 : return params; 28 : } 29 : 30 67646 : CheckOutputAction::CheckOutputAction(const InputParameters & params) : Action(params) {} 31 : 32 : void 33 61300 : CheckOutputAction::act() 34 : { 35 : // Perform the various output related checks 36 122600 : checkVariableOutput("add_variable"); 37 61300 : checkVariableOutput("add_aux_variable"); 38 61300 : checkMaterialOutput(); 39 61284 : checkConsoleOutput(); 40 61284 : checkPerfLogOutput(); 41 61284 : } 42 : 43 : void 44 122600 : CheckOutputAction::checkVariableOutput(const std::string & task) 45 : { 46 122600 : if (_problem.get() == nullptr) 47 0 : return; 48 : 49 122600 : if (task == "add_variable") 50 : { 51 121535 : for (const auto i : make_range(_problem->numNonlinearSystems())) 52 : { 53 60235 : const auto & field_vars = _problem->getNonlinearSystemBase(i).getVariables(/*tid =*/0); 54 119792 : for (const auto & var : field_vars) 55 : { 56 59557 : std::set<OutputName> outputs = var->getOutputs(); 57 59557 : _app.getOutputWarehouse().checkOutputs(outputs); 58 59557 : } 59 : 60 60235 : const auto & scalar_vars = _problem->getNonlinearSystemBase(i).getScalarVariables(/*tid =*/0); 61 61639 : 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 61300 : else if (task == "add_aux_variable") 70 : { 71 61300 : const auto & field_vars = _problem->getAuxiliarySystem().getVariables(/*tid =*/0); 72 154088 : for (const auto & var : field_vars) 73 : { 74 92788 : std::set<OutputName> outputs = var->getOutputs(); 75 92788 : _app.getOutputWarehouse().checkOutputs(outputs); 76 92788 : } 77 : 78 61300 : const auto & scalar_vars = _problem->getAuxiliarySystem().getScalarVariables(/*tid =*/0); 79 63093 : 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 61300 : 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 61300 : if (_problem.get() == NULL) 93 0 : return; 94 : 95 : // A complete list of all Material objects 96 61300 : const auto & materials = _problem->getMaterialWarehouse().getActiveObjects(); 97 : 98 : // TODO include boundary materials 99 : 100 : // Loop through each material object 101 75489 : for (const auto & mat : materials) 102 : { 103 : // Extract the names of the output objects to which the material properties will be exported 104 14205 : std::set<OutputName> outputs = mat->getOutputs(); 105 : 106 : // Check that the outputs exist, and that the output types support material output 107 14205 : _app.getOutputWarehouse().checkOutputs(outputs, /* supports_material_output = */ true); 108 14189 : } 109 : } 110 : 111 : void 112 61284 : CheckOutputAction::checkConsoleOutput() 113 : { 114 : // Warning if multiple Console objects are added with 'output_screen=true' in the input file 115 61284 : std::vector<Console *> console_ptrs = _app.getOutputWarehouse().getOutputs<Console>(); 116 61284 : unsigned int num_screen_outputs = 0; 117 122581 : for (const auto & console : console_ptrs) 118 183891 : if (console->getParam<bool>("output_screen")) 119 61297 : num_screen_outputs++; 120 : 121 61284 : 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 61284 : } 128 : 129 : void 130 61284 : CheckOutputAction::checkPerfLogOutput() 131 : { 132 : 133 : // Search for the existence of a Console output object 134 61284 : bool has_console = false; 135 61284 : std::vector<Console *> ptrs = _app.getOutputWarehouse().getOutputs<Console>(); 136 61284 : for (const auto & console : ptrs) 137 183849 : if (console->getParam<bool>("output_screen")) 138 : { 139 61283 : has_console = true; 140 61283 : 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 61284 : if (!has_console) 146 1 : libMesh::perflog.disable_logging(); 147 61284 : }