www.mooseframework.org
SingleGrainRigidBodyMotion.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
9 
10 template <>
11 InputParameters
13 {
14  InputParameters params = validParams<GrainRigidBodyMotionBase>();
15  params.addClassDescription("Adds rigid mody motion to a single grain");
16  params.addParam<unsigned int>("op_index", 0, "Grain number for the kernel to be applied");
17  return params;
18 }
19 
20 SingleGrainRigidBodyMotion::SingleGrainRigidBodyMotion(const InputParameters & parameters)
21  : GrainRigidBodyMotionBase(parameters), _op_index(getParam<unsigned int>("op_index"))
22 {
23 }
24 
25 Real
27 {
28  return _velocity_advection * _grad_u[_qp] * _test[_i][_qp];
29 }
30 
31 Real
33 {
34  return _velocity_advection * _grad_phi[_j][_qp] * _test[_i][_qp] +
35  _velocity_advection_jacobian * _grad_u[_qp] * _test[_i][_qp];
36 }
37 
38 Real
40 {
41  return _velocity_advection_jacobian * _grad_u[_qp] * _test[_i][_qp];
42 }
43 
45 {
46  return _velocity_advection_jacobian * _grad_u[_qp] * _test[_i][_qp];
47 }
48 
49 Real
51  dof_id_type /*dof_index*/)
52 {
53  return _velocity_advection_jacobian * _grad_u[_qp] * _test[_i][_qp];
54 }
55 
56 void
57 SingleGrainRigidBodyMotion::getUserObjectJacobian(unsigned int jvar, dof_id_type dof_index)
58 {
60 
61  auto grain_id = _grain_ids[_op_index];
62  if (grain_id != FeatureFloodCount::invalid_id)
63  {
64  mooseAssert(grain_id < _grain_volumes.size(), "grain_id out of bounds");
65  const auto volume = _grain_volumes[grain_id];
66  const auto centroid = _grain_tracker.getGrainCentroid(grain_id);
67  RealGradient force_jacobian;
68  RealGradient torque_jacobian;
69 
70  if (jvar == _c_var)
71  {
72  force_jacobian(0) = _grain_force_c_jacobians[(6 * grain_id + 0) * _total_dofs + dof_index];
73  force_jacobian(1) = _grain_force_c_jacobians[(6 * grain_id + 1) * _total_dofs + dof_index];
74  force_jacobian(2) = _grain_force_c_jacobians[(6 * grain_id + 2) * _total_dofs + dof_index];
75  torque_jacobian(0) = _grain_force_c_jacobians[(6 * grain_id + 3) * _total_dofs + dof_index];
76  torque_jacobian(1) = _grain_force_c_jacobians[(6 * grain_id + 4) * _total_dofs + dof_index];
77  torque_jacobian(2) = _grain_force_c_jacobians[(6 * grain_id + 5) * _total_dofs + dof_index];
78  }
79 
80  for (unsigned int jvar_index = 0; jvar_index < _op_num; ++jvar_index)
81  if (jvar == _vals_var[jvar_index])
82  {
83  force_jacobian(0) =
84  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 0) * _total_dofs + dof_index];
85  force_jacobian(1) =
86  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 1) * _total_dofs + dof_index];
87  force_jacobian(2) =
88  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 2) * _total_dofs + dof_index];
89  torque_jacobian(0) =
90  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 3) * _total_dofs + dof_index];
91  torque_jacobian(1) =
92  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 4) * _total_dofs + dof_index];
93  torque_jacobian(2) =
94  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 5) * _total_dofs + dof_index];
95  }
96 
97  const auto force_jac = _mt / volume * force_jacobian;
98  const auto torque_jac =
99  _mr / volume * torque_jacobian.cross(_current_elem->centroid() - centroid);
100 
101  _velocity_advection_jacobian = (force_jac + torque_jac);
102  }
103 }
104 
105 void
107 {
108  _velocity_advection = 0.0;
109  _grain_ids = _grain_tracker.getVarToFeatureVector(_current_elem->id());
110 
111  auto grain_id = _grain_ids[_op_index];
112  if (grain_id != FeatureFloodCount::invalid_id)
113  {
114  mooseAssert(grain_id < _grain_volumes.size(), "grain_id out of bounds");
115  const auto volume = _grain_volumes[grain_id];
116  const auto centroid = _grain_tracker.getGrainCentroid(grain_id);
117  const auto force = _mt / volume * _grain_forces[grain_id];
118  const auto torque =
119  _mr / volume * (_grain_torques[grain_id].cross(_current_elem->centroid() - centroid));
120 
121  _velocity_advection = (force + torque);
122  }
123 }
const unsigned int _op_num
no. of order parameters
virtual Point getGrainCentroid(unsigned int grain_id) const =0
Returns the centroid for the given grain number.
virtual Real computeQpOffDiagJacobian(unsigned int)
RealGradient _velocity_advection
storing the advection velocity and corresponding jacobian entries calculated in userobjects ...
const Real _mr
constant value corresponding to grain rotation
virtual Real computeQpNonlocalOffDiagJacobian(unsigned int, dof_id_type)
std::vector< unsigned int > _grain_ids
obtain the active grain ids
const std::vector< std::vector< Real > > & _grain_force_eta_jacobians
const VectorPostprocessorValue & _grain_volumes
The grain volumes.
const std::vector< RealGradient > & _grain_torques
virtual const std::vector< unsigned int > & getVarToFeatureVector(dof_id_type elem_id) const =0
Returns a list of active unique feature ids for a particular element.
const std::vector< RealGradient > & _grain_forces
std::vector< unsigned int > _vals_var
static const unsigned int invalid_id
SingleGrainRigidBodyMotion(const InputParameters &parameters)
unsigned int _total_dofs
get the total no. of dofs in the system
virtual Real computeQpNonlocalJacobian(dof_id_type)
const GrainTrackerInterface & _grain_tracker
grain tracker object
unsigned int _op_index
Grain number for the kernel to be applied.
InputParameters validParams< SingleGrainRigidBodyMotion >()
unsigned int _c_var
int label for the Concentration
const Real _mt
constant value corresponding to grain translation
InputParameters validParams< GrainRigidBodyMotionBase >()
virtual void getUserObjectJacobian(unsigned int jvar, dof_id_type dof_index)
const std::vector< Real > & _grain_force_c_jacobians