https://mooseframework.inl.gov
StoreVariableByElemIDSideUserObject.C
Go to the documentation of this file.
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 
11 #include "THMUtils.h"
12 
14 
17 {
19 
20  params.addRequiredCoupledVar("variable", "Variable to store");
21  params.addClassDescription(
22  "Stores variable values at each quadrature point on a side by element ID.");
23 
24  return params;
25 }
26 
28  const InputParameters & parameters)
29  : SideUserObject(parameters),
30 
31  _u(adCoupledValue("variable"))
32 {
33 }
34 
35 void
37 {
38  _elem_id_to_var_values.clear();
39 }
40 
41 void
43 {
44  unsigned int n_qp = _qrule->n_points();
45  const auto elem_id = _current_elem->id();
46 
47  _elem_id_to_var_values[elem_id].resize(n_qp);
48  for (unsigned int qp = 0; qp < n_qp; qp++)
49  _elem_id_to_var_values[elem_id][qp] = _u[qp];
50 }
51 
52 void
54 {
55  const auto & other_uo = static_cast<const StoreVariableByElemIDSideUserObject &>(uo);
56  const auto other_map = other_uo._elem_id_to_var_values;
57  for (auto & it : other_map)
58  _elem_id_to_var_values[it.first] = it.second;
59 }
60 
61 void
63 {
65 }
66 
67 const std::vector<ADReal> &
69 {
70  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
71 
72  auto it = _elem_id_to_var_values.find(elem_id);
73  if (it != _elem_id_to_var_values.end())
74  return it->second;
75  else
76  mooseError(
77  name(), ": The variable values for element ", elem_id, " were requested but not stored.");
78 }
registerMooseObject("ThermalHydraulicsApp", StoreVariableByElemIDSideUserObject)
StoreVariableByElemIDSideUserObject(const InputParameters &parameters)
const std::vector< ADReal > & getVariableValues(dof_id_type elem_id) const
Gets the variable values at each quadrature point on the provided element.
static InputParameters validParams()
void allGatherADVectorMap(const Parallel::Communicator &comm, std::map< dof_id_type, std::vector< ADReal >> &this_map)
Parallel gather of a map of DoF ID to AD vector.
Definition: THMUtils.C:47
Stores variable values at each quadrature point on a side by element ID.
const Parallel::Communicator & comm() const
virtual void threadJoin(const UserObject &y) override
const ADVariableValue & _u
Variable value.
virtual const std::string & name() const
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
const QBase *const & _qrule
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
const Elem *const & _current_elem
std::map< dof_id_type, std::vector< ADReal > > _elem_id_to_var_values
Map of element ID to variable values at each side quadrature point.
uint8_t dof_id_type