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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 155 - (hide annotations)
Wed Nov 9 02:02:19 2005 UTC (13 years, 11 months ago) by jgs
Original Path: trunk/escript/src/Data/DataVector.cpp
File size: 4808 byte(s)
move all directories from trunk/esys2 into trunk and remove esys2

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