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 25500 : ComputeLinearFVElementalThread::ComputeLinearFVElementalThread(FEProblemBase & fe_problem, 17 : const unsigned int system_num, 18 : const std::set<TagID> & vector_tags, 19 25500 : const std::set<TagID> & matrix_tags) 20 25500 : : _fe_problem(fe_problem), 21 25500 : _system_number(system_num), 22 25500 : _vector_tags(vector_tags), 23 25500 : _matrix_tags(matrix_tags), 24 25500 : _subdomain(Moose::INVALID_BLOCK_ID), 25 25500 : _old_subdomain(Moose::INVALID_BLOCK_ID), 26 25500 : _system_contrib_objects_ready(false) 27 : { 28 25500 : } 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 25500 : ComputeLinearFVElementalThread::operator()(const ElemInfoRange & range) 45 : { 46 25500 : ParallelUniqueId puid; 47 25500 : _tid = puid.id; 48 : 49 25500 : _old_subdomain = Moose::INVALID_BLOCK_ID; 50 : 51 25500 : setupSystemContributionObjects(); 52 25500 : printGeneralExecutionInformation(); 53 : 54 : // Iterate over all the elements in the range 55 34221298 : for (const auto & elem_info : range) 56 : { 57 34195798 : _subdomain = elem_info->subdomain_id(); 58 34195798 : if (_subdomain != _old_subdomain) 59 : { 60 25604 : fetchBlockSystemContributionObjects(); 61 25604 : printBlockExecutionInformation(); 62 : } 63 : 64 34195798 : const Real elem_volume = elem_info->volume() * elem_info->coordFactor(); 65 : 66 : // Time to add the contributions from the kernels 67 35223086 : for (auto kernel : _fv_kernels) 68 : { 69 1027288 : kernel->setCurrentElemInfo(elem_info); 70 1027288 : kernel->setCurrentElemVolume(elem_volume); 71 1027288 : kernel->addMatrixContribution(); 72 1027288 : kernel->addRightHandSideContribution(); 73 : } 74 : } 75 25500 : } 76 : 77 : void 78 0 : ComputeLinearFVElementalThread::join(const ComputeLinearFVElementalThread & /*y*/) 79 : { 80 0 : } 81 : 82 : void 83 25500 : 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 25500 : std::vector<LinearFVElementalKernel *> kernels_after_vectors; 88 25500 : _fe_problem.theWarehouse() 89 51000 : .query() 90 25500 : .template condition<AttribSysNum>(_system_number) 91 25500 : .template condition<AttribSystem>("LinearFVElementalKernel") 92 25500 : .template condition<AttribThread>(_tid) 93 25500 : .template condition<AttribVectorTags>(_vector_tags) 94 25500 : .queryInto(kernels_after_vectors); 95 : 96 25500 : std::vector<LinearFVElementalKernel *> kernels_after_matrices; 97 25500 : _fe_problem.theWarehouse() 98 51000 : .query() 99 25500 : .template condition<AttribSysNum>(_system_number) 100 25500 : .template condition<AttribSystem>("LinearFVElementalKernel") 101 25500 : .template condition<AttribThread>(_tid) 102 25500 : .template condition<AttribMatrixTags>(_matrix_tags) 103 25500 : .queryInto(kernels_after_matrices); 104 : 105 : // We fetch the union of the available objects 106 25500 : std::vector<LinearFVElementalKernel *> kernels; 107 25500 : 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 35320 : for (auto & kernel : kernels) 111 9820 : kernel->linkTaggedVectorsAndMatrices(_vector_tags, _matrix_tags); 112 : 113 25500 : _system_contrib_objects_ready = true; 114 25500 : } 115 : 116 : void 117 25604 : 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 25604 : std::vector<LinearFVElementalKernel *> kernels_after_vector; 125 25604 : _fe_problem.theWarehouse() 126 51208 : .query() 127 25604 : .template condition<AttribSysNum>(_system_number) 128 25604 : .template condition<AttribSystem>("LinearFVElementalKernel") 129 25604 : .template condition<AttribThread>(_tid) 130 25604 : .template condition<AttribVectorTags>(_vector_tags) 131 25604 : .template condition<AttribSubdomains>(_subdomain) 132 25604 : .queryInto(kernels_after_vector); 133 : 134 25604 : std::vector<LinearFVElementalKernel *> kernels_after_matrix; 135 25604 : _fe_problem.theWarehouse() 136 51208 : .query() 137 25604 : .template condition<AttribSysNum>(_system_number) 138 25604 : .template condition<AttribSystem>("LinearFVElementalKernel") 139 25604 : .template condition<AttribThread>(_tid) 140 25604 : .template condition<AttribMatrixTags>(_matrix_tags) 141 25604 : .template condition<AttribSubdomains>(_subdomain) 142 25604 : .queryInto(kernels_after_matrix); 143 : 144 : // We populate the list of kernels with the union of the two vectors 145 25604 : MooseUtils::getUnion(kernels_after_vector, kernels_after_matrix, _fv_kernels); 146 : 147 25604 : _old_subdomain = _subdomain; 148 25604 : } 149 : 150 : void 151 25500 : ComputeLinearFVElementalThread::printGeneralExecutionInformation() const 152 : { 153 25500 : if (!_fe_problem.shouldPrintExecution(_tid)) 154 25494 : 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 25604 : ComputeLinearFVElementalThread::printBlockExecutionInformation() const 167 : { 168 25604 : if (!_fe_problem.shouldPrintExecution(_tid) || _fv_kernels.empty()) 169 25592 : 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 : }