https://mooseframework.inl.gov
SingleGrainRigidBodyMotion.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 "GrainTrackerInterface.h"
12 
14 
17 {
19  params.addClassDescription("Adds rigid mody motion to a single grain");
20  params.addParam<unsigned int>("op_index", 0, "Grain number for the kernel to be applied");
21  return params;
22 }
23 
25  : GrainRigidBodyMotionBase(parameters), _op_index(getParam<unsigned int>("op_index"))
26 {
27 }
28 
29 Real
31 {
32  return _velocity_advection * _grad_u[_qp] * _test[_i][_qp];
33 }
34 
35 Real
37 {
38  return _velocity_advection * _grad_phi[_j][_qp] * _test[_i][_qp] +
40 }
41 
42 Real
44 {
46 }
47 
49 {
51 }
52 
53 Real
55  dof_id_type /*dof_index*/)
56 {
58 }
59 
60 void
62 {
64 
65  auto grain_id = _grain_ids[_op_index];
66  if (grain_id != FeatureFloodCount::invalid_id)
67  {
68  mooseAssert(grain_id < _grain_volumes.size(), "grain_id out of bounds");
69  const auto volume = _grain_volumes[grain_id];
70  const auto centroid = _grain_tracker.getGrainCentroid(grain_id);
71  RealGradient force_jacobian;
72  RealGradient torque_jacobian;
73 
74  if (jvar == _c_var)
75  {
76  force_jacobian(0) = _grain_force_c_jacobians[(6 * grain_id + 0) * _total_dofs + dof_index];
77  force_jacobian(1) = _grain_force_c_jacobians[(6 * grain_id + 1) * _total_dofs + dof_index];
78  force_jacobian(2) = _grain_force_c_jacobians[(6 * grain_id + 2) * _total_dofs + dof_index];
79  torque_jacobian(0) = _grain_force_c_jacobians[(6 * grain_id + 3) * _total_dofs + dof_index];
80  torque_jacobian(1) = _grain_force_c_jacobians[(6 * grain_id + 4) * _total_dofs + dof_index];
81  torque_jacobian(2) = _grain_force_c_jacobians[(6 * grain_id + 5) * _total_dofs + dof_index];
82  }
83 
84  for (unsigned int jvar_index = 0; jvar_index < _op_num; ++jvar_index)
85  if (jvar == _vals_var[jvar_index])
86  {
87  force_jacobian(0) =
88  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 0) * _total_dofs + dof_index];
89  force_jacobian(1) =
90  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 1) * _total_dofs + dof_index];
91  force_jacobian(2) =
92  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 2) * _total_dofs + dof_index];
93  torque_jacobian(0) =
94  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 3) * _total_dofs + dof_index];
95  torque_jacobian(1) =
96  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 4) * _total_dofs + dof_index];
97  torque_jacobian(2) =
98  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 5) * _total_dofs + dof_index];
99  }
100 
101  const auto force_jac = _mt / volume * force_jacobian;
102  const auto torque_jac =
103  _mr / volume * torque_jacobian.cross(_current_elem->vertex_average() - centroid);
104 
105  _velocity_advection_jacobian = (force_jac + torque_jac);
106  }
107 }
108 
109 void
111 {
112  _velocity_advection = 0.0;
114 
115  auto grain_id = _grain_ids[_op_index];
116  if (grain_id != FeatureFloodCount::invalid_id)
117  {
118  mooseAssert(grain_id < _grain_volumes.size(), "grain_id out of bounds");
119  const auto volume = _grain_volumes[grain_id];
120  const auto centroid = _grain_tracker.getGrainCentroid(grain_id);
121  const auto force = _mt / volume * _grain_forces[grain_id];
122  const auto torque =
123  _mr / volume * (_grain_torques[grain_id].cross(_current_elem->vertex_average() - centroid));
124 
125  _velocity_advection = (force + torque);
126  }
127 }
const unsigned int _op_num
no. of order parameters
const VariableGradient & _grad_u
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
virtual Real computeQpOffDiagJacobian(unsigned int)
const VariablePhiGradient & _grad_phi
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.
const VariableTestValue & _test
virtual Real computeQpNonlocalOffDiagJacobian(unsigned int, dof_id_type)
std::vector< unsigned int > _grain_ids
obtain the active grain ids
const std::vector< unsigned int > _vals_var
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
static InputParameters validParams()
unsigned int _i
static const unsigned int invalid_id
TypeVector< typename CompareTypes< Real, T2 >::supertype > cross(const TypeVector< T2 > &v) const
Real volume(const MeshBase &mesh, unsigned int dim=libMesh::invalid_uint)
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.
unsigned int _j
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int _c_var
int label for the Concentration
void addClassDescription(const std::string &doc_string)
const Real _mt
constant value corresponding to grain translation
const Elem *const & _current_elem
void ErrorVector unsigned int
virtual void getUserObjectJacobian(unsigned int jvar, dof_id_type dof_index)
unsigned int _qp
uint8_t dof_id_type
const std::vector< Real > & _grain_force_c_jacobians