https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
42void
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);
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
132const std::vector<RealGradient> &
137
138const std::vector<RealGradient> &
143
144const std::vector<Real> &
149
150const std::vector<std::vector<Real>> &
registerMooseObject("PhaseFieldApp", MaskedGrainForceAndTorque)
void ErrorVector unsigned int
static InputParameters validParams()
This class provides interface for extracting the forces and torques computed in other UserObjects.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
This class is here to get the force and torque acting on a grain from different userobjects and sum t...
virtual const std::vector< RealGradient > & getTorqueValues() const
static InputParameters validParams()
virtual const std::vector< Real > & getForceCJacobians() const
const std::vector< RealGradient > & _grain_forces_input
const std::vector< std::vector< Real > > & _grain_force_eta_jacobians_input
MaskedGrainForceAndTorque(const InputParameters &parameters)
std::vector< unsigned int > _pinned_grains
std::vector< RealGradient > _force_values
providing grain forces, torques and their jacobians w. r. t c
const std::vector< RealGradient > & _grain_torques_input
virtual const std::vector< std::vector< Real > > & getForceEtaJacobians() const
std::vector< std::vector< Real > > _eta_jacobians
const std::vector< Real > & _grain_force_c_jacobians_input
std::vector< RealGradient > _torque_values
virtual const std::vector< RealGradient > & getForceValues() const
const bool & currentlyComputingJacobian() const
virtual libMesh::EquationSystems & es()=0
SubProblem & _subproblem
FEProblemBase & _fe_problem
std::size_t n_dofs() const