Commit 0836c2fc authored by mozul's avatar mozul
Browse files

Squashed 'examples/' changes from 06e5e26..c315cae

c315cae maj notebooks
212a33f maj
b187a5d correct ComputeField before UpdateBulk in Pre examples
762edf1 remove sys.path.append from all examples
005bd6b add mecaMAILx_ComputeField before UpdateStep
3404940 command name change
941451a maj
757e441 modifs notebooks
dba1b41 nettoyage
ae4c4dd ajout notebook
be0cfcd exemple de treilli en elements BARxx

git-subtree-dir: examples
git-subtree-split: c315caecbc2e09c8fcfd36ecb0cec242c0d16cdf
parent 2739da53
......@@ -174,7 +174,7 @@ for k in xrange(1, nb_steps + 1, 1):
utilities_logMes('COMPUTE DOF, FIELDS, etc.')
mecaMAILx_ComputeDof()
RBDY2_ComputeDof()
mecaMAILx_ComputeBulk()
mecaMAILx_ComputeField()
#
utilities_logMes('UPDATE DOF, FIELDS')
TimeEvolution_UpdateStep()
......
import os,sys
sys.path.append('/Users/mrenouf/GitLab_LMGC90/build_dev_rc2015')
from pylmgc90.chipy import *
checkDirectories()
......
import os,sys
sys.path.append('/Users/mrenouf/GitLab_LMGC90/build_dev_rc2015')
from pylmgc90.chipy import *
checkDirectories()
......
import os,sys
sys.path.append('/Users/mrenouf/GitLab_LMGC90/build_dev_rc2015')
from pylmgc90.chipy import *
......@@ -99,6 +96,7 @@ for i in xrange(0,nb_steps_ther,1):
IncrementStep()
mp_solver_RecupTemperature()
mp_solver_SolveThermoProblem()
mecaMAILx_ComputeField()
UpdateStep()
### postpro ###
......
import os,sys
sys.path.append('/Users/mrenouf/GitLab_LMGC90/build_dev_rc2015')
from pylmgc90.chipy import *
from numpy import *
......@@ -99,7 +97,7 @@ nbspher = SPHER_GetNbSPHER()
Ts = np.zeros([nbspher])
spher2rbdy3 = SPHER_GetPtrSPHER2RBDY3()
spher2rbdy3 = SPHER_GetPtrSPHER2BDYTY()
#
for i in xrange(0,nb_iter,1):
......
%% Cell type:markdown id: tags:
# Biaxial compression of a rectangular box filled with disks
F. Dubois - 2016
%% Cell type:markdown id: tags:
## Pre-processing
%% Cell type:markdown id: tags:
Initialisation
%% Cell type:code id: tags:
``` python
import numpy as np
from pylmgc90.pre_lmgc import *
if not os.path.isdir('./DATBOX'):
os.mkdir('./DATBOX')
# 2D
dim = 2
# containers
# * bodies
bodies = avatars()
# * materials
mat = materials()
# * see tables
svs = see_tables()
# * contact laws
tacts = tact_behavs()
# creations de deux materiaux
tdur = material(name='TDURx',type='RIGID',density=1000.)
plex = material(name='PLEXx',type='RIGID',density=100.)
mat.addMaterial(tdur,plex)
# on cree un modele de rigide
mod = model(name='rigid', type='MECAx', element='Rxx2D', dimension=dim)
# on genere 1000 particules
nb_particles=1000
# distribtion aleatoire dans [0.5, 2.[
radii=granulo_Random(nb_particles, 0.5, 2.)
# on recupere le plus petit et le plus grand rayon
radius_min=min(radii)
radius_max=max(radii)
# depot dans une boite rectangulaire
lx = 75.
ly = 50.
[nb_remaining_particles, coor]=depositInBox2D(radii, lx, ly)
# si toutes les particules deposees n'ont pas ete conservees
if (nb_remaining_particles < nb_particles):
# on affiche un avertissement
print "Warning: granulometry changed, since some particles were removed!"
# boucle d'ajout des disques :
for i in xrange(0,nb_remaining_particles,1):
# creation un nouveau disque rigide, constitue du materiau plex
body=rigidDisk(r=radii[i], center=coor[2*i : 2*(i + 1)],
model=mod, material=plex, color='BLEUx')
# ajout du disque dans le conteneur de corps
bodies += body
# ajout d'une boite lisse, i.e. faite de joncs :
# on declare un corps par paroi
down = rigidJonc(axe1=0.5*lx+radius_max, axe2=radius_max, center=[0.5*lx, -radius_max],
model=mod, material=tdur, color='WALLx')
up = rigidJonc(axe1=0.5*lx+radius_max, axe2=radius_max, center=[0.5*lx, ly+radius_max],
model=mod, material=tdur, color='WALLx')
left = rigidJonc(axe1=0.5*ly+radius_max, axe2=radius_max, center=[-radius_max, 0.5*ly],
model=mod, material=tdur, color='WALLx')
right= rigidJonc(axe1=0.5*ly+radius_max, axe2=radius_max, center=[lx+radius_max, 0.5*ly],
model=mod, material=tdur, color='WALLx')
# on ajoute les parois a la liste des corps
bodies += down; bodies += up; bodies += left; bodies += right
# on tourne les parois verticales (par rapport a leur propres
# centre d'inertie)
left.rotate(psi=-math.pi/2., center=left.nodes[1].coor)
right.rotate(psi=math.pi/2., center=right.nodes[1].coor)
# on fixe les parois
down.imposeDrivenDof(component=[1, 2, 3], dofty='vlocy')
up.imposeDrivenDof(component=[1, 2, 3], dofty='vlocy')
left.imposeDrivenDof(component=[1, 2, 3], dofty='vlocy')
right.imposeDrivenDof(component=[1, 2, 3], dofty='vlocy')
# gestion des interactions :
# * declaration des lois
# - entre particules
ldkdk=tact_behav(name='iqsc0',type='IQS_CLB',fric=0.3)
tacts+=ldkdk
# - avec les parois
ldkjc=tact_behav(name='iqsc1',type='IQS_CLB',fric=0.5)
tacts+=ldkjc
# * declaration des tables de visibilite
# - entre particules
svdkdk = see_table(CorpsCandidat='RBDY2',candidat='DISKx',
colorCandidat='BLEUx',behav=ldkdk, CorpsAntagoniste='RBDY2',
antagoniste='DISKx',colorAntagoniste='BLEUx',alert=0.1*radius_min)
svs+=svdkdk
# - avec les parois
svdkjc = see_table(CorpsCandidat='RBDY2',candidat='DISKx',
colorCandidat='BLEUx',behav=ldkjc, CorpsAntagoniste='RBDY2',
antagoniste='JONCx',colorAntagoniste='WALLx',alert=0.1*radius_min)
svs+=svdkjc
# ecriture des fichiers
writeBodies(bodies,chemin='DATBOX/')
writeBulkBehav(mat,chemin='DATBOX/')
writeTactBehav(tacts,svs,chemin='DATBOX/')
writeDrvDof(bodies,chemin='DATBOX/')
writeDofIni(bodies,chemin='DATBOX/')
writeVlocRlocIni(chemin='DATBOX/')
try:
visuAvatars(bodies)
except:
pass
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
# How to build a rigid avatar
F. Dubois 2016
%% Cell type:markdown id: tags:
All avatars are made of nodes, elements, contactors and need a material and a model.
%% Cell type:markdown id: tags:
## 2D Case
%% Cell type:code id: tags:
``` python
#Initialization
from pylmgc90.pre_lmgc import *
# 2D
dim = 2
```
%%%% Output: stream
Info : med file reading module not available
%% Cell type:markdown id: tags:
Defining a material suitable for rigid objects.
%% Cell type:code id: tags:
``` python
mut = material(name='TDURx',type='RIGID',density=1000.)
```
%% Cell type:markdown id: tags:
Defining a model suitable for rigid objects.
%% Cell type:code id: tags:
``` python
mod = model(name='rigid', type='MECAx', element='Rxx2D', dimension=dim)
```
%% Cell type:markdown id: tags:
Defining an empty avatar
%% Cell type:code id: tags:
``` python
disk = avatar(type='RBDY2',dimension=2)
## some introspection
## what is disk ?
#help(disk)
## what is nodes in disk ?
#help(disk.nodes)
## what are the keys in nodes ?
#print disk.nodes.viewkeys()
## what are the values in nodes ?
#print disk.nodes.viewvalues()
```
%% Cell type:markdown id: tags:
Creating a node and adding it to the avatar (number MUST be 1)
%% Cell type:code id: tags:
``` python
no = node(type='NO2xx',coor=numpy.array([0.,0.1]),number=1)
## some introspection
## what is no ?
#help(no)
## what is containing no ?
#dir(no)
#print no.coor
# adding no to avatar
disk.addNode( no )
## some introspection
## does no.nodes change ?
#print disk.nodes.viewkeys()
#print disk.nodes.viewvalues()
## key to access to value of first node stored
#id=disk.nodes.keys()[0]
#print 'id= ',id
## what is this value ?
#help(disk.nodes[id])
#dir(disk.nodes[id])
#print disk.nodes[id].coor
#print disk.nodes[id].getCoor()
#print disk.nodes[id].number
#print disk.nodes.values()[0].coor
```
%% Cell type:markdown id: tags:
Creating an element and adding it to the avatar
%% Cell type:code id: tags:
``` python
disk.addBulk( rigid2d() )
## some introspection
#help(disk.bulks)
#print disk.bulks.keys()
#id=disk.bulks.keys()[0]
#help(disk.bulks[id])
#dir(disk.bulks[id])
#print disk.bulks[id].connectivity
```
%% Cell type:markdown id: tags:
We need groups to add model/material, contactors, drivendof, etc.
%% Cell type:code id: tags:
``` python
## does my object contain groups ?
#dir(disk.groups)
#print disk.groups.viewkeys()
#
disk.defineGroups()
## does my object contain groups ?
#print disk.groups.viewkeys()
## what is group 'all'?
#help(disk.groups['all'])
#dir(disk.groups['all'])
#help(disk.groups['all'].bulks)
#dir(disk.groups['all'])
#print disk.groups['all'].bulks.keys()
#print disk.groups['all'].bulks[0]
#print disk.groups['all'].nodes.keys()
#print disk.groups['all'].contactors.keys()
```
%% Cell type:markdown id: tags:
Adding model and material (default added to 'all').
%% Cell type:code id: tags:
``` python
disk.defineModel(model=mod)
disk.defineMaterial(material=mut)
```
%% Cell type:markdown id: tags:
Adding contactor (default added to 'all')
%% Cell type:code id: tags:
``` python
disk.addContactors(type='DISKx', color='BLUEx', byrd=1.)
```
%% Cell type:markdown id: tags:
Needs to compute some internal values (mass, inertia, frame, etc)
%% Cell type:code id: tags:
``` python
disk.computeRigidProperties()
```
%% Cell type:markdown id: tags:
Some magic function
%% Cell type:code id: tags:
``` python
disk2=rigidDisk(r=1., center=[2., 2.], model=mod, material=mut, color='BLUEx')
```
%% Cell type:code id: tags:
``` python
#Draw
bodies = avatars()
bodies.addAvatar(disk)
bodies.addAvatar(disk2)
visuAvatars(bodies)
```
%% Cell type:markdown id: tags:
# Managing 2D deposit
F. Dubois - 2016
%% Cell type:markdown id: tags:
Importing necessary modules for the tutorial
%% Cell type:code id: tags:
``` python
%matplotlib inline
import os,sys
import numpy
import matplotlib.pyplot as plt
from pylmgc90.pre_lmgc import *
```
%% Cell type:markdown id: tags:
For this tutorial we need a function able to draw circles.
%% Cell type:code id: tags:
``` python
def draw(coor,radii):
plt.axes()
for k in range(len(radii)):
circle = plt.Circle((coor[k,0], coor[k,1]), radius=radii[k], fc='y')
plt.gca().add_patch(circle)
plt.axis('scaled')
plt.show()
```
%% Cell type:markdown id: tags:
Nice we can draw ... Mickey Mouse !
%% Cell type:code id: tags:
``` python
coor=numpy.array([[0., 0.],[1.,1.],[-1.,1.],[0.,0.],[0.5,0.5],[-0.5,0.5]])
rayon=[1.,0.5,0.5,0.2,0.1,0.3]
draw(coor,rayon)
```
%% Cell type:markdown id: tags:
Lets consider a more interesting problem. We need a set of radius.
%% Cell type:code id: tags:
``` python
# Generating a list of radius
nb_particles = 10000
radius_min = 1.0
radius_max = 2.5
radii = granulo_Random(nb_particles, radius_min, radius_max)
```
%% Cell type:markdown id: tags:
Now we have to compute the positions of these disks.
%% Cell type:code id: tags:
``` python
case=0
if case == 0:
# putting particles in a box [0.,0.]*[150.,100.]
lx = 150.
ly = 100.
[nb_laid_particles, coors] = depositInBox2D(radii,lx,ly)
elif case == 1:
rext=150.
[nb_laid_particles, coors]=depositInDisk2D(radii, rext)
elif case == 2:
rext=150.
rint=100.
[nb_laid_particles, coors]=depositInCouetteD(radii, rint, rext)
elif case == 3:
rext=150.
[nb_laid_particles, coors]=depositInDrum2D(radii,rext)
elif case == 4:
# putting particles on a square lattice
coors=squareLattice2D(10, 10, 2*radius_max, x0=0., y0=0.)
#print numpy.shape(coors)
nb_laid_particles=numpy.shape(coors)[0]/2
elif case == 5:
coors=triangularLattice2D(20, 20, 2*radius_max, x0=0., y0=0.)
nb_laid_particles=numpy.shape(coors)[0]/2
# reducing coors & radii arrays to useful part
coors = coors[0:2*nb_laid_particles]
radii = radii[0:nb_laid_particles]
```
%% Cell type:markdown id: tags:
Lets draw
%% Cell type:code id: tags:
``` python
print 'Real number of particles: ',numpy.shape(radii)
# drawing
coors=numpy.reshape(coors,(nb_laid_particles,2))
draw(coors,radii)
```
%% Cell type:markdown id: tags:
# Managing granulometry
F. Dubois - 2016
%% Cell type:markdown id: tags:
Importing necessary modules
%% Cell type:code id: tags:
``` python
%matplotlib inline
%config InlineBackend.figure_formats = {'svg',}
#%config InlineBackend.figure_formats = {'png', 'retina'}
import os,sys
import numpy
import math
import scipy
import scipy.special
import random
import matplotlib.pyplot as plt
# Seaborn, useful for graphics
import seaborn as sns
# JB's favorite Seaborn settings for notebooks
rc = {'lines.linewidth': 2,
'axes.labelsize': 18,
'axes.titlesize': 18,
'axes.facecolor': 'DFDFE5'}
sns.set_context('notebook', rc=rc)
sns.set_style('darkgrid', rc=rc)
# Import Bokeh modules for interactive plotting
import bokeh.io
import bokeh.mpl
import bokeh.plotting
bokeh.io.output_notebook()
from pylmgc90.pre_lmgc import *
```
%% Cell type:markdown id: tags:
A function to draw the cumulated volume of particles
%% Cell type:code id: tags:
``` python
def draw_granulo(radii):
"""
A function to draw the cumulative volume occupied by a list of particles with respect to the radius
:param radii: an array of radii
"""
rd = numpy.sort(radii)
# computing total volume (4pi/3 voluntarily omitted)
vv=0.
for radius in radii:
vv+=math.pow(radius,3)
# ecriture granulo
v=0.
radius_prev=rd[0]
x=[]
y=[]
for radius in rd:
v += math.pow(radius,3)
if radius != radius_prev:
x.append(radius_prev)
y.append(v/vv)
radius_prev = radius
x.append(radius_prev)
y.append(v/vv)
plt.plot(numpy.array(x),numpy.array(y))
plt.xlabel('radius')
plt.ylabel('cumulated volume/total volume')
plt.title('Cumulated volume')
plt.grid(True)
#plt.savefig("test.png")
#plt.show()
# Make it interactive with Bokeh
bokeh.plotting.show(bokeh.mpl.to_bokeh())
```