darcy.py 5.7 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
# <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
from migflow import fluid as mbfluid
from migflow import scontact
25
from migflow import time_integration
Matthieu Constant's avatar
Matthieu Constant committed
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

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

class Darcy(unittest.TestCase) :
    def runTest(self) :
        dir_path = os.path.dirname(os.path.realpath(__file__))
        os.chdir(dir_path)


        outputdir = "output"
        if not os.path.isdir(outputdir) :
            os.makedirs(outputdir)
        subprocess.call(["gmsh", "-2", "mesh.geo","-clscale","1"])

        def genInitialPosition(filename, r, L, N, rhop) :
            p = scontact.ParticleProblem(2)
            #Loading of the mesh.msh file specifying physical boundaries name
            p.load_msh_boundaries("mesh.msh", ["Top", "Left", "Right","Bottom"])
            #Definition of the points where the grains are located
            e = L/N**.5
            #if e<2*r:
            #    print("Compacity too high!")
            #    exit(0)
            x = np.arange(-L+r, L-r, e)
            x_M = np.max(x)
            e_x = (L-r-x_M)/2
            y = np.arange(-L+r, L-r, e)
            y_M = np.max(y)
            e_y = (L-r-y_M)/2
            x = x+e_x
            y = y+e_y
            e_l = e-2*r
            x, y = np.meshgrid(x, y)
            x = x.flat
            y = y.flat
            for i in range(len(x)) :
                x_r = 0*random.uniform(-e_l/2,e_l/2)
                y_r = 0*random.uniform(-e_l/2,e_l/2)
                if x[i]+x_r<L-r and x[i]+x_r>r-L:
                    x[i] = x[i]+x_r
                if y[i]+y_r<L-r and y[i]+y_r>r-L:
                    y[i] = y[i]+y_r
74
                p.add_particle((x[i], y[i]), r, r**2 * np.pi * rhop)
Matthieu Constant's avatar
Matthieu Constant committed
75
76
77
78
            p.write_vtk(filename,0,0)

        n_test = 10
        c_v = np.linspace(0.01,0.85,n_test)
79
80
        c_v = [.5]
        n_test=1
Matthieu Constant's avatar
Matthieu Constant committed
81
82
83
84
85
86
        #c_v = np.array([0.1])
        pM = np.zeros_like(c_v)
        pm = np.zeros_like(c_v)
        Dp_drag = np.zeros_like(c_v)
        j = 0
        #physical parameters
Matthieu Constant's avatar
Matthieu Constant committed
87
        g =  np.array([0,0])                                      # gravity
Matthieu Constant's avatar
Matthieu Constant committed
88
89
        rho = 1000                                  # fluid density
        rhop = 1500                                 # grains density
90
        L = 1
Matthieu Constant's avatar
Matthieu Constant committed
91
92
93
94
95
        nu = 1e-3                                   # kinematic viscosity
        mu = 1
        r = 5e-3                                    # grains radius
        #numerical parameters
        dt = 0.001                                   # time step
96
        tEnd = dt*200                                 # final time
Matthieu Constant's avatar
Matthieu Constant committed
97
98
99
100
101
102
103
104
105
106
107
        outf = 10                                   # number of iterations between output files
        for compacity in c_v:
            a_g = np.pi*r**2
            a_b = L**2
            N = max(compacity*a_b/a_g,1)

            #Object particles creation
            genInitialPosition(outputdir, r, L, N, rhop)
            p = scontact.ParticleProblem(2)
            p.read_vtk(outputdir,0)
            ii = 0
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
108
            fluid = mbfluid.FluidProblem(2,g,mu,rho,drag_in_stab=True)
Matthieu Constant's avatar
Matthieu Constant committed
109
            fluid.load_msh("mesh.msh")
Michel Henry's avatar
Michel Henry committed
110
111
            U = 0.00001                                             # averaged fluid velocity
            fluid.solution()[:,0] = U
Jonathan Lambrechts's avatar
usolid    
Jonathan Lambrechts committed
112
            fluid.set_open_boundary("Left",velocity=[U,0])
Matthieu Constant's avatar
Matthieu Constant committed
113
            fluid.set_open_boundary("Right",pressure=0)
114
115
            fluid.set_wall_boundary("Bottom",velocity=[0,0])
            fluid.set_wall_boundary("Top",velocity=[0,0])
Michel Henry's avatar
Michel Henry committed
116
            fluid.set_particles(p.mass(), p.volume(), p.position(), p.velocity(), p.contact_forces())
117
            fluid.write_vtk(outputdir,0,0)
Matthieu Constant's avatar
Matthieu Constant committed
118
119
120
121
122
123
124

            t = 0
            ii = 0
            tic = time.time()
            #Computation loop
            while t < tEnd :
                #Fluid solver
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
125
                time_integration.iterate(fluid,p,dt,fixed_grains=True,check_residual_norm=1e-4)
Matthieu Constant's avatar
Matthieu Constant committed
126
127
128
129
130
                t += dt
                #Output files writting
                if ii %outf == 0 :
                    ioutput = int(ii/outf) + 1
                    p.write_vtk(outputdir, ioutput, t)
131
                    fluid.write_vtk(outputdir, ioutput, t)
Matthieu Constant's avatar
Matthieu Constant committed
132
133
134
                ii += 1
                print("%i : %.2g/%.2g (cpu %.6g)" % (ii, t, tEnd, time.time() - tic))
            
Michel Henry's avatar
Michel Henry committed
135
            gamma = (0.63*U/(1-compacity)+4.8*(mu/((1-compacity)*rho*2*r))**0.5)**2*(1-compacity)**-1.8*rho*r
Matthieu Constant's avatar
Matthieu Constant committed
136
137
            vol = (np.pi*r**2)
            N = compacity/vol
Michel Henry's avatar
Michel Henry committed
138
            Dp_drag[j] =  gamma*N*U/(1-compacity)**2
139
140
            pM[j] = np.mean(fluid.solution()[fluid.coordinates()[:,0]<-.99,2])
            pm[j] = np.mean(fluid.solution()[fluid.coordinates()[:,0]>.99,2])
Matthieu Constant's avatar
Matthieu Constant committed
141
142
            j = j+1

143
        dp = (pM-pm)/(2*L)
144
145
        print(dp)
        print(Dp_drag)
Matthieu Constant's avatar
Matthieu Constant committed
146
        error = np.sum(abs(dp-Dp_drag)/Dp_drag)/n_test
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
147
        self.assertLess(error,1./10., "error is too large in darcy")