https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CylinderComponent.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// MOOSE includes
11#include "CylinderComponent.h"
12#include "RotationMatrix.h"
13
14registerMooseAction("MooseApp", CylinderComponent, "add_mesh_generator");
15// CylinderComponent is an example of ComponentPhysicsInterface
16registerMooseAction("MooseApp", CylinderComponent, "init_component_physics");
17// CylinderComponent is an example of ComponentMaterialPropertyInterface
18registerMooseAction("MooseApp", CylinderComponent, "add_material");
19// CylinderComponent is an example of ComponentInitialConditionInterface
20registerMooseAction("MooseApp", CylinderComponent, "check_integrity");
22
25{
32 params.addClassDescription("Cylindrical component.");
33 MooseEnum dims("0 1 2 3");
34 params.addRequiredParam<MooseEnum>("dimension",
35 dims,
36 "Dimension of the cylinder. 0 for a point (not implemented), "
37 "1 for an (axial) 1D line, 2 for a 2D-RZ cylinder, and 3 for "
38 "a 3D cylinder");
39 params.addParam<SubdomainName>("block", "Block name for the cylinder");
40
41 // Geometry
42 params.addRequiredRangeCheckedParam<Real>("radius", "radius>0", "Radius of the cylinder");
43 params.addRequiredRangeCheckedParam<Real>("length", "length>0", "Length/Height of the cylinder");
44 params.addParam<bool>("position_is_bottom_center",
45 true,
46 "Whether the 'position' parameter gives the position of the bottom-center "
47 "of the cylinder. Only used in 3D");
48
49 // Discretization
50 params.addRangeCheckedParam<std::vector<unsigned int>>(
51 "n_radial",
52 {1},
53 "n_radial > 0",
54 "Number of radial elements (per ring if multiple values specified). All rings are lumped at "
55 "this time.");
56 // TODO: Specify the ring radii and subdomains as well
57 params.addRequiredRangeCheckedParam<unsigned int>(
58 "n_axial", "n_axial>0", "Number of axial elements of the cylinder");
59 params.addRangeCheckedParam<unsigned int>(
60 "n_sectors",
61 "n_sectors>0",
62 "Number of azimuthal sectors in each quadrant of cylinder face. Only used in 3D");
63 params.addParamNamesToGroup("n_radial n_axial n_sectors", "Discretization");
64
65 // Boundary layers
66 params.addRangeCheckedParam<Real>("boundary_layer_width",
67 "boundary_layer_width>=0",
68 "The width of the radial boundary layer (if assigned).");
69 params.addParam<unsigned int>(
70 "n_boundary_layers",
71 1,
72 "The number of radial boundary layers. Only active if boundary_layer_width is specified");
73 params.addParamNamesToGroup("boundary_layer_width n_boundary_layers", "Radial boundary layer");
74
75 return params;
76}
77
79 : ActionComponent(params),
85 _radius(getParam<Real>("radius")),
86 _height(getParam<Real>("length")),
87 _offset_position_to_center(getParam<bool>("position_is_bottom_center"))
88{
89 _dimension = getParam<MooseEnum>("dimension");
90 // The other component interfaces add their required task
91 addRequiredTask("add_mesh_generator");
92}
93
94void
96{
97 // Create the base mesh for the component using a mesh generator
98 if (_dimension == 0)
99 paramError("dimension", "0D cylinder not implemented");
100 else if (_dimension == 1 || _dimension == 2)
101 {
102 InputParameters params = _factory.getValidParams("GeneratedMeshGenerator");
103 params.set<MooseEnum>("dim") = _dimension;
104 params.set<Real>("xmax") = {getParam<Real>("length")};
105 params.set<unsigned int>("nx") = {getParam<unsigned int>("n_axial")};
106 params.set<std::string>("boundary_name_prefix") = name();
107 if (_dimension == 2)
108 {
109 params.set<Real>("ymax") = {getParam<Real>("radius")};
110 params.set<Real>("ymin") = 0;
111 if (!isParamValid("n_radial"))
112 paramError("n_radial", "Should be provided for a 2D cylinder");
113 params.set<unsigned int>("ny") = getParam<std::vector<unsigned int>>("n_radial")[0];
114 }
115 else if (isParamSetByUser("n_radial"))
116 paramError("n_radial", "Should not be provided for a 1D cylinder");
117 if (isParamValid("block"))
118 {
119 const auto block_name = getParam<SubdomainName>("block");
120 params.set<SubdomainName>("subdomain_name") = block_name;
121 _blocks.push_back(block_name);
122 }
124 "GeneratedMeshGenerator", name() + "_base", params);
125 _mg_names.push_back(name() + "_base");
126 }
127 else if (_dimension == 3)
128 {
129 if (!isParamValid("n_axial"))
130 paramError("n_axial", "Should be provided for a 3D cylinder");
131 if (!isParamValid("n_sectors"))
132 paramError("n_sectors", "Should be provided in 3D");
133
134 // create circular face
135 InputParameters circle_params = _factory.getValidParams("ConcentricCircleMeshGenerator");
136 circle_params.set<bool>("preserve_volumes") = true;
137 circle_params.set<bool>("has_outer_square") = false;
138 auto ring_disc_vec = getParam<std::vector<unsigned int>>("n_radial");
139 // TODO: multi-ring support
140 ring_disc_vec = {std::accumulate(ring_disc_vec.begin(), ring_disc_vec.end(), (unsigned int)0)};
141 if (isParamValid("boundary_layer_width"))
142 {
143 Real inner_radius = getParam<Real>("radius") - getParam<Real>("boundary_layer_width");
144 circle_params.set<std::vector<Real>>("radii") = {inner_radius, getParam<Real>("radius")};
145 ring_disc_vec.push_back(getParam<unsigned int>("n_boundary_layers"));
146 }
147 else
148 circle_params.set<std::vector<Real>>("radii") = {getParam<Real>("radius")};
149 circle_params.set<std::vector<unsigned int>>("rings") = ring_disc_vec;
150
151 circle_params.set<unsigned int>("num_sectors") = getParam<unsigned int>("n_sectors");
152 if (isParamValid("block"))
153 {
154 const auto block_name = getParam<SubdomainName>("block");
155 circle_params.set<SubdomainName>("subdomain_name") = block_name;
156 _blocks.push_back(block_name);
157 }
159 "ConcentricCircleMeshGenerator", name() + "_circle_base", circle_params);
160 _mg_names.push_back(name() + "_circle_base");
161
162 // rotate to have extrusion axis be along x-axis
163 // NOTE: this is re-rotated by the ComponentMeshTransformHelper
164 InputParameters rotate_params = _factory.getValidParams("TransformGenerator");
165 rotate_params.set<MeshGeneratorName>("input") = _mg_names.back();
166 rotate_params.set<MooseEnum>("transform") = "ROTATE_EXT";
167 RealVectorValue angles(-90, -90, 90);
168 rotate_params.set<RealVectorValue>("vector_value") = angles;
170 "TransformGenerator", name() + "_3D_init_rotate", rotate_params);
171 _mg_names.push_back(name() + "_3D_init_rotate");
172
173 // extrude the surface
174 InputParameters ext_params = _factory.getValidParams("AdvancedExtruderGenerator");
175 ext_params.set<std::vector<unsigned int>>("num_layers") = {getParam<unsigned int>("n_axial")};
176 ext_params.set<MeshGeneratorName>("input") = _mg_names.back();
177 ext_params.set<std::vector<Real>>("heights") = {_height};
178 ext_params.set<BoundaryName>("bottom_boundary") = name() + "_bottom_boundary";
179 ext_params.set<BoundaryName>("top_boundary") = name() + "_top_boundary";
180
181 const Point default_direction(1, 0, 0);
182 ext_params.set<Point>("direction") = default_direction;
184 "AdvancedExtruderGenerator", name() + "_base", ext_params);
185 _mg_names.push_back(name() + "_base");
186 }
187 _top_mg_name = _mg_names.back();
188
190}
191
192void
194{
195 if (_dimension == 2)
196 {
197 _awh.getMesh()->setCoordSystem(_blocks, MultiMooseEnum("COORD_RZ"));
198 if (_direction)
199 _awh.getMesh()->setGeneralAxisymmetricCoordAxes(
200 {getParam<SubdomainName>("block")},
201 {std::make_pair(translation(), _direction ? *_direction : RealVectorValue(0, 1, 0))});
202 if (_rotation)
203 paramError("rotation", "Rotation + 2D RZ cylinder not implemented");
204 }
205}
206
207void
213
214Point
216{
217 // The 1D or 2D RZ cylinders are naturally centered
220
221 auto input_translation = ComponentMeshTransformHelper::translation();
222 // The translation will be applied after the rotation, we need to translate by the rotated radius
223 // There are two options for specifying rotations / translations
224 if (_rotation)
225 paramError("position_is_bottom_center",
226 "Rotation + offset cylinder to center not implemented. Use 'direction' instead");
227
228 const auto rotation_matrix =
230 ? RotationMatrix::rodriguesRotationMatrix<false>(RealVectorValue(1, 0, 0), *_direction)
231 : RealTensorValue(1, 0, 0, 0, 1, 0, 0, 0, 1);
232 input_translation -= rotation_matrix * Point(_radius, 0, 0);
233
234 return input_translation;
235}
registerActionComponent("MooseApp", CylinderComponent)
registerMooseAction("MooseApp", CylinderComponent, "add_mesh_generator")
Base class for components that are defined using an action.
std::vector< MeshGeneratorName > _mg_names
Name(s) of the final mesh generator(s) creating the mesh for the component.
void addRequiredTask(const std::string &task)
Add a new required task for all physics deriving from this class NOTE: This does not register the tas...
std::vector< SubdomainName > _blocks
Names of the blocks the component is comprised of.
MeshGeneratorName _top_mg_name
Name of the top-most mesh generator in the hierarchy of MGs on top of the ones generating this compon...
static InputParameters validParams()
unsigned int _dimension
Maximum dimension of the component.
const std::shared_ptr< MooseMesh > & getMesh() const
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
ActionWarehouse & _awh
Reference to ActionWarehouse where we store object build by actions.
Definition Action.h:169
Helper class to help Components accept boundary condition parameters that the Physics may use to gene...
virtual void checkIntegrity() override
Used for various checks notably:
Helper class to help Components define the initial conditions the Physics may need from the parameter...
virtual void checkIntegrity() override
Used for various checks notably:
Helper class to help Components define the material properties the Physics may need from the paramete...
Helper class to help Components be located with the orientation and position we want.
const RealVectorValue *const _direction
Direction vector (easier to conceptualize than rotation)
const RealVectorValue *const _rotation
Rotation angles.
virtual Point translation() const
Return the translation of the component The default translation is the null vector.
Helper class to help creating an entire physics Note: Trying out virtual inheritance.
static InputParameters validParams()
Cylinder on which one can define a Physics.
const Real _radius
Radius of the cylinder.
const Real _height
Height of the cylinder.
virtual Point translation() const override
Return the translation of the component The default translation is the null vector.
virtual void setupComponent() override
virtual void checkIntegrity() override
Used for various checks notably:
static InputParameters validParams()
const bool _offset_position_to_center
Whether to center the cylinder.
virtual void addMeshGenerators() override
CylinderComponent(const InputParameters &params)
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
These methods add an range checked parameters.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
void addMeshGenerator(const std::string &type, const std::string &name, const InputParameters &params)
Add a mesh generator that will act on the meshes in the system.
MeshGeneratorSystem & getMeshGeneratorSystem()
Gets the system that manages the MeshGenerators.
Definition MooseApp.h:886
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
bool isParamSetByUser(const std::string &name) const
Test if the supplied parameter is set by a user, as opposed to not set or set to default.
Definition MooseBase.h:205
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition MooseBase.h:406
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type.
Factory & _factory
The Factory associated with the MooseApp.