avalanch1fluidfriction.py 3.65 KB
Newer Older
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
1
# MigFlow - Copyright (C) <2010-2020>
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
# <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:
# Collapsing of a grain column in fluid. 
# This test case cannot be runned on its own, it requires the output files of the depot test case (../depot/depot.py) to create a compact column as initial situation
# Positions, masses and radii of grains are setted in the depot.py file.
from migflow import fluid
from migflow import scontact
from migflow import time_integration

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

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

# Physical parameters
g = np.array([0,-9.81])                   # gravity
rhop = 1500                               # grains density
rhof = 1000                               # fluid density
nuf = 1e-6                                # kinematic fluid viscosity

# Numerical parameters
outf = 20                                 # number of iterations between output files
dt = 5e-4                                 # time step
tEnd = 10                                 # final time

# 
# PARTICLES PROBLEM
#
# Particles container structure builder to load file created with depot.py.
p1 = scontact.ParticleProblem(2)
# Use particles deposit computed by the depot.py file of "depot" folder.
p1.read_vtk("../depot/output",25)
# New particles container structure builder to set other boundary conditions than in depot.py.
p = scontact.ParticleProblem(2,True)
p.load_msh_boundaries("mesh.msh", ["Top", "Bottom", "Left", "Right"],material="Steel")
p.add_particles(p1.position(),p1.r(),p1.mass(),v=p1.velocity(),tag="Sand")

p.set_friction_coefficient(0.3,"Sand", "Sand")
p.set_friction_coefficient(0.5,"Steel", "Sand")
p.write_vtk(outputdir, 0, 0)

# Initial time and iteration.
t = 0
ii = 0

#
# FLUID PROBLEM
#
# Fluid structure builder.
fluid = fluid.FluidProblem(2,g,[nuf*rhof],[rhof])
# Set the mesh geometry for the fluid computation.
fluid.load_msh("mesh.msh")
fluid.set_wall_boundary("Bottom")
fluid.set_wall_boundary("Left")
fluid.set_wall_boundary("Top",pressure=0)
fluid.set_wall_boundary("Right")
# Set locations of the grains in the mesh and compute the porosity in each computation cell.
Nathan Coppin's avatar
Nathan Coppin committed
85
fluid.set_particles(p.mass(), p.volume(), p.position(), p.velocity(),p.contact_forces())
86
# Write output files for post-visualization.
Nathan Coppin's avatar
Nathan Coppin committed
87
fluid.write_vtk(outputdir,0,0)
88
89
90
91
92
93

tic = time.time()
# 
# COMPUTATION LOOP
# 
while t < tEnd : 
Nathan Coppin's avatar
Nathan Coppin committed
94
    time_integration.iterate(fluid,p,dt,min_nsub=5,external_particles_forces=g*p.mass())
95
96
97
98
99
    t += dt
    # Output files writing.
    if ii%outf == 0 :
        ioutput = int(ii/outf) + 1
        p.write_vtk(outputdir, ioutput, t)
Nathan Coppin's avatar
Nathan Coppin committed
100
        fluid.write_vtk(outputdir, ioutput, t)
101
102
    ii += 1
    print("%i : %.2g/%.2g (cpu %.6g)" % (ii, t, tEnd, time.time() - tic))