inject2f.py 2.59 KB
Newer Older
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
1
# MigFlow - Copyright (C) <2010-2020>
Matthieu Constant's avatar
Matthieu Constant committed
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
# <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
# Injection of a light fluid in a heavier fluid
from migflow import fluid

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 =  -9.81                                      # gravity
rho0 = 900                                      # fluid density
rho1 = 1000
nu1 = 1e-6                                   # kinematic viscosity
nu0 = nu1
r = 5e-4
N = 10000
rhop = 1500
# numerical parameters
tEnd = 10                                     # final time
dt = .01                                       # time step
outf = 1                                       # number of iterations between output files

def outerBndV(x) :
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
53
54
    l2 = x[:,0]**2+x[:,2]**2
    a = np.where(l2 < 0.03**2, 0.4*max(np.sin(t*np.pi*2./1),0),0)
Matthieu Constant's avatar
Matthieu Constant committed
55
56
57
58
    return a


fluid = fluid.FluidProblem(3,g,[nu0*rho0,nu1*rho1],[rho0,rho1])
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
59
#fluid = fluid.FluidProblem(3,g,[nu1*rho1],[rho1])
Matthieu Constant's avatar
Matthieu Constant committed
60
61
62
63
64
65
66
67
68
69
70
fluid.load_msh("mesh.msh")
fluid.set_wall_boundary("XVel")
fluid.set_wall_boundary("ZVel")
fluid.set_open_boundary("Top",pressure=0,concentration=0)
fluid.set_open_boundary("Bottom",velocity=[0,outerBndV,0],concentration=1)

#fluid.set_concentration_cg(np.where(fluid.coordinates()[:,1]>0.32,1,0))

ii = 0
t = 0

Nathan Coppin's avatar
Nathan Coppin committed
71
72

fluid.write_vtk(outputdir,0,0)
Matthieu Constant's avatar
Matthieu Constant committed
73
74
75
76
77
78
79
80
tic = time.time()
while t < tEnd : 
    #Fluid solver
    fluid.implicit_euler(dt)
    t += dt
    #Output files writting
    if ii %outf == 0 :
        ioutput = int(ii/outf) + 1
Nathan Coppin's avatar
Nathan Coppin committed
81
        fluid.write_vtk(outputdir, ioutput, t)
Matthieu Constant's avatar
Matthieu Constant committed
82
83
    ii += 1
    print("%i : %.2g/%.2g (cpu %.6g)" % (ii, t, tEnd, time.time() - tic))