PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
openBoundaryWalls2D.cpp
Go to the documentation of this file.
1/*
2 * -------------------------------------------
3 * Copyright (c) 2021 - 2026 Prashant K. Jha
4 * -------------------------------------------
5 * PeriDEM https://github.com/prashjha/PeriDEM
6 *
7 * Distributed under the Boost Software License, Version 1.0.
8 */
9
10#include "openBoundaryWalls2D.h"
11#include <algorithm>
12#include <cmath>
13#include <gmsh.h>
14#include <vector>
15
16namespace mesh_gen {
17
18void physicalGroupsWallOpenFromY2D(int surfaceTag, double yOpen, double tol,
19 const std::string &physWall,
20 const std::string &physOpen) {
21
22 std::vector<std::pair<int, int>> bnd;
23 gmsh::model::getBoundary({{2, surfaceTag}}, bnd, false);
24
25 std::vector<int> wallTags;
26 std::vector<int> openTags;
27 wallTags.reserve(bnd.size());
28 openTags.reserve(bnd.size());
29
30 const double horizEps = std::max(tol * 1.0e-3, 1.0e-12 * (1.0 + std::abs(yOpen)));
31
32 for (const auto &pr : bnd) {
33 if (pr.first != 1)
34 continue;
35 double xmin = 0., ymin = 0., zmin = 0., xmax = 0., ymax = 0., zmax = 0.;
36 gmsh::model::getBoundingBox(pr.first, pr.second, xmin, ymin, zmin, xmax, ymax, zmax);
37 const double dy = ymax - ymin;
38 const double yc = 0.5 * (ymin + ymax);
39 const bool nearlyHorizontal = dy < horizEps;
40 const bool nearTopOpen = yc >= yOpen - tol && nearlyHorizontal;
41 if (nearTopOpen)
42 openTags.push_back(pr.second);
43 else
44 wallTags.push_back(pr.second);
45 }
46
47 if (!wallTags.empty()) {
48 const int g = gmsh::model::addPhysicalGroup(1, wallTags, -1);
49 gmsh::model::setPhysicalName(1, g, physWall);
50 }
51 if (!openTags.empty()) {
52 const int g = gmsh::model::addPhysicalGroup(1, openTags, -1);
53 gmsh::model::setPhysicalName(1, g, physOpen);
54 }
55}
56
57} // namespace mesh_gen
void physicalGroupsWallOpenFromY2D(int surfaceTag, double yOpen, double tol, const std::string &physWall, const std::string &physOpen)