www.mooseframework.org
SingleGrainRigidBodyMotion.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "GrainTrackerInterface.h"
12 
14 
15 template <>
16 InputParameters
18 {
19  InputParameters params = validParams<GrainRigidBodyMotionBase>();
20  params.addClassDescription("Adds rigid mody motion to a single grain");
21  params.addParam<unsigned int>("op_index", 0, "Grain number for the kernel to be applied");
22  return params;
23 }
24 
25 SingleGrainRigidBodyMotion::SingleGrainRigidBodyMotion(const InputParameters & parameters)
26  : GrainRigidBodyMotionBase(parameters), _op_index(getParam<unsigned int>("op_index"))
27 {
28 }
29 
30 Real
32 {
33  return _velocity_advection * _grad_u[_qp] * _test[_i][_qp];
34 }
35 
36 Real
38 {
39  return _velocity_advection * _grad_phi[_j][_qp] * _test[_i][_qp] +
40  _velocity_advection_jacobian * _grad_u[_qp] * _test[_i][_qp];
41 }
42 
43 Real
45 {
46  return _velocity_advection_jacobian * _grad_u[_qp] * _test[_i][_qp];
47 }
48 
50 {
51  return _velocity_advection_jacobian * _grad_u[_qp] * _test[_i][_qp];
52 }
53 
54 Real
56  dof_id_type /*dof_index*/)
57 {
58  return _velocity_advection_jacobian * _grad_u[_qp] * _test[_i][_qp];
59 }
60 
61 void
62 SingleGrainRigidBodyMotion::getUserObjectJacobian(unsigned int jvar, dof_id_type dof_index)
63 {
65 
66  auto grain_id = _grain_ids[_op_index];
67  if (grain_id != FeatureFloodCount::invalid_id)
68  {
69  mooseAssert(grain_id < _grain_volumes.size(), "grain_id out of bounds");
70  const auto volume = _grain_volumes[grain_id];
71  const auto centroid = _grain_tracker.getGrainCentroid(grain_id);
72  RealGradient force_jacobian;
73  RealGradient torque_jacobian;
74 
75  if (jvar == _c_var)
76  {
77  force_jacobian(0) = _grain_force_c_jacobians[(6 * grain_id + 0) * _total_dofs + dof_index];
78  force_jacobian(1) = _grain_force_c_jacobians[(6 * grain_id + 1) * _total_dofs + dof_index];
79  force_jacobian(2) = _grain_force_c_jacobians[(6 * grain_id + 2) * _total_dofs + dof_index];
80  torque_jacobian(0) = _grain_force_c_jacobians[(6 * grain_id + 3) * _total_dofs + dof_index];
81  torque_jacobian(1) = _grain_force_c_jacobians[(6 * grain_id + 4) * _total_dofs + dof_index];
82  torque_jacobian(2) = _grain_force_c_jacobians[(6 * grain_id + 5) * _total_dofs + dof_index];
83  }
84 
85  for (unsigned int jvar_index = 0; jvar_index < _op_num; ++jvar_index)
86  if (jvar == _vals_var[jvar_index])
87  {
88  force_jacobian(0) =
89  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 0) * _total_dofs + dof_index];
90  force_jacobian(1) =
91  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 1) * _total_dofs + dof_index];
92  force_jacobian(2) =
93  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 2) * _total_dofs + dof_index];
94  torque_jacobian(0) =
95  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 3) * _total_dofs + dof_index];
96  torque_jacobian(1) =
97  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 4) * _total_dofs + dof_index];
98  torque_jacobian(2) =
99  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 5) * _total_dofs + dof_index];
100  }
101 
102  const auto force_jac = _mt / volume * force_jacobian;
103  const auto torque_jac =
104  _mr / volume * torque_jacobian.cross(_current_elem->centroid() - centroid);
105 
106  _velocity_advection_jacobian = (force_jac + torque_jac);
107  }
108 }
109 
110 void
112 {
113  _velocity_advection = 0.0;
114  _grain_ids = _grain_tracker.getVarToFeatureVector(_current_elem->id());
115 
116  auto grain_id = _grain_ids[_op_index];
117  if (grain_id != FeatureFloodCount::invalid_id)
118  {
119  mooseAssert(grain_id < _grain_volumes.size(), "grain_id out of bounds");
120  const auto volume = _grain_volumes[grain_id];
121  const auto centroid = _grain_tracker.getGrainCentroid(grain_id);
122  const auto force = _mt / volume * _grain_forces[grain_id];
123  const auto torque =
124  _mr / volume * (_grain_torques[grain_id].cross(_current_elem->centroid() - centroid));
125 
126  _velocity_advection = (force + torque);
127  }
128 }
VectorValue< Real > RealGradient
const unsigned int _op_num
no. of order parameters
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
registerMooseObject("PhaseFieldApp", SingleGrainRigidBodyMotion)
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.
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 Point getGrainCentroid(unsigned int grain_id) const =0
Returns the centroid for the given grain number.
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