@@ -269,10 +269,9 @@ def test_custom_field(tmp_path, expression):
269269 lambda T : T + 1 ,
270270 lambda c_A , c_B : c_A + c_B ,
271271 lambda c_A , T : c_A * T ,
272- # FIXME: the following don't work (easily) because of https://github.com/FEniCS/dolfinx/issues/3207
273- # lambda c_A, c_B, x: c_A * c_B + x[0],
274- # lambda c_A, T, x: c_A * T + x[0],
275- # lambda T, x: T + x[0],
272+ lambda c_A , c_B , x : c_A * c_B + x [0 ],
273+ lambda c_A , T , x : c_A * T + x [0 ],
274+ lambda T , x : T + x [0 ],
276275 ],
277276)
278277def test_custom_field_discontinuous (tmp_path , expression ):
@@ -340,3 +339,67 @@ def test_custom_field_discontinuous(tmp_path, expression):
340339 my_model .initialise ()
341340
342341 my_model .run ()
342+
343+
344+ @pytest .mark .parametrize (
345+ "expression" ,
346+ [lambda c_A , t : c_A * t , lambda t : t ],
347+ )
348+ def test_custom_field_not_implemented_error (expression ):
349+ my_model = F .HydrogenTransportProblemDiscontinuous ()
350+
351+ mat = F .Material (D_0 = 1 , E_D = 0 , K_S_0 = 1 , E_K_S = 0 )
352+
353+ vol = F .VolumeSubdomain (id = 1 , material = mat )
354+
355+ top = F .SurfaceSubdomain (id = 1 , locator = lambda x : np .isclose (x [1 ], 1 ))
356+ bottom = F .SurfaceSubdomain (id = 2 , locator = lambda x : np .isclose (x [1 ], 0 ))
357+ left = F .SurfaceSubdomain (id = 3 , locator = lambda x : np .isclose (x [0 ], 0 ))
358+ right = F .SurfaceSubdomain (id = 4 , locator = lambda x : np .isclose (x [0 ], 1 ))
359+
360+ my_model .subdomains = [vol , top , bottom , left , right ]
361+
362+ my_model .surface_to_volume = {top : vol , bottom : vol , left : vol , right : vol }
363+
364+ dolfinx_mesh = dolfinx .mesh .create_unit_square (MPI .COMM_WORLD , 10 , 10 )
365+ my_model .mesh = F .Mesh (dolfinx_mesh )
366+
367+ A = F .Species ("A" , subdomains = my_model .volume_subdomains )
368+ B = F .Species ("B" , subdomains = my_model .volume_subdomains )
369+ C = F .Species ("C" , subdomains = my_model .volume_subdomains )
370+ D = F .Species ("D" , subdomains = my_model .volume_subdomains )
371+
372+ my_model .species = [A , B , C , D ]
373+
374+ my_model .boundary_conditions = (
375+ [
376+ F .FixedConcentrationBC (species = A , subdomain = top , value = 1 ),
377+ F .FixedConcentrationBC (species = B , subdomain = left , value = 1 ),
378+ ]
379+ + [
380+ F .FixedConcentrationBC (species = C , subdomain = surf , value = 0 )
381+ for surf in [top , bottom , left , right ]
382+ ]
383+ + [
384+ F .FixedConcentrationBC (species = D , subdomain = surf , value = 0 )
385+ for surf in [top , bottom , left , right ]
386+ ]
387+ )
388+
389+ my_model .temperature = lambda x : 300 + 100 * x [0 ]
390+
391+ my_model .settings = F .Settings (transient = False , atol = 1e-9 , rtol = 1e-9 )
392+
393+ custom_field = F .CustomField (
394+ filename = "custom_field.bp" ,
395+ expression = expression ,
396+ species_dependent_value = {"c_A" : A , "c_B" : B },
397+ subdomain = vol ,
398+ )
399+
400+ my_model .exports = [
401+ custom_field ,
402+ ]
403+
404+ with pytest .raises (NotImplementedError ):
405+ my_model .initialise ()
0 commit comments