Polar coordinates in a mesh file

Hello everyone,
I generate a .msh file with the following script

# +
import numpy
import meshio
import gmsh
import pygmsh
resolution = 0.08
R = 1.0
r = 0.25
c = [0.0, 0.0, 0.0]


geometry = pygmsh.geo.Geometry()
model = geometry.__enter__()


circle_r = model.add_circle([0,-0.2,0], r, mesh_size=resolution)
circle_R = model.add_circle(c, R, mesh_size=resolution)


plane_surface = model.add_plane_surface(     circle_R.curve_loop, holes=[circle_r.curve_loop])

model.synchronize()
model.add_physical([plane_surface], "Volume")
model.add_physical(circle_r.curve_loop.curves, "Obstacle")

geometry.generate_mesh(dim=2)
gmsh.write("membrane_m`Preformatted text`esh.msh")
gmsh.clear()
geometry.__exit__()

mesh_from_file = meshio.read("membrane_mesh.msh")
def create_mesh(mesh, cell_type, prune_z=False):
    cells = mesh.get_cells_type(cell_type)
    cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
    points = mesh.points[:, :2] if prune_z else mesh.points
    out_mesh = meshio.Mesh(points=points, cells={cell_type: cells}, cell_data={
                           "name_to_read": [cell_data]})
    return out_mesh

line_mesh = create_mesh(mesh_from_file, "line", prune_z=True)
meshio.write("line_mesh.xdmf", line_mesh)
triangle_mesh = create_mesh(mesh_from_file, "triangle", prune_z=True)
meshio.write("triangle_mesh.xdmf", triangle_mesh)

and then read the mesh in another python script


#create mesh with new method
mesh=Mesh()
with XDMFFile("triangle_mesh.xdmf") as infile:
    infile.read(mesh)
mvc = MeshValueCollection("size_t", mesh, 2)
with XDMFFile("line_mesh.xdmf") as infile:
    infile.read(mvc, "name_to_read")

# Define function spaces
V = VectorFunctionSpace(mesh, 'P', 2)
Q = FunctionSpace(mesh, 'P', 1)

# Define boundaries
inflow   = 'on_boundary && (x[0] < 0.01) && (x[0]*x[0] + x[1]*x[1] > (0.5*0.5))'

This second script appears to automatically assume cartesian coordinates (x[0] = x and x[1] = y) to read the mesh. Is there a way to specify in the second script that x[0], x[1] are polar coordinates (x[0] = r, x[1] = theta) instead?

Thanks

dolfin and dolfinx work in cartesian coordinates. If you want you can create the mesh of a rectangle and then intrepret the x[0] coordinate as r and x[1] as theta, but keep in mind that you have to write the appropriate weak form for the problem (e.g., multiplying by r where appropriate) as it will not be done for you by the library.

1 Like