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

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

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

trunk/esys2/escript/src/Data/DataConstant.cpp revision 102 by jgs, Wed Dec 15 07:08:39 2004 UTC trunk/escript/src/Data/DataConstant.cpp revision 468 by jgs, Wed Jan 25 06:50:39 2006 UTC
# Line 15  Line 15 
15    
16  #include "escript/Data/DataConstant.h"  #include "escript/Data/DataConstant.h"
17  #include "escript/Data/DataException.h"  #include "escript/Data/DataException.h"
18  #include "esysUtils/EsysAssert.h"  #include "EsysAssert.h"
19    
20  #include <iostream>  #include <iostream>
21  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
# Line 32  DataConstant::DataConstant(const boost:: Line 32  DataConstant::DataConstant(const boost::
32    //    //
33    // copy the data in the correct format    // copy the data in the correct format
34    m_data=temp.getData();    m_data=temp.getData();
   DataArrayView tempView(m_data,temp.getView().getShape());  
35    //    //
36    // copy the view of the data    // create the view of the data
37      DataArrayView tempView(m_data,temp.getView().getShape());
38    setPointDataView(tempView);    setPointDataView(tempView);
39  }  }
40    
# Line 45  DataConstant::DataConstant(const DataArr Line 45  DataConstant::DataConstant(const DataArr
45    //    //
46    // copy the data in the correct format    // copy the data in the correct format
47    m_data=value.getData();    m_data=value.getData();
   DataArrayView tempView(m_data,value.getShape());  
48    //    //
49    // copy the view of the data    // create the view of the data
50      DataArrayView tempView(m_data,value.getShape());
51    setPointDataView(tempView);    setPointDataView(tempView);
52  }  }
53    
# Line 57  DataConstant::DataConstant(const DataCon Line 57  DataConstant::DataConstant(const DataCon
57    //    //
58    // copy the data in the correct format    // copy the data in the correct format
59    m_data=other.m_data;    m_data=other.m_data;
   DataArrayView tempView(m_data,other.getPointDataView().getShape());  
60    //    //
61    // copy the view of the data    // create the view of the data
62      DataArrayView tempView(m_data,other.getPointDataView().getShape());
63    setPointDataView(tempView);    setPointDataView(tempView);
64  }  }
65    
# Line 72  DataConstant::DataConstant(const DataCon Line 72  DataConstant::DataConstant(const DataCon
72    DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));    DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));
73    //    //
74    // allocate space for this new DataConstant's data    // allocate space for this new DataConstant's data
75    m_data.resize(DataArrayView::noValues(shape));    int len = DataArrayView::noValues(shape);
76      m_data.resize(len,0.,len);
77    //    //
78    // create a view of the data with the correct shape    // create a view of the data with the correct shape
79    DataArrayView tempView(m_data,shape);    DataArrayView tempView(m_data,shape);
80    // copy the data from the slice to the temp view    DataArrayView::RegionLoopRangeType region_loop_range=getSliceRegionLoopRange(region);
   tempView.copySlice(other.getPointDataView(),region);  
81    //    //
82    // store the temp view of the data in this object    // load the view with the data from the slice
83      tempView.copySlice(other.getPointDataView(),region_loop_range);
84      setPointDataView(tempView);
85    }
86    
87    DataConstant::DataConstant(const FunctionSpace& what,
88                               const DataArrayView::ShapeType &shape,
89                               const DataArrayView::ValueType &data)
90      : DataAbstract(what)
91    {
92      //
93      // copy the data in the correct format
94      m_data=data;
95      //
96      // create the view of the data
97      DataArrayView tempView(m_data,shape);
98    setPointDataView(tempView);    setPointDataView(tempView);
99  }  }
100    
# Line 95  DataConstant::getPointOffset(int sampleN Line 110  DataConstant::getPointOffset(int sampleN
110  {  {
111    EsysAssert((validSamplePointNo(dataPointNo) && validSampleNo(sampleNo)),    EsysAssert((validSamplePointNo(dataPointNo) && validSampleNo(sampleNo)),
112                "Invalid index, sampleNo: " << sampleNo << " dataPointNo: " << dataPointNo);                "Invalid index, sampleNo: " << sampleNo << " dataPointNo: " << dataPointNo);
113      //
114      // Whatever the coord's always return the same value as this is constant data.
115    return 0;    return 0;
116  }  }
117    
# Line 129  DataConstant::setSlice(const DataAbstrac Line 146  DataConstant::setSlice(const DataAbstrac
146    if (tempDataConst==0) {    if (tempDataConst==0) {
147      throw DataException("Programming error - casting to DataConstant.");      throw DataException("Programming error - casting to DataConstant.");
148    }    }
149    getPointDataView().copySliceFrom(tempDataConst->getPointDataView(),region);    //
150      DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));
151      DataArrayView::RegionLoopRangeType region_loop_range=getSliceRegionLoopRange(region);
152      //
153      // check shape:
154      if (getPointDataView().getRank()!=region.size()) {
155        throw DataException("Error - Invalid slice region.");
156      }
157      if (tempDataConst->getPointDataView().getRank()>0 and !value->getPointDataView().checkShape(shape)) {
158        throw DataException (value->getPointDataView().createShapeErrorMessage(
159                    "Error - Couldn't copy slice due to shape mismatch.",shape));
160      }
161      //
162      getPointDataView().copySliceFrom(tempDataConst->getPointDataView(),region_loop_range);
163  }  }
164    
165  void  void
# Line 141  DataConstant::reshapeDataPoint(const Dat Line 171  DataConstant::reshapeDataPoint(const Dat
171           << "This Data has data points with rank: " << getPointDataView().getRank();           << "This Data has data points with rank: " << getPointDataView().getRank();
172      throw DataException(temp.str());      throw DataException(temp.str());
173    }    }
174    m_data.resize(DataArrayView::noValues(shape),getPointDataView()());    int len = DataArrayView::noValues(shape);
175      m_data.resize(len,getPointDataView()(),len);
176    DataArrayView newView(m_data,shape);    DataArrayView newView(m_data,shape);
177    setPointDataView(newView);    setPointDataView(newView);
178  }  }
179    
180    int
181    DataConstant::archiveData(ofstream& archiveFile,
182                              const DataArrayView::ValueType::size_type noValues) const
183    {
184      return(m_data.archiveData(archiveFile, noValues));
185    }
186    
187    int
188    DataConstant::extractData(ifstream& archiveFile,
189                              const DataArrayView::ValueType::size_type noValues)
190    {
191      return(m_data.extractData(archiveFile, noValues));
192    }
193    
194  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.102  
changed lines
  Added in v.468

  ViewVC Help
Powered by ViewVC 1.1.26