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 "ComputeResidualAndJacobianThread.h" 11 : #include "NonlinearSystem.h" 12 : #include "Problem.h" 13 : #include "FEProblem.h" 14 : #include "KernelBase.h" 15 : #include "IntegratedBCBase.h" 16 : #include "DGKernelBase.h" 17 : #include "InterfaceKernelBase.h" 18 : #include "Material.h" 19 : #include "TimeKernel.h" 20 : #include "SwapBackSentinel.h" 21 : #include "FVTimeKernel.h" 22 : #include "HDGKernel.h" 23 : 24 : #include "libmesh/threads.h" 25 : 26 3467 : ComputeResidualAndJacobianThread::ComputeResidualAndJacobianThread( 27 : FEProblemBase & fe_problem, 28 : const std::set<TagID> & vector_tags, 29 3467 : const std::set<TagID> & matrix_tags) 30 3467 : : NonlinearThread(fe_problem), _vector_tags(vector_tags), _matrix_tags(matrix_tags) 31 : { 32 3467 : } 33 : 34 : // Splitting Constructor 35 339 : ComputeResidualAndJacobianThread::ComputeResidualAndJacobianThread( 36 339 : ComputeResidualAndJacobianThread & x, Threads::split split) 37 339 : : NonlinearThread(x, split), _vector_tags(x._vector_tags), _matrix_tags(x._matrix_tags) 38 : { 39 339 : } 40 : 41 4145 : ComputeResidualAndJacobianThread::~ComputeResidualAndJacobianThread() {} 42 : 43 : void 44 92994 : ComputeResidualAndJacobianThread::compute(ResidualObject & ro) 45 : { 46 92994 : ro.computeResidualAndJacobian(); 47 92994 : } 48 : 49 : void 50 270 : ComputeResidualAndJacobianThread::accumulateLower() 51 : { 52 270 : _fe_problem.addResidualLower(_tid); 53 270 : _fe_problem.addJacobianLowerD(_tid); 54 270 : } 55 : 56 : void 57 0 : ComputeResidualAndJacobianThread::accumulateNeighborLower() 58 : { 59 0 : _fe_problem.addResidualNeighbor(_tid); 60 0 : _fe_problem.addResidualLower(_tid); 61 0 : _fe_problem.addJacobianNeighborLowerD(_tid); 62 0 : } 63 : 64 : void 65 69 : ComputeResidualAndJacobianThread::accumulateNeighbor() 66 : { 67 69 : _fe_problem.addResidualNeighbor(_tid); 68 69 : _fe_problem.addJacobianNeighbor(_tid); 69 69 : } 70 : 71 : void 72 108424 : ComputeResidualAndJacobianThread::accumulate() 73 : { 74 108424 : _fe_problem.cacheResidual(_tid); 75 108424 : _fe_problem.cacheJacobian(_tid); 76 108424 : _num_cached++; 77 : 78 108424 : if (_num_cached % 20 == 0) 79 : { 80 4385 : Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx); 81 4385 : _fe_problem.addCachedResidual(_tid); 82 4385 : _fe_problem.addCachedJacobian(_tid); 83 4385 : } 84 108424 : } 85 : 86 : void 87 339 : ComputeResidualAndJacobianThread::join(const ComputeResidualAndJacobianThread & /*y*/) 88 : { 89 339 : } 90 : 91 : void 92 5938 : ComputeResidualAndJacobianThread::determineObjectWarehouses() 93 : { 94 : // We need to filter out vector tags that don't belong to the current nonlinear system 95 5938 : const auto & residual_vector_tags = _fe_problem.getVectorTags(Moose::VECTOR_TAG_RESIDUAL); 96 : 97 : // We would only like to consider the tags that belong to the current system 98 5938 : std::set<TagID> filtered_residual_tags; 99 5938 : _fe_problem.selectVectorTagsFromSystem(_nl, residual_vector_tags, filtered_residual_tags); 100 : 101 5938 : if (_vector_tags.size() && _vector_tags.size() != filtered_residual_tags.size()) 102 0 : mooseError("Can only currently compute the residual and Jacobian together if we are computing " 103 : "the full suite of residual tags"); 104 : 105 5938 : if (_matrix_tags.size() && _matrix_tags.size() != _fe_problem.numMatrixTags()) 106 0 : mooseError("Can only currently compute the residual and Jacobian together if we are computing " 107 : "the full suite of Jacobian tags"); 108 : 109 5938 : _tag_kernels = &_kernels; 110 5938 : _dg_warehouse = &_dg_kernels; 111 5938 : _ibc_warehouse = &_integrated_bcs; 112 5938 : _ik_warehouse = &_interface_kernels; 113 5938 : _hdg_warehouse = &_hdg_kernels; 114 : 115 5938 : if (_fe_problem.haveFV()) 116 : { 117 1633 : _fv_kernels.clear(); 118 1633 : _fe_problem.theWarehouse() 119 3266 : .query() 120 3266 : .template condition<AttribSysNum>(_nl.number()) 121 1633 : .template condition<AttribSystem>("FVElementalKernel") 122 1633 : .template condition<AttribSubdomains>(_subdomain) 123 1633 : .template condition<AttribThread>(_tid) 124 1633 : .queryInto(_fv_kernels); 125 : } 126 5938 : } 127 : 128 : void 129 0 : ComputeResidualAndJacobianThread::computeOnInternalFace() 130 : { 131 : mooseAssert(_hdg_warehouse->hasActiveBlockObjects(_subdomain, _tid), 132 : "We should not be called if we have no active HDG kernels"); 133 0 : for (const auto & hdg_kernel : _hdg_warehouse->getActiveBlockObjects(_subdomain, _tid)) 134 0 : if (hdg_kernel->hasBlocks(_subdomain)) 135 0 : hdg_kernel->computeResidualAndJacobianOnSide(); 136 0 : }