OGS
anonymous_namespace{generateStructuredMesh.cpp} Namespace Reference

Classes

struct  BoundarySide

Functions

void extract1DBoundaryMeshes (MeshLib::Mesh const &mesh, MathLib::Point3d const &origin, std::vector< double > const &length, std::string const &base)
void extract2D3DBoundaryMeshes (MeshLib::Mesh const &mesh, unsigned dim, MathLib::Point3d const &origin, std::vector< double > const &length, std::string const &base)

Function Documentation

◆ extract1DBoundaryMeshes()

void anonymous_namespace{generateStructuredMesh.cpp}::extract1DBoundaryMeshes ( MeshLib::Mesh const & mesh,
MathLib::Point3d const & origin,
std::vector< double > const & length,
std::string const & base )

Extract and write 1D boundary point meshes (left and right endpoints).

Parameters
meshThe 1D line mesh
originThe mesh origin point
lengthThe domain lengths
baseThe base filename (without extension) for output

Definition at line 48 of file generateStructuredMesh.cpp.

52{
53 auto const eps = std::numeric_limits<double>::epsilon() *
54 *std::max_element(length.begin(), length.end()) * 100;
55
56 std::array<BoundarySide, 2> const sides{
57 {{"left", 0, origin[0]}, {"right", 0, origin[0] + length[0]}}};
58
59 auto const& nodes = mesh.getNodes();
60 for (auto const& side : sides)
61 {
62 auto const it =
63 ranges::find_if(nodes, [&](auto const* n)
64 { return std::abs((*n)[0] - side.value) <= eps; });
65
66 if (it == nodes.end())
67 {
68 continue;
69 }
70
71 auto* node = *it;
72 auto* new_node = new MeshLib::Node(*node);
73 std::vector<MeshLib::Node*> side_nodes{new_node};
74 std::vector<MeshLib::Element*> side_elements{
75 new MeshLib::Point({new_node})};
76
77 MeshLib::Mesh side_mesh(side.name, side_nodes, side_elements);
78
79 std::array<std::size_t, 1> const bulk_node_id{node->getID()};
82 MeshLib::MeshItemType::Node, 1, std::span{bulk_node_id});
83
85 side_mesh,
86 std::filesystem::path(base + "_" + side.name + ".vtu")) != 0)
87 {
88 ERR("Could not write boundary mesh '{:s}'.", side.name);
89 continue;
90 }
91 INFO("Boundary mesh '{}' written.", side.name);
92 }
93}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > output_variable_names, bool const use_compression, int const data_mode)
void addPropertyToMesh(Mesh &mesh, std::string_view name, MeshItemType item_type, std::size_t number_of_components, std::span< T const > values)
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
TemplateElement< PointRule1 > Point

References MeshLib::addPropertyToMesh(), ERR(), MeshLib::getBulkIDString(), MeshLib::Mesh::getNodes(), INFO(), MeshLib::Node, and MeshLib::IO::writeMeshToFile().

Referenced by main().

◆ extract2D3DBoundaryMeshes()

void anonymous_namespace{generateStructuredMesh.cpp}::extract2D3DBoundaryMeshes ( MeshLib::Mesh const & mesh,
unsigned dim,
MathLib::Point3d const & origin,
std::vector< double > const & length,
std::string const & base )

Extract and write 2D/3D boundary meshes (left, right, bottom, top, and optionally front, back).

Parameters
meshThe 2D or 3D mesh
dimThe mesh dimension (2 or 3)
originThe mesh origin point
lengthThe domain lengths
baseThe base filename (without extension) for output

Definition at line 102 of file generateStructuredMesh.cpp.

107{
108 auto const eps = std::numeric_limits<double>::epsilon() *
109 *std::max_element(length.begin(), length.end()) * 100;
110
111 auto boundary_mesh =
116
117 std::vector<BoundarySide> sides{{"left", 0, origin[0]},
118 {"right", 0, origin[0] + length[0]},
119 {"bottom", 1, origin[1]},
120 {"top", 1, origin[1] + length[1]}};
121
122 if (dim == 3)
123 {
124 sides.push_back({"front", 2, origin[2]});
125 sides.push_back({"back", 2, origin[2] + length[2]});
126 }
127
128 for (auto const& side : sides)
129 {
130 auto const node_on_side = [&](auto const node_id)
131 {
132 auto const* node = boundary_mesh->getNode(node_id);
133 return std::abs((*node)[side.axis] - side.value) <= eps;
134 };
135 auto const element_not_on_side = [&](auto const* elem)
136 {
137 return !ranges::all_of(elem->nodes() | MeshLib::views::ids,
138 node_on_side);
139 };
140 auto const remove_ids = boundary_mesh->getElements() |
141 ranges::views::filter(element_not_on_side) |
142 MeshLib::views::ids | ranges::to<std::vector>;
143
144 std::unique_ptr<MeshLib::Mesh> side_mesh(MeshToolsLib::removeElements(
145 *boundary_mesh, remove_ids, side.name));
146
147 if (side_mesh && side_mesh->getNumberOfElements() > 0)
148 {
150 *side_mesh,
151 std::filesystem::path(base + "_" + side.name + ".vtu")) !=
152 0)
153 {
154 ERR("Could not write boundary mesh '{:s}'.", side.name);
155 continue;
156 }
157 INFO("Boundary mesh '{}' written: {:d} nodes, {:d} elements.",
158 side.name, side_mesh->getNumberOfNodes(),
159 side_mesh->getNumberOfElements());
160 }
161 }
162}
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition Mesh.h:218
std::unique_ptr< MeshLib::Mesh > getBoundaryElementsAsMesh(MeshLib::Mesh const &bulk_mesh, std::string_view subsfc_node_id_prop_name, std::string_view subsfc_element_id_prop_name, std::string_view face_id_prop_name)
MeshLib::Mesh * removeElements(const MeshLib::Mesh &mesh, const std::vector< std::size_t > &removed_element_ids, const std::string &new_mesh_name)

References MeshLib::Cell, ERR(), MeshLib::Face, MeshToolsLib::BoundaryExtraction::getBoundaryElementsAsMesh(), MeshLib::getBulkIDString(), MeshLib::views::ids, INFO(), MeshLib::Node, MeshToolsLib::removeElements(), and MeshLib::IO::writeMeshToFile().

Referenced by main().