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