/[escript]/branches/arrexp_2137_win_merge/escript/src/DataVector.cpp
ViewVC logotype

Annotation of /branches/arrexp_2137_win_merge/escript/src/DataVector.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 615 - (hide annotations)
Wed Mar 22 02:12:00 2006 UTC (13 years, 5 months ago) by elspeth
Original Path: trunk/escript/src/DataVector.cpp
File size: 4409 byte(s)
More copyright information.

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