← Back to team overview

yade-dev team mailing list archive

[svn] r1843 - trunk/core

 

Author: richefeu
Date: 2009-07-07 16:26:59 +0200 (Tue, 07 Jul 2009)
New Revision: 1843

Modified:
   trunk/core/GroupRelationData.cpp
   trunk/core/GroupRelationData.hpp
   trunk/core/MetaBody.hpp
Log:
Add GroupRelationData serialization (not used yet in *Relationships classes)
This class serves to manage parameters between bodies depending on their groupMasks.
Here is an example of 'command stream' in xml file to set the parameters:
<grpRelationData _className_="GroupRelationData"  commands_="[ngrp 2 parameter kn setall kn 1e6]" />

It means that there are 2 groupMasks (0 and 1 by default). The parameter 'kn' is created and
its value is 1e6 between 0-0, 0-1, 1-0 and 1-1 body groupMasks. For other 'commands' see the sources.
(PS. scons will rebuild a lot of thinks due  to the modification of MetaBody. Sorry for that).




Modified: trunk/core/GroupRelationData.cpp
===================================================================
--- trunk/core/GroupRelationData.cpp	2009-07-07 13:01:34 UTC (rev 1842)
+++ trunk/core/GroupRelationData.cpp	2009-07-07 14:26:59 UTC (rev 1843)
@@ -10,17 +10,18 @@
 
 GroupRelationData::GroupRelationData() : ngrp_(2), npar_(0)
 { 
-        initActivator(); 
+  isActivated_ = false;
 }
 
 GroupRelationData::GroupRelationData(unsigned int ngrp) : ngrp_(ngrp), npar_(0)
 { 
-	initActivator();
+  isActivated_ = false;
 }
 
 GroupRelationData::~GroupRelationData() 
 {
   // Free memory for the action table
+/*
   if (act_ != 0)
     {
     for(unsigned int i=0 ; i<ngrp_ ; ++i)
@@ -30,7 +31,8 @@
     delete [] act_;
     act_ = 0;
     }
-  
+  */
+
   // Free memory for each parameter table
   for(unsigned int p=0 ; p<npar_ ; ++p)
     {
@@ -46,6 +48,14 @@
     }
 }
 
+// void GroupRelationData::activate()
+// {
+//   istringstream istr;
+//   istr.str(commands_);
+//   read(istr);
+// }
+
+/*
 bool GroupRelationData::act(unsigned int g1, unsigned int g2) const
 {
   if (g1 < ngrp_ && g2 < ngrp_)
@@ -77,6 +87,7 @@
   else
     cerr << "@GroupRelationData::deactivate, bad groupMask number" << endl;
 }
+*/
 
 bool GroupRelationData::exists(string name)
 {
@@ -186,6 +197,7 @@
   lpar_.push_back(p);
 }
 
+/*
 void GroupRelationData::initActivator()
 {
   act_ = new bool * [ngrp_];
@@ -199,11 +211,9 @@
     for (unsigned int j = 0 ; j < ngrp_ ; ++j)
       act_[i][j] = true;
 }
+*/
 
 
-// The methods read and write are not used in YADE...
-
-/*
 void GroupRelationData::read(istream & is)
 {
   string token;
@@ -215,14 +225,7 @@
       {
       is >> ngrp_;
       if (ngrp_ == 0) cerr << "GroupRelationData::read, ngrp can not be 0" << endl;
-      else initActivator();
       }
-    else if (token == "noact")
-      { 
-      unsigned int i,j; 
-      is >> i ; is >> j;
-      deactivate(i,j);
-      }
     else if (token == "parameter")
       { 
       if (ngrp_ == 0) cerr << "GroupRelationData::read, ngrp can not be 0" << endl;
@@ -256,20 +259,15 @@
     
     is >> token;
     }
+
+    if (ngrp_ > 0) isActivated_ = true;
 }
 
+/*
 void GroupRelationData::write(ostream & os)
 {
   os << "ngrp " << ngrp_ << endl;
-  
-  for (unsigned int g1=0;g1<ngrp_;++g1)
-    {
-    for (unsigned int g2=0;g2<ngrp_;++g2)  
-      {
-      if (!act_[g1][g2]) os << "noact " << g1 << " " << g2 << endl;
-      }
-    }
-  
+
   mapIdParam::iterator imap = idParam_.begin();
   string parName;
   while (imap != idParam_.end())
@@ -295,3 +293,33 @@
   
 }
 */
+
+void GroupRelationData::preProcessAttributes(bool deserializing)
+{
+  if(deserializing)
+  {
+    //
+  }
+}
+
+
+void GroupRelationData::postProcessAttributes(bool deserializing)
+{
+  if(deserializing)
+  {
+    string cmdstring = "";
+    for (unsigned int i = 0 ; i< commands_.size() ; ++i)
+      cmdstring = cmdstring + commands_[i] + " ";
+
+    istringstream istr;
+    istr.str(cmdstring);
+    
+    cout << istr.str() << endl;
+
+    read(istr);
+  }
+}
+
+
+
+

