← Back to team overview

yade-dev team mailing list archive

[svn] r1735 - in trunk: core extra extra/clump extra/spherical-dem-simulator extra/tetra gui/py gui/qt3 pkg/common/Engine/DeusExMachina pkg/common/Engine/EngineUnit pkg/common/Engine/MetaEngine pkg/common/Engine/StandAloneEngine pkg/dem/Engine/DeusExMachina pkg/dem/Engine/StandAloneEngine pkg/dem/PreProcessor pkg/fem/Engine/StandAloneEngine pkg/fem/PreProcessor pkg/lattice/PreProcessor pkg/mass-spring/Engine/StandAloneEngine pkg/mass-spring/PreProcessor pkg/realtime-rigidbody/Engine/StandAloneEngine pkg/realtime-rigidbody/PreProcessor pkg/snow/PreProcessor

 

Author: eudoxos
Date: 2009-03-29 12:34:26 +0200 (Sun, 29 Mar 2009)
New Revision: 1735

Modified:
   trunk/core/BexContainer.hpp
   trunk/core/MetaBody.cpp
   trunk/core/MetaBody.hpp
   trunk/core/PhysicalAction.hpp
   trunk/extra/BrefcomTestGen.cpp
   trunk/extra/clump/Shop.cpp
   trunk/extra/spherical-dem-simulator/SphericalDEMSimulator.cpp
   trunk/extra/tetra/Tetra.cpp
   trunk/gui/py/yadeControl.cpp
   trunk/gui/qt3/SimulationController.cpp
   trunk/gui/qt3/SimulationController.hpp
   trunk/gui/qt3/YadeQtMainWindow.cpp
   trunk/pkg/common/Engine/DeusExMachina/CinemCNCEngine.cpp
   trunk/pkg/common/Engine/DeusExMachina/CinemKNCEngine.cpp
   trunk/pkg/common/Engine/DeusExMachina/DisplacementToForceEngine.cpp
   trunk/pkg/common/Engine/DeusExMachina/GravityEngines.cpp
   trunk/pkg/common/Engine/DeusExMachina/MomentEngine.cpp
   trunk/pkg/common/Engine/EngineUnit/CundallNonViscousDamping.cpp
   trunk/pkg/common/Engine/EngineUnit/CundallNonViscousDamping.hpp
   trunk/pkg/common/Engine/EngineUnit/NewtonsForceLaw.cpp
   trunk/pkg/common/Engine/EngineUnit/NewtonsForceLaw.hpp
   trunk/pkg/common/Engine/EngineUnit/NewtonsMomentumLaw.cpp
   trunk/pkg/common/Engine/EngineUnit/NewtonsMomentumLaw.hpp
   trunk/pkg/common/Engine/MetaEngine/ConstitutiveLaw.hpp
   trunk/pkg/common/Engine/MetaEngine/PhysicalActionApplier.cpp
   trunk/pkg/common/Engine/MetaEngine/PhysicalActionApplier.hpp
   trunk/pkg/common/Engine/MetaEngine/PhysicalActionApplierUnit.hpp
   trunk/pkg/common/Engine/MetaEngine/PhysicalActionDamper.cpp
   trunk/pkg/common/Engine/MetaEngine/PhysicalActionDamper.hpp
   trunk/pkg/common/Engine/MetaEngine/PhysicalActionDamperUnit.hpp
   trunk/pkg/common/Engine/StandAloneEngine/PhysicalActionContainerInitializer.cpp
   trunk/pkg/dem/Engine/DeusExMachina/CapillaryRecorder.cpp
   trunk/pkg/dem/Engine/DeusExMachina/HydraulicForceEngine.cpp
   trunk/pkg/dem/Engine/DeusExMachina/MakeItFlat.cpp
   trunk/pkg/dem/Engine/DeusExMachina/ResultantForceEngine.cpp
   trunk/pkg/dem/Engine/DeusExMachina/ResultantForceEngine.hpp
   trunk/pkg/dem/Engine/DeusExMachina/TriaxialStressController.cpp
   trunk/pkg/dem/Engine/DeusExMachina/WallStressRecorder.cpp
   trunk/pkg/dem/Engine/StandAloneEngine/CapillaryCohesiveLaw.cpp
   trunk/pkg/dem/Engine/StandAloneEngine/CohesiveFrictionalContactLaw.cpp
   trunk/pkg/dem/Engine/StandAloneEngine/ContactLaw1.cpp
   trunk/pkg/dem/Engine/StandAloneEngine/ElasticCohesiveLaw.cpp
   trunk/pkg/dem/Engine/StandAloneEngine/ForceRecorder.cpp
   trunk/pkg/dem/Engine/StandAloneEngine/GeometricalModelForceColorizer.cpp
   trunk/pkg/dem/Engine/StandAloneEngine/GlobalStiffnessCounter.cpp
   trunk/pkg/dem/Engine/StandAloneEngine/MyTetrahedronLaw.cpp
   trunk/pkg/dem/Engine/StandAloneEngine/ViscousForceDamping.cpp
   trunk/pkg/dem/Engine/StandAloneEngine/VolumicContactLaw.cpp
   trunk/pkg/dem/PreProcessor/CohesiveTriaxialTest.cpp
   trunk/pkg/dem/PreProcessor/DirectShearCis.cpp
   trunk/pkg/dem/PreProcessor/Funnel.cpp
   trunk/pkg/dem/PreProcessor/HydraulicTest.cpp
   trunk/pkg/dem/PreProcessor/MembraneTest.cpp
   trunk/pkg/dem/PreProcessor/ModifiedTriaxialTest.cpp
   trunk/pkg/dem/PreProcessor/SDECImpactTest.cpp
   trunk/pkg/dem/PreProcessor/SDECLinkedSpheres.cpp
   trunk/pkg/dem/PreProcessor/SDECMovingWall.cpp
   trunk/pkg/dem/PreProcessor/SDECSpheresPlane.cpp
   trunk/pkg/dem/PreProcessor/STLImporterTest.cpp
   trunk/pkg/dem/PreProcessor/SimpleShear.cpp
   trunk/pkg/dem/PreProcessor/TestSimpleViscoelastic.cpp
   trunk/pkg/dem/PreProcessor/TetrahedronsTest.cpp
   trunk/pkg/dem/PreProcessor/ThreePointBending.cpp
   trunk/pkg/dem/PreProcessor/TriaxialTest.cpp
   trunk/pkg/dem/PreProcessor/TriaxialTest.hpp
   trunk/pkg/dem/PreProcessor/TriaxialTestWater.cpp
   trunk/pkg/fem/Engine/StandAloneEngine/FEMLaw.cpp
   trunk/pkg/fem/PreProcessor/FEMBeam.cpp
   trunk/pkg/lattice/PreProcessor/LatticeExample.cpp
   trunk/pkg/mass-spring/Engine/StandAloneEngine/MassSpringLaw.cpp
   trunk/pkg/mass-spring/PreProcessor/HangingCloth.cpp
   trunk/pkg/realtime-rigidbody/Engine/StandAloneEngine/FrictionLessElasticContactLaw.cpp
   trunk/pkg/realtime-rigidbody/PreProcessor/BoxStack.cpp
   trunk/pkg/realtime-rigidbody/PreProcessor/RotatingBox.cpp
   trunk/pkg/snow/PreProcessor/SnowCreepTest.cpp
   trunk/pkg/snow/PreProcessor/SnowVoxelsLoader.cpp
Log:
1. Remove MetaBody::physicalActions if compiling with BEX_CONTAINER (default)
2. Make everything work with both BexContainer and deprecated PhysicalActionContainer
3. Change PhysicalActionDamper, PhysicalActionDamperUnit, PhysicalActionApplier and PhysicalActionApplierUnit to dispatch only according to PhysicalParameters (not PhysicalAction anymore). That means that only one unit will be called for each body and that NewtonsMomentumLaw has to do the job of NewtonsForceLaw as well (same for CundallNonViscousMomentumDamping).
4. Fix (finally) defaultDt computation in TriaxialTest (forgotten assignment to defaultDt in the GlobalStiffnessTimeStepper)
5. Fix (finally?) timestep manipulation form within the QtGUI. If reloading the same file, timestep settings will be preserved, otherwise those saved in the XML are used.



Modified: trunk/core/BexContainer.hpp
===================================================================
--- trunk/core/BexContainer.hpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/core/BexContainer.hpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -28,6 +28,12 @@
 		}
 
 		inline void ensureSynced(){ if(!synced) throw runtime_error("BexContainer not thread-synchronized; call sync() first!"); }
+
+		/*! Function to allow friend classes to get force even if not synced.
+		* Dangerous! The caller must know what it is doing! */
+		const Vector3r& getForceUnsynced (body_id_t id){ensureSize(id); return _force[id];}
+		const Vector3r& getTorqueUnsynced(body_id_t id){ensureSize(id); return _force[id];}
+		friend class PhysicalActionDamperUnit;
 	public:
 		BexContainer(): size(0), synced(true),syncCount(0){
 			nThreads=omp_get_max_threads();
@@ -102,6 +108,9 @@
 		std::vector<Vector3r> _torque;
 		size_t size;
 		inline void ensureSize(body_id_t id){ if(size<=(size_t)id) resize(min((size_t)1.5*(id+100),(size_t)(id+2000)));}
+		friend class PhysicalActionDamperUnit;
+		const Vector3r& getForceUnsynced (body_id_t id){ return getForce(id);}
+		const Vector3r& getTorqueUnsynced(body_id_t id){ return getForce(id);}
 	public:
 		BexContainer(): size(0),syncCount(0){}
 		const Vector3r& getForce(body_id_t id){ensureSize(id); return _force[id];}

Modified: trunk/core/MetaBody.cpp
===================================================================
--- trunk/core/MetaBody.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/core/MetaBody.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -35,7 +35,10 @@
 bool TimingInfo::enabled=false;
 
 MetaBody::MetaBody() :
-	  Body(),bodies(new BodyRedirectionVector), interactions(new InteractionVecMap), persistentInteractions(interactions),transientInteractions(interactions),physicalActions(new PhysicalActionVectorVector)
+	Body(),bodies(new BodyRedirectionVector), interactions(new InteractionVecMap), persistentInteractions(interactions),transientInteractions(interactions)
+	#ifndef BEX_CONTAINER
+	  	,physicalActions(new PhysicalActionVectorVector)
+	#endif
 {	
 	engines.clear();
 	initializers.clear();

Modified: trunk/core/MetaBody.hpp
===================================================================
--- trunk/core/MetaBody.hpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/core/MetaBody.hpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -29,9 +29,10 @@
 		__attribute__((__deprecated__)) shared_ptr<InteractionContainer>&	persistentInteractions; // disappear, reappear according to physical (or any other non-spatial) criterion
 		shared_ptr<InteractionContainer>&	transientInteractions;	// disappear, reappear according to spatial criterion
 
-		shared_ptr<PhysicalActionContainer>	physicalActions;
 		#ifdef BEX_CONTAINER
 			BexContainer bex;
+		#else
+			shared_ptr<PhysicalActionContainer>	physicalActions;
 		#endif
 		vector<shared_ptr<Serializable> > miscParams; // will set static parameters during deserialization (primarily for GLDraw functors which otherwise have no attribute access)
 		//! tags like mp3 tags: author, date, version, description etc.
@@ -65,7 +66,9 @@
 		(initializers)
 		(bodies)
 		(transientInteractions)
-		(physicalActions)
+		#ifndef BEX_CONTAINER
+			(physicalActions)
+		#endif
 		(miscParams)
 		(dispParams)
 		(dt)

Modified: trunk/core/PhysicalAction.hpp
===================================================================
--- trunk/core/PhysicalAction.hpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/core/PhysicalAction.hpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -20,9 +20,6 @@
 class PhysicalAction : public Serializable, public Indexable
 {
 	public :
-// FIXME - correct usage of this class, so that functions add(), etc.. are actually used!
-//		virtual void add(const shared_ptr<PhysicalAction>& )	{throw;};
-//		virtual void sub(const shared_ptr<PhysicalAction>& )	{throw;};
 
 		virtual void reset() 				{throw;};
 		virtual shared_ptr<PhysicalAction> clone()	{throw;};

Modified: trunk/extra/BrefcomTestGen.cpp
===================================================================
--- trunk/extra/BrefcomTestGen.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/extra/BrefcomTestGen.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -6,26 +6,8 @@
 YADE_PLUGIN("BrefcomTestGen");
 
 
-/************************ BrefcomTestGen ****************************/
-/*#include<yade/pkg-common/MetaInteractingGeometry2AABB.hpp>
-#include<yade/pkg-common/MetaInteractingGeometry.hpp>
-#include<yade/pkg-common/Box.hpp>
-#include<yade/pkg-common/Sphere.hpp>
-#include<yade/pkg-common/PersistentSAPCollider.hpp>
 
-#include<yade/pkg-common/BodyRedirectionVector.hpp>
-#include<yade/pkg-common/InteractionVecSet.hpp>
-#include<yade/pkg-common/PhysicalActionVectorVector.hpp>
 
-#include<yade/pkg-common/InteractingBox.hpp>
-
-#include<yade/pkg-common/InteractingBox2AABB.hpp>
-#include<yade/pkg-common/Momentum.hpp>
-#include<yade/pkg-common/Force.hpp>
-#include<yade/pkg-dem/InteractingSphere2InteractingSphere4SpheresContactGeometry.hpp>
-#include<yade/pkg-dem/InteractingBox2InteractingSphere4SpheresContactGeometry.hpp>*/
-
-
 #include<yade/pkg-common/PhysicalActionContainerReseter.hpp>
 #include<yade/pkg-common/PhysicalActionContainerInitializer.hpp>
 #include<yade/pkg-common/InteractingSphere.hpp>

Modified: trunk/extra/clump/Shop.cpp
===================================================================
--- trunk/extra/clump/Shop.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/extra/clump/Shop.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -232,9 +232,6 @@
 	shared_ptr<AABB> aabb(new AABB); aabb->diffuseColor=Vector3r(0,0,1);
 	rootBody->boundingVolume=YADE_PTR_CAST<BoundingVolume>(aabb);
 	
-	rootBody->transientInteractions=shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions=shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
-	rootBody->bodies=shared_ptr<BodyContainer>(new BodyRedirectionVector);
 
 	return rootBody;
 }

Modified: trunk/extra/spherical-dem-simulator/SphericalDEMSimulator.cpp
===================================================================
--- trunk/extra/spherical-dem-simulator/SphericalDEMSimulator.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/extra/spherical-dem-simulator/SphericalDEMSimulator.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -206,12 +206,19 @@
 		shared_ptr<PhysicalActionDamper> pade = dynamic_pointer_cast<PhysicalActionDamper>(e);
 		if (pade)
 		{	
+		#ifdef BEX_CONTAINER
+			shared_ptr<CundallNonViscousForceDamping> cnvfd = YADE_PTR_CAST<CundallNonViscousForceDamping>(pade->getExecutor("RigidBodyParameters"));
+			assert(cnvfd);
+			forceDamping=cnvfd->damping;
+			momentumDamping=forceDamping;
+		#else
 			shared_ptr<CundallNonViscousForceDamping> cnvfd = YADE_PTR_CAST<CundallNonViscousForceDamping>(pade->getExecutor("Force","RigidBodyParameters"));
 			shared_ptr<CundallNonViscousMomentumDamping> cnvmd = YADE_PTR_CAST<CundallNonViscousMomentumDamping>(pade->getExecutor("Momentum","RigidBodyParameters"));
 			assert(cnvfd);
 			assert(cnvmd);
 			forceDamping 	= cnvfd->damping;
 			momentumDamping = cnvmd->damping;
+		#endif
 		}
 	}
 }

Modified: trunk/extra/tetra/Tetra.cpp
===================================================================
--- trunk/extra/tetra/Tetra.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/extra/tetra/Tetra.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -405,10 +405,17 @@
 		TRWM3VEC(F);
 		TRWM3VEC((physB->se3.position-contactGeom->contactPoint).Cross(F));
 
