/[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/DataConstant.cpp revision 854 by gross, Thu Sep 21 05:29:42 2006 UTC
# Line 1  Line 1 
1  //$Id$  //$Id$
2  /*  /*
3   ******************************************************************************   ************************************************************
4   *                                                                            *   *          Copyright 2006 by ACcESS MNRF                   *
5   *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *   *                                                          *
6   *                                                                            *   *              http://www.access.edu.au                    *
7   * This software is the property of ACcESS. No part of this code              *   *       Primary Business: Queensland, Australia            *
8   * may be copied in any form or by any means without the expressed written    *   *  Licensed under the Open Software License version 3.0    *
9   * consent of ACcESS.  Copying, use or modification of this software          *   *     http://www.opensource.org/licenses/osl-3.0.php       *
10   * by any unauthorised person is illegal unless that person has a software    *   *                                                          *
11   * license agreement with ACcESS.                                             *   ************************************************************
  *                                                                            *  
  ******************************************************************************  
12  */  */
13    
14  #include "escript/Data/DataConstant.h"  #include "DataConstant.h"
15  #include "escript/Data/DataException.h"  #include "DataException.h"
16  #include "esysUtils/EsysAssert.h"  #include "esysUtils/EsysAssert.h"
17    
18  #include <iostream>  #include <iostream>
# Line 32  DataConstant::DataConstant(const boost:: Line 30  DataConstant::DataConstant(const boost::
30    //    //
31    // copy the data in the correct format    // copy the data in the correct format
32    m_data=temp.getData();    m_data=temp.getData();
   DataArrayView tempView(m_data,temp.getView().getShape());  
33    //    //
34    // copy the view of the data    // create the view of the data
35      DataArrayView tempView(m_data,temp.getView().getShape());
36    setPointDataView(tempView);    setPointDataView(tempView);
37  }  }
38    
# Line 45  DataConstant::DataConstant(const DataArr Line 43  DataConstant::DataConstant(const DataArr
43    //    //
44    // copy the data in the correct format    // copy the data in the correct format
45    m_data=value.getData();    m_data=value.getData();
   DataArrayView tempView(m_data,value.getShape());  
46    //    //
47    // copy the view of the data    // create the view of the data
48      DataArrayView tempView(m_data,value.getShape());
49    setPointDataView(tempView);    setPointDataView(tempView);
50  }  }
51    
# Line 57  DataConstant::DataConstant(const DataCon Line 55  DataConstant::DataConstant(const DataCon
55    //    //
56    // copy the data in the correct format    // copy the data in the correct format
57    m_data=other.m_data;    m_data=other.m_data;
   DataArrayView tempView(m_data,other.getPointDataView().getShape());  
