https://mooseframework.inl.gov
HeatStructure2DCouplerBase.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 "HeatStructurePlate.h"
13 #include "THMMesh.h"
14 
17 {
19 
20  params.addRequiredParam<std::string>("primary_heat_structure",
21  "The first heat structure to couple");
22  params.addRequiredParam<std::string>("secondary_heat_structure",
23  "The second heat structure to couple");
24  params.addRequiredParam<BoundaryName>("primary_boundary",
25  "The boundary of the first heat structure to couple");
26  params.addRequiredParam<BoundaryName>("secondary_boundary",
27  "The boundary of the second heat structure to couple");
28 
29  return params;
30 }
31 
33  : BoundaryBase(parameters),
34 
35  _hs_names({getParam<std::string>("primary_heat_structure"),
36  getParam<std::string>("secondary_heat_structure")}),
37  _hs_boundaries(
38  {getParam<BoundaryName>("primary_boundary"), getParam<BoundaryName>("secondary_boundary")}),
39 
40  _mesh_alignment(constMesh()),
41  _is_plate({false, false}),
42  _is_cylindrical({false, false})
43 {
44  addDependency(_hs_names[0]);
45  addDependency(_hs_names[1]);
46 }
47 
48 void
50 {
52 
53  if (hasComponentByName<HeatStructureBase>(_hs_names[0]) &&
54  hasComponentByName<HeatStructureBase>(_hs_names[1]))
55  {
56  const HeatStructureBase & primary_hs = getComponentByName<HeatStructureBase>(_hs_names[0]);
57  const HeatStructureBase & secondary_hs = getComponentByName<HeatStructureBase>(_hs_names[1]);
58 
59  if (primary_hs.hasBoundary(_hs_boundaries[0]) && secondary_hs.hasBoundary(_hs_boundaries[1]))
60  {
61  // Initialize the alignment mapping
63  secondary_hs.getBoundaryInfo(_hs_boundaries[1]));
64 
65  // Add entries to sparsity pattern for coupling
67  for (const auto & elem_id : _mesh_alignment.getPrimaryElemIDs())
68  {
69  if (_mesh_alignment.hasCoupledElemID(elem_id))
71  }
72  }
73  }
74 }
75 
76 void
78 {
80 
81  if (hasComponentByName<HeatStructureBase>(_hs_names[0]) &&
82  hasComponentByName<HeatStructureBase>(_hs_names[1]))
83  {
84  const HeatStructureBase & primary_hs = getComponentByName<HeatStructureBase>(_hs_names[0]);
85  const HeatStructureBase & secondary_hs = getComponentByName<HeatStructureBase>(_hs_names[1]);
86 
87  if (primary_hs.hasBoundary(_hs_boundaries[0]) && secondary_hs.hasBoundary(_hs_boundaries[1]))
88  {
89  // Get the heat structure types
90  _hs_side_types.resize(2);
92  _hs_side_types[1] = secondary_hs.getExternalBoundaryType(_hs_boundaries[1]);
93 
94  // Areas
95  _areas.resize(2);
96  _areas[0] = primary_hs.getBoundaryArea(_hs_boundaries[0]);
97  _areas[1] = secondary_hs.getBoundaryArea(_hs_boundaries[1]);
98 
99  // Compute the coupling area fractions in case areas are not equal
100  _coupling_area_fractions.resize(2);
101  if (_areas[0] > _areas[1])
102  {
104  _coupling_area_fractions[1] = 1.0;
105  }
106  else
107  {
108  _coupling_area_fractions[0] = 1.0;
110  }
111  }
112  }
113 
114  for (unsigned int i = 0; i < 2; i++)
115  {
116  if (hasComponentByName<HeatStructurePlate>(_hs_names[i]))
117  _is_plate[i] = true;
118  if (hasComponentByName<HeatStructureCylindricalBase>(_hs_names[i]))
119  _is_cylindrical[i] = true;
120  }
121 }
122 
123 void
125 {
127 
128  for (unsigned int i = 0; i < 2; i++)
129  {
130  checkComponentOfTypeExistsByName<HeatStructureBase>(_hs_names[i]);
131 
132  if (hasComponentByName<HeatStructureBase>(_hs_names[i]))
133  {
134  const HeatStructureBase & hs = getComponentByName<HeatStructureBase>(_hs_names[i]);
135  if (!hs.hasBoundary(_hs_boundaries[i]))
136  logError("The heat structure '",
137  _hs_names[i],
138  "' does not have the boundary '",
139  _hs_boundaries[i],
140  "'.");
141 
142  if ((!_is_plate[i]) && (!_is_cylindrical[i]))
143  logError("The type of the heat structure '",
144  _hs_names[i],
145  "' is not 'HeatStructurePlate' or inherited from 'HeatStructureCylindricalBase'.");
146  }
147  }
148 
149  if ((_is_plate[0] && _is_cylindrical[1]) || (_is_cylindrical[0] && _is_plate[1]))
150  logError("The coupled heat structures must have the same type.");
151 }
bool hasBoundary(const BoundaryName &boundary_name) const
Returns true if this component has the supplied boundary.
Definition: Component2D.C:473
static InputParameters validParams()
static InputParameters validParams()
Definition: BoundaryBase.C:13
const std::vector< BoundaryName > _hs_boundaries
Primary and secondary heat structure boundaries.
virtual void setupMesh()
Performs mesh setup such as creating mesh or naming mesh sets.
Definition: Component.h:306
THMProblem & getTHMProblem() const
Gets the THM problem.
Definition: Component.C:135
Base class for components of a boundary type.
Definition: BoundaryBase.h:18
void initialize(const std::vector< dof_id_type > &primary_elem_ids, const std::vector< std::tuple< dof_id_type, unsigned short int >> &secondary_boundary_info)
Extracts mesh information and builds the mapping.
Definition: MeshAlignment.C:22
const Real & getBoundaryArea(const BoundaryName &boundary_name) const
Gets the area for a boundary.
Definition: Component2D.C:570
void addRequiredParam(const std::string &name, const std::string &doc_string)
bool meshesAreAligned() const
Returns true if the primary and secondary meshes are aligned.
HeatStructure2DCouplerBase(const InputParameters &parameters)
void logError(Args &&... args) const
Logs an error.
Definition: Component.h:215
virtual void check() const
Check the component integrity.
Definition: Component.h:301
std::vector< bool > _is_cylindrical
Flag for each heat structure deriving from HeatStructureCylindricalBase.
const dof_id_type & getCoupledElemID(const dof_id_type &elem_id) const
Gets the coupled element ID for a given element ID.
virtual void init() override
Initializes the component.
std::vector< Real > _coupling_area_fractions
Area fractions by which to multiply coupling terms.
virtual void init()
Initializes the component.
Definition: Component.h:290
const std::vector< dof_id_type > & getPrimaryElemIDs() const
Returns the list of element IDs on the primary boundary.
std::vector< Real > _areas
Areas for the primary and secondary sides.
std::vector< Component2D::ExternalBoundaryType > _hs_side_types
Heat structure side types for each boundary.
const std::vector< std::tuple< dof_id_type, unsigned short int > > & getBoundaryInfo(const BoundaryName &boundary_name) const
Gets boundary info associated with the component boundary.
Definition: Component2D.C:519
MeshAlignment _mesh_alignment
Mesh alignment.
ExternalBoundaryType getExternalBoundaryType(const BoundaryName &boundary_name) const
Gets the external boundary type of the given boundary.
Definition: Component2D.C:496
virtual void setupMesh() override
Performs mesh setup such as creating mesh or naming mesh sets.
Base class for 2D generated heat structures.
const std::vector< std::string > _hs_names
Primary and secondary heat structure names.
virtual void augmentSparsity(const dof_id_type &elem_id1, const dof_id_type &elem_id2)
Hint how to augment sparsity pattern between two elements.
Definition: Simulation.C:71
std::vector< bool > _is_plate
Flag for each heat structure being HeatStructurePlate.
bool hasCoupledElemID(const dof_id_type &elem_id) const
Returns true if the element ID has a coupled element ID.
virtual void check() const override
Check the component integrity.