This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

print coordinate of boundary seperately i.e., left boundary

0 votes

Hi,

I want to print coordinates of the separate boundary such as left, right, top and bottom,

I have tried doing this but this will give all the coordinates on the boundary. Thanks in advance.

from dolfin import *
mesh = UnitSquareMesh(2,2)

It_mesh = vertices(mesh)
for c in It_mesh:
     print (c.point().x())
closed with the note: Got answer
asked Jun 16, 2017 by hirshikesh FEniCS User (1,890 points)
closed Jun 20, 2017 by hirshikesh

1 Answer

0 votes
 
Best answer

Would this work for you:


from dolfin import *
mesh = UnitSquareMesh(2,2)

class Boundary(SubDomain):
        def inside(self, x, on_boundary):
                tol = 1E-14
                return on_boundary and near(x[0], 0, tol)

boundary = Boundary()
ff = FacetFunction('size_t',mesh)
boundary.mark(ff,1)

It_mesh = SubsetIterator(ff, 1)

for c in It_mesh:
     print (c.midpoint().x(), c.midpoint().y())

answered Jun 16, 2017 by meron FEniCS User (2,340 points)
selected Jun 16, 2017 by hirshikesh

it is working but it is giving mid point of the nodes. I need x and y coordinates.

thanks for the help. :)

Ah, right, this iterates over the facets.
So maybe just play around with vertices() now, something like:


for f in It_mesh:
for v in vertices(f):
print v.midpoint().x(), v.midpoint().y()

This will give you overlapping vertices, but that could be fixed

Thanks it really helps

...