58    //    //
59    // copy the view of the data    // create the view of the data
60      DataArrayView tempView(m_data,other.getPointDataView().getShape());
61    setPointDataView(tempView);    setPointDataView(tempView);
62  }  }
63    
# Line 72  DataConstant::DataConstant(const DataCon Line 70  DataConstant::DataConstant(const DataCon
70    DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));    DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));
71    //    //
72    // allocate space for this new DataConstant's data    // allocate space for this new DataConstant's data
73    m_data.resize(DataArrayView::noValues(shape));    int len = DataArrayView::noValues(shape);
74      m_data.resize(len,0.,len);
75    //    //
76    // create a view of the data with the correct shape    // create a view of the data with the correct shape
77    DataArrayView tempView(m_data,shape);    DataArrayView tempView(m_data,shape);
78    // copy the data from the slice to the temp view    DataArrayView::RegionLoopRangeType region_loop_range=getSliceRegionLoopRange(region);
79    tempView.copySlice(other.getPointDataView(),region);    //
80      // load the view with the data from the slice
81      tempView.copySlice(other.getPointDataView(),region_loop_range);
82      setPointDataView(tempView);
83    }
84    
85    DataConstant::DataConstant(const FunctionSpace& what,
86                               const DataArrayView::ShapeType &shape,
87                               const DataArrayView::ValueType &data)
88      : DataAbstract(what)
89    {
90    //    //
91    // store the temp view of the data in this object    // copy the data in the correct format
92      m_data=data;
93      //
94      // create the view of the data
95      DataArrayView tempView(m_data,shape);
96    setPointDataView(tempView);    setPointDataView(tempView);
97  }  }
98    
# Line 95  DataConstant::getPointOffset(int sampleN Line 108  DataConstant::getPointOffset(int sampleN
108  {  {
109    EsysAssert((validSamplePointNo(dataPointNo) && validSampleNo(sampleNo)),    EsysAssert((validSamplePointNo(dataPointNo) && validSampleNo(sampleNo)),
110                "Invalid index, sampleNo: " << sampleNo << " dataPointNo: " << dataPointNo);                "Invalid index, sampleNo: " << sampleNo << " dataPointNo: " << dataPointNo);
111      //
112      // Whatever the coord's always return the same value as this is constant data.
113    return 0;    return 0;
114  }  }
115    
# Line 129  DataConstant::setSlice(const DataAbstrac Line 144  DataConstant::setSlice(const DataAbstrac
144    if (tempDataConst==0) {    if (tempDataConst==0) {
145      throw DataException("Programming error - casting to DataConstant.");      throw DataException("Programming error - casting to DataConstant.");
146    }    }
147    getPointDataView().copySliceFrom(tempDataConst->getPointDataView(),region);    //
148      DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));
149      DataArrayView::RegionLoopRangeType region_loop_range=getSliceRegionLoopRange(region);
150      //
151      // check shape:
152      if (getPointDataView().getRank()!=region.size()) {
153        throw DataException("Error - Invalid slice region.");
154      }
155      if (tempDataConst->getPointDataView().getRank()>0 && !value->getPointDataView().checkShape(shape)) {
156        throw DataException (value->getPointDataView().createShapeErrorMessage(
157                    "Error - Couldn't copy slice due to shape mismatch.",shape));
158      }
159      //
160      getPointDataView().copySliceFrom(tempDataConst->getPointDataView(),region_loop_range);
161    }
162    
163    int
164    DataConstant::archiveData(ofstream& archiveFile,
165                              const DataArrayView::ValueType::size_type noValues) const
166    {
167      return(m_data.archiveData(archiveFile, noValues));
168    }
169    
170    int
171    DataConstant::extractData(ifstream& archiveFile,
172                              const DataArrayView::ValueType::size_type noValues)
173    {
174      return(m_data.extractData(archiveFile, noValues));
175  }  }
176    
177  void  void
178  DataConstant::reshapeDataPoint(const DataArrayView::ShapeType& shape)  DataConstant::symmetric(DataAbstract* ev)
179  {  {
180    if (getPointDataView().getRank()!=0) {    DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
181      stringstream temp;    if (temp_ev==0) {
182      temp << "Error - Can only reshape Data with data points of rank 0. "      throw DataException("Error - DataConstant::symmetric: casting to DataConstant failed (propably a programming error).");
          << "This Data has data points with rank: " << getPointDataView().getRank();  
     throw DataException(temp.str());  
183    }    }
184    m_data.resize(DataArrayView::noValues(shape),getPointDataView()());    DataArrayView& thisView=getPointDataView();
185    DataArrayView newView(m_data,shape);    DataArrayView& evView=ev->getPointDataView();
186    setPointDataView(newView);    DataArrayView::symmetric(thisView,0,evView,0);
187  }  }
188    
189    void
190    DataConstant::nonsymmetric(DataAbstract* ev)
191    {
192      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
193      if (temp_ev==0) {
194        throw DataException("Error - DataConstant::nonsymmetric: casting to DataConstant failed (propably a programming error).");
195      }
196      DataArrayView& thisView=getPointDataView();
197      DataArrayView& evView=ev->getPointDataView();
198      DataArrayView::nonsymmetric(thisView,0,evView,0);
199    }
200    
201    void
202    DataConstant::trace(DataAbstract* ev, int axis_offset)
203    {
204      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
205      if (temp_ev==0) {
206        throw DataException("Error - DataConstant::trace: casting to DataConstant failed (propably a programming error).");
207      }
208      DataArrayView& thisView=getPointDataView();
209      DataArrayView& evView=ev->getPointDataView();
210      DataArrayView::trace(thisView,0,evView,0,axis_offset);
211    }
212    
213    void
214    DataConstant::swapaxes(DataAbstract* ev, int axis0, int axis1)
215    {
216      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
217      if (temp_ev==0) {
218        throw DataException("Error - DataConstant::swapaxes: casting to DataConstant failed (propably a programming error).");
219      }
220      DataArrayView& thisView=getPointDataView();
221      DataArrayView& evView=ev->getPointDataView();
222      DataArrayView::swapaxes(thisView,0,evView,0,axis0,axis1);
223    }
224    
225    void
226    DataConstant::transpose(DataAbstract* ev, int axis_offset)
227    {
228      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
229      if (temp_ev==0) {
230        throw DataException("Error - DataConstant::transpose: casting to DataConstant failed (propably a programming error).");
231      }
232      DataArrayView& thisView=getPointDataView();
233      DataArrayView& evView=ev->getPointDataView();
234      DataArrayView::transpose(thisView,0,evView,0,axis_offset);
235    }
236    
237    void
238    DataConstant::eigenvalues(DataAbstract* ev)
239    {
240      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
241      if (temp_ev==0) {
242        throw DataException("Error - DataConstant::eigenvalues: casting to DataConstant failed (propably a programming error).");
243      }
244      DataArrayView& thisView=getPointDataView();
245      DataArrayView& evView=ev->getPointDataView();
246      DataArrayView::eigenvalues(thisView,0,evView,0);
247    }
248    void
249    DataConstant::eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol)
250    {
251      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
252      if (temp_ev==0) {
253        throw DataException("Error - DataConstant::eigenvalues_and_eigenvectors: casting to DataConstant failed (propably a programming error).");
254      }
255      DataConstant* temp_V=dynamic_cast<DataConstant*>(V);
256      if (temp_V==0) {
257        throw DataException("Error - DataConstant::eigenvalues_and_eigenvectors: casting to DataConstant failed (propably a programming error).");
258      }
259      DataArrayView thisView=getPointDataView();
260      DataArrayView evView=ev->getPointDataView();
261      DataArrayView VView=V->getPointDataView();
262    
263      DataArrayView::eigenvalues_and_eigenvectors(thisView,0,evView,0,VView,tol);
264    }
265    
266    
267  }  // end of namespace  }  // end of namespace

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

  ViewVC Help
Powered by ViewVC 1.1.26