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 : #pragma once 11 : 12 : #include "ComputeFVFluxThread.h" 13 : #include "INSFVMomentumResidualObject.h" 14 : #include "INSFVAttributes.h" 15 : #include "TheWarehouse.h" 16 : 17 : /** 18 : * A class that gathers 'a' coefficient data from flux kernels, boundary conditions, and interface 19 : * kernels contributing to the Navier-Stokes momentum residuals. We loop over each active, local 20 : * face and call the gatherRCData method on each kernel with the current face as an argument 21 : */ 22 : template <typename RangeType> 23 : class GatherRCDataFaceThread : public ThreadedFaceLoop<RangeType> 24 : { 25 : public: 26 : using Parent = ThreadedFaceLoop<RangeType>; 27 : using Parent::join; 28 : 29 : GatherRCDataFaceThread(FEProblemBase & fe_problem, 30 : const unsigned int nl_sys_number, 31 : const std::vector<unsigned int> & vars, 32 : bool on_displaced); 33 : 34 : // Splitting Constructor 35 : GatherRCDataFaceThread(GatherRCDataFaceThread & x, Threads::split split); 36 : 37 : void onFace(const FaceInfo & fi) override final; 38 : void onBoundary(const FaceInfo & fi, BoundaryID boundary) override final; 39 : void subdomainChanged() override final; 40 : void neighborSubdomainChanged() override final; 41 : 42 : private: 43 : /** 44 : * Called at the end of either \p subdomainChanged or \p neighborSubdomainChanged, this method 45 : * computes the final \p _fv_flux_kernels set 46 : */ 47 : void finalizeContainers(); 48 : 49 : /** 50 : * This determines all the momentum residual objects for all the variables 51 : * @param ros The output of this method; all the momentum residual objects for all the variables 52 : * @param queries Candidate MooseObjects for momentum residual object consideration that have been 53 : * pre-filtered based on attributes such as thread ID, boundary ID, subdomain ID, etc. 54 : */ 55 : template <typename... Attribs> 56 : void getVarROs(std::vector<INSFVMomentumResidualObject *> & ros, 57 : TheWarehouse::QueryCache<Attribs...> & queries); 58 : 59 : /// The velocity variable numbers 60 : const std::vector<unsigned int> & _vars; 61 : 62 : /// The collection of flux kernels that contribute to the momentum equation residuals 63 : std::set<INSFVMomentumResidualObject *> _fv_flux_kernels; 64 : 65 : /// The subset of flux kernels that contribute to the momentum equation residual from the 66 : /// element side of the face 67 : std::set<INSFVMomentumResidualObject *> _elem_sub_fv_flux_kernels; 68 : 69 : /// The subset of flux kernels that contribute to the momentum equation residual from the 70 : /// neighbor side of the face 71 : std::set<INSFVMomentumResidualObject *> _neigh_sub_fv_flux_kernels; 72 : }; 73 : 74 : template <typename RangeType> 75 92458 : GatherRCDataFaceThread<RangeType>::GatherRCDataFaceThread(FEProblemBase & fe_problem, 76 : const unsigned int nl_sys_number, 77 : const std::vector<unsigned int> & vars, 78 : bool on_displaced) 79 184916 : : ThreadedFaceLoop<RangeType>(fe_problem, nl_sys_number, {}, on_displaced), _vars(vars) 80 : { 81 92458 : } 82 : 83 : template <typename RangeType> 84 16329 : GatherRCDataFaceThread<RangeType>::GatherRCDataFaceThread(GatherRCDataFaceThread & x, 85 : Threads::split split) 86 16329 : : ThreadedFaceLoop<RangeType>(x, split), _vars(x._vars) 87 : { 88 16329 : } 89 : 90 : template <typename RangeType> 91 : template <typename... Attribs> 92 : void 93 15435005 : GatherRCDataFaceThread<RangeType>::getVarROs(std::vector<INSFVMomentumResidualObject *> & ros, 94 : TheWarehouse::QueryCache<Attribs...> & queries) 95 : { 96 77494559 : for (const auto var_num : _vars) 97 : { 98 : // We don't want to do cascading var num attributes or else the second time around we won't get 99 : // any results out of the query (e.g. an object cannot have a variable that simultaneously has 100 : // both var number 0 and 1) 101 31029777 : auto copied_queries = queries; 102 : std::vector<INSFVMomentumResidualObject *> var_ros; 103 62059554 : copied_queries.template condition<AttribVar>(static_cast<int>(var_num)).queryInto(var_ros); 104 50261909 : for (auto * const var_ro : var_ros) 105 19232132 : ros.push_back(var_ro); 106 : } 107 15435005 : } 108 : 109 : template <typename RangeType> 110 : void 111 48420634 : GatherRCDataFaceThread<RangeType>::onFace(const FaceInfo & fi) 112 : { 113 258240552 : for (auto * const k : _fv_flux_kernels) 114 209819918 : k->gatherRCData(fi); 115 48420634 : } 116 : 117 : template <typename RangeType> 118 : void 119 3912812 : GatherRCDataFaceThread<RangeType>::onBoundary(const FaceInfo & fi, BoundaryID bnd_id) 120 : { 121 : { 122 : std::vector<INSFVMomentumResidualObject *> bcs; 123 : // cannot bind to lvalue reference otherwise the temporary is destroyed and we are left with a 124 : // dangling reference 125 7825624 : auto queries = this->_fe_problem.theWarehouse() 126 : .query() 127 7825624 : .template condition<AttribSystem>("FVFluxBC") 128 3912812 : .template condition<AttribSysNum>(this->_nl_system_num) 129 3912812 : .template condition<AttribDisplaced>(this->_on_displaced) 130 3912812 : .template condition<AttribThread>(this->_tid) 131 3912812 : .template condition<AttribBoundaries>(bnd_id); 132 3912812 : getVarROs(bcs, queries); 133 : 134 5579248 : for (auto * const bc : bcs) 135 1666436 : bc->gatherRCData(fi); 136 3912812 : } 137 : 138 : { 139 : std::vector<INSFVMomentumResidualObject *> iks; 140 : // cannot bind to lvalue reference otherwise the temporary is destroyed and we are left with a 141 : // dangling reference 142 7825624 : auto queries = this->_fe_problem.theWarehouse() 143 : .query() 144 7825624 : .template condition<AttribSystem>("FVInterfaceKernel") 145 3912812 : .template condition<AttribSysNum>(this->_nl_system_num) 146 3912812 : .template condition<AttribDisplaced>(this->_on_displaced) 147 3912812 : .template condition<AttribThread>(this->_tid) 148 3912812 : .template condition<AttribBoundaries>(bnd_id); 149 3912812 : getVarROs(iks, queries); 150 : 151 3912812 : for (auto * const ik : iks) 152 0 : ik->gatherRCData(fi); 153 3912812 : } 154 3912812 : } 155 : 156 : template <typename RangeType> 157 : void 158 381715 : GatherRCDataFaceThread<RangeType>::subdomainChanged() 159 : { 160 381715 : ThreadedFaceLoop<RangeType>::subdomainChanged(); 161 : 162 : // Clear kernels 163 : _fv_flux_kernels.clear(); 164 : _elem_sub_fv_flux_kernels.clear(); 165 : 166 : std::vector<INSFVMomentumResidualObject *> kernels; 167 : // cannot bind to lvalue reference otherwise the temporary is destroyed and we are left with a 168 : // dangling reference 169 763430 : auto queries = this->_fe_problem.theWarehouse() 170 : .query() 171 763430 : .template condition<AttribSysNum>(this->_nl_system_num) 172 381715 : .template condition<AttribSystem>("FVFluxKernel") 173 381715 : .template condition<AttribDisplaced>(this->_on_displaced) 174 381715 : .template condition<AttribSubdomains>(this->_subdomain) 175 381715 : .template condition<AttribThread>(this->_tid); 176 381715 : getVarROs(kernels, queries); 177 : 178 : _elem_sub_fv_flux_kernels = 179 381715 : std::set<INSFVMomentumResidualObject *>(kernels.begin(), kernels.end()); 180 : 181 381715 : finalizeContainers(); 182 381715 : } 183 : 184 : template <typename RangeType> 185 : void 186 7227666 : GatherRCDataFaceThread<RangeType>::neighborSubdomainChanged() 187 : { 188 7227666 : ThreadedFaceLoop<RangeType>::neighborSubdomainChanged(); 189 : 190 : // Clear kernels 191 : _fv_flux_kernels.clear(); 192 : _neigh_sub_fv_flux_kernels.clear(); 193 : 194 : std::vector<INSFVMomentumResidualObject *> kernels; 195 : // cannot bind to lvalue reference otherwise the temporary is destroyed and we are left with a 196 : // dangling reference 197 14455332 : auto queries = this->_fe_problem.theWarehouse() 198 : .query() 199 14455332 : .template condition<AttribSysNum>(this->_nl_system_num) 200 7227666 : .template condition<AttribSystem>("FVFluxKernel") 201 7227666 : .template condition<AttribDisplaced>(this->_on_displaced) 202 7227666 : .template condition<AttribSubdomains>(this->_neighbor_subdomain) 203 7227666 : .template condition<AttribThread>(this->_tid); 204 7227666 : getVarROs(kernels, queries); 205 : 206 : _neigh_sub_fv_flux_kernels = 207 7227666 : std::set<INSFVMomentumResidualObject *>(kernels.begin(), kernels.end()); 208 : 209 7227666 : finalizeContainers(); 210 7227666 : } 211 : 212 : template <typename RangeType> 213 : void 214 7609381 : GatherRCDataFaceThread<RangeType>::finalizeContainers() 215 : { 216 : const bool same_kernels = _elem_sub_fv_flux_kernels == _neigh_sub_fv_flux_kernels; 217 7609381 : if (same_kernels) 218 : _fv_flux_kernels = _elem_sub_fv_flux_kernels; 219 : else 220 3620216 : std::set_union(_elem_sub_fv_flux_kernels.begin(), 221 : _elem_sub_fv_flux_kernels.end(), 222 : _neigh_sub_fv_flux_kernels.begin(), 223 : _neigh_sub_fv_flux_kernels.end(), 224 3620216 : std::inserter(_fv_flux_kernels, _fv_flux_kernels.begin())); 225 7609381 : }