vortices.py 4.92 KB
Newer Older
Matthieu Constant's avatar
Matthieu Constant committed
1
# MigFlow - Copyright (C) <2010-2018>
2
3
4
# <Universite catholique de Louvain (UCL), Belgium
#  Universite de Montpellier, France>
# 	
Matthieu Constant's avatar
Matthieu Constant committed
5
# List of the contributors to the development of MigFlow: see AUTHORS file.
6
7
# Description and complete License: see LICENSE file.
# 	
Matthieu Constant's avatar
Matthieu Constant committed
8
# This program (MigFlow) is free software: 
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# you can redistribute it and/or modify it under the terms of the GNU Lesser General 
# 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
# GNU Lesser General Public License for more details.
# 
# 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, 
# see <http://www.gnu.org/licenses/>.

#!/usr/bin/env python
Matthieu Constant's avatar
Matthieu Constant committed
23
24
from migflow import fluid 
from migflow import scontact
Frédéric Dubois's avatar
Frédéric Dubois committed
25
from migflow import lmgc90Interface
26
27
28
29
30
31
32
33
34
35
36
37
38
39

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

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

t = 0
ii = 0

Matthieu Constant's avatar
Matthieu Constant committed
40
p = scontact.ParticleProblem(2)
41
42
43
44
45
46
47
48
49
50
51
52
53

#physical parameters
g =  -9.81                                            #gravity
rho = 1000                                            #fluid density
nu = 5e-5                                             #kinematic viscosity
rhop = 2500                                           #grains density

#numerical parameters
dt = 1e-3                                             #time step
tEnd = 50                                             #final time


#read the deposit achieve with dep.py
Matthieu Constant's avatar
Matthieu Constant committed
54
p1 = scontact.ParticleProblem(2)
55
56
57
58
59
60
p1.read_vtk("outputdep",15)
p.load_msh_boundaries("mesh.msh", ["Top", "Bottom", "Vertical","InnerLeft","InnerRight"])
for i in range(len(p1.position()[:,0])):
    p.add_particle((p1.position()[i,0], p1.position()[i,1]), p1.r()[i], p1.r()[i]**2 * np.pi * rhop)
p.write_vtk(outputdir, 0, 0)

Frédéric Dubois's avatar
Frédéric Dubois committed
61
62
63
#Use lmgc90 for friction or not without friction
use_lmgc90 = True
if use_lmgc90 :
64
    friction=0.3                                      #friction coefficient
Frédéric Dubois's avatar
Frédéric Dubois committed
65
66
    lmgc90Interface.scontactTolmgc90(outputdir, 2, 0, friction)
    p = lmgc90Interface.ParticleProblem(2)
67
else :
Matthieu Constant's avatar
Matthieu Constant committed
68
    p = scontact.ParticleProblem(2)
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
    p.read_vtk(outputdir,0)


outf = 10
outf1 = 100000

ii = 0

#Function defining the rotation of the inner boundaries
#Parameters:
#              -x:     coordinates of the point on the circle (x for vertical velocity and y for horizontal velocity)
#              -c:     centre of the circle (go along with x)
#              -A:     amplitude of the periodic signal
#              -T:     periode
#              -s:     sign for the rotation
def Bnd(x,c,A,T,s) :
    return s*A*(x[:]-c)*np.sin(t*np.pi*2./T)

Matthieu Constant's avatar
Matthieu Constant committed
87
88
89
90
91
92
93
94
# The following parameters depends on the mesh.geo
rin = 2.5e-4                                          # inner radius of vortices
xc = 1.5e-3                                           # absolute x-centre
yc = 3e-4                                             # absolute y-centre
# The following parameters depends on the physical problem
omega = 1e-5                                          # max absolute angular velocity
A = omega                                             # amplitude of periodic signal
T = 5                                                 # period
95
96

#initialise the fluid problem
Matthieu Constant's avatar
Matthieu Constant committed
97
98
99
100
101
102
103
104
105
106
fluid = fluid.FluidProblem(2,g,nu*rho,rho)
fluid.load_msh("mesh.msh")
fluid.set_strong_boundary("InnerLeft",0,lambda x : Bnd(x[:,1],yc,A,T,-1))
fluid.set_strong_boundary("InnerLeft",1,lambda x: Bnd(x[:,0],-xc,A,T,1))
fluid.set_strong_boundary("InnerRight",0,lambda x : Bnd(x[:,1],yc,A,T,1))
fluid.set_strong_boundary("InnerRight",1,lambda x : Bnd(x[:,0],xc,A,T,-1))
fluid.set_strong_boundary("Top",2,0.)
fluid.set_strong_boundary("Bottom",1,0.)
fluid.set_strong_boundary("Top",1,0)
fluid.set_strong_boundary("Vertical",0,0)
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
fluid.set_particles(p.mass(), p.volume(), p.position(), p.velocity())
fluid.export_vtk(outputdir,0,0)

tic = time.clock()
#computation loop
while t < tEnd : 
    fluid.set_particles(p.mass(), p.volume(), p.position(), p.velocity())
    fluid.implicit_euler(dt)
    forces = fluid.compute_node_force(dt)
    vn = p.velocity() + forces * dt / p.mass()
    vmax = np.max(np.hypot(vn[:, 0], vn[:, 1]))
    nsub = max(1, int(np.ceil((vmax * dt * 4)/min(p.r()))))
    print("NSUB", nsub,"VMAX",vmax, "VMAX * dt", vmax * dt, "r", min(p.r()))
    for i in range(nsub) :
        p.iterate(dt/nsub, forces)  
    t += dt
    if ii %outf == 0 :
        ioutput = int(ii/outf) + 1
        p.write_vtk(outputdir, ioutput, t)
        fluid.export_vtk(outputdir, t, ioutput)
    ii += 1
    print("%i : %.2g/%.2g (cpu %.6g)" % (ii, t, tEnd, time.clock() - tic))