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 "KernelValue.h" 11 : #include "Assembly.h" 12 : #include "SystemBase.h" 13 : #include "libmesh/quadrature.h" 14 : 15 : InputParameters 16 6176 : KernelValue::validParams() 17 : { 18 6176 : return Kernel::validParams(); 19 : } 20 : 21 30 : KernelValue::KernelValue(const InputParameters & parameters) : Kernel(parameters) {} 22 : 23 : void 24 57778 : KernelValue::computeResidual() 25 : { 26 57778 : prepareVectorTag(_assembly, _var.number()); 27 : 28 57778 : const unsigned int n_test = _test.size(); 29 288890 : for (_qp = 0; _qp < _qrule->n_points(); _qp++) 30 : { 31 231112 : Real value = precomputeQpResidual() * _JxW[_qp] * _coord[_qp]; 32 1155560 : for (_i = 0; _i < n_test; _i++) // target for auto vectorization 33 924448 : _local_re(_i) += value * _test[_i][_qp]; 34 : } 35 : 36 57778 : accumulateTaggedLocalResidual(); 37 : 38 57778 : if (_has_save_in) 39 0 : for (const auto & var : _save_in) 40 0 : var->sys().solution().add_vector(_local_re, var->dofIndices()); 41 57778 : } 42 : 43 : void 44 29232 : KernelValue::computeJacobian() 45 : { 46 29232 : prepareMatrixTag(_assembly, _var.number(), _var.number()); 47 : 48 29232 : const unsigned int n_test = _test.size(); 49 146160 : for (_qp = 0; _qp < _qrule->n_points(); _qp++) 50 584640 : for (_j = 0; _j < _phi.size(); _j++) 51 : { 52 467712 : Real value = precomputeQpJacobian() * _JxW[_qp] * _coord[_qp]; 53 2338560 : for (_i = 0; _i < n_test; _i++) // target for auto vectorization 54 1870848 : _local_ke(_i, _j) += value * _test[_i][_qp]; 55 : } 56 : 57 29232 : accumulateTaggedLocalMatrix(); 58 : 59 29232 : if (_has_diag_save_in) 60 : { 61 0 : unsigned int rows = _local_ke.m(); 62 0 : DenseVector<Number> diag(rows); 63 0 : for (unsigned int i = 0; i < rows; i++) // target for auto vectorization 64 0 : diag(i) = _local_ke(i, i); 65 : 66 0 : for (const auto & var : _diag_save_in) 67 0 : var->sys().solution().add_vector(diag, var->dofIndices()); 68 0 : } 69 29232 : } 70 : 71 : void 72 51200 : KernelValue::computeOffDiagJacobian(const unsigned int jvar_num) 73 : { 74 51200 : const auto & jvar = getVariable(jvar_num); 75 : 76 51200 : if (jvar_num == _var.number()) 77 25600 : computeJacobian(); 78 : else 79 : { 80 25600 : prepareMatrixTag(_assembly, _var.number(), jvar_num); 81 : // This (undisplaced) jvar could potentially yield the wrong phi size if this object is acting 82 : // on the displaced mesh 83 25600 : auto phi_size = jvar.dofIndices().size(); 84 : 85 128000 : for (_j = 0; _j < phi_size; _j++) 86 512000 : for (_qp = 0; _qp < _qrule->n_points(); _qp++) 87 2048000 : for (_i = 0; _i < _test.size(); _i++) 88 1638400 : _local_ke(_i, _j) += _JxW[_qp] * _coord[_qp] * computeQpOffDiagJacobian(jvar_num); 89 25600 : accumulateTaggedLocalMatrix(); 90 : } 91 51200 : } 92 : 93 : Real 94 0 : KernelValue::computeQpResidual() 95 : { 96 0 : mooseError("Override precomputeQpResidual() in your KernelValue derived class!"); 97 : } 98 : 99 : Real 100 0 : KernelValue::precomputeQpJacobian() 101 : { 102 0 : return 0.0; 103 : }