-		static_pointer_cast<Force>(rootBody->physicalActions->find(idA,actionForce->getClassIndex()))->force-=F;
-		static_pointer_cast<Force>(rootBody->physicalActions->find(idB,actionForce->getClassIndex()))->force+=F;
-		static_pointer_cast<Momentum>(rootBody->physicalActions->find(idA,actionMomentum->getClassIndex()))->momentum-=(physA->se3.position-contactGeom->contactPoint).Cross(F);
-		static_pointer_cast<Momentum>(rootBody->physicalActions->find(idB,actionMomentum->getClassIndex()))->momentum+=(physB->se3.position-contactGeom->contactPoint).Cross(F);
+		#ifdef BEX_CONTAINER
+			rootBody->bex.addForce (idA,-F);
+			rootBody->bex.addForce (idB, F);
+			rootBody->bex.addTorque(idA,-(physA->se3.position-contactGeom->contactPoint).Cross(F));
+			rootBody->bex.addTorque(idB, (physA->se3.position-contactGeom->contactPoint).Cross(F));
+		#else
+			static_pointer_cast<Force>(rootBody->physicalActions->find(idA,actionForce->getClassIndex()))->force-=F;
+			static_pointer_cast<Force>(rootBody->physicalActions->find(idB,actionForce->getClassIndex()))->force+=F;
+			static_pointer_cast<Momentum>(rootBody->physicalActions->find(idA,actionMomentum->getClassIndex()))->momentum-=(physA->se3.position-contactGeom->contactPoint).Cross(F);
+			static_pointer_cast<Momentum>(rootBody->physicalActions->find(idB,actionMomentum->getClassIndex()))->momentum+=(physB->se3.position-contactGeom->contactPoint).Cross(F);
+		#endif
 	}
 }
 

Modified: trunk/gui/py/yadeControl.cpp
===================================================================
--- trunk/gui/py/yadeControl.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/gui/py/yadeControl.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -633,14 +633,15 @@
 		rb->bodies=bc;
 	}
 	string bodyContainer_get(string clss){ return OMEGA.getRootBody()->bodies->getClassName(); }
+	#ifndef BEX_CONTAINER
+		void physicalActionContainer_set(string clss){
+			MetaBody* rb=OMEGA.getRootBody().get();
+			shared_ptr<PhysicalActionContainer> pac=dynamic_pointer_cast<PhysicalActionContainer>(ClassFactory::instance().createShared(clss));
+			rb->physicalActions=pac;
+		}
+		string physicalActionContainer_get(string clss){ return OMEGA.getRootBody()->physicalActions->getClassName(); }
+	#endif
 
-	void physicalActionContainer_set(string clss){
-		MetaBody* rb=OMEGA.getRootBody().get();
-		shared_ptr<PhysicalActionContainer> pac=dynamic_pointer_cast<PhysicalActionContainer>(ClassFactory::instance().createShared(clss));
-		rb->physicalActions=pac;
-	}
-	string physicalActionContainer_get(string clss){ return OMEGA.getRootBody()->physicalActions->getClassName(); }
-
 };
 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(omega_run_overloads,run,0,2);
 
@@ -698,7 +699,6 @@
 		.def("isChildClassOf",&pyOmega::isChildClassOf)
 		.add_property("bodyContainer",&pyOmega::bodyContainer_get,&pyOmega::bodyContainer_set)
 		.add_property("interactionContainer",&pyOmega::interactionContainer_get,&pyOmega::interactionContainer_set)
-		.add_property("actionContainer",&pyOmega::physicalActionContainer_get,&pyOmega::physicalActionContainer_set)
 		.add_property("timingEnabled",&pyOmega::timingEnabled_get,&pyOmega::timingEnabled_set)
 		#ifdef BEX_CONTAINER
 			.add_property("bexSyncCount",&pyOmega::bexSyncCount_get,&pyOmega::bexSyncCount_set)

Modified: trunk/gui/qt3/SimulationController.cpp
===================================================================
--- trunk/gui/qt3/SimulationController.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/gui/qt3/SimulationController.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -75,13 +75,15 @@
 	maxNbViews=0;
 	//addNewView(); // postpone until a file is loaded
 
-	// there is file existence assertion in lodSimulationFromFilename, so yade will abort cleanly...
+	// there is file existence assertion in loadSimulationFromFilename, so yade will abort cleanly...
 	LOG_DEBUG("Omega's simulation filename: `"<<Omega::instance().getSimulationFileName()<<"'");
 	if (Omega::instance().getSimulationFileName()!="" && (!Omega::instance().getRootBody() || (Omega::instance().getRootBody()->bodies->size()==0 && Omega::instance().getRootBody()->engines.size()==0))){
 		loadSimulationFromFileName(Omega::instance().getSimulationFileName());
 	}
+	else{ LOG_DEBUG("Not loading simulation in ctor"); }
 	// run timer ANY TIME (simulation may be started asynchronously)
 	updateTimerId=startTimer(refreshTime);
+
 }
 
 /* restart timer with SimulationController::refreshTime */
@@ -131,16 +133,23 @@
 }
 
 
-void SimulationController::loadSimulationFromFileName(const std::string& fileName,bool center, bool useTimeStepperIfPresent)
+void SimulationController::loadSimulationFromFileName(const std::string& fileName,bool center)
 {
 	assert(filesystem::exists(fileName) || fileName.find(":memory:")==(size_t)0);
 
 		Omega::instance().finishSimulationLoop();
 		Omega::instance().joinSimulationLoop();
 
+
+		bool keepTimeStepperSettings=Omega::instance().getSimulationFileName()==fileName;
+		Real prevDt=Omega::instance().getTimeStep();
+		bool timeStepperUsed=Omega::instance().timeStepperActive();
+
 		Omega::instance().setSimulationFileName(fileName);
 		try
 		{
+			//boost::mutex::scoped_lock lock(timeMutex);
+
 			Omega::instance().loadSimulation(); // expecting throw here.
 			string fullName = string(filesystem::basename(fileName.data()))+string(filesystem::extension(fileName.data()));
 			tlCurrentSimulation->setText(fullName); 
@@ -151,6 +160,24 @@
 			pbResetSimulation->setEnabled(true);
 			pbOneSimulationStep->setEnabled(true);
 
+			if(keepTimeStepperSettings){
+				LOG_DEBUG("The same simulation loaded again, keeping time stepper settings.");
+				// if we were using fixed time, set that fixed value now
+				if(!timeStepperUsed) { Omega::instance().setTimeStep(prevDt); LOG_DEBUG("Using previous fixed time step "<<prevDt);}
+				// recover whether timestepper was used or not
+				Omega::instance().skipTimeStepper(!timeStepperUsed);
+				LOG_DEBUG("Timestepper is "<<(timeStepperUsed?"":"NOT ")<<"being used.");
+			}
+			else {
+				LOG_DEBUG("New simulation loaded, timestepper is "<<(Omega::instance().timeStepperActive()?"":"NOT ")<<"being used (as per XML).");
+			}
+
+			//rbTimeStepper->setEnabled(Omega::instance().containTimeStepper());
+			//LOG_DEBUG("(Un)checking rbTimeStepper and rbFixed.");
+			//rbTimeStepper->setChecked(Omega::instance().timeStepperActive());
+			//rbFixed->setChecked(!Omega::instance().timeStepperActive());
+
+			#if 0
 			Real dt=Omega::instance().getTimeStep();
 			int exp10=(int)floor(log10(dt));
 			sbSecond->setValue((int)(dt/(pow(10.,exp10)))); // we may lose quite some precision here :-(
@@ -170,6 +197,7 @@
 				wasUsingTimeStepper = false;
 			}
 			skipTimeStepper=!wasUsingTimeStepper;
+			#endif
 		} 
 		catch(SerializableError& e) // catching it...
 		{
@@ -267,7 +295,7 @@
 	pbStopClicked();
 
 	std::string name=Omega::instance().getSimulationFileName(); 
-	loadSimulationFromFileName(name,false /* don't re-center scene */,wasUsingTimeStepper /* respect timeStepper setting from the prvious run*/);
+	loadSimulationFromFileName(name,false /* don't re-center scene */);
 
 	if(Omega::instance().getRootBody())
 	{
@@ -293,22 +321,34 @@
 	/* i: buttonGroupId, which is 0 for timeStepper, 2 for fixed step */
 	switch (i)
 	{
-		case 0 : //Use timeStepper
-			changeSkipTimeStepper = true;
-			skipTimeStepper = false;
+		case 0 : {//Use timeStepper
+			//changeSkipTimeStepper = true;
+			//skipTimeStepper = false;
 			wasUsingTimeStepper=true;
+			//boost::mutex::scoped_lock lock(timeMutex);
+			Omega::instance().skipTimeStepper(false);
 			break;
+			}
 		case 1 : // Try RealTime -- deprecated
-			changeSkipTimeStepper = true;
-			skipTimeStepper = true;
-			wasUsingTimeStepper=false;
+			//changeSkipTimeStepper = true;
+			//skipTimeStepper = true;
+			//wasUsingTimeStepper=false;
+			throw logic_error("RealTime timestep is deprecated and you couldn't click on it!");
 			break;
-		case 2 : // use fixed time Step
-			changeSkipTimeStepper = true;
-			skipTimeStepper = true;
+		case 2 : {// use fixed time Step
+			//changeSkipTimeStepper = true;
+			//skipTimeStepper = true;
+			//boost::mutex::scoped_lock lock(timeMutex);
 			changeTimeStep = true;
 			wasUsingTimeStepper=false;
+			Omega::instance().skipTimeStepper(true);
+			if(sbSecond->value()==0){ sbSecond->setValue(9); sb10PowerSecond->setValue(sb10PowerSecond->value()-1); }
+			if(sbSecond->value()==10){ sbSecond->setValue(1); sb10PowerSecond->setValue(sb10PowerSecond->value()+1); }
+			Real second = (Real)(sbSecond->value());
+			Real powerSecond = (Real)(sb10PowerSecond->value());
+			Omega::instance().setTimeStep(second*Mathr::Pow(10,powerSecond));
 			break;
+		}
 		default: break;
 	}
 
@@ -317,15 +357,19 @@
 
 void SimulationController::sb10PowerSecondValueChanged(int)
 {
-	if(!rbFixed->isOn()){ rbFixed->toggle(); bgTimeStepClicked(2); } // this should do the callback as if user clicked fixed timestepper button
-	changeTimeStep = true;
+//	if(!rbFixed->isOn() && userChangingTimestep){ rbFixed->toggle(); bgTimeStepClicked(2); } // this should do the callback as if user clicked fixed timestepper button
+//	changeTimeStep = true;
+	//assert(rbFixed->isOn()); 
+	if(rbFixed->isOn()) bgTimeStepClicked(2);
 }
 
 
 void SimulationController::sbSecondValueChanged(int)
 { 
-	if(!rbFixed->isOn()){ rbFixed->toggle(); bgTimeStepClicked(2); } // dtto
-	changeTimeStep = true;
+//	if(!rbFixed->isOn() && userChangingTimestep){ rbFixed->toggle(); bgTimeStepClicked(2); } // dtto
+//	changeTimeStep = true;
+	//assert(rbFixed->isOn());
+	if(rbFixed->isOn()) bgTimeStepClicked(2);
 }
 
 void SimulationController::sbRefreshValueChanged(int v)
@@ -399,29 +443,23 @@
     snprintf(strStopAtIter,64,"stopAtIter #%ld",Omega::instance().getRootBody()->stopAtIteration);
     labelStopAtIter->setText(strStopAtIter);
 
-	if (changeSkipTimeStepper) Omega::instance().skipTimeStepper(skipTimeStepper);
-	if (changeTimeStep) {
-		// wrap the mantissa around
-		if(sbSecond->value()==0){ sbSecond->setValue(9); sb10PowerSecond->setValue(sb10PowerSecond->value()-1); }
-		if(sbSecond->value()==10){ sbSecond->setValue(1); sb10PowerSecond->setValue(sb10PowerSecond->value()+1); }
-		Real second = (Real)(sbSecond->value());
-		Real powerSecond = (Real)(sb10PowerSecond->value());
-		Omega::instance().setTimeStep(second*Mathr::Pow(10,powerSecond));
-	} else {
-		Real dt=Omega::instance().getTimeStep();
-		int exp10=floor(log10(dt));
-		sb10PowerSecond->setValue(exp10);
-		sbSecond->setValue((int)(.1+dt/(pow((float)10,exp10)))); // .1: rounding issues
-	}
+	//boost::mutex::scoped_lock lock(timeMutex);
 
+	//if (changeSkipTimeStepper) Omega::instance().skipTimeStepper(skipTimeStepper);
+	//if (changeTimeStep) {
+	//	// wrap the mantissa around
+	//} else {
+	//}
+
 	if(sbRefreshTime->value()!=refreshTime) sbRefreshTime->setValue(refreshTime);
 
+
 	char strStep[64];
 	snprintf(strStep,64,"step %g",(double)Omega::instance().getTimeStep());
 	labelStep->setText(string(strStep));
 
-	changeSkipTimeStepper = false;
-	changeTimeStep = false;
+	//changeSkipTimeStepper = false;
+	//changeTimeStep = false;
 
 	//cerr<<"dt="<<dt<<",exp10="<<exp10<<",10^exp10="<<pow((float)10,exp10)<<endl;
 
@@ -437,9 +475,17 @@
 	pbResetSimulation->setEnabled(hasSimulation && hasFileName);
 	pbOneSimulationStep->setEnabled(hasSimulation && !isRunning);
 	rbTimeStepper->setEnabled(hasTimeStepper);
+	sbSecond->setEnabled(!usesTimeStepper);
+	sb10PowerSecond->setEnabled(!usesTimeStepper);
+
 	// conditionals only avoid setting the state that is already set, to avoid spurious signals
-	if(rbFixed->isChecked()==usesTimeStepper) rbFixed->setChecked(!usesTimeStepper);
-	if(rbTimeStepper->isChecked()!=usesTimeStepper) rbTimeStepper->setChecked(usesTimeStepper);
+	if(rbFixed->isChecked()==usesTimeStepper){ LOG_DEBUG("Checking rbFixed"); rbFixed->setChecked(!usesTimeStepper); }
+	if(rbTimeStepper->isChecked()!=usesTimeStepper){ LOG_DEBUG("Checking rbTimeStepper"); rbTimeStepper->setChecked(usesTimeStepper); }
 
+	Real dt=Omega::instance().getTimeStep();
+	int exp10=floor(log10(dt));
+	sb10PowerSecond->setValue(exp10);
+	sbSecond->setValue((int)(.1+dt/(pow((float)10,exp10)))); // .1: rounding issues
+
 }
 

Modified: trunk/gui/qt3/SimulationController.hpp
===================================================================
--- trunk/gui/qt3/SimulationController.hpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/gui/qt3/SimulationController.hpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -42,6 +42,8 @@
         boost::posix_time::time_duration estimation;
 		boost::posix_time::ptime iterPerSec_LastLocalTime;
 
+		boost::mutex timeMutex;
+
 	
 		void doUpdate();
 		void restartTimer();
@@ -52,7 +54,7 @@
 		void addNewView();
 	
 	public : 
-		void loadSimulationFromFileName(const std::string& fileName,bool center=true, bool useTimeStepperIfPresent=true);
+		void loadSimulationFromFileName(const std::string& fileName,bool center=true);
 		bool changeSkipTimeStepper,skipTimeStepper,changeTimeStep,wasUsingTimeStepper;
 		SimulationController (QWidget * parent=NULL);
 		virtual ~SimulationController () {}; 

Modified: trunk/gui/qt3/YadeQtMainWindow.cpp
===================================================================
--- trunk/gui/qt3/YadeQtMainWindow.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/gui/qt3/YadeQtMainWindow.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -98,7 +98,7 @@
 	}
 }
 
-void YadeQtMainWindow::loadSimulation(string file){createController();	controller->loadSimulationFromFileName(file); lookDown(glViews[0]);}
+void YadeQtMainWindow::loadSimulation(string file){createController(); while(!(bool)(controller)) usleep(50000); controller->loadSimulationFromFileName(file); lookDown(glViews[0]);}
 void YadeQtMainWindow::centerViews(){FOREACH(const shared_ptr<GLViewer>& glv,glViews){ if(glv){ glv->centerScene();}}}
 
 

