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 "ExternalForceDensityMaterial.h" 11 : #include "Function.h" 12 : 13 : registerMooseObject("PhaseFieldApp", ExternalForceDensityMaterial); 14 : 15 : InputParameters 16 117 : ExternalForceDensityMaterial::validParams() 17 : { 18 117 : InputParameters params = Material::validParams(); 19 117 : params.addClassDescription("Providing external applied force density to grains"); 20 234 : params.addParam<FunctionName>("force_x", 0.0, "The forcing function in x direction."); 21 234 : params.addParam<FunctionName>("force_y", 0.0, "The forcing function in y direction."); 22 234 : params.addParam<FunctionName>("force_z", 0.0, "The forcing function in z direction."); 23 234 : params.addRequiredCoupledVarWithAutoBuild( 24 : "etas", "var_name_base", "op_num", "Array of coupled order parameters"); 25 234 : params.addCoupledVar("c", "Concentration field"); 26 234 : params.addParam<Real>("k", 1.0, "stiffness constant multiplier"); 27 117 : return params; 28 0 : } 29 : 30 90 : ExternalForceDensityMaterial::ExternalForceDensityMaterial(const InputParameters & parameters) 31 : : DerivativeMaterialInterface<Material>(parameters), 32 90 : _force_x(getFunction("force_x")), 33 90 : _force_y(getFunction("force_y")), 34 90 : _force_z(getFunction("force_z")), 35 90 : _c(coupledValue("c")), 36 90 : _c_name(coupledName("c", 0)), 37 180 : _k(getParam<Real>("k")), 38 90 : _op_num(coupledComponents( 39 : "etas")), // determine number of grains from the number of names passed in. 40 90 : _vals(coupledValues("etas")), 41 90 : _vals_name(coupledNames("etas")), 42 90 : _dF(declareProperty<std::vector<RealGradient>>("force_density_ext")), 43 90 : _dFdc(isCoupledConstant(_c_name) ? nullptr 44 270 : : &declarePropertyDerivative<std::vector<RealGradient>>( 45 : "force_density_ext", _c_name)), 46 180 : _dFdeta(_op_num) 47 : { 48 : // Loop through grains and load derivatives 49 324 : for (unsigned int i = 0; i < _op_num; ++i) 50 234 : if (!isCoupledConstant(_vals_name[i])) 51 234 : _dFdeta[i] = 52 468 : &declarePropertyDerivative<std::vector<RealGradient>>("force_density_ext", _vals_name[i]); 53 90 : } 54 : 55 : void 56 238000 : ExternalForceDensityMaterial::computeQpProperties() 57 : { 58 238000 : _dF[_qp].resize(_op_num); 59 238000 : if (_dFdc) 60 238000 : (*_dFdc)[_qp].resize(_op_num); 61 : 62 714000 : for (unsigned int i = 0; i < _op_num; ++i) 63 : { 64 476000 : _dF[_qp][i](0) = _k * _c[_qp] * _force_x.value(_t, _q_point[_qp]) * (*_vals[i])[_qp]; 65 476000 : _dF[_qp][i](1) = _k * _c[_qp] * _force_y.value(_t, _q_point[_qp]) * (*_vals[i])[_qp]; 66 476000 : _dF[_qp][i](2) = _k * _c[_qp] * _force_z.value(_t, _q_point[_qp]) * (*_vals[i])[_qp]; 67 : 68 476000 : if (_dFdc) 69 : { 70 476000 : (*_dFdc)[_qp][i](0) = _k * _force_x.value(_t, _q_point[_qp]) * (*_vals[i])[_qp]; 71 476000 : (*_dFdc)[_qp][i](1) = _k * _force_y.value(_t, _q_point[_qp]) * (*_vals[i])[_qp]; 72 476000 : (*_dFdc)[_qp][i](2) = _k * _force_z.value(_t, _q_point[_qp]) * (*_vals[i])[_qp]; 73 : } 74 : } 75 : 76 714000 : for (unsigned int i = 0; i < _op_num; ++i) 77 : { 78 476000 : if (_dFdeta[i]) 79 : { 80 476000 : (*_dFdeta[i])[_qp].resize(_op_num); 81 1428000 : for (unsigned int j = 0; j < _op_num; ++j) 82 : { 83 952000 : (*_dFdeta[i])[_qp][j](0) = _k * _c[_qp] * _force_x.value(_t, _q_point[_qp]); 84 952000 : (*_dFdeta[i])[_qp][j](1) = _k * _c[_qp] * _force_y.value(_t, _q_point[_qp]); 85 952000 : (*_dFdeta[i])[_qp][j](2) = _k * _c[_qp] * _force_z.value(_t, _q_point[_qp]); 86 : } 87 : } 88 : } 89 238000 : }