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 "MaterialPropertyDebugOutput.h" 12 : #include "FEProblem.h" 13 : #include "MooseApp.h" 14 : #include "Material.h" 15 : #include "ConsoleUtils.h" 16 : #include "MooseMesh.h" 17 : #include "MooseObjectName.h" 18 : 19 : #include "libmesh/transient_system.h" 20 : 21 : registerMooseObject("MooseApp", MaterialPropertyDebugOutput); 22 : 23 : InputParameters 24 15313 : MaterialPropertyDebugOutput::validParams() 25 : { 26 15313 : InputParameters params = Output::validParams(); 27 30626 : params.addClassDescription("Debug output object for displaying material property information."); 28 15313 : params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL; 29 15313 : return params; 30 0 : } 31 : 32 284 : MaterialPropertyDebugOutput::MaterialPropertyDebugOutput(const InputParameters & parameters) 33 284 : : Output(parameters) 34 : { 35 284 : printMaterialMap(); 36 284 : } 37 : 38 : void 39 248 : MaterialPropertyDebugOutput::output() 40 : { 41 : // Write out objects that consume properties 42 248 : std::stringstream consumed; 43 3244 : for (const auto & pair : _problem_ptr->getConsumedPropertyMap()) 44 : { 45 2996 : consumed << " Object: " << pair.first << "\n"; 46 8988 : consumed << " Properties: " << MooseUtils::join(pair.second, ", ") << "\n\n"; 47 : } 48 : 49 248 : _console << "\n\nConsumed Material Properties:\n"; 50 248 : _console << std::setw(ConsoleUtils::console_field_width) << consumed.str() << std::endl; 51 248 : } 52 : 53 : void 54 284 : MaterialPropertyDebugOutput::printMaterialMap() const 55 : { 56 : // Build output streams for block materials and block face materials 57 284 : std::stringstream active_block, active_face, active_neighbor, active_boundary; 58 : 59 : // Reference to mesh for getting boundary/block names 60 284 : MooseMesh & mesh = _problem_ptr->mesh(); 61 : 62 : // Reference to the Material warehouse 63 284 : const MaterialWarehouse & warehouse = _problem_ptr->getMaterialWarehouse(); 64 : 65 : // Active materials on block 66 : { 67 284 : const auto & objects = warehouse.getBlockObjects(); 68 644 : for (const auto & it : objects) 69 : { 70 360 : active_block << " Subdomain: " << mesh.getSubdomainName(it.first) << " (" << it.first 71 360 : << ")\n"; 72 360 : printMaterialProperties(active_block, it.second); 73 : } 74 : } 75 : 76 : // Active face materials on blocks 77 : { 78 284 : const auto & objects = warehouse[Moose::FACE_MATERIAL_DATA].getBlockObjects(); 79 644 : for (const auto & it : objects) 80 : { 81 360 : active_face << " Subdomain: " << mesh.getSubdomainName(it.first) << " (" << it.first 82 360 : << ")\n"; 83 360 : printMaterialProperties(active_face, it.second); 84 : } 85 : } 86 : 87 : // Active neighbor materials on blocks 88 : { 89 284 : const auto & objects = warehouse[Moose::NEIGHBOR_MATERIAL_DATA].getBlockObjects(); 90 644 : for (const auto & it : objects) 91 : { 92 360 : active_neighbor << " Subdomain: " << mesh.getSubdomainName(it.first) << " (" << it.first 93 360 : << ")\n"; 94 360 : printMaterialProperties(active_neighbor, it.second); 95 : } 96 : } 97 : 98 : // Active boundary materials 99 : { 100 284 : const auto & objects = warehouse.getBoundaryObjects(); 101 356 : for (const auto & it : objects) 102 : { 103 72 : active_boundary << " Boundary: " << mesh.getBoundaryName(it.first) << " (" << it.first 104 72 : << ")\n"; 105 72 : printMaterialProperties(active_boundary, it.second); 106 : } 107 : } 108 : 109 : // Write the stored strings to the ConsoleUtils output objects 110 284 : _console << "\n\nActive Materials:\n"; 111 284 : _console << std::setw(ConsoleUtils::console_field_width) << active_block.str() << '\n'; 112 : 113 284 : _console << std::setw(ConsoleUtils::console_field_width) << "Active Face Materials:\n"; 114 284 : _console << std::setw(ConsoleUtils::console_field_width) << active_face.str() << '\n'; 115 : 116 284 : _console << std::setw(ConsoleUtils::console_field_width) << "Active Neighboring Materials:\n"; 117 284 : _console << std::setw(ConsoleUtils::console_field_width) << active_neighbor.str() << '\n'; 118 : 119 284 : _console << std::setw(ConsoleUtils::console_field_width) << "Active Boundary Materials:\n"; 120 284 : _console << std::setw(ConsoleUtils::console_field_width) << active_boundary.str() << std::endl; 121 284 : } 122 : 123 : void 124 1152 : MaterialPropertyDebugOutput::printMaterialProperties( 125 : std::stringstream & output, const std::vector<std::shared_ptr<MaterialBase>> & materials) const 126 : { 127 : // Loop through all material objects 128 3921 : for (const auto & mat : materials) 129 : { 130 : // Get a list of properties for the current material 131 2769 : const std::set<std::string> & props = mat->getSuppliedItems(); 132 : 133 : // Adds the material name to the output stream 134 2769 : output << std::left << std::setw(ConsoleUtils::console_field_width) 135 2769 : << " Material Name: " << mat->name() << '\n'; 136 : 137 : // Build stream for properties using the ConsoleUtils helper functions to wrap the names if 138 : // there are too many for one line 139 2769 : std::streampos begin_string_pos = output.tellp(); 140 2769 : std::streampos curr_string_pos = begin_string_pos; 141 2769 : output << std::left << std::setw(ConsoleUtils::console_field_width) << " Property Names: "; 142 7932 : for (const auto & prop : props) 143 : { 144 5163 : output << "\"" << prop << "\" "; 145 5163 : curr_string_pos = output.tellp(); 146 5163 : ConsoleUtils::insertNewline(output, begin_string_pos, curr_string_pos); 147 : } 148 2769 : output << '\n'; 149 : } 150 : 151 1152 : output << std::flush; 152 1152 : }