yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #03472
[Branch ~yade-dev/yade/trunk] Rev 2045: 1. spheresToFile() has been fixed and moved to export file. Do we need "consider=lambda id: True"...
------------------------------------------------------------
revno: 2045
committer: Anton Gladky <gladky.anton@xxxxxxxxx>
branch nick: trunk
timestamp: Sun 2010-02-21 01:04:22 +0100
message:
1. spheresToFile() has been fixed and moved to export file. Do we need "consider=lambda id: True" there?
2. ymport.ascii() was renamed to spheresFromFile; wenjieFormat was deleted there. The function is rewritten, comments are available now.
3. Added export.spheresToFile() and ymport.ascii() examples to regular-sphere-pack.py.
4. In timing.py InteractionDispatcher->InteractionDispatchers
5. Some default values in scons were changed to make YADE compilable with "standard" Ubuntu machine with 4GB RAM: chunkSize=7, jobs=2
added:
scripts/test/regular-sphere-pack-FromFile
modified:
SConstruct
py/SConscript
py/export.py
py/timing.py
py/utils.py
py/ymport.py
scripts/test/regular-sphere-pack.py
--
lp:yade
https://code.launchpad.net/~yade-dev/yade/trunk
Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription.
=== modified file 'SConstruct'
--- SConstruct 2010-02-18 07:59:29 +0000
+++ SConstruct 2010-02-21 00:04:22 +0000
@@ -140,11 +140,11 @@
ListVariable('exclude','Yade components that will not be built','none',names=['gui','extra','common','dem','lattice','snow']),
EnumVariable('PGO','Whether to "gen"erate or "use" Profile-Guided Optimization','',['','gen','use'],{'no':'','0':'','false':''},1),
ListVariable('features','Optional features that are turned on','log4cxx,opengl,gts,openmp,vtk',names=['opengl','log4cxx','cgal','openmp','gts','vtk','python','eigen','nowm3','never_use_this_one']),
- ('jobs','Number of jobs to run at the same time (same as -j, but saved)',4,None,int),
+ ('jobs','Number of jobs to run at the same time (same as -j, but saved)',2,None,int),
#('extraModules', 'Extra directories with their own SConscript files (must be in-tree) (whitespace separated)',None,None,Split),
('buildPrefix','Where to create build-[version][variant] directory for intermediary files','..'),
EnumVariable('linkStrategy','How to link plugins together',defOptions['linkStrategy'],['per-class','per-pkg[broken]','monolithic','static[broken]']),
- ('chunkSize','Maximum files to compile in one translation unit when building plugins.',20,None,int),
+ ('chunkSize','Maximum files to compile in one translation unit when building plugins.',7,None,int),
('version','Yade version (if not specified, guess will be attempted)',None),
('CPPPATH', 'Additional paths for the C preprocessor (colon-separated)','/usr/include/vtk-5.2:/usr/include/vtk-5.4:/usr/include/eigen2'),
('LIBPATH','Additional paths for the linker (colon-separated)',None),
=== modified file 'py/SConscript'
--- py/SConscript 2010-02-15 19:35:41 +0000
+++ py/SConscript 2010-02-21 00:04:22 +0000
@@ -24,6 +24,7 @@
env.AlwaysBuild(env.ScanReplace('config.py.in')),
env.File('utils.py'),
env.File('ymport.py'),
+ env.File('export.py'),
env.File('eudoxos.py'),
env.File('plot.py'),
env.File('linterpolation.py'),
=== modified file 'py/export.py'
--- py/export.py 2009-12-13 20:30:13 +0000
+++ py/export.py 2010-02-21 00:04:22 +0000
@@ -1,3 +1,6 @@
+"""
+Export geometry to various formats.
+"""
# encoding: utf-8
from yade.wrapper import *
@@ -117,3 +120,26 @@
outFile.close()
self.snapCount+=1
+def spheresToFile(filename, consider=lambda id: True):
+ """Save sphere coordinates into a text file; the format of the line is: x y z r.
+ Non-spherical bodies are silently skipped.
+ Returns number of spheres which were written.
+ Example added to scripts/test/regular-sphere-pack.py
+ """
+ O=Omega()
+
+ try:
+ out=open(filename,'w')
+ except:
+ raise RuntimeError("Problem to write into the file")
+
+ count=0
+ for b in O.bodies:
+ try:
+ if ((b.shape.name=="Sphere") and consider(b.id)):
+ out.write('%g\t%g\t%g\t%g\n'%(b.state.pos[0],b.state.pos[1],b.state.pos[2],b.shape['radius']))
+ count+=1
+ except AttributeError:
+ pass
+ out.close()
+ return count
=== modified file 'py/timing.py'
--- py/timing.py 2010-01-24 16:27:40 +0000
+++ py/timing.py 2010-02-21 00:04:22 +0000
@@ -57,7 +57,7 @@
else: execTime=e.execTime
lines+=_delta_stats(e.timingDeltas,execTime,level+1)
if isinstance(e,Dispatcher): lines+=_engines_stats(e.functors,e.execTime,level+1)
- if isinstance(e,InteractionDispatcher):
+ if isinstance(e,InteractionDispatchers):
lines+=_engines_stats(e.geomDispatcher.functors,e.execTime,level+1)
lines+=_engines_stats(e.physDispatcher.functors,e.execTime,level+1)
lines+=_engines_stats(e.lawDispatcher.functors,e.execTime,level+1)
=== modified file 'py/utils.py'
--- py/utils.py 2010-02-14 19:36:17 +0000
+++ py/utils.py 2010-02-21 00:04:22 +0000
@@ -399,23 +399,6 @@
color=(random.random(),random.random(),random.random())
if b.dynamic or not onlyDynamic: b.shape.diffuseColor=color
-
-
-def spheresToFile(filename,consider=lambda id: True):
- """Save sphere coordinates into ASCII file; the format of the line is: x y z r.
- Non-spherical bodies are silently skipped.
-
- Returns number of spheres that were written."""
- o=Omega()
- out=open(filename,'w')
- count=0
- for b in o.bodies:
- if not b.shape or not b.shape.name=='Sphere' or not consider(b.id): continue
- out.write('%g\t%g\t%g\t%g\n'%(b.phys.pos[0],b.phys.pos[1],b.phys.pos[2],b.shape.radius))
- count+=1
- out.close()
- return count
-
def avgNumInteractions(cutoff=0.):
nums,counts=bodyNumInteractionsHistogram(aabbExtrema(cutoff))
return sum([nums[i]*counts[i] for i in range(len(nums))])/(1.*sum(counts))
@@ -577,7 +560,7 @@
def spheresFromFile(*args,**kw):
_deprecatedUtilsFunction('spheresFromFile','yade.import.text')
import yade.ymport
- return yade.ymport.text(*args,**kw)
+ return yade.ymport.spheresFromFile(*args,**kw)
def import_stl_geometry(*args,**kw):
_deprecatedUtilsFunction('import_stl_geometry','yade.import.stl')
import yade.ymport
=== modified file 'py/ymport.py'
--- py/ymport.py 2010-01-24 16:27:40 +0000
+++ py/ymport.py 2010-02-21 00:04:22 +0000
@@ -7,23 +7,20 @@
from yade import utils
-def ascii(filename,scale=1.,wenjieFormat=False,**kw):
+def spheresFromFile(fileName,shift=[0.0,0.0,0.0],scale=1.0,**kw):
"""Load sphere coordinates from file, create spheres, insert them to the simulation.
-
- filename is the file holding ASCII numbers (at least 4 colums that hold x_center, y_center, z_center, radius).
- All remaining arguments are passed the the yade.utils.sphere function that creates the bodies.
-
- wenjieFormat will skip all lines that have exactly 5 numbers and where the 4th one is exactly 1.0 -
- this was used by a fellow developer called Wenjie to mark box elements.
-
- Returns list of body ids that were inserted into simulation."""
- from yade.utils import sphere
- o=Omega()
+ filename is the file which has 4 colums [x, y, z, radius].
+ All remaining arguments are passed the the yade.utils.sphere function which creates bodies.
+ Comments, started from # are supported
+ """
+ infile = open(fileName,"r")
+ lines = infile.readlines()
+ infile.close()
ret=[]
- for l in open(filename):
- ss=[float(i) for i in l.split()]
- if wenjieFormat and len(ss)==5 and ss[4]==1.0: continue
- ret.append(sphere([scale*ss[0],scale*ss[1],scale*ss[2]],scale*ss[3],**kw))
+ for line in lines:
+ data = line.split()
+ if (data[0][0] != "#"):
+ ret.append(utils.sphere([shift[0]+scale*float(data[0]),shift[1]+scale*float(data[1]),shift[2]+scale*float(data[2])],scale*float(data[3]),**kw))
return ret
def stl(file, dynamic=False,wire=True,color=None,highlight=False,noBound=False,material=0):
=== added file 'scripts/test/regular-sphere-pack-FromFile'
--- scripts/test/regular-sphere-pack-FromFile 1970-01-01 00:00:00 +0000
+++ scripts/test/regular-sphere-pack-FromFile 2010-02-21 00:04:22 +0000
@@ -0,0 +1,4 @@
+#This is the file with the geometry, which can be imported into the simulation script
+-1.69 -0.880052 3.53564 1.15
+-1.69 -3.880052 4.0899 0.55
+-1.69 -5.741487 3.25851 0.95
=== modified file 'scripts/test/regular-sphere-pack.py'
--- scripts/test/regular-sphere-pack.py 2010-01-26 15:45:20 +0000
+++ scripts/test/regular-sphere-pack.py 2010-02-21 00:04:22 +0000
@@ -1,4 +1,4 @@
-from yade import pack,ymport
+from yade import pack,ymport,export
""" This script demonstrates how to use 2 components of creating packings:
@@ -66,6 +66,11 @@
"""Import regular-sphere-pack-LSMGenGeo.geo into the YADE simulation"""
O.bodies.append(ymport.gengeoFile('regular-sphere-pack-LSMGenGeo.geo',shift=[-7.0,-7.0,-5.9],scale=1.0,color=(1,0,1),**kw))
+"""spheresToFile saves coordinates and radiuses of all spheres of the simulation into the text file"""
+print "Saved into the OutFile " + str (export.spheresToFile("OutFile")) + " spheres";
+
+"""spheresFromFile function imports coordinates and radiuses of all spheres of the simulation into the text file"""
+O.bodies.append(ymport.spheresFromFile('regular-sphere-pack-FromFile',shift=[6.0,6.0,-2.9],scale=0.7,color=(1,1,1),**kw))
try:
from yade import qt