← Back to team overview

yade-dev team mailing list archive

[svn] r1581 - in trunk: extra/usct gui/qt3 pkg/common/Engine/DeusExMachina

 

Author: eudoxos
Date: 2008-11-24 13:18:47 +0100 (Mon, 24 Nov 2008)
New Revision: 1581

Added:
   trunk/pkg/common/Engine/DeusExMachina/LinearInterpolate.hpp
Modified:
   trunk/extra/usct/UniaxialStrainControlledTest.cpp
   trunk/extra/usct/UniaxialStrainControlledTest.hpp
   trunk/gui/qt3/QtGUI.cpp
   trunk/pkg/common/Engine/DeusExMachina/RotationEngine.cpp
   trunk/pkg/common/Engine/DeusExMachina/RotationEngine.hpp
Log:
1. Add linear templated interpolation function working on 2 lists, t and values
2. Add InterpolatingRotationEngine that changes rotation speed as given by value table
3. Lower info about starting python thread to debug message only.



Modified: trunk/extra/usct/UniaxialStrainControlledTest.cpp
===================================================================
--- trunk/extra/usct/UniaxialStrainControlledTest.cpp	2008-11-22 22:54:46 UTC (rev 1580)
+++ trunk/extra/usct/UniaxialStrainControlledTest.cpp	2008-11-24 12:18:47 UTC (rev 1581)
@@ -102,6 +102,9 @@
 	// reverse if we're over the limit strain
 	if(notYetReversed && limitStrain!=0 && ((currentStrainRate>0 && strain>limitStrain) || (currentStrainRate<0 && strain<limitStrain))) { currentStrainRate*=-1; notYetReversed=false; LOG_INFO("Reversed strain rate to "<<currentStrainRate); }
 
