www.mooseframework.org
MultiGrainRigidBodyMotion.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 /****************************************************************/
8 
9 // MOOSE includes
10 #include "GrainTrackerInterface.h"
11 #include "MooseVariable.h"
12 
13 template <>
14 InputParameters
16 {
17  InputParameters params = validParams<GrainRigidBodyMotionBase>();
18  params.addClassDescription("Adds rigid mody motion to grains");
19  return params;
20 }
21 
22 MultiGrainRigidBodyMotion::MultiGrainRigidBodyMotion(const InputParameters & parameters)
23  : GrainRigidBodyMotionBase(parameters)
24 {
25 }
26 
27 Real
29 {
30  return _velocity_advection * _grad_c[_qp] * _test[_i][_qp];
31 }
32 
33 Real
35 {
36  if (_var.number() == _c_var) // Requires c jacobian
37  return _velocity_advection * _grad_phi[_j][_qp] * _test[_i][_qp] +
38  _velocity_advection_jacobian * _grad_c[_qp] * _test[_i][_qp];
39 
40  return 0.0;
41 }
42 
43 Real
45 {
46  if (jvar == _c_var) // Requires c jacobian
47  return _velocity_advection * _grad_phi[_j][_qp] * _test[_i][_qp] +
48  _velocity_advection_jacobian * _grad_c[_qp] * _test[_i][_qp];
49  else
50  return _velocity_advection_jacobian * _grad_c[_qp] * _test[_i][_qp];
51 }
52 
54 {
55  if (_var.number() == _c_var) // Requires c jacobian
56  return _velocity_advection_jacobian * _grad_c[_qp] * _test[_i][_qp];
57 
58  return 0.0;
59 }
60 
61 Real
63  dof_id_type /* dof_index */)
64 {
65  return _velocity_advection_jacobian * _grad_c[_qp] * _test[_i][_qp];
66 }
67 
68 void
69 MultiGrainRigidBodyMotion::getUserObjectJacobian(unsigned int jvar, dof_id_type dof_index)
70 {
72 
73  for (auto i = beginIndex(_grain_ids); i < _grain_ids.size(); ++i)
74  {
75  auto grain_id = _grain_ids[i];
76  if (grain_id != FeatureFloodCount::invalid_id)
77  {
78  mooseAssert(grain_id < _grain_volumes.size(), "grain_id out of bounds");
79  const auto volume = _grain_volumes[grain_id];
80  const auto centroid = _grain_tracker.getGrainCentroid(grain_id);
81  RealGradient force_jacobian;
82  RealGradient torque_jacobian;
83 
84  if (jvar == _c_var)
85  {
86  force_jacobian(0) = _grain_force_c_jacobians[(6 * grain_id + 0) * _total_dofs + dof_index];
87  force_jacobian(1) = _grain_force_c_jacobians[(6 * grain_id + 1) * _total_dofs + dof_index];
88  force_jacobian(2) = _grain_force_c_jacobians[(6 * grain_id + 2) * _total_dofs + dof_index];
89  torque_jacobian(0) = _grain_force_c_jacobians[(6 * grain_id + 3) * _total_dofs + dof_index];
90  torque_jacobian(1) = _grain_force_c_jacobians[(6 * grain_id + 4) * _total_dofs + dof_index];
91  torque_jacobian(2) = _grain_force_c_jacobians[(6 * grain_id + 5) * _total_dofs + dof_index];
92  }
93 
94  for (unsigned int jvar_index = 0; jvar_index < _op_num; ++jvar_index)
95  if (jvar == _vals_var[jvar_index])
96  {
97  force_jacobian(0) =
98  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 0) * _total_dofs + dof_index];
99  force_jacobian(1) =
100  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 1) * _total_dofs + dof_index];
101  force_jacobian(2) =
102  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 2) * _total_dofs + dof_index];
103  torque_jacobian(0) =
104  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 3) * _total_dofs + dof_index];
105  torque_jacobian(1) =
106  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 4) * _total_dofs + dof_index];
107  torque_jacobian(2) =
108  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 5) * _total_dofs + dof_index];
109  }
110 
111  const auto force_jac = _mt / volume * force_jacobian;
112  const auto torque_jac =
113  _mr / volume * torque_jacobian.cross(_current_elem->centroid() - centroid);
114 
115  _velocity_advection_jacobian += (force_jac + torque_jac);
116  }
117  }
118 }
119 
120 void
122 {
123  _velocity_advection = 0.0;
124  _grain_ids = _grain_tracker.getVarToFeatureVector(_current_elem->id());
125 
126  for (auto i = beginIndex(_grain_ids); i < _grain_ids.size(); ++i)
127  {
128  auto grain_id = _grain_ids[i];
129  if (grain_id != FeatureFloodCount::invalid_id)
130  {
131  mooseAssert(grain_id < _grain_volumes.size(), "grain_id out of bounds");
132  const auto volume = _grain_volumes[grain_id];
133  const auto centroid = _grain_tracker.getGrainCentroid(grain_id);
134  const auto force = _mt / volume * _grain_forces[grain_id];
135  const auto torque =
136  _mr / volume * (_grain_torques[grain_id].cross(_current_elem->centroid() - centroid));
137 
138  _velocity_advection += (force + torque);
139  }
140  }
141 }
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.
RealGradient _velocity_advection
storing the advection velocity and corresponding jacobian entries calculated in userobjects ...
virtual Real computeQpNonlocalJacobian(dof_id_type)
virtual Real computeQpOffDiagJacobian(unsigned int)
const Real _mr
constant value corresponding to grain rotation
const VariableGradient & _grad_c
Variable gradient for the concentration.
MultiGrainRigidBodyMotion(const InputParameters &parameters)
InputParameters validParams< MultiGrainRigidBodyMotion >()
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
unsigned int _total_dofs
get the total no. of dofs in the system
virtual Real computeQpNonlocalOffDiagJacobian(unsigned int, dof_id_type)
const GrainTrackerInterface & _grain_tracker
grain tracker object
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