← Back to team overview

yade-dev team mailing list archive

[svn] r1845 - in trunk: pkg/dem/Engine/StandAloneEngine py scripts/test

 

Author: eudoxos
Date: 2009-07-07 22:05:30 +0200 (Tue, 07 Jul 2009)
New Revision: 1845

Added:
   trunk/scripts/test/compare-identical.py
Modified:
   trunk/pkg/dem/Engine/StandAloneEngine/GlobalStiffnessTimeStepper.cpp
   trunk/py/plot.py
Log:
1. add yade.plot.resetData(), which unlike reset() resets just data 
2. Add scripts/test/compare-identical.py to run 2 simulations at the same time and check at every step (configurable) if they differ or not.
3. Add active=active line to GlobalStiffnessTimeStepper, which for some reason causes two same simulations to be the same. Any explanation someone??


Modified: trunk/pkg/dem/Engine/StandAloneEngine/GlobalStiffnessTimeStepper.cpp
===================================================================
--- trunk/pkg/dem/Engine/StandAloneEngine/GlobalStiffnessTimeStepper.cpp	2009-07-07 18:48:15 UTC (rev 1844)
+++ trunk/pkg/dem/Engine/StandAloneEngine/GlobalStiffnessTimeStepper.cpp	2009-07-07 20:05:30 UTC (rev 1845)
@@ -128,6 +128,9 @@
 
 void GlobalStiffnessTimeStepper::computeTimeStep(MetaBody* ncb)
 {
+	// for some reason, this line is necessary to have correct functioning (no idea _why_)
+	// see scripts/test/compare-identical.py, run with or without active=active.
+	active=active;
 	computeStiffnesses(ncb);
 
 	shared_ptr<BodyContainer>& bodies = ncb->bodies;

Modified: trunk/py/plot.py
===================================================================
--- trunk/py/plot.py	2009-07-07 18:48:15 UTC (rev 1844)
+++ trunk/py/plot.py	2009-07-07 20:05:30 UTC (rev 1845)
@@ -25,6 +25,10 @@
 	data={}; plots={}; plotsFilled={}; plotLines={}; needsFullReplot=True; 
 	pylab.close('all')
 
+def resetData():
+	global data
+	data={}
+
 # we could have a yplot class, that would hold: (yspec,...), (Line2d,Line2d,...) ?
 
 

Added: trunk/scripts/test/compare-identical.py
===================================================================
--- trunk/scripts/test/compare-identical.py	2009-07-07 18:48:15 UTC (rev 1844)
+++ trunk/scripts/test/compare-identical.py	2009-07-07 20:05:30 UTC (rev 1845)
@@ -0,0 +1,52 @@
+"""
+This files tests simulation correctness by loading a simulation two times,
+and periodically comparing the results, showing diffs in the simulation XML,
+if any. It stops after the differece is first spotted.
+
+On openMP-enabled installs, it should be run with OMP_NUM_THREADS=1, otherwise
+there will be noise differences coming from non-deterministic order of interactions
+in the container (although they are the same). You can use OMP_NUM_THREADS=2 to see
+what happens if the simulations get different.
+"""
+# this is to provide some default simulation to test on
+# comment it out and provide your own simulation XML in init
+TriaxialTest().generate('/tmp/TriaxialTest.xml')
+#
+
+# what is the initial file to load
+initFile='/tmp/TriaxialTest.xml'
+# that is the prefix for HTML diffs, if any
+outPrefix='/tmp/scene_'
+# at which step to stop
+stopIter=2000
+# how may steps to run between comparisons
+nSteps=100
+
+# quiet annoying messages
+import yade.log
+yade.log.setLevel('Omega',yade.log.WARN)
+yade.log.setLevel('TriaxialCompressionEngine',yade.log.WARN)
+
+if O.numThreads>1:
+	print "WARNING: You should run single-threaded with OMP_NUM_THREADS=1; interaction order will be probably different otherwise!"
+
+O.load(initFile); O.switchWorld(); O.load(initFile); O.switchWorld()
+from hashlib import md5; import difflib,sys
+print "Identical at steps ",
+for i in xrange(0,stopIter/nSteps):
+	sys.stdout.flush()
+	for world in 'A','B':
+		O.run(nSteps,True); O.saveTmp(world); O.switchWorld()
+	A,B=O.tmpToString('A'),O.tmpToString('B')
+	# fast compare first using hash digest
+	Ahash,Bhash=md5(A),md5(B)
+	if Ahash.digest()==Bhash.digest():
+		print O.iter,; continue
+	print "\nComputing differences..."
+	diff=difflib.HtmlDiff(tabsize=3,wrapcolumn=80)
+	outName=outPrefix+'%05d_diff.html'%O.iter
+	out=open(outName,'w')
+	out.write(diff.make_file(A.split('\n'),B.split('\n'),context=True,numlines=2))
+	print 'file://%s'%outName
+	break # stop at the first different value
+