Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Simulation.exports setter #836

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions festim/generic_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ def exports(self):
def exports(self, value):
if value is None:
self._exports = festim.Exports([])
elif isinstance(value, (festim.Export, festim.DerivedQuantities)):
self._exports = festim.Exports([value])
elif isinstance(value, festim.Exports):
self._exports = value
elif isinstance(value, list):
self._exports = festim.Exports(value)
elif isinstance(value, festim.Export):
self._exports = festim.Exports([value])
else:
raise TypeError(
"accepted types for exports are list, festim.Export or festim.Exports"
"accepted types for exports are list, festim.DerivedQuantities, festim.Export or festim.Exports"
)

@property
Expand Down
2 changes: 1 addition & 1 deletion test/simulation/test_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ def test_setting_exports_wrong_type(self, exp):

with pytest.raises(
TypeError,
match="accepted types for exports are list, festim.Export or festim.Exports",
match="accepted types for exports are list, festim.DerivedQuantities, festim.Export or festim.Exports",
):
self.my_sim.exports = exp
24 changes: 24 additions & 0 deletions test/simulation/test_postprocessing_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,27 @@ def test_surface_kinetics(self):
data = derived_quantities.data
assert np.isclose(data[1][1], 1)
assert np.isclose(data[1][2], 2)


def test_data_is_not_empty():
"""
Test to catch bug #833
"""

my_model = festim.Simulation()
my_model.mesh = festim.MeshFromVertices(vertices=np.linspace(0, 1, num=100))
my_model.materials = festim.Material(id=1, D_0=1, E_D=0)
my_model.T = festim.Temperature(value=700)
my_model.settings = festim.Settings(
absolute_tolerance=1e-10, relative_tolerance=1e-10, transient=False
)

flux_left = festim.SurfaceFlux(field=0, surface=1)
flux_right = festim.SurfaceFlux(field=0, surface=2)
my_model.exports = festim.DerivedQuantities([flux_left, flux_right])

my_model.initialise()
my_model.run()

assert flux_left.data != []
assert flux_right.data != []
Loading