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