www.mooseframework.org
MaskedGrainForceAndTorque.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 /****************************************************************/
7 
9 
10 template <>
11 InputParameters
13 {
14  InputParameters params = validParams<GeneralUserObject>();
15  params.addClassDescription("Userobject for masking/pinning grains and making forces and torques "
16  "acting on that grain zero");
17  params.addParam<UserObjectName>("grain_force",
18  "userobject for getting force and torque acting on grains");
19  params.addParam<std::vector<unsigned int>>("pinned_grains", "Grain numbers for pinned grains");
20  return params;
21 }
22 
23 MaskedGrainForceAndTorque::MaskedGrainForceAndTorque(const InputParameters & parameters)
25  GeneralUserObject(parameters),
26  _grain_force_torque_input(getUserObject<GrainForceAndTorqueInterface>("grain_force")),
27  _grain_forces_input(_grain_force_torque_input.getForceValues()),
28  _grain_torques_input(_grain_force_torque_input.getTorqueValues()),
29  _grain_force_c_jacobians_input(_grain_force_torque_input.getForceCJacobians()),
30  _grain_force_eta_jacobians_input(_grain_force_torque_input.getForceEtaJacobians()),
31  _pinned_grains(getParam<std::vector<unsigned int>>("pinned_grains")),
32  _num_pinned_grains(_pinned_grains.size()),
33  _grain_num(_grain_forces_input.size()),
34  _force_values(_grain_num),
35  _torque_values(_grain_num)
36 {
37 }
38 
39 void
41 {
42  for (unsigned int i = 0; i < _grain_num; ++i)
43  {
46 
47  if (_num_pinned_grains != 0)
48  {
49  for (unsigned int j = 0; j < _num_pinned_grains; ++j)
50  {
51  if (i == _pinned_grains[j])
52  {
53  _force_values[i] = 0.0;
54  _torque_values[i] = 0.0;
55  }
56  }
57  }
58  }
59 
60  if (_fe_problem.currentlyComputingJacobian())
61  {
62  unsigned int total_dofs = _subproblem.es().n_dofs();
63  _c_jacobians.resize(6 * _grain_num * total_dofs, 0.0);
64  _eta_jacobians.resize(_grain_num);
65  for (unsigned int i = 0; i < _grain_num; ++i)
66  for (unsigned int j = 0; j < total_dofs; ++j)
67  {
68  _c_jacobians[(6 * i + 0) * total_dofs + j] =
69  _grain_force_c_jacobians_input[(6 * i + 0) * total_dofs + j];
70  _c_jacobians[(6 * i + 1) * total_dofs + j] =
71  _grain_force_c_jacobians_input[(6 * i + 1) * total_dofs + j];
72  _c_jacobians[(6 * i + 2) * total_dofs + j] =
73  _grain_force_c_jacobians_input[(6 * i + 2) * total_dofs + j];
74  _c_jacobians[(6 * i + 3) * total_dofs + j] =
75  _grain_force_c_jacobians_input[(6 * i + 3) * total_dofs + j];
76  _c_jacobians[(6 * i + 4) * total_dofs + j] =
77  _grain_force_c_jacobians_input[(6 * i + 4) * total_dofs + j];
78  _c_jacobians[(6 * i + 5) * total_dofs + j] =
79  _grain_force_c_jacobians_input[(6 * i + 5) * total_dofs + j];
80 
81  if (_num_pinned_grains != 0)
82  for (unsigned int k = 0; k < _num_pinned_grains; ++k)
83  if (i == _pinned_grains[k])
84  {
85  _c_jacobians[(6 * i + 0) * total_dofs + j] = 0.0;
86  _c_jacobians[(6 * i + 1) * total_dofs + j] = 0.0;
87  _c_jacobians[(6 * i + 2) * total_dofs + j] = 0.0;
88  _c_jacobians[(6 * i + 3) * total_dofs + j] = 0.0;
89  _c_jacobians[(6 * i + 4) * total_dofs + j] = 0.0;
90  _c_jacobians[(6 * i + 5) * total_dofs + j] = 0.0;
91  }
92  }
93 
94  for (unsigned int i = 0; i < _grain_num; ++i)
95  {
96  _eta_jacobians[i].resize(6 * _grain_num * total_dofs);
97  for (unsigned int j = 0; j < _grain_num; ++j)
98  for (unsigned int k = 0; k < total_dofs; ++k)
99  {
100  _eta_jacobians[i][(6 * j + 0) * total_dofs + k] =
101  _grain_force_eta_jacobians_input[i][(6 * j + 0) * total_dofs + k];
102  _eta_jacobians[i][(6 * j + 1) * total_dofs + k] =
103  _grain_force_eta_jacobians_input[i][(6 * j + 1) * total_dofs + k];
104  _eta_jacobians[i][(6 * j + 2) * total_dofs + k] =
105  _grain_force_eta_jacobians_input[i][(6 * j + 2) * total_dofs + k];
106  _eta_jacobians[i][(6 * j + 3) * total_dofs + k] =
107  _grain_force_eta_jacobians_input[i][(6 * j + 3) * total_dofs + k];
108  _eta_jacobians[i][(6 * j + 4) * total_dofs + k] =
109  _grain_force_eta_jacobians_input[i][(6 * j + 4) * total_dofs + k];
110  _eta_jacobians[i][(6 * j + 5) * total_dofs + k] =
111  _grain_force_eta_jacobians_input[i][(6 * j + 5) * total_dofs + k];
112 
113  if (_num_pinned_grains != 0)
114  for (unsigned int l = 0; l < _num_pinned_grains; ++l)
115  if (j == _pinned_grains[l])
116  {
117  _eta_jacobians[i][(6 * j + 0) * total_dofs + k] = 0.0;
118  _eta_jacobians[i][(6 * j + 1) * total_dofs + k] = 0.0;
119  _eta_jacobians[i][(6 * j + 2) * total_dofs + k] = 0.0;
120  _eta_jacobians[i][(6 * j + 3) * total_dofs + k] = 0.0;
121  _eta_jacobians[i][(6 * j + 4) * total_dofs + k] = 0.0;
122  _eta_jacobians[i][(6 * j + 5) * total_dofs + k] = 0.0;
123  }
124  }
125  }
126  }
127 }
128 
129 const std::vector<RealGradient> &
131 {
132  return _force_values;
133 }
134 
135 const std::vector<RealGradient> &
137 {
138  return _torque_values;
139 }
140 
141 const std::vector<Real> &
143 {
144  return _c_jacobians;
145 }
146 
147 const std::vector<std::vector<Real>> &
149 {
150  return _eta_jacobians;
151 }
virtual const std::vector< std::vector< Real > > & getForceEtaJacobians() const
const std::vector< RealGradient > & _grain_forces_input
This class provides interface for extracting the forces and torques computed in other UserObjects...
MaskedGrainForceAndTorque(const InputParameters &parameters)
virtual const std::vector< RealGradient > & getForceValues() const
std::vector< RealGradient > _torque_values
const std::vector< RealGradient > & _grain_torques_input
virtual const std::vector< Real > & getForceCJacobians() const
const std::vector< Real > & _grain_force_c_jacobians_input
std::vector< RealGradient > _force_values
providing grain forces, torques and their jacobians w. r. t c
virtual const std::vector< RealGradient > & getTorqueValues() const
InputParameters validParams< MaskedGrainForceAndTorque >()
const std::vector< std::vector< Real > > & _grain_force_eta_jacobians_input
std::vector< unsigned int > _pinned_grains
std::vector< std::vector< Real > > _eta_jacobians