Exemple #1
0
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"
Mask only the water (outside fish)
"""

model_solution = model.solution  # pull solution
mask = plotting.generate_mask(model.solution, include_domains=("water", ))
plotting.mesh_plot_2d(model_solution, "solution",
                      mask=mask)  # plot the result named solution

# For convenience you can also exclude a domain by setting include=False
plt.figure()
mask = plotting.generate_mask(model.solution,
                              include_domains=("water", ),
                              include=False)
plotting.mesh_plot_2d(model_solution, "solution",
                      mask=mask)  # plot the result named solution
"""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)
"""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)
Exemple #4
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)
Exemple #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)
Exemple #6
0
model = PreyClass()
parameters = {"fish_x": [-15, 15], "fish_y": [0, 0]}
model.compile(**parameters)
model.solve(**parameters)
"""
Plot showing effect of color_style and flags

The colorbar flag turns the colorbar on or off
The mask flag sets the mask (requires valid mask)
"""

model_solution = model.solution  # pull solution
plt.figure()
plotting.mesh_plot_2d(model_solution,
                      "solution",
                      colorbar=True,
                      mask=None,
                      color_style="Full")  # plot the result named solution
plt.figure()
plotting.mesh_plot_2d(model_solution,
                      "solution",
                      colorbar=True,
                      mask=None,
                      color_style="Equal")  # plot the result named solution
plt.figure()
plotting.mesh_plot_2d(model_solution,
                      "solution",
                      colorbar=True,
                      mask=None,
                      color_style=None)  # plot the result named solution
plt.figure()