@@ -434,3 +434,104 @@ def test_initial_condition_continuous_multimaterial():
434434 # assert value of spe1 is not all the same across the domain
435435
436436 assert not np .allclose (my_model .u_n .x .array [:], intial_cond_value )
437+
438+
439+ def test_initial_condition_mixed_domain ():
440+ """Test the initial condition in a multi-material discontinous case"""
441+
442+ my_model = F .HydrogenTransportProblemDiscontinuous ()
443+
444+ vertices_left = np .linspace (0 , 0.5 , 500 )
445+ vertices_right = np .linspace (0.5 , 1 , 500 )
446+ vertices = np .concatenate ((vertices_left , vertices_right ))
447+ my_model .mesh = F .Mesh1D (vertices )
448+
449+ # assumes the same diffusivity for all species
450+ material_left = F .Material (D_0 = 1e-01 , E_D = 0 , K_S_0 = 1 , E_K_S = 0 )
451+ material_right = F .Material (D_0 = 1e-01 , E_D = 0 , K_S_0 = 2 , E_K_S = 0 )
452+
453+ vol1 = F .VolumeSubdomain1D (id = 1 , borders = [0 , 0.5 ], material = material_left )
454+ vol2 = F .VolumeSubdomain1D (id = 2 , borders = [0.5 , 1 ], material = material_right )
455+ my_model .subdomains = [vol1 , vol2 ]
456+
457+ spe1 = F .Species ("1" , mobile = True , subdomains = [vol1 , vol2 ])
458+ my_model .species = [spe1 ]
459+
460+ my_model .temperature = 300
461+
462+ intial_cond_value = 100
463+ V = fem .functionspace (my_model .mesh .mesh , ("CG" , 1 ))
464+ u = fem .Function (V )
465+ u .x .array [:] = intial_cond_value
466+
467+ my_model .initial_conditions = [
468+ F .InitialConcentration (value = u , species = spe1 , volume = vol1 ),
469+ ]
470+
471+ dt = F .Stepsize (0.1 )
472+ my_model .settings = F .Settings (
473+ atol = 1e-10 , rtol = 1e-10 , final_time = 5 , transient = True , stepsize = dt
474+ )
475+
476+ my_model .initialise ()
477+
478+ # assert value of spe1 in vol1
479+ left_spe1_un = vol1 .u .sub (0 )
480+
481+ assert not np .allclose (left_spe1_un .x .array [:], intial_cond_value )
482+
483+
484+ def test_initial_condition_mixed_domain_multispecies ():
485+ """Test the initial condition in a multispecies multi-material discontinous case"""
486+
487+ my_model = F .HydrogenTransportProblemDiscontinuous ()
488+
489+ vertices_left = np .linspace (0 , 0.5 , 500 )
490+ vertices_right = np .linspace (0.5 , 1 , 500 )
491+ vertices = np .concatenate ((vertices_left , vertices_right ))
492+ my_model .mesh = F .Mesh1D (vertices )
493+
494+ # assumes the same diffusivity for all species
495+ material_left = F .Material (D_0 = 1e-01 , E_D = 0 , K_S_0 = 1 , E_K_S = 0 )
496+ material_right = F .Material (D_0 = 1e-01 , E_D = 0 , K_S_0 = 2 , E_K_S = 0 )
497+
498+ vol1 = F .VolumeSubdomain1D (id = 1 , borders = [0 , 0.5 ], material = material_left )
499+ vol2 = F .VolumeSubdomain1D (id = 2 , borders = [0.5 , 1 ], material = material_right )
500+ my_model .subdomains = [vol1 , vol2 ]
501+
502+ spe1 = F .Species ("1" , mobile = True , subdomains = [vol1 , vol2 ])
503+ spe2 = F .Species ("2" , mobile = True , subdomains = [vol1 , vol2 ])
504+ my_model .species = [spe1 , spe2 ]
505+
506+ my_model .temperature = 300
507+
508+ intial_cond_value_1 = 100
509+ intial_cond_value_2 = 200
510+ V = fem .functionspace (my_model .mesh .mesh , ("CG" , 1 ))
511+ u = fem .Function (V )
512+ u .x .array [:] = intial_cond_value_1
513+
514+ V2 = fem .functionspace (my_model .mesh .mesh , ("CG" , 1 ))
515+ u2 = fem .Function (V2 )
516+ u2 .x .array [:] = intial_cond_value_2
517+
518+ my_model .initial_conditions = [
519+ F .InitialConcentration (value = u , species = spe1 , volume = vol1 ),
520+ F .InitialConcentration (value = u2 , species = spe2 , volume = vol1 ),
521+ ]
522+
523+ dt = F .Stepsize (0.1 )
524+ my_model .settings = F .Settings (
525+ atol = 1e-10 , rtol = 1e-10 , final_time = 5 , transient = True , stepsize = dt
526+ )
527+
528+ my_model .initialise ()
529+
530+ spe1_left , spe1_to_vol1 = vol1 .u_n .function_space .sub (0 ).collapse ()
531+ spe2_left , spe2_to_vol1 = vol1 .u_n .function_space .sub (1 ).collapse ()
532+
533+ prev_solution_spe1_left = vol1 .u_n .x .array [spe1_to_vol1 ]
534+ prev_solution_spe2_left = vol1 .u_n .x .array [spe2_to_vol1 ]
535+
536+ assert np .allclose (prev_solution_spe1_left , intial_cond_value_1 )
537+ assert np .allclose (prev_solution_spe2_left , intial_cond_value_2 )
0 commit comments