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 "HeatFluxFromHeatStructureBaseUserObject.h" 11 : 12 : InputParameters 13 0 : HeatFluxFromHeatStructureBaseUserObject::validParams() 14 : { 15 0 : InputParameters params = ElementUserObject::validParams(); 16 0 : params.addRequiredParam<MeshAlignment *>("_mesh_alignment", "Mesh alignment object"); 17 0 : params.addRequiredCoupledVar("P_hf", "Heat flux perimeter"); 18 0 : params.addClassDescription( 19 : "Base class for caching heat flux between flow channels and heat structures."); 20 0 : return params; 21 0 : } 22 : 23 0 : HeatFluxFromHeatStructureBaseUserObject::HeatFluxFromHeatStructureBaseUserObject( 24 0 : const InputParameters & parameters) 25 : : ElementUserObject(parameters), 26 0 : _mesh_alignment(*getParam<MeshAlignment *>("_mesh_alignment")), 27 0 : _P_hf(coupledValue("P_hf")) 28 : { 29 0 : _mesh_alignment.buildCoupledElemQpIndexMap(_assembly); 30 0 : } 31 : 32 : void 33 0 : HeatFluxFromHeatStructureBaseUserObject::initialize() 34 : { 35 0 : } 36 : 37 : void 38 0 : HeatFluxFromHeatStructureBaseUserObject::execute() 39 : { 40 0 : unsigned int n_qpts = _qrule->n_points(); 41 0 : const dof_id_type & nearest_elem_id = _mesh_alignment.getCoupledElemID(_current_elem->id()); 42 : 43 0 : _heated_perimeter[_current_elem->id()].resize(n_qpts); 44 0 : _heated_perimeter[nearest_elem_id].resize(n_qpts); 45 : 46 0 : _heat_flux[_current_elem->id()].resize(n_qpts); 47 0 : _heat_flux[nearest_elem_id].resize(n_qpts); 48 0 : for (_qp = 0; _qp < n_qpts; _qp++) 49 : { 50 0 : unsigned int nearest_qp = _mesh_alignment.getCoupledElemQpIndex(_current_elem->id(), _qp); 51 0 : Real q_wall = computeQpHeatFlux(); 52 : 53 0 : _heat_flux[_current_elem->id()][_qp] = q_wall; 54 0 : _heat_flux[nearest_elem_id][nearest_qp] = q_wall; 55 : 56 0 : _heated_perimeter[_current_elem->id()][_qp] = _P_hf[_qp]; 57 0 : _heated_perimeter[nearest_elem_id][nearest_qp] = _P_hf[_qp]; 58 : } 59 : 60 0 : if (_fe_problem.currentlyComputingJacobian()) 61 : { 62 0 : _heat_flux_jacobian[_current_elem->id()].resize(n_qpts); 63 0 : _heat_flux_jacobian[nearest_elem_id].resize(n_qpts); 64 0 : for (_qp = 0; _qp < n_qpts; _qp++) 65 : { 66 0 : unsigned int nearest_qp = _mesh_alignment.getCoupledElemQpIndex(_current_elem->id(), _qp); 67 0 : DenseVector<Real> jac = computeQpHeatFluxJacobian(); 68 : 69 0 : _heat_flux_jacobian[_current_elem->id()][_qp] = jac; 70 0 : _heat_flux_jacobian[nearest_elem_id][nearest_qp] = jac; 71 : } 72 : } 73 0 : } 74 : 75 : void 76 0 : HeatFluxFromHeatStructureBaseUserObject::finalize() 77 : { 78 0 : } 79 : 80 : void 81 0 : HeatFluxFromHeatStructureBaseUserObject::threadJoin(const UserObject & y) 82 : { 83 : const auto & uo = static_cast<const HeatFluxFromHeatStructureBaseUserObject &>(y); 84 0 : for (auto & it : uo._heated_perimeter) 85 0 : _heated_perimeter[it.first] = it.second; 86 0 : for (auto & it : uo._heat_flux) 87 0 : _heat_flux[it.first] = it.second; 88 0 : for (auto & it : uo._heat_flux_jacobian) 89 0 : _heat_flux_jacobian[it.first] = it.second; 90 0 : } 91 : 92 : const std::vector<Real> & 93 0 : HeatFluxFromHeatStructureBaseUserObject::getHeatedPerimeter(dof_id_type element_id) const 94 : { 95 : Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx); 96 : auto it = _heated_perimeter.find(element_id); 97 0 : if (it != _heated_perimeter.end()) 98 0 : return it->second; 99 : else 100 0 : mooseError( 101 0 : name(), ": Requested heated perimeter for element ", element_id, " was not computed."); 102 : } 103 : 104 : const std::vector<Real> & 105 0 : HeatFluxFromHeatStructureBaseUserObject::getHeatFlux(dof_id_type element_id) const 106 : { 107 : Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx); 108 : auto it = _heat_flux.find(element_id); 109 0 : if (it != _heat_flux.end()) 110 0 : return it->second; 111 : else 112 0 : mooseError(name(), ": Requested heat flux for element ", element_id, " was not computed."); 113 : } 114 : 115 : const std::vector<DenseVector<Real>> & 116 0 : HeatFluxFromHeatStructureBaseUserObject::getHeatFluxJacobian(dof_id_type element_id) const 117 : { 118 : Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx); 119 : auto it = _heat_flux_jacobian.find(element_id); 120 0 : if (it != _heat_flux_jacobian.end()) 121 0 : return it->second; 122 : else 123 0 : mooseError( 124 0 : name(), ": Requested heat flux jacobian for element ", element_id, " was not computed."); 125 : }