LCOV - code coverage report
Current view: top level - src/actions - HHPFCRFFSplitVariablesAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 30 30 100.0 %
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 "HHPFCRFFSplitVariablesAction.h"
      11             : #include "Factory.h"
      12             : #include "FEProblem.h"
      13             : #include "Conversion.h"
      14             : #include "AddVariableAction.h"
      15             : 
      16             : #include "libmesh/string_to_enum.h"
      17             : 
      18             : registerMooseAction("PhaseFieldApp", HHPFCRFFSplitVariablesAction, "add_variable");
      19             : 
      20             : InputParameters
      21           8 : HHPFCRFFSplitVariablesAction::validParams()
      22             : {
      23           8 :   InputParameters params = Action::validParams();
      24           8 :   params.addClassDescription(
      25             :       "Creates the L nonlinear variables for the Cahn-Hilliard equation for the RFF form of the "
      26             :       "phase field crystal model, when using a split approach");
      27           8 :   MooseEnum familyEnum = AddVariableAction::getNonlinearVariableFamilies();
      28          16 :   params.addParam<MooseEnum>(
      29             :       "family",
      30             :       familyEnum,
      31             :       "Specifies the family of FE shape functions to use for the L variables");
      32           8 :   MooseEnum orderEnum = AddVariableAction::getNonlinearVariableOrders();
      33          16 :   params.addParam<MooseEnum>(
      34             :       "order",
      35             :       orderEnum,
      36             :       "Specifies the order of the FE shape function to use for the L variables");
      37          16 :   params.addParam<Real>("scaling", 1.0, "Specifies a scaling factor to apply to the L variables");
      38          16 :   params.addRequiredParam<unsigned int>(
      39             :       "num_L", "specifies the number of complex L variables will be solved for");
      40          16 :   params.addRequiredParam<std::string>("L_name_base", "Base name for the complex L variables");
      41          16 :   params.addParam<std::vector<SubdomainName>>(
      42             :       "block", {}, "Block restriction for the variables and kernels");
      43           8 :   return params;
      44           8 : }
      45             : 
      46           8 : HHPFCRFFSplitVariablesAction::HHPFCRFFSplitVariablesAction(const InputParameters & params)
      47             :   : Action(params),
      48           8 :     _num_L(getParam<unsigned int>("num_L")),
      49          24 :     _L_name_base(getParam<std::string>("L_name_base"))
      50             : {
      51           8 : }
      52             : 
      53             : void
      54           8 : HHPFCRFFSplitVariablesAction::act()
      55             : {
      56             : #ifdef DEBUG
      57             :   Moose::err << "Inside the HHPFCRFFSplitVariablesAction Object\n";
      58             :   Moose::err << "VariableBase: " << _L_name_base << "\torder: " << getParam<MooseEnum>("order")
      59             :              << "\tfamily: " << getParam<MooseEnum>("family") << std::endl;
      60             : #endif
      61             : 
      62             :   // Loop through the number of L variables
      63          48 :   for (unsigned int l = 0; l < _num_L; ++l)
      64             :   {
      65             :     // Create L base name
      66          40 :     std::string L_name = _L_name_base + Moose::stringify(l);
      67             : 
      68             :     // Create real L variable
      69          40 :     std::string real_name = L_name + "_real";
      70             : 
      71             :     const auto type = "MooseVariable";
      72          40 :     auto params = _factory.getValidParams(type);
      73          40 :     params.applySpecificParameters(_pars, {"family", "order", "block"});
      74         120 :     params.set<std::vector<Real>>("scaling") = {getParam<Real>("scaling")};
      75             : 
      76          40 :     _problem->addVariable(type, real_name, params);
      77             : 
      78          40 :     if (l > 0)
      79             :     {
      80             :       // Create imaginary L variable IF l > 0
      81          32 :       std::string imag_name = L_name + "_imag";
      82             : 
      83          64 :       _problem->addVariable(type, imag_name, params);
      84             :     }
      85          40 :   }
      86           8 : }

Generated by: LCOV version 1.14