LCOV - code coverage report
Current view: top level - src/outputs - MaterialPropertyDebugOutput.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 65 66 98.5 %
Date: 2025-08-08 20:01:16 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          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       14749 : MaterialPropertyDebugOutput::validParams()
      25             : {
      26       14749 :   InputParameters params = Output::validParams();
      27       14749 :   params.addClassDescription("Debug output object for displaying material property information.");
      28       14749 :   params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL;
      29       14749 :   return params;
      30           0 : }
      31             : 
      32         242 : MaterialPropertyDebugOutput::MaterialPropertyDebugOutput(const InputParameters & parameters)
      33         242 :   : Output(parameters)
      34             : {
      35         242 :   printMaterialMap();
      36         242 : }
      37             : 
      38             : void
      39         218 : MaterialPropertyDebugOutput::output()
      40             : {
      41             :   // Write out objects that consume properties
      42         218 :   std::stringstream consumed;
      43        3134 :   for (const auto & pair : _problem_ptr->getConsumedPropertyMap())
      44             :   {
      45        2916 :     consumed << "      Object: " << pair.first << "\n";
      46        2916 :     consumed << "  Properties: " << MooseUtils::join(pair.second, ", ") << "\n\n";
      47             :   }
      48             : 
      49         218 :   _console << "\n\nConsumed Material Properties:\n";
      50         218 :   _console << std::setw(ConsoleUtils::console_field_width) << consumed.str() << std::endl;
      51         218 : }
      52             : 
      53             : void
      54         242 : MaterialPropertyDebugOutput::printMaterialMap() const
      55             : {
      56             :   // Build output streams for block materials and block face materials
      57         242 :   std::stringstream active_block, active_face, active_neighbor, active_boundary;
      58             : 
      59             :   // Reference to mesh for getting boundary/block names
      60         242 :   MooseMesh & mesh = _problem_ptr->mesh();
      61             : 
      62             :   // Reference to the Material warehouse
      63         242 :   const MaterialWarehouse & warehouse = _problem_ptr->getMaterialWarehouse();
      64             : 
      65             :   // Active materials on block
      66             :   {
      67         242 :     const auto & objects = warehouse.getBlockObjects();
      68         560 :     for (const auto & it : objects)
      69             :     {
      70         318 :       active_block << "    Subdomain: " << mesh.getSubdomainName(it.first) << " (" << it.first
      71         318 :                    << ")\n";
      72         318 :       printMaterialProperties(active_block, it.second);
      73             :     }
      74             :   }
      75             : 
      76             :   // Active face materials on blocks
      77             :   {
      78         242 :     const auto & objects = warehouse[Moose::FACE_MATERIAL_DATA].getBlockObjects();
      79         560 :     for (const auto & it : objects)
      80             :     {
      81         318 :       active_face << "    Subdomain: " << mesh.getSubdomainName(it.first) << " (" << it.first
      82         318 :                   << ")\n";
      83         318 :       printMaterialProperties(active_face, it.second);
      84             :     }
      85             :   }
      86             : 
      87             :   // Active neighbor materials on blocks
      88             :   {
      89         242 :     const auto & objects = warehouse[Moose::NEIGHBOR_MATERIAL_DATA].getBlockObjects();
      90         560 :     for (const auto & it : objects)
      91             :     {
      92         318 :       active_neighbor << "    Subdomain: " << mesh.getSubdomainName(it.first) << " (" << it.first
      93         318 :                       << ")\n";
      94         318 :       printMaterialProperties(active_neighbor, it.second);
      95             :     }
      96             :   }
      97             : 
      98             :   // Active boundary materials
      99             :   {
     100         242 :     const auto & objects = warehouse.getBoundaryObjects();
     101         314 :     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         242 :   _console << "\n\nActive Materials:\n";
     111         242 :   _console << std::setw(ConsoleUtils::console_field_width) << active_block.str() << '\n';
     112             : 
     113         242 :   _console << std::setw(ConsoleUtils::console_field_width) << "Active Face Materials:\n";
     114         242 :   _console << std::setw(ConsoleUtils::console_field_width) << active_face.str() << '\n';
     115             : 
     116         242 :   _console << std::setw(ConsoleUtils::console_field_width) << "Active Neighboring Materials:\n";
     117         242 :   _console << std::setw(ConsoleUtils::console_field_width) << active_neighbor.str() << '\n';
     118             : 
     119         242 :   _console << std::setw(ConsoleUtils::console_field_width) << "Active Boundary Materials:\n";
     120         242 :   _console << std::setw(ConsoleUtils::console_field_width) << active_boundary.str() << std::endl;
     121         242 : }
     122             : 
     123             : void
     124        1026 : MaterialPropertyDebugOutput::printMaterialProperties(
     125             :     std::stringstream & output, const std::vector<std::shared_ptr<MaterialBase>> & materials) const
     126             : {
     127             :   // Loop through all material objects
     128        3543 :   for (const auto & mat : materials)
     129             :   {
     130             :     // Get a list of properties for the current material
     131        2517 :     const std::set<std::string> & props = mat->getSuppliedItems();
     132             : 
     133             :     // Adds the material name to the output stream
     134        2517 :     output << std::left << std::setw(ConsoleUtils::console_field_width)
     135        2517 :            << "      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        2517 :     std::streampos begin_string_pos = output.tellp();
     140        2517 :     std::streampos curr_string_pos = begin_string_pos;
     141        2517 :     output << std::left << std::setw(ConsoleUtils::console_field_width) << "      Property Names: ";
     142        7428 :     for (const auto & prop : props)
     143             :     {
     144        4911 :       output << "\"" << prop << "\" ";
     145        4911 :       curr_string_pos = output.tellp();
     146        4911 :       ConsoleUtils::insertNewline(output, begin_string_pos, curr_string_pos);
     147             :     }
     148        2517 :     output << '\n';
     149             :   }
     150             : 
     151        1026 :   output << std::flush;
     152        1026 : }

Generated by: LCOV version 1.14