LCOV - code coverage report
Current view: top level - src/materials - ExternalForceDensityMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #30119 (aa6062) with base 79f9bd Lines: 49 50 98.0 %
Date: 2025-03-20 17:26:41 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://www.mooseframework.org
       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 "ExternalForceDensityMaterial.h"
      11             : #include "Function.h"
      12             : 
      13             : registerMooseObject("PhaseFieldApp", ExternalForceDensityMaterial);
      14             : 
      15             : InputParameters
      16          57 : ExternalForceDensityMaterial::validParams()
      17             : {
      18          57 :   InputParameters params = Material::validParams();
      19          57 :   params.addClassDescription("Providing external applied force density to grains");
      20         114 :   params.addParam<FunctionName>("force_x", 0.0, "The forcing function in x direction.");
      21         114 :   params.addParam<FunctionName>("force_y", 0.0, "The forcing function in y direction.");
      22         114 :   params.addParam<FunctionName>("force_z", 0.0, "The forcing function in z direction.");
      23         114 :   params.addRequiredCoupledVarWithAutoBuild(
      24             :       "etas", "var_name_base", "op_num", "Array of coupled order parameters");
      25         114 :   params.addCoupledVar("c", "Concentration field");
      26         114 :   params.addParam<Real>("k", 1.0, "stiffness constant multiplier");
      27          57 :   return params;
      28           0 : }
      29             : 
      30          45 : ExternalForceDensityMaterial::ExternalForceDensityMaterial(const InputParameters & parameters)
      31             :   : DerivativeMaterialInterface<Material>(parameters),
      32          45 :     _force_x(getFunction("force_x")),
      33          45 :     _force_y(getFunction("force_y")),
      34          45 :     _force_z(getFunction("force_z")),
      35          45 :     _c(coupledValue("c")),
      36          45 :     _c_name(coupledName("c", 0)),
      37          90 :     _k(getParam<Real>("k")),
      38          45 :     _op_num(coupledComponents(
      39             :         "etas")), // determine number of grains from the number of names passed in.
      40          45 :     _vals(coupledValues("etas")),
      41          45 :     _vals_name(coupledNames("etas")),
      42          45 :     _dF(declareProperty<std::vector<RealGradient>>("force_density_ext")),
      43          45 :     _dFdc(isCoupledConstant(_c_name) ? nullptr
      44         135 :                                      : &declarePropertyDerivative<std::vector<RealGradient>>(
      45             :                                            "force_density_ext", _c_name)),
      46          90 :     _dFdeta(_op_num)
      47             : {
      48             :   // Loop through grains and load derivatives
      49         165 :   for (unsigned int i = 0; i < _op_num; ++i)
      50         120 :     if (!isCoupledConstant(_vals_name[i]))
      51         120 :       _dFdeta[i] =
      52         240 :           &declarePropertyDerivative<std::vector<RealGradient>>("force_density_ext", _vals_name[i]);
      53          45 : }
      54             : 
      55             : void
      56      102000 : ExternalForceDensityMaterial::computeQpProperties()
      57             : {
      58      102000 :   _dF[_qp].resize(_op_num);
      59      102000 :   if (_dFdc)
      60      102000 :     (*_dFdc)[_qp].resize(_op_num);
      61             : 
      62      306000 :   for (unsigned int i = 0; i < _op_num; ++i)
      63             :   {
      64      204000 :     _dF[_qp][i](0) = _k * _c[_qp] * _force_x.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
      65      204000 :     _dF[_qp][i](1) = _k * _c[_qp] * _force_y.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
      66      204000 :     _dF[_qp][i](2) = _k * _c[_qp] * _force_z.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
      67             : 
      68      204000 :     if (_dFdc)
      69             :     {
      70      204000 :       (*_dFdc)[_qp][i](0) = _k * _force_x.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
      71      204000 :       (*_dFdc)[_qp][i](1) = _k * _force_y.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
      72      204000 :       (*_dFdc)[_qp][i](2) = _k * _force_z.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
      73             :     }
      74             :   }
      75             : 
      76      306000 :   for (unsigned int i = 0; i < _op_num; ++i)
      77             :   {
      78      204000 :     if (_dFdeta[i])
      79             :     {
      80      204000 :       (*_dFdeta[i])[_qp].resize(_op_num);
      81      612000 :       for (unsigned int j = 0; j < _op_num; ++j)
      82             :       {
      83      408000 :         (*_dFdeta[i])[_qp][j](0) = _k * _c[_qp] * _force_x.value(_t, _q_point[_qp]);
      84      408000 :         (*_dFdeta[i])[_qp][j](1) = _k * _c[_qp] * _force_y.value(_t, _q_point[_qp]);
      85      408000 :         (*_dFdeta[i])[_qp][j](2) = _k * _c[_qp] * _force_z.value(_t, _q_point[_qp]);
      86             :       }
      87             :     }
      88             :   }
      89      102000 : }

Generated by: LCOV version 1.14