Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_particles #39

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ As of today, rolling movement is **not** implemented

Running a specific case requires to write an application in `dem/app`, and then to register it in `dem/app/app.py`. You can than call it from root directory doing `python start.py <app_name>`. Multiple app examples are provided in the dedicated directory, to be copied and adapted. Below are some simple sanity checks and a bit more advanced examples of what is possible with this small library.

| **`gravity`** | **`gravity-tilted`** | **`obstacle`** |
| :-------------------------------------------------------: | :------------------------------------------------------------: | :-------------------------------------------------------: |
| <img height="250" alt="gif" src="dem/save/gravity.gif"> | <img height="250" alt="gif" src="dem/save/gravity_tilted.gif"> | <img height="250" alt="gif" src="dem/save/obstacle.gif"> |
| **`dam-break`** | **`silo`** | **`mill`** |
| <img height="250" alt="gif" src="dem/save/dam_break.gif"> | <img height="250" alt="gif" src="dem/save/silo.gif"> | <img height="250" alt="gif" src="dem/save/mill.gif"> |
| **`gravity`** | **`gravity-tilted`** | **`obstacle`** |
|:---------------------------------------------------------:|:--------------------------------------------------------------:|:--------------------------------------------------------:|
| <img height="250" alt="gif" src="dem/save/gravity.gif"> | <img height="250" alt="gif" src="dem/save/gravity_tilted.gif"> | <img height="250" alt="gif" src="dem/save/obstacle.gif"> |
| **`dam-break`** | **`silo`** | **`mill`** |
| <img height="250" alt="gif" src="dem/save/dam_break.gif"> | <img height="250" alt="gif" src="dem/save/silo.gif"> | <img height="250" alt="gif" src="dem/save/mill.gif"> |
| **`silo-open`** | **`?`** | **`?`** |
| <img height="250" alt="gif" src="dem/save/silo_open.gif"> | <img height="250" alt="gif" src="dem/save/logo.png"> | <img height="250" alt="gif" src="dem/save/logo.png"> |
52 changes: 35 additions & 17 deletions dem/app/silo_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def __init__(self,

self.nt = int(self.t_max/self.dt)
self.plot_it = 0
self.check_freq = 10 # check particles every 10 iterations

self.n_row = 25 # nb of particles on a row at start
self.n_col = 20 # nb of particles on a col at start
self.rmv_freq = 100 # check particles removal every 10 iterations
self.add_freq = 8000 # add new particles every 10 iterations

self.radius = 0.025

self.p = particles(np = self.n_row*self.n_col,
self.p = particles(np = 0,
nt = self.nt,
material = "steel",
radius = self.radius,
Expand All @@ -50,8 +50,8 @@ def __init__(self,
self.p.e_wall[:] = 0.5
self.p.e_part[:] = 0.5

colors = np.array(['r', 'g', 'b', 'c', 'm', 'y', 'k'])
self.p.c = colors[np.random.randint(0,len(colors),size=self.p.np)]
self.colors = np.array(['r', 'g', 'b', 'c', 'm', 'y', 'k'])
self.p.c = self.colors[np.random.randint(0,len(self.colors),size=self.p.np)]

self.d = domain_factory.create("rectangle",
x_min = 0.0,
Expand All @@ -64,14 +64,14 @@ def __init__(self,

self.o0 = domain_factory.create("rectangle",
x_min =-1.0,
x_max = 1.4,
x_max = 1.5,
y_min = 2.5,
y_max = 2.6,
angle =-30.0,
plot_fill = True,
material = "steel")
self.o1 = domain_factory.create("rectangle",
x_min = 1.6,
x_min = 1.5,
x_max = 4.0,
y_min = 2.5,
y_max = 2.6,
Expand All @@ -92,24 +92,42 @@ def reset(self):

self.it = 0
self.t = 0.0
sep = 4.0*self.radius
mid = 0.5*(self.d.x_min + self.d.x_max)
half = 0.5*self.n_row*(self.radius + 0.75*sep)
# sep = 4.0*self.radius
# mid = 0.5*(self.d.x_min + self.d.x_max)
# half = 0.5*self.n_row*(self.radius + 0.75*sep)

for i in range(self.n_row):
for j in range(self.n_col):
self.p.x[self.n_col*i+j,0] = mid - half + sep*i + self.radius*random.random()
self.p.x[self.n_col*i+j,1] = self.d.y_max - 2*sep - sep*j
# for i in range(self.n_row):
# for j in range(self.n_col):
# self.p.x[self.n_col*i+j,0] = mid - half + sep*i + self.radius*random.random()
# self.p.x[self.n_col*i+j,1] = self.d.y_max - 2*sep - sep*j

### ************************************************
### Compute forces
def forces(self):

# Removing lost particles requires to recompute the
# Adding or Removing particles requires to recompute the
# nearest neighbor lists. Everytime the check is done,
# we force the recomputation
force_nearest = False
if (self.it%self.check_freq == 0):

# Add new particles at the top
if (self.it%self.add_freq == 0):
n = 30
m = np.ones((n))*self.p.mass
r = np.ones((n))*self.p.radius
x = np.zeros((n,2))
c = self.colors[np.random.randint(0,len(self.colors),size=n)]

dx = (self.d.x_max - self.d.x_min)/n
for i in range(n):
x[i,0] = 0.5*dx + i*dx
x[i,1] = self.d.y_max - 0.5

self.p.add(n, m, r, x, c)
force_nearest = True

# Removing lost particles at the bottom
if (self.it%self.rmv_freq == 0):
self.check_particles(self.d)
force_nearest = True

Expand Down
Binary file added dem/save/silo_open.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions dem/src/core/particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@ def max_radius(self):
else:
return np.max(self.r)

### ************************************************
### Add n particles
def add(self, n, m, r, x, c):

self.np += n
self.m = np.append(self.m, m, axis=0)
self.r = np.append(self.r, r, axis=0)
self.x = np.append(self.x, x, axis=0)
self.d = np.append(self.d, np.zeros((n,2)), axis=0)
self.v = np.append(self.v, np.zeros((n,2)), axis=0)
self.a = np.append(self.a, np.zeros((n,2)), axis=0)
self.f = np.append(self.f, np.zeros((n,2)), axis=0)
self.e_wall = np.append(self.e_wall, np.ones((n))*self.mtr.e_wall, axis=0)
self.mu_wall = np.append(self.mu_wall, np.ones((n))*self.mtr.mu_wall, axis=0)
self.e_part = np.append(self.e_part, np.ones((n))*self.mtr.e_part, axis=0)
self.mu_part = np.append(self.mu_part, np.ones((n))*self.mtr.mu_part, axis=0)
self.Y = np.append(self.Y, np.ones((n))*self.mtr.Y, axis=0)
self.G = np.append(self.G, np.ones((n))*self.mtr.G, axis=0)
self.c = np.append(self.c, c)

### ************************************************
### Remove a list of particles
def delete(self, lst):
Expand Down