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 "FlowChannelHeatStructureCouplerUserObject.h" 11 : #include "THMUtils.h" 12 : 13 : InputParameters 14 662 : FlowChannelHeatStructureCouplerUserObject::validParams() 15 : { 16 662 : InputParameters params = ElementUserObject::validParams(); 17 662 : params += ADFunctorInterface::validParams(); 18 1324 : params.addRequiredParam<MeshAlignment *>("_mesh_alignment", "Mesh alignment object"); 19 662 : params.addClassDescription( 20 : "Base class for caching quantities computed between flow channels and heat structures."); 21 662 : return params; 22 0 : } 23 : 24 374 : FlowChannelHeatStructureCouplerUserObject::FlowChannelHeatStructureCouplerUserObject( 25 374 : const InputParameters & parameters) 26 : : ElementUserObject(parameters), 27 : ADFunctorInterface(this), 28 374 : _fc_elem_id(0), 29 374 : _hs_elem_id(0), 30 374 : _fc_qp(0), 31 374 : _hs_qp(0), 32 748 : _mesh_alignment(*getParam<MeshAlignment *>("_mesh_alignment")) 33 : { 34 374 : _mesh_alignment.buildCoupledElemQpIndexMap(_assembly); 35 374 : } 36 : 37 : void 38 23764 : FlowChannelHeatStructureCouplerUserObject::initialize() 39 : { 40 23764 : const auto map_ptrs = getCachedQuantityMaps(); 41 71292 : for (const auto map_ptr : map_ptrs) 42 : map_ptr->clear(); 43 23764 : } 44 : 45 : void 46 161995 : FlowChannelHeatStructureCouplerUserObject::execute() 47 : { 48 161995 : unsigned int n_qpts = _qrule->n_points(); 49 : 50 161995 : _fc_elem_id = _current_elem->id(); 51 161995 : _hs_elem_id = _mesh_alignment.getCoupledElemID(_fc_elem_id); 52 : 53 161995 : const auto map_ptrs = getCachedQuantityMaps(); 54 485985 : for (const auto map_ptr : map_ptrs) 55 : { 56 323990 : (*map_ptr)[_fc_elem_id].resize(n_qpts); 57 323990 : (*map_ptr)[_hs_elem_id].resize(n_qpts); 58 : } 59 : 60 485985 : for (_fc_qp = 0; _fc_qp < n_qpts; _fc_qp++) 61 : { 62 323990 : _hs_qp = _mesh_alignment.getCoupledElemQpIndex(_fc_elem_id, _fc_qp); 63 323990 : computeQpCachedQuantities(); 64 : } 65 161995 : } 66 : 67 : void 68 6030 : FlowChannelHeatStructureCouplerUserObject::threadJoin(const UserObject & uo) 69 : { 70 : const auto & fc_hs_uo = static_cast<const FlowChannelHeatStructureCouplerUserObject &>(uo); 71 : 72 6030 : const auto map_ptrs = getCachedQuantityMaps(); 73 6030 : const auto other_map_ptrs = fc_hs_uo.getCachedQuantityMaps(); 74 : 75 18090 : for (unsigned int i = 0; i < map_ptrs.size(); ++i) 76 59600 : for (auto & it : *other_map_ptrs[i]) 77 47540 : (*map_ptrs[i])[it.first] = it.second; 78 6030 : } 79 : 80 : void 81 17734 : FlowChannelHeatStructureCouplerUserObject::finalize() 82 : { 83 17734 : const auto map_ptrs = getCachedQuantityMaps(); 84 53202 : for (const auto map_ptr : map_ptrs) 85 35468 : THM::allGatherADVectorMap(comm(), *map_ptr); 86 17734 : } 87 : 88 : const std::vector<ADReal> & 89 3185800 : FlowChannelHeatStructureCouplerUserObject::getCachedQuantity( 90 : dof_id_type elem_id, 91 : const std::map<dof_id_type, std::vector<ADReal>> & elem_id_to_values, 92 : const std::string & description) const 93 : { 94 : Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx); 95 : 96 : auto it = elem_id_to_values.find(elem_id); 97 3185800 : if (it != elem_id_to_values.end()) 98 3185800 : return it->second; 99 : else 100 0 : mooseError(name(), 101 : ": The ", 102 : description, 103 : " for element ", 104 : elem_id, 105 : " was requested but not computed."); 106 : }