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 "ComputeResidualThread.h" 11 : #include "NonlinearSystemBase.h" 12 : #include "KernelBase.h" 13 : #include "DGKernelBase.h" 14 : #include "IntegratedBCBase.h" 15 : #include "FVElementalKernel.h" 16 : #include "InterfaceKernelBase.h" 17 : #include "HDGKernel.h" 18 : #include "libmesh/threads.h" 19 : 20 3293495 : ComputeResidualThread::ComputeResidualThread(FEProblemBase & fe_problem, 21 3293495 : const std::set<TagID> & tags) 22 3293495 : : NonlinearThread(fe_problem), _tags(tags) 23 : { 24 3293495 : } 25 : 26 : // Splitting Constructor 27 288862 : ComputeResidualThread::ComputeResidualThread(ComputeResidualThread & x, Threads::split split) 28 288862 : : NonlinearThread(x, split), _tags(x._tags) 29 : { 30 288862 : } 31 : 32 3871181 : ComputeResidualThread::~ComputeResidualThread() {} 33 : 34 : void 35 747665164 : ComputeResidualThread::compute(ResidualObject & ro) 36 : { 37 747665164 : ro.computeResidual(); 38 747665110 : } 39 : 40 : void 41 20264 : ComputeResidualThread::accumulateLower() 42 : { 43 20264 : _fe_problem.addResidualLower(_tid); 44 20264 : } 45 : 46 : void 47 44637 : ComputeResidualThread::accumulateNeighbor() 48 : { 49 44637 : _fe_problem.addResidualNeighbor(_tid); 50 44637 : } 51 : 52 : void 53 2054953 : ComputeResidualThread::accumulateNeighborLower() 54 : { 55 2054953 : _fe_problem.addResidualNeighbor(_tid); 56 2054953 : _fe_problem.addResidualLower(_tid); 57 2054953 : } 58 : 59 : void 60 327873953 : ComputeResidualThread::accumulate() 61 : { 62 327873953 : _fe_problem.cacheResidual(_tid); 63 327873953 : _num_cached++; 64 : 65 327873953 : if (_num_cached % 20 == 0) 66 : { 67 15229546 : Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx); 68 15229546 : _fe_problem.addCachedResidual(_tid); 69 15229546 : } 70 327873953 : } 71 : 72 : void 73 288859 : ComputeResidualThread::join(const ComputeResidualThread & /*y*/) 74 : { 75 288859 : } 76 : 77 : void 78 4317939 : ComputeResidualThread::determineObjectWarehouses() 79 : { 80 : // If users pass a empty vector or a full size of vector, 81 : // we take all kernels 82 4317939 : if (!_tags.size() || _tags.size() == _fe_problem.numVectorTags(Moose::VECTOR_TAG_RESIDUAL)) 83 : { 84 4259483 : _tag_kernels = &_kernels; 85 4259483 : _dg_warehouse = &_dg_kernels; 86 4259483 : _ibc_warehouse = &_integrated_bcs; 87 4259483 : _ik_warehouse = &_interface_kernels; 88 4259483 : _hdg_warehouse = &_hdg_kernels; 89 : } 90 : // If we have one tag only, 91 : // We call tag based storage 92 58456 : else if (_tags.size() == 1) 93 : { 94 34190 : _tag_kernels = &(_kernels.getVectorTagObjectWarehouse(*(_tags.begin()), _tid)); 95 34190 : _dg_warehouse = &(_dg_kernels.getVectorTagObjectWarehouse(*(_tags.begin()), _tid)); 96 34190 : _ibc_warehouse = &(_integrated_bcs.getVectorTagObjectWarehouse(*(_tags.begin()), _tid)); 97 34190 : _ik_warehouse = &(_interface_kernels.getVectorTagObjectWarehouse(*(_tags.begin()), _tid)); 98 34190 : _hdg_warehouse = &(_hdg_kernels.getVectorTagObjectWarehouse(*(_tags.begin()), _tid)); 99 : } 100 : // This one may be expensive 101 : else 102 : { 103 24266 : _tag_kernels = &(_kernels.getVectorTagsObjectWarehouse(_tags, _tid)); 104 24266 : _dg_warehouse = &(_dg_kernels.getVectorTagsObjectWarehouse(_tags, _tid)); 105 24266 : _ibc_warehouse = &(_integrated_bcs.getVectorTagsObjectWarehouse(_tags, _tid)); 106 24266 : _ik_warehouse = &(_interface_kernels.getVectorTagsObjectWarehouse(_tags, _tid)); 107 24266 : _hdg_warehouse = &(_hdg_kernels.getVectorTagsObjectWarehouse(_tags, _tid)); 108 : } 109 : 110 4317939 : if (_fe_problem.haveFV()) 111 : { 112 198493 : _fv_kernels.clear(); 113 198493 : _fe_problem.theWarehouse() 114 396986 : .query() 115 396986 : .template condition<AttribSysNum>(_nl.number()) 116 198493 : .template condition<AttribSystem>("FVElementalKernel") 117 198493 : .template condition<AttribSubdomains>(_subdomain) 118 198493 : .template condition<AttribThread>(_tid) 119 198493 : .template condition<AttribVectorTags>(_tags) 120 198493 : .queryInto(_fv_kernels); 121 : } 122 4317939 : } 123 : 124 : void 125 2646165 : ComputeResidualThread::computeOnInternalFace() 126 : { 127 : mooseAssert(_hdg_warehouse->hasActiveBlockObjects(_subdomain, _tid), 128 : "We should not be called if we have no active HDG kernels"); 129 6526029 : for (const auto & hdg_kernel : _hdg_warehouse->getActiveBlockObjects(_subdomain, _tid)) 130 : { 131 : mooseAssert( 132 : hdg_kernel->hasBlocks(_subdomain), 133 : "We queried the warehouse for active blocks on this subdomain, so this better be active"); 134 : mooseAssert( 135 : _neighbor_subdomain != Moose::INVALID_BLOCK_ID, 136 : "We should have set a valid neighbor subdomain ID if we made it in side this method"); 137 3879864 : if (hdg_kernel->hasBlocks(_neighbor_subdomain)) 138 3879846 : hdg_kernel->computeResidualOnSide(); 139 : } 140 2646165 : }