Modified: trunk/pkg/common/Engine/DeusExMachina/CinemCNCEngine.cpp
===================================================================
--- trunk/pkg/common/Engine/DeusExMachina/CinemCNCEngine.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/DeusExMachina/CinemCNCEngine.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -187,8 +187,11 @@
 
 void CinemCNCEngine::computeDu(MetaBody* ncb)
 {
-
-	Vector3r& F_sup = dynamic_cast<Force*>(ncb->physicalActions->find(id_boxhaut,actionForce->getClassIndex()) . get() )->force;
+	#ifdef BEX_CONTAINER
+		ncb->bex.sync(); Vector3r F_sup=ncb->bex.getForce(id_boxhaut);
+	#else
+		Vector3r& F_sup = dynamic_cast<Force*>(ncb->physicalActions->find(id_boxhaut,actionForce->getClassIndex()) . get() )->force;
+	#endif
 	
 	if(firstRun)
 	{

Modified: trunk/pkg/common/Engine/DeusExMachina/CinemKNCEngine.cpp
===================================================================
--- trunk/pkg/common/Engine/DeusExMachina/CinemKNCEngine.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/DeusExMachina/CinemKNCEngine.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -180,7 +180,11 @@
 void CinemKNCEngine::computeDu(MetaBody* ncb)
 {
 
-	Vector3r& F_sup = dynamic_cast<Force*>(ncb->physicalActions->find(id_boxhaut,actionForce->getClassIndex()) . get() )->force;
+	#ifdef BEX_CONTAINER
+		ncb->bex.sync(); Vector3r F_sup=ncb->bex.getForce(id_boxhaut);
+	#else
+		Vector3r& F_sup = dynamic_cast<Force*>(ncb->physicalActions->find(id_boxhaut,actionForce->getClassIndex()) . get() )->force;
+	#endif
 	
 	if(firstRun)
 	{

Modified: trunk/pkg/common/Engine/DeusExMachina/DisplacementToForceEngine.cpp
===================================================================
--- trunk/pkg/common/Engine/DeusExMachina/DisplacementToForceEngine.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/DeusExMachina/DisplacementToForceEngine.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -56,10 +56,18 @@
 	std::vector<int>::const_iterator ii = subscribedBodies.begin();
 	std::vector<int>::const_iterator iiEnd = subscribedBodies.end();
 
+	#ifdef BEX_CONTAINER
+		ncb->bex.sync();
+	#endif
+
 	for(;ii!=iiEnd;++ii)
 		if( bodies->exists(*ii) )
 		{
-			Vector3r current_force=static_cast<Force*>( ncb->physicalActions->find( ((*bodies)[*ii])->getId() , actionParameterForce->getClassIndex() ).get() )->force;
+			#ifdef BEX_CONTAINER
+				Vector3r current_force=ncb->bex.getForce(*ii);
+			#else
+				Vector3r current_force=static_cast<Force*>( ncb->physicalActions->find(*ii,actionParameterForce->getClassIndex() ).get() )->force;
+			#endif
 
 			Real current_length_sq = 
 				  (targetForceMask[0] != 0) ? current_force[0]*current_force[0]:0.0 

Modified: trunk/pkg/common/Engine/DeusExMachina/GravityEngines.cpp
===================================================================
--- trunk/pkg/common/Engine/DeusExMachina/GravityEngines.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/DeusExMachina/GravityEngines.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -24,11 +24,11 @@
 		if(b->isClumpMember()) continue;
 		shared_ptr<ParticleParameters> p=YADE_PTR_CAST<ParticleParameters>(b->physicalParameters);
 		if(p!=0) //not everything derives from ParticleParameters; this line was    assert(p); - Janek
-#ifdef BEX_CONTAINER
+		#ifdef BEX_CONTAINER
 			ncb->bex.addForce(b->getId(),gravity*p->mass);
-#else
+		#else
 			static_cast<Force*>(ncb->physicalActions->find(b->getId(),cachedForceClassIndex).get())->force+=gravity*p->mass;
-#endif
+		#endif
 	}
 }
 
@@ -38,13 +38,13 @@
 		if(b->isClumpMember() || b->getId()==centralBody) continue; // skip clump members and central body
 		Real F=accel*YADE_PTR_CAST<ParticleParameters>(b->physicalParameters)->mass;
 		Vector3r toCenter=centralPos-b->physicalParameters->se3.position; toCenter.Normalize();
-#ifdef BEX_CONTAINER
-		rootBody->bex.addForce(b->getId(),F*toCenter);
-		if(reciprocal) rootBody->bex.addForce(centralBody,-F*toCenter);
-#else
-		static_cast<Force*>(rootBody->physicalActions->find(b->getId(),cachedForceClassIndex).get())->force+=F*toCenter;
-		if(reciprocal) static_cast<Force*>(rootBody->physicalActions->find(centralBody,cachedForceClassIndex).get())->force-=F*toCenter;
-#endif
+		#ifdef BEX_CONTAINER
+			rootBody->bex.addForce(b->getId(),F*toCenter);
+			if(reciprocal) rootBody->bex.addForce(centralBody,-F*toCenter);
+		#else
+			static_cast<Force*>(rootBody->physicalActions->find(b->getId(),cachedForceClassIndex).get())->force+=F*toCenter;
+			if(reciprocal) static_cast<Force*>(rootBody->physicalActions->find(centralBody,cachedForceClassIndex).get())->force-=F*toCenter;
+		#endif
 	}
 }
 
@@ -58,11 +58,11 @@
 		const Vector3r x2=axisPoint+axisDirection;
 		Vector3r closestAxisPoint=(x2-x1) * /* t */ (-(x1-x0).Dot(x2-x1))/((x2-x1).SquaredLength());
 		Vector3r toAxis=closestAxisPoint-x0; toAxis.Normalize();
-#ifdef BEX_CONTAINER
-		rootBody->bex.addForce(b->getId(),acceleration*myMass*toAxis);
-#else
-		static_pointer_cast<Force>(rootBody->physicalActions->find(b->getId(),cachedForceClassIndex))->force+=acceleration*myMass*toAxis;
-		//if(b->getId()==20){ TRVAR3(toAxis,acceleration*myMass*toAxis,static_pointer_cast<Force>(rootBody->physicalActions->find(b->getId(),cachedForceClassIndex))->force); }
-#endif
+		#ifdef BEX_CONTAINER
+			rootBody->bex.addForce(b->getId(),acceleration*myMass*toAxis);
+		#else
+			static_pointer_cast<Force>(rootBody->physicalActions->find(b->getId(),cachedForceClassIndex))->force+=acceleration*myMass*toAxis;
+			//if(b->getId()==20){ TRVAR3(toAxis,acceleration*myMass*toAxis,static_pointer_cast<Force>(rootBody->physicalActions->find(b->getId(),cachedForceClassIndex))->force); }
+		#endif
 	}
 }

Modified: trunk/pkg/common/Engine/DeusExMachina/MomentEngine.cpp
===================================================================
--- trunk/pkg/common/Engine/DeusExMachina/MomentEngine.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/DeusExMachina/MomentEngine.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -40,7 +40,11 @@
 	{
 		if(ncb->bodies->exists( *ii ))
 		{
-			static_cast<Momentum*>( ncb->physicalActions->find( *ii        , actionParameterMoment->getClassIndex() ).get() )->momentum += moment;
+			#ifdef BEX_CONTAINER
+				ncb->bex.addTorque(*ii,moment);
+			#else
+				static_cast<Momentum*>( ncb->physicalActions->find( *ii        , actionParameterMoment->getClassIndex() ).get() )->momentum += moment;
+			#endif
 		} else {
 			std::cerr << "MomentEngine: body " << *ii << "doesn't exist, cannot apply moment.";
 		}

Modified: trunk/pkg/common/Engine/EngineUnit/CundallNonViscousDamping.cpp
===================================================================
--- trunk/pkg/common/Engine/EngineUnit/CundallNonViscousDamping.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/EngineUnit/CundallNonViscousDamping.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -8,6 +8,30 @@
 
 YADE_PLUGIN("CundallNonViscousForceDamping","CundallNonViscousMomentumDamping");
 
+#ifdef BEX_CONTAINER
+//! damping of force, for bodies that have only ParticleParameters
+void CundallNonViscousForceDamping::go(const shared_ptr<PhysicalParameters>& pp, const Body* body, MetaBody* rb){
+	if(body->isClump()) return;
+	Vector3r f=getForceUnsynced(body->getId(),rb);
+	ParticleParameters *p=static_cast<ParticleParameters*>(pp.get());
+	Vector3r df=Vector3r::ZERO;
+	for(int i=0; i<3; i++){df[i]=-f[i]*damping*Mathr::Sign(f[i]*p->velocity[i]);}
+	rb->bex.addForce(body->getId(),df);
+}
+//! damping of both force and torque, for bodies that have RigidBodyParameters
+void CundallNonViscousMomentumDamping::go(const shared_ptr<PhysicalParameters>& pp, const Body* body, MetaBody* rb){
+	if(body->isClump()) return;
+	body_id_t id=body->getId();
+	Vector3r f=getForceUnsynced(id,rb),t=getTorqueUnsynced(id,rb);
+	RigidBodyParameters *p=static_cast<RigidBodyParameters*>(pp.get());
+	Vector3r df=Vector3r::ZERO, dt=Vector3r::ZERO;
+	for(int i=0; i<3; i++){
+		df[i]=-f[i]*damping*Mathr::Sign(f[i]*p->velocity[i]);
+		dt[i]=-t[i]*damping*Mathr::Sign(t[i]*p->angularVelocity[i]);
+	}
+	rb->bex.addForce(id,df); rb->bex.addTorque(id,dt);
+}
+#else
 // this is Cundall non-viscous local damping, applied to force (Force)
 void CundallNonViscousForceDamping::go(    const shared_ptr<PhysicalAction>& a
 						, const shared_ptr<PhysicalParameters>& b
@@ -38,8 +62,8 @@
 		m[i] *= 1 - damping*Mathr::Sign(m[i]*rb->angularVelocity[i]);	
 	}
 }
+#endif
 
 
 
 
-

Modified: trunk/pkg/common/Engine/EngineUnit/CundallNonViscousDamping.hpp
===================================================================
--- trunk/pkg/common/Engine/EngineUnit/CundallNonViscousDamping.hpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/EngineUnit/CundallNonViscousDamping.hpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -6,16 +6,16 @@
 	public:
 		Real damping;
 		CundallNonViscousForceDamping(): damping(0){};
+		virtual void registerAttributes(){PhysicalActionDamperUnit::registerAttributes();REGISTER_ATTRIBUTE(damping);}
+	#ifdef BEX_CONTAINER
+		virtual void go(const shared_ptr<PhysicalParameters>&, const Body*, MetaBody*);
+		FUNCTOR1D(ParticleParameters);
+	#else
 		virtual void go(const shared_ptr<PhysicalAction>&, const shared_ptr<PhysicalParameters>& , const Body*);
-	protected:
-		virtual void registerAttributes(){
-			PhysicalActionDamperUnit::registerAttributes();
-			REGISTER_ATTRIBUTE(damping);
-		}
-	NEEDS_BEX("Force");
-	FUNCTOR2D(Force,ParticleParameters);
-	REGISTER_CLASS_NAME(CundallNonViscousForceDamping);
-	REGISTER_BASE_CLASS_NAME(PhysicalActionDamperUnit);
+		NEEDS_BEX("Force");
+		FUNCTOR2D(Force,ParticleParameters);
+	#endif
+	REGISTER_CLASS_AND_BASE(CundallNonViscousForceDamping,PhysicalActionDamperUnit);
 };
 REGISTER_SERIALIZABLE(CundallNonViscousForceDamping);
 
@@ -23,16 +23,16 @@
 	public:
 		Real damping;
 		CundallNonViscousMomentumDamping(): damping(0){};
+		virtual void registerAttributes(){PhysicalActionDamperUnit::registerAttributes();REGISTER_ATTRIBUTE(damping); }
+	#ifdef BEX_CONTAINER
+		virtual void go(const shared_ptr<PhysicalParameters>&, const Body*, MetaBody*);
+		FUNCTOR1D(RigidBodyParameters);
+	#else
 		virtual void go(const shared_ptr<PhysicalAction>&, const shared_ptr<PhysicalParameters>&, const Body*);
-	protected:
-		 virtual void registerAttributes(){
-			PhysicalActionDamperUnit::registerAttributes();
-			REGISTER_ATTRIBUTE(damping);
-		 }
-	NEEDS_BEX("Momentum");
-	FUNCTOR2D(Momentum,RigidBodyParameters);
-	REGISTER_CLASS_NAME(CundallNonViscousMomentumDamping);
-	REGISTER_BASE_CLASS_NAME(PhysicalActionDamperUnit);
+		NEEDS_BEX("Momentum");
+		FUNCTOR2D(Momentum,RigidBodyParameters);
+	#endif
+	REGISTER_CLASS_AND_BASE(CundallNonViscousMomentumDamping,PhysicalActionDamperUnit);
 };
 REGISTER_SERIALIZABLE(CundallNonViscousMomentumDamping);
 

Modified: trunk/pkg/common/Engine/EngineUnit/NewtonsForceLaw.cpp
===================================================================
--- trunk/pkg/common/Engine/EngineUnit/NewtonsForceLaw.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/EngineUnit/NewtonsForceLaw.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -8,43 +8,36 @@
 *  GNU General Public License v2 or later. See file LICENSE for details. *
 *************************************************************************/
 
-#include "NewtonsForceLaw.hpp"
+#include"NewtonsForceLaw.hpp"
 #include<yade/pkg-common/ParticleParameters.hpp>
 #include<yade/pkg-common/RigidBodyParameters.hpp>
 #include<yade/pkg-common/Force.hpp>
+#include<yade/core/MetaBody.hpp>
 
-
+#ifdef BEX_CONTAINER
+void NewtonsForceLaw::go(const shared_ptr<PhysicalParameters>& b, const Body* bb, MetaBody* rb){
+	Vector3r f=rb->bex.getForce(bb->getId());
+#else
 void NewtonsForceLaw::go( const shared_ptr<PhysicalAction>& a
 			, const shared_ptr<PhysicalParameters>& b
 			, const Body* bb)
 {
-	Force * af = YADE_CAST<Force*>(a.get());
+	const Vector3r& f = YADE_CAST<Force*>(a.get())->force;
+#endif
 	ParticleParameters * p = YADE_CAST<ParticleParameters*>(b.get());
 	
-	//FIXME : should be += and we should add an Engine that reset acceleration at the beginning
-	// if another PhysicalAction also acts on acceleration then we are overwritting it here
-	//
-	// currently this is not the case, because there is only one
-	// PhysicalAction that influences acceleration: Force
-	// 
-	// If another PhysicalAction will be added, that works on acceleration,
-	// then above will have to be fixed. And example of such action is: Acceleration
-	//
-	
-
-	// TODO: remove debugging stuff from the following
 	// normal behavior of a standalone particle or a clump itself
-	if (bb->isStandalone()) p->acceleration=af->force/p->mass;
+	if (bb->isStandalone()) p->acceleration=f/p->mass;
 	else if (bb->isClump()) {
 		// accel for clump reset in Clump::moveMembers, called by ClumpMemberMover engine
-		p->acceleration+=af->force/p->mass;
+		p->acceleration+=f/p->mass;
 	}
 	else{ // force applied to a clump member is applied to clump itself
 		const shared_ptr<Body>& clump(Body::byId(bb->clumpId));
 		RigidBodyParameters* clumpRBP=YADE_CAST<RigidBodyParameters*>(clump->physicalParameters.get());
 		// accels reset by Clump::moveMembers in last iteration
-		clumpRBP->acceleration+=af->force/clumpRBP->mass;
-		clumpRBP->angularAcceleration+=diagDiv((b->se3.position-clumpRBP->se3.position).Cross(af->force),clumpRBP->inertia); //acceleration from torque generated by the force WRT particle centroid on the clump centroid
+		clumpRBP->acceleration+=f/clumpRBP->mass;
+		clumpRBP->angularAcceleration+=diagDiv((b->se3.position-clumpRBP->se3.position).Cross(f),clumpRBP->inertia); //acceleration from torque generated by the force WRT particle centroid on the clump centroid
 	}
 }
 

Modified: trunk/pkg/common/Engine/EngineUnit/NewtonsForceLaw.hpp
===================================================================
--- trunk/pkg/common/Engine/EngineUnit/NewtonsForceLaw.hpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/EngineUnit/NewtonsForceLaw.hpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -10,18 +10,28 @@
 
 #include<yade/pkg-common/PhysicalActionApplierUnit.hpp>
 
-class NewtonsForceLaw : public PhysicalActionApplierUnit
-{
-	public :
-		virtual void go( 	  const shared_ptr<PhysicalAction>&
-					, const shared_ptr<PhysicalParameters>&
-					, const Body*);
-	NEEDS_BEX("Force");
-	FUNCTOR2D(Force,ParticleParameters);
-	REGISTER_CLASS_NAME(NewtonsForceLaw);
-	REGISTER_BASE_CLASS_NAME(PhysicalActionApplierUnit);
-};
+#ifdef BEX_CONTAINER
+	class NewtonsForceLaw: public PhysicalActionApplierUnit{
+		public:
+			virtual void go(const shared_ptr<PhysicalParameters>&, const Body*, MetaBody*);
+			FUNCTOR1D(ParticleParameters);
+			REGISTER_CLASS_AND_BASE(NewtonsForceLaw,PhysicalActionApplierUnit);
+	};
 
+#else
+	class NewtonsForceLaw : public PhysicalActionApplierUnit
+	{
+		public :
+			virtual void go( 	  const shared_ptr<PhysicalAction>&
+						, const shared_ptr<PhysicalParameters>&
+						, const Body*);
+		NEEDS_BEX("Force");
+		FUNCTOR2D(Force,ParticleParameters);
+		REGISTER_CLASS_NAME(NewtonsForceLaw);
+		REGISTER_BASE_CLASS_NAME(PhysicalActionApplierUnit);
+	};
+#endif
+
 REGISTER_SERIALIZABLE(NewtonsForceLaw);
 
 

Modified: trunk/pkg/common/Engine/EngineUnit/NewtonsMomentumLaw.cpp
===================================================================
--- trunk/pkg/common/Engine/EngineUnit/NewtonsMomentumLaw.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/EngineUnit/NewtonsMomentumLaw.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -12,8 +12,27 @@
 #include<yade/pkg-common/RigidBodyParameters.hpp>
 #include<yade/pkg-common/Momentum.hpp>
 #include<yade/lib-base/yadeWm3Extra.hpp>
+#include<yade/core/MetaBody.hpp>
 
-
+#ifdef BEX_CONTAINER
+//! Newtons law for both force and momentum
+void NewtonsMomentumLaw::go(const shared_ptr<PhysicalParameters>& b, const Body* bb, MetaBody* rb){
+	body_id_t id=bb->getId();
+	Vector3r f=rb->bex.getForce(id); Vector3r m=rb->bex.getTorque(id);
+	RigidBodyParameters *rbp = static_cast<RigidBodyParameters*>(b.get());
+	if(bb->isStandalone()){ rbp->acceleration=f/rbp->mass; rbp->angularAcceleration=diagDiv(m,rbp->inertia); }
+	else if(bb->isClump()){ rbp->acceleration+=f/rbp->mass; rbp->angularAcceleration+=diagDiv(m,rbp->inertia); }
+	else { // isClumpMember()
+		const shared_ptr<Body>& clump(Body::byId(bb->clumpId));
+		RigidBodyParameters* clumpRBP=YADE_CAST<RigidBodyParameters*>(clump->physicalParameters.get());
+		// accels reset by Clump::moveMembers in last iteration
+		clumpRBP->acceleration+=f/clumpRBP->mass;
+		clumpRBP->angularAcceleration+=diagDiv((b->se3.position-clumpRBP->se3.position).Cross(f),clumpRBP->inertia); //acceleration from torque generated by the force WRT particle centroid on the clump centroid
+		/* angularAcceleration is reset by ClumpMemberMover engine */
+		clumpRBP->angularAcceleration+=diagDiv(m,clumpRBP->inertia);
+	}
+}
+#else
 void NewtonsMomentumLaw::go( 	  const shared_ptr<PhysicalAction>& a
 				, const shared_ptr<PhysicalParameters>& b
 				, const Body* bb)
@@ -31,6 +50,6 @@
 		clumpRBP->angularAcceleration+=diagDiv(am->momentum,clumpRBP->inertia);
 	}
 }
