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 15596 : ComputeNodalKernelsThread::ComputeNodalKernelsThread( 22 : FEProblemBase & fe_problem, 23 : MooseObjectTagWarehouse<NodalKernelBase> & nodal_kernels, 24 15596 : const std::set<TagID> & tags) 25 : : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(fe_problem), 26 15596 : _fe_problem(fe_problem), 27 31192 : _aux_sys(fe_problem.getAuxiliarySystem()), 28 15596 : _tags(tags), 29 15596 : _nodal_kernels(nodal_kernels), 30 15596 : _num_cached(0) 31 : { 32 15596 : } 33 : 34 : // Splitting Constructor 35 7334 : ComputeNodalKernelsThread::ComputeNodalKernelsThread(ComputeNodalKernelsThread & x, 36 7334 : Threads::split split) 37 : : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(x, split), 38 7334 : _fe_problem(x._fe_problem), 39 7334 : _aux_sys(x._aux_sys), 40 7334 : _tags(x._tags), 41 7334 : _nodal_kernels(x._nodal_kernels), 42 7334 : _num_cached(0) 43 : { 44 7334 : } 45 : 46 : void 47 22930 : ComputeNodalKernelsThread::pre() 48 : { 49 22930 : _num_cached = 0; 50 : 51 22930 : if (!_tags.size() || _tags.size() == _fe_problem.numVectorTags(Moose::VECTOR_TAG_RESIDUAL)) 52 22917 : _nkernel_warehouse = &_nodal_kernels; 53 13 : else if (_tags.size() == 1) 54 0 : _nkernel_warehouse = &(_nodal_kernels.getVectorTagObjectWarehouse(*(_tags.begin()), _tid)); 55 : else 56 13 : _nkernel_warehouse = &(_nodal_kernels.getVectorTagsObjectWarehouse(_tags, _tid)); 57 22930 : } 58 : 59 : void 60 1251280 : ComputeNodalKernelsThread::onNode(ConstNodeRange::const_iterator & node_it) 61 : { 62 1251280 : const Node * node = *node_it; 63 : 64 1251280 : std::set<const NodalKernelBase *> nks_executed; 65 : 66 : // prepare variables 67 1677499 : for (auto * var : _aux_sys._nodal_vars[_tid]) 68 426219 : var->prepareAux(); 69 : 70 1251280 : _fe_problem.reinitNode(node, _tid); 71 : 72 1251280 : const auto & block_ids = _aux_sys.mesh().getNodeBlockIds(*node); 73 2512553 : for (const auto block : block_ids) 74 1261273 : if (_nkernel_warehouse->hasActiveBlockObjects(block, _tid)) 75 : { 76 1204623 : std::set<TagID> needed_fe_var_vector_tags; 77 1204623 : _nkernel_warehouse->updateBlockFEVariableCoupledVectorTagDependency( 78 : block, needed_fe_var_vector_tags, _tid); 79 1204623 : _fe_problem.setActiveFEVariableCoupleableVectorTags(needed_fe_var_vector_tags, _tid); 80 : 81 1204623 : const auto & objects = _nkernel_warehouse->getActiveBlockObjects(block, _tid); 82 3666022 : for (const auto & nodal_kernel : objects) 83 2461399 : if (nks_executed.emplace(nodal_kernel.get()).second) 84 : { 85 2461324 : nodal_kernel->setSubdomains(block_ids); 86 2461324 : nodal_kernel->computeResidual(); 87 : } 88 1204623 : } 89 : 90 1251280 : _num_cached++; 91 : 92 1251280 : if (_num_cached == 20) // Cache 20 nodes worth before adding into the residual 93 : { 94 55600 : _num_cached = 0; 95 55600 : Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx); 96 55600 : _fe_problem.addCachedResidual(_tid); 97 55600 : } 98 1251280 : } 99 : 100 : void 101 7334 : ComputeNodalKernelsThread::join(const ComputeNodalKernelsThread & /*y*/) 102 : { 103 7334 : } 104 : 105 : void 106 22930 : ComputeNodalKernelsThread::printGeneralExecutionInformation() const 107 : { 108 22930 : if (!_fe_problem.shouldPrintExecution(_tid) || !_nkernel_warehouse->hasActiveObjects()) 109 22862 : 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 : }