Author: eudoxos
Date: 2008-10-29 20:29:18 +0100 (Wed, 29 Oct 2008)
New Revision: 1565

Modified:
   trunk/gui/py/pyAttrUtils.hpp
   trunk/lib/serialization/FundamentalHandler.tpp
   trunk/lib/serialization/KnownFundamentalsHandler.tpp
   trunk/pkg/dem/PreProcessor/MembraneTest.cpp
   trunk/pkg/dem/PreProcessor/TriaxialTest.cpp
   trunk/pkg/dem/PreProcessor/TriaxialTest.hpp
Log:
1. Make our intelligence-challenged deserializer finally gracefully handle nan, 
inf, -inf (arbitrary lower-upper case).
2. Fix crash in MembraneTest (leftover in the commit from testing, oh well)
3. Add TriaxialTest::fixedBoxDims to not scale selected box dimensions if 
sphere mean radius is given (example underway).



Modified: trunk/gui/py/pyAttrUtils.hpp
===================================================================
--- trunk/gui/py/pyAttrUtils.hpp        2008-10-29 10:31:21 UTC (rev 1564)
+++ trunk/gui/py/pyAttrUtils.hpp        2008-10-29 19:29:18 UTC (rev 1565)
@@ -4,6 +4,7 @@
 #include<map>
 #include<vector>
 #include<boost/shared_ptr.hpp>
+#include<yade/lib-serialization/Archive.hpp>
 #include<yade/lib-serialization-xml/XMLFormatManager.hpp>
 #include<boost/python.hpp>
 
@@ -159,6 +160,7 @@
                //! return python list of keys (attribute names)
                boost::python::list pyKeys(){boost::python::list ret; 
for(DescriptorMap::iterator 
I=descriptors.begin();I!=descriptors.end();I++)ret.append(I->first); return 
ret;}
 
+
                //! return attribute value as python object
                boost::python::object pyGet(std::string key){
                        DescriptorMap::iterator I=descriptors.find(key);
@@ -167,15 +169,15 @@
                        LOG_DEBUG("Got raw attribute `"<<key<<"'");
                        switch(descriptors[key].type){
                                case BOOL: return 
python::object(lexical_cast<bool>(raw[0]));
-                               case NUMBER: return 
python::object(lexical_cast<double>(raw[0]));
+                               case NUMBER: return 
python::object(lexical_cast_maybeNanInf<double>(raw[0]));
                                case STRING: return python::object(raw[0]);
                                case SEQ_STRING: {python::list ret; for(size_t 
i=0; i<raw.size(); i++) ret.append(python::object(raw[i])); return ret;}
-                               case SEQ_NUMBER: {python::list ret; for(size_t 
i=0; i<raw.size(); i++){ 
ret.append(python::object(lexical_cast<double>(raw[i]))); LOG_TRACE("Appended 
"<<raw[i]);} return ret; }
+                               case SEQ_NUMBER: {python::list ret; for(size_t 
i=0; i<raw.size(); i++){ 
ret.append(python::object(lexical_cast_maybeNanInf<double>(raw[i]))); 
LOG_TRACE("Appended "<<raw[i]);} return ret; }
                                case VEC_VEC: {
                                        python::list ret; for(size_t i=0; 
i<raw.size(); i++){
                                                /* raw[i] has the form "{number 
number number}" */
                                                vector<string> s; 
boost::algorithm::split(s,raw[i],algorithm::is_any_of("{} 
"),algorithm::token_compress_on);
-                                               python::list subList; 
FOREACH(string ss, s) subList.append(python::object(lexical_cast<double>(ss)));
+                                               python::list subList; 
FOREACH(string ss, s) 
subList.append(python::object(lexical_cast_maybeNanInf<double>(ss)));
                                                ret.append(subList);
                                        }
                                }

Modified: trunk/lib/serialization/FundamentalHandler.tpp
===================================================================
--- trunk/lib/serialization/FundamentalHandler.tpp      2008-10-29 10:31:21 UTC 
(rev 1564)
+++ trunk/lib/serialization/FundamentalHandler.tpp      2008-10-29 19:29:18 UTC 
(rev 1565)
@@ -87,6 +87,15 @@
        }
 };
 
+template <typename RealType>
+RealType lexical_cast_maybeNanInf(const string& s){
+       if((s[0]=='n' || s[0]=='N') && (s[1]=='a' || s[1]=='A') && (s[2]=='n' 
|| s[2]=='N')) return std::numeric_limits<RealType>::quiet_NaN();
+       if((s[0]=='i' || s[0]=='I') && (s[1]=='n' || s[1]=='N') && (s[2]=='f' 
|| s[2]=='F')) return std::numeric_limits<RealType>::infinity();
+       if(s[0]=='-' && (s[1]=='i' || s[1]=='I') && (s[2]=='n' || s[2]=='N') && 
(s[3]=='f' || s[3]=='F')) return -std::numeric_limits<RealType>::infinity();
+       return lexical_cast<RealType>(s);
+};
+
+
 template<typename Type >
 inline void lexical_copy(Archive& ac , any& a )
 {
@@ -99,7 +108,9 @@
                try{
                        *tmp = lexical_cast<Type>(*tmpStr);
                } catch(boost::bad_lexical_cast& e){
-                       if(typeid(tmp)==typeid(bool*) && 
atoi(tmpStr->c_str())!=0) { cerr<<"warning: offensive bool value 
`"<<*tmpStr<<"' encountered (interpreted as true)."<<endl; 
*tmp=lexical_cast<Type>("1"); /* cerr<<"New value: 
"<<lexical_cast<string>(*tmp)<<endl; cerr<<"Atoi returns 
"<<atoi(tmpStr->c_str())<<", bool !=0 is "<<(atoi(tmpStr->c_str())!=0)<<endl;*/ 
}
+                       if(typeid(tmp)==typeid(bool*) && 
atoi(tmpStr->c_str())!=0) { cerr<<"warning: offensive bool value 
`"<<*tmpStr<<"' encountered (interpreted as true)."<<endl; 
*tmp=lexical_cast<Type>("1"); /* cerr<<"New value: 
"<<lexical_cast<string>(*tmp)<<endl; cerr<<"Atoi returns 
"<<atoi(tmpStr->c_str())<<", bool !=0 is "<<(atoi(tmpStr->c_str())!=0)<<endl;*/
+                       }
+                       else *tmp=lexical_cast_maybeNanInf<Type>(*tmpStr);
                }
        }
        else if (a.type()==typeid(string*)) // serialization - writing to 
string from some Type
@@ -115,6 +126,9 @@
                throw HandlerError(SerializationExceptions::LexicalCopyError);
 }
 
+
+
+
 template< >
 struct FundamentalHandler< int >
 {

Modified: trunk/lib/serialization/KnownFundamentalsHandler.tpp
===================================================================
--- trunk/lib/serialization/KnownFundamentalsHandler.tpp        2008-10-29 
10:31:21 UTC (rev 1564)
+++ trunk/lib/serialization/KnownFundamentalsHandler.tpp        2008-10-29 
19:29:18 UTC (rev 1565)
@@ -110,8 +110,8 @@
                        vector<string> tokens;
                        IOFormatManager::parseFundamental(*tmpStr, tokens);
                
-                       tmp->X() = lexical_cast<RealType>(tokens[0]);
-                       tmp->Y() = lexical_cast<RealType>(tokens[1]);
+                       tmp->X() = 
lexical_cast_maybeNanInf<RealType>(tokens[0]);
+                       tmp->Y() = 
lexical_cast_maybeNanInf<RealType>(tokens[1]);
                }
                else if (a.type()==typeid(const vector<unsigned char>*)) // 
from binary stream to Type
                {
@@ -168,9 +168,9 @@
                        vector<string> tokens;
                        IOFormatManager::parseFundamental(*tmpStr, tokens);
                
-                       tmp->X() = lexical_cast<RealType>(tokens[0]);
-                       tmp->Y() = lexical_cast<RealType>(tokens[1]);
-                       tmp->Z() = lexical_cast<RealType>(tokens[2]);
+                       tmp->X() = 
lexical_cast_maybeNanInf<RealType>(tokens[0]);
+                       tmp->Y() = 
lexical_cast_maybeNanInf<RealType>(tokens[1]);
+                       tmp->Z() = 
lexical_cast_maybeNanInf<RealType>(tokens[2]);
                }
                else if (a.type()==typeid(const vector<unsigned char>*)) // 
from binary stream to Type
                {
@@ -231,10 +231,10 @@
                        vector<string> tokens;
                        IOFormatManager::parseFundamental(*tmpStr, tokens);
                
-                       tmp->X() = lexical_cast<RealType>(tokens[0]);
-                       tmp->Y() = lexical_cast<RealType>(tokens[1]);
-                       tmp->Z() = lexical_cast<RealType>(tokens[2]);
-                       tmp->W() = lexical_cast<RealType>(tokens[3]);
+                       tmp->X() = 
lexical_cast_maybeNanInf<RealType>(tokens[0]);
+                       tmp->Y() = 
lexical_cast_maybeNanInf<RealType>(tokens[1]);
+                       tmp->Z() = 
lexical_cast_maybeNanInf<RealType>(tokens[2]);
+                       tmp->W() = 
lexical_cast_maybeNanInf<RealType>(tokens[3]);
                }
                else if (a.type()==typeid(const vector<unsigned char>*)) // 
from binary stream to Type
                {
@@ -299,10 +299,11 @@
                        vector<string> tokens;
                        IOFormatManager::parseFundamental(*tmpStr, tokens);
                
-                       *tmp = Matrix2<RealType>(       
lexical_cast<RealType>(tokens[0]),
-                                                       
lexical_cast<RealType>(tokens[1]),
-                                                       
lexical_cast<RealType>(tokens[2]),
-                                                       
lexical_cast<RealType>(tokens[3]));
+                       *tmp = Matrix2<RealType>(
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[0]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[1]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[2]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[3]));
                }
                else if (a.type()==typeid(const vector<unsigned char>*)) // 
from binary stream to Type
                {
@@ -367,15 +368,16 @@
                        vector<string> tokens;
                        IOFormatManager::parseFundamental(*tmpStr, tokens);
                
-                       *tmp = Matrix3<RealType>(       
lexical_cast<RealType>(tokens[0]),
-                                                       
lexical_cast<RealType>(tokens[1]),
-                                                       
lexical_cast<RealType>(tokens[2]),
-                                                       
lexical_cast<RealType>(tokens[3]),
-                                                       
lexical_cast<RealType>(tokens[4]),
-                                                       
lexical_cast<RealType>(tokens[5]),
-                                                       
lexical_cast<RealType>(tokens[6]),
-                                                       
lexical_cast<RealType>(tokens[7]),
-                                                       
lexical_cast<RealType>(tokens[8]));
+                       *tmp = Matrix3<RealType>(
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[0]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[1]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[2]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[3]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[4]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[5]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[6]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[7]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[8]));
                }
                else if (a.type()==typeid(const vector<unsigned char>*)) // 
from binary stream to Type
                {
@@ -460,22 +462,23 @@
                        vector<string> tokens;
                        IOFormatManager::parseFundamental(*tmpStr, tokens);
                
-                       *tmp = Matrix4<RealType>(       
lexical_cast<RealType>(tokens[0]),
-                                                       
lexical_cast<RealType>(tokens[1]),
-                                                       
lexical_cast<RealType>(tokens[2]),
-                                                       
lexical_cast<RealType>(tokens[3]),
-                                                       
lexical_cast<RealType>(tokens[4]),
-                                                       
lexical_cast<RealType>(tokens[5]),
-                                                       
lexical_cast<RealType>(tokens[6]),
-                                                       
lexical_cast<RealType>(tokens[7]),
-                                                       
lexical_cast<RealType>(tokens[8]),
-                                                       
lexical_cast<RealType>(tokens[9]),
-                                                       
lexical_cast<RealType>(tokens[10]),
-                                                       
lexical_cast<RealType>(tokens[11]),
-                                                       
lexical_cast<RealType>(tokens[12]),
-                                                       
lexical_cast<RealType>(tokens[13]),
-                                                       
lexical_cast<RealType>(tokens[14]),
-                                                       
lexical_cast<RealType>(tokens[15]));
+                       *tmp = Matrix4<RealType>(
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[0]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[1]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[2]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[3]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[4]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[5]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[6]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[7]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[8]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[9]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[10]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[11]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[12]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[13]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[14]),
+                                                       
lexical_cast_maybeNanInf<RealType>(tokens[15]));
                }
                else if (a.type()==typeid(const vector<unsigned char>*)) // 
from binary stream to Type
                {
@@ -594,17 +597,17 @@
                
                        if (tokens.size()==3) // Quaternion is written as axis 
which norm is the angle in radian
                        {
-                               axis[0] = lexical_cast<RealType>(tokens[0]);
-                               axis[1] = lexical_cast<RealType>(tokens[1]);
-                               axis[2] = lexical_cast<RealType>(tokens[2]);
+                               axis[0] = 
lexical_cast_maybeNanInf<RealType>(tokens[0]);
+                               axis[1] = 
lexical_cast_maybeNanInf<RealType>(tokens[1]);
+                               axis[2] = 
lexical_cast_maybeNanInf<RealType>(tokens[2]);
                                angle = axis.Normalize();
                        }
                        else // tokens.size()==4 Quaternion is written as axis 
angle
                        {
-                               axis[0] = lexical_cast<RealType>(tokens[0]);
-                               axis[1] = lexical_cast<RealType>(tokens[1]);
-                               axis[2] = lexical_cast<RealType>(tokens[2]);
-                               angle   = lexical_cast<RealType>(tokens[3]);
+                               axis[0] = 
lexical_cast_maybeNanInf<RealType>(tokens[0]);
+                               axis[1] = 
lexical_cast_maybeNanInf<RealType>(tokens[1]);
+                               axis[2] = 
lexical_cast_maybeNanInf<RealType>(tokens[2]);
+                               angle   = 
lexical_cast_maybeNanInf<RealType>(tokens[3]);
                        }
                        tmp->FromAxisAngle(axis,angle);
                }
@@ -687,23 +690,23 @@
                
                        if (tokens.size()==6) // Quaternion is written as axis 
which norm is the angle in radian
                        {
-                               position[0]     = 
lexical_cast<RealType>(tokens[0]);
-                               position[1]     = 
lexical_cast<RealType>(tokens[1]);
-                               position[2]     = 
lexical_cast<RealType>(tokens[2]);
-                               axis[0]         = 
lexical_cast<RealType>(tokens[4]);
-                               axis[1]         = 
lexical_cast<RealType>(tokens[3]);
-                               axis[2]         = 
lexical_cast<RealType>(tokens[5]);
+                               position[0]     = 
lexical_cast_maybeNanInf<RealType>(tokens[0]);
+                               position[1]     = 
lexical_cast_maybeNanInf<RealType>(tokens[1]);
+                               position[2]     = 
lexical_cast_maybeNanInf<RealType>(tokens[2]);
+                               axis[0]         = 
lexical_cast_maybeNanInf<RealType>(tokens[4]);
+                               axis[1]         = 
lexical_cast_maybeNanInf<RealType>(tokens[3]);
+                               axis[2]         = 
lexical_cast_maybeNanInf<RealType>(tokens[5]);
                                angle           = axis.Normalize();
                        }
                        else // tokens.size()==7 Quaternion is writted as axis 
angle
                        {
-                               position[0]     = 
lexical_cast<RealType>(tokens[0]);
-                               position[1]     = 
lexical_cast<RealType>(tokens[1]);
-                               position[2]     = 
lexical_cast<RealType>(tokens[2]);
-                               axis[0]         = 
lexical_cast<RealType>(tokens[3]);
-                               axis[1]         = 
lexical_cast<RealType>(tokens[4]);
-                               axis[2]         = 
lexical_cast<RealType>(tokens[5]);
-                               angle           = 
lexical_cast<RealType>(tokens[6]);
+                               position[0]     = 
lexical_cast_maybeNanInf<RealType>(tokens[0]);
+                               position[1]     = 
lexical_cast_maybeNanInf<RealType>(tokens[1]);
+                               position[2]     = 
lexical_cast_maybeNanInf<RealType>(tokens[2]);
+                               axis[0]         = 
lexical_cast_maybeNanInf<RealType>(tokens[3]);
+                               axis[1]         = 
lexical_cast_maybeNanInf<RealType>(tokens[4]);
+                               axis[2]         = 
lexical_cast_maybeNanInf<RealType>(tokens[5]);
+                               angle           = 
lexical_cast_maybeNanInf<RealType>(tokens[6]);
                        }
                        orientation.FromAxisAngle(axis,angle);
                        *tmp = Se3<RealType>(position,orientation);

Modified: trunk/pkg/dem/PreProcessor/MembraneTest.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/MembraneTest.cpp 2008-10-29 10:31:21 UTC (rev 
1564)
+++ trunk/pkg/dem/PreProcessor/MembraneTest.cpp 2008-10-29 19:29:18 UTC (rev 
1565)
@@ -301,7 +301,7 @@
        
//interactionGeometryDispatcher->add("InteractingMyTetrahedron2InteractingBox4InteractionOfMyTetrahedron");
 
        shared_ptr<InteractingGeometryMetaEngine> interactingGeometryDispatcher 
= shared_ptr<InteractingGeometryMetaEngine>(new InteractingGeometryMetaEngine);
-       
//interactingGeometryDispatcher->add("ef2_BshTube_BssSweptSphereLineSegment_makeBssSweptSphereLineSegment");
+       
interactingGeometryDispatcher->add("ef2_BshTube_BssSweptSphereLineSegment_makeBssSweptSphereLineSegment");
        
        shared_ptr<BoundingVolumeMetaEngine> boundingVolumeDispatcher   = 
shared_ptr<BoundingVolumeMetaEngine>(new BoundingVolumeMetaEngine);
        boundingVolumeDispatcher->add("InteractingSphere2AABB"); // 

Modified: trunk/pkg/dem/PreProcessor/TriaxialTest.cpp
===================================================================
--- trunk/pkg/dem/PreProcessor/TriaxialTest.cpp 2008-10-29 10:31:21 UTC (rev 
1564)
+++ trunk/pkg/dem/PreProcessor/TriaxialTest.cpp 2008-10-29 19:29:18 UTC (rev 
1565)
@@ -94,7 +94,7 @@
        lowerCorner             = Vector3r(0,0,0);
        upperCorner             = Vector3r(1,1,1);
        thickness               = 0.001;
-       importFilename          = 
"../../YADE/trunk-clean/examples/sphere16bidisperse.txt"; // "./small.sdec.xyz";
+       importFilename          = ""; // oh, PLEASE, keep this empty -- i.e., 
by default, generate spheres in the box, not load them.
        Key                     ="";
        outputFileName          = "./TriaxialTest"+Key+".xml";
        //nlayers = 1;
@@ -260,6 +260,7 @@
        REGISTER_ATTRIBUTE(DieCompaction);
        REGISTER_ATTRIBUTE(translationspeed);
        REGISTER_ATTRIBUTE(wishedporosity);
+       REGISTER_ATTRIBUTE(fixedBoxDims);
  
 
 
@@ -301,9 +302,13 @@
 
        if(radiusMean<=0) 
really_radiusMean=pow(volume*(1-porosity)/(Mathr::PI*(4/3.)*numberOfGrains),1/3.);
        else {
-               Real 
boxScaleFactor=radiusMean*pow((4/3.)*Mathr::PI*numberOfGrains/(volume*(1-porosity)),1/3.);
-               LOG_INFO("Mean radius value of "<<radiusMean<<" requested, 
scaling box by "<<boxScaleFactor);
-               dimensions*=boxScaleFactor;
+               bool fixedDims[3];
+               fixedDims[0]=fixedBoxDims.find('x')!=string::npos; 
fixedDims[1]=fixedBoxDims.find('y')!=string::npos; 
fixedDims[2]=fixedBoxDims.find('z')!=string::npos;
+               int 
nScaled=(3-(int)fixedDims[0]+(int)fixedDims[1]+(int)fixedDims[2]);
+               if(nScaled==3) throw std::invalid_argument("At most 2 (not 3) 
axes can have fixed dimensions in fixedBoxDims if scaling for given 
radiusMean.");
+               Real 
boxScaleFactor=radiusMean*pow((4/3.)*Mathr::PI*numberOfGrains/(volume*(1-porosity)),1./nScaled);
+               LOG_INFO("Mean radius value of "<<radiusMean<<" requested, 
scaling "<<nScaled<<" dimensions by "<<boxScaleFactor);
+               dimensions[0]*=fixedDims[0]?1.:boxScaleFactor; 
dimensions[1]*=fixedDims[1]?1.:boxScaleFactor; 
dimensions[2]*=fixedDims[2]?1.:boxScaleFactor;
                upperCorner=lowerCorner+dimensions;
                really_radiusMean=radiusMean;
        }

Modified: trunk/pkg/dem/PreProcessor/TriaxialTest.hpp
===================================================================
--- trunk/pkg/dem/PreProcessor/TriaxialTest.hpp 2008-10-29 10:31:21 UTC (rev 
1564)
+++ trunk/pkg/dem/PreProcessor/TriaxialTest.hpp 2008-10-29 19:29:18 UTC (rev 
1565)
@@ -120,7 +120,9 @@
                string          importFilename
                                ,AnimationSnapshotsBaseName
                                ,WallStressRecordFile
-                               ,Key;//A code that is added to output filenames
+                               ,Key //A code that is added to output filenames
+                               //! string that contains some subset (max. 2) 
of {'x','y','z'} ; containes axes will have box dimension hardcoded, even if 
box is scaled as mean_radius is prescribed: scaling will be applied on the rest.
+                               ,fixedBoxDims;
        
                shared_ptr<TriaxialCompressionEngine> triaxialcompressionEngine;
                shared_ptr<TriaxialStressController> triaxialstressController;


_______________________________________________
Mailing list: https://launchpad.net/~yade-dev
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~yade-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to