couette.py 4.84 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# 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
# Grains in circular shear flow generated by a rotating drum.
# This example shows how to set boundary conditions as a function of some parameters.

# A boolean parameter gives the possibility to use lmgc90 to solve contacts instead of scontact.
use_lmgc90 = False

from migflow import fluid
from migflow import scontact
from migflow import time_integration
if use_lmgc90 :
    from migflow import lmgc90Interface

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

def genInitialPosition(filename, r, rout, rin, rhop) :
    """Create a container to initialize particles and write particles in an initial output file.

    Keyword arguments:
    filename -- directory to write the output file
    r -- max particle radius
    rout -- outer radius of the drum
    rhop -- particle density
    """
    # Grains structure builder
    p = scontact.ParticleProblem(2)
    # Load mesh.msh file specifying physical boundaries names
    p.load_msh_boundaries("mesh.msh", ["Outer", "Inner"],material="Steel")
    
    # Definition of the points where the grains are located
    x = np.arange(rout, -rout, 2.5 * -r)
    x, y = np.meshgrid(x, x)
    R2 = x**2 + y**2
    # Condition to be inside the outer boundary
    keep = R2 < (rout-r)**2
    x = x[keep]
    y = y[keep]
    R2 = x**2 + y**2
    # Condition to be outside the inner boundary
    keep = R2 > (rin+r)**2
    x = x[keep]
    y = y[keep]
    # Add a grain at each centre position
    for i in range(x.shape[0]) :
        if y[i]<rout:
            rhop1 = random.choice([rhop*.9,1.1*rhop,rhop])
            p.add_particle((x[i], y[i]), r, r**2 * np.pi * rhop1,"Sand")
    p.write_vtk(filename,0,0)
 


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

# Physical parameters
g = 0                                          # gravity
rho = 1.253e3                                  # fluid density
rhop = 1000                                    # grains density
nu = 1e-3                                      # kinematic viscosity

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

# Geometry parameters
outf = 50                                      # number of iterations between output files
rout = 0.0254                                  # outer radius
rin = 0.0064                                   # inner radius
r = 397e-6/2                                   # grains radius

#
# PARTICLE PROBLEM
#
# Object particles creation
genInitialPosition(outputdir, r, rout, rin, rhop)
if use_lmgc90 :
Matthieu Constant's avatar
Matthieu Constant committed
106
    friction = 0.1                             # friction coefficient
107
108
109
110
111
    lmgc90Interface.scontactTolmgc90(outputdir,2,0,friction)
    p = lmgc90Interface.ParticleProblem(2)
else :
  p = scontact.ParticleProblem(2,True)
  p.read_vtk(outputdir,0)
Matthieu Constant's avatar
Matthieu Constant committed
112
113
  p.set_friction_coefficient(0.1,"Sand","Sand") # Particle-Particle
  p.set_friction_coefficient(0.1,"Sand","Steel")# Particle-Wall
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

# Initial time and iteration
t = 0
ii = 0

#
# FLUID PROBLEM
#
fluid = fluid.FluidProblem(2,g,[nu*rho],[rho])
# Set the mesh geometry for the fluid computation
fluid.load_msh("mesh.msh")
fluid.set_wall_boundary("Outer",velocity=[0,0],pressure=0)
fluid.set_wall_boundary("Inner",velocity=[lambda x : -x[:, 1]/10,lambda x : x[:, 0]/10])
# Set location of the grains 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)
fluid.export_vtk(outputdir,0,0)

tic = time.time()

# 
# COMPUTATION LOOP
#
while t < tEnd :
137
    time_integration.iterate(fluid, p, dt)
138
139
140
141
142
143
144
145
    t += dt
    # 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
    print("%i : %.2g/%.2g (cpu %.6g)" % (ii, t, tEnd, time.time()-tic))