From fa99a7246b3895647fdde4b306e5e66898a2728e Mon Sep 17 00:00:00 2001 From: Bryan Rumsey Date: Tue, 2 Mar 2021 13:27:23 -0500 Subject: [PATCH 1/3] Added timestep_size to the timespan function. Closes #74 --- spatialpy/Model.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spatialpy/Model.py b/spatialpy/Model.py index 007f146a..502c923e 100644 --- a/spatialpy/Model.py +++ b/spatialpy/Model.py @@ -123,7 +123,7 @@ def set_timesteps(self, step_size, num_steps): self.num_timesteps = math.ceil(num_steps * steps_per_output) self.output_freq = steps_per_output - def timespan(self, time_span): + def timespan(self, time_span, timestep_size=None): """ Set the time span of simulation. The SSA-SDPD engine does not support non-uniform timespans. @@ -134,6 +134,8 @@ def timespan(self, time_span): """ self.tspan = time_span + if timestep_size is not None: + self.timestep_size = timestep_size items_diff = numpy.diff(time_span) items = map(lambda x: round(x, 10), items_diff) From 7583ce7b13dea340877bbc0d6e0ad17be689dc87 Mon Sep 17 00:00:00 2001 From: Bryan Rumsey Date: Tue, 2 Mar 2021 13:52:53 -0500 Subject: [PATCH 2/3] Added 'add_mesh' function that will set a models mesh and the list of type ids. Closes #73 --- spatialpy/Model.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spatialpy/Model.py b/spatialpy/Model.py index 502c923e..b581d546 100644 --- a/spatialpy/Model.py +++ b/spatialpy/Model.py @@ -200,6 +200,19 @@ def restrict(self, species, listOfTypes): else: self.listOfDiffusionRestrictions[species] = listOfTypes + def add_mesh(self, mesh): + ''' + Add a mesh to the model + + mesh : Mesh + The Mesh to be added to the model + ''' + if type(mesh).__name__ != 'Mesh': + raise ModelError("Unexpected parameter for add_mesh. Parameter must be a Mesh.") + + self.mesh = mesh + self.listOfTypeIDs = list(set(mesh.type)) + def add_data_function(self, data_function): """ Add a scalar spatial function to the simulation. This is useful if you have a spatially varying in put to your model. Argument is a instances of subclass of the From 8542d4d8613e6e968e7c0ba42ae09c1438a57ab3 Mon Sep 17 00:00:00 2001 From: Bryan Rumsey Date: Tue, 2 Mar 2021 13:55:34 -0500 Subject: [PATCH 3/3] Fixed interation bug in the initial conditions section of the models '__str__' function. --- spatialpy/Model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spatialpy/Model.py b/spatialpy/Model.py index b581d546..cd3e491d 100644 --- a/spatialpy/Model.py +++ b/spatialpy/Model.py @@ -68,7 +68,7 @@ def decorate(header): print_string += f"\n{str(species)}" if len(self.listOfInitialConditions): print_string += decorate("Initial Conditions") - for _, initial_condition in self.listOfInitialConditions.items(): + for _, initial_condition in self.listOfInitialConditions: print_string += f"\n{str(initial_condition)}" if len(self.listOfDiffusionRestrictions): print_string += decorate("Diffusion Restrictions")