Last active
January 12, 2023 00:18
-
-
Save danshapero/a140daaf951ba58c48285ec29f5973cc to your computer and use it in GitHub Desktop.
Test for reading 2nd-order gmsh meshes into PETSc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
from petsc4py import PETSc | |
geo_text = """ | |
Point(1) = {0, 0, 0, 1.0}; | |
Point(2) = {-0.5, -0, 0, 1.0}; | |
Point(3) = {0, -0.5, 0, 1.0}; | |
Point(4) = {0, 0.5, 0, 1.0}; | |
Point(5) = {0.5, -0, 0, 1.0}; | |
Characteristic Length { 1,2,3,4,5 } = 0.25; | |
Circle(1) = {2, 1, 3}; | |
Circle(2) = {3, 1, 5}; | |
Circle(3) = {5, 1, 4}; | |
Circle(4) = {4, 1, 2}; | |
Line Loop(5) = {4, 1, 2, 3}; | |
Plane Surface(6) = {5}; | |
Physical Surface("MyDisk") = {6}; | |
Physical Line("Bdry") = {4, 1, 2, 3}; | |
""" | |
with open("disc.geo", "w") as geo_file: | |
geo_file.write(geo_text) | |
command = "gmsh -2 -order 2 -v 0 -o disc.msh disc.geo" | |
subprocess.run(command.split()) | |
viewer = PETSc.Viewer().create() | |
viewer.setType("ascii") | |
viewer.setFileMode("r") | |
viewer.setFileName("disc.msh") | |
plex = PETSc.DMPlex().createGmsh(viewer) | |
dm = plex.getCoordinateDM() | |
section = dm.getSection() | |
print(f"Depth strata: {[plex.getDepthStratum(k) for k in [0, 1, 2]]}\n") | |
section.view() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment