dropReload.py 4.02 KB
Newer Older
Matthieu Constant's avatar
Matthieu Constant committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# MigFlow - Copyright (C) <2010-2018>
# <Universite catholique de Louvain (UCL), Belgium
#  Universite de Montpellier, France>
# 	
# List of the contributors to the development of MigFlow: see AUTHORS file.
# Description and complete License: see LICENSE file.
# 	
# This program (MigFlow) is free software: 
# 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

# TESTCASE DESCRIPTION
Matthieu Constant's avatar
Matthieu Constant committed
25
26
# Example of reload
# This tescase presents the fall of a cloud made of particles in a viscous fluid (Stokes cloud) reloaded from drop.py test case.
Matthieu Constant's avatar
Matthieu Constant committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Physical parameters for the drops are the ones presented by Metzger et al. (2007) 
# "Falling clouds of particles in viscous fluids"

from migflow import fluid
from migflow import scontact

import numpy as np
import os
import time
import shutil

# Define output directory
outputdir = "output1"
outputrel = "output"
if not os.path.isdir(outputdir) :
    os.makedirs(outputdir)

# Physical parameters
g = -9.81                                       # gravity
rhop = 2450                                     # particles density
r = 154e-6                                      # particles radii
compacity = 0.20                                # solid volume fraction in the drop
rho = 1030                                      # fluid density
nu = 1.17/rho                                   # kinematic viscosity
rout = 3.3e-3                                   # cloud radius
mu = nu*rho                                     # dynamic viscosity
print("RHOP = %g, r = %g, RHO = %g" % (rhop,r,rho))

# Numerical parameters
outf = 1                                        # number of iterations between output files
dt = 5e-2                                       # time step
tEnd = 100                                      # final time

#
# PARTICLE PROBLEM
#
# Reload particles
iReload = 10                                    # iteration file reloaded
p = scontact.ParticleProblem(2)
p.read_vtk(outputrel,iReload)

# Initial time and iteration
t = 0
ii = 0
jj = 0
tEnd1 = 0.2

#
# FLUID PROBLEM
#
Matthieu Constant's avatar
Matthieu Constant committed
77
fluid = fluid.FluidProblem(2,g,[nu*rho],[rho],petsc_solver_type="-pc_type ilu -ksp_max_it 30")
Matthieu Constant's avatar
Matthieu Constant committed
78
# Set the mesh geometry for the fluid computation
Matthieu Constant's avatar
Matthieu Constant committed
79
80
81
82
fluid.load_msh("mesh.msh")
fluid.set_wall_boundary("Top", pressure=0)
fluid.set_wall_boundary("Bottom")
fluid.set_wall_boundary("Lateral")
Matthieu Constant's avatar
Matthieu Constant committed
83
84
fluid.import_vtk(outputrel+"/fluid_%05d.vtu"%iReload)

85
fluid.set_particles(p.mass(), p.volume(), p.position(), p.velocity(),reload=1)
Matthieu Constant's avatar
Matthieu Constant committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
ii = (iReload-1)*outf+1
t=ii*dt

#
# COMPUTATION LOOP
#
tic = time.time()

while t < tEnd : 
    # Fluid solver
    fluid.implicit_euler(dt)

    # Adaptation of the mesh.
    if (ii%15==0 and ii != 0):
       fluid.adapt_mesh(5e-3,8e-4,50000)
    
    # Computation of the new velocities
    forces = fluid.compute_node_force(dt)
    vn = p.velocity() + forces * dt / p.mass()
    vmax = np.max(np.hypot(vn[:, 0], vn[:, 1]))
    # Number of sub time step
    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()))
    # NLGS iterations
    for i in range(nsub) :
        p.iterate(dt/nsub, forces)  

    t += dt
114
    fluid.set_particles(p.mass(), p.volume(), p.position(), p.velocity())
Matthieu Constant's avatar
Matthieu Constant committed
115
116
117
118
119
120
121

    # Output files writting
    if ii %outf == 0 :
        ioutput = int(ii/outf) + 1
        p.write_vtk(outputdir, ioutput, t)
        fluid.export_vtk(outputdir, t, ioutput)
    ii += 1
122
    print("%i : %.2g/%.2g (cpu %.6g)" % (ii, t, tEnd, time.time() - tic))