+#endif
 
-
 YADE_PLUGIN();

Modified: trunk/pkg/common/Engine/EngineUnit/NewtonsMomentumLaw.hpp
===================================================================
--- trunk/pkg/common/Engine/EngineUnit/NewtonsMomentumLaw.hpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/EngineUnit/NewtonsMomentumLaw.hpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -9,7 +9,14 @@
 #pragma once
 
 #include<yade/pkg-common/PhysicalActionApplierUnit.hpp>
-
+#ifdef BEX_CONTAINER
+	class NewtonsMomentumLaw: public PhysicalActionApplierUnit{
+		public:
+			virtual void go(const shared_ptr<PhysicalParameters>&, const Body*, MetaBody*);
+			FUNCTOR1D(RigidBodyParameters);
+			REGISTER_CLASS_AND_BASE(NewtonsMomentumLaw,PhysicalActionApplierUnit);
+	};
+#else
 class NewtonsMomentumLaw : public PhysicalActionApplierUnit
 {
 	public :
@@ -22,7 +29,7 @@
 	REGISTER_CLASS_NAME(NewtonsMomentumLaw);
 	REGISTER_BASE_CLASS_NAME(PhysicalActionApplierUnit);
 };
-
+#endif
 REGISTER_SERIALIZABLE(NewtonsMomentumLaw);
 
 

Modified: trunk/pkg/common/Engine/MetaEngine/ConstitutiveLaw.hpp
===================================================================
--- trunk/pkg/common/Engine/MetaEngine/ConstitutiveLaw.hpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/MetaEngine/ConstitutiveLaw.hpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -9,12 +9,16 @@
 class ConstitutiveLaw: public EngineUnit2D <
 		void, TYPELIST_4(shared_ptr<InteractionGeometry>&, shared_ptr<InteractionPhysics>&, Interaction*, MetaBody*)
 	>{
+	#ifndef BEX_CONTAINER
 		int forceIdx, torqueIdx;
+	#endif
 	public:
 		ConstitutiveLaw(){
 			// cache force/torque indices for fast access in bodyForce and bodyTorque
-			forceIdx=shared_ptr<PhysicalAction>(new Force())->getClassIndex();
-			torqueIdx=shared_ptr<PhysicalAction>(new Momentum())->getClassIndex();
+			#ifndef BEX_CONTAINER
+				forceIdx=shared_ptr<PhysicalAction>(new Force())->getClassIndex();
+				torqueIdx=shared_ptr<PhysicalAction>(new Momentum())->getClassIndex();
+			#endif
 		}
 	REGISTER_CLASS_AND_BASE(ConstitutiveLaw,EngineUnit2D);
 	/*! Convenience functions to get forces/torques quickly.

Modified: trunk/pkg/common/Engine/MetaEngine/PhysicalActionApplier.cpp
===================================================================
--- trunk/pkg/common/Engine/MetaEngine/PhysicalActionApplier.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/MetaEngine/PhysicalActionApplier.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -6,23 +6,31 @@
 *  GNU General Public License v2 or later. See file LICENSE for details. *
 *************************************************************************/
 
-#include "PhysicalActionApplier.hpp"
+#include"PhysicalActionApplier.hpp"
 #include<yade/core/MetaBody.hpp>
 
+#ifdef BEX_CONTAINER
+void PhysicalActionApplier::action(MetaBody* ncb){
+	FOREACH(const shared_ptr<Body>& b, *ncb->bodies){
+		operator()(b->physicalParameters,b.get(),ncb);
+	}
+}
+#else
 void PhysicalActionApplier::action(MetaBody* ncb)
 {
-	shared_ptr<BodyContainer>& bodies = ncb->bodies;
+		throw logic_error("PhysicalActionApplier cannot be used with BexContainer. Use NewtonsDampedLaw instead (or recompile with NO_BEX).");
+		shared_ptr<BodyContainer>& bodies = ncb->bodies;
 
-	PhysicalActionContainer::iterator pai    = ncb->physicalActions->begin();
-	PhysicalActionContainer::iterator paiEnd = ncb->physicalActions->end(); 
-	for( ; pai!=paiEnd ; ++pai)
-	{
-		shared_ptr<PhysicalAction> action = *pai;
-		int id = pai.getCurrentIndex();
-		// FIXME - solve the problem of Body's id
-		operator()( action , (*bodies)[id]->physicalParameters , (*bodies)[id].get() );
-	}
+		PhysicalActionContainer::iterator pai    = ncb->physicalActions->begin();
+		PhysicalActionContainer::iterator paiEnd = ncb->physicalActions->end(); 
+		for( ; pai!=paiEnd ; ++pai)
+		{
+			shared_ptr<PhysicalAction> action = *pai;
+			int id = pai.getCurrentIndex();
+			operator()( action , (*bodies)[id]->physicalParameters , (*bodies)[id].get() );
+		}
 }
+#endif
 
 
 YADE_PLUGIN();

Modified: trunk/pkg/common/Engine/MetaEngine/PhysicalActionApplier.hpp
===================================================================
--- trunk/pkg/common/Engine/MetaEngine/PhysicalActionApplier.hpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/MetaEngine/PhysicalActionApplier.hpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -12,13 +12,20 @@
 
 
 #include<yade/core/MetaEngine2D.hpp>
+#include<yade/core/MetaEngine1D.hpp>
 #include<yade/lib-multimethods/DynLibDispatcher.hpp>
 #include<yade/core/PhysicalAction.hpp>
 
 #include<yade/pkg-common/PhysicalActionApplierUnit.hpp>
 
 class Body;
-
+#ifdef BEX_CONTAINER
+class PhysicalActionApplier: public MetaEngine1D<PhysicalParameters,PhysicalActionApplierUnit,void,TYPELIST_3(const shared_ptr<PhysicalParameters>&,const Body*, MetaBody*)>{
+	public: virtual void action(MetaBody*);
+	REGISTER_CLASS_AND_BASE(PhysicalActionApplier,MetaEngine1D);
+};
+REGISTER_SERIALIZABLE(PhysicalActionApplier);
+#else
 class PhysicalActionApplier :	public MetaEngine2D
 				<
 					PhysicalAction ,					// base classe for dispatch
@@ -37,7 +44,6 @@
 	REGISTER_CLASS_NAME(PhysicalActionApplier);
 	REGISTER_BASE_CLASS_NAME(MetaEngine2D);
 };
-
 REGISTER_SERIALIZABLE(PhysicalActionApplier);
+#endif
 
-

Modified: trunk/pkg/common/Engine/MetaEngine/PhysicalActionApplierUnit.hpp
===================================================================
--- trunk/pkg/common/Engine/MetaEngine/PhysicalActionApplierUnit.hpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/MetaEngine/PhysicalActionApplierUnit.hpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -12,7 +12,14 @@
 #include<yade/core/PhysicalParameters.hpp>
 #include<yade/core/Body.hpp>
 #include<yade/core/EngineUnit2D.hpp>
+#include<yade/core/EngineUnit1D.hpp>
 
+#ifdef BEX_CONTAINER
+class PhysicalActionApplierUnit: public EngineUnit1D<void,TYPELIST_3(const shared_ptr<PhysicalParameters>&,const Body*, MetaBody*)>{
+	REGISTER_CLASS_AND_BASE(PhysicalActionApplierUnit,EngineUnit1D);
+};
+REGISTER_SERIALIZABLE(PhysicalActionApplierUnit);
+#else
 class PhysicalActionApplierUnit :	public EngineUnit2D
 					<
 		 				void ,
@@ -25,7 +32,6 @@
 	REGISTER_CLASS_NAME(PhysicalActionApplierUnit);
 	REGISTER_BASE_CLASS_NAME(EngineUnit2D);
 };
-
 REGISTER_SERIALIZABLE(PhysicalActionApplierUnit);
+#endif
 
-

Modified: trunk/pkg/common/Engine/MetaEngine/PhysicalActionDamper.cpp
===================================================================
--- trunk/pkg/common/Engine/MetaEngine/PhysicalActionDamper.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/MetaEngine/PhysicalActionDamper.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -11,28 +11,27 @@
 #include "PhysicalActionDamper.hpp"
 #include<yade/core/MetaBody.hpp>
 
+#ifdef BEX_CONTAINER
+void PhysicalActionDamper::action(MetaBody* ncb){
+	FOREACH(const shared_ptr<Body>& b, *ncb->bodies){
+		operator()(b->physicalParameters,b.get(),ncb);
+	}
+}
+#else
 void PhysicalActionDamper::action(MetaBody* ncb)
 {
-	shared_ptr<BodyContainer>& bodies = ncb->bodies;
-	PhysicalActionContainer::iterator pai    = ncb->physicalActions->begin();
-	PhysicalActionContainer::iterator paiEnd = ncb->physicalActions->end();
-	for( ; pai!=paiEnd ; ++pai)
-	{
-		shared_ptr<PhysicalAction> action = *pai;
-		int id = pai.getCurrentIndex();
-		// FIXME - solve the problem of Body's id
-		operator()( action , (*bodies)[id]->physicalParameters , (*bodies)[id].get() );
-	}
-
-
-//	for( ncb->physicalActions->gotoFirst() ; ncb->physicalActions->notAtEnd() ; ncb->physicalActions->gotoNext())
-//	{
-//		shared_ptr<PhysicalAction>& action = ncb->physicalActions->getCurrent(id);
-//		// FIXME - solve the problem of Body's id
-//		operator()( action , (*bodies)[id]->physicalParameters , (*bodies)[id].get() );
-//	}
-
+		shared_ptr<BodyContainer>& bodies = ncb->bodies;
+		PhysicalActionContainer::iterator pai    = ncb->physicalActions->begin();
+		PhysicalActionContainer::iterator paiEnd = ncb->physicalActions->end();
+		for( ; pai!=paiEnd ; ++pai)
+		{
+			shared_ptr<PhysicalAction> action = *pai;
+			int id = pai.getCurrentIndex();
+			// FIXME - solve the problem of Body's id
+			operator()( action , (*bodies)[id]->physicalParameters , (*bodies)[id].get() );
+		}
 }
+#endif
 
 
 YADE_PLUGIN();

Modified: trunk/pkg/common/Engine/MetaEngine/PhysicalActionDamper.hpp
===================================================================
--- trunk/pkg/common/Engine/MetaEngine/PhysicalActionDamper.hpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/MetaEngine/PhysicalActionDamper.hpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -9,30 +9,38 @@
 #pragma once
 
 #include<yade/core/MetaEngine2D.hpp>
+#include<yade/core/MetaEngine1D.hpp>
 #include<yade/lib-multimethods/DynLibDispatcher.hpp>
 #include<yade/core/PhysicalAction.hpp>
 #include<yade/pkg-common/PhysicalActionDamperUnit.hpp>
 
 class Body;
+class MetaBody;
+#ifdef BEX_CONTAINER
+	class PhysicalActionDamper: public MetaEngine1D<PhysicalParameters,PhysicalActionDamperUnit,void,TYPELIST_3(const shared_ptr<PhysicalParameters>&, const Body*, MetaBody*)>{
+		public: virtual void action(MetaBody*);
+		REGISTER_CLASS_AND_BASE(PhysicalActionDamper,MetaEngine1D);
+	};
+	REGISTER_SERIALIZABLE(PhysicalActionDamper);
+#else
+	class PhysicalActionDamper : public MetaEngine2D
+					<	PhysicalAction,						// base classe for dispatch
+						PhysicalParameters,					// base classe for dispatch
+						PhysicalActionDamperUnit,				// class that provides multivirtual call
+						void,							// return type
+						TYPELIST_3(	  const shared_ptr<PhysicalAction>&	// function arguments
+								, const shared_ptr<PhysicalParameters>& 
+								, const Body *
+							  )
+					>
+	{
+		public :
+			virtual void action(MetaBody*);
 
-class PhysicalActionDamper : public MetaEngine2D
-				<	PhysicalAction,						// base classe for dispatch
-					PhysicalParameters,					// base classe for dispatch
-					PhysicalActionDamperUnit,				// class that provides multivirtual call
-					void,							// return type
-					TYPELIST_3(	  const shared_ptr<PhysicalAction>&	// function arguments
-							, const shared_ptr<PhysicalParameters>& 
-							, const Body *
-						  )
-				>
-{
-	public :
-		virtual void action(MetaBody*);
+		REGISTER_CLASS_NAME(PhysicalActionDamper);
+		REGISTER_BASE_CLASS_NAME(MetaEngine2D);
+	};
+	REGISTER_SERIALIZABLE(PhysicalActionDamper);
+#endif
 
-	REGISTER_CLASS_NAME(PhysicalActionDamper);
-	REGISTER_BASE_CLASS_NAME(MetaEngine2D);
-};
 
-REGISTER_SERIALIZABLE(PhysicalActionDamper);
-
-

Modified: trunk/pkg/common/Engine/MetaEngine/PhysicalActionDamperUnit.hpp
===================================================================
--- trunk/pkg/common/Engine/MetaEngine/PhysicalActionDamperUnit.hpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/MetaEngine/PhysicalActionDamperUnit.hpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -11,8 +11,19 @@
 #include<yade/core/PhysicalAction.hpp>
 #include<yade/core/PhysicalParameters.hpp>
 #include<yade/core/Body.hpp>
+#include<yade/core/MetaBody.hpp>
 #include<yade/core/EngineUnit2D.hpp>
+#include<yade/core/EngineUnit1D.hpp>
 
+#ifdef BEX_CONTAINER
+class PhysicalActionDamperUnit: public EngineUnit1D<void,TYPELIST_3(const shared_ptr<PhysicalParameters>&,const Body*, MetaBody*)>{
+	REGISTER_CLASS_AND_BASE(PhysicalActionDamperUnit,EngineUnit1D);
+	/* We are friend of BexContainer. These functions can be used safely provided that bex is NEVER read after being modified. */
+	Vector3r getForceUnsynced (body_id_t id, MetaBody* rb){ return rb->bex.getForceUnsynced (id);}
+	Vector3r getTorqueUnsynced(body_id_t id, MetaBody* rb){ return rb->bex.getTorqueUnsynced(id);}
+};
+REGISTER_SERIALIZABLE(PhysicalActionDamperUnit);
+#else
 class PhysicalActionDamperUnit : public EngineUnit2D
 				 <
 		 			void ,
@@ -25,6 +36,5 @@
 	REGISTER_CLASS_NAME(PhysicalActionDamperUnit);
 	REGISTER_BASE_CLASS_NAME(EngineUnit2D);
 };
-
 REGISTER_SERIALIZABLE(PhysicalActionDamperUnit);
