https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SurfaceDelaunayGeneratorBase.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#include "libmesh/parallel_implementation.h"
12#include "libmesh/parallel_algebra.h"
13
16{
18
19 params.addParam<bool>("use_auto_area_func",
20 false,
21 "Use the automatic area function for the triangle meshing region.");
22 params.addParam<Real>(
23 "auto_area_func_default_size",
24 0,
25 "Background size for automatic area function, or 0 to use non background size");
26 params.addParam<Real>("auto_area_func_default_size_dist",
27 -1.0,
28 "Effective distance of background size for automatic area "
29 "function, or negative to use non background size");
30 params.addParam<unsigned int>("auto_area_function_num_points",
31 10,
32 "Maximum number of nearest points used for the inverse distance "
33 "interpolation algorithm for automatic area function calculation.");
34 params.addRangeCheckedParam<Real>(
35 "auto_area_function_power",
36 1.0,
37 "auto_area_function_power>0",
38 "Polynomial power of the inverse distance interpolation algorithm for automatic area "
39 "function calculation.");
40
41 params.addClassDescription("Base class for Delaunay mesh generators applied to a surface.");
42
44 "use_auto_area_func auto_area_func_default_size auto_area_func_default_size_dist "
45 "auto_area_function_num_points auto_area_function_power",
46 "Automatic triangle meshing area control");
47
48 params.addRangeCheckedParam<Real>(
49 "max_angle_deviation",
50 60.0,
51 "max_angle_deviation>0 & max_angle_deviation<90",
52 "Maximum angle deviation from the global average normal vector in the input mesh.");
53 params.addParam<bool>(
54 "verbose", false, "Whether the generator should output additional information");
55 return params;
56}
57
59 : MeshGenerator(parameters),
60 _use_auto_area_func(getParam<bool>("use_auto_area_func")),
61 _auto_area_func_default_size(getParam<Real>("auto_area_func_default_size")),
62 _auto_area_func_default_size_dist(getParam<Real>("auto_area_func_default_size_dist")),
63 _auto_area_function_num_points(getParam<unsigned int>("auto_area_function_num_points")),
64 _auto_area_function_power(getParam<Real>("auto_area_function_power")),
65 _max_angle_deviation(getParam<Real>("max_angle_deviation")),
66 _verbose(getParam<bool>("verbose"))
67{
68}
69
70Point
72{
73 mooseAssert(elem.n_vertices() == 3 || elem.n_vertices() == 4, "unsupported element type.");
74 // Only the first three vertices are used to calculate the normal vector
75 const Point & p0 = *elem.node_ptr(0);
76 const Point & p1 = *elem.node_ptr(1);
77 const Point & p2 = *elem.node_ptr(2);
78
79 if (elem.n_vertices() == 4)
80 {
81 const Point & p3 = *elem.node_ptr(3);
82 return ((p2 - p0).cross(p3 - p1)).unit();
83 }
84
85 return ((p2 - p1).cross(p0 - p1)).unit();
86}
87
88Point
90{
91 Point mesh_norm = Point(0.0, 0.0, 0.0);
92 Real mesh_area = 0.0;
93
94 // Check all the elements' normal vectors
95 for (const auto & elem : mesh.active_local_element_ptr_range())
96 {
97 const Real elem_area = elem->volume();
98 mesh_norm += elemNormal(*elem) * elem_area;
99 mesh_area += elem_area;
100 }
101 mesh.comm().sum(mesh_norm);
102 mesh.comm().sum(mesh_area);
103 mesh_norm /= mesh_area;
104 return mesh_norm.unit();
105}
106
107Real
109 const Point & global_norm)
110{
111 Real max_deviation(0.0);
112 // Check all the elements' deviation from the global normal vector
113 for (const auto & elem : mesh.active_local_element_ptr_range())
114 {
115 const Real elem_deviation = std::acos(global_norm * elemNormal(*elem)) / M_PI * 180.0;
116 max_deviation = std::max(max_deviation, elem_deviation);
117 if (_verbose && elem_deviation > _max_angle_deviation)
118 _console << "Element " << elem->id() << " from subdomain ID " << elem->subdomain_id()
119 << " has normal deviation: " << elem_deviation << std::endl;
120 }
121 mesh.comm().max(max_deviation);
122 return max_deviation;
123}
void ErrorVector unsigned int
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
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 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 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.
static InputParameters validParams()
const bool _verbose
Whether the generator should be verbose.
Real meshNormalDeviation2D(const MeshBase &mesh, const Point &global_norm)
Calculate the maximum deviation of the normal vectors in a given mesh from a global average normal ve...
Point meshNormal2D(const MeshBase &mesh)
Calculate the average normal vector of a 2D mesh based on the normal vectors of its elements using th...
Point elemNormal(const Elem &elem)
Calculate the normal vector of a 2D element based the first three vertices.
SurfaceDelaunayGeneratorBase(const InputParameters &parameters)
const Real _max_angle_deviation
Max angle deviation from the global average normal vector in the input mesh.
MeshBase & mesh