Skip to content

Commit

Permalink
increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jhdark committed Nov 8, 2023
1 parent 89b270d commit fe8ae33
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/test_h_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,59 @@ def test_update_time_dependent_values_source(source_value, expected_values):
else:
computed_value = my_model.sources[0].value_fenics.vector.array[-1]
assert np.isclose(computed_value, expected_values[i])


@pytest.mark.parametrize(
"temperature_value, source_value, expected_values",
[
(5, 1.0, [1.0, 1.0, 1.0]),
(lambda t: t + 1, lambda T: T, [2.0, 3.0, 4.0]),
(lambda x: 1 + x[0], lambda T: 2 * T, [10.0, 10.0, 10.0]),
(lambda x, t: t + x[0], lambda T: 0.5 * T, [2.5, 3.0, 3.5]),
(
lambda x, t: ufl.conditional(ufl.lt(t, 2), 3 + x[0], 0.0),
lambda T: T,
[7.0, 0.0, 0.0],
),
],
)
def test_update_sources_with_time_dependent_temperature(
temperature_value, source_value, expected_values
):
"""Test that temperature dependent bcs are updated at each time step when the
temperature is time dependent, and match an expected value"""

# BUILD
H = F.Species("H")
volume_subdomain = F.VolumeSubdomain1D(id=1, borders=[0, 4], material=dummy_mat)
surface_subdomain = F.SurfaceSubdomain1D(id=1, x=4)
my_model = F.HydrogenTransportProblem(
mesh=test_mesh,
species=[H],
subdomains=[volume_subdomain, surface_subdomain],
temperature=temperature_value,
)
my_model.t = fem.Constant(my_model.mesh.mesh, 0.0)
dt = fem.Constant(test_mesh.mesh, 1.0)

my_model.sources = [
F.Source(value=source_value, volume=volume_subdomain, species=H)
]

my_model.define_temperature()
my_model.define_function_spaces()
my_model.assign_functions_to_species()
my_model.define_markers_and_measures()
my_model.define_sources()

for i in range(3):
# RUN
my_model.t.value += dt.value
my_model.update_time_dependent_values()

# TEST
if isinstance(my_model.sources[0].value_fenics, fem.Constant):
computed_value = float(my_model.sources[0].value_fenics)
else:
computed_value = my_model.sources[0].value_fenics.vector.array[-1]
assert np.isclose(computed_value, expected_values[i])

0 comments on commit fe8ae33

Please sign in to comment.