/[escript]/branches/schroedinger/escript/src/Data.cpp
ViewVC logotype

Diff of /branches/schroedinger/escript/src/Data.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1900 by jfenwick, Mon Oct 20 05:13:24 2008 UTC revision 1901 by jfenwick, Wed Oct 22 02:44:34 2008 UTC
# Line 42  using namespace boost::python; Line 42  using namespace boost::python;
42  using namespace boost;  using namespace boost;
43  using namespace escript;  using namespace escript;
44    
45    // ensure the current object is not a DataLazy
46    #define FORCERESOLVE if (isLazy()) {resolve();}
47    
48  Data::Data()  Data::Data()
49  {  {
50    //    //
# Line 477  Data::setToZero() Line 480  Data::setToZero()
480    throw DataException("Error - Data can not be set to zero.");    throw DataException("Error - Data can not be set to zero.");
481  }  }
482    
483    
484    // This implementation of this operation should not need any special treatment of LazyData.
485  void  void
486  Data::copyWithMask(const Data& other,  Data::copyWithMask(const Data& other,
487                     const Data& mask)                     const Data& mask)
# Line 755  Data:: getValueOfDataPoint(int dataPoint Line 760  Data:: getValueOfDataPoint(int dataPoint
760  {  {
761    size_t length=0;    size_t length=0;
762    int i, j, k, l;    int i, j, k, l;
763    
764      FORCERESOLVE;
765    
766    //    //
767    // determine the rank and shape of each data point    // determine the rank and shape of each data point
768    int dataPointRank = getDataPointRank();    int dataPointRank = getDataPointRank();
# Line 848  Data::setValueOfDataPointToPyObject(int Line 856  Data::setValueOfDataPointToPyObject(int
856      // this will throw if the value cannot be represented      // this will throw if the value cannot be represented
857      boost::python::numeric::array num_array(py_object);      boost::python::numeric::array num_array(py_object);
858      setValueOfDataPointToArray(dataPointNo,num_array);      setValueOfDataPointToArray(dataPointNo,num_array);
   
   
859  }  }
860    
861  void  void
# Line 858  Data::setValueOfDataPointToArray(int dat Line 864  Data::setValueOfDataPointToArray(int dat
864    if (isProtected()) {    if (isProtected()) {
865          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
866    }    }
867      FORCERESOLVE;
868    //    //
869    // check rank    // check rank
870    if (num_array.getrank()<getDataPointRank())    if (num_array.getrank()<getDataPointRank())
# Line 891  Data::setValueOfDataPoint(int dataPointN Line 898  Data::setValueOfDataPoint(int dataPointN
898    }    }
899    //    //
900    // make sure data is expanded:    // make sure data is expanded:
901      FORCERESOLVE;
902    if (!isExpanded()) {    if (!isExpanded()) {
903      expand();      expand();
904    }    }
# Line 909  Data::getValueOfGlobalDataPoint(int proc Line 917  Data::getValueOfGlobalDataPoint(int proc
917  {  {
918    size_t length=0;    size_t length=0;
919    int i, j, k, l, pos;    int i, j, k, l, pos;
920      FORCERESOLVE;
921    //    //
922    // determine the rank and shape of each data point    // determine the rank and shape of each data point
923    int dataPointRank = getDataPointRank();    int dataPointRank = getDataPointRank();
# Line 2151  Data::setTaggedValueByName(std::string n Line 2160  Data::setTaggedValueByName(std::string n
2160                             const boost::python::object& value)                             const boost::python::object& value)
2161  {  {
2162       if (getFunctionSpace().getDomain()->isValidTagName(name)) {       if (getFunctionSpace().getDomain()->isValidTagName(name)) {
2163        FORCERESOLVE;
2164          int tagKey=getFunctionSpace().getDomain()->getTag(name);          int tagKey=getFunctionSpace().getDomain()->getTag(name);
2165          setTaggedValue(tagKey,value);          setTaggedValue(tagKey,value);
2166       }       }
# Line 2164  Data::setTaggedValue(int tagKey, Line 2174  Data::setTaggedValue(int tagKey,
2174    }    }
2175    //    //
2176    // Ensure underlying data object is of type DataTagged    // Ensure underlying data object is of type DataTagged
2177      FORCERESOLVE;
2178    if (isConstant()) tag();    if (isConstant()) tag();
   
2179    numeric::array asNumArray(value);    numeric::array asNumArray(value);
2180    
   
2181    // extract the shape of the numarray    // extract the shape of the numarray
2182    DataTypes::ShapeType tempShape;    DataTypes::ShapeType tempShape;
2183    for (int i=0; i < asNumArray.getrank(); i++) {    for (int i=0; i < asNumArray.getrank(); i++) {
2184      tempShape.push_back(extract<int>(asNumArray.getshape()[i]));      tempShape.push_back(extract<int>(asNumArray.getshape()[i]));
2185    }    }
2186    
   // get the space for the data vector  
 //   int len = DataTypes::noValues(tempShape);  
 //   DataVector temp_data(len, 0.0, len);  
 //   DataArrayView temp_dataView(temp_data, tempShape);  
 //   temp_dataView.copy(asNumArray);  
   
2187    DataVector temp_data2;    DataVector temp_data2;
2188    temp_data2.copyFromNumArray(asNumArray);    temp_data2.copyFromNumArray(asNumArray);
2189    
2190    //    m_data->setTaggedValue(tagKey,tempShape, temp_data2);
   // Call DataAbstract::setTaggedValue  
   //m_data->setTaggedValue(tagKey,temp_dataView);  
   
     m_data->setTaggedValue(tagKey,tempShape, temp_data2);  
2191  }  }
2192    
2193    
# Line 2203  Data::setTaggedValueFromCPP(int tagKey, Line 2202  Data::setTaggedValueFromCPP(int tagKey,
2202    }    }
2203    //    //
2204    // Ensure underlying data object is of type DataTagged    // Ensure underlying data object is of type DataTagged
2205      FORCERESOLVE;
2206    if (isConstant()) tag();    if (isConstant()) tag();
   
2207    //    //
2208    // Call DataAbstract::setTaggedValue    // Call DataAbstract::setTaggedValue
2209    m_data->setTaggedValue(tagKey,pointshape, value, dataOffset);    m_data->setTaggedValue(tagKey,pointshape, value, dataOffset);
# Line 2731  void Line 2730  void
2730  Data::dump(const std::string fileName) const  Data::dump(const std::string fileName) const
2731  {  {
2732    try    try
2733       {    {
2734          return m_data->dump(fileName);      if (isLazy())
2735       }      {
2736       catch (exception& e)        Data temp(*this); // this is to get a non-const object which we can resolve
2737       {        temp.resolve();
2738          temp.dump(fileName);
2739        }
2740        else
2741        {
2742              return m_data->dump(fileName);
2743        }
2744      }
2745      catch (exception& e)
2746      {
2747          cout << e.what() << endl;          cout << e.what() << endl;
2748       }    }
2749  }  }
2750    
2751  int  int

Legend:
Removed from v.1900  
changed lines
  Added in v.1901

  ViewVC Help
Powered by ViewVC 1.1.26