Commit 80c750b2 authored by Matthieu Constant's avatar Matthieu Constant
Browse files

update couette-2d and mill-2d

parent f01123be
Pipeline #5571 passed with stage
in 2 minutes and 8 seconds
......@@ -4,7 +4,7 @@ import numpy as np
def pred_corr_solver(fluid, p, dt, min_nsub=1, tol=1e-8, alpha=0.5, bi_fluids=False) :
# Give to the fluid the solid information
fluid.set_particles(p.mass(), p.volume(), p.position(), p.velocity(),p.contact_forces())
fluid.set_particles(p.mass(), p.volume(), p.position(), p.velocity(), p.contact_forces())
# Copy the fluid solution of the previous time step before computing the prediction
sf0 = np.copy(fluid.solution())
# Copy the solid solution of the previous time step before computing the prediction
......
# MigFlow - Copyright (C) <2010-2018>
# <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
# Grains in circular shear flow generated by a rotating drum.
# This example shows how to set boundary conditions as a function of some parameters.
# A boolean parameter gives the possibility to use lmgc90 to solve contacts instead of scontact.
use_lmgc90 = False
from migflow import fluid
from migflow import scontact
from migflow import time_integration
if use_lmgc90 :
from migflow import lmgc90Interface
import numpy as np
import os
import time
import shutil
import random
def genInitialPosition(filename, r, rout, rin, rhop) :
"""Create a container to initialize particles and write particles in an initial output file.
Keyword arguments:
filename -- directory to write the output file
r -- max particle radius
rout -- outer radius of the drum
rhop -- particle density
"""
# Grains structure builder
p = scontact.ParticleProblem(2)
# Load mesh.msh file specifying physical boundaries names
p.load_msh_boundaries("mesh.msh", ["Outer", "Inner"],material="Steel")
# Definition of the points where the grains are located
x = np.arange(rout, -rout, 2.5 * -r)
x, y = np.meshgrid(x, x)
R2 = x**2 + y**2
# Condition to be inside the outer boundary
keep = R2 < (rout-r)**2
x = x[keep]
y = y[keep]
R2 = x**2 + y**2
# Condition to be outside the inner boundary
keep = R2 > (rin+r)**2
x = x[keep]
y = y[keep]
# Add a grain at each centre position
for i in range(x.shape[0]) :
if y[i]<rout:
rhop1 = random.choice([rhop*.9,1.1*rhop,rhop])
p.add_particle((x[i], y[i]), r, r**2 * np.pi * rhop1,"Sand")
p.write_vtk(filename,0,0)
# Define output directory
outputdir = "output"
if not os.path.isdir(outputdir) :
os.makedirs(outputdir)
# Physical parameters
g = 0 # gravity
rho = 1.253e3 # fluid density
rhop = 1000 # grains density
nu = 1e-3 # kinematic viscosity
# Numerical parameters
dt = 1e-3 # time step
tEnd = 50 # final time
# Geometry parameters
outf = 50 # number of iterations between output files
rout = 0.0254 # outer radius
rin = 0.0064 # inner radius
r = 397e-6/2 # grains radius
#
# PARTICLE PROBLEM
#
# Object particles creation
genInitialPosition(outputdir, r, rout, rin, rhop)
if use_lmgc90 :
friction = 0.1 # friction coefficient
lmgc90Interface.scontactTolmgc90(outputdir,2,0,friction)
p = lmgc90Interface.ParticleProblem(2)
else :
p = scontact.ParticleProblem(2,True)
p.read_vtk(outputdir,0)
p.set_friction_coefficient(0.1,"Sand","Sand")#Particle-Particle
p.set_friction_coefficient(0.1,"Sand","Steel")#Particle-Wall
# Initial time and iteration
t = 0
ii = 0
#
# FLUID PROBLEM
#
fluid = fluid.FluidProblem(2,g,[nu*rho],[rho])
# Set the mesh geometry for the fluid computation
fluid.load_msh("mesh.msh")
fluid.set_wall_boundary("Outer",velocity=[0,0],pressure=0)
fluid.set_wall_boundary("Inner",velocity=[lambda x : -x[:, 1]/10,lambda x : x[:, 0]/10])
# Set location of the grains in the mesh and compute the porosity in each computation cell
fluid.set_particles(p.mass(), p.volume(), p.position(), p.velocity(), p.contact_forces(), init=True)
fluid.export_vtk(outputdir,0,0)
tic = time.time()
#
# COMPUTATION LOOP
#
while t < tEnd :
time_integration.pred_corr_solver(fluid, p, dt)
t += dt
# Output files writting
if ii %outf == 0 :
ioutput = int(ii/outf) + 1
p.write_vtk(outputdir, ioutput, t)
fluid.export_vtk(outputdir, t, ioutput)
ii += 1
print("%i : %.2g/%.2g (cpu %.6g)" % (ii, t, tEnd, time.time()-tic))
......@@ -22,6 +22,7 @@
#!/usr/bin/env python
from migflow import scontact
from migflow import fluid
from migflow import time_integration
import numpy as np
import os
......@@ -103,33 +104,15 @@ fluid.load_msh("mesh.msh")
#fluid.set_strong_boundary("Outer",1,lambda x : (-x[:,0]/rout)*-v)
fluid.set_wall_boundary("Outer",0,velocity = [lambda x : (x[:,1]/rout)*-v, lambda x : (-x[:,0]/rout)*-v])
# Set location of the grains in the mesh and compute the porosity in each computation cell
fluid.set_particles(p.mass(), p.volume(), p.position(), p.velocity())
fluid.set_particles(p.mass(), p.volume(), p.position(), p.velocity())
fluid.set_particles(p.mass(), p.volume(), p.position(), p.velocity(), p.contact_forces(), init=True)
fluid.export_vtk(outputdir, 0.,0)
#Computation loop
forces = np.zeros_like(p.velocity())
k=0
while t < tEnd :
# Fluid solver
fluid.implicit_euler(dt,newton_max_it=1000)
# Computation of the new velocities
forces = fluid.compute_node_force(dt)
#forces[:,1] = g*p.mass()[0]
vn = p.velocity() + forces * dt / p.mass()
vmax = np.max(np.hypot(vn[:, 0], vn[:, 1]))
#number of sub time step
nsub = max(1, int(np.ceil((vmax * dt * 4)/min(p.r()))))
print("i", k,"NSUB", nsub,"VMAX",vmax, "VMAX * dt", vmax * dt, "r", min(p.r()))
#Contact solver
k = k+1
for i in range(nsub) :
tol = 1e-6
p.iterate(dt/nsub, forces, tol)
fluid.set_particles(p.mass(), p.volume(), p.position(), p.velocity())
time_integration.pred_corr_solver(fluid, p, dt)
t += dt
#Output files writting
if ii %outf == 0 :
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment