Test some edge cases for the GFCF cache in userdata
(unit_mesh_2d, test_compile, real_compile)
| 21 | |
| 22 | @pytest.mark.parametrize("test_compile,real_compile", VARIANTS) |
| 23 | def test_gf_userdata_cache(unit_mesh_2d, test_compile, real_compile): |
| 24 | """Test some edge cases for the GFCF cache in userdata""" |
| 25 | mesh = unit_mesh_2d |
| 26 | Compile = _compile_fn(test_compile, real_compile) |
| 27 | |
| 28 | fesr = H1(mesh, order=2) |
| 29 | fesc = H1(mesh, order=2, complex=True) |
| 30 | u, v = fesr.TnT() |
| 31 | uc, vc = fesc.TnT() |
| 32 | |
| 33 | gfc = GridFunction(fesc) |
| 34 | gfr = GridFunction(fesr) |
| 35 | gfc.Set(1j) |
| 36 | gfr.Set(1) |
| 37 | |
| 38 | f = LinearForm(fesr) |
| 39 | f += Compile(Norm(gfc) * v) * dx |
| 40 | |
| 41 | a = BilinearForm(fesr) |
| 42 | a += Compile(Norm(gfc) * u * v) * dx |
| 43 | |
| 44 | f.Assemble() |
| 45 | r = f.vec.CreateVector() |
| 46 | a.Apply(gfr.vec, r) |
| 47 | assert np.linalg.norm(r.FV().NumPy() - f.vec.FV().NumPy()) < 1e-10 |
| 48 | |
| 49 | fc = LinearForm(fesc) |
| 50 | fc += Compile(gfr * vc) * dx |
| 51 | fc.Assemble() |
| 52 | |
| 53 | ac = BilinearForm(fesc) |
| 54 | ac += Compile(gfr * uc * vc) * dx |
| 55 | |
| 56 | rc = gfc.vec.CreateVector() |
| 57 | ac.Apply(gfc.vec, rc) |
| 58 | assert np.linalg.norm(rc.FV().NumPy().imag - fc.vec.FV().NumPy().real) < 1e-10 |
| 59 | |
| 60 | a3 = BilinearForm(fesr) |
| 61 | a3 += Compile(Norm(1j * gfr) * u * v) * dx |
| 62 | |
| 63 | r3 = gfr.vec.CreateVector() |
| 64 | a3.Apply(gfr.vec, r3) |
| 65 | assert np.linalg.norm(r3.FV().NumPy() - f.vec.FV().NumPy()) < 1e-10 |
nothing calls this directly
no test coverage detected