https://mooseframework.inl.gov
FlowChannelHeatStructureCouplerUserObject.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 
15 {
18  params.addRequiredParam<MeshAlignment *>("_mesh_alignment", "Mesh alignment object");
19  params.addClassDescription(
20  "Base class for caching quantities computed between flow channels and heat structures.");
21  return params;
22 }
23 
25  const InputParameters & parameters)
26  : ElementUserObject(parameters),
27  ADFunctorInterface(this),
28  _fc_elem_id(0),
29  _hs_elem_id(0),
30  _fc_qp(0),
31  _hs_qp(0),
32  _mesh_alignment(*getParam<MeshAlignment *>("_mesh_alignment"))
33 {
35 }
36 
37 void
39 {
40  const auto map_ptrs = getCachedQuantityMaps();
41  for (const auto map_ptr : map_ptrs)
42  map_ptr->clear();
43 }
44 
45 void
47 {
48  unsigned int n_qpts = _qrule->n_points();
49 
50  _fc_elem_id = _current_elem->id();
52 
53  const auto map_ptrs = getCachedQuantityMaps();
54  for (const auto map_ptr : map_ptrs)
55  {
56  (*map_ptr)[_fc_elem_id].resize(n_qpts);
57  (*map_ptr)[_hs_elem_id].resize(n_qpts);
58  }
59 
60  for (_fc_qp = 0; _fc_qp < n_qpts; _fc_qp++)
61  {
64  }
65 }
66 
67 void
69 {
70  const auto & fc_hs_uo = static_cast<const FlowChannelHeatStructureCouplerUserObject &>(uo);
71 
72  const auto map_ptrs = getCachedQuantityMaps();
73  const auto other_map_ptrs = fc_hs_uo.getCachedQuantityMaps();
74 
75  for (unsigned int i = 0; i < map_ptrs.size(); ++i)
76  for (auto & it : *other_map_ptrs[i])
77  (*map_ptrs[i])[it.first] = it.second;
78 }
79 
80 void
82 {
83  const auto map_ptrs = getCachedQuantityMaps();
84  for (const auto map_ptr : map_ptrs)
85  THM::allGatherADVectorMap(comm(), *map_ptr);
86 }
87 
88 const std::vector<ADReal> &
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  if (it != elem_id_to_values.end())
98  return it->second;
99  else
100  mooseError(name(),
101  ": The ",
102  description,
103  " for element ",
104  elem_id,
105  " was requested but not computed.");
106 }
virtual void computeQpCachedQuantities()=0
Computes the cached quantities at a quadrature point.
Assembly & _assembly
unsigned int _hs_qp
Current heat structure quadrature point index.
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
static InputParameters validParams()
static InputParameters validParams()
const std::vector< ADReal > & getCachedQuantity(dof_id_type elem_id, const std::map< dof_id_type, std::vector< ADReal >> &elem_id_to_values, const std::string &description) const
Gets a cached quantity from a map.
Builds mapping between two aligned subdomains/boundaries.
Definition: MeshAlignment.h:24
const Parallel::Communicator & comm() const
virtual const std::string & name() const
void addRequiredParam(const std::string &name, const std::string &doc_string)
const dof_id_type & getCoupledElemID(const dof_id_type &elem_id) const
Gets the coupled element ID for a given element ID.
virtual std::vector< std::map< dof_id_type, std::vector< ADReal > > * > getCachedQuantityMaps()=0
Gets the cached quantity maps.
dof_id_type _fc_elem_id
Current flow channel element ID.
void buildCoupledElemQpIndexMap(Assembly &assembly)
Builds the map used for getting the coupled quadrature point index.
const QBase *const & _qrule
const Elem *const & _current_elem
void mooseError(Args &&... args) const
Base class for caching quantities computed between flow channels and heat structures.
void addClassDescription(const std::string &doc_string)
unsigned int _fc_qp
Current flow channel quadrature point index.
FlowChannelHeatStructureCouplerUserObject(const InputParameters &parameters)
unsigned int getCoupledElemQpIndex(const dof_id_type &elem_id, const unsigned int &qp) const
Gets the quadrature point index on the coupled element corresponding to the quadrature point index on...
uint8_t dof_id_type
dof_id_type _hs_elem_id
Current heat structure element ID.