-
+#endif

Modified: trunk/pkg/common/Engine/StandAloneEngine/PhysicalActionContainerInitializer.cpp
===================================================================
--- trunk/pkg/common/Engine/StandAloneEngine/PhysicalActionContainerInitializer.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/common/Engine/StandAloneEngine/PhysicalActionContainerInitializer.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -32,33 +32,32 @@
 void PhysicalActionContainerInitializer::action(MetaBody* ncb)
 {
 	#ifdef BEX_CONTAINER
-		// this is not necessary, since BexContainer grows upon requests.
+		// this is not necessary, since BexContainer grows upon request.
 		// But it takes about 10 resizes to get to 2000 bodies (only at the beginning), so you can save a few milliseconds here
 		ncb->bex.resize(ncb->bodies->size());
-		return;
-	#endif
-	list<string> allNames;
-	// copy physical action names that were passed by the user directly
-	allNames.insert(allNames.end(),physicalActionNames.begin(),physicalActionNames.end());
-	LOG_DEBUG("allNames as defined by the user: ");	FOREACH(string an,allNames) LOG_DEBUG(an);
-	// loop over all engines, get Bex from them
-	FOREACH(shared_ptr<Engine> e, ncb->engines){
-		list<string> bex=e->getNeededBex();
-		allNames.insert(allNames.end(),bex.begin(),bex.end());
-		LOG_DEBUG("The following engines were inserted by "<<e->getClassName()<<":"); FOREACH(string b,bex) LOG_DEBUG(b);
-	}
-	LOG_DEBUG("allNames after loop over engines: ");	FOREACH(string an,allNames) LOG_DEBUG(an);
-	// eliminate all duplicates
-	allNames.sort();
-	allNames.unique();
-	LOG_DEBUG("allNames after sort and unique: ");	FOREACH(string an,allNames) LOG_DEBUG(an);
+	#else
+		list<string> allNames;
+		// copy physical action names that were passed by the user directly
+		allNames.insert(allNames.end(),physicalActionNames.begin(),physicalActionNames.end());
+		LOG_DEBUG("allNames as defined by the user: ");	FOREACH(string an,allNames) LOG_DEBUG(an);
+		// loop over all engines, get Bex from them
+		FOREACH(shared_ptr<Engine> e, ncb->engines){
+			list<string> bex=e->getNeededBex();
+			allNames.insert(allNames.end(),bex.begin(),bex.end());
+			LOG_DEBUG("The following engines were inserted by "<<e->getClassName()<<":"); FOREACH(string b,bex) LOG_DEBUG(b);
+		}
+		LOG_DEBUG("allNames after loop over engines: ");	FOREACH(string an,allNames) LOG_DEBUG(an);
+		// eliminate all duplicates
+		allNames.sort();
+		allNames.unique();
+		LOG_DEBUG("allNames after sort and unique: ");	FOREACH(string an,allNames) LOG_DEBUG(an);
 
-	vector<shared_ptr<PhysicalAction> > physicalActions;
-	FOREACH(string physicalActionName, allNames){
-		physicalActions.push_back(YADE_PTR_CAST<PhysicalAction>(ClassFactory::instance().createShared(physicalActionName)));
-	}
-	ncb->physicalActions->prepare(physicalActions);
-	
+		vector<shared_ptr<PhysicalAction> > physicalActions;
+		FOREACH(string physicalActionName, allNames){
+			physicalActions.push_back(YADE_PTR_CAST<PhysicalAction>(ClassFactory::instance().createShared(physicalActionName)));
+		}
+		ncb->physicalActions->prepare(physicalActions);
+	#endif
 }
 
 

Modified: trunk/pkg/dem/Engine/DeusExMachina/CapillaryRecorder.cpp
===================================================================
--- trunk/pkg/dem/Engine/DeusExMachina/CapillaryRecorder.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/Engine/DeusExMachina/CapillaryRecorder.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -53,9 +53,13 @@
 {
 	Real fx=0, fy=0, fz=0;
 	
+	#ifdef BEX_CONTAINER
+		ncb->bex.sync();
+		Vector3r force=ncb->bex.getForce(bigBallId);
+	#else
+		Vector3r force = static_cast<Force*>(ncb->physicalActions->find(bigBallId, actionForce->getClassIndex() ) . get() )->force;
+	#endif
 	
-	Vector3r force = static_cast<Force*>(ncb->physicalActions->find(
-bigBallId, actionForce->getClassIndex() ) . get() )->force;
 		
 		fx=force[0];
 		fy=force[1];

Modified: trunk/pkg/dem/Engine/DeusExMachina/HydraulicForceEngine.cpp
===================================================================
--- trunk/pkg/dem/Engine/DeusExMachina/HydraulicForceEngine.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/Engine/DeusExMachina/HydraulicForceEngine.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -73,7 +73,11 @@
                     //cerr << "translate it" << endl;
                     if ((static_cast<CohesiveFrictionalBodyParameters*> (b->physicalParameters.get()))->isBroken == true)
                     {
-                        static_cast<Force*>( ncb->physicalActions->find( b->getId() , actionParameterForce->getClassIndex() ).get() )->force += Vector3r(0,5,0);
+                        #ifdef BEX_CONTAINER
+									ncb->bex.addForce(b->getId(),Vector3r(0,5,0));
+								#else
+									static_cast<Force*>( ncb->physicalActions->find( b->getId() , actionParameterForce->getClassIndex() ).get() )->force += Vector3r(0,5,0);
+								#endif
                     }
                     // else  b->geometricalModel->diffuseColor= Vector3r(0.5,0.9,0.3);
                 }
@@ -99,9 +103,14 @@
                     Vector3r t (mx,my,mz);
                     //f /= -10000;
                     //t *= 0;
-                    static_cast<Force*>( ncb->physicalActions->find( id , actionParameterForce->getClassIndex() ).get() )->force += f;
-                    //cerr << "added force = " << f << endl;
-                    static_cast<Momentum*>( ncb->physicalActions->find( id , actionParameterMomentum->getClassIndex() ).get() )->momentum += t;
+						  #ifdef BEX_CONTAINER
+						  		ncb->bex.addForce(id,f);
+								ncb->bex.addTorque(id,t);
+						  #else
+	                    static_cast<Force*>( ncb->physicalActions->find( id , actionParameterForce->getClassIndex() ).get() )->force += f;
+	                    //cerr << "added force = " << f << endl;
+	                    static_cast<Momentum*>( ncb->physicalActions->find( id , actionParameterMomentum->getClassIndex() ).get() )->momentum += t;
+						  #endif
 
                 }
             }

Modified: trunk/pkg/dem/Engine/DeusExMachina/MakeItFlat.cpp
===================================================================
--- trunk/pkg/dem/Engine/DeusExMachina/MakeItFlat.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/Engine/DeusExMachina/MakeItFlat.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -56,7 +56,11 @@
 			{
 				p->se3.position[direction]=plane_position;
 				if(reset_force)
-					static_cast<Force*>( ncb->physicalActions->find( b->getId() , actionParameterForce->getClassIndex() ).get() )->force[direction]=0;// 
+					#ifdef BEX_CONTAINER
+						throw runtime_error("BexContainer doesn't work with MakeIfFlat resetting forces, since it would have to sync() frequently. Use PhysicalParameters::blockedDOFs instead, MakeItFlat will be removed.");
+					#else
+						static_cast<Force*>( ncb->physicalActions->find( b->getId() , actionParameterForce->getClassIndex() ).get() )->force[direction]=0;// 
+					#endif
 			}
 		}
 	}

Modified: trunk/pkg/dem/Engine/DeusExMachina/ResultantForceEngine.cpp
===================================================================
--- trunk/pkg/dem/Engine/DeusExMachina/ResultantForceEngine.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/Engine/DeusExMachina/ResultantForceEngine.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -7,91 +7,94 @@
 *  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. *
 *************************************************************************/
+#include"ResultantForceEngine.hpp"
 
+#ifndef BEX_CONTAINER
 
-#include"ResultantForceEngine.hpp"
-#include<yade/pkg-common/ParticleParameters.hpp>
-#include<yade/pkg-common/Force.hpp>
-#include<yade/pkg-dem/GlobalStiffness.hpp>
-#include<Wm3Math.h>
-#include<yade/lib-base/yadeWm3.hpp>
-#include<yade/lib-base/yadeWm3Extra.hpp>
+	#include<yade/pkg-common/ParticleParameters.hpp>
+	#include<yade/pkg-common/Force.hpp>
+	#include<yade/pkg-dem/GlobalStiffness.hpp>
+	#include<Wm3Math.h>
+	#include<yade/lib-base/yadeWm3.hpp>
+	#include<yade/lib-base/yadeWm3Extra.hpp>
 
 
 
-#include<yade/core/MetaBody.hpp>
+	#include<yade/core/MetaBody.hpp>
 
 
-ResultantForceEngine::ResultantForceEngine() : actionParameterGlobalStiffness(new GlobalStiffness), actionParameterForce(new Force)
-{
-	interval =1;
-	damping = 0.1;
-	force = Vector3r::ZERO;
-	previoustranslation = Vector3r::ZERO;
-	stiffness = Vector3r::ZERO;
-	max_vel = 0.001;
-}
+	ResultantForceEngine::ResultantForceEngine() : actionParameterGlobalStiffness(new GlobalStiffness), actionParameterForce(new Force)
+	{
+		interval =1;
+		damping = 0.1;
+		force = Vector3r::ZERO;
+		previoustranslation = Vector3r::ZERO;
+		stiffness = Vector3r::ZERO;
+		max_vel = 0.001;
+	}
 
-ResultantForceEngine::~ResultantForceEngine()
-{
-}
+	ResultantForceEngine::~ResultantForceEngine()
+	{
+	}
 
 
-void ResultantForceEngine::registerAttributes()
-{
-	DeusExMachina::registerAttributes();
-	REGISTER_ATTRIBUTE(interval);
-	REGISTER_ATTRIBUTE(damping);
-	REGISTER_ATTRIBUTE(force);
-	REGISTER_ATTRIBUTE(previoustranslation);
-	REGISTER_ATTRIBUTE(stiffness);
-	REGISTER_ATTRIBUTE(max_vel);
-}
+	void ResultantForceEngine::registerAttributes()
+	{
+		DeusExMachina::registerAttributes();
+		REGISTER_ATTRIBUTE(interval);
+		REGISTER_ATTRIBUTE(damping);
+		REGISTER_ATTRIBUTE(force);
+		REGISTER_ATTRIBUTE(previoustranslation);
+		REGISTER_ATTRIBUTE(stiffness);
+		REGISTER_ATTRIBUTE(max_vel);
+	}
 
 
 
-void ResultantForceEngine::applyCondition(MetaBody* ncb)
-{
-	//cerr << "void ResultantForceEngine::applyCondition(Body* body)" << std::endl;
-	shared_ptr<BodyContainer>& bodies = ncb->bodies;
-	
-	std::vector<int>::const_iterator ii = subscribedBodies.begin();
-	std::vector<int>::const_iterator iiEnd = subscribedBodies.end();
-	
-	//cerr << "std::vector<int>::const_iterator iiEnd = subscribedBodies.end();" << Omega::instance().getCurrentIteration() << std::endl;
-	
-	
-	
-	for(;ii!=iiEnd;++ii)
+	void ResultantForceEngine::applyCondition(MetaBody* ncb)
 	{
-	//cerr << "for(;ii!=iiEnd;++ii)" << std::endl;
-	//if( bodies->exists(*ii) ) 
-	//{
-		//Update stiffness only if it has been computed by StiffnessCounter (see "interval")
-		if (Omega::instance().getCurrentIteration() % interval == 0)	stiffness =
-		(static_cast<GlobalStiffness*>( ncb->physicalActions->find (*ii, actionParameterGlobalStiffness->getClassIndex() ).get() ))->stiffness;
-	
-		//cerr << "static_cast<GlobalStiffness*>( ncb->physicalActions->find (*ii, actionParameterGlobalStiffness->getClassIndex() ).get() ))->stiffness" << std::endl;
+		//cerr << "void ResultantForceEngine::applyCondition(Body* body)" << std::endl;
+		shared_ptr<BodyContainer>& bodies = ncb->bodies;
 		
-		if(PhysicalParameters* p = dynamic_cast<PhysicalParameters*>((*bodies)[*ii]->physicalParameters.get()))
+		std::vector<int>::const_iterator ii = subscribedBodies.begin();
+		std::vector<int>::const_iterator iiEnd = subscribedBodies.end();
+		
+		//cerr << "std::vector<int>::const_iterator iiEnd = subscribedBodies.end();" << Omega::instance().getCurrentIteration() << std::endl;
+		
+		
+		
+		for(;ii!=iiEnd;++ii)
 		{
-			//cerr << "dynamic_cast<PhysicalParameters*>((*bodies)[*ii]->physicalParameters.get()" << std::endl;
-//			GlobalStiffness* sm = static_cast<GlobalStiffness*>( ncb->physicalActions->find (*ii, actionParameterGlobalStiffness->getClassIndex() ).get() );
+		//cerr << "for(;ii!=iiEnd;++ii)" << std::endl;
+		//if( bodies->exists(*ii) ) 
+		//{
+			//Update stiffness only if it has been computed by StiffnessCounter (see "interval")
+			if (Omega::instance().getCurrentIteration() % interval == 0)	stiffness =
+			(static_cast<GlobalStiffness*>( ncb->physicalActions->find (*ii, actionParameterGlobalStiffness->getClassIndex() ).get() ))->stiffness;
+		
+			//cerr << "static_cast<GlobalStiffness*>( ncb->physicalActions->find (*ii, actionParameterGlobalStiffness->getClassIndex() ).get() ))->stiffness" << std::endl;
 			
-			Vector3r effectiveforce =
-			 	static_cast<Force*>( ncb->physicalActions->find( *ii,actionParameterForce->getClassIndex() ).get() )->force; 
-			Vector3r deltaf (effectiveforce - force);
-			Vector3r translation 
-				(stiffness.X()==0 ? Mathr::Sign(deltaf.X())*max_vel : Mathr::Sign(deltaf.X())*std::min( abs(deltaf.X()/stiffness.X()), max_vel),
-				stiffness.Y()==0 ? Mathr::Sign(deltaf.Y())*max_vel : Mathr::Sign(deltaf.Y())*std::min( abs(deltaf.Y()/stiffness.Y()), max_vel),
-				stiffness.Z()==0 ? Mathr::Sign(deltaf.Z())*max_vel : Mathr::Sign(deltaf.Z())*std::min( abs(deltaf.Z()/stiffness.Z()), max_vel) );
-			previoustranslation = (1-damping)*translation + 0.9*previoustranslation;// formula for "steady-flow" evolution with fluctuations
-			p->se3.position	+= previoustranslation;
-			//p->velocity		=  previoustranslation/dt;//FIXME : useless???	
-		}		
-	//}
+			if(PhysicalParameters* p = dynamic_cast<PhysicalParameters*>((*bodies)[*ii]->physicalParameters.get()))
+			{
+				//cerr << "dynamic_cast<PhysicalParameters*>((*bodies)[*ii]->physicalParameters.get()" << std::endl;
+	//			GlobalStiffness* sm = static_cast<GlobalStiffness*>( ncb->physicalActions->find (*ii, actionParameterGlobalStiffness->getClassIndex() ).get() );
+				
+				Vector3r effectiveforce =
+					static_cast<Force*>( ncb->physicalActions->find( *ii,actionParameterForce->getClassIndex() ).get() )->force; 
+				Vector3r deltaf (effectiveforce - force);
+				Vector3r translation 
+					(stiffness.X()==0 ? Mathr::Sign(deltaf.X())*max_vel : Mathr::Sign(deltaf.X())*std::min( abs(deltaf.X()/stiffness.X()), max_vel),
+					stiffness.Y()==0 ? Mathr::Sign(deltaf.Y())*max_vel : Mathr::Sign(deltaf.Y())*std::min( abs(deltaf.Y()/stiffness.Y()), max_vel),
+					stiffness.Z()==0 ? Mathr::Sign(deltaf.Z())*max_vel : Mathr::Sign(deltaf.Z())*std::min( abs(deltaf.Z()/stiffness.Z()), max_vel) );
+				previoustranslation = (1-damping)*translation + 0.9*previoustranslation;// formula for "steady-flow" evolution with fluctuations
+				p->se3.position	+= previoustranslation;
+				//p->velocity		=  previoustranslation/dt;//FIXME : useless???	
+			}		
+		//}
+		}
 	}
-}
 
 
-YADE_PLUGIN();
+	YADE_PLUGIN();
+
+#endif

Modified: trunk/pkg/dem/Engine/DeusExMachina/ResultantForceEngine.hpp
===================================================================
--- trunk/pkg/dem/Engine/DeusExMachina/ResultantForceEngine.hpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/Engine/DeusExMachina/ResultantForceEngine.hpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -9,49 +9,45 @@
 *************************************************************************/
 
 #pragma once
