Skip to content

Commit

Permalink
Merge pull request #422 from yungyuc/multidim-rectangle-2dmesh
Browse files Browse the repository at this point in the history
Add 2D unstructured mesh of triangle elements in a rectangle
  • Loading branch information
yungyuc authored Sep 8, 2024
2 parents 69a768b + 2ae66b0 commit 9c4e122
Show file tree
Hide file tree
Showing 5 changed files with 458 additions and 12 deletions.
4 changes: 4 additions & 0 deletions cpp/modmesh/view/RManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ void RManager::setUpMenu()
QString("Sample: mesh of \"solvcon\" text in 2D"),
QString("Create a sample mesh drawing a text string of \"solvcon\""),
QString("modmesh.gui.sample_mesh.mesh_solvcon_2dtext")));
m_meshMenu->addAction(new RPythonAction(
QString("Sample: 2D mesh in a rectangle"),
QString("Triangular mesh in a rectangle"),
QString("modmesh.gui.sample_mesh.mesh_rectangle")));
m_meshMenu->addAction(new RPythonAction(
QString("Sample: 3D mesh of mixed elements"),
QString("Create a very simple sample mesh of mixed elements in 3D"),
Expand Down
24 changes: 24 additions & 0 deletions modmesh/gui/sample_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
Show example meshes.
"""

import os

import modmesh as mm
from .. import core
from .. import view

Expand Down Expand Up @@ -201,4 +204,25 @@ def mesh_3dmix():
w_3dmix.showMark()
view.mgr.pycon.writeToHistory(f"3dmix nedge: {mh.nedge}\n")


def mesh_rectangle():
fn = os.path.join(os.path.dirname(mm.__file__), '..')
fn = os.path.abspath(fn)
fn = os.path.join(fn, "tests", "data", "rectangle.msh")
if not os.path.exists(fn):
view.mgr.pycon.writeToHistory(f"{fn} does not exist\n")
return

with open(fn, 'rb') as fobj:
data = fobj.read()
view.mgr.pycon.writeToHistory(f"gmsh mesh file {fn} is read\n")
gmsh = mm.Gmsh(data)
mh = gmsh.to_block()
view.mgr.pycon.writeToHistory("StaticMesh object created from gmsh\n")
# Open a sub window for triangles and quadrilaterals:
w = view.mgr.add3DWidget()
w.updateMesh(mh)
w.showMark()
view.mgr.pycon.writeToHistory(f"nedge: {mh.nedge}\n")

# vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:
27 changes: 27 additions & 0 deletions tests/data/rectangle.geo
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* A Gmsh template file for a rectangle domain.
*/
lc = 0.25;
// vertices.
Point(1) = {0,0,0,lc};
Point(2) = {4,0,0,lc};
Point(3) = {4,1,0,lc};
Point(4) = {0,1,0,lc};
// lines.
Line(1) = {1,2};
Line(2) = {2,3};
Line(3) = {3,4};
Line(4) = {4,1};
// surface.
Line Loop(1) = {1,2,3,4};
Plane Surface(1) = {1};
// physics.
Physical Line("lower") = {1};
Physical Line("right") = {2};
Physical Line("upper") = {3};
Physical Line("left") = {4};
Physical Surface("domain") = {1};
// mesh
Mesh.MshFileVersion = 2.2;
Mesh.ALgorithm = 6; // Frontal-Delaunay for 2D mesh.
Mesh 2;
Loading

0 comments on commit 9c4e122

Please sign in to comment.