| 1 |
"""This demo program demonstrates how to extract matching sub meshes |
| 2 |
from a common mesh.""" |
| 3 |
|
| 4 |
# Copyright (C) 2009, 2015 Anders Logg |
| 5 |
# |
| 6 |
# This file is part of DOLFIN. |
| 7 |
# |
| 8 |
# DOLFIN is free software: you can redistribute it and/or modify |
| 9 |
# it under the terms of the GNU Lesser General Public License as published by |
| 10 |
# the Free Software Foundation, either version 3 of the License, or |
| 11 |
# (at your option) any later version. |
| 12 |
# |
| 13 |
# DOLFIN is distributed in the hope that it will be useful, |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU Lesser General Public License for more details. |
| 17 |
# |
| 18 |
# You should have received a copy of the GNU Lesser General Public License |
| 19 |
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
# |
| 21 |
# First added: 2009-02-11 |
| 22 |
# Last changed: 2015-06-15 |
| 23 |
|
| 24 |
|
| 25 |
from dolfin import * |
| 26 |
import matplotlib.pyplot as plt |
| 27 |
|
| 28 |
# Structure sub domain |
| 29 |
class Structure(SubDomain): |
| 30 |
def inside(self, x, on_boundary): |
| 31 |
return x[0] > 1.4 - DOLFIN_EPS and x[0] < 1.6 \ |
| 32 |
+ DOLFIN_EPS and x[1] < 0.6 + DOLFIN_EPS |
| 33 |
|
| 34 |
# Create mesh |
| 35 |
mesh = RectangleMesh(Point(0.0, 0.0), Point(3.0, 1.0), 60, 20) |
| 36 |
|
| 37 |
# Create sub domain markers and mark everaything as 0 |
| 38 |
sub_domains = MeshFunction("size_t", mesh, mesh.topology().dim()) |
| 39 |
sub_domains.set_all(0) |
| 40 |
|
| 41 |
# Mark structure domain as 1 |
| 42 |
structure = Structure() |
| 43 |
structure.mark(sub_domains, 1) |
| 44 |
|
| 45 |
# Extract sub meshes |
| 46 |
fluid_mesh = SubMesh(mesh, sub_domains, 0) |
| 47 |
structure_mesh = SubMesh(mesh, sub_domains, 1) |
| 48 |
|
| 49 |
# Move structure mesh |
| 50 |
for x in structure_mesh.coordinates(): |
| 51 |
x[0] += 0.1*x[0]*x[1] |
| 52 |
|
| 53 |
# Move fluid mesh according to structure mesh |
| 54 |
ALE.move(fluid_mesh, structure_mesh) |
| 55 |
fluid_mesh.smooth() |
| 56 |
|
| 57 |
# Plot meshes |
| 58 |
plt.figure() |
| 59 |
plot(fluid_mesh, title="Fluid") |
| 60 |
plt.figure() |
| 61 |
plot(structure_mesh, title="Structure") |
| 62 |
plt.show() |
| 63 |
|
| 64 |
# Build mapping from structure to fluid mesh |
| 65 |
structure_to_fluid = compute_vertex_map(structure_mesh, fluid_mesh) |
| 66 |
print(structure_to_fluid) |