-
 #include<yade/core/DeusExMachina.hpp>
-#include <Wm3Math.h>
-#include<yade/lib-base/yadeWm3.hpp>
-#include <Wm3Vector3.h>
-#include<yade/lib-base/yadeWm3.hpp>
+#ifndef BEX_CONTAINER
 
-class PhysicalAction;
+	class PhysicalAction;
 
-class ResultantForceEngine : public DeusExMachina 
-{
-	private :
-		shared_ptr<PhysicalAction> actionParameterGlobalStiffness;
-		shared_ptr<PhysicalAction> actionParameterForce;
-		
+	class ResultantForceEngine : public DeusExMachina 
+	{
+		private :
+			shared_ptr<PhysicalAction> actionParameterGlobalStiffness;
+			shared_ptr<PhysicalAction> actionParameterForce;
 			
-	public :
-		//! CAUTION : interval must be equal to the interval of the StiffnessCounter, it is used here to check if stiffness has been computed 
-		unsigned int interval;
-		//! Defines the prescibed resultant force 
-		Vector3r		force;	
-		//! Stores the value of the translation at the previous time step
-		Vector3r 		previoustranslation;
-		//! The value of stiffness (updated according to interval) 
-		Vector3r		stiffness;
-		//! damping coefficient - damping=1 implies a "perfect" control of the resultant force
-		Real			damping;
-		//! maximum velocity (usefull to prevent explosions when stiffness is very low...) 
-		Real			max_vel;
+				
+		public :
+			//! CAUTION : interval must be equal to the interval of the StiffnessCounter, it is used here to check if stiffness has been computed 
+			unsigned int interval;
+			//! Defines the prescibed resultant force 
+			Vector3r		force;	
+			//! Stores the value of the translation at the previous time step
+			Vector3r 		previoustranslation;
+			//! The value of stiffness (updated according to interval) 
+			Vector3r		stiffness;
+			//! damping coefficient - damping=1 implies a "perfect" control of the resultant force
+			Real			damping;
+			//! maximum velocity (usefull to prevent explosions when stiffness is very low...) 
+			Real			max_vel;
 
-		ResultantForceEngine();
-		virtual ~ResultantForceEngine();
-	
-		virtual void applyCondition(MetaBody*);
+			ResultantForceEngine();
+			virtual ~ResultantForceEngine();
 		
-	
-	protected :
-		virtual void registerAttributes();
-	NEEDS_BEX("Force","GlobalStiffness");
-	REGISTER_CLASS_NAME(ResultantForceEngine);
-	REGISTER_BASE_CLASS_NAME(DeusExMachina);
-};
+			virtual void applyCondition(MetaBody*);
+			
+		
+		protected :
+			virtual void registerAttributes();
+		NEEDS_BEX("Force","GlobalStiffness");
+		REGISTER_CLASS_NAME(ResultantForceEngine);
+		REGISTER_BASE_CLASS_NAME(DeusExMachina);
+	};
 
-REGISTER_SERIALIZABLE(ResultantForceEngine);
+	REGISTER_SERIALIZABLE(ResultantForceEngine);
+#endif
 
-

Modified: trunk/pkg/dem/Engine/DeusExMachina/TriaxialStressController.cpp
===================================================================
--- trunk/pkg/dem/Engine/DeusExMachina/TriaxialStressController.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/Engine/DeusExMachina/TriaxialStressController.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -329,25 +329,7 @@
 	force[wall_front]= getForce(ncb,wall_id[wall_front]);  stress[wall_front]= force[wall_front] *invZSurface;
 	force[wall_back]=  getForce(ncb,wall_id[wall_back]);   stress[wall_back]=  force[wall_back]  *invZSurface;
 
-// remove this, it is in the 6 lines above now
-#if 0	
-	stress[wall_bottom] = ( static_cast<Force*>( ncb->physicalActions->find(wall_id[wall_bottom],ForceClassIndex).get() )->force ) * invYSurface;
-	stress[wall_top] = static_cast<Force*>( ncb->physicalActions->find(wall_id[wall_top],ForceClassIndex).get() )->force * invYSurface;
-	stress[wall_left] = ( static_cast<Force*>( ncb->physicalActions->find(wall_id[wall_left],ForceClassIndex).get() )->force ) * invXSurface;
-	stress[wall_right] = ( static_cast<Force*>( ncb->physicalActions->find(wall_id[wall_right],ForceClassIndex).get() )->force ) * invXSurface;
-	stress[wall_front] = ( static_cast<Force*>( ncb->physicalActions->find(wall_id[wall_front],ForceClassIndex).get() )->force ) * invZSurface;
-	stress[wall_back] = ( static_cast<Force*>( ncb->physicalActions->find(wall_id[wall_back],ForceClassIndex).get() )->force ) * invZSurface;	
 
-// ==================================================== jf
-	force[wall_bottom] = ( static_cast<Force*>( ncb->physicalActions->find(wall_id[wall_bottom],ForceClassIndex).get() )->force );
-	force[wall_top] = static_cast<Force*>( ncb->physicalActions->find(wall_id[wall_top],ForceClassIndex).get() )->force ;
-	force[wall_left] = ( static_cast<Force*>( ncb->physicalActions->find(wall_id[wall_left],ForceClassIndex).get() )->force ) ;
-	force[wall_right] = ( static_cast<Force*>( ncb->physicalActions->find(wall_id[wall_right],ForceClassIndex).get() )->force ) ;
-	force[wall_front] = ( static_cast<Force*>( ncb->physicalActions->find(wall_id[wall_front],ForceClassIndex).get() )->force ) ;
-	force[wall_back] = ( static_cast<Force*>( ncb->physicalActions->find(wall_id[wall_back],ForceClassIndex).get() )->force ) ;	
-// ====================================================
-#endif
-
  	//cerr << "stresses : " <<  stress[wall_bottom] << " " <<
  //stress[wall_top]<< " " << stress[wall_left]<< " " << stress[wall_right]<< " "
  //<< stress[wall_front] << " " << stress[wall_back] << endl;

Modified: trunk/pkg/dem/Engine/DeusExMachina/WallStressRecorder.cpp
===================================================================
--- trunk/pkg/dem/Engine/DeusExMachina/WallStressRecorder.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/Engine/DeusExMachina/WallStressRecorder.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -91,17 +91,19 @@
 	/// calcul des contraintes via forces resultantes sur murs
 	
 	Real SIG_wall_11 = 0, SIG_wall_22 = 0, SIG_wall_33 = 0;
+	#ifdef BEX_CONTAINER
+		ncb->bex.sync();
+		Vector3r F_wall_11=ncb->bex.getForce(wall_left_id);
+		Vector3r F_wall_22=ncb->bex.getForce(wall_top_id);
+		Vector3r F_wall_33=ncb->bex.getForce(wall_front_id);
+	#else
+		Vector3r F_wall_11 = static_cast<Force*>( ncb->physicalActions->find(wall_left_id, actionForce->getClassIndex() ). get() )->force;
+		Vector3r F_wall_22 = static_cast<Force*>( ncb->physicalActions->find(wall_top_id, actionForce->getClassIndex() ). get() )->force;
+		Vector3r F_wall_33 = static_cast<Force*>( ncb->physicalActions->find(wall_front_id, actionForce->getClassIndex() ). get() )->force;
+	#endif
 	
-	Vector3r F_wall_11 = static_cast<Force*>( ncb->physicalActions->find(wall_left_id, actionForce->getClassIndex() ). get() )->force;
-	
 	SIG_wall_11 = F_wall_11[0]/(depth*height);
-	
-	Vector3r F_wall_22 = static_cast<Force*>( ncb->physicalActions->find(wall_top_id, actionForce->getClassIndex() ). get() )->force;
-	
 	SIG_wall_22 = F_wall_22[1]/(depth*width);
-	
-	Vector3r F_wall_33 = static_cast<Force*>( ncb->physicalActions->find(wall_front_id, actionForce->getClassIndex() ). get() )->force;
-	
 	SIG_wall_33 = F_wall_33[2]/(width*height);
 	
 	ofile << lexical_cast<string>(Omega::instance().getSimulationTime()) << " " 

Modified: trunk/pkg/dem/Engine/StandAloneEngine/CapillaryCohesiveLaw.cpp
===================================================================
--- trunk/pkg/dem/Engine/StandAloneEngine/CapillaryCohesiveLaw.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/Engine/StandAloneEngine/CapillaryCohesiveLaw.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -291,8 +291,13 @@
 					else if (currentContactPhysics->fusionNumber !=0)
 						currentContactPhysics->Fcap /= (currentContactPhysics->fusionNumber+1);
                                 }
-                                static_cast<Force*>   (ncb->physicalActions->find( (*ii)->getId1() , actionForce  ->getClassIndex()).get())->force    += currentContactPhysics->Fcap;
-                                static_cast<Force*>   (ncb->physicalActions->find( (*ii)->getId2() , actionForce  ->getClassIndex()).get())->force    -= currentContactPhysics->Fcap;
+											#ifdef BEX_CONTAINER
+												ncb->bex.addForce((*ii)->getId1(), currentContactPhysics->Fcap);
+												ncb->bex.addForce((*ii)->getId2(),-currentContactPhysics->Fcap);
+											#else
+	                                static_cast<Force*>   (ncb->physicalActions->find( (*ii)->getId1() , actionForce  ->getClassIndex()).get())->force    += currentContactPhysics->Fcap;
+	                                static_cast<Force*>   (ncb->physicalActions->find( (*ii)->getId2() , actionForce  ->getClassIndex()).get())->force    -= currentContactPhysics->Fcap;
+											#endif
 
 				//cerr << "id1/id2 " << (*ii)->getId1() << "/" << (*ii)->getId2() << " Fcap= " << currentContactPhysics->Fcap << endl;
 

Modified: trunk/pkg/dem/Engine/StandAloneEngine/CohesiveFrictionalContactLaw.cpp
===================================================================
--- trunk/pkg/dem/Engine/StandAloneEngine/CohesiveFrictionalContactLaw.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/Engine/StandAloneEngine/CohesiveFrictionalContactLaw.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -255,11 +255,17 @@
                 //  cerr << "shearForce " << shearForce << endl;
                 // cerr << "f= " << f << endl;
                 // it will be some macro(	body->physicalActions,	ActionType , bodyId )
+					#ifdef BEX_CONTAINER
+						ncb->bex.addForce (id1, f);
+						ncb->bex.addForce (id2,-f);
+						ncb->bex.addTorque(id1, c1x.Cross(f));
+						ncb->bex.addTorque(id2,-c2x.Cross(f));
+					#else
                 static_cast<Force*>   ( ncb->physicalActions->find( id1 , actionForce   ->getClassIndex() ).get() )->force    -= f;
                 static_cast<Force*>   ( ncb->physicalActions->find( id2 , actionForce   ->getClassIndex() ).get() )->force    += f;
-
                 static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentum->getClassIndex() ).get() )->momentum -= c1x.Cross(f);
                 static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentum->getClassIndex() ).get() )->momentum += c2x.Cross(f);
+					#endif
 
 /////	/// Moment law					 	 ///
 /////		if(momentRotationLaw /*&& currentContactPhysics->cohesionBroken == false*/ )
@@ -358,9 +364,13 @@
 	Vector3r moment = moment_twist + moment_bending;
 currentContactPhysics->moment_twist = moment_twist;
 currentContactPhysics->moment_bending = moment_bending;
-
-			static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentum->getClassIndex() ).get() )->momentum -= moment;
-			static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentum->getClassIndex() ).get() )->momentum += moment;
+			#ifdef BEX_CONTAINER
+				ncb->bex.addTorque(id1,-moment);
+				ncb->bex.addTorque(id2, moment);
+			#else
+				static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentum->getClassIndex() ).get() )->momentum -= moment;
+				static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentum->getClassIndex() ).get() )->momentum += moment;
+			#endif
 		}
 	/// Moment law	END				 	 ///
 

Modified: trunk/pkg/dem/Engine/StandAloneEngine/ContactLaw1.cpp
===================================================================
--- trunk/pkg/dem/Engine/StandAloneEngine/ContactLaw1.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/Engine/StandAloneEngine/ContactLaw1.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -214,12 +214,18 @@
                 //  cerr << "shearForce " << shearForce << endl;
                 // cerr << "f= " << f << endl;
                 // it will be some macro(	body->physicalActions,	ActionType , bodyId )
-                static_cast<Force*>   ( ncb->physicalActions->find( id1 , actionForce   ->getClassIndex() ).get() )->force    -= f;
-                static_cast<Force*>   ( ncb->physicalActions->find( id2 , actionForce   ->getClassIndex() ).get() )->force    += f;
+					#ifdef BEX_CONTAINER
+						ncb->bex.addForce (id1,-f);
+						ncb->bex.addForce (id2,+f);
+						ncb->bex.addTorque(id1,-c1x.Cross(f));
+						ncb->bex.addTorque(id2, c2x.Cross(f));
+					#else
+	               static_cast<Force*>   ( ncb->physicalActions->find( id1 , actionForce   ->getClassIndex() ).get() )->force    -= f;
+   	            static_cast<Force*>   ( ncb->physicalActions->find( id2 , actionForce   ->getClassIndex() ).get() )->force    += f;
+      	         static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentum->getClassIndex() ).get() )->momentum -= c1x.Cross(f);
+         	      static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentum->getClassIndex() ).get() )->momentum += c2x.Cross(f);
+					#endif
 
-                static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentum->getClassIndex() ).get() )->momentum -= c1x.Cross(f);
-                static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentum->getClassIndex() ).get() )->momentum += c2x.Cross(f);
-
 /////	/// Moment law					 	 ///
 /////		if(momentRotationLaw /*&& currentContactPhysics->cohesionBroken == false*/ )
 /////		{	
@@ -307,9 +313,13 @@
 					nbreInteracMomPlastif++;
 					}
 			}
-
-			static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentum->getClassIndex() ).get() )->momentum -= moment;
-			static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentum->getClassIndex() ).get() )->momentum += moment;
+			#ifdef BEX_CONTAINER
+				ncb->bex.addTorque(id1,-moment);
+				ncb->bex.addTorque(id2,+moment);
+			#else
+				static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentum->getClassIndex() ).get() )->momentum -= moment;
+				static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentum->getClassIndex() ).get() )->momentum += moment;
+			#endif
 		}
 	/// Moment law	END				 	 ///
 

Modified: trunk/pkg/dem/Engine/StandAloneEngine/ElasticCohesiveLaw.cpp
===================================================================
--- trunk/pkg/dem/Engine/StandAloneEngine/ElasticCohesiveLaw.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/Engine/StandAloneEngine/ElasticCohesiveLaw.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -113,15 +113,20 @@
 			currentContactPhysics->shearForce      -= currentContactPhysics->ks*shearDisplacement;
 	
 			Vector3r f = currentContactPhysics->normalForce + currentContactPhysics->shearForce;
+			#ifdef BEX_CONTAINER
+				ncb->bex.addForce (id1,-f);
+				ncb->bex.addForce (id2,+f);
+				ncb->bex.addTorque(id1,-c1x.Cross(f));
+				ncb->bex.addTorque(id2, c2x.Cross(f));
+			#else
+				static_cast<Force*>   ( ncb->physicalActions->find( id1 , actionForce   ->getClassIndex() ).get() )->force    -= f;
+				static_cast<Force*>   ( ncb->physicalActions->find( id2 , actionForce   ->getClassIndex() ).get() )->force    += f;
+				static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentum->getClassIndex() ).get() )->momentum -= c1x.Cross(f);
+				static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentum->getClassIndex() ).get() )->momentum += c2x.Cross(f);
+			#endif
 	
-			static_cast<Force*>   ( ncb->physicalActions->find( id1 , actionForce   ->getClassIndex() ).get() )->force    -= f;
-			static_cast<Force*>   ( ncb->physicalActions->find( id2 , actionForce   ->getClassIndex() ).get() )->force    += f;
-			
-			static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentum->getClassIndex() ).get() )->momentum -= c1x.Cross(f);
-			static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentum->getClassIndex() ).get() )->momentum += c2x.Cross(f);
 	
 	
-	
 	/// Moment law					 	 ///
 		if(momentRotationLaw)
 		{
@@ -214,8 +219,13 @@
 	
 			//if (normElastic<=normMPlastic)
 			//{
-			static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentum->getClassIndex() ).get() )->momentum -= q_n_i*mElastic;
-			static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentum->getClassIndex() ).get() )->momentum += q_n_i*mElastic;
+			#ifdef BEX_CONTAINER
+				ncb->bex.addTorque(id1,-q_n_i*mElastic);
+				ncb->bex.addTorque(id2, q_n_i*mElastic);
+			#else
+				static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentum->getClassIndex() ).get() )->momentum -= q_n_i*mElastic;
+				static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentum->getClassIndex() ).get() )->momentum += q_n_i*mElastic;
+			#endif
 	
 			//}  
 			//else

