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 "ComputeNodalKernelsThread.h" 11 : 12 : // MOOSE includes 13 : #include "AuxiliarySystem.h" 14 : #include "FEProblem.h" 15 : #include "MooseMesh.h" 16 : #include "MooseVariableFE.h" 17 : #include "NodalKernelBase.h" 18 : 19 : #include "libmesh/threads.h" 20 : 21 14423 : ComputeNodalKernelsThread::ComputeNodalKernelsThread( 22 : FEProblemBase & fe_problem, 23 : MooseObjectTagWarehouse<NodalKernelBase> & nodal_kernels, 24 14423 : const std::set<TagID> & tags) 25 : : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(fe_problem), 26 14423 : _fe_problem(fe_problem), 27 28846 : _aux_sys(fe_problem.getAuxiliarySystem()), 28 14423 : _tags(tags), 29 14423 : _nodal_kernels(nodal_kernels), 30 14423 : _num_cached(0) 31 : { 32 14423 : } 33 : 34 : // Splitting Constructor 35 6866 : ComputeNodalKernelsThread::ComputeNodalKernelsThread(ComputeNodalKernelsThread & x, 36 6866 : Threads::split split) 37 : : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(x, split), 38 6866 : _fe_problem(x._fe_problem), 39 6866 : _aux_sys(x._aux_sys), 40 6866 : _tags(x._tags), 41 6866 : _nodal_kernels(x._nodal_kernels), 42 6866 : _num_cached(0) 43 : { 44 6866 : } 45 : 46 : void 47 21289 : ComputeNodalKernelsThread::pre() 48 : { 49 21289 : _num_cached = 0; 50 : 51 21289 : if (!_tags.size() || _tags.size() == _fe_problem.numVectorTags(Moose::VECTOR_TAG_RESIDUAL)) 52 21277 : _nkernel_warehouse = &_nodal_kernels; 53 12 : else if (_tags.size() == 1) 54 0 : _nkernel_warehouse = &(_nodal_kernels.getVectorTagObjectWarehouse(*(_tags.begin()), _tid)); 55 : else 56 12 : _nkernel_warehouse = &(_nodal_kernels.getVectorTagsObjectWarehouse(_tags, _tid)); 57 21289 : } 58 : 59 : void 60 1114733 : ComputeNodalKernelsThread::onNode(ConstNodeRange::const_iterator & node_it) 61 : { 62 1114733 : const Node * node = *node_it; 63 : 64 1114733 : std::set<const NodalKernelBase *> nks_executed; 65 : 66 : // prepare variables 67 1493920 : for (auto * var : _aux_sys._nodal_vars[_tid]) 68 379187 : var->prepareAux(); 69 : 70 1114733 : _fe_problem.reinitNode(node, _tid); 71 : 72 1114733 : const auto & block_ids = _aux_sys.mesh().getNodeBlockIds(*node); 73 2238066 : for (const auto block : block_ids) 74 1123333 : if (_nkernel_warehouse->hasActiveBlockObjects(block, _tid)) 75 : { 76 1074669 : std::set<TagID> needed_fe_var_vector_tags; 77 1074669 : _nkernel_warehouse->updateBlockFEVariableCoupledVectorTagDependency( 78 : block, needed_fe_var_vector_tags, _tid); 79 1074669 : _fe_problem.setActiveFEVariableCoupleableVectorTags(needed_fe_var_vector_tags, _tid); 80 : 81 1074669 : const auto & objects = _nkernel_warehouse->getActiveBlockObjects(block, _tid); 82 3269991 : for (const auto & nodal_kernel : objects) 83 2195322 : if (nks_executed.emplace(nodal_kernel.get()).second) 84 : { 85 2195254 : nodal_kernel->setSubdomains(block_ids); 86 2195254 : nodal_kernel->computeResidual(); 87 : } 88 1074669 : } 89 : 90 1114733 : _num_cached++; 91 : 92 1114733 : if (_num_cached == 20) // Cache 20 nodes worth before adding into the residual 93 : { 94 48832 : _num_cached = 0; 95 48832 : Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx); 96 48832 : _fe_problem.addCachedResidual(_tid); 97 48832 : } 98 1114733 : } 99 : 100 : void 101 6866 : ComputeNodalKernelsThread::join(const ComputeNodalKernelsThread & /*y*/) 102 : { 103 6866 : } 104 : 105 : void 106 21289 : ComputeNodalKernelsThread::printGeneralExecutionInformation() const 107 : { 108 21289 : if (!_fe_problem.shouldPrintExecution(_tid) || !_nkernel_warehouse->hasActiveObjects()) 109 21221 : return; 110 : 111 68 : const auto & console = _fe_problem.console(); 112 68 : const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag(); 113 68 : console << "[DBG] Computing nodal kernels contribution to residual on nodes on " << execute_on 114 68 : << std::endl; 115 68 : console << "[DBG] Nodes at boundaries between blocks will execute lower block ID first" 116 68 : << std::endl; 117 68 : console << "[DBG] Ordering of the nodal kernels on nodes they are defined on:" << std::endl; 118 68 : console << _nkernel_warehouse->activeObjectsToFormattedString() << std::endl; 119 : }