| 1 |
# Copyright (C) 2007 Kristian B. Oelgaard and Garth N. Wells |
| 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 |
# First added: 2007-06-29 |
| 19 |
# Last changed: 2011-03-09 |
| 20 |
# |
| 21 |
# The bilinear form a(phi, v) and linear form L(v) for |
| 22 |
# advection-diffusion. Discontinuous formulation with upwinding. |
| 23 |
|
| 24 |
from ufl_legacy import (Coefficient, dS, ds, dx, FiniteElement, VectorElement, |
| 25 |
avg, CellDiameter, dot, FacetNormal, grad, jump, |
| 26 |
triangle, TestFunction, TrialFunction) |
| 27 |
|
| 28 |
cell = triangle |
| 29 |
scalar = FiniteElement("Discontinuous Lagrange", cell, 1) |
| 30 |
vector = VectorElement("Lagrange", cell, 2) |
| 31 |
constant = FiniteElement("Discontinuous Lagrange", cell, 0) |
| 32 |
R = FiniteElement("Real", cell, 0) |
| 33 |
|
| 34 |
# Trial and test functions |
| 35 |
phi = TrialFunction(scalar) |
| 36 |
v = TestFunction(scalar) |
| 37 |
|
| 38 |
u = Coefficient(vector) |
| 39 |
f = Coefficient(scalar) |
| 40 |
h = CellDiameter(cell) |
| 41 |
h_avg = (h('+') + h('-'))/2 |
| 42 |
n = FacetNormal(cell) |
| 43 |
|
| 44 |
kappa = Coefficient(R) |
| 45 |
alpha = Coefficient(R) |
| 46 |
|
| 47 |
# ( dot(v, n) + |dot(v, n)| )/2.0 |
| 48 |
un = (dot(u, n) + abs(dot(u, n)))/2.0 |
| 49 |
|
| 50 |
# Bilinear form |
| 51 |
a_int = dot(kappa*grad(phi) - u*phi, grad(v))*dx |
| 52 |
|
| 53 |
a_fac = (kappa*(alpha/h_avg)*dot(jump(phi, n), jump(v, n))*dS |
| 54 |
- kappa*dot(jump(phi, n), avg(grad(v)))*dS |
| 55 |
- kappa*dot(avg(grad(phi)), jump(v, n))*dS) |
| 56 |
|
| 57 |
a_vel = (dot(un('+')*phi('+') - un('-')*phi('-'), jump(v))*dS |
| 58 |
+ dot(un*phi, v)*ds) |
| 59 |
|
| 60 |
a = a_int + a_fac + a_vel |
| 61 |
|
| 62 |
# Linear form |
| 63 |
L = v*f*dx |