https://mooseframework.inl.gov
Component1D.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 
10 #include "Component1D.h"
11 #include "THMMesh.h"
12 
15 {
17  return params;
18 }
19 
21 
22 void
24 {
25  Point p(0, 0, 0);
26  for (unsigned int i = 0; i < _node_locations.size(); i++)
27  {
28  p(0) = _node_locations[i];
29  addNode(p);
30  }
31 }
32 
33 void
35 {
37 
38  MeshBase & the_mesh = mesh().getMesh();
39  BoundaryInfo & boundary_info = the_mesh.get_boundary_info();
40 
41  // create nodeset for all nodes for this component
43  _nodeset_name = name();
44  boundary_info.nodeset_name(_nodeset_id) = _nodeset_name;
45 
46  // Check that the number of nodes is consistent with the number of nodes in case component
47  // developers screw up (typically in buildMeshNodes() call)
49  {
50  if (_node_ids.size() != (2 * _n_elem + 1))
51  mooseError(name(),
52  ": Inconsistent number of nodes and elements. You have ",
53  _n_elem,
54  " elements and ",
55  _node_ids.size(),
56  " nodes.");
57  }
58  else
59  {
60  if (_node_ids.size() != _n_elem + 1)
61  mooseError(name(),
62  ": Inconsistent number of nodes and elements. You have ",
63  _n_elem,
64  " elements and ",
65  _node_ids.size(),
66  " nodes.");
67  }
68 
69  for (auto & node_id : _node_ids)
70  {
71  const Node * nd = the_mesh.node_ptr(node_id);
72  boundary_info.add_node(nd, _nodeset_id);
73  }
74 
75  // elems
76  BoundaryID bc_id_inlet = mesh().getNextBoundaryId();
77  BoundaryID bc_id_outlet = mesh().getNextBoundaryId();
78  auto & binfo = mesh().getMesh().get_boundary_info();
79  for (unsigned int i = 0; i < _n_elem; i++)
80  {
81  Elem * elem = nullptr;
83  elem = addElementEdge3(_node_ids[2 * i], _node_ids[2 * i + 2], _node_ids[2 * i + 1]);
84  else
85  elem = addElementEdge2(_node_ids[i], _node_ids[i + 1]);
86 
87  // BCs
88  if (i == 0)
89  {
90  Point pt = _position;
91  _connections[Component1DConnection::IN].push_back(Connection(pt, elem, 0, bc_id_inlet, -1));
92  boundary_info.add_side(elem, 0, bc_id_inlet);
93  binfo.sideset_name(bc_id_inlet) = genName(name(), "in");
94  }
95  if (i == (_n_elem - 1))
96  {
97  Point pt = _position + _length * _dir;
98  _connections[Component1DConnection::OUT].push_back(Connection(pt, elem, 1, bc_id_outlet, 1));
99  boundary_info.add_side(elem, 1, bc_id_outlet);
100  binfo.sideset_name(bc_id_outlet) = genName(name(), "out");
101  }
102  }
103 
104  if (_axial_region_names.size() > 0)
105  {
106  unsigned int k = 0;
107  for (unsigned int i = 0; i < _axial_region_names.size(); i++)
108  {
109  const std::string & region_name = _axial_region_names[i];
110  SubdomainID subdomain_id = mesh().getNextSubdomainId();
111  setSubdomainInfo(subdomain_id, genName(name(), region_name));
112 
113  for (unsigned int j = 0; j < _n_elems[i]; j++, k++)
114  {
115  dof_id_type elem_id = _elem_ids[k];
116  mesh().elemPtr(elem_id)->subdomain_id() = subdomain_id;
117  }
118  }
119  }
120  else
121  {
122  SubdomainID subdomain_id = mesh().getNextSubdomainId();
123  setSubdomainInfo(subdomain_id, name());
124 
125  for (auto && id : _elem_ids)
126  mesh().elemPtr(id)->subdomain_id() = subdomain_id;
127  }
128 
129  // Update the mesh
130  mesh().update();
131 }
132 
133 bool
135 {
136  return false;
137 }
138 
139 unsigned int
141 {
143 
144  return _nodeset_id;
145 }
146 
147 const BoundaryName &
149 {
151 
152  return _nodeset_name;
153 }
154 
155 const std::vector<Component1D::Connection> &
157 {
159 
160  std::map<Component1DConnection::EEndType, std::vector<Connection>>::const_iterator it =
161  _connections.find(end_type);
162  if (it != _connections.end())
163  return it->second;
164  else
165  mooseError(name(), ": Invalid end type (", end_type, ").");
166 }
Elem * addElementEdge2(dof_id_type node0, dof_id_type node1)
virtual void buildMeshNodes()
Definition: Component1D.C:23
std::string genName(const std::string &prefix, unsigned int id, const std::string &suffix="") const
Build a name from a prefix, number and possible suffix.
std::map< Component1DConnection::EEndType, std::vector< Connection > > _connections
Map of end type to a list of connections.
Definition: Component1D.h:78
virtual Elem * elemPtr(const dof_id_type i)
virtual bool usingSecondOrderMesh() const override
Check if second order mesh is being used by this geometrical component.
Definition: Component1D.C:134
Component1D(const InputParameters &parameters)
Definition: Component1D.C:20
BoundaryID _nodeset_id
Nodeset ID for all 1D component nodes.
Definition: Component1D.h:84
Structure for storing connection data.
Definition: Component1D.h:24
static InputParameters validParams()
virtual void setSubdomainInfo(SubdomainID subdomain_id, const std::string &subdomain_name, const Moose::CoordinateSystemType &coord_system=Moose::COORD_XYZ)
Sets the next subdomain ID, name, and coordinate system.
Definition: Component.C:229
Node * addNode(const Point &pt)
Definition: Component.C:213
virtual const std::string & name() const
std::vector< dof_id_type > _elem_ids
Element IDs of this component.
Definition: Component.h:457
const RealVectorValue _dir
Normalized direction of axis from start position to end position.
MeshBase & getMesh()
std::vector< dof_id_type > _node_ids
Node IDs of this component.
Definition: Component.h:455
Base class for components that generate their own mesh.
boundary_id_type BoundaryID
void update()
BoundaryName _nodeset_name
Nodeset name for all 1D component nodes.
Definition: Component1D.h:86
const Point & _position
Start position of axis in 3-D space.
virtual SubdomainID getNextSubdomainId()
Gets the next subdomain ID.
Definition: THMMesh.C:202
Elem * addElementEdge3(dof_id_type node0, dof_id_type node1, dof_id_type node2)
const BoundaryName & getNodesetName() const
Gets the 1D component nodeset name.
Definition: Component1D.C:148
THMMesh & mesh()
Non-const reference to THM mesh, which can only be called before the end of mesh setup.
Definition: Component.C:60
const std::vector< unsigned int > & _n_elems
Number of elements in each axial section.
const unsigned int _n_elem
Total number of axial elements.
virtual const std::vector< Connection > & getConnections(Component1DConnection::EEndType end_type) const
Gets the vector of connections of an end type for this component.
Definition: Component1D.C:156
void checkSetupStatus(const EComponentSetupStatus &status) const
Throws an error if the supplied setup status of this component has not been reached.
Definition: Component.C:117
virtual BoundaryID getNextBoundaryId()
Gets the next nodeset or sideset ID.
Definition: THMMesh.C:209
static InputParameters validParams()
Definition: Component1D.C:14
void mooseError(Args &&... args) const
virtual void buildMesh() override
Definition: Component1D.C:34
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
std::vector< Real > _node_locations
Node locations along the main axis.
static const std::string k
Definition: NS.h:130
unsigned int getNodesetID() const
Gets the 1D component nodeset ID.
Definition: Component1D.C:140
uint8_t dof_id_type
const std::vector< std::string > & _axial_region_names
Axial region names.