/[escript]/branches/lapack2681/escript/src/DataConstant.cpp
ViewVC logotype

Annotation of /branches/lapack2681/escript/src/DataConstant.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 122 - (hide annotations)
Thu Jun 9 05:38:05 2005 UTC (14 years, 1 month ago) by jgs
Original Path: trunk/esys2/escript/src/Data/DataConstant.cpp
File size: 5821 byte(s)
Merge of development branch back to main trunk on 2005-06-09

1 jgs 102 //$Id$
2 jgs 82 /*
3     ******************************************************************************
4     * *
5     * COPYRIGHT ACcESS 2004 - All Rights Reserved *
6     * *
7     * This software is the property of ACcESS. No part of this code *
8     * may be copied in any form or by any means without the expressed written *
9     * consent of ACcESS. Copying, use or modification of this software *
10     * by any unauthorised person is illegal unless that person has a software *
11     * license agreement with ACcESS. *
12     * *
13     ******************************************************************************
14     */
15    
16     #include "escript/Data/DataConstant.h"
17     #include "escript/Data/DataException.h"
18     #include "esysUtils/EsysAssert.h"
19    
20     #include <iostream>
21     #include <boost/python/extract.hpp>
22    
23     using namespace std;
24    
25     namespace escript {
26    
27 jgs 102 DataConstant::DataConstant(const boost::python::numeric::array& value,
28     const FunctionSpace& what)
29     : DataAbstract(what)
30     {
31     DataArray temp(value);
32     //
33     // copy the data in the correct format
34     m_data=temp.getData();
35 jgs 119 //
36     // create the view of the data
37 jgs 102 DataArrayView tempView(m_data,temp.getView().getShape());
38     setPointDataView(tempView);
39     }
40 jgs 82
41 jgs 102 DataConstant::DataConstant(const DataArrayView& value,
42     const FunctionSpace& what)
43     : DataAbstract(what)
44     {
45     //
46     // copy the data in the correct format
47     m_data=value.getData();
48 jgs 119 //
49     // create the view of the data
50 jgs 102 DataArrayView tempView(m_data,value.getShape());
51     setPointDataView(tempView);
52     }
53 jgs 82
54 jgs 102 DataConstant::DataConstant(const DataConstant& other)
55     : DataAbstract(other.getFunctionSpace())
56     {
57     //
58     // copy the data in the correct format
59     m_data=other.m_data;
60 jgs 119 //
61     // create the view of the data
62 jgs 102 DataArrayView tempView(m_data,other.getPointDataView().getShape());
63     setPointDataView(tempView);
64     }
65 jgs 82
66 jgs 102 DataConstant::DataConstant(const DataConstant& other,
67     const DataArrayView::RegionType& region)
68     : DataAbstract(other.getFunctionSpace())
69     {
70     //
71     // get the shape of the slice to copy from
72     DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));
73     //
74     // allocate space for this new DataConstant's data
75     m_data.resize(DataArrayView::noValues(shape));
76     //
77     // create a view of the data with the correct shape
78     DataArrayView tempView(m_data,shape);
79 jgs 108 DataArrayView::RegionLoopRangeType region_loop_range=getSliceRegionLoopRange(region);
80 jgs 119 //
81     // load the view with the data from the slice
82 jgs 108 tempView.copySlice(other.getPointDataView(),region_loop_range);
83 jgs 119 setPointDataView(tempView);
84     }
85    
86     DataConstant::DataConstant(const FunctionSpace& what,
87     const DataArrayView::ShapeType &shape,
88     const DataArrayView::ValueType &data)
89     : DataAbstract(what)
90     {
91 jgs 102 //
92 jgs 119 // copy the data in the correct format
93     m_data=data;
94     //
95     // create the view of the data
96     DataArrayView tempView(m_data,shape);
97 jgs 102 setPointDataView(tempView);
98     }
99 jgs 82
100 jgs 102 string
101     DataConstant::toString() const
102     {
103     return getPointDataView().toString("");
104     }
105 jgs 82
106 jgs 102 DataArrayView::ValueType::size_type
107     DataConstant::getPointOffset(int sampleNo,
108     int dataPointNo) const
109     {
110     EsysAssert((validSamplePointNo(dataPointNo) && validSampleNo(sampleNo)),
111     "Invalid index, sampleNo: " << sampleNo << " dataPointNo: " << dataPointNo);
112 jgs 122 //
113     // Whatever the coord's always return the same value as this is constant data.
114 jgs 102 return 0;
115     }
116 jgs 82
117 jgs 102 DataArrayView::ValueType::size_type
118     DataConstant::getLength() const
119     {
120     return m_data.size();
121     }
122 jgs 82
123 jgs 102 DataArrayView
124     DataConstant::getDataPoint(int sampleNo,
125     int dataPointNo)
126     {
127     EsysAssert((validSamplePointNo(dataPointNo) && validSampleNo(sampleNo)),
128     "Invalid index, sampleNo: " << sampleNo << " dataPointNo: " << dataPointNo);
129     //
130     // Whatever the coord's always return the same value as this is constant data.
131     return getPointDataView();
132     }
133 jgs 82
134 jgs 102 DataAbstract*
135     DataConstant::getSlice(const DataArrayView::RegionType& region) const
136     {
137     return new DataConstant(*this,region);
138     }
139 jgs 82
140 jgs 102 void
141     DataConstant::setSlice(const DataAbstract* value,
142     const DataArrayView::RegionType& region)
143     {
144     const DataConstant* tempDataConst=dynamic_cast<const DataConstant*>(value);
145     if (tempDataConst==0) {
146     throw DataException("Programming error - casting to DataConstant.");
147 jgs 82 }
148 jgs 108 //
149     DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));
150     DataArrayView::RegionLoopRangeType region_loop_range=getSliceRegionLoopRange(region);
151     //
152     // check shape:
153     if (getPointDataView().getRank()!=region.size()) {
154     throw DataException("Error - Invalid slice region.");
155     }
156     if (tempDataConst->getPointDataView().getRank()>0 and !value->getPointDataView().checkShape(shape)) {
157     throw DataException (value->getPointDataView().createShapeErrorMessage(
158     "Error - Couldn't copy slice due to shape mismatch.",shape));
159     }
160     //
161     getPointDataView().copySliceFrom(tempDataConst->getPointDataView(),region_loop_range);
162 jgs 102 }
163 jgs 82
164 jgs 102 void
165     DataConstant::reshapeDataPoint(const DataArrayView::ShapeType& shape)
166     {
167     if (getPointDataView().getRank()!=0) {
168     stringstream temp;
169     temp << "Error - Can only reshape Data with data points of rank 0. "
170     << "This Data has data points with rank: " << getPointDataView().getRank();
171     throw DataException(temp.str());
172 jgs 82 }
173 jgs 102 m_data.resize(DataArrayView::noValues(shape),getPointDataView()());
174     DataArrayView newView(m_data,shape);
175     setPointDataView(newView);
176     }
177 jgs 82
178     } // end of namespace

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26