LCOV - code coverage report
Current view: top level - src/outputs - ParaviewComponentAnnotationMap.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #30301 (3b550b) with base 2ad78d Lines: 34 35 97.1 %
Date: 2025-07-30 13:02:48 Functions: 4 4 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             : #include "ParaviewComponentAnnotationMap.h"
      11             : 
      12             : #include "nlohmann/json.h"
      13             : #include "LockFile.h"
      14             : #include "JsonIO.h"
      15             : #include "THMProblem.h"
      16             : #include "Component.h"
      17             : #include <fstream>
      18             : 
      19             : registerMooseObject("ThermalHydraulicsApp", ParaviewComponentAnnotationMap);
      20             : 
      21             : /// KAAMS color profile from paraview
      22             : static const std::vector<Real> kaams_colors = {1.0, 1.0, 1.0,  1.0,  0.0,  0.0, 0.0,  1.0,  0.0,
      23             :                                                0.0, 0.0, 1.0,  1.0,  1.0,  0.0, 1.0,  0.0,  1.0,
      24             :                                                0.0, 1.0, 1.0,  0.63, 0.63, 1.0, 0.67, 0.5,  0.33,
      25             :                                                1.0, 0.5, 0.75, 0.53, 0.35, 0.7, 1.0,  0.75, 0.5};
      26             : 
      27             : InputParameters
      28          38 : ParaviewComponentAnnotationMap::validParams()
      29             : {
      30          38 :   InputParameters params = FileOutput::validParams();
      31          38 :   ExecFlagEnum execute_options = MooseUtils::getDefaultExecFlagEnum();
      32         114 :   execute_options = {EXEC_INITIAL};
      33          76 :   params.set<ExecFlagEnum>("execute_on") = execute_options;
      34          38 :   return params;
      35          38 : }
      36             : 
      37          19 : ParaviewComponentAnnotationMap::ParaviewComponentAnnotationMap(const InputParameters & parameters)
      38          19 :   : FileOutput(parameters)
      39             : {
      40          19 :   THMProblem * thm_problem = dynamic_cast<THMProblem *>(_problem_ptr);
      41          19 :   if (!thm_problem)
      42           0 :     mooseError(name(),
      43             :                ": ParaviewComponentAnnotationMap can only be used with THM-based simulation.");
      44          19 : }
      45             : 
      46             : void
      47          14 : ParaviewComponentAnnotationMap::output()
      48             : {
      49          14 :   if (processor_id() == 0)
      50             :   {
      51           9 :     THMProblem * thm_problem = dynamic_cast<THMProblem *>(_problem_ptr);
      52             :     const std::vector<std::shared_ptr<Component>> & comps = thm_problem->getComponents();
      53             : 
      54             :     std::vector<Real> clrs;
      55             :     unsigned int clr_idx = 0;
      56             : 
      57             :     std::vector<std::string> anns;
      58          81 :     for (auto & comp : comps)
      59             :     {
      60          72 :       const auto & subdomains = comp->getSubdomainNames();
      61         135 :       for (auto & sn : subdomains)
      62             :       {
      63          63 :         SubdomainID sid = _mesh_ptr->getSubdomainID(sn);
      64             : 
      65          63 :         anns.push_back(Moose::stringify(sid));
      66          63 :         anns.push_back(sn);
      67             : 
      68          63 :         clrs.push_back(kaams_colors[clr_idx++]);
      69          63 :         clrs.push_back(kaams_colors[clr_idx++]);
      70          63 :         clrs.push_back(kaams_colors[clr_idx++]);
      71             :         // 12 colors with RGB values
      72          63 :         clr_idx = clr_idx % (12 * 3);
      73             :       }
      74             :     }
      75             : 
      76             :     nlohmann::json json;
      77           9 :     json[0]["Annotations"] = anns;
      78           9 :     json[0]["IndexedColors"] = clrs;
      79           9 :     json[0]["Name"] = _file_base;
      80             : 
      81          18 :     std::ofstream out(filename().c_str());
      82           9 :     out << std::setw(4) << json << std::endl;
      83          18 :   }
      84          14 : }
      85             : 
      86             : std::string
      87          28 : ParaviewComponentAnnotationMap::filename()
      88             : {
      89          28 :   return _file_base + ".json";
      90             : }

Generated by: LCOV version 1.14