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 236 : StoreVariableByElemIDSideUserObject::validParams() 17 : { 18 236 : InputParameters params = SideUserObject::validParams(); 19 : 20 472 : params.addRequiredCoupledVar("variable", "Variable to store"); 21 236 : params.addClassDescription( 22 : "Stores variable values at each quadrature point on a side by element ID."); 23 : 24 236 : return params; 25 0 : } 26 : 27 127 : StoreVariableByElemIDSideUserObject::StoreVariableByElemIDSideUserObject( 28 127 : const InputParameters & parameters) 29 : : SideUserObject(parameters), 30 : 31 127 : _u(adCoupledValue("variable")) 32 : { 33 127 : } 34 : 35 : void 36 4545 : StoreVariableByElemIDSideUserObject::initialize() 37 : { 38 : _elem_id_to_var_values.clear(); 39 4545 : } 40 : 41 : void 42 45850 : StoreVariableByElemIDSideUserObject::execute() 43 : { 44 45850 : unsigned int n_qp = _qrule->n_points(); 45 45850 : const auto elem_id = _current_elem->id(); 46 : 47 45850 : _elem_id_to_var_values[elem_id].resize(n_qp); 48 137550 : for (unsigned int qp = 0; qp < n_qp; qp++) 49 91700 : _elem_id_to_var_values[elem_id][qp] = _u[qp]; 50 45850 : } 51 : 52 : void 53 852 : 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 4845 : for (auto & it : other_map) 58 3993 : _elem_id_to_var_values[it.first] = it.second; 59 852 : } 60 : 61 : void 62 3693 : StoreVariableByElemIDSideUserObject::finalize() 63 : { 64 3693 : THM::allGatherADVectorMap(comm(), _elem_id_to_var_values); 65 3693 : } 66 : 67 : const std::vector<ADReal> & 68 127201 : 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 127201 : if (it != _elem_id_to_var_values.end()) 74 127201 : return it->second; 75 : else 76 0 : mooseError( 77 0 : name(), ": The variable values for element ", elem_id, " were requested but not stored."); 78 : }