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