# Copyright (C) 2010 Kristian B. Oelgaard # # 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 . # # The bilinear form a(u, v) and linear form L(v) for # Poisson's equation where spatial coordinates are used to define the source # term. However, the source term is only active in a part of the domain and # a Conditional is used to handle this. # # Compile this form with FFC: ffc -l dolfin Conditional.ufl from ufl_legacy import (dx, FiniteElement, conditional, ge, le, SpatialCoordinate, grad, inner, triangle, TestFunction, TrialFunction) element = FiniteElement("Lagrange", triangle, 2) u = TrialFunction(element) v = TestFunction(element) x = SpatialCoordinate(triangle) c0 = conditional(le( (x[0]-0.33)**2 + (x[1]-0.67)**2, 0.015), -1.0, 5.0) c = conditional( le( (x[0]-0.33)**2 + (x[1]-0.67)**2, 0.025), c0, 0.0 ) t0 = conditional(ge( x[0], 0.55), -1.0, 0.0) t1 = conditional(le( x[0], 0.95), t0, 0.0) t2 = conditional(ge( x[1], 0.05), t1, 0.0) t3 = conditional(le( x[1], 0.45), t2, 0.0) t = conditional(ge( x[1] - x[0] - 0.05 + 0.55, 0.0), t3, 0.0) f = c + t a = inner(grad(u), grad(v))*dx L = f*v*dx