shaker.py 4.34 KB
Newer Older
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
1
# MigFlow - Copyright (C) <2010-2018>
2
3
# <Universite catholique de Louvain (UCL), Belgium
#  Universite de Montpellier, France>
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
4
# 	
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
5
# List of the contributors to the development of MigFlow: see AUTHORS file.
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
6
7
# Description and complete License: see LICENSE file.
# 	
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
8
# This program (MigFlow) is free software: 
9
# you can redistribute it and/or modify it under the terms of the GNU Lesser General 
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
10
11
12
13
14
15
# Public License as published by the Free Software Foundation, either version
# 3 of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
# GNU Lesser General Public License for more details.
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
17
# 
18
19
# You should have received a copy of the GNU Lesser General Public License
# along with this program (see COPYING and COPYING.LESSER files).  If not, 
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
20
21
# see <http://www.gnu.org/licenses/>.

Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
22
#!/usr/bin/env python
Matthieu Constant's avatar
Matthieu Constant committed
23
24
25
26
27

# TESTCASE DESCRIPTION
# Sort particles with respect to their mass by jigging the granular matrix
from migflow import fluid
from migflow import scontact
Matthieu Constant's avatar
Matthieu Constant committed
28
from migflow import time_integration
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
29
30
31
32
33
34
35
36

import numpy as np
import os
import time
import shutil
import random

def genInitialPosition(filename, r, ly, rhop) :
Matthieu Constant's avatar
Matthieu Constant committed
37
38
39
40
41
42
43
44
    """Set all the particles centre positions and create the particles objects to add in the computing structure
    
    Keyword arguments:    
    filename -- name of the output file
    r -- radius of the particles
    ly - particles area height
    rhop -- particles density        
    """
Matthieu Constant's avatar
Matthieu Constant committed
45
    p = scontact.ParticleProblem(2)
Matthieu Constant's avatar
Matthieu Constant committed
46
    # Loading of the mesh.msh file specifying physical boundaries name
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
47
    p.load_msh_boundaries("mesh.msh", ["Top", "Lateral","Bottom","BottomOut","TopOut"])
Matthieu Constant's avatar
Matthieu Constant committed
48
49
50
    # Definition of the points where the grains are located
    x = np.arange(-0.5+r, 0.5-r+1e-10, 2*r)
    y = np.arange(-ly/2+r, 0.5*ly/2-r, 2*r)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
51
52
53
54
55
    x, y = np.meshgrid(x, y)
    x = x.flat
    y = y.flat
    for i in range(len(x)) :
        rhop = random.choice([1100,1350,1600])
Matthieu Constant's avatar
Matthieu Constant committed
56
        # Addition of a particle object at each point
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
57
58
59
60
61
62
63
        p.add_particle((x[i], y[i]), r, r**2 * np.pi * rhop);
    p.write_vtk(filename,0,0)

outputdir = "output"
if not os.path.isdir(outputdir) :
    os.makedirs(outputdir)

Matthieu Constant's avatar
Matthieu Constant committed
64
# physical parameters
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
65
66
67
68
69
70
71
g =  -9.81                                  # gravity
rho = 1000                                  # fluid density
rhop = 1500                                 # grains density
nu = 1e-6                                   # kinematic viscosity
r = 5e-3                                    # grains radius
ly = 1                                      # box height

Matthieu Constant's avatar
Matthieu Constant committed
72
73
74
75
# numerical parameters
dt = 5e-3                                   # time step
tEnd = 100                                  # final time
outf = 10                                   # number of iterations between output files
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
76

Matthieu Constant's avatar
Matthieu Constant committed
77
78
79
80
#
# PARTICLE PROBLEM
#
# Initialise particles
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
81
genInitialPosition(outputdir, r, ly, rhop)
Matthieu Constant's avatar
Matthieu Constant committed
82
p = scontact.ParticleProblem(2)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
83
84
p.read_vtk(outputdir,0)

Matthieu Constant's avatar
Matthieu Constant committed
85
86
87
print("r = %g, m = %g" %  (p.r()[0], p.mass()[0]))
print("RHOP = %g" % rhop)
print("number of grains = %d"%len(p.r()))
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
88

Matthieu Constant's avatar
Matthieu Constant committed
89
90
91
# Initial time and iteration
t         =  0
ii        =  0
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
92

Matthieu Constant's avatar
Matthieu Constant committed
93
94
95
#
# FLUID PROBLEM
#
Matthieu Constant's avatar
Matthieu Constant committed
96
fluid = fluid.FluidProblem(2,g,nu*rho,rho)
Matthieu Constant's avatar
Matthieu Constant committed
97
# Set the mesh geometry for the fluid computation
Matthieu Constant's avatar
Matthieu Constant committed
98
fluid.load_msh("mesh.msh")
Matthieu Constant's avatar
Matthieu Constant committed
99
100
101
# periodic boundary condition function
def outerBndV(x) :
    return 0.15*max(np.sin(-t*np.pi*2./5-4*np.pi/5),0)
Matthieu Constant's avatar
Matthieu Constant committed
102
103
104
105
106
fluid.set_wall_boundary("Lateral")
fluid.set_open_boundary("Bottom",velocity=[0, outerBndV])
fluid.set_open_boundary("BottomOut",velocity=[0, outerBndV])
fluid.set_open_boundary("TopOut",pressure=0)
fluid.set_open_boundary("Top",pressure=0)
Matthieu Constant's avatar
Matthieu Constant committed
107
108
# Set location of the particles in the mesh and compute the porosity in each computation cell
fluid.set_particles(p.mass(), p.volume(), p.position(), p.velocity(), p.contact_forces(), init=True)
Matthieu Constant's avatar
Matthieu Constant committed
109
fluid.export_vtk(outputdir,0,0)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
110

Matthieu Constant's avatar
Matthieu Constant committed
111
tic = time.time()
Matthieu Constant's avatar
Matthieu Constant committed
112
113
114
115
116
G = np.zeros_like(p.velocity())
G[:,1] = p.mass()[:,0]*g
#
# COMPUTATION LOOP
#
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
117
while t < tEnd :
Matthieu Constant's avatar
Matthieu Constant committed
118
    time_integration.iterate(fluid, p, dt, min_nsub=25, external_particles_forces=G)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
119
    t += dt
Matthieu Constant's avatar
Matthieu Constant committed
120
    # Output files writting
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
121
122
123
124
125
    if ii %outf == 0 :
        ioutput = int(ii/outf) + 1
        p.write_vtk(outputdir, ioutput, t)
        fluid.export_vtk(outputdir, t, ioutput)
    ii += 1
Matthieu Constant's avatar
Matthieu Constant committed
126
    print("%i : %.2g/%.2g (cpu %.6g)" % (ii, t, tEnd, time.time() - tic))