poiseuille.py 4.44 KB
Newer Older
Jonathan Lambrechts's avatar
Jonathan Lambrechts 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
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
# Marblesbag - Copyright (C) <2010-2018>
# <Universite catholique de Louvain (UCL), Belgium
#  Universite de Montpellier, France>
# 	
# List of the contributors to the development of Marblesbag: see AUTHORS file.
# Description and complete License: see LICENSE file.
# 	
# This program (Marblesbag) 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
from marblesbag import fluid as mbfluid
from marblesbag import scontact2

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

class Poiseuille(unittest.TestCase) :
    def runTest(self) :
        dir_path = os.path.dirname(os.path.realpath(__file__))
        os.chdir(dir_path)
        # Physical parameters for the drops are the ones presented by Metzger et al. (2007) "Falling clouds of particles in viscous fluids"

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

        subprocess.call(["gmsh", "-2", "mesh.geo","-clscale","2"])
        t = 0
        ii = 0


        #physical parameters
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
50
        g =  0                                      # gravity
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
        rho = 1000                                      # fluid density
        nu = 1e-3                                   # kinematic viscosity
        mu = nu*rho                                     # dynamic viscosity
        tEnd = 100000                                     # final time

        #numerical parameters
        lcmin = .1                                  # mesh size
        dt = 10                                       # time step
        alpha = 1e-4                                    # stabilization coefficient
        epsilon = alpha*lcmin**2 /nu                    # stabilization parametre
        print('epsilon',epsilon)

        shutil.copy("mesh.msh", outputdir +"/mesh.msh")

65
        outf = 1                                       # number of iterations between output files
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
66
67

        #Object fluid creation + Boundary condition of the fluid (field 0 is horizontal velocity; field 1 is vertical velocity; field 2 is pressure)
68
69
70
71
72
73
74
75
76
77
78
        fluid = mbfluid.fluid_problem(g,nu*rho,rho)
        fluid.set_strong_boundary("RightUp",2,0.)
        fluid.set_strong_boundary("RightDown",2,0.)
        fluid.set_strong_boundary("Top",0,0)
        fluid.set_strong_boundary("Bottom",0,0)
        fluid.set_strong_boundary("LeftUp",1,0)
        fluid.set_strong_boundary("RightUp",1,0)
        fluid.set_strong_boundary("LeftDown",1,0)
        fluid.set_strong_boundary("RightDown",1,0)
        fluid.set_strong_boundary("LeftUp",0,lambda x : 1/(20*mu)*x[:,1]*(1-x[:, 1]))
        fluid.set_strong_boundary("LeftDown",0,lambda x : 1/(20*mu)*x[:,1]*(1-x[:, 1]))
79
        fluid.load_msh("mesh.msh")
80
81
82
83
84
85
86
87
        fluid.set_weak_boundary("LeftUp","Inflow")
        fluid.set_weak_boundary("LeftDown","Inflow")
        fluid.set_weak_boundary("Bottom","Wall")
        fluid.set_weak_boundary("Top","Wall")
        fluid.set_weak_boundary("RightUp","Outflow")
        fluid.set_weak_boundary("RightDown","Outflow")


Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
88
89
90
91
        ii = 0
        t = 0

        #set initial_condition
Matthieu Constant's avatar
Matthieu Constant committed
92
    
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
        fluid.export_vtk(outputdir,0,0)

        ii = 0
        tic = time.clock()
        while ii < 100 : 
            #Fluid solver
            fluid.implicit_euler(dt)
            t += dt
            #Output files writting
            if ii %outf == 0 :
                ioutput = int(ii/outf) + 1
                fluid.export_vtk(outputdir, t, ioutput)
            ii += 1
            print("%i : %.2g/%.2g (cpu %.6g)" % (ii, t, tEnd, time.clock() - tic))
            
        s = fluid.solution()
        x = fluid.coordinates()
        vel = (s[:,0]-1/(20*nu*rho)*x[:,1]*(1-x[:, 1]))**2
Matthieu Constant's avatar
Matthieu Constant committed
111
        vS = np.sum((1/(20*nu*rho)*x[:,1]*(1-x[:, 1]))**2)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
112
113
        print('Error', (vel.sum())**.5)

114
        self.assertLess(vel.sum()**.5,(vS**0.5)/50, "error is too large in Poiseuille")