def HodgeLaplaceGradCurl(element, felement): tau, v = TestFunctions(element) sigma, u = TrialFunctions(element) f = Coefficient(felement) a = (inner(tau, sigma) - inner(grad(tau), u) + inner(v, grad(sigma)) + inner(curl(v), curl(u))) * dx L = inner(v, f) * dx return a, L
# 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 UFL. If not, see <http://www.gnu.org/licenses/>. # # Modified by Martin Sandve Alnes, 2009 # # Last changed: 2009-01-12 # # The bilinear form a(v, u) and linear form L(v) for # a mixed formulation of Poisson's equation with BDM # (Brezzi-Douglas-Marini) elements. # from ufl import (Coefficient, FiniteElement, TestFunctions, TrialFunctions, div, dot, dx, triangle) cell = triangle BDM1 = FiniteElement("Brezzi-Douglas-Marini", cell, 1) DG0 = FiniteElement("Discontinuous Lagrange", cell, 0) element = BDM1 * DG0 (tau, w) = TestFunctions(element) (sigma, u) = TrialFunctions(element) f = Coefficient(DG0) a = (dot(tau, sigma) - div(tau) * u + w * div(sigma)) * dx L = w * f * dx
""" from ufl import (FiniteElement, TestFunction, TestFunctions, TrialFunction, TrialFunctions, dx) from ufl import exterior_derivative as d from ufl import inner, interval, tetrahedron, triangle cells = [interval, triangle, tetrahedron] r = 1 for cell in cells: for family in ["P Lambda", "P- Lambda"]: tdim = cell.topological_dimension() for k in range(0, tdim + 1): # Testing exterior derivative V = FiniteElement(family, cell, r, form_degree=k) v = TestFunction(V) u = TrialFunction(V) a = inner(d(u), d(v)) * dx # Testing mixed formulation of Hodge Laplace if k > 0 and k < tdim + 1: S = FiniteElement(family, cell, r, form_degree=k - 1) W = S * V (sigma, u) = TrialFunctions(W) (tau, v) = TestFunctions(W) a = (inner(sigma, tau) - inner(d(tau), u) + inner(d(sigma), v) + inner(d(u), d(v))) * dx
# # Author: Marie Rognes # Modified by: Martin Sandve Alnes # Date: 2009-02-12 # from ufl import (FacetNormal, FiniteElement, TestFunctions, TrialFunctions, div, dot, ds, dx, tetrahedron) cell = tetrahedron RT = FiniteElement("Raviart-Thomas", cell, 1) DG = FiniteElement("DG", cell, 0) MX = RT * DG (u, p) = TrialFunctions(MX) (v, q) = TestFunctions(MX) n = FacetNormal(cell) a0 = (dot(u, v) + div(u) * q + div(v) * p) * dx a1 = (dot(u, v) + div(u) * q + div(v) * p) * dx - p * dot(v, n) * ds forms = [a0, a1]
# (at your option) any later version. # # UFL 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 UFL. If not, see <http://www.gnu.org/licenses/>. # # Modified by: Martin Sandve Alnes (2009) # Date: 2009-03-02 # # The bilinear form a(v, u) and Linear form L(v) for the Stokes # equations using a mixed formulation (Taylor-Hood elements). from ufl import (Coefficient, FiniteElement, TestFunctions, TrialFunctions, VectorElement, div, dot, dx, grad, inner, triangle) cell = triangle P2 = VectorElement("Lagrange", cell, 2) P1 = FiniteElement("Lagrange", cell, 1) TH = P2 * P1 (v, q) = TestFunctions(TH) (u, p) = TrialFunctions(TH) f = Coefficient(P2) a = (inner(grad(v), grad(u)) - div(v) * p + q * div(u)) * dx L = dot(v, f) * dx
bcs = [bc0, bc1] # The first argument to # :py:class:`DirichletBC <dolfinx.cpp.fem.DirichletBC>` # specifies the :py:class:`FunctionSpace # <dolfinx.cpp.function.FunctionSpace>`. Since we have a # mixed function space, we write # ``W.sub(0)`` for the velocity component of the space, and # ``W.sub(1)`` for the pressure component of the space. # The second argument specifies the value on the Dirichlet # boundary. # The bilinear and linear forms corresponding to the weak mixed # formulation of the Stokes equations are defined as follows:: # Define variational problem (u, p) = TrialFunctions(W) (v, q) = TestFunctions(W) f = Function(W.sub(0).collapse()) a = (inner(grad(u), grad(v)) - inner(p, div(v)) + inner(div(u), q)) * dx L = inner(f, v) * dx # We also need to create a :py:class:`Function # <dolfinx.cpp.function.Function>` to store the solution(s). The (full) # solution will be stored in ``w``, which we initialize using the mixed # function space ``W``. The actual # computation is performed by calling solve with the arguments ``a``, # ``L``, ``w`` and ``bcs``. The separate components ``u`` and ``p`` of # the solution can be extracted by calling the :py:meth:`split # <dolfinx.functions.function.Function.split>` function. Here we use an # optional argument True in the split function to specify that we want a # deep copy. If no argument is given we will get a shallow copy. We want
def skw(tau): """Define vectorized skew operator""" sk = 2 * skew(tau) return as_vector((sk[0, 1], sk[0, 2], sk[1, 2])) cell = tetrahedron n = 3 # Finite element exterior calculus syntax r = 1 S = VectorElement("P Lambda", cell, r, form_degree=n - 1) V = VectorElement("P Lambda", cell, r - 1, form_degree=n) Q = VectorElement("P Lambda", cell, r - 1, form_degree=n) # Alternative syntax: # S = VectorElement("BDM", cell, r) # V = VectorElement("Discontinuous Lagrange", cell, r-1) # Q = VectorElement("Discontinuous Lagrange", cell, r-1) W = MixedElement(S, V, Q) (sigma, u, gamma) = TrialFunctions(W) (tau, v, eta) = TestFunctions(W) a = (inner(sigma, tau) - tr(sigma) * tr(tau) + dot(div(tau), u) - dot(div(sigma), v) + inner(skw(tau), gamma) + inner(skw(sigma), eta)) * dx