| 1 |
# Copyright (C) 2014-2015 Anders Logg |
| 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: 2014-06-10 |
| 19 |
# Last changed: 2015-11-17 |
| 20 |
# |
| 21 |
# The bilinear form a(u, v) and linear form L(v) for a multimesh |
| 22 |
# formulation of the Stokes equations. |
| 23 |
# |
| 24 |
# Compile this form with FFC: ffc -l dolfin MultiMeshStokes.ufl. |
| 25 |
|
| 26 |
from ufl_legacy import (Circumradius, Coefficient, dC, dI, dO, dX, FiniteElement, VectorElement, |
| 27 |
avg, div, FacetNormal, inner, grad, jump, outer, |
| 28 |
triangle, TestFunctions, TrialFunctions) |
| 29 |
|
| 30 |
|
| 31 |
# Define element |
| 32 |
P2 = VectorElement("Lagrange", triangle, 2) |
| 33 |
P1 = FiniteElement("Lagrange", triangle, 1) |
| 34 |
TH = P2 * P1 |
| 35 |
|
| 36 |
# Define trial and test functions and right-hand side |
| 37 |
(u, p) = TrialFunctions(TH) |
| 38 |
(v, q) = TestFunctions(TH) |
| 39 |
f = Coefficient(P2) |
| 40 |
|
| 41 |
# Define facet normal and mesh size |
| 42 |
n = FacetNormal(triangle) |
| 43 |
h = 2.0*Circumradius(triangle) |
| 44 |
|
| 45 |
# Parameters |
| 46 |
alpha = 20.0 |
| 47 |
beta = 5 |
| 48 |
|
| 49 |
def tensor_jump(v, n): |
| 50 |
return outer(v('+'), n('+')) + outer(v('-'), n('-')) |
| 51 |
|
| 52 |
def a_h(v, w): |
| 53 |
return inner(grad(v), grad(w))*dX \ |
| 54 |
- inner(avg(grad(v)), tensor_jump(w, n))*dI \ |
| 55 |
- inner(avg(grad(w)), tensor_jump(v, n))*dI \ |
| 56 |
+ alpha/avg(h) * inner(jump(v), jump(w))*dI |
| 57 |
|
| 58 |
def b_h(v, q): |
| 59 |
return -div(v)*q*dX + jump(v, n)*avg(q)*dI |
| 60 |
|
| 61 |
def l_h(v, q, f): |
| 62 |
return inner(f, v)*dX |
| 63 |
|
| 64 |
def s_O(v, q, w, r): |
| 65 |
return (beta/avg(h)**2) * inner(jump(v), jump(w))*dO \ |
| 66 |
+ beta * inner(jump(q), jump(r))*dO |
| 67 |
|
| 68 |
def s_C(v, q, w, r): |
| 69 |
return h*h*inner(-div(grad(v)) + grad(q), -div(grad(w)) - grad(r))*dC |
| 70 |
|
| 71 |
def l_C(v, q, f): |
| 72 |
return h*h*inner(f, -div(grad(v)) - grad(q))*dC |
| 73 |
|
| 74 |
# Define bilinear form |
| 75 |
a = a_h(u, v) + b_h(v, p) + b_h(u, q) + s_O(u, p, v, q) + s_C(u, p, v, q) |
| 76 |
|
| 77 |
# Define linear form |
| 78 |
L = l_h(v, q, f) + l_C(v, q, f) |