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 "PeridynamicsKernelBase.h" 11 : #include "PeridynamicsMesh.h" 12 : 13 : InputParameters 14 1336 : PeridynamicsKernelBase::validParams() 15 : { 16 1336 : InputParameters params = Kernel::validParams(); 17 1336 : params.addClassDescription( 18 : "Base class for calculating the residual and Jacobian for the peridynamic kernels"); 19 : 20 2672 : params.addParam<bool>("full_jacobian", 21 2672 : false, 22 : "Whether to include coupling terms with nodes connected to neighbors in " 23 : "the Jacobian matrix for state based formulations"); 24 : 25 1336 : return params; 26 0 : } 27 : 28 925 : PeridynamicsKernelBase::PeridynamicsKernelBase(const InputParameters & parameters) 29 : : Kernel(parameters), 30 925 : _bond_status_var(&_subproblem.getStandardVariable(_tid, "bond_status")), 31 1850 : _use_full_jacobian(getParam<bool>("full_jacobian")), 32 925 : _pdmesh(dynamic_cast<PeridynamicsMesh &>(_mesh)), 33 925 : _dim(_pdmesh.dimension()), 34 925 : _nnodes(2), 35 925 : _node_vol(_nnodes), 36 925 : _dg_vol_frac(_nnodes), 37 925 : _horizon_radius(_nnodes), 38 1850 : _horizon_vol(_nnodes) 39 : { 40 925 : } 41 : 42 : void 43 6845760 : PeridynamicsKernelBase::prepare() 44 : { 45 20537280 : for (unsigned int nd = 0; nd < _nnodes; ++nd) 46 : { 47 13691520 : _node_vol[nd] = _pdmesh.getNodeVolume(_current_elem->node_id(nd)); 48 : dof_id_type id_ji_in_ij = 49 13691520 : _pdmesh.getNeighborIndex(_current_elem->node_id(nd), _current_elem->node_id(1 - nd)); 50 13691520 : _dg_vol_frac[nd] = 51 13691520 : _pdmesh.getHorizonSubsetVolumeFraction(_current_elem->node_id(nd), id_ji_in_ij); 52 13691520 : _horizon_radius[nd] = _pdmesh.getHorizon(_current_elem->node_id(nd)); 53 13691520 : _horizon_vol[nd] = _pdmesh.getHorizonVolume(_current_elem->node_id(nd)); 54 : } 55 : 56 6845760 : _origin_vec = _pdmesh.getNodeCoord(_current_elem->node_id(1)) - 57 6845760 : _pdmesh.getNodeCoord(_current_elem->node_id(0)); 58 6845760 : _bond_status = _bond_status_var->getElementalValue(_current_elem); 59 6845760 : } 60 : 61 : void 62 5829230 : PeridynamicsKernelBase::computeResidual() 63 : { 64 5829230 : prepare(); 65 : 66 5829230 : prepareVectorTag(_assembly, _var.number()); 67 : mooseAssert(_local_re.size() == _nnodes, 68 : "PeridynamicsKernelBase is designed to only work with EDGE2 elements"); 69 5829230 : computeLocalResidual(); 70 5829230 : accumulateTaggedLocalResidual(); 71 : 72 5829230 : if (_has_save_in) 73 0 : for (unsigned int i = 0; i < _save_in.size(); ++i) 74 0 : _save_in[i]->sys().solution().add_vector(_local_re, _save_in[i]->dofIndices()); 75 : 76 : _local_re.zero(); 77 : 78 5829230 : computeNonlocalResidual(); 79 5829230 : } 80 : 81 : void 82 359377 : PeridynamicsKernelBase::computeJacobian() 83 : { 84 359377 : prepare(); 85 : 86 359377 : prepareMatrixTag(_assembly, _var.number(), _var.number()); 87 359377 : computeLocalJacobian(); 88 359377 : accumulateTaggedLocalMatrix(); 89 : 90 359377 : if (_has_diag_save_in) 91 : { 92 : unsigned int rows = _local_ke.m(); 93 0 : DenseVector<Number> diag(rows); 94 0 : for (unsigned int i = 0; i < rows; ++i) 95 0 : diag(i) = _local_ke(i, i); 96 : 97 0 : for (unsigned int i = 0; i < _diag_save_in.size(); ++i) 98 0 : _diag_save_in[i]->sys().solution().add_vector(diag, _diag_save_in[i]->dofIndices()); 99 : } 100 : 101 : _local_ke.zero(); 102 : 103 359377 : if (_use_full_jacobian) 104 29397 : computeNonlocalJacobian(); 105 359377 : }