LCOV - code coverage report
Current view: top level - src/actions - MultiAuxVariablesAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 29 32 90.6 %
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 "MultiAuxVariablesAction.h"
      11             : #include "FEProblem.h"
      12             : #include "Conversion.h"
      13             : #include "MooseMesh.h"
      14             : 
      15             : registerMooseAction("PhaseFieldApp", MultiAuxVariablesAction, "add_aux_variable");
      16             : 
      17             : InputParameters
      18          11 : MultiAuxVariablesAction::validParams()
      19             : {
      20          11 :   InputParameters params = AddAuxVariableAction::validParams();
      21          11 :   params.addClassDescription("Set up auxvariables for components of "
      22             :                              "MaterialProperty<std::vector<data_type> > for polycrystal sample.");
      23          22 :   params.addRequiredParam<unsigned int>(
      24             :       "grain_num", "Specifies the number of grains to create the aux variables for.");
      25          22 :   params.addRequiredParam<std::vector<std::string>>(
      26             :       "variable_base", "Vector that specifies the base name of the variables.");
      27          11 :   MultiMooseEnum data_type("Real RealGradient", "Real");
      28          22 :   params.addRequiredParam<MultiMooseEnum>(
      29             :       "data_type",
      30             :       data_type,
      31             :       "Specifying data type of the materials property, variables are created accordingly");
      32          11 :   return params;
      33          11 : }
      34             : 
      35          11 : MultiAuxVariablesAction::MultiAuxVariablesAction(const InputParameters & params)
      36             :   : AddAuxVariableAction(params),
      37          11 :     _grain_num(getParam<unsigned int>("grain_num")),
      38          22 :     _var_name_base(getParam<std::vector<std::string>>("variable_base")),
      39          11 :     _num_var(_var_name_base.size()),
      40          22 :     _data_type(getParam<MultiMooseEnum>("data_type")),
      41          22 :     _data_size(_data_type.size())
      42             : {
      43          11 : }
      44             : 
      45             : void
      46          11 : MultiAuxVariablesAction::act()
      47             : {
      48          11 :   init();
      49             : 
      50          11 :   if (_num_var != _data_size)
      51           0 :     mooseError("Data type not provided for all the AuxVariables in MultiAuxVariablesAction");
      52             : 
      53             :   // mesh dimension & components required for gradient variables
      54          11 :   const unsigned int dim = _mesh->dimension();
      55          11 :   const std::vector<char> suffix = {'x', 'y', 'z'};
      56             : 
      57             :   // Loop through the number of order parameters
      58          22 :   for (unsigned int val = 0; val < _num_var; ++val)
      59          33 :     for (unsigned int gr = 0; gr < _grain_num; ++gr)
      60             :     {
      61             :       /// for extracting data from MaterialProperty<std::vector<Real> >
      62          22 :       if (_data_type[val] == "Real")
      63             :       {
      64             :         // Create variable names with variable name base followed by the order parameter it applies
      65             :         // to.
      66           0 :         std::string var_name = _var_name_base[val] + Moose::stringify(gr);
      67             : 
      68           0 :         _problem->addAuxVariable(_type, var_name, _moose_object_pars);
      69             :       }
      70             :       /// for extracting data from MaterialProperty<std::vector<RealGradient> >
      71          22 :       if (_data_type[val] == "RealGradient")
      72          66 :         for (unsigned int x = 0; x < dim; ++x)
      73             :         {
      74             :           /**
      75             :            * The name of the variable is the variable name base followed by
      76             :            * the order parameter and a suffix mentioning dimension it applies to.
      77             :            */
      78          88 :           std::string var_name = _var_name_base[val] + Moose::stringify(gr) + "_" + suffix[x];
      79             : 
      80          44 :           _problem->addAuxVariable(_type, var_name, _moose_object_pars);
      81             :         }
      82             :     }
      83          11 : }

Generated by: LCOV version 1.14