https://mooseframework.inl.gov
MaskedGrainForceAndTorque.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 
13 
16 {
18  params.addClassDescription("Userobject for masking/pinning grains and making forces and torques "
19  "acting on that grain zero");
20  params.addParam<UserObjectName>("grain_force",
21  "userobject for getting force and torque acting on grains");
22  params.addParam<std::vector<unsigned int>>("pinned_grains", "Grain numbers for pinned grains");
23  return params;
24 }
25 
28  GeneralUserObject(parameters),
29  _grain_force_torque_input(getUserObject<GrainForceAndTorqueInterface>("grain_force")),
30  _grain_forces_input(_grain_force_torque_input.getForceValues()),
31  _grain_torques_input(_grain_force_torque_input.getTorqueValues()),
32  _grain_force_c_jacobians_input(_grain_force_torque_input.getForceCJacobians()),
33  _grain_force_eta_jacobians_input(_grain_force_torque_input.getForceEtaJacobians()),
34  _pinned_grains(getParam<std::vector<unsigned int>>("pinned_grains")),
35  _num_pinned_grains(_pinned_grains.size()),
36  _grain_num(_grain_forces_input.size()),
37  _force_values(_grain_num),
38  _torque_values(_grain_num)
39 {
40 }
41 
42 void
44 {
45  for (unsigned int i = 0; i < _grain_num; ++i)
46  {
49 
50  if (_num_pinned_grains != 0)
51  {
52  for (unsigned int j = 0; j < _num_pinned_grains; ++j)
53  {
54  if (i == _pinned_grains[j])
55  {
56  _force_values[i] = 0.0;
57  _torque_values[i] = 0.0;
58  }
59  }
60  }
61  }
62 
64  {
65  unsigned int total_dofs = _subproblem.es().n_dofs();
66  _c_jacobians.resize(6 * _grain_num * total_dofs, 0.0);
67  _eta_jacobians.resize(_grain_num);
68  for (unsigned int i = 0; i < _grain_num; ++i)
69  for (unsigned int j = 0; j < total_dofs; ++j)
70  {
71  _c_jacobians[(6 * i + 0) * total_dofs + j] =
72  _grain_force_c_jacobians_input[(6 * i + 0) * total_dofs + j];
73  _c_jacobians[(6 * i + 1) * total_dofs + j] =
74  _grain_force_c_jacobians_input[(6 * i + 1) * total_dofs + j];
75  _c_jacobians[(6 * i + 2) * total_dofs + j] =
76  _grain_force_c_jacobians_input[(6 * i + 2) * total_dofs + j];
77  _c_jacobians[(6 * i + 3) * total_dofs + j] =
78  _grain_force_c_jacobians_input[(6 * i + 3) * total_dofs + j];
79  _c_jacobians[(6 * i + 4) * total_dofs + j] =
80  _grain_force_c_jacobians_input[(6 * i + 4) * total_dofs + j];
81  _c_jacobians[(6 * i + 5) * total_dofs + j] =
82  _grain_force_c_jacobians_input[(6 * i + 5) * total_dofs + j];
83 
84  if (_num_pinned_grains != 0)
85  for (unsigned int k = 0; k < _num_pinned_grains; ++k)
86  if (i == _pinned_grains[k])
87  {
88  _c_jacobians[(6 * i + 0) * total_dofs + j] = 0.0;
89  _c_jacobians[(6 * i + 1) * total_dofs + j] = 0.0;
90  _c_jacobians[(6 * i + 2) * total_dofs + j] = 0.0;
91  _c_jacobians[(6 * i + 3) * total_dofs + j] = 0.0;
92  _c_jacobians[(6 * i + 4) * total_dofs + j] = 0.0;
93  _c_jacobians[(6 * i + 5) * total_dofs + j] = 0.0;
94  }
95  }
96 
97  for (unsigned int i = 0; i < _grain_num; ++i)
98  {
99  _eta_jacobians[i].resize(6 * _grain_num * total_dofs);
100  for (unsigned int j = 0; j < _grain_num; ++j)
101  for (unsigned int k = 0; k < total_dofs; ++k)
102  {
103  _eta_jacobians[i][(6 * j + 0) * total_dofs + k] =
104  _grain_force_eta_jacobians_input[i][(6 * j + 0) * total_dofs + k];
105  _eta_jacobians[i][(6 * j + 1) * total_dofs + k] =
106  _grain_force_eta_jacobians_input[i][(6 * j + 1) * total_dofs + k];
107  _eta_jacobians[i][(6 * j + 2) * total_dofs + k] =
108  _grain_force_eta_jacobians_input[i][(6 * j + 2) * total_dofs + k];
109  _eta_jacobians[i][(6 * j + 3) * total_dofs + k] =
110  _grain_force_eta_jacobians_input[i][(6 * j + 3) * total_dofs + k];
111  _eta_jacobians[i][(6 * j + 4) * total_dofs + k] =
112  _grain_force_eta_jacobians_input[i][(6 * j + 4) * total_dofs + k];
113  _eta_jacobians[i][(6 * j + 5) * total_dofs + k] =
114  _grain_force_eta_jacobians_input[i][(6 * j + 5) * total_dofs + k];
115 
116  if (_num_pinned_grains != 0)
117  for (unsigned int l = 0; l < _num_pinned_grains; ++l)
118  if (j == _pinned_grains[l])
119  {
120  _eta_jacobians[i][(6 * j + 0) * total_dofs + k] = 0.0;
121  _eta_jacobians[i][(6 * j + 1) * total_dofs + k] = 0.0;
122  _eta_jacobians[i][(6 * j + 2) * total_dofs + k] = 0.0;
123  _eta_jacobians[i][(6 * j + 3) * total_dofs + k] = 0.0;
124  _eta_jacobians[i][(6 * j + 4) * total_dofs + k] = 0.0;
125  _eta_jacobians[i][(6 * j + 5) * total_dofs + k] = 0.0;
126  }
127  }
128  }
129  }
130 }
131 
132 const std::vector<RealGradient> &
134 {
135  return _force_values;
136 }
137 
138 const std::vector<RealGradient> &
140 {
141  return _torque_values;
142 }
143 
144 const std::vector<Real> &
146 {
147  return _c_jacobians;
148 }
149 
150 const std::vector<std::vector<Real>> &
152 {
153  return _eta_jacobians;
154 }
static InputParameters validParams()
const std::vector< RealGradient > & _grain_forces_input
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
This class provides interface for extracting the forces and torques computed in other UserObjects...
std::size_t n_dofs() const
registerMooseObject("PhaseFieldApp", MaskedGrainForceAndTorque)
MaskedGrainForceAndTorque(const InputParameters &parameters)
virtual const std::vector< RealGradient > & getForceValues() const
virtual const std::vector< std::vector< Real > > & getForceEtaJacobians() const
This class is here to get the force and torque acting on a grain from different userobjects and sum t...
SubProblem & _subproblem
virtual libMesh::EquationSystems & es()=0
std::vector< RealGradient > _torque_values
const std::vector< RealGradient > & _grain_torques_input
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
FEProblemBase & _fe_problem
const std::vector< std::vector< Real > > & _grain_force_eta_jacobians_input
void addClassDescription(const std::string &doc_string)
virtual const std::vector< RealGradient > & getTorqueValues() const
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
const bool & currentlyComputingJacobian() const
virtual const std::vector< Real > & getForceCJacobians() const
std::vector< unsigned int > _pinned_grains
static const std::string k
Definition: NS.h:130
void ErrorVector unsigned int
std::vector< std::vector< Real > > _eta_jacobians