Modified: trunk/core/GroupRelationData.hpp
===================================================================
--- trunk/core/GroupRelationData.hpp	2009-07-07 13:01:34 UTC (rev 1842)
+++ trunk/core/GroupRelationData.hpp	2009-07-07 14:26:59 UTC (rev 1843)
@@ -8,31 +8,20 @@
 
 #pragma once
 
+#include<yade/lib-serialization/Serializable.hpp>
+
 #include <iostream>
+#include <sstream>
 #include <string>
 #include <map>
 #include <vector>
 
 using namespace std;
 
-//! \brief  Define the visibility and the parameters between groups of elements
+//! \brief  Define the parameters between groupMasks
 //! \author V. Richefeu
 
-// Note that the parameters of this class cannot be serialized yet
 
-
-// bool **act_
-// |
-// +------------------------------------+
-// |     |   1     2     4        ...   |  <---- groupMasks
-// | 1   |   YES   YES   YES      ...   |
-// | 2   |         NO    YES      ...   |
-// | 4   |  (SYM.)       YES      ...   |
-// | ... |                        ...   |
-// +------------------------------------+
-//   ^groupMasks 
-
-
 //  vector <double **> lpar_
 //  |
 //  |   +------------------------------------+
@@ -54,21 +43,21 @@
 //  |     ^groupMasks 
 //  ...
 
-class GroupRelationData
+class GroupRelationData : public Serializable
 {
   typedef map<string ,unsigned int > mapIdParam;
 
 private:
 
-  unsigned int ngrp_;                   // Number of groups
+  unsigned int ngrp_;                   // Number of groupMasks
   unsigned int npar_;                   // Number of parameters
 
   map <string ,unsigned int > idParam_; // Hash table for parameter identifiers
-  bool ** act_;                         // Table of visibility 
   vector <double **> lpar_;             // Table of parameter values
-// FIXME - the following should be better in particular for serialization (?)
-// vector<vector<bool> > act_;
-// vector<vector<vector<double> > > lpar_;
+
+  bool isActivated_;
+  //string commands_;
+  vector<string> commands_;
     
 public:
   
@@ -76,21 +65,8 @@
   GroupRelationData(unsigned int ngrp); 
   ~GroupRelationData();
   
-  //! Return true if the body with groupMask g1 'see' the body with groupMask g2
-  //! \param g1  First groupMask
-  //! \param g2  Second groupMask  
-  bool act(unsigned int g1, unsigned int g2) const;
+  //void activate();
 
-  //! Activate the visibility of the bodies with groupMasks g1 and g2
-  //! \param g1  First groupMask
-  //! \param g2  Second groupMask  
-  void activate(unsigned int g1, unsigned int g2);
-  
-  //! Deactivate the visibility of the groups with groupMasks g1 and g2
-  //! \param g1  First groupMask
-  //! \param g2  Second groupMask
-  void deactivate(unsigned int g1, unsigned int g2);
-  
   //! Return true if the parameter exist
   //! \param name  Parameter name 
   bool exists(string name);
@@ -121,15 +97,15 @@
   //! Add a new parameter
   void addParameter(string name);
   
-  //! 
-  void initActivator();
-  
-// Was used in the code gdm-tk, but not usefull in YADE
-/*
   void read(istream & is);  
   void write(ostream & os);
-*/
-  
 
+  REGISTER_ATTRIBUTES(/*no base*/,(commands_));
+  REGISTER_CLASS_AND_BASE(GroupRelationData,Serializable);
+ 
+  protected : virtual void preProcessAttributes  (bool deserializing);
+  public    : virtual void postProcessAttributes (bool deserializing);
 };
+REGISTER_SERIALIZABLE(GroupRelationData);
 
+

Modified: trunk/core/MetaBody.hpp
===================================================================
--- trunk/core/MetaBody.hpp	2009-07-07 13:01:34 UTC (rev 1842)
+++ trunk/core/MetaBody.hpp	2009-07-07 14:26:59 UTC (rev 1843)
@@ -15,7 +15,7 @@
 #include"Engine.hpp"
 #include"DisplayParameters.hpp"
 #include"BexContainer.hpp"
-//#include"groupRelationData.hpp"
+#include"GroupRelationData.hpp"
 
 class MetaBody : public Body
 {
@@ -37,7 +37,7 @@
 		//! "hash maps" of display parameters
 		vector<shared_ptr<DisplayParameters> > dispParams;
 
-		//shared_ptr<GroupRelationData>           grpRelationData;
+		shared_ptr<GroupRelationData>           grpRelationData;
 
 		MetaBody();
 
@@ -59,6 +59,7 @@
 		virtual void postProcessAttributes(bool deserializing);
 	REGISTER_ATTRIBUTES(Body,
 		(tags)
+		(grpRelationData)
 		(engines)
 		(initializers)
 		(bodies)




Follow ups