~ubuntu-branches/debian/jessie/yade/jessie

« back to all changes in this revision

Viewing changes to pkg/dem/SpherePack.cpp

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2014-06-25 20:43:49 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20140625204349-tn3dqehk352c2xv1
Tags: 1.10.0-1
* [431abb8] Imported Upstream version 1.10.0 (Closes: #750318)
* [3552a3e] Set minimal vtk6 version 6.1.0+dfsg-8.
* [cd915f6] Set minimal eigen3 version 3.2.1-2.
* [8e02049] Add autopkgtest-field to control.
* [38389f8] Remove patches aplied by upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
CREATE_LOGGER(SpherePack);
19
19
 
20
20
using namespace std;
21
 
using namespace boost;
 
21
 
22
22
namespace py=boost::python;
23
23
 
24
24
 
36
36
 
37
37
void SpherePack::fromLists(const vector<Vector3r>& centers, const vector<Real>& radii){
38
38
        pack.clear();
39
 
        if(centers.size()!=radii.size()) throw std::invalid_argument(("The same number of centers and radii must be given (is "+lexical_cast<string>(centers.size())+", "+lexical_cast<string>(radii.size())+")").c_str());
 
39
        if(centers.size()!=radii.size()) throw std::invalid_argument(("The same number of centers and radii must be given (is "+boost::lexical_cast<string>(centers.size())+", "+boost::lexical_cast<string>(radii.size())+")").c_str());
40
40
        size_t l=centers.size();
41
41
        for(size_t i=0; i<l; i++){
42
42
                add(centers[i],radii[i]);
51
51
};
52
52
 
53
53
void SpherePack::fromFile(string file) {
54
 
        typedef tuple<Vector3r,Real,int> tupleVector3rRealInt;
 
54
        typedef boost::tuple<Vector3r,Real,int> tupleVector3rRealInt;
55
55
        vector<tupleVector3rRealInt> ss;
56
56
        Vector3r mn,mx;
57
57
        ss=Shop::loadSpheresFromFile(file,mn,mx,&cellSize);
58
58
        pack.clear();
59
 
        FOREACH(const tupleVector3rRealInt& s, ss) pack.push_back(Sph(get<0>(s),get<1>(s),get<2>(s)));
 
59
        FOREACH(const tupleVector3rRealInt& s, ss) pack.push_back(Sph(boost::get<0>(s),boost::get<1>(s),boost::get<2>(s)));
60
60
}
61
61
 
62
62
void SpherePack::toFile(const string fname) const {
75
75
        Scene* scene=Omega::instance().getScene().get();
76
76
        FOREACH(const shared_ptr<Body>& b, *scene->bodies){
77
77
                if(!b) continue;
78
 
                shared_ptr<Sphere> intSph=dynamic_pointer_cast<Sphere>(b->shape);
 
78
                shared_ptr<Sphere> intSph=boost::dynamic_pointer_cast<Sphere>(b->shape);
79
79
                if(!intSph) continue;
80
80
                pack.push_back(Sph(b->state->pos,intSph->radius,(b->isClumpMember()?b->clumpId:-1)));
81
81
        }
118
118
        // transform sizes and cummulated fractions values in something convenient for the generation process
119
119
        if(psdSizes.size()>0){
120
120
                err=(mode>=0); mode=RDIST_PSD;
121
 
                if(psdSizes.size()!=psdCumm.size()) throw invalid_argument(("SpherePack.makeCloud: psdSizes and psdCumm must have same dimensions ("+lexical_cast<string>(psdSizes.size())+"!="+lexical_cast<string>(psdCumm.size())).c_str());
 
121
                if(psdSizes.size()!=psdCumm.size()) throw invalid_argument(("SpherePack.makeCloud: psdSizes and psdCumm must have same dimensions ("+boost::lexical_cast<string>(psdSizes.size())+"!="+boost::lexical_cast<string>(psdCumm.size())).c_str());
122
122
                if(psdSizes.size()<=1) throw invalid_argument("SpherePack.makeCloud: psdSizes must have at least 2 items");
123
123
                if((*psdCumm.begin())!=0. && (*psdCumm.rbegin())!=1.) throw invalid_argument("SpherePack.makeCloud: first and last items of psdCumm *must* be exactly 0 and 1.");
124
124
                psdRadii.reserve(psdSizes.size());
129
129
                                if (i==0) psdCumm2.push_back(0);
130
130
                                else psdCumm2.push_back(psdCumm2[i-1] + 3.0* (volume?volume:(area*psdSizes[psdSizes.size()-1])) *(1-porosity)/Mathr::PI*(psdCumm[i]-psdCumm[i-1])/(psdSizes[i]-psdSizes[i-1])*(pow(psdSizes[i-1],-2)-pow(psdSizes[i],-2)));
131
131
                        }
132
 
                        LOG_DEBUG(i<<". "<<psdRadii[i]<<", cdf="<<psdCumm[i]<<", cdf2="<<(distributeMass?lexical_cast<string>(psdCumm2[i]):string("--")));
 
132
                        LOG_DEBUG(i<<". "<<psdRadii[i]<<", cdf="<<psdCumm[i]<<", cdf2="<<(distributeMass?boost::lexical_cast<string>(psdCumm2[i]):string("--")));
133
133
                        // check monotonicity
134
134
                        if(i>0 && (psdSizes[i-1]>psdSizes[i] || psdCumm[i-1]>psdCumm[i])) throw invalid_argument("SpherePack:makeCloud: psdSizes and psdCumm must be both non-decreasing.");
135
135
                }
540
540
}
541
541
 
542
542
bool SpherePack::hasClumps() const { FOREACH(const Sph& s, pack){ if(s.clumpId>=0) return true; } return false; }
543
 
python::tuple SpherePack::getClumps() const{
 
543
py::tuple SpherePack::getClumps() const{
544
544
        std::map<int,py::list> clumps;
545
545
        py::list standalone; size_t packSize=pack.size();
546
546
        for(size_t i=0; i<packSize; i++){
552
552
        py::list clumpList;
553
553
        typedef std::pair<int,py::list> intListPair;
554
554
        FOREACH(const intListPair& c, clumps) clumpList.append(c.second);
555
 
        return python::make_tuple(standalone,clumpList); 
 
555
        return py::make_tuple(standalone,clumpList); 
556
556
}
557
557