LCOV - code coverage report
Current view: top level - src/actions - ElementIDOutputAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 34 36 94.4 %
Date: 2025-07-17 01:28:37 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://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 "ElementIDOutputAction.h"
      12             : #include "MooseMesh.h"
      13             : #include "FEProblemBase.h"
      14             : #include "AddOutputAction.h"
      15             : #include "Assembly.h"
      16             : 
      17             : registerMooseAction("MooseApp", ElementIDOutputAction, "add_aux_kernel");
      18             : 
      19             : InputParameters
      20       62387 : ElementIDOutputAction::validParams()
      21             : {
      22       62387 :   InputParameters params = Action::validParams();
      23       62387 :   params.addClassDescription(
      24             :       "Action for copying extra element IDs into auxiliary variables for output.");
      25       62387 :   return params;
      26           0 : }
      27             : 
      28       62149 : ElementIDOutputAction::ElementIDOutputAction(const InputParameters & params) : Action(params) {}
      29             : 
      30             : void
      31       56588 : ElementIDOutputAction::act()
      32             : {
      33             :   // Do nothing if the application does not have output
      34       56588 :   if (!_app.actionWarehouse().hasActions("add_output"))
      35           0 :     return;
      36             : 
      37       56588 :   if (_current_task == "add_aux_kernel")
      38             :   {
      39       56588 :     const auto & output_actions = _app.actionWarehouse().getActionListByName("add_output");
      40      333995 :     for (const auto & act : output_actions)
      41             :     {
      42             :       // Extract the Output action
      43      277407 :       AddOutputAction * action = dynamic_cast<AddOutputAction *>(act);
      44      277407 :       if (!action)
      45       58187 :         continue;
      46             : 
      47      219220 :       InputParameters & params = action->getObjectParams();
      48      473129 :       if (params.isParamValid("output_extra_element_ids") &&
      49      253909 :           params.get<bool>("output_extra_element_ids"))
      50             :       {
      51          38 :         bool has_element_id_names = params.isParamValid("extra_element_ids_to_output");
      52          38 :         std::vector<std::string> element_id_names;
      53          38 :         if (has_element_id_names)
      54          12 :           element_id_names = params.get<std::vector<std::string>>("extra_element_ids_to_output");
      55             : 
      56          38 :         auto var_params = _factory.getValidParams("MooseVariableConstMonomial");
      57          38 :         auto kernel_params = _factory.getValidParams("ExtraElementIDAux");
      58          38 :         kernel_params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL;
      59         113 :         for (unsigned int i = 0; i < _problem->assembly(0, 0).numExtraElemIntegers(); ++i)
      60             :         {
      61          75 :           auto & var_name = _mesh->getMesh().get_elem_integer_name(i);
      62          99 :           if (!has_element_id_names ||
      63          24 :               (std::find(element_id_names.begin(), element_id_names.end(), var_name) !=
      64          99 :                element_id_names.end()))
      65             :           {
      66             :             // Create aux variables based on the extra element id name
      67          63 :             _problem->addAuxVariable("MooseVariableConstMonomial", var_name, var_params);
      68             : 
      69             :             // Create aux kernels based on the extra element id name
      70          63 :             kernel_params.set<AuxVariableName>("variable") = var_name;
      71         126 :             kernel_params.set<std::vector<ExtraElementIDName>>("extra_id_name") = {var_name};
      72          63 :             _problem->addAuxKernel("ExtraElementIDAux", "_output_" + var_name, kernel_params);
      73             :           }
      74             :         }
      75          38 :       }
      76             :     }
      77             :   }
      78          63 : }

Generated by: LCOV version 1.14