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 5366 : ComputeLinearFVElementalThread::ComputeLinearFVElementalThread(FEProblemBase & fe_problem, 17 : const unsigned int system_num, 18 : const std::set<TagID> & vector_tags, 19 5366 : const std::set<TagID> & matrix_tags) 20 5366 : : _fe_problem(fe_problem), 21 5366 : _system_number(system_num), 22 5366 : _vector_tags(vector_tags), 23 5366 : _matrix_tags(matrix_tags), 24 5366 : _subdomain(Moose::INVALID_BLOCK_ID), 25 5366 : _old_subdomain(Moose::INVALID_BLOCK_ID), 26 5366 : _system_contrib_objects_ready(false) 27 : { 28 5366 : } 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 5366 : ComputeLinearFVElementalThread::operator()(const ElemInfoRange & range) 45 : { 46 5366 : ParallelUniqueId puid; 47 5366 : _tid = puid.id; 48 : 49 5366 : _old_subdomain = Moose::INVALID_BLOCK_ID; 50 : 51 5366 : setupSystemContributionObjects(); 52 5366 : printGeneralExecutionInformation(); 53 : 54 : // Iterate over all the elements in the range 55 1612070 : for (const auto & elem_info : range) 56 : { 57 1606704 : _subdomain = elem_info->subdomain_id(); 58 1606704 : if (_subdomain != _old_subdomain) 59 : { 60 5950 : fetchBlockSystemContributionObjects(); 61 5950 : printBlockExecutionInformation(); 62 : } 63 : 64 1606704 : const Real elem_volume = elem_info->volume() * elem_info->coordFactor(); 65 : 66 : // Time to add the contributions from the kernels 67 3258382 : for (auto kernel : _fv_kernels) 68 : { 69 1651678 : kernel->setCurrentElemInfo(elem_info); 70 1651678 : kernel->setCurrentElemVolume(elem_volume); 71 1651678 : kernel->addMatrixContribution(); 72 1651678 : kernel->addRightHandSideContribution(); 73 : } 74 : } 75 5366 : } 76 : 77 : void 78 0 : ComputeLinearFVElementalThread::join(const ComputeLinearFVElementalThread & /*y*/) 79 : { 80 0 : } 81 : 82 : void 83 5366 : 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 5366 : std::vector<LinearFVElementalKernel *> kernels_after_vectors; 88 5366 : _fe_problem.theWarehouse() 89 10732 : .query() 90 5366 : .template condition<AttribSysNum>(_system_number) 91 5366 : .template condition<AttribSystem>("LinearFVElementalKernel") 92 5366 : .template condition<AttribThread>(_tid) 93 5366 : .template condition<AttribVectorTags>(_vector_tags) 94 5366 : .queryInto(kernels_after_vectors); 95 : 96 5366 : std::vector<LinearFVElementalKernel *> kernels_after_matrices; 97 5366 : _fe_problem.theWarehouse() 98 10732 : .query() 99 5366 : .template condition<AttribSysNum>(_system_number) 100 5366 : .template condition<AttribSystem>("LinearFVElementalKernel") 101 5366 : .template condition<AttribThread>(_tid) 102 5366 : .template condition<AttribMatrixTags>(_matrix_tags) 103 5366 : .queryInto(kernels_after_matrices); 104 : 105 : // We fetch the union of the available objects 106 5366 : std::vector<LinearFVElementalKernel *> kernels; 107 5366 : 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 11528 : for (auto & kernel : kernels) 111 6162 : kernel->linkTaggedVectorsAndMatrices(_vector_tags, _matrix_tags); 112 : 113 5366 : _system_contrib_objects_ready = true; 114 5366 : } 115 : 116 : void 117 5950 : 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 5950 : std::vector<LinearFVElementalKernel *> kernels_after_vector; 125 5950 : _fe_problem.theWarehouse() 126 11900 : .query() 127 5950 : .template condition<AttribSysNum>(_system_number) 128 5950 : .template condition<AttribSystem>("LinearFVElementalKernel") 129 5950 : .template condition<AttribThread>(_tid) 130 5950 : .template condition<AttribVectorTags>(_vector_tags) 131 5950 : .template condition<AttribSubdomains>(_subdomain) 132 5950 : .queryInto(kernels_after_vector); 133 : 134 5950 : std::vector<LinearFVElementalKernel *> kernels_after_matrix; 135 5950 : _fe_problem.theWarehouse() 136 11900 : .query() 137 5950 : .template condition<AttribSysNum>(_system_number) 138 5950 : .template condition<AttribSystem>("LinearFVElementalKernel") 139 5950 : .template condition<AttribThread>(_tid) 140 5950 : .template condition<AttribMatrixTags>(_matrix_tags) 141 5950 : .template condition<AttribSubdomains>(_subdomain) 142 5950 : .queryInto(kernels_after_matrix); 143 : 144 : // We populate the list of kernels with the union of the two vectors 145 5950 : MooseUtils::getUnion(kernels_after_vector, kernels_after_matrix, _fv_kernels); 146 : 147 5950 : _old_subdomain = _subdomain; 148 5950 : } 149 : 150 : void 151 5366 : ComputeLinearFVElementalThread::printGeneralExecutionInformation() const 152 : { 153 5366 : if (!_fe_problem.shouldPrintExecution(_tid)) 154 5352 : return; 155 14 : auto & console = _fe_problem.console(); 156 14 : auto execute_on = _fe_problem.getCurrentExecuteOnFlag(); 157 14 : console << "[DBG] Beginning linear finite volume elemental objects loop on " << execute_on 158 14 : << std::endl; 159 : 160 14 : 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 14 : } 164 : 165 : void 166 5950 : ComputeLinearFVElementalThread::printBlockExecutionInformation() const 167 : { 168 5950 : if (!_fe_problem.shouldPrintExecution(_tid) || _fv_kernels.empty()) 169 5908 : return; 170 : 171 42 : auto & console = _fe_problem.console(); 172 42 : console << "[DBG] Linear FV elemental kernels on block " 173 42 : << _fe_problem.mesh().getSubdomainName(_subdomain); 174 : 175 : // Print the list of objects 176 42 : std::vector<MooseObject *> kernels_to_print; 177 105 : for (const auto & kernel : _fv_kernels) 178 63 : kernels_to_print.push_back(dynamic_cast<MooseObject *>(kernel)); 179 : 180 84 : console << ConsoleUtils::formatString(ConsoleUtils::mooseObjectVectorToString(kernels_to_print), 181 42 : "[DBG]") 182 42 : << std::endl; 183 42 : }