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 "ComputeLinearFVElementalThread.h" 11 : #include "LinearSystem.h" 12 : #include "LinearFVKernel.h" 13 : #include "LinearFVElementalKernel.h" 14 : #include "FEProblemBase.h" 15 : 16 26160 : ComputeLinearFVElementalThread::ComputeLinearFVElementalThread(FEProblemBase & fe_problem, 17 : const unsigned int system_num, 18 : const std::set<TagID> & vector_tags, 19 26160 : const std::set<TagID> & matrix_tags) 20 26160 : : _fe_problem(fe_problem), 21 26160 : _system_number(system_num), 22 26160 : _vector_tags(vector_tags), 23 26160 : _matrix_tags(matrix_tags), 24 26160 : _subdomain(Moose::INVALID_BLOCK_ID), 25 26160 : _old_subdomain(Moose::INVALID_BLOCK_ID), 26 26160 : _system_contrib_objects_ready(false) 27 : { 28 26160 : } 29 : 30 : // Splitting Constructor 31 0 : ComputeLinearFVElementalThread::ComputeLinearFVElementalThread(ComputeLinearFVElementalThread & x, 32 0 : Threads::split /*split*/) 33 0 : : _fe_problem(x._fe_problem), 34 0 : _system_number(x._system_number), 35 0 : _vector_tags(x._vector_tags), 36 0 : _matrix_tags(x._matrix_tags), 37 0 : _subdomain(x._subdomain), 38 0 : _old_subdomain(x._old_subdomain), 39 0 : _system_contrib_objects_ready(x._system_contrib_objects_ready) 40 : { 41 0 : } 42 : 43 : void 44 26160 : ComputeLinearFVElementalThread::operator()(const ElemInfoRange & range) 45 : { 46 26160 : ParallelUniqueId puid; 47 26160 : _tid = puid.id; 48 : 49 26160 : _old_subdomain = Moose::INVALID_BLOCK_ID; 50 : 51 26160 : setupSystemContributionObjects(); 52 26160 : printGeneralExecutionInformation(); 53 : 54 : // Iterate over all the elements in the range 55 34622018 : for (const auto & elem_info : range) 56 : { 57 34595858 : _subdomain = elem_info->subdomain_id(); 58 34595858 : if (_subdomain != _old_subdomain) 59 : { 60 26358 : fetchBlockSystemContributionObjects(); 61 26358 : printBlockExecutionInformation(); 62 : } 63 : 64 34595858 : const Real elem_volume = elem_info->volume() * elem_info->coordFactor(); 65 : 66 : // Time to add the contributions from the kernels 67 35737266 : for (auto kernel : _fv_kernels) 68 : { 69 1141408 : kernel->setCurrentElemInfo(elem_info); 70 1141408 : kernel->setCurrentElemVolume(elem_volume); 71 1141408 : kernel->addMatrixContribution(); 72 1141408 : kernel->addRightHandSideContribution(); 73 : } 74 : } 75 26160 : } 76 : 77 : void 78 0 : ComputeLinearFVElementalThread::join(const ComputeLinearFVElementalThread & /*y*/) 79 : { 80 0 : } 81 : 82 : void 83 26160 : ComputeLinearFVElementalThread::setupSystemContributionObjects() 84 : { 85 : // The reason why we need to grab vectors and matrices separately is that 86 : // we want to grab a union instead of an intersection. 87 26160 : std::vector<LinearFVElementalKernel *> kernels_after_vectors; 88 26160 : _fe_problem.theWarehouse() 89 52320 : .query() 90 26160 : .template condition<AttribSysNum>(_system_number) 91 26160 : .template condition<AttribSystem>("LinearFVElementalKernel") 92 26160 : .template condition<AttribThread>(_tid) 93 26160 : .template condition<AttribVectorTags>(_vector_tags) 94 26160 : .queryInto(kernels_after_vectors); 95 : 96 26160 : std::vector<LinearFVElementalKernel *> kernels_after_matrices; 97 26160 : _fe_problem.theWarehouse() 98 52320 : .query() 99 26160 : .template condition<AttribSysNum>(_system_number) 100 26160 : .template condition<AttribSystem>("LinearFVElementalKernel") 101 26160 : .template condition<AttribThread>(_tid) 102 26160 : .template condition<AttribMatrixTags>(_matrix_tags) 103 26160 : .queryInto(kernels_after_matrices); 104 : 105 : // We fetch the union of the available objects 106 26160 : std::vector<LinearFVElementalKernel *> kernels; 107 26160 : MooseUtils::getUnion(kernels_after_vectors, kernels_after_matrices, kernels); 108 : 109 : // As a last step, we make sure the kernels know which vectors/matrices they need to contribute to 110 36623 : for (auto & kernel : kernels) 111 10463 : kernel->linkTaggedVectorsAndMatrices(_vector_tags, _matrix_tags); 112 : 113 26160 : _system_contrib_objects_ready = true; 114 26160 : } 115 : 116 : void 117 26358 : ComputeLinearFVElementalThread::fetchBlockSystemContributionObjects() 118 : { 119 : mooseAssert(_system_contrib_objects_ready, 120 : "The system contribution objects need to be set up before we fetch the " 121 : "block-restricted objects!"); 122 : 123 : // Here we just filter based on subdomain ID on top of everything else 124 26358 : std::vector<LinearFVElementalKernel *> kernels_after_vector; 125 26358 : _fe_problem.theWarehouse() 126 52716 : .query() 127 26358 : .template condition<AttribSysNum>(_system_number) 128 26358 : .template condition<AttribSystem>("LinearFVElementalKernel") 129 26358 : .template condition<AttribThread>(_tid) 130 26358 : .template condition<AttribVectorTags>(_vector_tags) 131 26358 : .template condition<AttribSubdomains>(_subdomain) 132 26358 : .queryInto(kernels_after_vector); 133 : 134 26358 : std::vector<LinearFVElementalKernel *> kernels_after_matrix; 135 26358 : _fe_problem.theWarehouse() 136 52716 : .query() 137 26358 : .template condition<AttribSysNum>(_system_number) 138 26358 : .template condition<AttribSystem>("LinearFVElementalKernel") 139 26358 : .template condition<AttribThread>(_tid) 140 26358 : .template condition<AttribMatrixTags>(_matrix_tags) 141 26358 : .template condition<AttribSubdomains>(_subdomain) 142 26358 : .queryInto(kernels_after_matrix); 143 : 144 : // We populate the list of kernels with the union of the two vectors 145 26358 : MooseUtils::getUnion(kernels_after_vector, kernels_after_matrix, _fv_kernels); 146 : 147 26358 : _old_subdomain = _subdomain; 148 26358 : } 149 : 150 : void 151 26160 : ComputeLinearFVElementalThread::printGeneralExecutionInformation() const 152 : { 153 26160 : if (!_fe_problem.shouldPrintExecution(_tid)) 154 26154 : return; 155 6 : auto & console = _fe_problem.console(); 156 6 : auto execute_on = _fe_problem.getCurrentExecuteOnFlag(); 157 6 : console << "[DBG] Beginning linear finite volume elemental objects loop on " << execute_on 158 6 : << std::endl; 159 : 160 6 : mooseDoOnce(console << "[DBG] Loop on elements (ElemInfo), objects ordered on each face: " 161 : << std::endl; 162 : console << "[DBG] - linear finite volume kernels" << std::endl;); 163 6 : } 164 : 165 : void 166 26358 : ComputeLinearFVElementalThread::printBlockExecutionInformation() const 167 : { 168 26358 : if (!_fe_problem.shouldPrintExecution(_tid) || _fv_kernels.empty()) 169 26346 : return; 170 : 171 12 : auto & console = _fe_problem.console(); 172 12 : console << "[DBG] Linear FV elemental kernels on block " 173 12 : << _fe_problem.mesh().getSubdomainName(_subdomain); 174 : 175 : // Print the list of objects 176 12 : std::vector<MooseObject *> kernels_to_print; 177 30 : for (const auto & kernel : _fv_kernels) 178 18 : kernels_to_print.push_back(dynamic_cast<MooseObject *>(kernel)); 179 : 180 48 : console << ConsoleUtils::formatString(ConsoleUtils::mooseObjectVectorToString(kernels_to_print), 181 12 : "[DBG]") 182 12 : << std::endl; 183 12 : }