Skip to content

Commit

Permalink
Update growing particle number example
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTov committed May 15, 2024
1 parent 24577d4 commit 1d0c299
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
59 changes: 59 additions & 0 deletions examples/growing_sphere_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
ZnVis: A Zincwarecode package.
License
-------
This program and the accompanying materials are made available under the terms
of the Eclipse Public License v2.0 which accompanies this distribution, and is
available at https://www.eclipse.org/legal/epl-v20.html
SPDX-License-Identifier: EPL-2.0
Copyright Contributors to the Zincwarecode Project.
Contact Information
-------------------
email: zincwarecode@gmail.com
github: https://github.com/zincware
web: https://zincwarecode.com/
Citation
--------
If you use this module please cite us with:
Summary
-------
Tutorial script to visualize simple spheres over a random trajectory.
"""

import numpy as np

import znvis as vis

if __name__ == "__main__":
"""
Run the simple spheres example.
"""
material_1 = vis.Material(colour=np.array([30, 144, 255]) / 255, alpha=0.6)
# Define the first particle.
trajectory = np.random.uniform(-100, 100, (100, 1000, 3))
trajectory = []
p_number = 1
for t in range(1000):
trajectory.append(np.random.uniform(-100, 100, (p_number, 3)))

p_number = np.random.randint(p_number, 5 * p_number)

if p_number > 20000:
p_number = 20000

mesh = vis.Sphere(radius=2.0, resolution=3, material=material_1)
particle = vis.Particle(
name="Blue", mesh=mesh, position=trajectory, smoothing=False
)

# Create a bounding box
bounding_box = vis.BoundingBox(
center=np.array([0, 0, 0]), box_size=np.array([100, 100, 100])
)

# Construct the visualizer and run
visualizer = vis.Visualizer(
particles=[particle], frame_rate=20, bounding_box=bounding_box
)
visualizer.run_visualization()
6 changes: 3 additions & 3 deletions znvis/particle/particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ def construct_mesh_list(self):
"""
self.mesh_list = []
try:
n_particles = int(self.position.shape[1])
n_time_steps = int(self.position.shape[0])
# n_particles = int(self.position.shape[1])
n_time_steps = int(len(self.position))
except ValueError:
raise ValueError("There is no data for these particles.")

for i in track(range(n_time_steps), description=f"Building {self.name} Mesh"):
for j in range(n_particles):
for j in range(np.shape(self.position[i])[0]):
if j == 0:
if self.director is not None:
mesh = self._create_mesh(
Expand Down
2 changes: 1 addition & 1 deletion znvis/visualizer/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(
self.bounding_box = bounding_box() if bounding_box else None

if number_of_steps is None:
number_of_steps = particles[0].position.shape[0]
number_of_steps = len(particles[0].position)
self.number_of_steps = number_of_steps

self.output_folder = pathlib.Path(output_folder).resolve()
Expand Down

0 comments on commit 1d0c299

Please sign in to comment.