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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 97 - (hide annotations)
Tue Dec 14 05:39:33 2004 UTC (14 years, 11 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/DataConstant.cpp
File size: 4715 byte(s)
*** empty log message ***

1 jgs 97 //$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 97 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     DataArrayView tempView(m_data,temp.getView().getShape());
36     //
37     // copy the view of the data
38     setPointDataView(tempView);
39     }
40 jgs 82
41 jgs 97 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     DataArrayView tempView(m_data,value.getShape());
49     //
50     // copy the view of the data
51     setPointDataView(tempView);
52     }
53 jgs 82
54 jgs 97 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     DataArrayView tempView(m_data,other.getPointDataView().getShape());
61     //
62     // copy the view of the data
63     setPointDataView(tempView);
64     }
65 jgs 82
66 jgs 97 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     // copy the data from the slice to the temp view
80     tempView.copySlice(other.getPointDataView(),region);
81     //
82     // store the temp view of the data in this object
83     setPointDataView(tempView);
84     }
85 jgs 82
86 jgs 97 string
87     DataConstant::toString() const
88     {
89     return getPointDataView().toString("");
90     }
91 jgs 82
92 jgs 97 DataArrayView::ValueType::size_type
93     DataConstant::getPointOffset(int sampleNo,
94     int dataPointNo) const
95     {
96     EsysAssert((validSamplePointNo(dataPointNo) && validSampleNo(sampleNo)),
97     "Invalid index, sampleNo: " << sampleNo << " dataPointNo: " << dataPointNo);
98     return 0;
99     }
100 jgs 82
101 jgs 97 DataArrayView::ValueType::size_type
102     DataConstant::getLength() const
103     {
104     return m_data.size();
105     }
106 jgs 82
107 jgs 97 DataArrayView
108     DataConstant::getDataPoint(int sampleNo,
109     int dataPointNo)
110     {
111     EsysAssert((validSamplePointNo(dataPointNo) && validSampleNo(sampleNo)),
112     "Invalid index, sampleNo: " << sampleNo << " dataPointNo: " << dataPointNo);
113     //
114     // Whatever the coord's always return the same value as this is constant data.
115     return getPointDataView();
116     }
117 jgs 82
118 jgs 97 DataAbstract*
119     DataConstant::getSlice(const DataArrayView::RegionType& region) const
120     {
121     return new DataConstant(*this,region);
122     }
123 jgs 82
124 jgs 97 void
125     DataConstant::setSlice(const DataAbstract* value,
126     const DataArrayView::RegionType& region)
127     {
128     const DataConstant* tempDataConst=dynamic_cast<const DataConstant*>(value);
129     if (tempDataConst==0) {
130     throw DataException("Programming error - casting to DataConstant.");
131 jgs 82 }
132 jgs 97 getPointDataView().copySliceFrom(tempDataConst->getPointDataView(),region);
133     }
134 jgs 82
135 jgs 97 void
136     DataConstant::reshapeDataPoint(const DataArrayView::ShapeType& shape)
137     {
138     if (getPointDataView().getRank()!=0) {
139     stringstream temp;
140     temp << "Error - Can only reshape Data with data points of rank 0. "
141     << "This Data has data points with rank: " << getPointDataView().getRank();
142     throw DataException(temp.str());
143 jgs 82 }
144 jgs 97 m_data.resize(DataArrayView::noValues(shape),getPointDataView()());
145     DataArrayView newView(m_data,shape);
146     setPointDataView(newView);
147     }
148 jgs 82
149     } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26