Salome HOME
files forgotten on previous comit
authorLauffenburger Thomas <thomas.lauffenburger@edf.fr>
Mon, 18 Sep 2017 14:10:03 +0000 (16:10 +0200)
committerLauffenburger Thomas <thomas.lauffenburger@edf.fr>
Mon, 18 Sep 2017 14:10:03 +0000 (16:10 +0200)
src/engine/ComplexWeight.cxx [new file with mode: 0644]
src/engine/ComplexWeight.hxx [new file with mode: 0644]
src/yacsloader_swig/Test/testHPDecorator.py

diff --git a/src/engine/ComplexWeight.cxx b/src/engine/ComplexWeight.cxx
new file mode 100644 (file)
index 0000000..a55f454
--- /dev/null
@@ -0,0 +1,154 @@
+// Copyright (C) 2006-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "ComplexWeight.hxx"
+
+#include "Exception.hxx"
+
+using namespace YACS::ENGINE;
+
+ComplexWeight::ComplexWeight()
+{
+  setToZero();
+}
+
+ComplexWeight::ComplexWeight(double elementaryWeight, double loopWeight, int nbCoresByIteration): _elementaryWeight(elementaryWeight), _bootWeight(false)
+{
+  _loopWeight.push_back(std::pair<double,int>(loopWeight,nbCoresByIteration));
+}
+
+double ComplexWeight::getSimpleLoopWeight() const
+{
+  if(_loopWeight.size()!=1)
+    throw Exception("ComplexWeight::getSimpleLoopWeight : can not get loop weight. Node contain multiple loop weights!");
+  return (*(_loopWeight.begin())).first;
+}
+
+double ComplexWeight::calculateTotalLength(int nbOfCoresAllocated) const
+{
+  if (isDefaultValue())
+    throw Exception("ComplexWeight::calculateTotalLength : can not calculate total weight with default value!");
+  double totalWeight(0);
+  if (hasValidElementaryWeight())
+    totalWeight+=_elementaryWeight;
+  for(std::vector< std::pair<double,int> >::const_iterator it=_loopWeight.begin();it!=_loopWeight.end();it++)
+    {
+      if ((*it).second>0)
+        totalWeight+=(*it).first*((double)(*it).second)/((double)nbOfCoresAllocated);
+       }
+  return totalWeight;
+}
+
+void ComplexWeight::setLoopWeight(double loopWeight, int nbCoresByIteration) 
+{
+  bool found(false);
+  int i(0), rankFound(0);
+  _bootWeight=false;
+  for(std::vector<std::pair<double,int> >::const_iterator it=_loopWeight.begin();it!=_loopWeight.end();it++,i++)
+    {
+      if ((*it).second==nbCoresByIteration)
+        {
+          found=true;
+          rankFound=i;
+        }
+        
+    }
+  if (found)
+    _loopWeight.erase(_loopWeight.begin()+rankFound);
+  _loopWeight.push_back(std::pair<double,int>(loopWeight,nbCoresByIteration));
+  if ((_loopWeight.size()>1) && ((*(_loopWeight.begin())).second==-1))
+    _loopWeight.erase(_loopWeight.begin());  
+}
+
+int ComplexWeight::getNbCoresConsoLoopMax() const
+{
+  int nbCoresPerShotLoopMax(0);
+  for(std::vector< std::pair<double,int> >::const_iterator it=_loopWeight.begin();it!=_loopWeight.end();it++)
+    if ((*it).second>nbCoresPerShotLoopMax)nbCoresPerShotLoopMax=(*it).second;
+  return nbCoresPerShotLoopMax;
+}
+
+void ComplexWeight::max(ComplexWeight &other)
+{
+  _elementaryWeight=std::max(_elementaryWeight,other._elementaryWeight);
+  
+  double allLoopWeight1(0);
+  double allLoopWeight2(0);
+  for(std::vector< std::pair<double,int> >::const_iterator it=_loopWeight.begin();it!=_loopWeight.end();it++)
+    {
+      if (((*it).first>0) && ((*it).second>0))
+        allLoopWeight1+=(*it).first * (*it).second;
+    }
+  for(std::vector< std::pair<double,int> >::const_iterator it=other._loopWeight.begin();it!=other._loopWeight.end();it++)
+    {
+      if (((*it).first>0) && ((*it).second>0))
+        allLoopWeight2+=(*it).first * (*it).second;
+    }
+  if (allLoopWeight2>allLoopWeight1)
+    _loopWeight=other._loopWeight;  
+}
+
+ComplexWeight& ComplexWeight::addWeight(const ComplexWeight *other)
+{
+  bool found;
+  if ((!_bootWeight) && ((other->isUnsetLoopWeight() && this->isDefaultValueLoop()) || (this->isUnsetLoopWeight() && other->isDefaultValueLoop())))
+    this->unsetLoop();
+  else
+    {
+         for(std::vector< std::pair<double,int> >::const_iterator it=other->_loopWeight.begin();it!=other->_loopWeight.end();it++)
+           {
+             found=false;
+             for(std::vector< std::pair<double,int> >::iterator it2=_loopWeight.begin();it2!=_loopWeight.end();it2++)  
+               {
+                 if ((*it).second == (*it2).second)
+                   {
+                     if (((*it2).first>=0) && ((*it).first>=0))
+                       this->setLoopWeight((*it2).first+(*it).first, (*it2).second);
+                     else if ((*it).first>=0)
+                       this->setLoopWeight((*it).first, (*it2).second);
+                     found=true;
+                     continue;
+                   }            
+               }
+             if ((!found) && ((*it).second!=-1))
+               this->setLoopWeight((*it).first, (*it).second);
+           }
+         if ((_loopWeight.size()>1) && ((*(_loopWeight.begin())).second==-1))
+           _loopWeight.erase(_loopWeight.begin());
+       }
+
+  if ((!_bootWeight) && ((other->isUnsetElementaryWeight() && this->isDefaultValueElementary()) || (this->isUnsetElementaryWeight() && other->isDefaultValueElementary())))
+    this->unsetElementary();
+  else
+    {
+         if (other->hasValidElementaryWeight())
+           {
+             if (hasValidElementaryWeight())
+               _elementaryWeight+=other->_elementaryWeight;
+             else
+               _elementaryWeight=other->_elementaryWeight;
+           }
+    }
+  if (!other->_bootWeight)
+    _bootWeight=false;
+}
+
+
+
+
diff --git a/src/engine/ComplexWeight.hxx b/src/engine/ComplexWeight.hxx
new file mode 100644 (file)
index 0000000..872fe0f
--- /dev/null
@@ -0,0 +1,82 @@
+// Copyright (C) 2006-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef __COMPLEXWEIGHT_HXX__
+#define __COMPLEXWEIGHT_HXX__
+
+#include <vector>
+
+namespace YACS
+{
+  namespace ENGINE
+  {
+    class ComplexWeight
+    {
+    public:
+      ComplexWeight();
+      ComplexWeight(double elementaryWeight, double loopWeight, int nbCoresByIteration);
+      ComplexWeight(const ComplexWeight& other) {_bootWeight=other._bootWeight; _loopWeight=other._loopWeight; _elementaryWeight=other._elementaryWeight;}
+      ~ComplexWeight() {};
+      std::vector<std::pair<double,int> > getLoopWeight() const {return _loopWeight;}
+      double getSimpleLoopWeight() const;
+      double getElementaryWeight() const {return _elementaryWeight;}
+      double calculateTotalLength(int nbOfCoresAllocated) const;
+      void setDefaultElementary() {setToZero(); setLoopWeight(0.,0);}
+      void setDefaultLoop() {setToZero(); setElementaryWeight(0.);}
+      bool isDefaultValue() const { return ((isDefaultValueElementary()) && (isDefaultValueLoop()));}
+      bool isUnsetLoopWeight() const {return ((*(_loopWeight.begin())).second==0);}
+      bool isUnsetElementaryWeight() const {return (_elementaryWeight==0);}
+      bool hasValidLoopWeight() const { return (((*(_loopWeight.begin())).first>0) && ((*(_loopWeight.begin())).second!=-1));}
+      bool hasValidElementaryWeight() const { return (_elementaryWeight>=0);}
+      void setLoopWeight(double loopWeight, int nbCoresByIteration);
+      void setElementaryWeight(double elementaryWeight) {_bootWeight=false; _elementaryWeight=elementaryWeight;}
+      void setToZero() {_bootWeight=true; unsetElementary(); unsetLoop(); }
+      int getNbCoresConsoLoopMax() const;
+      void max(ComplexWeight &other);
+      ComplexWeight& addWeight(const ComplexWeight *other);
+    protected:
+      bool _bootWeight;
+      // _loopWeight: vect<pair(weight,nbcorePerIteration)>, for first element of vector: nbcorePerIteration<0 -> unset, nbcorePerIteration==0 -> no loopweight
+      std::vector<std::pair<double,int> > _loopWeight; 
+      double _elementaryWeight;
+    private:
+      void unsetLoop() {_loopWeight.clear(); _loopWeight.push_back(std::pair<double,int>(-1.,-1));}
+      void unsetElementary(){_elementaryWeight=-1.;}
+      bool isDefaultValueLoop() const {return ((*(_loopWeight.begin())).second==-1);}
+      bool isDefaultValueElementary() const {return (_elementaryWeight<0);}
+    };
+  }
+}
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
index 717654e442c6007dabbf503751d8935fe929d9d7..2aec239c0465bd8c3049c7e64aa16ac9fe320bcc 100644 (file)
@@ -502,7 +502,7 @@ class TestHPDecortator(unittest.TestCase):
         n1_0_1sc.setContainer(hp4)
         w=pilot.ComplexWeight()
         b0.getWeightRegardingDPL(w)
         n1_0_1sc.setContainer(hp4)
         w=pilot.ComplexWeight()
         b0.getWeightRegardingDPL(w)
-        assert(w.getElementaryWeight()==0.)
+        assert(w.getElementaryWeight()==-1.)
         assert(w.calculateTotalLength(4)==30.)
         assert(w.calculateTotalLength(8)==15.)
         pg.setData([("m0",120)])
         assert(w.calculateTotalLength(4)==30.)
         assert(w.calculateTotalLength(8)==15.)
         pg.setData([("m0",120)])