Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://www.mooseframework.org 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 "NonlocalDamage.h" 11 : 12 : registerMooseObject("TensorMechanicsApp", NonlocalDamage); 13 : registerMooseObject("TensorMechanicsApp", ADNonlocalDamage); 14 : 15 : template <bool is_ad> 16 : InputParameters 17 24 : NonlocalDamageTempl<is_ad>::validParams() 18 : { 19 24 : InputParameters params = ScalarDamageBaseTempl<is_ad>::validParams(); 20 24 : params.addClassDescription( 21 : "Nonlocal damage model. Given an RadialAverage UO this creates a new damage index that can " 22 : "be used as for ComputeDamageStress without havign to change existing local damage models."); 23 48 : params.addRequiredParam<UserObjectName>("average_UO", "Radial Average user object"); 24 48 : params.addRequiredParam<MaterialName>("local_damage_model", 25 : "Name of the local damage model used to compute " 26 : "the nonlocal damage index"); 27 24 : return params; 28 0 : } 29 : 30 : template <bool is_ad> 31 18 : NonlocalDamageTempl<is_ad>::NonlocalDamageTempl(const InputParameters & parameters) 32 : : ScalarDamageBaseTempl<is_ad>(parameters), 33 : GuaranteeConsumer(this), 34 18 : _average(this->template getUserObject<RadialAverage>("average_UO").getAverage()), 35 18 : _local_damage_model_name(this->template getParam<MaterialName>("local_damage_model")), 36 18 : _prev_elem(nullptr) 37 : { 38 18 : } 39 : template <bool is_ad> 40 : void 41 18 : NonlocalDamageTempl<is_ad>::initialSetup() 42 : { 43 18 : _local_damage_model = dynamic_cast<ScalarDamageBaseTempl<is_ad> *>( 44 18 : &this->getMaterialByName(_local_damage_model_name)); 45 : 46 18 : if (!_local_damage_model) 47 0 : this->template paramError("damage_model", 48 : "Damage Model " + _local_damage_model_name + 49 : " is not compatible with NonlocalDamage model"); 50 18 : } 51 : 52 : template <bool is_ad> 53 : void 54 8000 : NonlocalDamageTempl<is_ad>::initQpStatefulProperties() 55 : { 56 4000 : ScalarDamageBaseTempl<is_ad>::initQpStatefulProperties(); 57 8000 : } 58 : 59 : template <bool is_ad> 60 : void 61 1080000 : NonlocalDamageTempl<is_ad>::updateQpDamageIndex() 62 : { 63 : // First update underlying local damage model 64 1080000 : _local_damage_model->getQpDamageIndex(_qp); 65 : // Now update the nonlocal damage model 66 : // Only update iterator when we change to another element. This is for 67 : // computational costs related to map lookup. 68 1080000 : if (_prev_elem != _current_elem) 69 : { 70 135000 : _average_damage = _average.find(_current_elem->id()); 71 135000 : _prev_elem = _current_elem; 72 : } 73 : // Check that we found the new element 74 1080000 : if (_average_damage != _average.end()) 75 : // return max of the old damage or new average damage 76 1076000 : _damage_index[_qp] = std::max(_average_damage->second[_qp], _damage_index_old[_qp]); 77 : else 78 : // during startup the map is not made yet or 79 : // if AMR is used then the new element will not be found but it should 80 : // already have an old nonlocal damage value that needs to perserved 81 4000 : _damage_index[_qp] = std::max(0.0, _damage_index_old[_qp]); 82 1080000 : } 83 : 84 : template class NonlocalDamageTempl<false>; 85 : template class NonlocalDamageTempl<true>;