LCOV - code coverage report
Current view: top level - src/actions - EulerAngle2RGBAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 45 46 97.8 %
Date: 2025-09-04 07:55:36 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             : #include "EulerAngle2RGBAction.h"
      11             : #include "Factory.h"
      12             : #include "FEProblem.h"
      13             : 
      14             : #include "libmesh/string_to_enum.h"
      15             : 
      16             : registerMooseAction("PhaseFieldApp", EulerAngle2RGBAction, "add_aux_kernel");
      17             : 
      18             : registerMooseAction("PhaseFieldApp", EulerAngle2RGBAction, "add_aux_variable");
      19             : 
      20             : InputParameters
      21          27 : EulerAngle2RGBAction::validParams()
      22             : {
      23          27 :   InputParameters params = Action::validParams();
      24          54 :   params.addParam<std::string>("auxvariable_name_base", "RGB", "Base name of the auxvariables");
      25          27 :   params.addClassDescription("Set up auxvariables and auxkernels to output Euler angles as RGB "
      26             :                              "values interpolated across inverse pole figure");
      27          54 :   params.addParam<unsigned int>("phase", "The phase to use for all queries.");
      28          54 :   MooseEnum sd_enum = MooseEnum("100=1 010=2 001=3", "001");
      29          54 :   params.addParam<MooseEnum>("sd", sd_enum, "Reference sample direction");
      30             :   MooseEnum structure_enum = MooseEnum(
      31          54 :       "cubic=43 hexagonal=62 tetragonal=42 trigonal=32 orthorhombic=22 monoclinic=2 triclinic=1");
      32          54 :   params.addRequiredParam<MooseEnum>(
      33             :       "crystal_structure", structure_enum, "Crystal structure of the material");
      34          54 :   params.addRequiredParam<UserObjectName>("euler_angle_provider",
      35             :                                           "Name of Euler angle provider user object");
      36          54 :   params.addRequiredParam<UserObjectName>("grain_tracker",
      37             :                                           "The GrainTracker UserObject to get values from.");
      38          27 :   params.addParam<Point>(
      39             :       "no_grain_color",
      40          27 :       Point(0, 0, 0),
      41             :       "RGB value of color used to represent area with no grains, defaults to black");
      42          54 :   params.addParam<std::vector<SubdomainName>>(
      43             :       "block", {}, "Block restriction for the variables and kernels");
      44          27 :   return params;
      45          27 : }
      46             : 
      47          27 : EulerAngle2RGBAction::EulerAngle2RGBAction(const InputParameters & params)
      48          54 :   : Action(params), _var_name_base(getParam<std::string>("auxvariable_name_base"))
      49             : {
      50          27 : }
      51             : 
      52             : void
      53          54 : EulerAngle2RGBAction::act()
      54             : {
      55             :   // Auxvariable suffix names that will automatically become a vector in Paraview
      56          54 :   std::vector<std::string> suffixes = {"_x", "_y", "_z"};
      57             : 
      58             :   // Three color types that will be outputted
      59          54 :   std::vector<std::string> colors = {"red", "green", "blue"};
      60             : 
      61         216 :   for (unsigned int i = 0; i < 3; ++i)
      62             :   {
      63             :     // Create the auxvariable name
      64         162 :     std::string var_name = _var_name_base + suffixes[i];
      65             : 
      66         162 :     if (_current_task == "add_aux_variable")
      67             :     {
      68          81 :       auto var_params = _factory.getValidParams("MooseVariableConstMonomial");
      69          81 :       var_params.applySpecificParameters(_pars, {"block"});
      70             :       // Create scalar auxvariables for the three components of the RGB vector
      71          81 :       _problem->addAuxVariable("MooseVariableConstMonomial", var_name, var_params);
      72          81 :     }
      73          81 :     else if (_current_task == "add_aux_kernel")
      74             :     {
      75             :       // Create auxkernels corresponding to each auxvariable
      76         162 :       InputParameters params = _factory.getValidParams("EulerAngleProvider2RGBAux");
      77         162 :       params.set<AuxVariableName>("variable") = var_name;
      78         243 :       params.set<MooseEnum>("sd") = getParam<MooseEnum>("sd");
      79         243 :       params.set<MooseEnum>("crystal_structure") = getParam<MooseEnum>("crystal_structure");
      80          81 :       params.set<MooseEnum>("output_type") = colors[i];
      81         162 :       params.set<UserObjectName>("euler_angle_provider") =
      82          81 :           getParam<UserObjectName>("euler_angle_provider");
      83         243 :       params.set<UserObjectName>("grain_tracker") = getParam<UserObjectName>("grain_tracker");
      84         324 :       params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
      85         162 :       params.set<Point>("no_grain_color") = getParam<Point>("no_grain_color");
      86         162 :       if (isParamValid("phase"))
      87          66 :         params.set<unsigned int>("phase") = getParam<unsigned int>("phase");
      88          81 :       _problem->addAuxKernel("EulerAngleProvider2RGBAux", var_name, params);
      89          81 :     }
      90             :     else
      91           0 :       mooseError("Internal error in EulerAngle2RGBAction.");
      92             :   }
      93         135 : }

Generated by: LCOV version 1.14