Skip to content

Commit

Permalink
Add t_init parameter to model
Browse files Browse the repository at this point in the history
  • Loading branch information
Sosnowsky committed Jan 28, 2025
1 parent fbb09bd commit c37af80
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
8 changes: 6 additions & 2 deletions blobmodel/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(
Ly: float,
dt: float,
T: float,
t_init: float,
periodic_y: bool,
) -> None:
"""
Expand All @@ -36,6 +37,8 @@ def __init__(
Time step.
T : float
Time length.
t_init : float
Initial time
periodic_y : bool
Flag indicating whether periodicity is allowed in the y-direction.
"""
Expand All @@ -45,6 +48,7 @@ def __init__(
self.Ly = Ly
self.dt = dt
self.T = T
self.t_init = t_init
self.periodic_y = periodic_y

# calculate x, y and t coordinates
Expand All @@ -53,7 +57,7 @@ def __init__(
self.y: NDArray[Literal[64], Any] = np.array([0])
else:
self.y = np.arange(0, self.Ly, self.Ly / self.Ny)
self.t: NDArray[Literal[64], Any] = np.arange(0, self.T, self.dt)
self.t: NDArray[Literal[64], Any] = np.arange(t_init, self.T + t_init, self.dt)
self.x_matrix, self.y_matrix, self.t_matrix = np.meshgrid(
self.x, self.y, self.t
)
Expand All @@ -69,5 +73,5 @@ def __str__(self) -> str:
"""
return (
f"Geometry parameters: Nx:{self.Nx}, Ny:{self.Ny}, Lx:{self.Lx}, Ly:{self.Ly}, "
+ f"dt:{self.dt}, T:{self.T}, y-periodicity:{self.periodic_y}"
+ f"dt:{self.dt}, T:{self.T}, t_init:{self.t_init}, y-periodicity:{self.periodic_y}"
)
4 changes: 4 additions & 0 deletions blobmodel/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(
num_blobs: int = 1000,
t_drain: Union[float, NDArray, int] = 10,
blob_factory: BlobFactory = DefaultBlobFactory(),
t_init: float = 0,
labels: str = "off",
label_border: float = 0.75,
one_dimensional: bool = False,
Expand Down Expand Up @@ -63,6 +64,8 @@ def __init__(
of length Nx.
blob_factory : BlobFactory, optional
BlobFactory instance for setting blob parameter distributions.
t_init : float, optional
Initial time for simulation, default 0.
labels : str, optional
Blob label setting. Possible values: "off", "same", "individual".
"off": no blob labels returned
Expand Down Expand Up @@ -108,6 +111,7 @@ def __init__(
Ly=Ly,
dt=dt,
T=T,
t_init=t_init,
periodic_y=periodic_y,
)
self.blob_shape = (
Expand Down
2 changes: 1 addition & 1 deletion blobmodel/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def show_model(
interval: int = 100,
gif_name: Union[str, None] = None,
fps: int = 10,
initial_time: float = 0
initial_time: float = 0,
) -> None:
"""
Creates an animation that shows the evolution of a specific variable over time.
Expand Down
15 changes: 10 additions & 5 deletions examples/blob_tilting.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
vx_parameter=vx,
wx_parameter=wx,
wy_parameter=wy,
blob_alignment=True # Blobs are aligned
blob_alignment=True, # Blobs are aligned
)

# blob tilting
theta = np.pi / 4
# Using a lambda function to set the tilt angle theta, allows us to set a distribution for tilt angles if desired.
# In this case we use a degenerate distribution.
bf.set_theta_setter(
lambda: theta
)
bf.set_theta_setter(lambda: theta)

# create data
bm = Model(
Expand All @@ -42,7 +40,14 @@
num_blobs=100,
t_drain=1e10,
blob_factory=bf,
t_init=10,
)
ds = bm.make_realization(speed_up=True, error=1e-2)
# show animation and save as gif
show_model(dataset=ds, interval=100, gif_name="blob_alignment_true.gif", fps=10, initial_time=10)
show_model(
dataset=ds,
interval=100,
gif_name="blob_alignment_true.gif",
fps=10,
initial_time=10,
)
4 changes: 2 additions & 2 deletions tests/test_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@


def test_geometry_str():
geo = Geometry(1, 1, 1, 1, 1, 1, False)
geo = Geometry(1, 1, 1, 1, 1, 1, 1, False)
assert (
str(geo)
== "Geometry parameters: Nx:1, Ny:1, Lx:1, Ly:1, dt:1, T:1, y-periodicity:False"
== "Geometry parameters: Nx:1, Ny:1, Lx:1, Ly:1, dt:1, T:1, t_init:1, y-periodicity:False"
)


Expand Down

0 comments on commit c37af80

Please sign in to comment.