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