← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-pkg/yade/git-trunk] Rev 3529: added export.textPolyhedra function

 

------------------------------------------------------------
revno: 3529
committer: Jan Stransky <jan.stransky@xxxxxxxxxxx>
timestamp: Sat 2014-11-08 10:56:26 +0100
message:
  added export.textPolyhedra function
added:
  examples/polyhedra/textExport.py
modified:
  pkg/dem/Polyhedra.hpp
  py/export.py


--
lp:yade
https://code.launchpad.net/~yade-pkg/yade/git-trunk

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-pkg/yade/git-trunk/+edit-subscription
=== added file 'examples/polyhedra/textExport.py'
--- examples/polyhedra/textExport.py	1970-01-01 00:00:00 +0000
+++ examples/polyhedra/textExport.py	2014-11-08 09:56:26 +0000
@@ -0,0 +1,3 @@
+from yade import polyhedra_utils,export
+polyhedra_utils.fillBox((0,0,0), (0.3,0.3,0.3),defaultMaterial(),sizemin=(0.025,0.025,0.025),sizemax=(0.05,0.05,0.05),seed=4)
+export.textPolyhedra('/tmp/textPolyhedra.txt')

=== modified file 'pkg/dem/Polyhedra.hpp'
--- pkg/dem/Polyhedra.hpp	2014-10-22 10:13:18 +0000
+++ pkg/dem/Polyhedra.hpp	2014-11-08 09:56:26 +0000
@@ -160,7 +160,8 @@
 	virtual ~PolyhedraMat(){};
 	YADE_CLASS_BASE_DOC_ATTRS_CTOR(PolyhedraMat,FrictMat,"Elastic material with Coulomb friction.",
 		((bool,IsSplitable,0,,"To be splitted ... or not"))
-		((Real,strength,100,,"Stress at whis polyhedra of volume 4/3*pi [mm] breaks.")),
+		((Real,strength,100,,"Stress at which polyhedra of volume 4/3*pi [mm] breaks."))
+		((Real,young,1e8,,"TODO")),
 		/*ctor*/ createIndex();
 	);
 	REGISTER_CLASS_INDEX(PolyhedraMat,FrictMat);

=== modified file 'py/export.py'
--- py/export.py	2014-06-29 21:25:01 +0000
+++ py/export.py	2014-11-08 09:56:26 +0000
@@ -118,7 +118,7 @@
 	outFile.close()
 	return len(bodies)
   
-#textExt===============================================================
+#textClumps===============================================================
 def textClumps(filename, format='x_y_z_r_clumpId', comment='',mask=-1):
 	"""Save clumps-members into a text file. Non-clumps members are bodies are silently skipped.
 
@@ -163,6 +163,48 @@
 	out.close()
 	return countClumps,count
 
+#textPolyhedra===============================================================
+def textPolyhedra(fileName, comment='',mask=-1, explanationComment=True):
+	"""Save polyhedra into a text file. Non-polyhedra bodies are silently skipped.
+
+	:param string filename: the name of the output file
+	:param string comment: the text, which will be added as a comment at the top of file. If you want to create several lines of text, please use '\\\\n#' for next lines.
+	:param int mask: export only polyhedra with the corresponding mask
+	:param str explanationComment: inclde explanation of format to the beginning of file
+	:return: number of polyhedra which were written.
+	:rtype: int
+	"""
+	count = 0
+	f = open(fileName,'w')
+	f.writelines('# %s\n'%l for l in [
+		'YADE export of polyhedra.',
+		'Each polyhedron export contains first line with id, nuber of vertices and number of surfaces.',
+		'x,y,z coordinates of each vertex follows (each vertex on separate line).',
+		'ids if vertices of individual surfaces follows (numbering from 0, each surface on separate line).',
+		'',
+		'Example of tetrahedron and cube with random ids:',
+		'23 4 4',
+		'0.1 0.2 0.3','1.3 0.1 -0.1','-0.2 1.2 0','0 -0.1 1.5',
+		'0 2 1','0 3 2','0 1 3','1 2 3',
+		'65 8 6',
+		'4 0 0','5 0 0','4 1 0','5 1 0','4 0 1','5 0 1','4 1 1','5 1 1',
+		'0 2 3 1','0 1 5 4','1 3 7 5','3 2 6 7','2 0 4 6','4 5 7 6',
+		'',
+	])
+	if comment:
+		f.write('#\n# %s\n'%comment)
+	for b in O.bodies:
+		if not isinstance(b.shape,Polyhedra) or not mask & b.mask:
+			continue
+		count += 1
+		vertices = [b.state.pos + b.state.ori*v for v in b.shape.v]
+		surfaces = b.shape.GetSurfaces()
+		f.write('%d %d %d\n'%(b.id,len(vertices),len(surfaces)))
+		f.writelines('%.8e %.8e %.8e\n'%(v[0],v[1],v[2]) for v in vertices)
+		f.writelines(' '.join(str(i) for i in surface)+'\n' for surface in surfaces)
+	f.close()
+	return count
+
 #VTKWriter===============================================================
 class VTKWriter:
 	"""