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