https://mooseframework.inl.gov
PolyLineMeshGenerator.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 "PolyLineMeshGenerator.h"
11 
12 #include "CastUniquePointer.h"
13 #include "MooseMeshUtils.h"
14 #include "MooseUtils.h"
15 
16 #include "libmesh/elem.h"
17 #include "libmesh/int_range.h"
18 #include "libmesh/unstructured_mesh.h"
19 
21 
24 {
26 
27  params.addParam<std::vector<Point>>("points", "The points defining the polyline, in order");
28 
29  params.addParam<bool>("loop", false, "Whether edges should form a closed loop");
30 
31  params.addParam<BoundaryName>(
32  "start_boundary", "start", "Boundary to assign to (non-looped) polyline start");
33 
34  params.addParam<BoundaryName>(
35  "end_boundary", "end", "Boundary to assign to (non-looped) polyline end");
36 
37  params.addParam<std::vector<unsigned int>>(
38  "nums_edges_between_points",
39  {1},
40  "How many Edge elements to build between each point pair. If a single value is given, it is "
41  "applied to all segments. Otherwise, the number of entries must match the number of "
42  "segments.");
43  params.addDeprecatedParam<unsigned int>("num_edges_between_points",
44  1,
45  "How many Edge elements to build between each point pair",
46  "Use nums_edges_between_points instead");
47 
48  params.addClassDescription("Generates meshes from edges connecting a list of points.");
49 
50  return params;
51 }
52 
54  : MeshGenerator(parameters),
55  _points(getParam<std::vector<Point>>("points")),
56  _loop(getParam<bool>("loop")),
57  _start_boundary(_loop ? BoundaryName() : getParam<BoundaryName>("start_boundary")),
58  _end_boundary(_loop ? BoundaryName() : getParam<BoundaryName>("end_boundary")),
59  _nums_edges_between_points(
60  parameters.isParamSetByUser("num_edges_between_points")
61  ? std::vector<unsigned int>{getParam<unsigned int>("num_edges_between_points")}
62  : getParam<std::vector<unsigned int>>("nums_edges_between_points"))
63 {
64  if (_points.size() < 2)
65  paramError("points", "At least 2 points are needed to define a polyline");
66 
67  if (_loop && _points.size() < 3)
68  paramError("points", "At least 3 points are needed to define a polygon");
69 
70  if (_nums_edges_between_points.size() != 1 &&
71  _nums_edges_between_points.size() != _points.size() - 1 + (_loop ? 1 : 0))
72  paramError(
73  "nums_edges_between_points",
74  "This size of this vector input parameter must be 1 or match the number of segments");
75 }
76 
77 std::unique_ptr<MeshBase>
79 {
80  auto uptr_mesh = buildMeshBaseObject();
81  MeshBase & mesh = *uptr_mesh;
82 
85 
86  return uptr_mesh;
87 }
void buildPolyLineMesh(MeshBase &mesh, const std::vector< Point > &points, const bool loop, const BoundaryName &start_boundary, const BoundaryName &end_boundary, const std::vector< unsigned int > &nums_edges_between_points)
Generates meshes from edges connecting a list of points.
Generates a polyline (open ended or looped) of Edge elements through a series of nodal locations and ...
static InputParameters validParams()
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
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:467
registerMooseObject("MooseApp", PolyLineMeshGenerator)
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const BoundaryName _start_boundary
Boundary names to assign to (non-looped) polyline start and end.
const std::vector< unsigned int > _nums_edges_between_points
How many Edge elements to build between each point pair.
PolyLineMeshGenerator(const InputParameters &parameters)
const bool _loop
Whether edges should form a closed loop.
static InputParameters validParams()
Definition: MeshGenerator.C:23
const BoundaryName _end_boundary
const std::vector< Point > _points
The points defining the polyline, in order.
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
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...
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...
std::unique_ptr< MeshBase > buildMeshBaseObject(unsigned int dim=libMesh::invalid_uint)
Build a MeshBase object whose underlying type will be determined by the Mesh input file block...
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:33
void ErrorVector unsigned int