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 9598 : ComputeResidualAndJacobianThread::ComputeResidualAndJacobianThread( 27 : FEProblemBase & fe_problem, 28 : const std::set<TagID> & vector_tags, 29 9598 : const std::set<TagID> & matrix_tags) 30 9598 : : NonlinearThread(fe_problem), _vector_tags(vector_tags), _matrix_tags(matrix_tags) 31 : { 32 9598 : } 33 : 34 : // Splitting Constructor 35 1403 : ComputeResidualAndJacobianThread::ComputeResidualAndJacobianThread( 36 1403 : ComputeResidualAndJacobianThread & x, Threads::split split) 37 1403 : : NonlinearThread(x, split), _vector_tags(x._vector_tags), _matrix_tags(x._matrix_tags) 38 : { 39 1403 : } 40 : 41 12404 : ComputeResidualAndJacobianThread::~ComputeResidualAndJacobianThread() {} 42 : 43 : void 44 81303 : ComputeResidualAndJacobianThread::compute(ResidualObject & ro) 45 : { 46 81303 : ro.computeResidualAndJacobian(); 47 81303 : } 48 : 49 : void 50 240 : ComputeResidualAndJacobianThread::accumulateLower() 51 : { 52 240 : _fe_problem.addResidualLower(_tid); 53 240 : _fe_problem.addJacobianLowerD(_tid); 54 240 : } 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 62 : ComputeResidualAndJacobianThread::accumulateNeighbor() 66 : { 67 62 : _fe_problem.addResidualNeighbor(_tid); 68 62 : _fe_problem.addJacobianNeighbor(_tid); 69 62 : } 70 : 71 : void 72 95480 : ComputeResidualAndJacobianThread::accumulate() 73 : { 74 95480 : _fe_problem.cacheResidual(_tid); 75 95480 : _fe_problem.cacheJacobian(_tid); 76 95480 : _num_cached++; 77 : 78 95480 : if (_num_cached % 20 == 0) 79 : { 80 3820 : _fe_problem.addCachedResidual(_tid); 81 3820 : _fe_problem.addCachedJacobian(_tid); 82 : } 83 95480 : } 84 : 85 : void 86 1403 : ComputeResidualAndJacobianThread::join(const ComputeResidualAndJacobianThread & /*y*/) 87 : { 88 1403 : } 89 : 90 : void 91 5231 : ComputeResidualAndJacobianThread::determineObjectWarehouses() 92 : { 93 : // We need to filter out vector tags that don't belong to the current nonlinear system 94 5231 : const auto & residual_vector_tags = _fe_problem.getVectorTags(Moose::VECTOR_TAG_RESIDUAL); 95 : 96 : // We would only like to consider the tags that belong to the current system 97 5231 : std::set<TagID> filtered_residual_tags; 98 5231 : _fe_problem.selectVectorTagsFromSystem(_nl, residual_vector_tags, filtered_residual_tags); 99 : 100 5231 : if (_vector_tags.size() && _vector_tags.size() != filtered_residual_tags.size()) 101 0 : mooseError("Can only currently compute the residual and Jacobian together if we are computing " 102 : "the full suite of residual tags"); 103 : 104 5231 : if (_matrix_tags.size() && _matrix_tags.size() != _fe_problem.numMatrixTags()) 105 0 : mooseError("Can only currently compute the residual and Jacobian together if we are computing " 106 : "the full suite of Jacobian tags"); 107 : 108 5231 : _tag_kernels = &_kernels; 109 5231 : _dg_warehouse = &_dg_kernels; 110 5231 : _ibc_warehouse = &_integrated_bcs; 111 5231 : _ik_warehouse = &_interface_kernels; 112 5231 : _hdg_warehouse = &_hdg_kernels; 113 : 114 5231 : if (_fe_problem.haveFV()) 115 : { 116 1475 : _fv_kernels.clear(); 117 1475 : _fe_problem.theWarehouse() 118 2950 : .query() 119 2950 : .template condition<AttribSysNum>(_nl.number()) 120 1475 : .template condition<AttribSystem>("FVElementalKernel") 121 1475 : .template condition<AttribSubdomains>(_subdomain) 122 1475 : .template condition<AttribThread>(_tid) 123 1475 : .queryInto(_fv_kernels); 124 : } 125 5231 : } 126 : 127 : void 128 0 : ComputeResidualAndJacobianThread::computeOnInternalFace() 129 : { 130 : mooseAssert(_hdg_warehouse->hasActiveBlockObjects(_subdomain, _tid), 131 : "We should not be called if we have no active HDG kernels"); 132 0 : for (const auto & hdg_kernel : _hdg_warehouse->getActiveBlockObjects(_subdomain, _tid)) 133 0 : hdg_kernel->computeResidualAndJacobianOnSide(); 134 0 : }