# Copyright (C) 2007 Kristian B. Oelgaard and Garth N. Wells # # This file is part of DOLFIN. # # DOLFIN is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # DOLFIN is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with DOLFIN. If not, see . # # First added: 2007-06-29 # Last changed: 2011-03-09 # # The bilinear form a(phi, v) and linear form L(v) for # advection-diffusion. Discontinuous formulation with upwinding. from ufl_legacy import (Coefficient, dS, ds, dx, FiniteElement, VectorElement, avg, CellDiameter, dot, FacetNormal, grad, jump, triangle, TestFunction, TrialFunction) cell = triangle scalar = FiniteElement("Discontinuous Lagrange", cell, 1) vector = VectorElement("Lagrange", cell, 2) constant = FiniteElement("Discontinuous Lagrange", cell, 0) R = FiniteElement("Real", cell, 0) # Trial and test functions phi = TrialFunction(scalar) v = TestFunction(scalar) u = Coefficient(vector) f = Coefficient(scalar) h = CellDiameter(cell) h_avg = (h('+') + h('-'))/2 n = FacetNormal(cell) kappa = Coefficient(R) alpha = Coefficient(R) # ( dot(v, n) + |dot(v, n)| )/2.0 un = (dot(u, n) + abs(dot(u, n)))/2.0 # Bilinear form a_int = dot(kappa*grad(phi) - u*phi, grad(v))*dx a_fac = (kappa*(alpha/h_avg)*dot(jump(phi, n), jump(v, n))*dS - kappa*dot(jump(phi, n), avg(grad(v)))*dS - kappa*dot(avg(grad(phi)), jump(v, n))*dS) a_vel = (dot(un('+')*phi('+') - un('-')*phi('-'), jump(v))*dS + dot(un*phi, v)*ds) a = a_int + a_fac + a_vel # Linear form L = v*f*dx