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

Which vertices in your dolfin_fine.xml database apply directly to the shape of the dolfin?

0 votes

I have downloaded the mesh, and generated the dolfin using your database. Now I want to move the dolfin inside the mesh using my own code, but I need to know which vertices are used to make up the shape of the dolfin, so I know when points inside the mesh I should move using my code.

Also, do you have any other 2D triangular generated meshes with an inner deformation that I may apply my moving method too?

Thanks for any help in this regard.

asked Mar 13, 2015 by JOFE FEniCS Novice (120 points)

2 Answers

0 votes

Just take a look at the .xml file. Obviously, the nodes that make up the boundary of the outer rectangle are those where either x or y is 0 or 1. Thus, you can get the dolfin by

dolfin = whole boundary - rectangle boundary

Once you have the dolfin as a SubDomain, you can get the vertices by marking a MeshFunction of dimension 0.

answered Mar 13, 2015 by Gregor Mitscha-Baude FEniCS User (2,280 points)

This will just give me ALL the nodes inside the rectangle boundary. However, not every node inside is use to make up the shape of the dolfin (i.e. the point (0.2, 0.2) roughly is clearly a node inside, but is not apart of the design for the dolfin)

There are roughly 2800 nodes inside, based on the database I have found some of the ones I need, but the others are mixed up with the others that I do not need. So when I try to "move" the dolfin inside, only parts of the image is moving, which is distorting the shape which I do not want.

Errrr wait, I just read your last part.....will try it and see how it goes

0 votes

Hi, consider

from dolfin import *

mesh = Mesh('dolfin_fine.xml.gz')
# We will be getting vertices from facets that are on the boundary of domain
facet_f = FacetFunction('size_t', mesh, 0)

# Mark all facets on the boundary as 1
DomainBoundary().mark(facet_f, 1)

on_outer_boundary = lambda x: near(x[0]*(1-x[0]), 0) or near(x[1]*(1-x[1]), 0)
# Mark facets on the boundary of the square as 2
AutoSubDomain(lambda x, on_boundary:\
              on_boundary and on_outer_boundary(x)).mark(facet_f, 2)

# Get the vertices connected to facets marked with 2
mesh.init(1, 0)
dolfin_vertices = set(sum((facet.entities(0).tolist()
                           for facet in SubsetIterator(facet_f, 2)), []))

# Check
vertex_x = mesh.coordinates().reshape((-1, 2))
assert all(on_outer_boundary(vertex_x[vertex]) for vertex in dolfin_vertices) 

As far as other meshes are concerned, you can create them by yourself with mshr. Here's a 'funny' example

from dolfin import Point, plot, interactive
from mshr import *

domain = Circle(Point(0, 0), 1) - Circle(Point(0.5, 0.5), 0.2)\
                                - Circle(Point(-0.5, 0.5), 0.2)\
                                - Circle(Point(0, -0.5), 0.35)\
                                - Rectangle(Point(-0.125, -0.125), Point(0.125, 0.5))

mesh = generate_mesh(domain, 50)

plot(mesh, title='What!')
interactive() 
answered Mar 13, 2015 by MiroK FEniCS Expert (80,920 points)
...