feat(meshGeneration): added mesh generation scripts and three res of spherical mesh
This commit is contained in:
BIN
assets/dynamic/mesh/core.msh
Normal file
BIN
assets/dynamic/mesh/core.msh
Normal file
Binary file not shown.
BIN
assets/dynamic/mesh/core_hires.msh
Normal file
BIN
assets/dynamic/mesh/core_hires.msh
Normal file
Binary file not shown.
BIN
assets/dynamic/mesh/core_lowres.msh
Normal file
BIN
assets/dynamic/mesh/core_lowres.msh
Normal file
Binary file not shown.
BIN
assets/dynamic/mesh/core_midres.msh
Normal file
BIN
assets/dynamic/mesh/core_midres.msh
Normal file
Binary file not shown.
Binary file not shown.
@@ -1,15 +1,25 @@
|
||||
import pygmsh
|
||||
import meshio
|
||||
import numpy as np
|
||||
from math import sqrt
|
||||
|
||||
import argparse
|
||||
|
||||
def generate_spherical_mesh(radius=1, meshSize=0.1):
|
||||
with pygmsh.geo.Geometry() as geo:
|
||||
# Create a spherical (ball) geometry centered at (0,0,0)
|
||||
sphere = geo.add_ball([0, 0, 0], radius)
|
||||
# Generate a 2D mesh (i.e. surface mesh) of the sphere
|
||||
myMesh = geo.generate_mesh(dim=3)
|
||||
return myMesh
|
||||
def mesh_size_callback(dim, tag, x, y, z, lc, a, b, k):
|
||||
r = np.sqrt(x**2 + y**2 + z**2)
|
||||
size = a + (b-a) * (1-np.exp(-k*r))
|
||||
return size
|
||||
|
||||
def generate_spherical_mesh(radius=1.0, coreRes = 0.1, outRes = 0.1, k = 2):
|
||||
with pygmsh.occ.Geometry() as geom:
|
||||
originPoint = geom.add_point([0.0, 0.0, 0.0], mesh_size=coreRes)
|
||||
geom.add_ball([0.0, 0.0, 0.0], 1.0)
|
||||
|
||||
geom.set_mesh_size_callback(lambda dim, tag, x, y, z, lc: mesh_size_callback(dim, tag, x, y, z, lc, coreRes, outRes, k))
|
||||
mesh = geom.generate_mesh(verbose=True)
|
||||
|
||||
return mesh
|
||||
|
||||
|
||||
def write_mfem_mesh(meshData, filename):
|
||||
meshio.write(filename, meshData, file_format='gmsh22')
|
||||
@@ -17,8 +27,11 @@ def write_mfem_mesh(meshData, filename):
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='Generate a spherical mesh')
|
||||
parser.add_argument('--radius', type=float, default=1.0, help='Radius of the sphere')
|
||||
parser.add_argument('--meshSize', type=float, default=0.1, help='Mesh size')
|
||||
parser.add_argument('--coreMeshRes', type=float, default=0.01, help='Core Mesh Resolution')
|
||||
parser.add_argument('--outerMeshRes', type=float, default=0.1, help='Outer Mesh Resolution')
|
||||
parser.add_argument('--k', type=float, default=2, help='Mesh size scaling factor')
|
||||
parser.add_argument('--output', type=str, default='sphere.msh', help='Output file name')
|
||||
args = parser.parse_args()
|
||||
|
||||
meshData = generate_spherical_mesh(args.radius, args.meshSize)
|
||||
write_mfem_mesh(meshData, 'sphere.msh')
|
||||
meshData = generate_spherical_mesh(args.radius, args.coreMeshRes, args.outerMeshRes, args.k)
|
||||
write_mfem_mesh(meshData, args.output)
|
||||
|
||||
Reference in New Issue
Block a user