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 "StoreVariableByElemIDSideUserObject.h" 11 : #include "THMUtils.h" 12 : 13 : registerMooseObject("ThermalHydraulicsApp", StoreVariableByElemIDSideUserObject); 14 : 15 : InputParameters 16 239 : StoreVariableByElemIDSideUserObject::validParams() 17 : { 18 239 : InputParameters params = SideUserObject::validParams(); 19 : 20 478 : params.addRequiredCoupledVar("variable", "Variable to store"); 21 239 : params.addClassDescription( 22 : "Stores variable values at each quadrature point on a side by element ID."); 23 : 24 239 : return params; 25 0 : } 26 : 27 129 : StoreVariableByElemIDSideUserObject::StoreVariableByElemIDSideUserObject( 28 129 : const InputParameters & parameters) 29 : : SideUserObject(parameters), 30 : 31 129 : _u(adCoupledValue("variable")) 32 : { 33 129 : } 34 : 35 : void 36 4547 : StoreVariableByElemIDSideUserObject::initialize() 37 : { 38 : _elem_id_to_var_values.clear(); 39 4547 : } 40 : 41 : void 42 45860 : StoreVariableByElemIDSideUserObject::execute() 43 : { 44 45860 : unsigned int n_qp = _qrule->n_points(); 45 45860 : const auto elem_id = _current_elem->id(); 46 : 47 45860 : _elem_id_to_var_values[elem_id].resize(n_qp); 48 137580 : for (unsigned int qp = 0; qp < n_qp; qp++) 49 91720 : _elem_id_to_var_values[elem_id][qp] = _u[qp]; 50 45860 : } 51 : 52 : void 53 853 : StoreVariableByElemIDSideUserObject::threadJoin(const UserObject & uo) 54 : { 55 : const auto & other_uo = static_cast<const StoreVariableByElemIDSideUserObject &>(uo); 56 : const auto other_map = other_uo._elem_id_to_var_values; 57 4846 : for (auto & it : other_map) 58 3993 : _elem_id_to_var_values[it.first] = it.second; 59 853 : } 60 : 61 : void 62 3694 : StoreVariableByElemIDSideUserObject::finalize() 63 : { 64 3694 : THM::allGatherADVectorMap(comm(), _elem_id_to_var_values); 65 3694 : } 66 : 67 : const std::vector<ADReal> & 68 127203 : StoreVariableByElemIDSideUserObject::getVariableValues(dof_id_type elem_id) const 69 : { 70 : Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx); 71 : 72 : auto it = _elem_id_to_var_values.find(elem_id); 73 127203 : if (it != _elem_id_to_var_values.end()) 74 127203 : return it->second; 75 : else 76 0 : mooseError( 77 : name(), ": The variable values for element ", elem_id, " were requested but not stored."); 78 : }