← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 2591: 1. Add MatchMaker(Real) ctor

 

------------------------------------------------------------
revno: 2591
committer: Václav Šmilauer <eu@xxxxxxxx>
branch nick: yade
timestamp: Mon 2010-12-06 21:05:12 +0100
message:
  1. Add MatchMaker(Real) ctor 
  2. Adjust timing report format for batch (precision)
modified:
  core/main/yade-batch.in
  pkg/common/MatchMaker.cpp
  pkg/common/MatchMaker.hpp
  pkg/dem/DomainLimiter.cpp
  pkg/dem/DomainLimiter.hpp
  py/wrapper/customConverters.cpp


--
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 'core/main/yade-batch.in'
--- core/main/yade-batch.in	2010-12-05 17:10:06 +0000
+++ core/main/yade-batch.in	2010-12-06 20:05:12 +0000
@@ -464,7 +464,7 @@
 		tMin,tMax=min(jobTimes),max(jobTimes)
 		tDev=math.sqrt(sum((t-tAvg)**2 for t in jobTimes)/len(jobTimes))
 		tRelDev=tDev/tAvg
-		out.write('%d\t%d\t%g\t%g\t%g\t%g\t%g\t|\t'%(l,len(jobTimes),tAvg,tDev,tRelDev,tMin,tMax)+'\t'.join([params[l][p] for p in paramNames])+'\n')
+		out.write('%d\t%d\t%.2f\t%.2f\t%.3g\t%.2f\t%.2f\t|\t'%(l,len(jobTimes),tAvg,tDev,tRelDev,tMin,tMax)+'\t'.join([params[l][p] for p in paramNames])+'\n')
 
 if not gnuplotOut:
 	print 'Bye.'

=== modified file 'pkg/common/MatchMaker.cpp'
--- pkg/common/MatchMaker.cpp	2010-11-07 11:46:20 +0000
+++ pkg/common/MatchMaker.cpp	2010-12-06 20:05:12 +0000
@@ -14,18 +14,18 @@
 		if(((int)m[0]==id1 && (int)m[1]==id2) || ((int)m[0]==id2 && (int)m[1]==id1)) return m[2];
 	}
 	// no match
-	if(fbNeedsValues && (isnan(val1) || isnan(val2))) throw std::invalid_argument("MatchMaker: no match for ("+lexical_cast<string>(id1)+","+lexical_cast<string>(id2)+"), and values required for fallback computation '"+fallback+"' not specified.");
+	if(fbNeedsValues && (isnan(val1) || isnan(val2))) throw std::invalid_argument("MatchMaker: no match for ("+lexical_cast<string>(id1)+","+lexical_cast<string>(id2)+"), and values required for algo computation '"+algo+"' not specified.");
 	return computeFallback(val1,val2);
 }
 
 void MatchMaker::postLoad(MatchMaker&){
-	if(fallback=="val")      { fbPtr=&MatchMaker::fbVal; fbNeedsValues=false; }
-	else if(fallback=="zero"){ fbPtr=&MatchMaker::fbZero;fbNeedsValues=false; } 
-	else if(fallback=="avg") { fbPtr=&MatchMaker::fbAvg; fbNeedsValues=true;  }
-	else if(fallback=="min") { fbPtr=&MatchMaker::fbMin; fbNeedsValues=true;  }
-	else if(fallback=="max") { fbPtr=&MatchMaker::fbMax; fbNeedsValues=true;  }
-	else if(fallback=="harmAvg") { fbPtr=&MatchMaker::fbHarmAvg; fbNeedsValues=true; }
-	else throw std::invalid_argument("MatchMaker:: fallback '"+fallback+"' not recognized (possible values: val, avg, min, max, harmAvg).");
+	if(algo=="val")      { fbPtr=&MatchMaker::fbVal; fbNeedsValues=false; }
+	else if(algo=="zero"){ fbPtr=&MatchMaker::fbZero;fbNeedsValues=false; } 
+	else if(algo=="avg") { fbPtr=&MatchMaker::fbAvg; fbNeedsValues=true;  }
+	else if(algo=="min") { fbPtr=&MatchMaker::fbMin; fbNeedsValues=true;  }
+	else if(algo=="max") { fbPtr=&MatchMaker::fbMax; fbNeedsValues=true;  }
+	else if(algo=="harmAvg") { fbPtr=&MatchMaker::fbHarmAvg; fbNeedsValues=true; }
+	else throw std::invalid_argument("MatchMaker:: algo '"+algo+"' not recognized (possible values: val, avg, min, max, harmAvg).");
 }
 
 Real MatchMaker::computeFallback(Real v1, Real v2) const { return (this->*MatchMaker::fbPtr)(v1,v2); }

