1 | |
---|
2 | #ifndef __FIELD_IMPL_HPP__ |
---|
3 | #define __FIELD_IMPL_HPP__ |
---|
4 | |
---|
5 | #include "xios_spl.hpp" |
---|
6 | #include "field.hpp" |
---|
7 | #include "context.hpp" |
---|
8 | #include "grid.hpp" |
---|
9 | #include "timer.hpp" |
---|
10 | #include "array_new.hpp" |
---|
11 | |
---|
12 | |
---|
13 | namespace xios { |
---|
14 | |
---|
15 | template <int N> |
---|
16 | void CField::setData(const CArray<double, N>& _data) |
---|
17 | { |
---|
18 | if (hasInstantData) |
---|
19 | { |
---|
20 | grid->inputField(_data, instantData); |
---|
21 | for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it) it->first->setSlot(it->second); |
---|
22 | } |
---|
23 | |
---|
24 | if (!hasExpression) |
---|
25 | { |
---|
26 | const std::vector<CField*>& refField=getAllReference(); |
---|
27 | std::vector<CField*>::const_iterator it = refField.begin(), end = refField.end(), |
---|
28 | itFilterSrc, iteFilterSrc; |
---|
29 | |
---|
30 | for (; it != end; it++) |
---|
31 | { |
---|
32 | const std::vector<CField*>& fieldFilterSources = (*it)->getFilterSources(); |
---|
33 | if (!fieldFilterSources.empty()) |
---|
34 | { |
---|
35 | itFilterSrc = fieldFilterSources.begin(); |
---|
36 | iteFilterSrc = fieldFilterSources.end(); |
---|
37 | for (; itFilterSrc != iteFilterSrc; ++itFilterSrc) |
---|
38 | { |
---|
39 | (*itFilterSrc)->updateDataWithoutOperation(_data, (*itFilterSrc)->data); |
---|
40 | if ((*it)->filteredData.numElements() != (*it)->grid->storeIndex_client.numElements()) |
---|
41 | { |
---|
42 | (*it)->filteredData.resize((*it)->grid->storeIndex_client.numElements()); |
---|
43 | } |
---|
44 | (*it)->applyFilter((*itFilterSrc)->data, (*it)->filteredData); |
---|
45 | } |
---|
46 | if ((*it)->hasOutputFile || (*it)->hasFieldOut) (*it)->updateFilteredData((*it)->filteredData); |
---|
47 | } |
---|
48 | else |
---|
49 | { |
---|
50 | (*it)->setData(_data); |
---|
51 | if (hasOutputFile || hasFieldOut) updateData(_data); |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | void CField::setDataFromExpression(const CArray<double, 1>& _data) |
---|
59 | { |
---|
60 | if (hasInstantData) |
---|
61 | { |
---|
62 | instantData=_data; |
---|
63 | for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it) it->first->setSlot(it->second); |
---|
64 | } |
---|
65 | |
---|
66 | if (!hasExpression) |
---|
67 | { |
---|
68 | const std::vector<CField*>& refField=getAllReference(); |
---|
69 | std::vector<CField*>::const_iterator it = refField.begin(), end = refField.end(); |
---|
70 | |
---|
71 | for (; it != end; it++) (*it)->setDataFromExpression(_data); |
---|
72 | if (hasOutputFile || hasFieldOut) updateDataFromExpression(_data); |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | template<int N> |
---|
77 | void CField::updateDataWithoutOperation(const CArray<double, N>& _data, CArray<double,1>& updatedData) |
---|
78 | { |
---|
79 | if (updatedData.numElements() != this->grid->storeIndex_client.numElements()) |
---|
80 | { |
---|
81 | updatedData.resize(this->grid->storeIndex_client.numElements()); |
---|
82 | this->grid->inputField(_data, updatedData); |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | template<int N> |
---|
87 | bool CField::updateFilteredData(CArray<double, N>& filteredData) |
---|
88 | { |
---|
89 | CContext* context=CContext::getCurrent(); |
---|
90 | const CDate & currDate = context->getCalendar()->getCurrentDate(); |
---|
91 | const CDate opeDate = *last_operation + freq_operation; |
---|
92 | const CDate writeDate = *last_Write + freq_write; |
---|
93 | bool doOperation, doWrite; |
---|
94 | |
---|
95 | |
---|
96 | info(50) << "CField::updateData " << currDate << " : send data to " << this->getBaseFieldId() << std::endl; |
---|
97 | info(50) << "Next operation " << opeDate<<std::endl; |
---|
98 | |
---|
99 | doOperation = (opeDate <= currDate); |
---|
100 | if (isOnceOperation) |
---|
101 | if (isFirstOperation) doOperation=true; |
---|
102 | else doOperation=false; |
---|
103 | |
---|
104 | if (doOperation) |
---|
105 | { |
---|
106 | if (this->data.numElements() != filteredData.numElements()) |
---|
107 | { |
---|
108 | this->data.resize(filteredData.numElements()); |
---|
109 | } |
---|
110 | |
---|
111 | (*this->foperation)(filteredData); |
---|
112 | |
---|
113 | *last_operation = currDate; |
---|
114 | info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl; |
---|
115 | } |
---|
116 | |
---|
117 | doWrite = (writeDate < (currDate + freq_operation)); |
---|
118 | if (isOnceOperation) |
---|
119 | { |
---|
120 | if(isFirstOperation) |
---|
121 | { |
---|
122 | doWrite=true; |
---|
123 | isFirstOperation=false; |
---|
124 | } |
---|
125 | else doWrite=false; |
---|
126 | } |
---|
127 | |
---|
128 | if (doWrite) |
---|
129 | { |
---|
130 | this->foperation->final(); |
---|
131 | *last_Write = writeDate; |
---|
132 | if (hasOutputFile) |
---|
133 | { |
---|
134 | info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl; |
---|
135 | CTimer::get("XIOS Send Data").resume(); |
---|
136 | sendUpdateData(); |
---|
137 | CTimer::get("XIOS Send Data").suspend(); |
---|
138 | } |
---|
139 | |
---|
140 | // if (hasFieldOut) |
---|
141 | // { |
---|
142 | // fieldOut->setDataFromExpression(data); |
---|
143 | // } |
---|
144 | return (true); |
---|
145 | } |
---|
146 | |
---|
147 | return (false); |
---|
148 | } |
---|
149 | |
---|
150 | template <int N> |
---|
151 | bool CField::updateData(const CArray<double, N>& _data) |
---|
152 | { |
---|
153 | CContext* context=CContext::getCurrent(); |
---|
154 | const CDate & currDate = context->getCalendar()->getCurrentDate(); |
---|
155 | const CDate opeDate = *last_operation + freq_operation; |
---|
156 | const CDate writeDate = *last_Write + freq_write; |
---|
157 | bool doOperation, doWrite; |
---|
158 | |
---|
159 | |
---|
160 | info(50) << "CField::updateData " << currDate << " : send data to " << this->getBaseFieldId() << std::endl; |
---|
161 | info(50) << "Next operation " << opeDate<<std::endl; |
---|
162 | |
---|
163 | doOperation = (opeDate <= currDate); |
---|
164 | if (isOnceOperation) |
---|
165 | if (isFirstOperation) doOperation=true; |
---|
166 | else doOperation=false; |
---|
167 | |
---|
168 | if (doOperation) |
---|
169 | { |
---|
170 | if (this->data.numElements() != this->grid->storeIndex_client.numElements()) |
---|
171 | { |
---|
172 | this->data.resize(this->grid->storeIndex_client.numElements()); |
---|
173 | } |
---|
174 | |
---|
175 | CArray<double,1> input(data.numElements()); |
---|
176 | this->grid->inputField(_data, input); |
---|
177 | (*this->foperation)(input); |
---|
178 | |
---|
179 | *last_operation = currDate; |
---|
180 | info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl; |
---|
181 | } |
---|
182 | |
---|
183 | doWrite = (writeDate < (currDate + freq_operation)); |
---|
184 | if (isOnceOperation) |
---|
185 | { |
---|
186 | if(isFirstOperation) |
---|
187 | { |
---|
188 | doWrite=true; |
---|
189 | isFirstOperation=false; |
---|
190 | } |
---|
191 | else doWrite=false; |
---|
192 | } |
---|
193 | |
---|
194 | if (doWrite) |
---|
195 | { |
---|
196 | this->foperation->final(); |
---|
197 | *last_Write = writeDate; |
---|
198 | if (hasOutputFile) |
---|
199 | { |
---|
200 | info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl; |
---|
201 | CTimer::get("XIOS Send Data").resume(); |
---|
202 | sendUpdateData(); |
---|
203 | CTimer::get("XIOS Send Data").suspend(); |
---|
204 | } |
---|
205 | |
---|
206 | if (hasFieldOut) |
---|
207 | { |
---|
208 | fieldOut->setDataFromExpression(data); |
---|
209 | } |
---|
210 | return (true); |
---|
211 | } |
---|
212 | |
---|
213 | return (false); |
---|
214 | } |
---|
215 | |
---|
216 | bool CField::updateDataFromExpression(const CArray<double, 1>& _data) |
---|
217 | { |
---|
218 | CContext* context=CContext::getCurrent(); |
---|
219 | const CDate & currDate = context->getCalendar()->getCurrentDate(); |
---|
220 | const CDate opeDate = *last_operation + freq_operation; |
---|
221 | const CDate writeDate = *last_Write + freq_write; |
---|
222 | bool doOperation, doWrite; |
---|
223 | |
---|
224 | |
---|
225 | info(50) << "CField::updateData " << currDate << " : send data to " << this->getBaseFieldId() << std::endl; |
---|
226 | info(50) << "Next operation " << opeDate<<std::endl; |
---|
227 | |
---|
228 | doOperation = (opeDate <= currDate); |
---|
229 | if (isOnceOperation) |
---|
230 | if (isFirstOperation) doOperation=true; |
---|
231 | else doOperation=false; |
---|
232 | |
---|
233 | if (doOperation) |
---|
234 | { |
---|
235 | if (this->data.numElements() != this->grid->storeIndex_client.numElements()) |
---|
236 | { |
---|
237 | this->data.resize(this->grid->storeIndex_client.numElements()); |
---|
238 | } |
---|
239 | |
---|
240 | (*this->foperation)(_data); |
---|
241 | |
---|
242 | *last_operation = currDate; |
---|
243 | info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl; |
---|
244 | } |
---|
245 | |
---|
246 | doWrite = (writeDate < (currDate + freq_operation)); |
---|
247 | if (isOnceOperation) |
---|
248 | { |
---|
249 | if(isFirstOperation) |
---|
250 | { |
---|
251 | doWrite=true; |
---|
252 | isFirstOperation=false; |
---|
253 | } |
---|
254 | else doWrite=false; |
---|
255 | } |
---|
256 | |
---|
257 | if (doWrite) |
---|
258 | { |
---|
259 | this->foperation->final(); |
---|
260 | *last_Write = writeDate; |
---|
261 | if (hasOutputFile) |
---|
262 | { |
---|
263 | info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl; |
---|
264 | CTimer::get("XIOS Send Data").resume(); |
---|
265 | sendUpdateData(); |
---|
266 | CTimer::get("XIOS Send Data").suspend(); |
---|
267 | } |
---|
268 | |
---|
269 | if (hasFieldOut) |
---|
270 | { |
---|
271 | fieldOut->setDataFromExpression(data); |
---|
272 | } |
---|
273 | return (true); |
---|
274 | } |
---|
275 | |
---|
276 | return (false); |
---|
277 | } |
---|
278 | |
---|
279 | template <int N> |
---|
280 | void CField::getData(CArray<double, N>& _data) const |
---|
281 | { |
---|
282 | if (!read_access.isEmpty() && read_access.getValue() && hasInstantData) |
---|
283 | { |
---|
284 | CContext* context = CContext::getCurrent(); |
---|
285 | const CDate& currentDate = context->getCalendar()->getCurrentDate(); |
---|
286 | |
---|
287 | while (isReadDataRequestPending) |
---|
288 | context->checkBuffersAndListen(); |
---|
289 | |
---|
290 | if (isEOF) |
---|
291 | ERROR("void CField::getData(CArray<double, N>& _data) const", |
---|
292 | << "Impossible to access field data, all the records of the field [ id = " << getId() << " ] have been already read."); |
---|
293 | |
---|
294 | grid->outputField(instantData, _data); |
---|
295 | } |
---|
296 | else |
---|
297 | { |
---|
298 | ERROR("void CField::getData(CArray<double, N>& _data) const", |
---|
299 | << "Impossible to access field data, the field [ id = " << getId() << " ] does not have read access."); |
---|
300 | } |
---|
301 | } |
---|
302 | } // namespace xios |
---|
303 | |
---|
304 | #endif |
---|