LCOV - code coverage report
Current view: top level - src/actions - RigidBodyMultiKernelAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 84 90 93.3 %
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 "RigidBodyMultiKernelAction.h"
      11             : #include "Factory.h"
      12             : #include "Parser.h"
      13             : #include "Conversion.h"
      14             : #include "FEProblem.h"
      15             : 
      16             : registerMooseAction("PhaseFieldApp", RigidBodyMultiKernelAction, "add_kernel");
      17             : 
      18             : InputParameters
      19          19 : RigidBodyMultiKernelAction::validParams()
      20             : {
      21          19 :   InputParameters params = Action::validParams();
      22          19 :   params.addClassDescription(
      23             :       "Action for applying Allen-Cahn equations and SingleGrainRigidBodyMotion to grains");
      24          38 :   params.addRequiredParam<unsigned int>("op_num", "specifies the number of grains to create");
      25          38 :   params.addRequiredParam<std::string>("var_name_base", "specifies the base name of the variables");
      26          38 :   params.addParam<VariableName>("c", "Name of coupled concentration variable");
      27          38 :   params.addParam<MaterialPropertyName>("kappa_name", "kappa_op", "The kappa used with the kernel");
      28          38 :   params.addParam<MaterialPropertyName>("mob_name", "L", "The mobility used with the kernel");
      29          38 :   params.addParam<MaterialPropertyName>(
      30             :       "f_name", "Base name of the free energy function F defined in a DerivativeParsedMaterial");
      31          38 :   params.addParam<std::string>("base_name",
      32             :                                "Optional parameter that allows the user to define "
      33             :                                "type of force density under consideration");
      34          38 :   params.addParam<Real>(
      35          38 :       "translation_constant", 500, "constant value characterizing grain translation");
      36          38 :   params.addParam<Real>("rotation_constant", 1.0, "constant value characterizing grain rotation");
      37          38 :   params.addRequiredParam<UserObjectName>(
      38             :       "grain_force", "userobject for getting force and torque acting on grains");
      39          38 :   params.addRequiredParam<UserObjectName>("grain_tracker_object",
      40             :                                           "The FeatureFloodCount UserObject to get values from.");
      41          38 :   params.addRequiredParam<VectorPostprocessorName>("grain_volumes",
      42             :                                                    "The feature volume VectorPostprocessorValue.");
      43          38 :   params.addParam<bool>("implicit", true, "Whether kernels are implicit or not");
      44          38 :   params.addParam<bool>(
      45          38 :       "use_displaced_mesh", false, "Whether to use displaced mesh in the kernels");
      46          19 :   return params;
      47           0 : }
      48             : 
      49          19 : RigidBodyMultiKernelAction::RigidBodyMultiKernelAction(const InputParameters & params)
      50             :   : Action(params),
      51          19 :     _op_num(getParam<unsigned int>("op_num")),
      52          38 :     _var_name_base(getParam<std::string>("var_name_base")),
      53          57 :     _implicit(getParam<bool>("implicit"))
      54             : {
      55          19 : }
      56             : 
      57             : void
      58          19 : RigidBodyMultiKernelAction::act()
      59             : {
      60          73 :   for (unsigned int op = 0; op < _op_num; ++op)
      61             :   {
      62             :     //
      63             :     // Create variable names
      64             :     //
      65             : 
      66         108 :     std::string var_name = _var_name_base + Moose::stringify(op);
      67             : 
      68             :     //
      69             :     // Create vector of coupled variables
      70             :     //
      71             : 
      72             :     std::vector<VariableName> arg;
      73             :     unsigned int ind = 0;
      74             : 
      75         108 :     if (isParamValid("c"))
      76             :     {
      77          54 :       VariableName c = getParam<VariableName>("c");
      78          54 :       arg.resize(_op_num);
      79             : 
      80         226 :       for (unsigned int j = 0; j < _op_num; ++j)
      81         172 :         if (j != op)
      82         354 :           arg[ind++] = _var_name_base + Moose::stringify(j);
      83             : 
      84          54 :       arg[ind++] = c;
      85             :     }
      86             :     else
      87             :     {
      88           0 :       arg.resize(_op_num - 1);
      89           0 :       for (unsigned int j = 0; j < _op_num; ++j)
      90           0 :         if (j != op)
      91           0 :           arg[ind++] = _var_name_base + Moose::stringify(j);
      92             :     }
      93             : 
      94             :     //
      95             :     // Create vector of order parameters
      96             :     //
      97             : 
      98          54 :     std::vector<VariableName> v(_op_num);
      99         226 :     for (unsigned int j = 0; j < _op_num; ++j)
     100         516 :       v[j] = _var_name_base + Moose::stringify(j);
     101             : 
     102             :     //
     103             :     // Set up ACInterface kernels
     104             :     //
     105             : 
     106             :     {
     107         108 :       InputParameters params = _factory.getValidParams("ACInterface");
     108         108 :       params.set<NonlinearVariableName>("variable") = var_name;
     109         108 :       params.set<bool>("implicit") = getParam<bool>("implicit");
     110         108 :       params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
     111         162 :       params.set<MaterialPropertyName>("kappa_name") = getParam<MaterialPropertyName>("kappa_name");
     112         162 :       params.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mob_name");
     113             : 
     114          54 :       std::string kernel_name = "ACInt_" + var_name;
     115         108 :       _problem->addKernel("ACInterface", kernel_name, params);
     116          54 :     }
     117             : 
     118             :     //
     119             :     // Set up the AllenCahn kernels
     120             :     //
     121             : 
     122             :     {
     123         108 :       InputParameters params = _factory.getValidParams("AllenCahn");
     124         108 :       params.set<NonlinearVariableName>("variable") = var_name;
     125          54 :       params.set<std::vector<VariableName>>("args") = arg;
     126         162 :       params.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mob_name");
     127         162 :       params.set<MaterialPropertyName>("f_name") = getParam<MaterialPropertyName>("f_name");
     128          54 :       params.set<bool>("implicit") = _implicit;
     129         108 :       params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
     130             : 
     131          54 :       std::string kernel_name = "AC_" + var_name;
     132         108 :       _problem->addKernel("AllenCahn", kernel_name, params);
     133          54 :     }
     134             : 
     135             :     //
     136             :     // Set up SingleGrainRigidBodyMotion kernels
     137             :     //
     138             : 
     139             :     {
     140         108 :       InputParameters params = _factory.getValidParams("SingleGrainRigidBodyMotion");
     141         108 :       params.set<NonlinearVariableName>("variable") = var_name;
     142          54 :       params.set<std::vector<VariableName>>("v") = v;
     143          54 :       params.set<unsigned int>("op_index") = op;
     144         162 :       params.set<std::vector<VariableName>>("c") = {getParam<VariableName>("c")};
     145          54 :       if (isParamValid("base_name"))
     146           0 :         params.set<std::string>("base_name") = getParam<std::string>("base_name");
     147         108 :       params.set<Real>("translation_constant") = getParam<Real>("translation_constant");
     148         108 :       params.set<Real>("rotation_constant") = getParam<Real>("rotation_constant");
     149         162 :       params.set<UserObjectName>("grain_force") = getParam<UserObjectName>("grain_force");
     150         108 :       params.set<UserObjectName>("grain_tracker_object") =
     151          54 :           getParam<UserObjectName>("grain_tracker_object");
     152         108 :       params.set<VectorPostprocessorName>("grain_volumes") =
     153          54 :           getParam<VectorPostprocessorName>("grain_volumes");
     154             : 
     155          54 :       params.set<bool>("implicit") = _implicit;
     156         108 :       params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
     157             : 
     158          54 :       std::string kernel_name = "RigidBody_" + var_name;
     159         108 :       _problem->addKernel("SingleGrainRigidBodyMotion", kernel_name, params);
     160          54 :     }
     161             : 
     162             :     //
     163             :     // Set up TimeDerivative kernels
     164             :     //
     165             : 
     166             :     {
     167         108 :       InputParameters params = _factory.getValidParams("TimeDerivative");
     168         108 :       params.set<NonlinearVariableName>("variable") = var_name;
     169          54 :       params.set<bool>("implicit") = true;
     170         108 :       params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
     171             : 
     172          54 :       std::string kernel_name = "IE_" + var_name;
     173         108 :       _problem->addKernel("TimeDerivative", kernel_name, params);
     174          54 :     }
     175          54 :   }
     176         127 : }

Generated by: LCOV version 1.14