www.mooseframework.org
MultiGrainRigidBodyMotion.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 
12 // MOOSE includes
13 #include "GrainTrackerInterface.h"
14 #include "MooseVariable.h"
15 
17 
18 template <>
19 InputParameters
21 {
22  InputParameters params = validParams<GrainRigidBodyMotionBase>();
23  params.addClassDescription("Adds rigid mody motion to grains");
24  return params;
25 }
26 
27 MultiGrainRigidBodyMotion::MultiGrainRigidBodyMotion(const InputParameters & parameters)
28  : GrainRigidBodyMotionBase(parameters)
29 {
30 }
31 
32 Real
34 {
35  return _velocity_advection * _grad_c[_qp] * _test[_i][_qp];
36 }
37 
38 Real
40 {
41  if (_var.number() == _c_var) // Requires c jacobian
42  return _velocity_advection * _grad_phi[_j][_qp] * _test[_i][_qp] +
43  _velocity_advection_jacobian * _grad_c[_qp] * _test[_i][_qp];
44 
45  return 0.0;
46 }
47 
48 Real
50 {
51  if (jvar == _c_var) // Requires c jacobian
52  return _velocity_advection * _grad_phi[_j][_qp] * _test[_i][_qp] +
53  _velocity_advection_jacobian * _grad_c[_qp] * _test[_i][_qp];
54  else
55  return _velocity_advection_jacobian * _grad_c[_qp] * _test[_i][_qp];
56 }
57 
59 {
60  if (_var.number() == _c_var) // Requires c jacobian
61  return _velocity_advection_jacobian * _grad_c[_qp] * _test[_i][_qp];
62 
63  return 0.0;
64 }
65 
66 Real
68  dof_id_type /* dof_index */)
69 {
70  return _velocity_advection_jacobian * _grad_c[_qp] * _test[_i][_qp];
71 }
72 
73 void
74 MultiGrainRigidBodyMotion::getUserObjectJacobian(unsigned int jvar, dof_id_type dof_index)
75 {
77 
78  for (MooseIndex(_grain_ids) i = 0; i < _grain_ids.size(); ++i)
79  {
80  auto grain_id = _grain_ids[i];
81  if (grain_id != FeatureFloodCount::invalid_id)
82  {
83  mooseAssert(grain_id < _grain_volumes.size(), "grain_id out of bounds");
84  const auto volume = _grain_volumes[grain_id];
85  const auto centroid = _grain_tracker.getGrainCentroid(grain_id);
86  RealGradient force_jacobian;
87  RealGradient torque_jacobian;
88 
89  if (jvar == _c_var)
90  {
91  force_jacobian(0) = _grain_force_c_jacobians[(6 * grain_id + 0) * _total_dofs + dof_index];
92  force_jacobian(1) = _grain_force_c_jacobians[(6 * grain_id + 1) * _total_dofs + dof_index];
93  force_jacobian(2) = _grain_force_c_jacobians[(6 * grain_id + 2) * _total_dofs + dof_index];
94  torque_jacobian(0) = _grain_force_c_jacobians[(6 * grain_id + 3) * _total_dofs + dof_index];
95  torque_jacobian(1) = _grain_force_c_jacobians[(6 * grain_id + 4) * _total_dofs + dof_index];
96  torque_jacobian(2) = _grain_force_c_jacobians[(6 * grain_id + 5) * _total_dofs + dof_index];
97  }
98 
99  for (unsigned int jvar_index = 0; jvar_index < _op_num; ++jvar_index)
100  if (jvar == _vals_var[jvar_index])
101  {
102  force_jacobian(0) =
103  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 0) * _total_dofs + dof_index];
104  force_jacobian(1) =
105  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 1) * _total_dofs + dof_index];
106  force_jacobian(2) =
107  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 2) * _total_dofs + dof_index];
108  torque_jacobian(0) =
109  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 3) * _total_dofs + dof_index];
110  torque_jacobian(1) =
111  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 4) * _total_dofs + dof_index];
112  torque_jacobian(2) =
113  _grain_force_eta_jacobians[jvar_index][(6 * grain_id + 5) * _total_dofs + dof_index];
114  }
115 
116  const auto force_jac = _mt / volume * force_jacobian;
117  const auto torque_jac =
118  _mr / volume * torque_jacobian.cross(_current_elem->centroid() - centroid);
119 
120  _velocity_advection_jacobian += (force_jac + torque_jac);
121  }
122  }
123 }
124 
125 void
127 {
128  _velocity_advection = 0.0;
129  _grain_ids = _grain_tracker.getVarToFeatureVector(_current_elem->id());
130 
131  for (MooseIndex(_grain_ids) i = 0; i < _grain_ids.size(); ++i)
132  {
133  auto grain_id = _grain_ids[i];
134  if (grain_id != FeatureFloodCount::invalid_id)
135  {
136  mooseAssert(grain_id < _grain_volumes.size(), "grain_id out of bounds");
137  const auto volume = _grain_volumes[grain_id];
138  const auto centroid = _grain_tracker.getGrainCentroid(grain_id);
139  const auto force = _mt / volume * _grain_forces[grain_id];
140  const auto torque =
141  _mr / volume * (_grain_torques[grain_id].cross(_current_elem->centroid() - centroid));
142 
143  _velocity_advection += (force + torque);
144  }
145  }
146 }
VectorValue< Real > RealGradient
const unsigned int _op_num
no. of order parameters
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.
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.
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 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
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
registerMooseObject("PhaseFieldApp", MultiGrainRigidBodyMotion)
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