www.mooseframework.org
GrainForceAndTorqueSum.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 summing forces and torques acting on a grain");
16  params.addParam<std::vector<UserObjectName>>(
17  "grain_forces",
18  "List of names of user objects that provides forces and torques applied to grains");
19  params.addParam<unsigned int>("grain_num", "Number of grains");
20  return params;
21 }
22 
23 GrainForceAndTorqueSum::GrainForceAndTorqueSum(const InputParameters & parameters)
25  GeneralUserObject(parameters),
26  _sum_objects(getParam<std::vector<UserObjectName>>("grain_forces")),
27  _num_forces(_sum_objects.size()),
28  _grain_num(getParam<unsigned int>("grain_num")),
29  _sum_forces(_num_forces),
30  _force_values(_grain_num),
31  _torque_values(_grain_num)
32 {
33  for (unsigned int i = 0; i < _num_forces; ++i)
34  _sum_forces[i] = &getUserObjectByName<GrainForceAndTorqueInterface>(_sum_objects[i]);
35 }
36 
37 void
39 {
40  for (unsigned int i = 0; i < _grain_num; ++i)
41  {
42  _force_values[i] = 0.0;
43  _torque_values[i] = 0.0;
44  for (unsigned int j = 0; j < _num_forces; ++j)
45  {
46  _force_values[i] += (_sum_forces[j]->getForceValues())[i];
47  _torque_values[i] += (_sum_forces[j]->getTorqueValues())[i];
48  }
49  }
50 
51  if (_fe_problem.currentlyComputingJacobian())
52  {
53  unsigned int total_dofs = _subproblem.es().n_dofs();
54  _c_jacobians.resize(6 * _grain_num * total_dofs, 0.0);
55  _eta_jacobians.resize(_grain_num);
56 
57  for (unsigned int i = 0; i < _c_jacobians.size(); ++i)
58  for (unsigned int j = 0; j < _num_forces; ++j)
60 
61  for (unsigned int i = 0; i < _grain_num; ++i)
62  {
63  _eta_jacobians[i].resize(6 * _grain_num * total_dofs, 0.0);
64  for (unsigned int j = 0; j < _eta_jacobians[i].size(); ++j)
65  for (unsigned int k = 0; k < _num_forces; ++k)
66  _eta_jacobians[i][j] += (_sum_forces[k]->getForceEtaJacobians())[i][j];
67  }
68  }
69 }
70 
71 const std::vector<RealGradient> &
73 {
74  return _force_values;
75 }
76 
77 const std::vector<RealGradient> &
79 {
80  return _torque_values;
81 }
82 
83 const std::vector<Real> &
85 {
86  return _c_jacobians;
87 }
88 
89 const std::vector<std::vector<Real>> &
91 {
92  return _eta_jacobians;
93 }
virtual const std::vector< std::vector< Real > > & getForceEtaJacobians() const
std::vector< RealGradient > _force_values
providing grain forces, torques and their jacobians w. r. t c
std::vector< Real > _c_jacobians
std::vector< const GrainForceAndTorqueInterface * > _sum_forces
This class provides interface for extracting the forces and torques computed in other UserObjects...
GrainForceAndTorqueSum(const InputParameters &parameters)
virtual const std::vector< RealGradient > & getTorqueValues() const
virtual const std::vector< RealGradient > & getForceValues() const
std::vector< UserObjectName > _sum_objects
Vector of userobjects providing forces and torques acting on grains.
std::vector< std::vector< Real > > _eta_jacobians
unsigned int _num_forces
Total no. of userobjects that provides forces and torques acting on grains.
InputParameters validParams< GrainForceAndTorqueSum >()
std::vector< RealGradient > _torque_values
virtual const std::vector< Real > & getForceCJacobians() const