https://mooseframework.inl.gov
Loading...
Searching...
No Matches
BoundaryMeshBuilder.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 "BoundaryMeshBuilder.h"
11#include "MooseMesh.h"
12#include "MeshGeneratorSystem.h"
13
15
18{
21 "Owns a saved surface (boundary) mesh and the SurfaceElement wrappers built from it, "
22 "for use by point-containment and distance user objects.");
23
24 params.addRequiredParam<std::string>(
25 "surface_mesh",
26 "The name of the surface mesh saved via the MeshGenerator's `save_with_name` parameter.");
27
28 params.addParam<bool>(
29 "check_watertightness",
30 false,
31 "Check if the mesh is watertight. If false, the mesh may not be suitable for In-Out tests.");
32
33 return params;
34}
35
37 : GeneralUserObject(parameters),
38 _bnd_mesh_name(getParam<std::string>("surface_mesh")),
39 _check_watertightness(getParam<bool>("check_watertightness")),
40 _dim_embedding_mesh(_fe_problem.mesh().dimension() /*MooseMesh*/)
41{
42}
43
44void
46{
47 // A saved mesh has single-retrieval semantics: getSavedMesh() std::move()s it
48 // out and errors on a second retrieval. This builder is the sole owner.
50
51 // A saved mesh produced by a MeshGenerator may be unprepared, leaving
52 // mesh_dimension() stale and element neighbor links unset. Prepare it so the
53 // dimension check and the neighbor-based watertightness test are reliable.
54 _mesh->prepare_for_use();
55
56 if (!_mesh->is_replicated())
57 mooseError("BoundaryMeshBuilder '",
58 name(),
59 "': the saved surface mesh is distributed. A serialized/replicated surface mesh is "
60 "required for point-containment queries.");
61
62 const auto expected_dim_embedding_mesh = _mesh->mesh_dimension() + 1;
63 if (_dim_embedding_mesh != expected_dim_embedding_mesh)
64 mooseError("BoundaryMeshBuilder '",
65 name(),
66 "': the background mesh dimension (",
68 ") does not match the surface mesh dimension + 1 (",
69 expected_dim_embedding_mesh,
70 ").");
71
73 {
75 mooseInfo("The mesh is watertight. It is suitable for In-Out tests.");
76 else
77 mooseInfo("The mesh is not watertight. It may not be suitable for In-Out tests.");
78 }
79}
80
81void
83{
84 _set = std::make_unique<SurfaceElementSet>(SurfaceElementSet::fromMesh(*_mesh));
85}
86
87bool
89{
90 for (const auto * elem : _mesh->active_element_ptr_range())
91 for (const auto s : make_range(elem->n_sides()))
92 if (!elem->neighbor_ptr(s))
93 return false;
94
95 return true;
96}
97
98MeshBase &
100{
101 mooseAssert(_mesh, "BoundaryMeshBuilder mesh is not available until initialSetup().");
102 return *_mesh;
103}
104
105const SurfaceElementSet &
107{
108 // Build the whole-mesh set on first use so backends that never need it (e.g.
109 // the fixed_x_ray TriangleManifold engine) pay no allocation for it.
110 if (!_set)
112
113 if (!_set)
114 mooseError("BoundaryMeshBuilder '", name(), "': buildDefaultSet() did not initialize _set.");
115 return *_set;
116}
registerMooseObject("MooseApp", BoundaryMeshBuilder)
void mooseInfo(Args &&... args)
Emit an informational message with the given stringified, concatenated args.
Definition MooseError.h:401
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Owns a saved boundary (surface) mesh and the SurfaceElementSet wrapping it.
BoundaryMeshBuilder(const InputParameters &parameters)
static InputParameters validParams()
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
virtual void buildDefaultSet() const
Build the default (whole-mesh) SurfaceElementSet.
MeshBase & mesh() const
The owned boundary mesh.
std::unique_ptr< MeshBase > _mesh
The owned boundary mesh, kept alive so SurfaceElement pointers stay valid.
const unsigned int _dim_embedding_mesh
The dimension of the embedding (background) mesh.
const bool _check_watertightness
Whether to check watertightness of the mesh (informational only).
const SurfaceElementSet & surfaceElementSet() const
The whole-mesh SurfaceElementSet, built lazily on first call.
const std::string _bnd_mesh_name
The name of a mesh saved via a MeshGenerator's save_mesh_as parameter.
std::unique_ptr< SurfaceElementSet > _set
The whole-mesh SurfaceElementSet, lazily cached on first use.
bool checkWatertightness() const
Whether the boundary mesh is "closed" – i.e.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
std::unique_ptr< libMesh::MeshBase > getSavedMesh(const std::string &name)
Get the saved mesh by name.
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
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
A group of surface elements wrapped for point-containment / distance queries.
static SurfaceElementSet fromMesh(const MeshBase &mesh)
Build a set from every active element of a surface mesh.
MeshBase & mesh