| 1 |
# Copyright (C) 2007 Kristian B. Oelgaard |
| 2 |
# |
| 3 |
# This file is part of DOLFIN. |
| 4 |
# |
| 5 |
# DOLFIN is free software: you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU Lesser General Public License as published by |
| 7 |
# the Free Software Foundation, either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# DOLFIN is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU Lesser General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU Lesser General Public License |
| 16 |
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
# |
| 18 |
# Modified by Anders Logg, 2008 |
| 19 |
# Modified by Johan Hake, 2008 |
| 20 |
# Modified by Garth N. Wells, 2009 |
| 21 |
# Modified by Johan Hake, 2013 |
| 22 |
# |
| 23 |
# First added: 2007-11-14 |
| 24 |
# Last changed: 2013-04-05 |
| 25 |
# |
| 26 |
# This demo solves the time-dependent convection-diffusion equation by |
| 27 |
# a SUPG stabilized method. The velocity field used |
| 28 |
# in the simulation is the output from the Stokes (Taylor-Hood) demo. |
| 29 |
# The sub domains for the different boundary conditions are computed |
| 30 |
# by the demo program in src/demo/subdomains. |
| 31 |
# |
| 32 |
# FIXME: Add shock capturing term and then revert back to the Stokes |
| 33 |
# velocity |
| 34 |
# FIXME: This demo showcase experimental features of a RKSolver (time integrator) |
| 35 |
# FIXME: using a MultiStageScheme. It could be removed or changed anytime. |
| 36 |
|
| 37 |
|
| 38 |
from dolfin import * |
| 39 |
|
| 40 |
print("RKSolver is temporarily unavailable") |
| 41 |
exit(0) |
| 42 |
|
| 43 |
# Load mesh and subdomains |
| 44 |
mesh = Mesh("../dolfin_fine.xml.gz") |
| 45 |
sub_domains = MeshFunction("size_t", mesh, "../dolfin_fine_subdomains.xml.gz"); |
| 46 |
h = CellDiameter(mesh) |
| 47 |
|
| 48 |
# Create FunctionSpaces |
| 49 |
Q = FunctionSpace(mesh, "CG", 1) |
| 50 |
V = VectorFunctionSpace(mesh, "CG", 2) |
| 51 |
|
| 52 |
# Create velocity Function from file |
| 53 |
velocity = Function(V); |
| 54 |
File("../dolfin_fine_velocity.xml.gz") >> velocity |
| 55 |
|
| 56 |
# Initialise source function and previous solution function |
| 57 |
f = Constant(0.0) |
| 58 |
u0 = Function(Q) |
| 59 |
|
| 60 |
# Parameters |
| 61 |
T = 5.0 |
| 62 |
dt = 0.1 |
| 63 |
t = Constant(0.0) |
| 64 |
c = 0.00005 |
| 65 |
|
| 66 |
# Test and trial functions |
| 67 |
u, v = Function(Q), TestFunction(Q) |
| 68 |
|
| 69 |
# Residual |
| 70 |
r = dot(velocity, grad(u)) - c*div(grad(u)) - f |
| 71 |
|
| 72 |
# Galerkin variational problem (rhs) |
| 73 |
F = -(v*dot(velocity, grad(u)) + c*dot(grad(v), grad(u)))*dx |
| 74 |
|
| 75 |
# Add SUPG stabilisation terms |
| 76 |
vnorm = sqrt(dot(velocity, velocity)) |
| 77 |
F -= h/(2.0*vnorm)*dot(velocity, grad(v))*r*dx |
| 78 |
|
| 79 |
# Set up boundary condition |
| 80 |
g = Expression("(t<=ramp_stop) ? t : 1.0", t=t, ramp_stop=1.0, degeree=1) |
| 81 |
bc = DirichletBC(Q, g, sub_domains, 1) |
| 82 |
|
| 83 |
# Output file |
| 84 |
out_file = File("results/temperature.pvd") |
| 85 |
|
| 86 |
scheme = BDF1(F, u, t, [bc]) |
| 87 |
solver = RKSolver(scheme) |
| 88 |
|
| 89 |
# Time-stepping |
| 90 |
while float(scheme.t()) < T: |
| 91 |
|
| 92 |
solver.step(dt) |
| 93 |
|
| 94 |
# Plot solution |
| 95 |
plot(u) |
| 96 |
|
| 97 |
# Save the solution to file |
| 98 |
out_file << (u, float(scheme.t())) |