https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
19
21
22void
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
33void
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
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))
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)
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
133bool
135{
136 return false;
137}
138
139unsigned int
146
147const BoundaryName &
154
155const 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}
167
168std::string
170{
171 // choose the dominant direction
172 std::string dominant_direction = "x";
173 const Real x_abs = std::abs(_dir(0));
174 const Real y_abs = std::abs(_dir(1));
175 const Real z_abs = std::abs(_dir(2));
176 Real max_value = x_abs;
177 if (y_abs > max_value)
178 {
179 dominant_direction = "y";
180 max_value = y_abs;
181 }
182 if (z_abs > max_value)
183 {
184 dominant_direction = "z";
185 max_value = z_abs;
186 }
187 return dominant_direction;
188}
boundary_id_type BoundaryID
const Real p
const std::string name
Definition Setup.h:21
std::map< Component1DConnection::EEndType, std::vector< Connection > > _connections
Map of end type to a list of connections.
Definition Component1D.h:79
virtual void buildMeshNodes()
Definition Component1D.C:23
Component1D(const InputParameters &parameters)
Definition Component1D.C:20
virtual void buildMesh() override
Definition Component1D.C:34
virtual bool usingSecondOrderMesh() const override
Check if second order mesh is being used by this geometrical component.
unsigned int getNodesetID() const
Gets the 1D component nodeset ID.
BoundaryName _nodeset_name
Nodeset name for all 1D component nodes.
Definition Component1D.h:87
static InputParameters validParams()
Definition Component1D.C:14
std::string sortBy() const
virtual const std::vector< Connection > & getConnections(Component1DConnection::EEndType end_type) const
Gets the vector of connections of an end type for this component.
BoundaryID _nodeset_id
Nodeset ID for all 1D component nodes.
Definition Component1D.h:85
const BoundaryName & getNodesetName() const
Gets the 1D component nodeset name.
std::vector< dof_id_type > _elem_ids
Element IDs of this component.
Definition Component.h:508
Node * addNode(const Point &pt)
Definition Component.C:203
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:219
@ MESH_PREPARED
mesh set up
Definition Component.h:40
std::vector< dof_id_type > _node_ids
Node IDs of this component.
Definition Component.h:506
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
THMMesh & mesh()
Non-const reference to THM mesh, which can only be called before the end of mesh setup.
Definition Component.C:60
unsigned int _n_elem
Total number of axial elements.
std::vector< unsigned int > _n_elems
Number of elements in each axial section.
const Point & _position
Start position of axis in 3-D space.
const RealVectorValue _dir
Normalized direction of axis from start position to end position.
Base class for components that generate their own mesh.
std::vector< Real > _node_locations
Node locations along the main axis.
static InputParameters validParams()
const std::vector< std::string > & _axial_region_names
Axial region names.
Elem * addElementEdge3(dof_id_type node0, dof_id_type node1, dof_id_type node2)
Elem * addElementEdge2(dof_id_type node0, dof_id_type node1)
void mooseError(Args &&... args) const
virtual Elem * elemPtr(const dof_id_type i)
MeshBase & getMesh()
void update()
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.
virtual SubdomainID getNextSubdomainId()
Gets the next subdomain ID.
Definition THMMesh.C:202
virtual BoundaryID getNextBoundaryId()
Gets the next nodeset or sideset ID.
Definition THMMesh.C:209
Structure for storing connection data.
Definition Component1D.h:25