https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SurfaceElementSet.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 "SurfaceElementSet.h"
11#include "SurfaceEdge2.h"
12#include "SurfaceTri3.h"
13#include "MooseError.h"
14
15#include "libmesh/string_to_enum.h"
16
18SurfaceElementSet::fromMesh(const MeshBase & mesh)
19{
21
22 const auto n = mesh.n_active_elem();
23 set._elements.reserve(n);
24 set._centroids.reserve(n);
25
26 for (const auto * elem : mesh.active_element_ptr_range())
27 set.addElement(elem);
28
29 return set;
30}
31
33SurfaceElementSet::fromElements(const std::vector<const Elem *> & elems)
34{
36
37 set._elements.reserve(elems.size());
38 set._centroids.reserve(elems.size());
39
40 for (const auto * elem : elems)
41 set.addElement(elem);
42
43 return set;
44}
45
46void
48{
49 mooseAssert(elem, "Element must not be null");
50
51 // Enforce a homogeneous element family: every element must share the type of
52 // the first one added, so a group never mixes 2D EDGE2 and 3D TRI3 faces.
53 if (!_elements.empty() && _elements.front()->elem().type() != elem->type())
54 mooseError("SurfaceElementSet: mixed element types are not supported (found ",
56 " after ",
57 libMesh::Utility::enum_to_string(_elements.front()->elem().type()),
58 ").");
59
60 std::unique_ptr<SurfaceElement> surface_elem;
61 if (elem->type() == EDGE2)
62 surface_elem = std::make_unique<SurfaceEdge2>(elem);
63 else if (elem->type() == TRI3)
64 surface_elem = std::make_unique<SurfaceTri3>(elem);
65 else
66 mooseError("SurfaceElementSet: unsupported element type ",
68 ". Only EDGE2 (2D) and TRI3 (3D) surface elements are supported.");
69
70 // Grow the AABB; initialize it from the first element so an empty union does
71 // not leave the box in libMesh's inverted default state.
72 const auto bbox = elem->loose_bounding_box();
73 if (_elements.empty())
74 _bounding_box = bbox;
75 else
77
78 _centroids.emplace_back(elem->vertex_average());
79 _elements.emplace_back(std::move(surface_elem));
80}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
A group of surface elements wrapped for point-containment / distance queries.
void addElement(const Elem *elem)
Validate, wrap, and append a single element, growing centroids and the AABB.
std::vector< std::unique_ptr< SurfaceElement > > _elements
static SurfaceElementSet fromElements(const std::vector< const Elem * > &elems)
Build a set from a caller-provided subset of surface elements.
static SurfaceElementSet fromMesh(const MeshBase &mesh)
Build a set from every active element of a surface mesh.
libMesh::BoundingBox _bounding_box
std::vector< Point > _centroids
void union_with(const Point &p)
MeshBase & mesh
std::string enum_to_string(const T e)