← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-pkg/yade/git-trunk] Rev 3797: Fix segfault during save/load of CapViscModels

 

------------------------------------------------------------
revno: 3797
committer: Anton Gladky <gladky.anton@xxxxxxxxx>
timestamp: Sun 2016-02-28 07:46:24 +0100
message:
  Fix segfault during save/load of CapViscModels
  
  It looks like there was a problem in a searilaztion
  of pointer to functions, which are implementing different
  capillary bridge models.
  
  Created a vector of pointers on capillary functions and call
  them all from Lawfunctor.
  
  Looks like the problem is resolved.
modified:
  pkg/dem/ViscoelasticCapillarPM.cpp
  pkg/dem/ViscoelasticCapillarPM.hpp


--
lp:yade
https://code.launchpad.net/~yade-pkg/yade/git-trunk

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-pkg/yade/git-trunk/+edit-subscription
=== modified file 'pkg/dem/ViscoelasticCapillarPM.cpp'
--- pkg/dem/ViscoelasticCapillarPM.cpp	2015-06-19 13:01:53 +0000
+++ pkg/dem/ViscoelasticCapillarPM.cpp	2016-02-28 06:46:24 +0000
@@ -1,9 +1,9 @@
-#include"ViscoelasticCapillarPM.hpp"
-#include<core/State.hpp>
-#include<pkg/dem/ScGeom.hpp>
-#include<core/Omega.hpp>
-#include<core/Scene.hpp>
-#include<pkg/common/Sphere.hpp>
+#include "ViscoelasticCapillarPM.hpp"
+#include <core/State.hpp>
+#include <pkg/dem/ScGeom.hpp>
+#include <core/Omega.hpp>
+#include <core/Scene.hpp>
+#include <pkg/common/Sphere.hpp>
 
 YADE_PLUGIN((ViscElCapMat)(ViscElCapPhys)(Ip2_ViscElCapMat_ViscElCapMat_ViscElCapPhys)(Law2_ScGeom_ViscElCapPhys_Basic));
 
@@ -57,13 +57,13 @@
     
     if (mat1->CapillarType == mat2->CapillarType and mat2->CapillarType != ""){
       
-      if      (mat1->CapillarType == "Willett_numeric")  {phys->CapillarType = Willett_numeric;  phys->CapFunct = Law2_ScGeom_ViscElCapPhys_Basic::Willett_numeric_f;}
-      else if (mat1->CapillarType == "Willett_analytic") {phys->CapillarType = Willett_analytic; phys->CapFunct = Law2_ScGeom_ViscElCapPhys_Basic::Willett_analytic_f;}
-      else if (mat1->CapillarType == "Weigert")          {phys->CapillarType = Weigert;          phys->CapFunct = Law2_ScGeom_ViscElCapPhys_Basic::Weigert_f;}
-      else if (mat1->CapillarType == "Rabinovich")       {phys->CapillarType = Rabinovich;       phys->CapFunct = Law2_ScGeom_ViscElCapPhys_Basic::Rabinovich_f;}
-      else if (mat1->CapillarType == "Lambert")          {phys->CapillarType = Lambert;          phys->CapFunct = Law2_ScGeom_ViscElCapPhys_Basic::Lambert_f;}
-      else if (mat1->CapillarType == "Soulie")           {phys->CapillarType = Soulie;           phys->CapFunct = Law2_ScGeom_ViscElCapPhys_Basic::Soulie_f;}
-      else                                               {phys->CapillarType = None_Capillar;    phys->CapFunct = Law2_ScGeom_ViscElCapPhys_Basic::None_f;}
+      if      (mat1->CapillarType == "Willett_numeric")  {phys->CapillarType = Willett_numeric;}
+      else if (mat1->CapillarType == "Willett_analytic") {phys->CapillarType = Willett_analytic;}
+      else if (mat1->CapillarType == "Weigert")          {phys->CapillarType = Weigert;}
+      else if (mat1->CapillarType == "Rabinovich")       {phys->CapillarType = Rabinovich;}
+      else if (mat1->CapillarType == "Lambert")          {phys->CapillarType = Lambert;}
+      else if (mat1->CapillarType == "Soulie")           {phys->CapillarType = Soulie;}
+      else                                               {phys->CapillarType = None_Capillar;}
     } else {
       throw runtime_error("CapillarType should be equal for both particles!.");
     }
@@ -131,7 +131,7 @@
         NLiqBridg += 1;
       }
       
-      const auto normalCapForceScalar = phys.CapFunct(geom, phys);
+      const auto normalCapForceScalar = CapFunctionsPool[phys.CapillarType](geom, phys);
       Real dampCapForceScalar = 0.0;
       
       if (phys.dcap) {

=== modified file 'pkg/dem/ViscoelasticCapillarPM.hpp'
--- pkg/dem/ViscoelasticCapillarPM.hpp	2015-06-19 13:01:53 +0000
+++ pkg/dem/ViscoelasticCapillarPM.hpp	2016-02-28 06:46:24 +0000
@@ -2,6 +2,7 @@
 #include "ViscoelasticPM.hpp"
 #include <boost/unordered_map.hpp>
 #include <core/PartialEngine.hpp>
+#include <functional>
 
 class ViscElCapMat : public ViscElMat {
 	public:
@@ -29,7 +30,6 @@
 	public:
 		virtual ~ViscElCapPhys();
 		Real R;
-		CapillarFunction CapFunct;
 	YADE_CLASS_BASE_DOC_ATTRS_CTOR(ViscElCapPhys,ViscElPhys,"IPhys created from :yref:`ViscElCapMat`, for use with :yref:`Law2_ScGeom_ViscElCapPhys_Basic`.",
 		((bool,Capillar,false,,"True, if capillar forces need to be added."))
 		((bool,liqBridgeCreated,false,,"Whether liquid bridge was created, only after a normal contact of spheres"))
@@ -75,12 +75,23 @@
 		static Real Lambert_f             (const ScGeom& geom, ViscElCapPhys& phys);
 		static Real Soulie_f              (const ScGeom& geom, ViscElCapPhys& phys);
 		static Real None_f                (const ScGeom& geom, ViscElCapPhys& phys);
+		std::deque<std::function<Real(const ScGeom& geom, ViscElCapPhys& phys)> > CapFunctionsPool;
 		Real critDist(const Real& Vb, const Real& R, const Real& Theta);
 	FUNCTOR2D(ScGeom,ViscElCapPhys);
 	YADE_CLASS_BASE_DOC_ATTRS_CTOR_PY(Law2_ScGeom_ViscElCapPhys_Basic,LawFunctor,"Extended version of Linear viscoelastic model with capillary parameters.",
 		((OpenMPAccumulator<Real>,VLiqBridg,,Attr::noSave,"The total volume of liquid bridges"))
 		((OpenMPAccumulator<int>, NLiqBridg,,Attr::noSave,"The total number of liquid bridges"))
-		,/* ctor */
+		,{
+//enum CapType {None_Capillar, Willett_numeric, Willett_analytic, Weigert, Rabinovich, Lambert, Soulie};
+			CapFunctionsPool.resize(20, nullptr);
+			CapFunctionsPool[None_Capillar] = None_f;
+			CapFunctionsPool[Willett_numeric] = Willett_numeric_f;
+			CapFunctionsPool[Willett_analytic] = Willett_analytic_f;
+			CapFunctionsPool[Weigert] = Weigert_f;
+			CapFunctionsPool[Rabinovich] = Rabinovich_f;
+			CapFunctionsPool[Lambert] = Lambert_f;
+			CapFunctionsPool[Soulie] = Soulie_f;
+		 }
 		,/* py */
 		;
 	)