Modified: trunk/pkg/dem/Engine/StandAloneEngine/ForceRecorder.cpp
===================================================================
--- trunk/pkg/dem/Engine/StandAloneEngine/ForceRecorder.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/Engine/StandAloneEngine/ForceRecorder.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -69,6 +69,9 @@
 void ForceRecorder::action(MetaBody * ncb)
 {
 	if (first) init();
+	#ifdef BEX_CONTAINER
+		ncb->bex.sync();
+	#endif
 
 	Real x=0, y=0, z=0;
 	
@@ -76,7 +79,11 @@
 	{
 		if(ncb->bodies->exists(i))
 		{
-			Vector3r force = YADE_CAST<Force*>(ncb->physicalActions->find( i , actionForce->getClassIndex() ) . get() )->force;
+			#ifdef BEX_CONTAINER
+				Vector3r force=ncb->bex.getForce(i);
+			#else
+				Vector3r force = YADE_CAST<Force*>(ncb->physicalActions->find( i , actionForce->getClassIndex() ) . get() )->force;
+			#endif
 		
 			x+=force[0];
 			y+=force[1];

Modified: trunk/pkg/dem/Engine/StandAloneEngine/GeometricalModelForceColorizer.cpp
===================================================================
--- trunk/pkg/dem/Engine/StandAloneEngine/GeometricalModelForceColorizer.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/Engine/StandAloneEngine/GeometricalModelForceColorizer.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -31,6 +31,9 @@
 void GeometricalModelForceColorizer::action(MetaBody * ncb)
 {
 	// FIXME the same in GLDrawLatticeBeamState.cpp
+	#ifdef BEX_CONTAINER
+		ncb->bex.sync();
+	#endif
 
 	BodyContainer* bodies = ncb->bodies.get();
 	
@@ -44,7 +47,11 @@
 		if(body->isDynamic)
 		{
 			unsigned int i = body -> getId();
-			Vector3r force = YADE_CAST<Force*>(ncb->physicalActions->find( i , actionForce->getClassIndex() ) . get() )->force;
+			#ifdef BEX_CONTAINER
+				Vector3r force=ncb->bex.getForce(i);
+			#else
+				Vector3r force = YADE_CAST<Force*>(ncb->physicalActions->find( i , actionForce->getClassIndex() ) . get() )->force;
+			#endif
 			min = std::min( force[0] , std::min( force[1] , std::min( force[2], min ) ) );
 			max = std::max( force[0] , std::max( force[1] , std::max( force[2], max ) ) );
 		}
@@ -60,7 +67,11 @@
 		{
 			GeometricalModel* gm = body->geometricalModel.get();
 			unsigned int i = body -> getId();
-			Vector3r force = YADE_CAST<Force*>(ncb->physicalActions->find( i , actionForce->getClassIndex() ) . get() )->force;
+			#ifdef BEX_CONTAINER
+				Vector3r force=ncb->bex.getForce(i);
+			#else
+				Vector3r force = YADE_CAST<Force*>(ncb->physicalActions->find( i , actionForce->getClassIndex() ) . get() )->force;
+			#endif
 
 			gm->diffuseColor[0] = (force[2]-min)/(max-min);
 			gm->diffuseColor[1] = (force[2]-min)/(max-min);

Modified: trunk/pkg/dem/Engine/StandAloneEngine/GlobalStiffnessCounter.cpp
===================================================================
--- trunk/pkg/dem/Engine/StandAloneEngine/GlobalStiffnessCounter.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/Engine/StandAloneEngine/GlobalStiffnessCounter.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -56,49 +56,50 @@
 void GlobalStiffnessCounter::traverseInteractions(MetaBody* ncb, const shared_ptr<InteractionContainer>& interactions){
 	#ifdef BEX_CONTAINER
 		return;
-	#endif
-	FOREACH(const shared_ptr<Interaction>& contact, *interactions){
-		if(!contact->isReal) continue;
+	#else
+		FOREACH(const shared_ptr<Interaction>& contact, *interactions){
+			if(!contact->isReal) continue;
 
-		SpheresContactGeometry* geom=YADE_CAST<SpheresContactGeometry*>(contact->interactionGeometry.get()); assert(geom);
-		NormalShearInteraction* phys=YADE_CAST<NormalShearInteraction*>(contact->interactionPhysics.get()); assert(phys);
-		// all we need for getting stiffness
-		Vector3r& normal=geom->normal; Real& kn=phys->kn; Real& ks=phys->ks; Real& radius1=geom->radius1; Real& radius2=geom->radius2;
-		// FIXME? NormalShearInteraction knows nothing about whether the contact is "active" (force!=0) or not;
-		// former code: if(force==0) continue; /* disregard this interaction, it is not active */.
-		// It seems though that in such case either the interaction is accidentally at perfect equilibrium (unlikely)
-		// or it should have been deleted already. Right? 
-		//ANSWER : some interactions can exist without fn, e.g. distant capillary force, wich does not contribute to the overall stiffness via kn. The test is needed.
-		Real fn = (static_cast<ElasticContactInteraction *> (contact->interactionPhysics.get()))->normalForce.SquaredLength();
+			SpheresContactGeometry* geom=YADE_CAST<SpheresContactGeometry*>(contact->interactionGeometry.get()); assert(geom);
+			NormalShearInteraction* phys=YADE_CAST<NormalShearInteraction*>(contact->interactionPhysics.get()); assert(phys);
+			// all we need for getting stiffness
+			Vector3r& normal=geom->normal; Real& kn=phys->kn; Real& ks=phys->ks; Real& radius1=geom->radius1; Real& radius2=geom->radius2;
+			// FIXME? NormalShearInteraction knows nothing about whether the contact is "active" (force!=0) or not;
+			// former code: if(force==0) continue; /* disregard this interaction, it is not active */.
+			// It seems though that in such case either the interaction is accidentally at perfect equilibrium (unlikely)
+			// or it should have been deleted already. Right? 
+			//ANSWER : some interactions can exist without fn, e.g. distant capillary force, wich does not contribute to the overall stiffness via kn. The test is needed.
+			Real fn = (static_cast<ElasticContactInteraction *> (contact->interactionPhysics.get()))->normalForce.SquaredLength();
 
-		if (fn!=0) {
+			if (fn!=0) {
 
-		//Diagonal terms of the translational stiffness matrix
-		Vector3r diag_stiffness = Vector3r(std::pow(normal.X(),2),std::pow(normal.Y(),2),std::pow(normal.Z(),2));
-		diag_stiffness *= kn-ks;
-		diag_stiffness = diag_stiffness + Vector3r(1,1,1)*ks;
+			//Diagonal terms of the translational stiffness matrix
+			Vector3r diag_stiffness = Vector3r(std::pow(normal.X(),2),std::pow(normal.Y(),2),std::pow(normal.Z(),2));
+			diag_stiffness *= kn-ks;
+			diag_stiffness = diag_stiffness + Vector3r(1,1,1)*ks;
 
-		//diagonal terms of the rotational stiffness matrix
-		// Vector3r branch1 = currentContactGeometry->normal*currentContactGeometry->radius1;
-		// Vector3r branch2 = currentContactGeometry->normal*currentContactGeometry->radius2;
-		Vector3r diag_Rstiffness =
-			Vector3r(std::pow(normal.Y(),2)+std::pow(normal.Z(),2),
-				std::pow(normal.X(),2)+std::pow(normal.Z(),2),
-				std::pow(normal.X(),2)+std::pow(normal.Y(),2));
-		diag_Rstiffness *= ks;
-		//cerr << "diag_Rstifness=" << diag_Rstiffness << endl;
+			//diagonal terms of the rotational stiffness matrix
+			// Vector3r branch1 = currentContactGeometry->normal*currentContactGeometry->radius1;
+			// Vector3r branch2 = currentContactGeometry->normal*currentContactGeometry->radius2;
+			Vector3r diag_Rstiffness =
+				Vector3r(std::pow(normal.Y(),2)+std::pow(normal.Z(),2),
+					std::pow(normal.X(),2)+std::pow(normal.Z(),2),
+					std::pow(normal.X(),2)+std::pow(normal.Y(),2));
+			diag_Rstiffness *= ks;
+			//cerr << "diag_Rstifness=" << diag_Rstiffness << endl;
 
-		PhysicalAction* st = ncb->physicalActions->find(contact->getId1(),actionStiffnessIndex).get();
-		GlobalStiffness* s = static_cast<GlobalStiffness*>(st);
-		s->stiffness += diag_stiffness;
-		s->Rstiffness += diag_Rstiffness*pow(radius1,2);	
-		st = ncb->physicalActions->find(contact->getId2(),actionStiffnessIndex).get();
-		s = static_cast<GlobalStiffness*>(st);
-		s->stiffness += diag_stiffness;
-		s->Rstiffness += diag_Rstiffness*pow(radius2,2);
-		
+			PhysicalAction* st = ncb->physicalActions->find(contact->getId1(),actionStiffnessIndex).get();
+			GlobalStiffness* s = static_cast<GlobalStiffness*>(st);
+			s->stiffness += diag_stiffness;
+			s->Rstiffness += diag_Rstiffness*pow(radius1,2);	
+			st = ncb->physicalActions->find(contact->getId2(),actionStiffnessIndex).get();
+			s = static_cast<GlobalStiffness*>(st);
+			s->stiffness += diag_stiffness;
+			s->Rstiffness += diag_Rstiffness*pow(radius2,2);
+			
+			}
 		}
-	}
+	#endif
 }
 
 void GlobalStiffnessCounter::action(MetaBody* ncb)

Modified: trunk/pkg/dem/Engine/StandAloneEngine/MyTetrahedronLaw.cpp
===================================================================
--- trunk/pkg/dem/Engine/StandAloneEngine/MyTetrahedronLaw.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/Engine/StandAloneEngine/MyTetrahedronLaw.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -73,13 +73,18 @@
 						Vector3r x			= currentContactGeometry->contactPoints[i][j];
 						Vector3r c1x			= (x - de1->se3.position);
 						Vector3r c2x			= (x - de2->se3.position);
+						#ifdef BEX_CONTAINER
+							ncb->bex.addForce (id1,-force);
+							ncb->bex.addForce (id2,+force);
+							ncb->bex.addTorque(id1,-c1x.Cross(force));
+							ncb->bex.addTorque(id2, c2x.Cross(force));
+						#else
+							static_cast<Force*>   ( ncb->physicalActions->find( id1 , actionForce   ->getClassIndex() ).get() )->force    -= force;
+							static_cast<Force*>   ( ncb->physicalActions->find( id2 , actionForce   ->getClassIndex() ).get() )->force    += force;
+							static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentum->getClassIndex() ).get() )->momentum -= c1x.Cross(force);
+							static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentum->getClassIndex() ).get() )->momentum += c2x.Cross(force);
+						#endif
 
-						// it will be some macro(	body->physicalActions,	ActionType , bodyId )
-						static_cast<Force*>   ( ncb->physicalActions->find( id1 , actionForce   ->getClassIndex() ).get() )->force    -= force;
-						static_cast<Force*>   ( ncb->physicalActions->find( id2 , actionForce   ->getClassIndex() ).get() )->force    += force;
-
-						static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentum->getClassIndex() ).get() )->momentum -= c1x.Cross(force);
-						static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentum->getClassIndex() ).get() )->momentum += c2x.Cross(force);
 					}
 				}
 

Modified: trunk/pkg/dem/Engine/StandAloneEngine/ViscousForceDamping.cpp
===================================================================
--- trunk/pkg/dem/Engine/StandAloneEngine/ViscousForceDamping.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/Engine/StandAloneEngine/ViscousForceDamping.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -140,12 +140,17 @@
 			Vector3r viscousDampingForce	= normalDampingForce + shearDampingForce;
 			
 //	Add forces
-			static_cast<Force*>   ( ncb->physicalActions->find( id1 , actionForce   ->getClassIndex() ).get() )->force    -= viscousDampingForce;
-			static_cast<Force*>   ( ncb->physicalActions->find( id2 , actionForce   ->getClassIndex() ).get() )->force    += viscousDampingForce;
-			
-			static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentum->getClassIndex() ).get() )->momentum -= c1x.Cross(viscousDampingForce);
-			static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentum->getClassIndex() ).get() )->momentum += c2x.Cross(viscousDampingForce);
-			
+			#ifdef BEX_CONTAINER
+				ncb->bex.addForce (id1,-viscousDampingForce);
+				ncb->bex.addForce (id2,+viscousDampingForce);
+				ncb->bex.addTorque(id1,-c1x.Cross(viscousDampingForce));
+				ncb->bex.addTorque(id2, c2x.Cross(viscousDampingForce));
+			#else
+				static_cast<Force*>   ( ncb->physicalActions->find( id1 , actionForce   ->getClassIndex() ).get() )->force    -= viscousDampingForce;
+				static_cast<Force*>   ( ncb->physicalActions->find( id2 , actionForce   ->getClassIndex() ).get() )->force    += viscousDampingForce;
+				static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentum->getClassIndex() ).get() )->momentum -= c1x.Cross(viscousDampingForce);
+				static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentum->getClassIndex() ).get() )->momentum += c2x.Cross(viscousDampingForce);
+			#endif
 			currentContactPhysics->prevNormal = currentContactGeometry->normal;
 		}
 	}

Modified: trunk/pkg/dem/Engine/StandAloneEngine/VolumicContactLaw.cpp
===================================================================
--- trunk/pkg/dem/Engine/StandAloneEngine/VolumicContactLaw.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/Engine/StandAloneEngine/VolumicContactLaw.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -479,13 +479,18 @@
 	
 			Vector3r f				= currentContactPhysics->normalForce + shearForce;
 			
-	// it will be some macro(	body->physicalActions,	ActionType , bodyId )
-			static_cast<Force*>   ( ncb->physicalActions->find( id1 , actionForceIndex).get() )->force    -= f;
-			static_cast<Force*>   ( ncb->physicalActions->find( id2 , actionForceIndex ).get() )->force    += f;
+			#ifdef BEX_CONTAINER
+				ncb->bex.addForce (id1,-f);
+				ncb->bex.addForce (id2,+f);
+				ncb->bex.addTorque(id1,-c1x.Cross(f));
+				ncb->bex.addTorque(id2, c2x.Cross(f));
+			#else
+				static_cast<Force*>   ( ncb->physicalActions->find( id1 , actionForceIndex).get() )->force    -= f;
+				static_cast<Force*>   ( ncb->physicalActions->find( id2 , actionForceIndex ).get() )->force    += f;
+				static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentumIndex ).get() )->momentum -= c1x.Cross(f);
+				static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentumIndex ).get() )->momentum += c2x.Cross(f);
+			#endif
 			
-			static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentumIndex ).get() )->momentum -= c1x.Cross(f);
-			static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentumIndex ).get() )->momentum += c2x.Cross(f);
-			
 			currentContactPhysics->prevNormal = currentContactGeometry->normal;
 		}
 	}

Modified: trunk/pkg/dem/PreProcessor/CohesiveTriaxialTest.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/CohesiveTriaxialTest.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/CohesiveTriaxialTest.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -255,7 +255,6 @@
 	createActors(rootBody);
 	positionRootBody(rootBody);
 
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 
 	shared_ptr<Body> body;

Modified: trunk/pkg/dem/PreProcessor/DirectShearCis.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/DirectShearCis.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/DirectShearCis.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -149,7 +149,6 @@
 // Container
 	
 	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 		
 

Modified: trunk/pkg/dem/PreProcessor/Funnel.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/Funnel.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/Funnel.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -108,7 +108,6 @@
 ///////// Container
 	
 	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 		
 ////////////////////////////////////

Modified: trunk/pkg/dem/PreProcessor/HydraulicTest.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/HydraulicTest.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/HydraulicTest.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -98,7 +98,6 @@
 ////////////////////////////////////
 
 	rootBody->transientInteractions  = shared_ptr<InteractionContainer> ( new InteractionVecSet );
-	rootBody->physicalActions  = shared_ptr<PhysicalActionContainer> ( new PhysicalActionVectorVector );
 	rootBody->bodies    = shared_ptr<BodyContainer> ( new BodyRedirectionVector );
 
 /////////////////////////////////////

Modified: trunk/pkg/dem/PreProcessor/MembraneTest.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/MembraneTest.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/MembraneTest.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -115,7 +115,6 @@
 // Containers
 	
 	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 
 // Nodes

Modified: trunk/pkg/dem/PreProcessor/ModifiedTriaxialTest.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/ModifiedTriaxialTest.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/ModifiedTriaxialTest.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -261,7 +261,6 @@
 	createActors(rootBody);
 	positionRootBody(rootBody);
 	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionHashMap);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 
 	shared_ptr<Body> body;