+	// if(strain==stopAtStrain){LOG_INFO("Prescibed strain "<<stopAtStrain<<" reached, pausing."); }
+	if(!isnan(stopAtStrain) && ((strain*stopAtStrain>0) && abs(strain)>abs(stopAtStrain))) { strain=stopAtStrain;	rootBody->stopAtIteration=Omega::instance().getCurrentIteration()+2; LOG_INFO("Prescribed strain "<<stopAtStrain<<" reached, will stop in 2 iterations"); }
+
 	if(Omega::instance().getCurrentIteration()%10==0 ) {
 		computeAxialForce(rootBody);
 		#if 0

Modified: trunk/extra/usct/UniaxialStrainControlledTest.hpp
===================================================================
--- trunk/extra/usct/UniaxialStrainControlledTest.hpp	2008-11-22 22:54:46 UTC (rev 1580)
+++ trunk/extra/usct/UniaxialStrainControlledTest.hpp	2008-11-24 12:18:47 UTC (rev 1581)
@@ -15,7 +15,7 @@
 	private:
 		void createEngines();
 	public:
-		USCTGen(){ axis=1; limitStrain=0; damping=0.2;cohesiveThresholdIter=200; };
+		USCTGen(){ axis=1; limitStrain=0; damping=0.2;cohesiveThresholdIter=200;};
 		~USCTGen (){};
 		bool generate();
 		string spheresFile;
@@ -81,6 +81,8 @@
 		void init();
 	public:
 		Real strainRate,currentStrainRate;
+		//! strain at which we will pause simulation; inactive (nan) by default; must be reached from below (in absolute value)
+		Real stopAtStrain;
 		//! distance of reference bodies in the direction of axis before straining started
 		Real originalLength;
 		vector<Real> originalWidths;
@@ -124,11 +126,12 @@
 		Real strain, avgStress;
 
 		virtual void applyCondition(MetaBody* rootBody);
-		UniaxialStrainer(){axis=2; asymmetry=0; currentStrainRate=0; originalLength=-1; limitStrain=0; notYetReversed=true; crossSectionArea=-1; needsInit=true; /* sensorsPusher=shared_ptr<UniaxialStrainSensorPusher>(); */ recordFile="/tmp/usct.data"; strain=avgStress=/*avgTransStrain=*/0; blockRotations=false; blockDisplacements=false;};
+		UniaxialStrainer(){axis=2; asymmetry=0; currentStrainRate=0; originalLength=-1; limitStrain=0; notYetReversed=true; crossSectionArea=-1; needsInit=true; /* sensorsPusher=shared_ptr<UniaxialStrainSensorPusher>(); */ recordFile="/tmp/usct.data"; strain=avgStress=/*avgTransStrain=*/0; blockRotations=false; blockDisplacements=false;  stopAtStrain=numeric_limits<Real>::quiet_NaN();};
 		virtual ~UniaxialStrainer(){};
 		void registerAttributes(){
 			DeusExMachina::registerAttributes();
 			REGISTER_ATTRIBUTE(strainRate);
+			REGISTER_ATTRIBUTE(stopAtStrain);
 			REGISTER_ATTRIBUTE(currentStrainRate);
 			REGISTER_ATTRIBUTE(axis);
 			REGISTER_ATTRIBUTE(asymmetry);

Modified: trunk/gui/qt3/QtGUI.cpp
===================================================================
--- trunk/gui/qt3/QtGUI.cpp	2008-11-22 22:54:46 UTC (rev 1580)
+++ trunk/gui/qt3/QtGUI.cpp	2008-11-24 12:18:47 UTC (rev 1581)
@@ -62,7 +62,7 @@
 	mainWindow->show();
 	app.setMainWidget(mainWindow);
 	#ifdef EMBED_PYTHON
-		LOG_INFO("Launching Python thread now...");
+		LOG_DEBUG("Launching Python thread now...");
 		//PyEval_InitThreads();
 		boost::thread pyThread(boost::function0<void>(&PythonUI::pythonSession));
 	#endif

Added: trunk/pkg/common/Engine/DeusExMachina/LinearInterpolate.hpp
===================================================================
--- trunk/pkg/common/Engine/DeusExMachina/LinearInterpolate.hpp	2008-11-22 22:54:46 UTC (rev 1580)
+++ trunk/pkg/common/Engine/DeusExMachina/LinearInterpolate.hpp	2008-11-24 12:18:47 UTC (rev 1581)
@@ -0,0 +1,47 @@
+// 2008 © Václav Šmilauer <eudoxos@xxxxxxxx>
+
+#include<vector>
+#include<iostream>
+#include<cassert>
+
+/* Linear interpolation function suitable only for sequential interpolation.
+ *
+ * Template parameter T must support: addition, subtraction, scalar multiplication.
+ *
+ * @param t "time" at which the interpolated variable should be evaluated.
+ * @param tt "time" points at which values are given; must be increasing.
+ * @param values values at "time" points specified by tt
+ * @param pos holds lookup state
+ *
+ * @return value at "time" t; out of range: t<t0 → value(t0), t>t_last → value(t_last)
+ */
+template<typename T>
+T linearInterpolate(const Real t, const std::vector<Real>& tt, const std::vector<T>& values, size_t& pos){
+	assert(tt.size()==values.size());
+	if(t<=tt[0]){ pos=0; return values[0];}
+	if(t>=*tt.rbegin()){ pos=tt.size()-2; return *values.rbegin();}
+	pos=std::min(pos,tt.size()-2);
+	while((tt[pos]>t) || (tt[pos+1]<t)){
+		assert(tt[pos]<tt[pos+1]);
+		if(tt[pos]>t) pos--;
+		else pos++;
+	}
+	const Real& t0=tt[pos], t1=tt[pos+1]; const T& v0=values[pos], v1=values[pos+1];
+	return v0+(v1-v0)*((t-t0)/(t1-t0));
+}
+
+#if 0
+	// test program
+	int main(void){
+		Real t,v;
+		std::vector<Real> tt,vv;
+		while(std::cin){
+			std::cin>>t>>v;
+			tt.push_back(t); vv.push_back(v);	
+		}
+		size_t pos;
+		for(Real t=0; t<10; t+=0.1){
+			std::cout<<t<<" "<<linearInterpolate<Real>(t,tt,vv,pos)<<std::endl;
+		}
+	}
+#endif 

Modified: trunk/pkg/common/Engine/DeusExMachina/RotationEngine.cpp
===================================================================
--- trunk/pkg/common/Engine/DeusExMachina/RotationEngine.cpp	2008-11-22 22:54:46 UTC (rev 1580)
+++ trunk/pkg/common/Engine/DeusExMachina/RotationEngine.cpp	2008-11-24 12:18:47 UTC (rev 1581)
@@ -9,12 +9,20 @@
 *************************************************************************/
 
 
-#include "RotationEngine.hpp"
+#include"RotationEngine.hpp"
 #include<yade/pkg-common/RigidBodyParameters.hpp>
 #include<yade/core/MetaBody.hpp>
 #include<yade/lib-base/yadeWm3Extra.hpp>
 
+#include<yade/pkg-common/LinearInterpolate.hpp>
 
+YADE_PLUGIN("RotationEngine","InterpolatingRotationEngine");
+
+void InterpolatingRotationEngine::applyCondition(MetaBody* rb){
+	angularVelocity=linearInterpolate<Real>(rb->simulationTime,times,velocities,pos);
+	RotationEngine::applyCondition(rb);
+}
+
 RotationEngine::RotationEngine()
 {
 	rotateAroundZero = false;
@@ -73,4 +81,3 @@
 
 }
 
-YADE_PLUGIN();

Modified: trunk/pkg/common/Engine/DeusExMachina/RotationEngine.hpp
===================================================================
--- trunk/pkg/common/Engine/DeusExMachina/RotationEngine.hpp	2008-11-22 22:54:46 UTC (rev 1580)
+++ trunk/pkg/common/Engine/DeusExMachina/RotationEngine.hpp	2008-11-24 12:18:47 UTC (rev 1581)
@@ -1,18 +1,14 @@
-/*************************************************************************
-*  Copyright (C) 2004 by Olivier Galizzi                                 *
-*  olivier.galizzi@xxxxxxx                                               *
-*                                                                        *
-*  This program is free software; it is licensed under the terms of the  *
-*  GNU General Public License v2 or later. See file LICENSE for details. *
-*************************************************************************/
+// © 2004 Olivier Galizzi <olivier.galizzi@xxxxxxx>
+// © 2008 Václav Šmilauer <eudoxos@xxxxxxxx>
+#pragma once
 
-#ifndef ROTATIONENGINE_HPP
-#define ROTATIONENGINE_HPP
-
 #include<yade/core/DeusExMachina.hpp>
-#include <Wm3Vector3.h>
+#include<Wm3Vector3.h>
 #include<yade/lib-base/yadeWm3.hpp>
 
+/*! Engine applying rotation (by setting angular velocity) to subscribed bodies.
+ * If rotateAroundZero is set, then each body is also displaced around zeroPoint.
+ */
 class RotationEngine : public DeusExMachina
 {
 	public :
@@ -31,8 +27,23 @@
 	REGISTER_CLASS_NAME(RotationEngine);
 	REGISTER_BASE_CLASS_NAME(DeusExMachina);
 };
-
 REGISTER_SERIALIZABLE(RotationEngine,false);
 
-#endif // ROTATIONENGINE_HPP
+/*! Engine applying rotation, finding current angular velocity by interpolating in times and velocities */
+class InterpolatingRotationEngine: public RotationEngine{
+	public:
+		//! list of times at which velocities are given; must be increasing
+		vector<Real> times;
+		//! list of angular velocities
+		vector<Real> velocities;
+		//! holder of interpolation state, should not be touched by the user.
+		size_t pos;
+		InterpolatingRotationEngine(){pos=0;}
+		void registerAttributes(){ RotationEngine::registerAttributes(); REGISTER_ATTRIBUTE(times); REGISTER_ATTRIBUTE(velocities); REGISTER_ATTRIBUTE(pos); }
+		void applyCondition(MetaBody* rb);
+	REGISTER_CLASS_NAME(InterpolatingRotationEngine);
+	REGISTER_BASE_CLASS_NAME(RotationEngine);
+};
+REGISTER_SERIALIZABLE(InterpolatingRotationEngine,false);
 
+