yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #01272
[svn] r1784 - trunk/extra/SpherePadder
Author: richefeu
Date: 2009-05-29 10:42:46 +0200 (Fri, 29 May 2009)
New Revision: 1784
Modified:
trunk/extra/SpherePadder/SpherePadder.hpp
trunk/extra/SpherePadder/SpherePadder_wrapper.cpp
Log:
Add a function to SpherePadder_wrapper to pass the result back to python.
As Vaclav suggested, it is a list of (x,y,z,R) tuples.
(Complet integration into yade is not done yet)
Modified: trunk/extra/SpherePadder/SpherePadder.hpp
===================================================================
--- trunk/extra/SpherePadder/SpherePadder.hpp 2009-05-28 13:44:55 UTC (rev 1783)
+++ trunk/extra/SpherePadder/SpherePadder.hpp 2009-05-29 08:42:46 UTC (rev 1784)
@@ -31,155 +31,157 @@
typedef unsigned int id_type; // [0 -> 4,294,967,295] if 32 bits
enum SphereType
{
- AT_NODE,
- AT_SEGMENT,
- AT_FACE,
- AT_TETRA_CENTER,
- AT_TETRA_VERTEX,
- INSERTED_BY_USER,
- FROM_TRIANGULATION,
- VIRTUAL
+ AT_NODE,
+ AT_SEGMENT,
+ AT_FACE,
+ AT_TETRA_CENTER,
+ AT_TETRA_VERTEX,
+ INSERTED_BY_USER,
+ FROM_TRIANGULATION,
+ VIRTUAL
};
struct Criterion
{
- bool nb_spheres;
- bool solid_fraction;
- id_type nb_spheres_max;
- double solid_fraction_max;
- double x,y,z,R;
+ bool nb_spheres;
+ bool solid_fraction;
+ id_type nb_spheres_max;
+ double solid_fraction_max;
+ double x,y,z,R;
};
struct Sphere
{
- double x,y,z,R;
- SphereType type;
+ double x,y,z,R;
+ SphereType type;
};
struct Neighbor
{
- id_type i,j;
+ id_type i,j;
};
struct neighbor_with_distance
{
- id_type sphereId;
- double distance;
- bool priority;
+ id_type sphereId;
+ double distance;
+ bool priority;
};
struct tetra_porosity
{
- id_type id1,id2,id3,id4;
- double volume;
- double void_volume;
+ id_type id1,id2,id3,id4;
+ double volume;
+ double void_volume;
};
// not used
class CompareNeighborId
{
- public:
- bool operator()(Neighbor& N1, Neighbor& N2)
- {
- if (N1.i < N2.i) return true;
- if ((N1.i == N2.i) && (N1.j < N2.j)) return true;
- return false;
- }
+ public:
+ bool operator()(Neighbor& N1, Neighbor& N2)
+ {
+ if (N1.i < N2.i) return true;
+ if ((N1.i == N2.i) && (N1.j < N2.j)) return true;
+ return false;
+ }
};
class SpherePadder
{
- protected:
+ protected:
- vector<vector<id_type> > combination;
- SpherePackingTriangulation triangulation;
- vector<tetra_porosity> tetra_porosities;
- Criterion criterion;
+ vector<vector<id_type> > combination;
+ SpherePackingTriangulation triangulation;
+ vector<tetra_porosity> tetra_porosities;
+ Criterion criterion;
- double distance_spheres (id_type i, id_type j); // deprecated
- double distance_spheres (Sphere& S1,Sphere& S2);
- double squared_distance_centre_spheres(id_type i, id_type j); // deprecated
- double distance_centre_spheres(Sphere& S1, Sphere& S2);
- double distance_vector3 (double V1[],double V2[]);
- void build_sorted_list_of_neighbors(id_type sphereId, vector<neighbor_with_distance> & neighbor);
- void build_sorted_list_of_neighbors(Sphere & S, vector<neighbor_with_distance> & neighbor);
- double spherical_triangle (double point1[],double point2[],double point3[],double point4[]);
- double solid_volume_of_tetrahedron(Sphere& S1, Sphere& S2, Sphere& S3, Sphere& S4);
- void place_at_nodes ();
- void place_at_segment_middle ();
- void place_at_faces ();
- void place_at_tetra_centers ();
- void place_at_tetra_vertexes ();
- void cancel_overlaps ();
- unsigned int iter_densify(unsigned int nb_check = 20);
- void repack_null_radii();
+ double distance_spheres (id_type i, id_type j); // deprecated
+ double distance_spheres (Sphere& S1,Sphere& S2);
+ double squared_distance_centre_spheres(id_type i, id_type j); // deprecated
+ double distance_centre_spheres(Sphere& S1, Sphere& S2);
+ double distance_vector3 (double V1[],double V2[]);
+ void build_sorted_list_of_neighbors(id_type sphereId, vector<neighbor_with_distance> & neighbor);
+ void build_sorted_list_of_neighbors(Sphere & S, vector<neighbor_with_distance> & neighbor);
+ double spherical_triangle (double point1[],double point2[],double point3[],double point4[]);
+ double solid_volume_of_tetrahedron(Sphere& S1, Sphere& S2, Sphere& S3, Sphere& S4);
+ void place_at_nodes ();
+ void place_at_segment_middle ();
+ void place_at_faces ();
+ void place_at_tetra_centers ();
+ void place_at_tetra_vertexes ();
+ void cancel_overlaps ();
+ unsigned int iter_densify(unsigned int nb_check = 20);
+ void repack_null_radii();
// some key functions
- unsigned int place_fifth_sphere(id_type s1, id_type s2, id_type s3, id_type s4, Sphere& S);
- unsigned int place_sphere_4contacts (id_type sphereId, unsigned int nb_combi_max = 15);// (deprecated)
- unsigned int place_sphere_4contacts (Sphere& S, unsigned int nb_combi_max = 15);
- unsigned int check_overlaps(Sphere & S, id_type excludedId);
+ unsigned int place_fifth_sphere(id_type s1, id_type s2, id_type s3, id_type s4, Sphere& S);
+ unsigned int place_sphere_4contacts (id_type sphereId, unsigned int nb_combi_max = 15);// (deprecated)
+ unsigned int place_sphere_4contacts (Sphere& S, unsigned int nb_combi_max = 15);
+ unsigned int check_overlaps(Sphere & S, id_type excludedId);
- double rmin,rmax,rmoy;
- double ratio; // rmax/rmin
- double max_overlap_rate;
- id_type n1,n2,n3,n4,n5,n_densify,nzero;
- unsigned int max_iter_densify;
- double virtual_radius_factor;
- bool RadiusDataIsOK,RadiusIsSet;
- unsigned int zmin;
- double gap_max;
+ double rmin,rmax,rmoy;
+ double ratio; // rmax/rmin
+ double max_overlap_rate;
+ id_type n1,n2,n3,n4,n5,n_densify,nzero;
+ unsigned int max_iter_densify;
+ double virtual_radius_factor;
+ bool RadiusDataIsOK,RadiusIsSet;
+ unsigned int zmin;
+ double gap_max;
- TetraMesh * mesh;
- vector <Sphere> sphere;
- CellPartition partition;
- list <id_type> bounds;
+ TetraMesh * mesh;
+ vector <Sphere> sphere;
+ CellPartition partition;
+ list <id_type> bounds;
- bool verbose;
- bool Must_Stop;
+ bool verbose;
+ bool Must_Stop;
- public:
+ public:
- bool meshIsPlugged;
+ bool meshIsPlugged;
- void ShutUp() { verbose = false; }
- void Speak() { verbose = true; }
+ void ShutUp() { verbose = false; }
+ void Speak() { verbose = true; }
- void setRadiusRatio (double r, double rapp = 0.125);
- void setRadiusRange (double min, double max);
- void setMaxOverlapRate (double r) { max_overlap_rate = fabs(r); }
- void setVirtualRadiusFactor (double f) {virtual_radius_factor = fabs(f);}
- void setMaxNumberOfSpheres (id_type max);
- void setMaxSolidFractioninProbe (double max, double x, double y,double z, double R);
+ void setRadiusRatio (double r, double rapp = 0.125);
+ void setRadiusRange (double min, double max);
+ void setMaxOverlapRate (double r) { max_overlap_rate = fabs(r); }
+ void setVirtualRadiusFactor (double f) {virtual_radius_factor = fabs(f);}
+ void setMaxNumberOfSpheres (id_type max);
+ void setMaxSolidFractioninProbe (double max, double x, double y,double z, double R);
- id_type getNumberOfSpheres ();
- double getMeanSolidFraction (double x, double y, double z, double R);
+ vector<Sphere> & getSphereList() { return sphere;}
+ TetraMesh * getMesh() { return mesh; }
+ id_type getNumberOfSpheres ();
+ double getMeanSolidFraction (double x, double y, double z, double R);
- void plugTetraMesh (TetraMesh * mesh);
- void save_mgpost (const char* name);
- void save_tri_mgpost (const char* name);
- void save_Rxyz (const char* name);
+ void plugTetraMesh (TetraMesh * mesh);
+ void save_mgpost (const char* name);
+ void save_tri_mgpost (const char* name);
+ void save_Rxyz (const char* name);
- SpherePadder ();
+ SpherePadder ();
// Check functions only for debug (very slow!!)
- void detect_overlap ();
+ void detect_overlap ();
//! \brief 5-step padding (for details see Jerier et al.)
- void pad_5 ();
+ void pad_5 ();
//! \brief Place virtual spheres at mesh boudaries and modify the position and radius of overlapping spheres in such a way that theu are in contact with the boundary plans.
- void place_virtual_spheres ();
+ void place_virtual_spheres ();
//! \brief Make the packing denser by filling void spaces detected by building a Delaunay triangulation (with CGAL)
- void densify ();
+ void densify ();
//! \brief Insert a sphere (x,y,z,R) within the packing. Overlapping spheres are cancelled.
- void insert_sphere (double x, double y, double z, double R);
+ void insert_sphere (double x, double y, double z, double R);
// FOR ANALYSIS
- void save_granulo (const char* name);
- void rdf (unsigned int Npoint, unsigned int Nrmean);
+ void save_granulo (const char* name);
+ void rdf (unsigned int Npoint, unsigned int Nrmean);
};
Modified: trunk/extra/SpherePadder/SpherePadder_wrapper.cpp
===================================================================
--- trunk/extra/SpherePadder/SpherePadder_wrapper.cpp 2009-05-28 13:44:55 UTC (rev 1783)
+++ trunk/extra/SpherePadder/SpherePadder_wrapper.cpp 2009-05-29 08:42:46 UTC (rev 1784)
@@ -10,39 +10,56 @@
#include "TetraMesh.hpp"
#include <boost/python.hpp>
-using namespace boost::python;
-BOOST_PYTHON_MODULE(packing){
+boost::python::list getSphereList(SpherePadder* SP)
+{
+ boost::python::list l;
+ vector <Sphere> & spheres = SP->getSphereList();
+ double xtrans = SP->getMesh()->xtrans;
+ double ytrans = SP->getMesh()->ytrans;
+ double ztrans = SP->getMesh()->ztrans;
+ for (unsigned int i = 0 ; i < spheres.size() ; ++i)
+ {
+ if (spheres[i].type == VIRTUAL || spheres[i].R <= 0.0) continue;
+ l.append( boost::python::make_tuple(spheres[i].x+xtrans, spheres[i].y+ytrans, spheres[i].z+ztrans, spheres[i].R) );
+ }
+ return l;
+}
- class_<TetraMesh>("TetraMesh")
- .def("read", &TetraMesh::read)
- .def("read_gmsh", &TetraMesh::read_gmsh)
- .def("read_inp", &TetraMesh::read_inp)
- ;
- class_<SpherePadder>("SpherePadder")
+BOOST_PYTHON_MODULE(packing){
+ using namespace boost::python;
+
+ class_<TetraMesh>("TetraMesh")
+ .def("read", &TetraMesh::read)
+ .def("read_gmsh", &TetraMesh::read_gmsh)
+ .def("read_inp", &TetraMesh::read_inp)
+ ;
- .def("ShutUp", &SpherePadder::ShutUp)
- .def("Speak", &SpherePadder::Speak)
- .def("setRadiusRatio", &SpherePadder::setRadiusRatio)
- .def("setRadiusRange", &SpherePadder::setRadiusRange)
- .def("setMaxOverlapRate", &SpherePadder::setMaxOverlapRate)
- .def("setVirtualRadiusFactor", &SpherePadder::setVirtualRadiusFactor)
- .def("setMaxNumberOfSpheres", &SpherePadder::setMaxNumberOfSpheres)
- .def("setMaxSolidFractioninProbe", &SpherePadder::setMaxSolidFractioninProbe)
- .def("getNumberOfSpheres", &SpherePadder::getNumberOfSpheres)
- .def("getMeanSolidFraction", &SpherePadder::getMeanSolidFraction)
+ class_<SpherePadder>("SpherePadder")
- .def("plugTetraMesh", &SpherePadder::plugTetraMesh)
- .def("save_mgpost", &SpherePadder::save_mgpost)
- .def("save_Rxyz", &SpherePadder::save_Rxyz)
+ .def("ShutUp", &SpherePadder::ShutUp)
+ .def("Speak", &SpherePadder::Speak)
+ .def("setRadiusRatio", &SpherePadder::setRadiusRatio)
+ .def("setRadiusRange", &SpherePadder::setRadiusRange)
+ .def("setMaxOverlapRate", &SpherePadder::setMaxOverlapRate)
+ .def("setVirtualRadiusFactor", &SpherePadder::setVirtualRadiusFactor)
+ .def("setMaxNumberOfSpheres", &SpherePadder::setMaxNumberOfSpheres)
+ .def("setMaxSolidFractioninProbe", &SpherePadder::setMaxSolidFractioninProbe)
+ .def("getNumberOfSpheres", &SpherePadder::getNumberOfSpheres)
+ .def("getMeanSolidFraction", &SpherePadder::getMeanSolidFraction)
- .def("pad_5", &SpherePadder::pad_5)
- .def("place_virtual_spheres", &SpherePadder::place_virtual_spheres)
- .def("densify", &SpherePadder::densify)
- .def("insert_sphere", &SpherePadder::insert_sphere)
- ;
+ .def("plugTetraMesh", &SpherePadder::plugTetraMesh)
+ .def("save_mgpost", &SpherePadder::save_mgpost)
+ .def("save_Rxyz", &SpherePadder::save_Rxyz)
+ .def("pad_5", &SpherePadder::pad_5)
+ .def("place_virtual_spheres", &SpherePadder::place_virtual_spheres)
+ .def("densify", &SpherePadder::densify)
+ .def("insert_sphere", &SpherePadder::insert_sphere)
+ ;
+
+ def("getSphereList", getSphereList);
}
Follow ups