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 "ForceDensityMaterial.h" 11 : 12 : registerMooseObject("PhaseFieldApp", ForceDensityMaterial); 13 : 14 : InputParameters 15 188 : ForceDensityMaterial::validParams() 16 : { 17 188 : InputParameters params = Material::validParams(); 18 188 : params.addClassDescription("Calculating the force density acting on a grain"); 19 376 : params.addCoupledVar("etas", "Array of coupled order parameters"); 20 376 : params.addCoupledVar("c", "Concentration field"); 21 376 : params.addParam<Real>("ceq", 0.9816, "Equilibrium density"); 22 376 : params.addParam<Real>("cgb", 0.25, "Threshold Concentration for GB"); 23 376 : params.addParam<Real>("k", 100.0, "stiffness constant"); 24 188 : return params; 25 0 : } 26 : 27 144 : ForceDensityMaterial::ForceDensityMaterial(const InputParameters & parameters) 28 : : DerivativeMaterialInterface<Material>(parameters), 29 144 : _c(coupledValue("c")), 30 144 : _c_name(coupledName("c", 0)), 31 288 : _ceq(getParam<Real>("ceq")), 32 288 : _cgb(getParam<Real>("cgb")), 33 288 : _k(getParam<Real>("k")), 34 144 : _op_num(coupledComponents( 35 : "etas")), // determine number of grains from the number of names passed in. 36 144 : _vals(coupledValues("etas")), 37 144 : _grad_vals(coupledGradients("etas")), 38 144 : _vals_name(coupledNames("etas")), 39 144 : _product_etas(_op_num), 40 144 : _sum_grad_etas(_op_num), 41 144 : _dF(declareProperty<std::vector<RealGradient>>("force_density")), 42 144 : _dFdc(declarePropertyDerivative<std::vector<RealGradient>>("force_density", _c_name)), 43 288 : _dFdgradeta(_op_num) 44 : { 45 : // Loop through grains and load derivatives 46 432 : for (unsigned int i = 0; i < _op_num; ++i) 47 288 : if (!isCoupledConstant(_vals_name[i])) 48 288 : _dFdgradeta[i] = 49 576 : &declarePropertyDerivative<std::vector<Real>>("force_density", _vals_name[i]); 50 144 : } 51 : 52 : void 53 575720 : ForceDensityMaterial::computeQpProperties() 54 : { 55 575720 : _dF[_qp].resize(_op_num); 56 575720 : _dFdc[_qp].resize(_op_num); 57 : 58 1727160 : for (unsigned int i = 0; i < _op_num; ++i) 59 : { 60 1151440 : _sum_grad_etas[i] = 0.0; 61 3454320 : for (unsigned int j = 0; j < _op_num; ++j) 62 2302880 : if (j != i) 63 : { 64 2295024 : _product_etas[i] = (*_vals[i])[_qp] * (*_vals[j])[_qp] >= _cgb ? 1.0 : 0.0; 65 1151440 : _sum_grad_etas[i] += _product_etas[i] * ((*_grad_vals[i])[_qp] - (*_grad_vals[j])[_qp]); 66 : } 67 1151440 : _dF[_qp][i] = _k * (_c[_qp] - _ceq) * _sum_grad_etas[i]; 68 1151440 : _dFdc[_qp][i] = _k * _sum_grad_etas[i]; 69 : } 70 : 71 1727160 : for (unsigned int i = 0; i < _op_num; ++i) 72 : { 73 1151440 : if (_dFdgradeta[i]) 74 1151440 : (*_dFdgradeta[i])[_qp].resize(_op_num); 75 3454320 : for (unsigned int j = 0; j < _op_num; ++j) 76 : { 77 6908640 : for (unsigned int k = 0; k < _op_num; ++k) 78 4605760 : if (k != j) 79 4590048 : _product_etas[j] = (*_vals[j])[_qp] * (*_vals[k])[_qp] >= _cgb ? 1.0 : 0.0; 80 : 81 2302880 : if (_dFdgradeta[i]) 82 : { 83 2302880 : if (j == i) 84 1151440 : (*_dFdgradeta[i])[_qp][j] = _k * _product_etas[j] * (_c[_qp] - _ceq); 85 : else 86 1151440 : (*_dFdgradeta[i])[_qp][j] = -_k * _product_etas[j] * (_c[_qp] - _ceq); 87 : } 88 : } 89 : } 90 575720 : }