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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 100 - (hide annotations)
Wed Dec 15 03:48:48 2004 UTC (14 years, 10 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/DataConstant.cpp
File size: 4805 byte(s)
*** empty log message ***

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26