Terfous.py 2.62 KB
Newer Older
Matthieu Constant's avatar
Matthieu Constant committed
1
2
3
4
5
6
7
8
9
10
#!/usr/bin/env python
from marblesbag import fluid as fluid
from marblesbag import scontact2

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

Matthieu Constant's avatar
Matthieu Constant committed
11
def genInitialPosition(filename, r, rhop) :
Matthieu Constant's avatar
Matthieu Constant committed
12
13
14
15
16
    p = scontact2.ParticleProblem()
    p.load_msh_boundaries("mesh.msh", ["Top", "Bottom","Left","Right"])
        
    p.add_particle((0, 0), r, r**2 * np.pi * rhop);

Matthieu Constant's avatar
Matthieu Constant committed
17
    p.position()[:, 1] += 1.7
Matthieu Constant's avatar
Matthieu Constant committed
18
19
20
21
    p.write(filename)



Matthieu Constant's avatar
Matthieu Constant committed
22
outputdir = "outputc"
Matthieu Constant's avatar
Matthieu Constant committed
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
if not os.path.isdir(outputdir) :
    os.makedirs(outputdir)

t = 0
ii = 0

r=4e-3
p = scontact2.ParticleProblem()
#R = np.random.uniform(45e-06, 90e-06, len(x))

#physical parameters
g =  -9.81
rho = 793
rhop = 1380
nu = 2.19e-3#/(10**0.5)
V = 0.5 # todo : estimate V base on limit velocity
print('V',V)
tEnd = 10000

#numerical parameters
lcmin = 0.005 # approx r*100 but should match the mesh size
dt = 1e-2
alpha = 2.5e-4
epsilon = alpha*lcmin**2 /nu#2e-2*c*h*2#2e-2*c*h # ?? not sure ??1e-5
autoEpsilon = False
print('epsilon',epsilon)

shutil.copy("mesh.msh", outputdir +"/mesh.msh")
#scontact2Interface.MeshLoader(p, "funnel.msh", ("Funnel", "Top", "Bottom", "Lateral"))
p.write(outputdir+"/part-00000")

Matthieu Constant's avatar
Matthieu Constant committed
54
genInitialPosition(outputdir + "/part-00000", r, rhop)
Matthieu Constant's avatar
Matthieu Constant committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

p = scontact2.ParticleProblem(outputdir+"/part-00000")

print("r = %g, m = %g\n" %  (p.r()[0], p.mass()[0]))
print("RHOP = %g" % rhop)
outf = 1
outf1 = 100000

strong_boundaries = [("Top",2,0.),("Top",1,0.),("Top",0,0.),("Bottom",1,0.),("Bottom",0,0.),("Left",0,0.),("Left",1,0.),("Right",0,0.),("Right",1,0.)]
fluid = fluid.fluid_problem("mesh.msh",g,nu*rho,rho,epsilon,autoEpsilon,strong_boundaries)

fluid.set_particles(p.mass(), p.volume(), p.position(), p.velocity())
fluid.export(outputdir,0,0)

ii = 0
    

tic = time.clock()
forces = g*p.mass()
while t < tEnd : 
Matthieu Constant's avatar
Matthieu Constant committed
75
    forces = fluid.compute_node_force(dt,10*r)
Matthieu Constant's avatar
Matthieu Constant committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
    vn = p.velocity() + forces * dt / p.mass()
    vmax = np.max(np.hypot(vn[:, 0], vn[:, 1]))
    nsub = max(1, int(np.ceil((vmax * dt * 4)/min(10*p.r()))))
    print("NSUB", nsub,"VMAX",vmax, "VMAX * dt", vmax * dt, "r", min(p.r()))
    for i in range(nsub) :
        p.iterate(dt/nsub, forces)  
    fluid.set_particles(p.mass(), p.volume(), p.position(), p.velocity())
    fluid.implicit_euler(dt)
    t += dt
    if ii %outf == 0 :
        ioutput = int(ii/outf) + 1
        p.write_vtk(outputdir, ioutput, t)
        p.write(outputdir+"/part-%05d" % ioutput)
        p.write_boundary_vtk(outputdir, ioutput, t)
        fluid.export(outputdir, t, ioutput)
    ii += 1
    print("%i : %.2g/%.2g (cpu %.6g)" % (ii, t, tEnd, time.clock() - tic))