/[escript]/trunk/escript/src/Data.cpp
ViewVC logotype

Diff of /trunk/escript/src/Data.cpp

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

revision 1318 by ksteube, Mon Sep 24 06:18:44 2007 UTC revision 1319 by matt, Thu Sep 27 00:27:51 2007 UTC
# Line 19  Line 19 
19  #include "DataConstant.h"  #include "DataConstant.h"
20  #include "DataTagged.h"  #include "DataTagged.h"
21  #include "DataEmpty.h"  #include "DataEmpty.h"
 #include "DataArray.h"  
22  #include "DataArrayView.h"  #include "DataArrayView.h"
23  #include "FunctionSpaceFactory.h"  #include "FunctionSpaceFactory.h"
24  #include "AbstractContinuousDomain.h"  #include "AbstractContinuousDomain.h"
# Line 61  Data::Data(double value, Line 60  Data::Data(double value,
60    for (int i = 0; i < shape.attr("__len__")(); ++i) {    for (int i = 0; i < shape.attr("__len__")(); ++i) {
61      dataPointShape.push_back(extract<const int>(shape[i]));      dataPointShape.push_back(extract<const int>(shape[i]));
62    }    }
63    DataArray temp(dataPointShape,value);  
64    initialise(temp.getView(),what,expanded);    int len = DataArrayView::noValues(dataPointShape);
65      DataVector temp_data(len,value,len);
66      DataArrayView temp_dataView(temp_data, dataPointShape);
67    
68      initialise(temp_dataView, what, expanded);
69    
70    m_protected=false;    m_protected=false;
71  }  }
72    
# Line 71  Data::Data(double value, Line 75  Data::Data(double value,
75         const FunctionSpace& what,         const FunctionSpace& what,
76             bool expanded)             bool expanded)
77  {  {
78    DataArray temp(dataPointShape,value);    int len = DataArrayView::noValues(dataPointShape);
79    initialise(temp.getView(),what,expanded);  
80      DataVector temp_data(len,value,len);
81      DataArrayView temp_dataView(temp_data, dataPointShape);
82    
83      initialise(temp_dataView, what, expanded);
84    
85    m_protected=false;    m_protected=false;
86  }  }
87    
# Line 155  Data::Data(const object& value, Line 164  Data::Data(const object& value,
164    m_protected=false;    m_protected=false;
165  }  }
166    
167    
168  Data::Data(const object& value,  Data::Data(const object& value,
169             const Data& other)             const Data& other)
170  {  {
171    
172      numeric::array asNumArray(value);
173    
174    
175      // extract the shape of the numarray
176      DataArrayView::ShapeType tempShape;
177      for (int i=0; i < asNumArray.getrank(); i++) {
178        tempShape.push_back(extract<int>(asNumArray.getshape()[i]));
179      }
180      // get the space for the data vector
181      int len = DataArrayView::noValues(tempShape);
182      DataVector temp_data(len, 0.0, len);
183      DataArrayView temp_dataView(temp_data, tempShape);
184      temp_dataView.copy(asNumArray);
185    
186    //    //
187    // Create DataConstant using the given value and all other parameters    // Create DataConstant using the given value and all other parameters
188    // copied from other. If value is a rank 0 object this Data    // copied from other. If value is a rank 0 object this Data
189    // will assume the point data shape of other.    // will assume the point data shape of other.
190    DataArray temp(value);  
191    if (temp.getView().getRank()==0) {    if (temp_dataView.getRank()==0) {
192      //      int len = DataArrayView::noValues(other.getPointDataView().getShape());
193      // Create a DataArray with the scalar value for all elements  
194      DataArray temp2(other.getPointDataView().getShape(),temp.getView()());      DataVector temp2_data(len, temp_dataView(), len);
195      initialise(temp2.getView(),other.getFunctionSpace(),false);      DataArrayView temp2_dataView(temp_data, other.getPointDataView().getShape());
196        initialise(temp2_dataView, other.getFunctionSpace(), false);
197    
198    } else {    } else {
199      //      //
200      // Create a DataConstant with the same sample shape as other      // Create a DataConstant with the same sample shape as other
201      initialise(temp.getView(),other.getFunctionSpace(),false);      initialise(temp_dataView, other.getFunctionSpace(), false);
202    }    }
203    m_protected=false;    m_protected=false;
204  }  }
# Line 1795  Data::setTaggedValue(int tagKey, Line 1822  Data::setTaggedValue(int tagKey,
1822      throw DataException("Error - DataTagged conversion failed!!");      throw DataException("Error - DataTagged conversion failed!!");
1823    }    }
1824    
1825    //    numeric::array asNumArray(value);
1826    // Construct DataArray from boost::python::object input value  
1827    DataArray valueDataArray(value);  
1828      // extract the shape of the numarray
1829      DataArrayView::ShapeType tempShape;
1830      for (int i=0; i < asNumArray.getrank(); i++) {
1831        tempShape.push_back(extract<int>(asNumArray.getshape()[i]));
1832      }
1833    
1834      // get the space for the data vector
1835      int len = DataArrayView::noValues(tempShape);
1836      DataVector temp_data(len, 0.0, len);
1837      DataArrayView temp_dataView(temp_data, tempShape);
1838      temp_dataView.copy(asNumArray);
1839    
1840    //    //
1841    // Call DataAbstract::setTaggedValue    // Call DataAbstract::setTaggedValue
1842    m_data->setTaggedValue(tagKey,valueDataArray.getView());    m_data->setTaggedValue(tagKey,temp_dataView);
1843  }  }
1844    
1845  void  void

Legend:
Removed from v.1318  
changed lines
  Added in v.1319

  ViewVC Help
Powered by ViewVC 1.1.26