|
| 1 | +from ufl import (triangle, Mesh, MixedMesh, FunctionSpace, TestFunction, TrialFunction, Coefficient, Constant, |
| 2 | + Measure, SpatialCoordinate, FacetNormal, CellVolume, FacetArea, inner, grad, div, split, ) |
| 3 | +from ufl.algorithms import compute_form_data |
| 4 | +from ufl.finiteelement import FiniteElement, MixedElement |
| 5 | +from ufl.pullback import identity_pullback, contravariant_piola |
| 6 | +from ufl.sobolevspace import H1, HDiv, L2 |
| 7 | +from ufl.domain import extract_domains |
| 8 | + |
| 9 | + |
| 10 | +def test_mixed_function_space_with_mixed_mesh_basic(): |
| 11 | + cell = triangle |
| 12 | + elem0 = FiniteElement("Lagrange", cell, 1, (), identity_pullback, H1) |
| 13 | + elem1 = FiniteElement("Brezzi-Douglas-Marini", cell, 1, (2, ), contravariant_piola, HDiv) |
| 14 | + elem2 = FiniteElement("Discontinuous Lagrange", cell, 0, (), identity_pullback, L2) |
| 15 | + elem = MixedElement([elem0, elem1, elem2]) |
| 16 | + mesh0 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=100) |
| 17 | + mesh1 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=101) |
| 18 | + mesh2 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=102) |
| 19 | + domain = MixedMesh(mesh0, mesh1, mesh2) |
| 20 | + V = FunctionSpace(domain, elem) |
| 21 | + u = TrialFunction(V) |
| 22 | + v = TestFunction(V) |
| 23 | + f = Coefficient(V, count=1000) |
| 24 | + g = Coefficient(V, count=2000) |
| 25 | + u0, u1, u2 = split(u) |
| 26 | + v0, v1, v2 = split(v) |
| 27 | + f0, f1, f2 = split(f) |
| 28 | + g0, g1, g2 = split(g) |
| 29 | + dx1 = Measure("dx", mesh1) |
| 30 | + ds2 = Measure("ds", mesh2) |
| 31 | + x = SpatialCoordinate(mesh1) |
| 32 | + form = x[1] * f0 * inner(grad(u0), v1) * dx1(999) + div(f1) * g2 * inner(u1, grad(v2)) * ds2(888) |
| 33 | + fd = compute_form_data(form, |
| 34 | + do_apply_function_pullbacks=True, |
| 35 | + do_apply_integral_scaling=True, |
| 36 | + do_apply_geometry_lowering=True, |
| 37 | + preserve_geometry_types=(CellVolume, FacetArea), |
| 38 | + do_apply_restrictions=True, |
| 39 | + do_estimate_degrees=True, |
| 40 | + complex_mode=False) |
| 41 | + id0, id1 = fd.integral_data |
| 42 | + assert fd.preprocessed_form.arguments() == (v, u) |
| 43 | + assert fd.reduced_coefficients == [f, g] |
| 44 | + assert form.coefficients()[fd.original_coefficient_positions[0]] is f |
| 45 | + assert form.coefficients()[fd.original_coefficient_positions[1]] is g |
| 46 | + assert id0.domain is mesh1 |
| 47 | + assert id0.integral_type == 'cell' |
| 48 | + assert id0.subdomain_id == (999, ) |
| 49 | + assert fd.original_form.domain_numbering()[id0.domain] == 0 |
| 50 | + assert id0.integral_coefficients == set([f]) |
| 51 | + assert id0.enabled_coefficients == [True, False] |
| 52 | + assert id1.domain is mesh2 |
| 53 | + assert id1.integral_type == 'exterior_facet' |
| 54 | + assert id1.subdomain_id == (888, ) |
| 55 | + assert fd.original_form.domain_numbering()[id1.domain] == 1 |
| 56 | + assert id1.integral_coefficients == set([f, g]) |
| 57 | + assert id1.enabled_coefficients == [True, True] |
| 58 | + |
| 59 | + |
| 60 | +def test_mixed_function_space_with_mixed_mesh_restriction(): |
| 61 | + cell = triangle |
| 62 | + elem0 = FiniteElement("Lagrange", cell, 1, (), identity_pullback, H1) |
| 63 | + elem1 = FiniteElement("Brezzi-Douglas-Marini", cell, 1, (2, ), contravariant_piola, HDiv) |
| 64 | + elem2 = FiniteElement("Discontinuous Lagrange", cell, 0, (), identity_pullback, L2) |
| 65 | + elem = MixedElement([elem0, elem1, elem2]) |
| 66 | + mesh0 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=100) |
| 67 | + mesh1 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=101) |
| 68 | + mesh2 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=102) |
| 69 | + domain = MixedMesh(mesh0, mesh1, mesh2) |
| 70 | + V = FunctionSpace(domain, elem) |
| 71 | + V0 = FunctionSpace(mesh0, elem0) |
| 72 | + V1 = FunctionSpace(mesh1, elem1) |
| 73 | + V2 = FunctionSpace(mesh2, elem2) |
| 74 | + u1 = TrialFunction(V1) |
| 75 | + v2 = TestFunction(V2) |
| 76 | + f = Coefficient(V, count=1000) |
| 77 | + g = Coefficient(V, count=2000) |
| 78 | + f0, f1, f2 = split(f) |
| 79 | + g0, g1, g2 = split(g) |
| 80 | + dS1 = Measure("dS", mesh1) |
| 81 | + x2 = SpatialCoordinate(mesh2) |
| 82 | + form = inner(x2, g1) * g2 * inner(u1('-'), grad(v2('|'))) * dS1(999) |
| 83 | + fd = compute_form_data(form, |
| 84 | + do_apply_function_pullbacks=True, |
| 85 | + do_apply_integral_scaling=True, |
| 86 | + do_apply_geometry_lowering=True, |
| 87 | + preserve_geometry_types=(CellVolume, FacetArea), |
| 88 | + do_apply_restrictions=True, |
| 89 | + do_estimate_degrees=True, |
| 90 | + do_split_coefficients=(f, g), |
| 91 | + do_assume_single_integral_type=False, |
| 92 | + complex_mode=False) |
| 93 | + integral_data, = fd.integral_data |
| 94 | + assert integral_data.domain_integral_type_map[mesh1] == "interior_facet" |
| 95 | + assert integral_data.domain_integral_type_map[mesh2] == "exterior_facet" |
| 96 | + |
| 97 | + |
| 98 | +def test_mixed_function_space_with_mixed_mesh_signature(): |
| 99 | + cell = triangle |
| 100 | + mesh0 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=100) |
| 101 | + mesh1 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=101) |
| 102 | + dx0 = Measure("dx", mesh0) |
| 103 | + dx1 = Measure("dx", mesh1) |
| 104 | + n0 = FacetNormal(mesh0) |
| 105 | + n1 = FacetNormal(mesh1) |
| 106 | + form_a = inner(n1, n1) * dx0(999) |
| 107 | + form_b = inner(n0, n0) * dx1(999) |
| 108 | + assert form_a.signature() == form_b.signature() |
| 109 | + assert extract_domains(form_a) == (mesh0, mesh1) |
| 110 | + assert extract_domains(form_b) == (mesh1, mesh0) |
0 commit comments