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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 474 - (hide annotations)
Mon Jan 30 04:23:44 2006 UTC (13 years, 8 months ago) by jgs
File size: 4663 byte(s)
restructure escript source tree
move src/Data/* -> src
remove inc
modify #includes and cpppath settings accordingly

1 jgs 117 /*
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 jgs 474 #include "DataVector.h"
16 jgs 117
17     using namespace std;
18 jgs 121 using namespace escript;
19 jgs 117
20     namespace escript {
21    
22 jgs 121 Taipan arrayManager;
23    
24     DataVector::DataVector() :
25     m_array_data(0),
26     m_size(0),
27     m_dim(0),
28     m_N(0)
29     {
30 jgs 117 }
31    
32 jgs 121 DataVector::DataVector(const DataVector& other) :
33     m_array_data(0),
34     m_size(other.m_size),
35     m_dim(other.m_dim),
36     m_N(other.m_N)
37     {
38     m_array_data = arrayManager.new_array(m_dim,m_N);
39 jgs 122 int i;
40     #pragma omp parallel for private(i) schedule(static)
41     for (i=0; i<m_size; i++) {
42 jgs 121 m_array_data[i] = other.m_array_data[i];
43     }
44 jgs 117 }
45    
46 jgs 121 DataVector::DataVector(const DataVector::size_type size,
47     const DataVector::value_type val,
48     const DataVector::size_type blockSize) :
49     m_array_data(0),
50     m_size(size),
51     m_dim(blockSize)
52     {
53     resize(size, val, blockSize);
54 jgs 117 }
55    
56 jgs 121 DataVector::~DataVector()
57     {
58     // dispose of data array
59 jgs 151 if (m_array_data!=0) {
60     arrayManager.delete_array(m_array_data);
61     }
62 jgs 121
63     // clear data members
64     m_size = -1;
65     m_dim = -1;
66     m_N = -1;
67     m_array_data = 0;
68 jgs 117 }
69    
70 jgs 121 void
71     DataVector::resize(const DataVector::size_type newSize,
72     const DataVector::value_type newValue,
73     const DataVector::size_type newBlockSize)
74     {
75     assert(m_size >= 0);
76    
77 jgs 151 if ( newBlockSize == 0) {
78     throw DataException("DataVector: invalid blockSize specified");
79     }
80    
81 jgs 121 if ( (newSize % newBlockSize) != 0) {
82     throw DataException("DataVector: invalid blockSize specified");
83     }
84    
85 jgs 151 if (m_array_data!=0) {
86     arrayManager.delete_array(m_array_data);
87     }
88 jgs 121
89     m_size = newSize;
90     m_dim = newBlockSize;
91     m_N = newSize / newBlockSize;
92     m_array_data = arrayManager.new_array(m_dim,m_N);
93    
94 jgs 122 int i;
95     #pragma omp parallel for private(i) schedule(static)
96     for (i=0; i<m_size; i++) {
97     m_array_data[i] = newValue;
98 jgs 121 }
99     }
100    
101     DataVector&
102     DataVector::operator=(const DataVector& other)
103     {
104     assert(m_size >= 0);
105    
106 jgs 151 if (m_array_data!=0) {
107     arrayManager.delete_array(m_array_data);
108     }
109 jgs 121
110     m_size = other.m_size;
111     m_dim = other.m_dim;
112     m_N = other.m_N;
113    
114     m_array_data = arrayManager.new_array(m_dim,m_N);
115 jgs 122 int i;
116     #pragma omp parallel for private(i) schedule(static)
117     for (i=0; i<m_size; i++) {
118 jgs 121 m_array_data[i] = other.m_array_data[i];
119     }
120    
121     return *this;
122     }
123    
124     bool
125     DataVector::operator==(const DataVector& other) const
126     {
127     assert(m_size >= 0);
128    
129     if (m_size!=other.m_size) {
130     return false;
131     }
132     if (m_dim!=other.m_dim) {
133     return false;
134     }
135     if (m_N!=other.m_N) {
136     return false;
137     }
138     for (int i=0; i<m_size; i++) {
139     if (m_array_data[i] != other.m_array_data[i]) {
140     return false;
141     }
142     }
143     return true;
144     }
145    
146     bool
147     DataVector::operator!=(const DataVector& other) const
148     {
149     return !(*this==other);
150     }
151    
152 jgs 123 int
153     DataVector::archiveData(ofstream& archiveFile,
154     const size_type noValues) const
155     {
156     //
157     // Check number of values expected to be written matches number in this object
158     if (noValues != size()) {
159     return 2;
160     }
161    
162     //
163     // Write all values in this object out to archiveFile
164     for (int i=0; i<size(); i++) {
165     archiveFile.write(reinterpret_cast<char *>(&m_array_data[i]),sizeof(double));
166     }
167    
168     //
169     // Check no errors were encountered before returning
170     if (!archiveFile.good()) {
171     return 1;
172     }
173    
174     return 0;
175     }
176    
177     int
178     DataVector::extractData(ifstream& archiveFile,
179     const size_type noValues)
180     {
181     //
182     // Check number of values expected to be read matches number in this object
183     if (noValues != size()) {
184     return 2;
185     }
186    
187     //
188     // Read all values in archiveFile back to this object
189     for (int i=0; i<size(); i++) {
190     archiveFile.read(reinterpret_cast<char *>(&m_array_data[i]),sizeof(double));
191     }
192    
193     //
194     // Check no errors were encountered before returning
195     if (!archiveFile.good()) {
196     return 1;
197     }
198    
199     return 0;
200     }
201    
202 jgs 117 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26