Ejemplo n.º 1
0
"""Example where we show how to set eod phase."""

from fish2eod import BaseFishModel, plotting
"""
Define model parameters.

Here we draw a normal 20cm fish but set its phase to 0.5 in the EOD cycle
"""
parameters = {"fish_x": [0, 20], "fish_y": [0, 0], "phase": 0.5}
"""
Create the model and compile it

Plot the subdomains afterwards
"""
model = BaseFishModel()
model.compile(**parameters)
model.solve(**parameters)

plotting.mesh_plot_2d(model.solution, "solution")
plotting.plot_outline(model.solution)
Ejemplo n.º 2
0
from fish2eod import plotting, BaseFishModel, Circle
"""
Boilerplate to solve the model
"""


class PreyClass(BaseFishModel):
    def add_geometry(self, **kwargs):
        prey = Circle((3, 2), 0.5)

        self.model_geometry.add_domain("prey", prey, sigma=1)


model = PreyClass()
parameters = {"fish_x": [-15, 15], "fish_y": [0, 0]}
model.compile(**parameters)
model.solve(**parameters)
"""
Extract the solution object

Plot the "FEM solution"
"""

model_solution = model.solution  # pull solution
plotting.plot_outline(model_solution)  # plot the result named solution
Ejemplo n.º 3
0
prey_x = ParameterSet("prey_x", prey_x=[3, 6], rebuild_mesh=True)
prey_y = ParameterSet("prey_y", prey_y=[2, 4], rebuild_mesh=True)

parameter_sweep = ParameterSweep(prey_x, prey_y)
it = IterativeSolver("temp",
                     d.name,
                     PreyClass,
                     parameter_sweep,
                     fish_x=[-15, 15],
                     fish_y=[0, 0])
it.run()
"""
Extract the solution object

Plot the "FEM solution"
"""

loaded_solution = load_from_file(d.name + "/temp")
prey_x_values = loaded_solution.parameter_levels["prey_x"]
prey_y_values = loaded_solution.parameter_levels["prey_y"]
for prey_x, prey_y in product(prey_x_values, prey_y_values):
    plt.figure()

    # pass the solution parameters in an additional dictionary.
    # all other arguments can be used as normal
    plotting.mesh_plot_2d(loaded_solution,
                          "solution",
                          prey_x=prey_x,
                          prey_y=prey_y)
    plotting.plot_outline(loaded_solution, prey_x=prey_x, prey_y=prey_y)
Ejemplo n.º 4
0
"""Example with Neumann conditions (current sources)."""
from fish2eod import BaseFishModel, Circle, BoundaryCondition, plotting


class ExampleCurrentSource(BaseFishModel):
    """Example model with an additional voltage source."""

    def add_geometry(self, **kwargs):
        """Add a circular object to carry the current."""
        source = Circle([0, 3], 1)
        self.model_geometry.add_domain("fg", source, sigma=1)

    def add_current_sources(self, **kwargs):
        """Add a voltage source to the circle"""
        # We can pull the domain id of the "fg" domain from the model geometry
        # value=-3e-6 means that the Neurmann condition is as -3uA/cm^2 source
        return (BoundaryCondition(value=-3e-6, label=self.model_geometry["fg"]),)


"""
Compile and solve the model

Plot the result with a color bar
"""
model = ExampleCurrentSource()
model.compile(fish_x=[0, 20], fish_y=[0, 0])
model.solve(fish_x=[0, 20], fish_y=[0, 0])

plotting.plot_outline(model.solution, color="k")
plotting.mesh_plot_2d(model.solution, "solution", colorbar=True)
Ejemplo n.º 5
0
class PreyClass(BaseFishModel):
    def add_geometry(self, prey_cond, **kwargs):
        prey = Circle((3, 2), 0.5)
        self.model_geometry.add_domain("prey", prey, sigma=prey_cond)


parameter_set = ParameterSet("sigma", prey_cond=[0.00023 / 10, 0.00023, 0.00023 * 10])
parameter_sweep = ParameterSweep(parameter_set)

d = TemporaryDirectory()  # VERY IMPORTANT - do not do this!
# you want to use a proper save directiory. This directory created as is WILL BE DELETED when python closes.

EIP = ElectricImageParameters(domains=("prey",), value=BaseFishModel.WATER_CONDUCTIVITY)
solver = IterativeSolver(
    "Example",
    d.name,
    PreyClass,
    parameter_sweep,
    fish_x=[-15, 15],
    fish_y=[0, 0],
    image=EIP,
)
solver.run()

loaded_solution = load_from_file(d.name + "/Example")
for ix in range(3):
    plt.figure()
    plotting.mesh_plot_2d(loaded_solution, "solution", sigma=ix)
    plotting.plot_outline(loaded_solution, sigma=ix)