usnistgov / fipy

FiPy is a Finite Volume PDE solver written in Python
http://pages.nist.gov/fipy/en/latest
Other
489 stars 148 forks source link

Could fipy load the .msh file from the gmsh or build a natural river mesh file with Gmsh2D? #975

Closed xrc123456 closed 8 months ago

xrc123456 commented 8 months ago

When I want to load the .msh file which have been build by the gmsh, it will have many issues, like the file have been occupied. When I want to build a natural 2D mesh byu Gmsh2D , the fipy can't build it, but for a rectangle data, it could do. But we want to simulate something in a river , it almost not the regular shape. Hope you can help us to solve this problem, Thanks...

# Define the characteristic length
lc = 0.2  # Adjust this value as needed for your mesh

data_points = [
    (1, 2),
    (1, 3),
    (2, 2.5),
    (2, 3.5),
    (3, 1.5),
    (3, 2.5)
]

point_str = ""
line_str = ""

for i, point in enumerate(data_points):
    # Include lc in each point definition
    point_str += "Point(%d) = {%f, %f, 0, %f};\n" % (i+1, point[0], point[1], lc)

    if i > 0:
        line_str += "Line(%d) = {%d, %d};\n" % (i, i, i+1)

# Closing the loop
line_str += "Line(%d) = {%d, 1};\n" % (len(data_points), len(data_points))

# Creating a loop and a surface
loop_str = "Line Loop(%d) = {%s};\n" % (len(data_points)+1, ", ".join([str(i) for i in range(1, len(data_points)+1)]))
surface_str = "Plane Surface(%d) = {%d};\n" % (len(data_points)+2, len(data_points)+1)

# Complete Gmsh script
gmsh_script = point_str + line_str + loop_str + surface_str

# Creating mesh in FiPy
from fipy import Gmsh2D

mesh = Gmsh2D(gmsh_script)

# Visualization
from fipy import Viewer

viewer = Viewer(mesh)
viewer.plot()
guyer commented 8 months ago

The boundary you have defined crosses itself. That's not valid in Gmsh. This is not a FiPy issue.

image