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

Contents of /trunk/escript/src/DataVariable.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

1 /*
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 "DataVariable.h"
16
17 using namespace std;
18 using namespace escript;
19
20 namespace escript {
21
22 DataVariable::DataVariable() :
23 op(nullop),
24 leftArg(0),
25 rightArg(0),
26 opBuffer(0)
27 {
28 // cout << "DataVariable default constructor." << endl;
29 }
30
31 DataVariable::DataVariable(Data* data) :
32 op(idop),
33 leftArg(data),
34 rightArg(0),
35 opBuffer(0)
36 {
37
38 int numSamples = leftArg->getNumSamples();
39 int numValsPerSample = leftArg->getNumDataPointsPerSample() * leftArg->getDataPointSize();
40 int bufSize = numSamples * numValsPerSample;
41
42 // cout << "DataVariable constructor. " << bufSize << endl;
43 opBuffer = new double[bufSize];
44 for (int i=0; i<bufSize; i++) {
45 opBuffer[i] = 0.0;
46 }
47 }
48
49 DataVariable::~DataVariable()
50 {
51 // cout << "DataVariable destructor";
52
53 if (opBuffer!=0) {
54 // cout << ": freeing buffer";
55 delete[] opBuffer;
56 }
57
58 // cout << "." << endl;
59 }
60
61 Data
62 DataVariable::evaluate()
63 {
64 // cout << "DataVariable evaluate." << endl;
65
66 if (op==idop) {
67
68 return *leftArg;
69
70 } else {
71
72 Data expTemp(0,leftArg->getDataPointShape(),leftArg->getFunctionSpace(),true);
73
74 int numSamples = leftArg->getNumSamples();
75 int numValsPerSample = leftArg->getNumDataPointsPerSample() * leftArg->getDataPointSize();
76
77 for (int sampleNo=0; sampleNo<numSamples; sampleNo++) {
78
79 double* sampleBuf = evaluate_samp(sampleNo);
80 double* sampleLoc = expTemp.getSampleData(sampleNo);
81
82 for (int i=0; i<numValsPerSample; i++) {
83 sampleLoc[i] = sampleBuf[i];
84 }
85
86 }
87
88 return expTemp;
89
90 }
91
92 throw DataException("DataVariable: nothing to evaluate");
93 return *leftArg;
94
95 }
96
97 double*
98 DataVariable::evaluate_samp(int sampleNo)
99 {
100
101 // cout << "DataVariable(" << sampleNo << ") evaluate." << endl;
102
103 if (op==idop) {
104
105 return leftArg->getSampleData(sampleNo);
106
107 } else {
108
109 int numValsPerSample = leftArg->getNumDataPointsPerSample() * leftArg->getDataPointSize();
110 int offset = sampleNo * numValsPerSample;
111
112 double* leftBuff = leftArg->getSampleData(sampleNo);
113 double* rightBuff = rightArg->evaluate_samp(sampleNo);
114
115 if (op == sumop) {
116 for (int i=0; i<numValsPerSample; i++) {
117 opBuffer[offset+i] = leftBuff[i] + rightBuff[i];
118 }
119 }
120
121 if (op == diffop) {
122 for (int i=0; i<numValsPerSample; i++) {
123 opBuffer[offset+i] = leftBuff[i] - rightBuff[i];
124 }
125 }
126
127 return opBuffer+offset;
128
129 }
130
131 throw DataException("DataVariable: nothing to evaluate(i)");
132 return 0;
133
134 }
135
136 void
137 DataVariable::sum(DataVariable* right)
138 {
139 // cout << "DataVariable sum." << endl;
140 if (leftArg != 0) {
141 if (leftArg->getNumDataPointsPerSample() == right->leftArg->getNumDataPointsPerSample() &&
142 leftArg->getDataPointSize() == right->leftArg->getDataPointSize() &&
143 leftArg->getNumSamples() == right->leftArg->getNumSamples()) {
144 op=sumop;
145 rightArg=right;
146 } else {
147 throw DataException("DataVariable: incompatible operands");
148 }
149 } else {
150 throw DataException("DataVariable: cannot apply op to empty object.");
151 }
152 }
153
154 void
155 DataVariable::diff(DataVariable* right)
156 {
157 cout << "DataVariable diff." << endl;
158 if (leftArg != 0) {
159 if (leftArg->getNumDataPointsPerSample() == right->leftArg->getNumDataPointsPerSample() &&
160 leftArg->getDataPointSize() == right->leftArg->getDataPointSize() &&
161 leftArg->getNumSamples() == right->leftArg->getNumSamples()) {
162 op=diffop;
163 rightArg=right;
164 } else {
165 throw DataException("DataVariable: incompatible operands");
166 }
167 } else {
168 throw DataException("DataVariable: cannot apply op to empty object.");
169 }
170 }
171
172 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26