=== modified file 'pkg/common/MatchMaker.hpp'
--- pkg/common/MatchMaker.hpp	2010-11-07 11:46:20 +0000
+++ pkg/common/MatchMaker.hpp	2010-12-06 20:05:12 +0000
@@ -8,7 +8,7 @@
 /* Future optimizations, in postLoad:
 
 1. Use matches to update lookup table/hash for faster matching, instead of traversing matches every time
-2. Use fallback to update fbPtr, instead of string-comparison of fallback every time
+2. Use algo to update fbPtr, instead of string-comparison of algo every time
 
 */
 class MatchMaker: public Serializable {
@@ -26,20 +26,21 @@
 	#endif 
 	public:
 		virtual ~MatchMaker();
-		MatchMaker(std::string _fallback): fallback(_fallback){}
+		MatchMaker(std::string _algo): algo(_algo){ postLoad(*this); }
+		MatchMaker(Real _val): algo("val"), val(_val){ postLoad(*this); }
 		Real computeFallback(Real val1, Real val2) const ;
 		void postLoad(MatchMaker&);
 		// return value looking up matches for id1+id2 (the order is arbitrary)
-		// if no match is found, use val1,val2 and fallback strategy to compute new value.
+		// if no match is found, use val1,val2 and algo strategy to compute new value.
 		// if no match is found and val1 or val2 are not given, throw exception
 		Real operator()(const int id1, const int id2, const Real val1=NaN, const Real val2=NaN) const;
 		YADE_CLASS_BASE_DOC_ATTRS_CTOR_PY(MatchMaker,Serializable,"Class matching pair of ids to return pre-defined or derived value of a scalar parameter.\n\n.. note:: There is a :ref:`converter <customconverters>` from python number defined for this class, which creates a new :yref:`MatchMaker` returning the value of that number; instead of giving the object instance therefore, you can only pass the number value and it will be converted automatically.",
 			((std::vector<Vector3r>,matches,,,"Array of ``(id1,id2,value)`` items; queries matching ``id1``+``id2`` or ``id2``+``id1`` will return ``value``"))
-			((std::string,fallback,"avg",Attr::triggerPostLoad,"Alogorithm used to compute value when no match for ids is found. Possible values are\n* 'avg' (arithmetic average)\n* 'min' (minimum value)\n* 'max' (maximum value)\n* 'harmAvg' (harmonic average)\n\nThe following fallback algorithms do *not* require meaningful input values in order to work:\n* 'val' (return value specified by :yref:`val<MatchMaker.val>`)\n* 'zero' (return 0.)"))
-			((Real,val,NaN,,"Constant value returned if there is no match and :yref:`fallback<MatchMaker::fallback>` is ``val``"))
-			, fbPtr=&MatchMaker::fbAvg; fbNeedsValues=true; /* keep in sync with the fallback value for fallback */
-			, /*py*/ .def("__call__",&MatchMaker::operator(),(py::arg("id1"),py::arg("id2"),py::arg("val1")=NaN,py::arg("val2")=NaN),"Ask the instance for scalar value for given pair *id1*,*id2* (the order is irrelevant). Optionally, *val1*, *val2* can be given so that if there is no :yref:`match<MatchMaker.matches>`, return value can be computed using given :yref:`fallback<MatchMaker.fallback>`. If there is no match and *val1*, *val2* are not given, an exception is raised.")
-			.def("computeFallback",&MatchMaker::computeFallback,(py::arg("val1"),py::arg("val2")),"Compute fallback value for *val1* and *val2*, using algorithm specified by :yref:`fallback<MatchMaker.fallback>`.")
+			((std::string,algo,"avg",Attr::triggerPostLoad,"Alogorithm used to compute value when no match for ids is found. Possible values are\n* 'avg' (arithmetic average)\n* 'min' (minimum value)\n* 'max' (maximum value)\n* 'harmAvg' (harmonic average)\n\nThe following algo algorithms do *not* require meaningful input values in order to work:\n* 'val' (return value specified by :yref:`val<MatchMaker.val>`)\n* 'zero' (return 0.)"))
+			((Real,val,NaN,,"Constant value returned if there is no match and :yref:`algo<MatchMaker::algo>` is ``val``"))
+			, fbPtr=&MatchMaker::fbAvg; fbNeedsValues=true; /* keep in sync with the algo value for algo */
+			, /*py*/ .def("__call__",&MatchMaker::operator(),(py::arg("id1"),py::arg("id2"),py::arg("val1")=NaN,py::arg("val2")=NaN),"Ask the instance for scalar value for given pair *id1*,*id2* (the order is irrelevant). Optionally, *val1*, *val2* can be given so that if there is no :yref:`match<MatchMaker.matches>`, return value can be computed using given :yref:`algo<MatchMaker.algo>`. If there is no match and *val1*, *val2* are not given, an exception is raised.")
+			.def("computeFallback",&MatchMaker::computeFallback,(py::arg("val1"),py::arg("val2")),"Compute algo value for *val1* and *val2*, using algorithm specified by :yref:`algo<MatchMaker.algo>`.")
 		);
 };
 REGISTER_SERIALIZABLE(MatchMaker);

