https://mooseframework.inl.gov
Loading...
Searching...
No Matches
XYQuadrilateralMeshFromBoundaryCurve.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
12#include "Factory.h"
13#include "MooseApp.h"
14
16
19{
21
22 params.addRequiredParam<MeshGeneratorName>(
23 "boundary",
24 "The input MeshGenerator defining the outer boundary of the region to mesh with "
25 "quadrilaterals.");
26 params.addParam<std::vector<MeshGeneratorName>>(
27 "holes", std::vector<MeshGeneratorName>(), "The MeshGenerators that define mesh holes.");
28 params.addRangeCheckedParam<Real>(
29 "desired_area",
30 0,
31 "desired_area>=0",
32 "Desired (maximum) triangle area of the triangulation the quadrilaterals are built from, or "
33 "0 to size the elements from the boundary alone.");
34 params.addParam<bool>("refine_boundary",
35 true,
36 "Whether the triangulation may split the segments of the outer boundary "
37 "to reach 'desired_area'. Set to false to keep the boundary nodes of the "
38 "input, for example to stitch the mesh to a neighboring one.");
39 params.addParam<std::vector<bool>>("refine_holes",
40 std::vector<bool>(),
41 "Whether the triangulation may split the segments of each "
42 "hole boundary to reach 'desired_area', one entry per hole. "
43 "Set to false to keep the boundary nodes of that hole.");
44
45 params.addParam<BoundaryName>("output_boundary",
46 "Boundary name to set on the new outer boundary.");
47 params.addParam<std::vector<BoundaryName>>("hole_boundaries",
48 "Boundary names to set on the holes.");
49 params.addParam<SubdomainName>("output_subdomain_name",
50 "Subdomain name to set on the new elements.");
51
52 params.addRangeCheckedParam<Real>(
53 "eta_min",
54 0.3,
55 "eta_min > 0 & eta_min <= 1",
56 "The quality score eta = 1 - (2 / pi) max_k |pi / 2 - alpha_k| of the quadrilateral, in "
57 "which alpha_k are its four internal angles, that a pair of adjacent triangles must reach "
58 "to be merged. A rectangle scores 1 and a non-convex quadrilateral 0.");
59 params.addParam<bool>("all_quad",
60 true,
61 "Whether the triangles that could not be merged are eliminated so that the "
62 "mesh consists exclusively of quadrilaterals. When false, they are kept "
63 "and the mesh is quad-dominant.");
64
65 params.addParam<std::vector<MeshGeneratorName>>(
66 "parsed_curve_generators",
67 std::vector<MeshGeneratorName>(),
68 "The ParsedCurveGenerators whose curves the boundaries named in 'snap_boundaries' are "
69 "snapped onto, one generator per entry of that parameter.");
70 params.addParam<std::vector<BoundaryName>>(
71 "snap_boundaries",
72 std::vector<BoundaryName>(),
73 "The boundaries whose nodes are snapped onto the curves of 'parsed_curve_generators', one "
74 "boundary "
75 "per entry of that parameter. Use the names given in 'output_boundary' and "
76 "'hole_boundaries'.");
77
78 params.addParam<bool>("smooth",
79 true,
80 "Whether to finish the pipeline with a variational smoothing pass, which "
81 "relaxes the elements. The boundary nodes stay on the boundary but may "
82 "slide along it; set to false to keep them where the earlier steps placed "
83 "them.");
84
85 params.addParamNamesToGroup("boundary holes desired_area refine_boundary refine_holes", "Region");
86 params.addParamNamesToGroup("eta_min all_quad", "Recombination");
87 params.addParamNamesToGroup("parsed_curve_generators snap_boundaries", "Boundary snapping");
88
90 "Meshes a region bounded by input curves with quadrilaterals in one step, by chaining a "
91 "frontal Delaunay triangulation, the triangle-to-quadrilateral conversion, the snapping of "
92 "boundary nodes onto parametric curves, and an optional variational smoothing pass.");
93
94 return params;
95}
96
98 const InputParameters & parameters)
99 : MeshGenerator(parameters)
100{
101 const auto & parsed_curve_generators =
102 getParam<std::vector<MeshGeneratorName>>("parsed_curve_generators");
103 const auto & snap_boundaries = getParam<std::vector<BoundaryName>>("snap_boundaries");
104 if (parsed_curve_generators.size() != snap_boundaries.size())
106 "snap_boundaries",
107 "Need one entry per entry of 'parsed_curve_generators', because each boundary is snapped "
108 "onto the curve of the generator it is paired with.");
109
110 // The boundary and hole meshes are consumed by the triangulation sub-generator below rather
111 // than by this generator itself, and the curve generators by the snap sub-generators
112 declareMeshForSub("boundary");
113 declareMeshesForSub("holes");
114 declareMeshesForSubByName(parsed_curve_generators);
115
116 {
117 auto params = _app.getFactory().getValidParams("XYFrontalDelaunayGenerator");
118
119 params.set<MeshGeneratorName>("boundary") = getParam<MeshGeneratorName>("boundary");
120 params.set<std::vector<MeshGeneratorName>>("holes") =
121 getParam<std::vector<MeshGeneratorName>>("holes");
122 params.set<Real>("desired_area") = getParam<Real>("desired_area");
123 params.set<bool>("refine_boundary") = getParam<bool>("refine_boundary");
124 params.set<std::vector<bool>>("refine_holes") = getParam<std::vector<bool>>("refine_holes");
125 if (isParamValid("output_boundary"))
126 params.set<BoundaryName>("output_boundary") = getParam<BoundaryName>("output_boundary");
127 if (isParamValid("hole_boundaries"))
128 params.set<std::vector<BoundaryName>>("hole_boundaries") =
129 getParam<std::vector<BoundaryName>>("hole_boundaries");
130 if (isParamValid("output_subdomain_name"))
131 params.set<SubdomainName>("output_subdomain_name") =
132 getParam<SubdomainName>("output_subdomain_name");
133
134 // The defaults of 'metric' and 'orientation' already give the right isosceles triangles that
135 // recombine into good quadrilaterals, so they are not exposed
136 addMeshSubgenerator("XYFrontalDelaunayGenerator", name() + "_frontal", params);
137 }
138
139 {
140 auto params = _app.getFactory().getValidParams("TriToQuadConverter");
141
142 params.set<MeshGeneratorName>("input") = name() + "_frontal";
143 params.set<Real>("eta_min") = getParam<Real>("eta_min");
144 params.set<bool>("all_quad") = getParam<bool>("all_quad");
145
146 addMeshSubgenerator("TriToQuadConverter", name() + "_to_quad", params);
147 }
148
149 MeshGeneratorName previous = name() + "_to_quad";
150 for (const auto snap_i : index_range(parsed_curve_generators))
151 {
152 auto params = _app.getFactory().getValidParams("MoveBoundaryNodesToCurveGenerator");
153
154 params.set<MeshGeneratorName>("input") = previous;
155 params.set<BoundaryName>("boundary") = snap_boundaries[snap_i];
156 params.set<MeshGeneratorName>("parsed_curve_generator") = parsed_curve_generators[snap_i];
157
158 previous = name() + "_snap_" + std::to_string(snap_i);
159 addMeshSubgenerator("MoveBoundaryNodesToCurveGenerator", previous, params);
160 }
161
162 if (getParam<bool>("smooth"))
163 {
164 auto params = _app.getFactory().getValidParams("SmoothMeshGenerator");
165
166 params.set<MeshGeneratorName>("input") = previous;
167 // The variational algorithm cannot tangle the mesh and only allows node movement that leaves
168 // the domain unchanged, so the snapped geometry survives the smoothing
169 params.set<MooseEnum>("algorithm") = "variational";
170
171 previous = name() + "_smooth";
172 addMeshSubgenerator("SmoothMeshGenerator", previous, params);
173 }
174
175 _build_mesh = &getMeshByName(previous);
176}
177
178std::unique_ptr<MeshBase>
registerMooseObject("MooseApp", XYQuadrilateralMeshFromBoundaryCurve)
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 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)
MeshGenerators are objects that can modify or add to an existing mesh.
void declareMeshForSub(const std::string &param_name)
Declares that a MeshGenerator referenced in the InputParameters is to be used as a dependency of a su...
void addMeshSubgenerator(const std::string &type, const std::string &name, Ts... extra_input_parameters)
Construct a "subgenerator", a different MeshGenerator subclass that will be added to the same MooseAp...
std::unique_ptr< MeshBase > & getMeshByName(const MeshGeneratorName &mesh_generator_name)
Like getMesh(), but takes the name of another MeshGenerator directly.
static InputParameters validParams()
void declareMeshesForSub(const std::string &param_name)
Like declareMeshForSub(), but for multiple generators.
void declareMeshesForSubByName(const std::vector< MeshGeneratorName > &mesh_generator_names)
Like declareMeshForSubByName(), but for multiple generators.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
Definition MooseApp.h:407
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
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
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
Meshes a region bounded by input curves with quadrilaterals in one step, by chaining the generators o...
XYQuadrilateralMeshFromBoundaryCurve(const InputParameters &parameters)
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
std::unique_ptr< MeshBase > * _build_mesh
Mesh of the final sub-generator of the chain, which is the mesh this generator produces.