demo_submesh.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. """Extract matchingsub meshes from a common mesh"""
  2. from dolfin import *
  3. class Structure(SubDomain):
  4. def inside(self, x, on_boundary):
  5. return x[0] > 1.4 - DOLFIN_EPS and x[0] < 1.6 \
  6. + DOLFIN_EPS and x[1] < 0.6 + DOLFIN_EPS
  7. mesh = RectangleMesh(Point(0.0, 0.0), Point(3.0, 1.0), 60, 20)
  8. # Create sub domain markers and mark everaything as 0
  9. sub_domains = MeshFunction("size_t", mesh, mesh.topology().dim())
  10. sub_domains.set_all(0)
  11. # Mark structure domain as 1
  12. structure = Structure()
  13. structure.mark(sub_domains, 1)
  14. # Extract sub meshes
  15. fluid_mesh = SubMesh(mesh, sub_domains, 0)
  16. structure_mesh = SubMesh(mesh, sub_domains, 1)
  17. # Move structure mesh
  18. for x in structure_mesh.coordinates():
  19. x[0] += 0.2*x[0]*x[1]
  20. # Move fluid mesh according to structure mesh
  21. ALE.move(fluid_mesh, structure_mesh)
  22. fluid_mesh.smooth()
  23. #############################################
  24. from vedo.dolfin import plot
  25. plot(fluid_mesh, text=__doc__, interactive=False)
  26. plot(structure_mesh, c='tomato', add=True)
  27. plot()