=== modified file 'pkg/dem/DomainLimiter.cpp'
--- pkg/dem/DomainLimiter.cpp	2010-12-05 17:10:06 +0000
+++ pkg/dem/DomainLimiter.cpp	2010-12-06 20:05:12 +0000
@@ -82,8 +82,6 @@
 	// get body objects
 	State *state1=Body::byId(id1,scene)->state.get(), *state2=Body::byId(id2,scene)->state.get();
 	scene->forces.sync();
-	//if(state1->blockedDOFs!=State::DOF_RXRYRZ) { LOG_INFO("Blocking rotational DOFs for #"<<id1); state1->blockedDOFs=State::DOF_RXRYRZ;}
-	//if(state2->blockedDOFs!=State::DOF_RXRYRZ) { LOG_INFO("Blocking rotational DOFs for #"<<id2); state2->blockedDOFs=State::DOF_RXRYRZ;}
 	if(state1->blockedDOFs!=State::DOF_ALL) { LOG_INFO("Blocking all DOFs for #"<<id1); state1->blockedDOFs=State::DOF_ALL;}
 	if(state2->blockedDOFs!=State::DOF_ALL) { LOG_INFO("Blocking all DOFs for #"<<id2); state2->blockedDOFs=State::DOF_ALL;}
 

=== modified file 'pkg/dem/DomainLimiter.hpp'
--- pkg/dem/DomainLimiter.hpp	2010-11-17 11:25:26 +0000
+++ pkg/dem/DomainLimiter.hpp	2010-12-06 20:05:12 +0000
@@ -52,7 +52,7 @@
 		((Real,refLength,0,(Attr::readonly),"Reference contact length, for rendering only."))
 		((Vector3r,contPt,Vector3r::Zero(),,"Contact point (for rendering only)"))
 		((Real,idWeight,1,,"Float ∈〈0,1〉 determining on which particle are displacements applied (0 for id1, 1 for id2); intermediate values will apply respective part to each of them."))
-		((Real,rotWeight,1,,"Float ∈〈0,1〉 determining whether shear displacement is applied as rotation or displacement on arc (0 is displacemetn-only, 1 is rotation-only)."))
+		((Real,rotWeight,1,,"Float ∈〈0,1〉 determining whether shear displacement is applied as rotation or displacement on arc (0 is displacement-only, 1 is rotation-only). Not effective when mutual rotation is specified."))
 		// reset force components along individual axes, instead of blocking DOFs which have no specific direction (for the force control)
 	);
 };

=== modified file 'py/wrapper/customConverters.cpp'
--- py/wrapper/customConverters.cpp	2010-11-12 08:03:16 +0000
+++ py/wrapper/customConverters.cpp	2010-12-06 20:05:12 +0000
@@ -148,7 +148,7 @@
 		void* storage=((converter::rvalue_from_python_storage<shared_ptr<MatchMaker> >*)(data))->storage.bytes;
 		new (storage) shared_ptr<MatchMaker>(new MatchMaker); // allocate the object at given address
 		shared_ptr<MatchMaker>* mm=(shared_ptr<MatchMaker>*)(storage); // convert that address to our type
-		(*mm)->fallback="val"; (*mm)->val=PyFloat_AsDouble(obj_ptr); (*mm)->postLoad(**mm);
+		(*mm)->algo="val"; (*mm)->val=PyFloat_AsDouble(obj_ptr); (*mm)->postLoad(**mm);
 		data->convertible=storage;
 	}
 };