| 1 |
"""This program is used to generate the coefficients c00, c01 and c11 |
| 2 |
used in the demo.""" |
| 3 |
|
| 4 |
# Copyright (C) 2007-2009 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-12-16 |
| 22 |
# Last changed: 2009-12-16 |
| 23 |
# Begin demo |
| 24 |
|
| 25 |
from dolfin import * |
| 26 |
|
| 27 |
# Create mesh |
| 28 |
mesh = UnitSquareMesh(32, 32) |
| 29 |
|
| 30 |
# Create mesh functions for c00, c01, c11 |
| 31 |
c00 = MeshFunction("double", mesh, 2) |
| 32 |
c01 = MeshFunction("double", mesh, 2) |
| 33 |
c11 = MeshFunction("double", mesh, 2) |
| 34 |
|
| 35 |
# Iterate over mesh and set values |
| 36 |
for cell in cells(mesh): |
| 37 |
if cell.midpoint().x() < 0.5: |
| 38 |
c00[cell] = 1.0 |
| 39 |
c01[cell] = 0.3 |
| 40 |
c11[cell] = 2.0 |
| 41 |
else: |
| 42 |
c00[cell] = 3.0 |
| 43 |
c01[cell] = 0.5 |
| 44 |
c11[cell] = 4.0 |
| 45 |
|
| 46 |
# Store to file |
| 47 |
mesh_file = File("../unitsquare_32_32.xml.gz") |
| 48 |
c00_file = File("../unitsquare_32_32_c00.xml.gz") |
| 49 |
c01_file = File("../unitsquare_32_32_c01.xml.gz") |
| 50 |
c11_file = File("../unitsquare_32_32_c11.xml.gz") |
| 51 |
|
| 52 |
mesh_file << mesh |
| 53 |
c00_file << c00 |
| 54 |
c01_file << c01 |
| 55 |
c11_file << c11 |
| 56 |
|
| 57 |
# Plot mesh functions |
| 58 |
plot(c00, title="C00", interactive=True) |
| 59 |
plot(c01, title="C01", interactive=True) |
| 60 |
plot(c11, title="C11", interactive=True) |