LCOV - code coverage report
Current view: top level - src/actions - CSGOnlyAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 863ef6 Lines: 33 35 94.3 %
Date: 2025-10-15 18:16:15 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://www.mooseframework.org
       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 "MooseApp.h"
      11             : #include "CSGOnlyAction.h"
      12             : #include "CSGBase.h"
      13             : #include "MeshGenerator.h"
      14             : 
      15             : registerMooseAction("MooseApp", CSGOnlyAction, "csg_only");
      16             : registerMooseAction("MooseApp", CSGOnlyAction, "setup_mesh");
      17             : registerMooseAction("MooseApp", CSGOnlyAction, "execute_csg_generators");
      18             : 
      19             : InputParameters
      20          31 : CSGOnlyAction::validParams()
      21             : {
      22          31 :   return Action::validParams();
      23             : }
      24             : 
      25          31 : CSGOnlyAction::CSGOnlyAction(const InputParameters & params) : Action(params) {}
      26             : 
      27             : void
      28          89 : CSGOnlyAction::act()
      29             : {
      30          89 :   if (_current_task == "setup_mesh")
      31             :   {
      32          31 :     if (!_mesh)
      33           0 :       mooseError("Cannot generate CSG object without a [Mesh] block in the input file");
      34          31 :     _app.getMeshGeneratorSystem().setCSGOnly();
      35             :   }
      36          58 :   else if (_current_task == "execute_csg_generators")
      37             :   {
      38          31 :     const auto final_mg_name = _app.getMeshGeneratorSystem().getFinalMeshGeneratorName();
      39          31 :     const auto ordered_mg = _app.getMeshGeneratorSystem().getOrderedMeshGenerators();
      40             : 
      41          44 :     for (const auto & generator_set : ordered_mg)
      42          57 :       for (const auto & generator : generator_set)
      43             :       {
      44          44 :         auto csg_obj = generator->generateInternalCSG();
      45          40 :         const auto & name = generator->name();
      46             :         // If we are running generateCSG for final generator, store CSG object for use in csg_only
      47             :         // task
      48          40 :         if (name == final_mg_name)
      49             :         {
      50          27 :           _csg_obj = std::move(csg_obj);
      51          27 :           return;
      52             :         }
      53             :         else
      54             :         {
      55             :           // Store CSG object created by mesh generator for use by downstream MG's
      56          13 :           _app.getMeshGeneratorSystem().saveOutputCSGBase(name, csg_obj);
      57             :         }
      58          40 :       }
      59          54 :   }
      60          27 :   else if (_current_task == "csg_only")
      61             :   {
      62          27 :     const auto final_mg_name = _app.getMeshGeneratorSystem().getFinalMeshGeneratorName();
      63          27 :     if (!_csg_obj)
      64           0 :       mooseError("Expecting final generator with name " + final_mg_name +
      65             :                  " but not found in mesh generator tree");
      66             : 
      67          27 :     Moose::out << "Outputting CSGBase object for " + final_mg_name + "\n";
      68             : 
      69          27 :     auto csg_json = _csg_obj->generateOutput();
      70             : 
      71             :     // write generated json to file. Filename will be based on optional argument to
      72             :     // --csg-only. If not provided, the output name will be based on the filename
      73          27 :     std::string json_out = _app.parameters().get<std::string>("csg_only");
      74          27 :     if (json_out.empty())
      75          18 :       json_out = _app.getOutputFileBase() + "_csg.json";
      76             : 
      77          27 :     std::ofstream csg_file;
      78          27 :     csg_file.open(json_out);
      79          27 :     csg_file << csg_json.dump(/*indent=*/2);
      80          27 :     csg_file.close();
      81          27 :   }
      82             : }

Generated by: LCOV version 1.14