LCOV - code coverage report
Current view: top level - src/actions - PolycrystalKernelAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #32971 (54bef8) with base c6cf66 Lines: 56 57 98.2 %
Date: 2026-05-29 20:38:39 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 "PolycrystalKernelAction.h"
      11             : #include "Factory.h"
      12             : #include "Conversion.h"
      13             : #include "FEProblem.h"
      14             : 
      15             : registerMooseAction("PhaseFieldApp", PolycrystalKernelAction, "add_kernel");
      16             : 
      17             : InputParameters
      18         502 : PolycrystalKernelAction::validParams()
      19             : {
      20         502 :   InputParameters params = Action::validParams();
      21         502 :   params.addClassDescription(
      22             :       "Set up ACGrGrPoly, ACInterface, TimeDerivative, and ACGBPoly kernels");
      23        1004 :   params.addRequiredParam<unsigned int>(
      24             :       "op_num", "specifies the total number of grains (deformed + recrystallized) to create");
      25        1004 :   params.addRequiredParam<std::string>("var_name_base", "specifies the base name of the variables");
      26        1004 :   params.addParam<VariableName>("c", "Name of coupled concentration variable");
      27        1004 :   params.addParam<Real>("en_ratio", 1.0, "Ratio of surface to GB energy");
      28        1004 :   params.addParam<unsigned int>("ndef", 0, "specifies the number of deformed grains to create");
      29        1004 :   params.addParam<bool>("implicit", true, "Whether kernels are implicit or not");
      30        1004 :   params.addParam<bool>(
      31        1004 :       "use_displaced_mesh", false, "Whether to use displaced mesh in the kernels");
      32        1004 :   params.addParam<bool>("variable_mobility",
      33        1004 :                         true,
      34             :                         "The mobility is a function of any MOOSE variable (if "
      35             :                         "this is set to false, L must be constant over the "
      36             :                         "entire domain!)");
      37        1004 :   params.addCoupledVar("coupled_variables",
      38             :                        "Vector of nonlinear variable arguments that L depends on");
      39             : 
      40         502 :   return params;
      41           0 : }
      42             : 
      43         502 : PolycrystalKernelAction::PolycrystalKernelAction(const InputParameters & params)
      44             :   : Action(params),
      45         502 :     _op_num(getParam<unsigned int>("op_num")),
      46        1506 :     _var_name_base(getParam<std::string>("var_name_base"))
      47             : {
      48         502 : }
      49             : 
      50             : void
      51         502 : PolycrystalKernelAction::act()
      52             : {
      53        3568 :   for (unsigned int op = 0; op < _op_num; ++op)
      54             :   {
      55             :     //
      56             :     // Create variable names
      57             :     //
      58             : 
      59        6132 :     std::string var_name = _var_name_base + Moose::stringify(op);
      60             :     std::vector<VariableName> v;
      61        3066 :     v.resize(_op_num - 1);
      62             : 
      63             :     unsigned int ind = 0;
      64       26220 :     for (unsigned int j = 0; j < _op_num; ++j)
      65       23154 :       if (j != op)
      66       60264 :         v[ind++] = _var_name_base + Moose::stringify(j);
      67             : 
      68             :     //
      69             :     // Set up ACGrGrPoly kernels
      70             :     //
      71             : 
      72             :     {
      73        6132 :       InputParameters params = _factory.getValidParams("ACGrGrPoly");
      74        6132 :       params.set<NonlinearVariableName>("variable") = var_name;
      75        6132 :       params.set<std::vector<VariableName>>("v") = v;
      76        3066 :       params.applyParameters(parameters());
      77             : 
      78        3066 :       std::string kernel_name = "ACBulk_" + var_name;
      79        6132 :       _problem->addKernel("ACGrGrPoly", kernel_name, params);
      80        3066 :     }
      81             : 
      82             :     //
      83             :     // Set up ACInterface kernels
      84             :     //
      85             : 
      86             :     {
      87        6132 :       InputParameters params = _factory.getValidParams("ACInterface");
      88        6132 :       params.set<NonlinearVariableName>("variable") = var_name;
      89        3066 :       params.applyParameters(parameters());
      90             : 
      91        3066 :       std::string kernel_name = "ACInt_" + var_name;
      92        6132 :       _problem->addKernel("ACInterface", kernel_name, params);
      93        3066 :     }
      94             : 
      95             :     //
      96             :     // Set up TimeDerivative kernels
      97             :     //
      98             : 
      99             :     {
     100        6132 :       InputParameters params = _factory.getValidParams("TimeDerivative");
     101        6132 :       params.set<NonlinearVariableName>("variable") = var_name;
     102        3066 :       params.set<bool>("implicit") = true;
     103        3066 :       params.applyParameters(parameters());
     104             : 
     105        3066 :       std::string kernel_name = "IE_" + var_name;
     106        6132 :       _problem->addKernel("TimeDerivative", kernel_name, params);
     107        3066 :     }
     108             : 
     109             :     //
     110             :     // Set up optional ACGBPoly bubble interaction kernels
     111             :     //
     112             : 
     113        6132 :     if (isParamValid("c"))
     114             :     {
     115         140 :       InputParameters params = _factory.getValidParams("ACGBPoly");
     116         140 :       params.set<NonlinearVariableName>("variable") = var_name;
     117         210 :       params.set<std::vector<VariableName>>("c") = {getParam<VariableName>("c")};
     118          70 :       params.applyParameters(parameters());
     119             : 
     120          70 :       std::string kernel_name = "ACBubInteraction_" + var_name;
     121         140 :       _problem->addKernel("ACGBPoly", kernel_name, params);
     122          70 :     }
     123        3066 :   }
     124         642 : }

Generated by: LCOV version 1.14