← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 2242: 1. VTKRecorder is static now.

 

------------------------------------------------------------
revno: 2242
committer: Anton Gladky <gladky.anton@xxxxxxxxx>
branch nick: trunk
timestamp: Wed 2010-05-19 13:09:23 +0200
message:
  1. VTKRecorder is static now.
  2. function ymport.testExt and export.testExt are added
modified:
  pkg/dem/Engine/GlobalEngine/VTKRecorder.cpp
  pkg/dem/meta/Shop.hpp
  py/export.py
  py/ymport.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 'pkg/dem/Engine/GlobalEngine/VTKRecorder.cpp'
--- pkg/dem/Engine/GlobalEngine/VTKRecorder.cpp	2010-05-18 22:10:18 +0000
+++ pkg/dem/Engine/GlobalEngine/VTKRecorder.cpp	2010-05-19 11:09:23 +0000
@@ -177,10 +177,7 @@
 
 	//Additional Vector for storing forces
 	vector<Shop::bodyState> bodyStates;
-	if(recActive[REC_STRESS]){
-		Shop shopTemp;
-		shopTemp.getStressForEachBody(bodyStates);
-	}
+	if(recActive[REC_STRESS]) Shop::getStressForEachBody(bodyStates);
 	
 	FOREACH(const shared_ptr<Body>& b, *scene->bodies){
 		if (!b) continue;

=== modified file 'pkg/dem/meta/Shop.hpp'
--- pkg/dem/meta/Shop.hpp	2010-05-18 22:10:18 +0000
+++ pkg/dem/meta/Shop.hpp	2010-05-19 11:09:23 +0000
@@ -129,5 +129,5 @@
 				}
 		};
 		//! Function of getting stresses for each body
-		void getStressForEachBody(vector<Shop::bodyState>&);
+		static void getStressForEachBody(vector<Shop::bodyState>&);
 };

=== modified file 'py/export.py'
--- py/export.py	2010-05-08 20:24:44 +0000
+++ py/export.py	2010-05-19 11:09:23 +0000
@@ -120,11 +120,21 @@
 		outFile.close()
 		self.snapCount+=1
 
-def text(filename, consider=lambda id: True):
-	"""Save sphere coordinates into a text file; the format of the line is: x y z r.
+def textExt(filename, format='x_y_z_r',consider=lambda id: True):
+	"""Save sphere coordinates and other parameters into a text file in specific format.
 	Non-spherical bodies are silently skipped.
-	Returns number of spheres which were written.
-	Example added to examples/regular-sphere-pack/regular-sphere-pack.py
+	Users can add here their own specific format, giving meaningful names.
+	The first file row will contain the format name.
+	Be sure to add the same format specification in ymport.textExt.
+	
+	:parameters:
+	`filename`: string
+		the name of the file, where sphere coordinates will be exported.
+	`format`:
+		the name of output format. Supported `x_y_z_r`(default), `x_y_z_r_matId`
+	`consider`:
+		anonymous function(optional)
+:return: number of spheres which were written.
 	"""
 	O=Omega()
 	
@@ -134,12 +144,33 @@
 		raise RuntimeError("Problem to write into the file")
 	
 	count=0
+	
+	out.write('#format ' + format + '\n')
 	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']))
+				if (format=='x_y_z_r'):
+					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))
+				elif (format=='x_y_z_r_matId'):
+					out.write('%g\t%g\t%g\t%g\t%d\n'%(b.state.pos[0],b.state.pos[1],b.state.pos[2],b.shape.radius,b.material.id))
+				else:
+					raise RuntimeError("Please, specify a correct format output!");
 				count+=1
 		except AttributeError:
 			pass
 	out.close()
 	return count
+	
+def text(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.
+	Example added to examples/regular-sphere-pack/regular-sphere-pack.py
+:parameters:
+	`filename`: string
+		the name of the file, where sphere coordinates will be exported.
+	`consider`:
+		anonymous function(optional)
+:return: number of spheres which were written.
+	"""
+	return (textExt(filename=filename, format='x_y_z_r',consider=consider))
+

=== modified file 'py/ymport.py'
--- py/ymport.py	2010-05-08 20:24:44 +0000
+++ py/ymport.py	2010-05-19 11:09:23 +0000
@@ -6,6 +6,42 @@
 from miniEigen import *
 from yade import utils
 
+def textExt(fileName,format='x_y_z_r',shift=[0.0,0.0,0.0],scale=1.0,**kw):
+	"""Load sphere coordinates from file in specific format, create spheres, insert them to the simulation.
+	
+	:Parameters:
+		`filename`: string
+		`format`:
+			the name of output format. Supported `x_y_z_r`(default), `x_y_z_r_matId`
+		`shift`: [float,float,float]
+			[X,Y,Z] parameter moves the specimen.
+		`scale`: float
+			factor scales the given data.
+		`**kw`: (unused keyword arguments)
+				is passed to :yref:`utils.sphere`
+	:Returns: list of spheres.
+	Lines starting with # are skipped
+	"""
+	infile = open(fileName,"r")
+	lines = infile.readlines()
+	infile.close()
+	ret=[]
+	for line in lines:
+		data = line.split()
+		if (data[0] == "#format"):
+			format=data[1]
+			continue
+		elif (data[0][0] == "#"): continue
+		
+		if (format=='x_y_z_r'):
+			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))
+			
+		elif (format=='x_y_z_r_matId'):
+			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]),material=int(data[4]),**kw))
+			
+		else:
+			raise RuntimeError("Please, specify a correct format output!");
+	return ret
 
 def text(fileName,shift=[0.0,0.0,0.0],scale=1.0,**kw):
 	"""Load sphere coordinates from file, create spheres, insert them to the simulation.
@@ -22,16 +58,9 @@
 	:Returns: list of spheres.
 	Lines starting with # are skipped
 	"""
-	infile = open(fileName,"r")
-	lines = infile.readlines()
-	infile.close()
-	ret=[]
-	for line in lines:
-		data = line.split()
-		if (data[0][0] == "#"): continue
-		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
-
+	
+	return textExt(fileName=fileName,format='x_y_z_r',shift=shift,scale=scale,**kw)
+	
 def stl(file, dynamic=False,wire=True,color=None,highlight=False,noBound=False,material=-1):
 	""" Import geometry from stl file, return list of created facets."""
 	imp = STLImporter()