@@ -276,6 +275,7 @@
 	{
 		cerr << "sphere (" << it->first << " " << it->second << endl;
 		createSphere(body,it->first,it->second,false,true);
+		if(want_2d) body->physicalParameters->blockedDOFs=PhysicalParameters::DOF_Z;
 		rootBody->bodies->insert(body);
 	}
 	
@@ -593,8 +593,6 @@
 	gravityCondition->gravity = gravity;
 //	shared_ptr<HydraulicForceEngine> hydraulicForceCondition(new HydraulicForceEngine);
 //	hydraulicForceCondition->hydraulicForce = hydraulicForce;
-  	shared_ptr<MakeItFlat> makeItFlat(new MakeItFlat);
-//	makeItFlatCondition->makeItFlat= makeItFlat;
 
 	shared_ptr<CundallNonViscousForceDamping> actionForceDamping(new CundallNonViscousForceDamping);
 	actionForceDamping->damping = dampingForce;
@@ -687,8 +685,13 @@
 	rootBody->engines.push_back(globalStiffnessTimeStepper);
 	rootBody->engines.push_back(wallStressRecorder);
 	rootBody->engines.push_back(gravityCondition);
-	if(want_2d)
-		rootBody->engines.push_back(makeItFlat);
+	// replaced by PhysicalParameters::blockedDOFs
+	#if 0
+		if(want_2d){
+	  		shared_ptr<MakeItFlat> makeItFlat(new MakeItFlat);
+			rootBody->engines.push_back(makeItFlat);
+		}
+	#endif
 	rootBody->engines.push_back(actionDampingDispatcher);
 	rootBody->engines.push_back(applyActionDispatcher);
 	rootBody->engines.push_back(positionIntegrator);

Modified: trunk/pkg/dem/PreProcessor/SDECImpactTest.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/SDECImpactTest.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/SDECImpactTest.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -194,7 +194,6 @@
 	positionRootBody(rootBody);
 
 	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 
 	shared_ptr<Body> body;

Modified: trunk/pkg/dem/PreProcessor/SDECLinkedSpheres.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/SDECLinkedSpheres.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/SDECLinkedSpheres.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -123,7 +123,6 @@
 	
 //	rootBody->persistentInteractions	= shared_ptr<InteractionContainer>(new InteractionVecSet);
 //	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 
 ////////////////////////////////////

Modified: trunk/pkg/dem/PreProcessor/SDECMovingWall.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/SDECMovingWall.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/SDECMovingWall.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -146,7 +146,6 @@
 ///////// Container
 	
 	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 		
 ////////////////////////////////////

Modified: trunk/pkg/dem/PreProcessor/SDECSpheresPlane.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/SDECSpheresPlane.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/SDECSpheresPlane.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -117,7 +117,6 @@
 ///////// Container
 	
 	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 		
 ////////////////////////////////////

Modified: trunk/pkg/dem/PreProcessor/STLImporterTest.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/STLImporterTest.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/STLImporterTest.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -106,7 +106,6 @@
 ///////// Container
 	
 	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 		
 ////////////////////////////////////

Modified: trunk/pkg/dem/PreProcessor/SimpleShear.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/SimpleShear.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/SimpleShear.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -140,7 +140,6 @@
 // Container
 	
 	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 		
 

Modified: trunk/pkg/dem/PreProcessor/TestSimpleViscoelastic.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/TestSimpleViscoelastic.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/TestSimpleViscoelastic.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -93,7 +93,6 @@
 ///////// Container
 	
     rootBody->transientInteractions	= shared_ptr<InteractionContainer>(new InteractionVecSet);
-    rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
     rootBody->bodies			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 
 ////////////////////////////////////

Modified: trunk/pkg/dem/PreProcessor/TetrahedronsTest.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/TetrahedronsTest.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/TetrahedronsTest.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -132,7 +132,6 @@
 ///////// Container
 	
 	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 		
 ////////////////////////////////////

Modified: trunk/pkg/dem/PreProcessor/ThreePointBending.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/ThreePointBending.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/ThreePointBending.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -128,7 +128,6 @@
 ////////////////////////////////////
 	
 	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 
 	Vector3r min(10000,10000,10000),max(-10000,-10000,-10000);

Modified: trunk/pkg/dem/PreProcessor/TriaxialTest.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/TriaxialTest.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/TriaxialTest.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -253,7 +253,6 @@
 
 	//rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionHashMap);
 
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 
 	createActors(rootBody);
@@ -399,10 +398,16 @@
 	FOREACH(const BasicSphere& it, sphere_list){
 		LOG_DEBUG("sphere (" << it.first << " " << it.second << ")");
 		createSphere(body,it.first,it.second,false,true);
+		if(biaxial2dTest){ body->physicalParameters->blockedDOFs=PhysicalParameters::DOF_Z; }
 		rootBody->bodies->insert(body);
 	}	
 
-	if(defaultDt<0) defaultDt=Shop::PWaveTimeStep();
+	if(defaultDt<0){
+		defaultDt=Shop::PWaveTimeStep(rootBody);
+		rootBody->dt=defaultDt;
+		globalStiffnessTimeStepper->defaultDt=defaultDt;
+		LOG_INFO("Computed default (PWave) timestep "<<defaultDt);
+	}
 
 	return true;
 }
@@ -562,7 +567,7 @@
 	//stiffnessMatrixTimeStepper->sdecGroupMask = 2;
 	//stiffnessMatrixTimeStepper->timeStepUpdateInterval = timeStepUpdateInterval;
 	
-	shared_ptr<GlobalStiffnessTimeStepper> globalStiffnessTimeStepper(new GlobalStiffnessTimeStepper);
+	globalStiffnessTimeStepper=shared_ptr<GlobalStiffnessTimeStepper>(new GlobalStiffnessTimeStepper);
 	globalStiffnessTimeStepper->sdecGroupMask = 2;
 	globalStiffnessTimeStepper->timeStepUpdateInterval = timeStepUpdateInterval;
 	globalStiffnessTimeStepper->defaultDt = defaultDt;
@@ -611,12 +616,8 @@
 		triaxialStateRecorder-> interval 		= recordIntervalIter;
 		//triaxialStateRecorderer-> thickness 		= thickness;
 	}
+	
 
-	shared_ptr<MakeItFlat> makeItFlat(new MakeItFlat);
-	makeItFlat->direction=2;
-	makeItFlat->plane_position = (lowerCorner[2]+upperCorner[2])*0.5;
-	makeItFlat->reset_force = false;	
-
 	#if 0	
 	// moving walls to regulate the stress applied
 	//cerr << "triaxialstressController = shared_ptr<TriaxialStressController> (new TriaxialStressController);" << std::endl;
@@ -652,7 +653,16 @@
 	
 	//if (0) rootBody->engines.push_back(shared_ptr<Engine>(new MicroMacroAnalyser));
 	
-	if(biaxial2dTest) rootBody->engines.push_back(makeItFlat);
+	// replaced by PhysicalParameters::blockedDOFs
+	#if 0
+		if(biaxial2dTest){
+			shared_ptr<MakeItFlat> makeItFlat(new MakeItFlat);
+			makeItFlat->direction=2;
+			makeItFlat->plane_position = (lowerCorner[2]+upperCorner[2])*0.5;
+			makeItFlat->reset_force = false;	
+			rootBody->engines.push_back(makeItFlat);
+		}
+	#endif
 	
 	//if(!rotationBlocked)
 	//	rootBody->engines.push_back(orientationIntegrator);

Modified: trunk/pkg/dem/PreProcessor/TriaxialTest.hpp
===================================================================
--- trunk/pkg/dem/PreProcessor/TriaxialTest.hpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/TriaxialTest.hpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -22,6 +22,7 @@
 class TriaxialStressController;
 class TriaxialCompressionEngine;
 class TriaxialStateRecorder;
+class GlobalStiffnessTimeStepper;
 
 /*! \brief Isotropic compression + triaxial compression test
 
@@ -128,6 +129,7 @@
 		shared_ptr<TriaxialCompressionEngine> triaxialcompressionEngine;
 		shared_ptr<TriaxialStressController> triaxialstressController;
 		shared_ptr<TriaxialStateRecorder> triaxialStateRecorder;
+		shared_ptr<GlobalStiffnessTimeStepper> globalStiffnessTimeStepper;
 			
 		void createBox(shared_ptr<Body>& body, Vector3r position, Vector3r extents,bool wire);
 		void createSphere(shared_ptr<Body>& body, Vector3r position, Real radius,bool big,bool dynamic);

Modified: trunk/pkg/dem/PreProcessor/TriaxialTestWater.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/TriaxialTestWater.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/dem/PreProcessor/TriaxialTestWater.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -276,7 +276,6 @@
 
 	//rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionHashMap);
 
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 
 	shared_ptr<Body> body;

Modified: trunk/pkg/fem/Engine/StandAloneEngine/FEMLaw.cpp
===================================================================
--- trunk/pkg/fem/Engine/StandAloneEngine/FEMLaw.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/fem/Engine/StandAloneEngine/FEMLaw.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -42,7 +42,6 @@
 void FEMLaw::action(MetaBody* fem)
 {
 	shared_ptr<BodyContainer>& bodies = fem->bodies;
-	shared_ptr<PhysicalActionContainer>& physicalActions = fem->physicalActions;
 	
 	ublas::matrix<double> Ue1 , fe;
 	Ue1.resize(12,1);
@@ -76,10 +75,11 @@
 			Vector3r force = Vector3r(	  fe( i*3     , 0 )
 							, fe( i*3 + 1 , 0 )
 							, fe( i*3 + 2 , 0 ));
-			
-			static_cast<Force*>( physicalActions
-				->find( femTet->ids[i] , actionForce ->getClassIndex() ).get() )
-					->force  += force;
+			#ifdef BEX_CONTAINER
+				fem->bex.addForce(femTet->ids[i],force);
+			#else
+				static_cast<Force*>( physicalActions->find( femTet->ids[i] , actionForce ->getClassIndex() ).get() )->force  += force;
+			#endif
 					
 		}
 	}

Modified: trunk/pkg/fem/PreProcessor/FEMBeam.cpp
===================================================================
--- trunk/pkg/fem/PreProcessor/FEMBeam.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/fem/PreProcessor/FEMBeam.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -120,7 +120,6 @@
 	
 	
 	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 	
 	

Modified: trunk/pkg/lattice/PreProcessor/LatticeExample.cpp
===================================================================
--- trunk/pkg/lattice/PreProcessor/LatticeExample.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/lattice/PreProcessor/LatticeExample.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -455,7 +455,6 @@
 	positionRootBody(rootBody);
 	
 	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 
 	

Modified: trunk/pkg/mass-spring/Engine/StandAloneEngine/MassSpringLaw.cpp
===================================================================
--- trunk/pkg/mass-spring/Engine/StandAloneEngine/MassSpringLaw.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/mass-spring/Engine/StandAloneEngine/MassSpringLaw.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -34,7 +34,6 @@
 {
 	shared_ptr<BodyContainer>& bodies = massSpring->bodies;
 	shared_ptr<InteractionContainer>& persistentInteractions = massSpring->persistentInteractions;
-	shared_ptr<PhysicalActionContainer>& physicalActions = massSpring->physicalActions;
 	
 
 	InteractionContainer::iterator ii    = persistentInteractions->begin();
@@ -69,9 +68,13 @@
 			Real e  = (l-l0)/l0;
 			Real relativeVelocity = dir.Dot((p1->velocity-p2->velocity));
 			Vector3r f3 = (e*physics->stiffness + relativeVelocity* ( 1.0 - physics->damping )  )*dir;
-			
-			static_cast<Force*>   ( physicalActions->find( id1 , actionForce->getClassIndex() ).get() )->force    -= f3;
-			static_cast<Force*>   ( physicalActions->find( id2 , actionForce->getClassIndex() ).get() )->force    += f3;
+			#ifdef BEX_CONTAINER
+				massSpring->bex.addForce(id1,-f3);
+				massSpring->bex.addForce(id2, f3);
+			#else
+				static_cast<Force*>   ( physicalActions->find( id1 , actionForce->getClassIndex() ).get() )->force    -= f3;
+				static_cast<Force*>   ( physicalActions->find( id2 , actionForce->getClassIndex() ).get() )->force    += f3;
+			#endif
 		}
 	}
 	

Modified: trunk/pkg/mass-spring/PreProcessor/HangingCloth.cpp
===================================================================
--- trunk/pkg/mass-spring/PreProcessor/HangingCloth.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/mass-spring/PreProcessor/HangingCloth.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -148,7 +148,6 @@
 
 	rootBody->persistentInteractions	= shared_ptr<InteractionContainer>(new InteractionVecSet);
 	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 
 	shared_ptr<PhysicalActionContainerInitializer> physicalActionInitializer(new PhysicalActionContainerInitializer);

Modified: trunk/pkg/realtime-rigidbody/Engine/StandAloneEngine/FrictionLessElasticContactLaw.cpp
===================================================================
--- trunk/pkg/realtime-rigidbody/Engine/StandAloneEngine/FrictionLessElasticContactLaw.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/realtime-rigidbody/Engine/StandAloneEngine/FrictionLessElasticContactLaw.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -77,12 +77,18 @@
 				Vector3r v2 = rb2->velocity+rb2->angularVelocity.Cross(o2p);
 				Real relativeVelocity = dir.Dot(v2-v1);
 				Vector3r f = (elongation*stiffness+relativeVelocity*viscosity)/size*dir;
-	
-				static_cast<Force*>   ( ncb->physicalActions->find( id1 , actionForce   ->getClassIndex() ).get() )->force    += f;
-				static_cast<Force*>   ( ncb->physicalActions->find( id2 , actionForce   ->getClassIndex() ).get() )->force    -= f;
-			
-				static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentum->getClassIndex() ).get() )->momentum += o1p.Cross(f);
-				static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentum->getClassIndex() ).get() )->momentum -= o2p.Cross(f);
+				#ifdef BEX_CONTAINER
+					ncb->bex.addForce (id1, f);
+					ncb->bex.addForce (id2,-f);
+					ncb->bex.addTorque(id1, o1p.Cross(f));
+					ncb->bex.addTorque(id2,-o2p.Cross(f));
+				#else
+					static_cast<Force*>   ( ncb->physicalActions->find( id1 , actionForce   ->getClassIndex() ).get() )->force    += f;
+					static_cast<Force*>   ( ncb->physicalActions->find( id2 , actionForce   ->getClassIndex() ).get() )->force    -= f;
+					static_cast<Momentum*>( ncb->physicalActions->find( id1 , actionMomentum->getClassIndex() ).get() )->momentum += o1p.Cross(f);
+					static_cast<Momentum*>( ncb->physicalActions->find( id2 , actionMomentum->getClassIndex() ).get() )->momentum -= o2p.Cross(f);
+				#endif
+
 			}
 		}
 	}

Modified: trunk/pkg/realtime-rigidbody/PreProcessor/BoxStack.cpp
===================================================================
--- trunk/pkg/realtime-rigidbody/PreProcessor/BoxStack.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/realtime-rigidbody/PreProcessor/BoxStack.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -95,7 +95,6 @@
 
 	rootBody->persistentInteractions	= shared_ptr<InteractionContainer>(new InteractionVecSet);
 	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 
 	shared_ptr<Body> body;

Modified: trunk/pkg/realtime-rigidbody/PreProcessor/RotatingBox.cpp
===================================================================
--- trunk/pkg/realtime-rigidbody/PreProcessor/RotatingBox.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/realtime-rigidbody/PreProcessor/RotatingBox.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -94,7 +94,6 @@
 	positionRootBody(rootBody);
 	
 	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 
 	

Modified: trunk/pkg/snow/PreProcessor/SnowCreepTest.cpp
===================================================================
--- trunk/pkg/snow/PreProcessor/SnowCreepTest.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/snow/PreProcessor/SnowCreepTest.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -263,7 +263,6 @@
 	positionRootBody(rootBody);
 
 // 	rootBody->transientInteractions		= shared_ptr<InteractionContainer>(new InteractionVecSet);
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 
 	shared_ptr<Body> body;

Modified: trunk/pkg/snow/PreProcessor/SnowVoxelsLoader.cpp
===================================================================
--- trunk/pkg/snow/PreProcessor/SnowVoxelsLoader.cpp	2009-03-29 01:57:12 UTC (rev 1734)
+++ trunk/pkg/snow/PreProcessor/SnowVoxelsLoader.cpp	2009-03-29 10:34:26 UTC (rev 1735)
@@ -234,7 +234,6 @@
 	createActors(rootBody);
 	positionRootBody(rootBody);
 
-	rootBody->physicalActions		= shared_ptr<PhysicalActionContainer>(new PhysicalActionVectorVector);
 	rootBody->bodies 			= shared_ptr<BodyContainer>(new BodyRedirectionVector);
 	
 	if(m_grains.size() == 0)