https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ExternalForceDensityMaterial.C
Go to the documentation of this file.
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
11#include "Function.h"
12
14
17{
19 params.addClassDescription("Providing external applied force density to grains");
20 params.addParam<FunctionName>("force_x", 0.0, "The forcing function in x direction.");
21 params.addParam<FunctionName>("force_y", 0.0, "The forcing function in y direction.");
22 params.addParam<FunctionName>("force_z", 0.0, "The forcing function in z direction.");
24 "etas", "var_name_base", "op_num", "Array of coupled order parameters");
25 params.addCoupledVar("c", "Concentration field");
26 params.addParam<Real>("k", 1.0, "stiffness constant multiplier");
27 return params;
28}
29
32 _force_x(getFunction("force_x")),
33 _force_y(getFunction("force_y")),
34 _force_z(getFunction("force_z")),
35 _c(coupledValue("c")),
36 _c_name(coupledName("c", 0)),
37 _k(getParam<Real>("k")),
38 _op_num(coupledComponents(
39 "etas")), // determine number of grains from the number of names passed in.
40 _vals(coupledValues("etas")),
41 _vals_name(coupledNames("etas")),
42 _dF(declareProperty<std::vector<RealGradient>>("force_density_ext")),
43 _dFdc(isCoupledConstant(_c_name) ? nullptr
44 : &declarePropertyDerivative<std::vector<RealGradient>>(
45 "force_density_ext", _c_name)),
46 _dFdeta(_op_num)
47{
48 // Loop through grains and load derivatives
49 for (unsigned int i = 0; i < _op_num; ++i)
50 if (!isCoupledConstant(_vals_name[i]))
51 _dFdeta[i] =
52 &declarePropertyDerivative<std::vector<RealGradient>>("force_density_ext", _vals_name[i]);
53}
54
55void
57{
58 _dF[_qp].resize(_op_num);
59 if (_dFdc)
60 (*_dFdc)[_qp].resize(_op_num);
61
62 for (unsigned int i = 0; i < _op_num; ++i)
63 {
64 _dF[_qp][i](0) = _k * _c[_qp] * _force_x.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
65 _dF[_qp][i](1) = _k * _c[_qp] * _force_y.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
66 _dF[_qp][i](2) = _k * _c[_qp] * _force_z.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
67
68 if (_dFdc)
69 {
70 (*_dFdc)[_qp][i](0) = _k * _force_x.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
71 (*_dFdc)[_qp][i](1) = _k * _force_y.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
72 (*_dFdc)[_qp][i](2) = _k * _force_z.value(_t, _q_point[_qp]) * (*_vals[i])[_qp];
73 }
74 }
75
76 for (unsigned int i = 0; i < _op_num; ++i)
77 {
78 if (_dFdeta[i])
79 {
80 (*_dFdeta[i])[_qp].resize(_op_num);
81 for (unsigned int j = 0; j < _op_num; ++j)
82 {
83 (*_dFdeta[i])[_qp][j](0) = _k * _c[_qp] * _force_x.value(_t, _q_point[_qp]);
84 (*_dFdeta[i])[_qp][j](1) = _k * _c[_qp] * _force_y.value(_t, _q_point[_qp]);
85 (*_dFdeta[i])[_qp][j](2) = _k * _c[_qp] * _force_z.value(_t, _q_point[_qp]);
86 }
87 }
88 }
89}
registerMooseObject("PhaseFieldApp", ExternalForceDensityMaterial)
This Material calculates the force density acting on a particle/grain due to interaction between part...
std::vector< MaterialProperty< std::vector< RealGradient > > * > _dFdeta
ExternalForceDensityMaterial(const InputParameters &parameters)
const std::vector< const VariableValue * > _vals
const std::vector< VariableName > _vals_name
MaterialProperty< std::vector< RealGradient > > & _dF
force density material
MaterialProperty< std::vector< RealGradient > > * _dFdc
first order derivative of force density material w.r.t c
const VariableValue & _c
concentration field considered to be the density of particles
virtual Real value(Real t, const Point &p) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void addCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredCoupledVarWithAutoBuild(const std::string &name, const std::string &base_name, const std::string &num_name, const std::string &doc_string)
virtual void resize(const std::size_t size) override final
static InputParameters validParams()