[219] | 1 | #include "field.hpp" |
---|
| 2 | |
---|
[352] | 3 | #include "attribute_template.hpp" |
---|
| 4 | #include "object_template.hpp" |
---|
| 5 | #include "group_template.hpp" |
---|
[219] | 6 | |
---|
| 7 | #include "node_type.hpp" |
---|
| 8 | #include "calendar_util.hpp" |
---|
[352] | 9 | #include "message.hpp" |
---|
[591] | 10 | #include "xios_spl.hpp" |
---|
[352] | 11 | #include "type.hpp" |
---|
[638] | 12 | #include "timer.hpp" |
---|
[352] | 13 | #include "context_client.hpp" |
---|
[586] | 14 | #include "context_server.hpp" |
---|
[459] | 15 | #include <set> |
---|
[640] | 16 | #include "garbage_collector.hpp" |
---|
| 17 | #include "source_filter.hpp" |
---|
| 18 | #include "store_filter.hpp" |
---|
| 19 | #include "file_writer_filter.hpp" |
---|
[641] | 20 | #include "pass_through_filter.hpp" |
---|
[642] | 21 | #include "filter_expr_node.hpp" |
---|
| 22 | #include "lex_parser.hpp" |
---|
[643] | 23 | #include "temporal_filter.hpp" |
---|
[644] | 24 | #include "spatial_transform_filter.hpp" |
---|
[1025] | 25 | #include "file_server_writer_filter.hpp" |
---|
[219] | 26 | |
---|
[335] | 27 | namespace xios{ |
---|
[509] | 28 | |
---|
[219] | 29 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 30 | |
---|
| 31 | CField::CField(void) |
---|
| 32 | : CObjectTemplate<CField>(), CFieldAttributes() |
---|
| 33 | , grid(), file() |
---|
[707] | 34 | , written(false) |
---|
[645] | 35 | , nstep(0), nstepMax(0) |
---|
| 36 | , hasOutputFile(false) |
---|
[1129] | 37 | , domAxisScalarIds_(vector<StdString>(3,"")) |
---|
| 38 | , areAllReferenceSolved(false), isReferenceSolved(false), isReferenceSolvedAndTransformed(false) |
---|
[676] | 39 | , useCompressedOutput(false) |
---|
[1021] | 40 | , wasDataAlreadyReceivedFromServer(false) |
---|
[957] | 41 | { setVirtualVariableGroup(CVariableGroup::create(getId() + "_virtual_variable_group")); } |
---|
[219] | 42 | |
---|
[562] | 43 | CField::CField(const StdString& id) |
---|
[219] | 44 | : CObjectTemplate<CField>(id), CFieldAttributes() |
---|
| 45 | , grid(), file() |
---|
[707] | 46 | , written(false) |
---|
[645] | 47 | , nstep(0), nstepMax(0) |
---|
| 48 | , hasOutputFile(false) |
---|
[1129] | 49 | , domAxisScalarIds_(vector<StdString>(3,"")) |
---|
| 50 | , areAllReferenceSolved(false), isReferenceSolved(false), isReferenceSolvedAndTransformed(false) |
---|
[676] | 51 | , useCompressedOutput(false) |
---|
[1021] | 52 | , wasDataAlreadyReceivedFromServer(false) |
---|
[957] | 53 | { setVirtualVariableGroup(CVariableGroup::create(getId() + "_virtual_variable_group")); } |
---|
[219] | 54 | |
---|
| 55 | CField::~CField(void) |
---|
[645] | 56 | {} |
---|
[509] | 57 | |
---|
[472] | 58 | //---------------------------------------------------------------- |
---|
| 59 | |
---|
| 60 | void CField::setVirtualVariableGroup(CVariableGroup* newVVariableGroup) |
---|
[509] | 61 | { |
---|
| 62 | this->vVariableGroup = newVVariableGroup; |
---|
[472] | 63 | } |
---|
[509] | 64 | |
---|
[472] | 65 | CVariableGroup* CField::getVirtualVariableGroup(void) const |
---|
| 66 | { |
---|
[562] | 67 | return this->vVariableGroup; |
---|
[472] | 68 | } |
---|
| 69 | |
---|
| 70 | std::vector<CVariable*> CField::getAllVariables(void) const |
---|
| 71 | { |
---|
[562] | 72 | return this->vVariableGroup->getAllChildren(); |
---|
[472] | 73 | } |
---|
[509] | 74 | |
---|
[562] | 75 | void CField::solveDescInheritance(bool apply, const CAttributeMap* const parent) |
---|
[472] | 76 | { |
---|
[562] | 77 | SuperClassAttribute::setAttributes(parent, apply); |
---|
[472] | 78 | this->getVirtualVariableGroup()->solveDescInheritance(apply, NULL); |
---|
| 79 | } |
---|
[219] | 80 | |
---|
[645] | 81 | //---------------------------------------------------------------- |
---|
[509] | 82 | |
---|
[598] | 83 | bool CField::dispatchEvent(CEventServer& event) |
---|
[300] | 84 | { |
---|
[562] | 85 | if (SuperClass::dispatchEvent(event)) return true; |
---|
[300] | 86 | else |
---|
| 87 | { |
---|
| 88 | switch(event.type) |
---|
| 89 | { |
---|
| 90 | case EVENT_ID_UPDATE_DATA : |
---|
[562] | 91 | recvUpdateData(event); |
---|
| 92 | return true; |
---|
| 93 | break; |
---|
[472] | 94 | |
---|
[598] | 95 | case EVENT_ID_READ_DATA : |
---|
| 96 | recvReadDataRequest(event); |
---|
| 97 | return true; |
---|
| 98 | break; |
---|
[509] | 99 | |
---|
[598] | 100 | case EVENT_ID_READ_DATA_READY : |
---|
| 101 | recvReadDataReady(event); |
---|
| 102 | return true; |
---|
| 103 | break; |
---|
[509] | 104 | |
---|
[598] | 105 | case EVENT_ID_ADD_VARIABLE : |
---|
| 106 | recvAddVariable(event); |
---|
| 107 | return true; |
---|
| 108 | break; |
---|
| 109 | |
---|
| 110 | case EVENT_ID_ADD_VARIABLE_GROUP : |
---|
| 111 | recvAddVariableGroup(event); |
---|
| 112 | return true; |
---|
| 113 | break; |
---|
| 114 | |
---|
[300] | 115 | default : |
---|
[562] | 116 | ERROR("bool CField::dispatchEvent(CEventServer& event)", << "Unknown Event"); |
---|
| 117 | return false; |
---|
[300] | 118 | } |
---|
| 119 | } |
---|
| 120 | } |
---|
[509] | 121 | |
---|
[638] | 122 | void CField::sendUpdateData(const CArray<double,1>& data) |
---|
| 123 | { |
---|
| 124 | CTimer::get("XIOS Send Data").resume(); |
---|
| 125 | |
---|
| 126 | CContext* context = CContext::getCurrent(); |
---|
[1054] | 127 | CContextClient* client = (!context->hasServer) ? context->client : this->file->getContextClient(); |
---|
[638] | 128 | |
---|
[1009] | 129 | CEventClient event(getType(), EVENT_ID_UPDATE_DATA); |
---|
| 130 | |
---|
| 131 | map<int, CArray<int,1> >::iterator it; |
---|
| 132 | list<CMessage> list_msg; |
---|
| 133 | list<CArray<double,1> > list_data; |
---|
| 134 | |
---|
| 135 | if (!grid->doGridHaveDataDistributed()) |
---|
| 136 | { |
---|
| 137 | if (client->isServerLeader()) |
---|
| 138 | { |
---|
| 139 | for (it = grid->storeIndex_toSrv.begin(); it != grid->storeIndex_toSrv.end(); it++) |
---|
| 140 | { |
---|
| 141 | int rank = it->first; |
---|
| 142 | CArray<int,1>& index = it->second; |
---|
| 143 | |
---|
| 144 | list_msg.push_back(CMessage()); |
---|
| 145 | list_data.push_back(CArray<double,1>(index.numElements())); |
---|
| 146 | |
---|
| 147 | CArray<double,1>& data_tmp = list_data.back(); |
---|
| 148 | for (int n = 0; n < data_tmp.numElements(); n++) data_tmp(n) = data(index(n)); |
---|
| 149 | |
---|
| 150 | list_msg.back() << getId() << data_tmp; |
---|
| 151 | event.push(rank, 1, list_msg.back()); |
---|
| 152 | } |
---|
| 153 | client->sendEvent(event); |
---|
| 154 | } |
---|
| 155 | else client->sendEvent(event); |
---|
| 156 | } |
---|
| 157 | else |
---|
| 158 | { |
---|
| 159 | for (it = grid->storeIndex_toSrv.begin(); it != grid->storeIndex_toSrv.end(); it++) |
---|
| 160 | { |
---|
| 161 | int rank = it->first; |
---|
| 162 | CArray<int,1>& index = it->second; |
---|
| 163 | |
---|
| 164 | list_msg.push_back(CMessage()); |
---|
| 165 | list_data.push_back(CArray<double,1>(index.numElements())); |
---|
| 166 | |
---|
| 167 | CArray<double,1>& data_tmp = list_data.back(); |
---|
| 168 | for (int n = 0; n < data_tmp.numElements(); n++) data_tmp(n) = data(index(n)); |
---|
| 169 | |
---|
| 170 | list_msg.back() << getId() << data_tmp; |
---|
[1099] | 171 | event.push(rank, grid->nbSenders[0][rank], list_msg.back()); |
---|
[1009] | 172 | } |
---|
| 173 | client->sendEvent(event); |
---|
[1144] | 174 | } |
---|
[1009] | 175 | |
---|
| 176 | CTimer::get("XIOS Send Data").suspend(); |
---|
| 177 | } |
---|
| 178 | |
---|
[300] | 179 | void CField::recvUpdateData(CEventServer& event) |
---|
| 180 | { |
---|
[1025] | 181 | std::map<int,CBufferIn*> rankBuffers; |
---|
[509] | 182 | |
---|
[562] | 183 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 184 | string fieldId; |
---|
[219] | 185 | |
---|
[562] | 186 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
[300] | 187 | { |
---|
[562] | 188 | int rank = it->rank; |
---|
| 189 | CBufferIn* buffer = it->buffer; |
---|
| 190 | *buffer >> fieldId; |
---|
[1025] | 191 | rankBuffers[rank] = buffer; |
---|
[300] | 192 | } |
---|
[1025] | 193 | get(fieldId)->recvUpdateData(rankBuffers); |
---|
[300] | 194 | } |
---|
[509] | 195 | |
---|
[1025] | 196 | void CField::recvUpdateData(std::map<int,CBufferIn*>& rankBuffers) |
---|
[300] | 197 | { |
---|
[983] | 198 | CContext* context = CContext::getCurrent(); |
---|
| 199 | |
---|
[1025] | 200 | size_t sizeData = 0; |
---|
| 201 | if (0 == recvDataSrv.numElements()) |
---|
[1129] | 202 | { |
---|
| 203 | CArray<int,1>& storeClient = grid->storeIndex_client; |
---|
[1025] | 204 | |
---|
[1136] | 205 | // Gather all data from different clients |
---|
[1129] | 206 | recvDataSrv.resize(storeClient.numElements()); |
---|
[1025] | 207 | recvFoperationSrv = boost::shared_ptr<func::CFunctor>(new func::CInstant(recvDataSrv)); |
---|
[300] | 208 | } |
---|
| 209 | |
---|
[1136] | 210 | CArray<double,1> recv_data_tmp(recvDataSrv.numElements()); |
---|
[562] | 211 | const CDate& currDate = context->getCalendar()->getCurrentDate(); |
---|
[1099] | 212 | const CDate opeDate = last_operation_srv +freq_op + freq_operation_srv - freq_op; |
---|
[300] | 213 | |
---|
| 214 | if (opeDate <= currDate) |
---|
| 215 | { |
---|
[1136] | 216 | for (map<int, CArray<size_t, 1> >::iterator it = grid->outLocalIndexStoreOnClient.begin(); it != grid->outLocalIndexStoreOnClient.end(); ++it) |
---|
[1129] | 217 | { |
---|
[1099] | 218 | CArray<double,1> tmp; |
---|
| 219 | CArray<size_t,1>& indexTmp = it->second; |
---|
[1025] | 220 | *(rankBuffers[it->first]) >> tmp; |
---|
[1099] | 221 | for (int idx = 0; idx < indexTmp.numElements(); ++idx) |
---|
| 222 | { |
---|
| 223 | recv_data_tmp(indexTmp(idx)) = tmp(idx); |
---|
[1136] | 224 | } |
---|
[300] | 225 | } |
---|
| 226 | } |
---|
[509] | 227 | |
---|
[1025] | 228 | this->setData(recv_data_tmp); |
---|
| 229 | } |
---|
[509] | 230 | |
---|
[1025] | 231 | void CField::writeUpdateData(const CArray<double,1>& data) |
---|
| 232 | { |
---|
| 233 | CContext* context = CContext::getCurrent(); |
---|
[983] | 234 | |
---|
[1025] | 235 | const CDate& currDate = context->getCalendar()->getCurrentDate(); |
---|
| 236 | const CDate opeDate = last_operation_srv +freq_op + freq_operation_srv - freq_op; |
---|
| 237 | const CDate writeDate = last_Write_srv + freq_write_srv; |
---|
| 238 | |
---|
| 239 | if (opeDate <= currDate) |
---|
[983] | 240 | { |
---|
[1025] | 241 | (*recvFoperationSrv)(data); |
---|
| 242 | last_operation_srv = currDate; |
---|
[983] | 243 | } |
---|
[1025] | 244 | |
---|
| 245 | if (writeDate < (currDate + freq_operation_srv)) |
---|
[983] | 246 | { |
---|
[1025] | 247 | recvFoperationSrv->final(); |
---|
| 248 | last_Write_srv = writeDate; |
---|
[1129] | 249 | grid->computeWrittenIndex(); |
---|
[562] | 250 | writeField(); |
---|
[1025] | 251 | lastlast_Write_srv = last_Write_srv; |
---|
[300] | 252 | } |
---|
[1025] | 253 | } |
---|
| 254 | |
---|
| 255 | // void CField::recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers) |
---|
| 256 | // { |
---|
| 257 | // CContext* context = CContext::getCurrent(); |
---|
[983] | 258 | |
---|
[1025] | 259 | // if (data_srv.empty()) |
---|
| 260 | // { |
---|
| 261 | // for (map<int, CArray<size_t, 1> >::iterator it = grid->outIndexFromClient.begin(); it != grid->outIndexFromClient.end(); ++it) |
---|
| 262 | // { |
---|
| 263 | // int rank = it->first; |
---|
| 264 | // data_srv.insert(std::make_pair(rank, CArray<double,1>(it->second.numElements()))); |
---|
| 265 | // foperation_srv.insert(pair<int,boost::shared_ptr<func::CFunctor> >(rank,boost::shared_ptr<func::CFunctor>(new func::CInstant(data_srv[rank])))); |
---|
| 266 | // } |
---|
| 267 | // } |
---|
[983] | 268 | |
---|
[1025] | 269 | // const CDate& currDate = context->getCalendar()->getCurrentDate(); |
---|
| 270 | // const CDate opeDate = last_operation_srv +freq_op + freq_operation_srv - freq_op; |
---|
| 271 | // const CDate writeDate = last_Write_srv + freq_write_srv; |
---|
[509] | 272 | |
---|
[1025] | 273 | // if (opeDate <= currDate) |
---|
| 274 | // { |
---|
| 275 | // for (int n = 0; n < ranks.size(); n++) |
---|
| 276 | // { |
---|
| 277 | // CArray<double,1> data_tmp; |
---|
| 278 | // *buffers[n] >> data_tmp; |
---|
| 279 | // (*foperation_srv[ranks[n]])(data_tmp); |
---|
| 280 | // } |
---|
| 281 | // last_operation_srv = currDate; |
---|
| 282 | // } |
---|
| 283 | |
---|
| 284 | // if (writeDate < (currDate + freq_operation_srv)) |
---|
| 285 | // { |
---|
| 286 | // for (int n = 0; n < ranks.size(); n++) |
---|
| 287 | // { |
---|
| 288 | // this->foperation_srv[ranks[n]]->final(); |
---|
| 289 | // } |
---|
| 290 | |
---|
| 291 | // last_Write_srv = writeDate; |
---|
| 292 | // } |
---|
| 293 | |
---|
| 294 | // if (context->hasClient && context->hasServer) |
---|
| 295 | // { |
---|
| 296 | // size_t writtenSize; |
---|
| 297 | // // if (field->getUseCompressedOutput()) |
---|
| 298 | // // writtenSize = grid->getNumberWrittenIndexes(); |
---|
| 299 | // // else |
---|
| 300 | // writtenSize = grid->getWrittenDataSize(); |
---|
| 301 | |
---|
| 302 | // CArray<double,1> fieldData(writtenSize); |
---|
| 303 | // // if (!field->default_value.isEmpty()) fieldData = field->default_value; |
---|
| 304 | |
---|
| 305 | // // if (field->getUseCompressedOutput()) |
---|
| 306 | // // field->outputCompressedField(fieldData); |
---|
| 307 | // // else |
---|
| 308 | // this->outputField(fieldData); |
---|
| 309 | // sendUpdateData(fieldData); |
---|
| 310 | // } |
---|
| 311 | // if (!context->hasClient && context->hasServer) |
---|
| 312 | // { |
---|
| 313 | // writeField(); |
---|
| 314 | // } |
---|
| 315 | |
---|
| 316 | // lastlast_Write_srv = last_Write_srv; |
---|
| 317 | |
---|
| 318 | // } |
---|
| 319 | |
---|
[300] | 320 | void CField::writeField(void) |
---|
| 321 | { |
---|
[562] | 322 | if (!getRelFile()->allDomainEmpty) |
---|
[586] | 323 | { |
---|
[599] | 324 | if (grid->doGridHaveDataToWrite() || getRelFile()->type == CFile::type_attr::one_file) |
---|
[379] | 325 | { |
---|
[1136] | 326 | getRelFile()->checkWriteFile(); |
---|
[379] | 327 | this->incrementNStep(); |
---|
| 328 | getRelFile()->getDataOutput()->writeFieldData(CField::get(this)); |
---|
| 329 | } |
---|
[586] | 330 | } |
---|
[300] | 331 | } |
---|
[562] | 332 | |
---|
[1021] | 333 | void CField::sendReadDataRequest(const CDate& tsDataRequested) |
---|
[598] | 334 | { |
---|
| 335 | CContext* context = CContext::getCurrent(); |
---|
[1071] | 336 | CContextClient* client = (!context->hasServer) ? context->client : this->file->getContextClient(); |
---|
[598] | 337 | |
---|
[1071] | 338 | |
---|
[1021] | 339 | lastDataRequestedFromServer = tsDataRequested; |
---|
[708] | 340 | |
---|
[598] | 341 | CEventClient event(getType(), EVENT_ID_READ_DATA); |
---|
| 342 | if (client->isServerLeader()) |
---|
| 343 | { |
---|
| 344 | CMessage msg; |
---|
| 345 | msg << getId(); |
---|
| 346 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 347 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 348 | event.push(*itRank, 1, msg); |
---|
| 349 | client->sendEvent(event); |
---|
| 350 | } |
---|
| 351 | else client->sendEvent(event); |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | /*! |
---|
| 355 | Send request new data read from file if need be, that is the current data is out-of-date. |
---|
| 356 | \return true if and only if some data was requested |
---|
| 357 | */ |
---|
| 358 | bool CField::sendReadDataRequestIfNeeded(void) |
---|
| 359 | { |
---|
| 360 | const CDate& currentDate = CContext::getCurrent()->getCalendar()->getCurrentDate(); |
---|
| 361 | |
---|
[1021] | 362 | bool dataRequested = false; |
---|
| 363 | while (currentDate >= lastDataRequestedFromServer) |
---|
[850] | 364 | { |
---|
[1021] | 365 | info(20) << "currentDate : " << currentDate << endl ; |
---|
| 366 | info(20) << "lastDataRequestedFromServer : " << lastDataRequestedFromServer << endl ; |
---|
| 367 | info(20) << "file->output_freq.getValue() : " << file->output_freq.getValue() << endl ; |
---|
| 368 | info(20) << "lastDataRequestedFromServer + file->output_freq.getValue() : " << lastDataRequestedFromServer + file->output_freq << endl ; |
---|
[873] | 369 | |
---|
[1021] | 370 | sendReadDataRequest(lastDataRequestedFromServer + file->output_freq); |
---|
| 371 | |
---|
| 372 | dataRequested = true; |
---|
[850] | 373 | } |
---|
[1021] | 374 | return dataRequested; |
---|
[598] | 375 | } |
---|
| 376 | |
---|
| 377 | void CField::recvReadDataRequest(CEventServer& event) |
---|
| 378 | { |
---|
| 379 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
| 380 | StdString fieldId; |
---|
| 381 | *buffer >> fieldId; |
---|
| 382 | get(fieldId)->recvReadDataRequest(); |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | void CField::recvReadDataRequest(void) |
---|
| 386 | { |
---|
| 387 | CContext* context = CContext::getCurrent(); |
---|
[1136] | 388 | CContextClient* client = context->client; |
---|
[598] | 389 | |
---|
| 390 | CEventClient event(getType(), EVENT_ID_READ_DATA_READY); |
---|
| 391 | std::list<CMessage> msgs; |
---|
| 392 | |
---|
[599] | 393 | bool hasData = readField(); |
---|
[598] | 394 | |
---|
[1136] | 395 | |
---|
[1021] | 396 | if (!grid->doGridHaveDataDistributed()) |
---|
[598] | 397 | { |
---|
[1021] | 398 | if (client->isServerLeader()) |
---|
| 399 | { |
---|
[1136] | 400 | if (0 != recvDataSrv.numElements()) |
---|
| 401 | { |
---|
[1021] | 402 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 403 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 404 | { |
---|
| 405 | msgs.push_back(CMessage()); |
---|
| 406 | CMessage& msg = msgs.back(); |
---|
| 407 | msg << getId(); |
---|
| 408 | if (hasData) |
---|
[1136] | 409 | msg << getNStep() - 1 << recvDataSrv; |
---|
[1021] | 410 | else |
---|
| 411 | msg << int(-1); |
---|
| 412 | event.push(*itRank, 1, msg); |
---|
| 413 | } |
---|
| 414 | } |
---|
[1136] | 415 | |
---|
[1021] | 416 | client->sendEvent(event); |
---|
| 417 | } |
---|
| 418 | else |
---|
| 419 | { |
---|
| 420 | client->sendEvent(event); |
---|
| 421 | } |
---|
[598] | 422 | } |
---|
[1021] | 423 | else |
---|
| 424 | { |
---|
[1136] | 425 | for (map<int, CArray<size_t, 1> >::iterator it = grid->outLocalIndexStoreOnClient.begin(); |
---|
| 426 | it != grid->outLocalIndexStoreOnClient.end(); ++it) |
---|
[1021] | 427 | { |
---|
[1136] | 428 | CArray<size_t,1>& indexTmp = it->second; |
---|
| 429 | CArray<double,1> tmp(indexTmp.numElements()); |
---|
| 430 | for (int idx = 0; idx < indexTmp.numElements(); ++idx) |
---|
| 431 | { |
---|
| 432 | tmp(idx) = recvDataSrv(indexTmp(idx)); |
---|
| 433 | } |
---|
| 434 | |
---|
[1021] | 435 | msgs.push_back(CMessage()); |
---|
| 436 | CMessage& msg = msgs.back(); |
---|
| 437 | msg << getId(); |
---|
| 438 | if (hasData) |
---|
[1136] | 439 | msg << getNStep() - 1 << tmp; |
---|
[1021] | 440 | else |
---|
| 441 | msg << int(-1); |
---|
[1136] | 442 | event.push(it->first, grid->nbReadSenders[0][it->first], msg); |
---|
[1021] | 443 | } |
---|
| 444 | client->sendEvent(event); |
---|
| 445 | } |
---|
[599] | 446 | } |
---|
[598] | 447 | |
---|
[599] | 448 | bool CField::readField(void) |
---|
| 449 | { |
---|
[1136] | 450 | grid->computeWrittenIndex(); |
---|
[599] | 451 | if (!getRelFile()->allDomainEmpty) |
---|
| 452 | { |
---|
| 453 | if (grid->doGridHaveDataToWrite() || getRelFile()->type == CFile::type_attr::one_file) |
---|
| 454 | { |
---|
[1136] | 455 | if (0 == recvDataSrv.numElements()) |
---|
| 456 | { |
---|
| 457 | CArray<int,1>& storeClient = grid->storeIndex_client; |
---|
| 458 | recvDataSrv.resize(storeClient.numElements()); |
---|
[599] | 459 | } |
---|
| 460 | |
---|
[1136] | 461 | getRelFile()->checkReadFile(); |
---|
[599] | 462 | if (!nstepMax) |
---|
| 463 | { |
---|
| 464 | nstepMax = getRelFile()->getDataInput()->getFieldNbRecords(CField::get(this)); |
---|
| 465 | } |
---|
[873] | 466 | |
---|
[850] | 467 | this->incrementNStep(); |
---|
[599] | 468 | |
---|
[850] | 469 | if (getNStep() > nstepMax && (getRelFile()->cyclic.isEmpty() || !getRelFile()->cyclic) ) |
---|
[599] | 470 | return false; |
---|
| 471 | |
---|
| 472 | getRelFile()->getDataInput()->readFieldData(CField::get(this)); |
---|
| 473 | } |
---|
| 474 | } |
---|
| 475 | |
---|
| 476 | return true; |
---|
[598] | 477 | } |
---|
| 478 | |
---|
| 479 | void CField::recvReadDataReady(CEventServer& event) |
---|
| 480 | { |
---|
| 481 | string fieldId; |
---|
| 482 | vector<int> ranks; |
---|
| 483 | vector<CBufferIn*> buffers; |
---|
| 484 | |
---|
| 485 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 486 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
| 487 | { |
---|
| 488 | ranks.push_back(it->rank); |
---|
| 489 | CBufferIn* buffer = it->buffer; |
---|
| 490 | *buffer >> fieldId; |
---|
| 491 | buffers.push_back(buffer); |
---|
| 492 | } |
---|
| 493 | get(fieldId)->recvReadDataReady(ranks, buffers); |
---|
| 494 | } |
---|
| 495 | |
---|
| 496 | void CField::recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers) |
---|
| 497 | { |
---|
| 498 | CContext* context = CContext::getCurrent(); |
---|
[959] | 499 | int record; |
---|
[640] | 500 | std::map<int, CArray<double,1> > data; |
---|
| 501 | |
---|
[645] | 502 | bool isEOF = false; |
---|
| 503 | |
---|
[598] | 504 | for (int i = 0; i < ranks.size(); i++) |
---|
| 505 | { |
---|
| 506 | int rank = ranks[i]; |
---|
[599] | 507 | *buffers[i] >> record; |
---|
[959] | 508 | isEOF = (record == int(-1)); |
---|
[598] | 509 | |
---|
[599] | 510 | if (!isEOF) |
---|
[640] | 511 | *buffers[i] >> data[rank]; |
---|
| 512 | else |
---|
| 513 | break; |
---|
| 514 | } |
---|
| 515 | |
---|
[1021] | 516 | if (wasDataAlreadyReceivedFromServer) |
---|
| 517 | lastDataReceivedFromServer = lastDataReceivedFromServer + file->output_freq; |
---|
| 518 | else |
---|
| 519 | { |
---|
| 520 | lastDataReceivedFromServer = context->getCalendar()->getInitDate(); |
---|
| 521 | wasDataAlreadyReceivedFromServer = true; |
---|
| 522 | } |
---|
| 523 | |
---|
[640] | 524 | if (isEOF) |
---|
[1021] | 525 | serverSourceFilter->signalEndOfStream(lastDataReceivedFromServer); |
---|
[640] | 526 | else |
---|
[1021] | 527 | serverSourceFilter->streamDataFromServer(lastDataReceivedFromServer, data); |
---|
[598] | 528 | } |
---|
| 529 | |
---|
[219] | 530 | //---------------------------------------------------------------- |
---|
| 531 | |
---|
[347] | 532 | void CField::setRelFile(CFile* _file) |
---|
[509] | 533 | { |
---|
[459] | 534 | this->file = _file; |
---|
[562] | 535 | hasOutputFile = true; |
---|
[219] | 536 | } |
---|
| 537 | |
---|
| 538 | //---------------------------------------------------------------- |
---|
| 539 | |
---|
[562] | 540 | StdString CField::GetName(void) { return StdString("field"); } |
---|
| 541 | StdString CField::GetDefName(void) { return CField::GetName(); } |
---|
| 542 | ENodeType CField::GetType(void) { return eField; } |
---|
[219] | 543 | |
---|
| 544 | //---------------------------------------------------------------- |
---|
| 545 | |
---|
[347] | 546 | CGrid* CField::getRelGrid(void) const |
---|
[509] | 547 | { |
---|
[562] | 548 | return this->grid; |
---|
[219] | 549 | } |
---|
| 550 | |
---|
| 551 | //---------------------------------------------------------------- |
---|
| 552 | |
---|
[347] | 553 | CFile* CField::getRelFile(void) const |
---|
[509] | 554 | { |
---|
[562] | 555 | return this->file; |
---|
[219] | 556 | } |
---|
[509] | 557 | |
---|
[952] | 558 | int CField::getNStep(void) const |
---|
[266] | 559 | { |
---|
[562] | 560 | return this->nstep; |
---|
[266] | 561 | } |
---|
[509] | 562 | |
---|
[645] | 563 | func::CFunctor::ETimeType CField::getOperationTimeType() const |
---|
| 564 | { |
---|
| 565 | return operationTimeType; |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | //---------------------------------------------------------------- |
---|
| 569 | |
---|
[266] | 570 | void CField::incrementNStep(void) |
---|
| 571 | { |
---|
| 572 | this->nstep++; |
---|
| 573 | } |
---|
[509] | 574 | |
---|
[952] | 575 | void CField::resetNStep(int nstep /*= 0*/) |
---|
[321] | 576 | { |
---|
[707] | 577 | this->nstep = nstep; |
---|
[321] | 578 | } |
---|
[219] | 579 | |
---|
[599] | 580 | void CField::resetNStepMax(void) |
---|
| 581 | { |
---|
| 582 | this->nstepMax = 0; |
---|
| 583 | } |
---|
| 584 | |
---|
[219] | 585 | //---------------------------------------------------------------- |
---|
| 586 | |
---|
[310] | 587 | bool CField::isActive(void) const |
---|
[509] | 588 | { |
---|
[767] | 589 | return (instantDataFilter != NULL); |
---|
[310] | 590 | } |
---|
[562] | 591 | |
---|
[219] | 592 | //---------------------------------------------------------------- |
---|
[509] | 593 | |
---|
[707] | 594 | bool CField::wasWritten() const |
---|
| 595 | { |
---|
| 596 | return written; |
---|
| 597 | } |
---|
| 598 | |
---|
| 599 | void CField::setWritten() |
---|
| 600 | { |
---|
| 601 | written = true; |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | //---------------------------------------------------------------- |
---|
| 605 | |
---|
[676] | 606 | bool CField::getUseCompressedOutput() const |
---|
| 607 | { |
---|
| 608 | return useCompressedOutput; |
---|
| 609 | } |
---|
| 610 | |
---|
| 611 | void CField::setUseCompressedOutput() |
---|
| 612 | { |
---|
| 613 | useCompressedOutput = true; |
---|
| 614 | } |
---|
| 615 | |
---|
| 616 | //---------------------------------------------------------------- |
---|
| 617 | |
---|
[641] | 618 | boost::shared_ptr<COutputPin> CField::getInstantDataFilter() |
---|
| 619 | { |
---|
| 620 | return instantDataFilter; |
---|
| 621 | } |
---|
| 622 | |
---|
| 623 | //---------------------------------------------------------------- |
---|
| 624 | |
---|
[823] | 625 | /*! |
---|
| 626 | Build up graph of grids which plays role of destination and source in grid transformation |
---|
| 627 | This function should be called before \func solveGridReference() |
---|
| 628 | */ |
---|
| 629 | void CField::buildGridTransformationGraph() |
---|
| 630 | { |
---|
| 631 | CContext* context = CContext::getCurrent(); |
---|
[983] | 632 | if (context->hasClient && !context->hasServer) |
---|
[687] | 633 | { |
---|
[823] | 634 | if (grid && !grid->isTransformed() && hasDirectFieldReference() && grid != getDirectFieldReference()->grid) |
---|
| 635 | { |
---|
| 636 | grid->addTransGridSource(getDirectFieldReference()->grid); |
---|
| 637 | } |
---|
[687] | 638 | } |
---|
[823] | 639 | } |
---|
[687] | 640 | |
---|
[823] | 641 | /*! |
---|
| 642 | Generate a new grid destination if there are more than one grid source pointing to a same grid destination |
---|
| 643 | */ |
---|
| 644 | void CField::generateNewTransformationGridDest() |
---|
| 645 | { |
---|
| 646 | CContext* context = CContext::getCurrent(); |
---|
[983] | 647 | if (context->hasClient && !context->hasServer) |
---|
[823] | 648 | { |
---|
| 649 | std::map<CGrid*,std::pair<bool,StdString> >& gridSrcMap = grid->getTransGridSource(); |
---|
| 650 | if (1 < gridSrcMap.size()) |
---|
| 651 | { |
---|
| 652 | // Search for grid source |
---|
| 653 | CGrid* gridSrc = grid; |
---|
| 654 | CField* currField = this; |
---|
| 655 | std::vector<CField*> hieraField; |
---|
[687] | 656 | |
---|
[823] | 657 | while (currField->hasDirectFieldReference() && (gridSrc == grid)) |
---|
| 658 | { |
---|
| 659 | hieraField.push_back(currField); |
---|
| 660 | CField* tmp = currField->getDirectFieldReference(); |
---|
| 661 | currField = tmp; |
---|
| 662 | gridSrc = currField->grid; |
---|
| 663 | } |
---|
| 664 | |
---|
| 665 | if (gridSrcMap.end() != gridSrcMap.find(gridSrc)) |
---|
| 666 | { |
---|
| 667 | CGrid* gridTmp; |
---|
| 668 | std::pair<bool,StdString> newGridDest = gridSrcMap[gridSrc]; |
---|
| 669 | if (newGridDest.first) |
---|
| 670 | { |
---|
| 671 | StdString newIdGridDest = newGridDest.second; |
---|
| 672 | if (!CGrid::has(newIdGridDest)) |
---|
| 673 | { |
---|
| 674 | ERROR("CGrid* CGrid::generateNewTransformationGridDest()", |
---|
| 675 | << " Something wrong happened! Grid whose id " << newIdGridDest |
---|
| 676 | << "should exist "); |
---|
| 677 | } |
---|
| 678 | gridTmp = CGrid::get(newIdGridDest); |
---|
| 679 | } |
---|
| 680 | else |
---|
| 681 | { |
---|
| 682 | StdString newIdGridDest = CGrid::generateId(gridSrc, grid); |
---|
| 683 | gridTmp = CGrid::cloneGrid(newIdGridDest, grid); |
---|
| 684 | |
---|
| 685 | (gridSrcMap[gridSrc]).first = true; |
---|
| 686 | (gridSrcMap[gridSrc]).second = newIdGridDest; |
---|
| 687 | } |
---|
| 688 | |
---|
| 689 | // Update all descendants |
---|
| 690 | for (std::vector<CField*>::iterator it = hieraField.begin(); it != hieraField.end(); ++it) |
---|
| 691 | { |
---|
| 692 | (*it)->grid = gridTmp; |
---|
| 693 | (*it)->updateRef((*it)->grid); |
---|
| 694 | } |
---|
| 695 | } |
---|
| 696 | } |
---|
| 697 | } |
---|
| 698 | } |
---|
| 699 | |
---|
| 700 | void CField::updateRef(CGrid* grid) |
---|
| 701 | { |
---|
| 702 | if (!grid_ref.isEmpty()) grid_ref.setValue(grid->getId()); |
---|
| 703 | else |
---|
| 704 | { |
---|
| 705 | std::vector<CAxis*> axisTmp = grid->getAxis(); |
---|
| 706 | std::vector<CDomain*> domainTmp = grid->getDomains(); |
---|
| 707 | if ((1<axisTmp.size()) || (1<domainTmp.size())) |
---|
| 708 | ERROR("void CField::updateRef(CGrid* grid)", |
---|
| 709 | << "More than one domain or axis is available for domain_ref/axis_ref of field " << this->getId()); |
---|
| 710 | |
---|
| 711 | if ((!domain_ref.isEmpty()) && (domainTmp.empty())) |
---|
| 712 | ERROR("void CField::updateRef(CGrid* grid)", |
---|
| 713 | << "Incoherent between available domain and domain_ref of field " << this->getId()); |
---|
| 714 | if ((!axis_ref.isEmpty()) && (axisTmp.empty())) |
---|
| 715 | ERROR("void CField::updateRef(CGrid* grid)", |
---|
| 716 | << "Incoherent between available axis and axis_ref of field " << this->getId()); |
---|
| 717 | |
---|
| 718 | if (!domain_ref.isEmpty()) domain_ref.setValue(domainTmp[0]->getId()); |
---|
| 719 | if (!axis_ref.isEmpty()) axis_ref.setValue(axisTmp[0]->getId()); |
---|
| 720 | } |
---|
| 721 | } |
---|
[1025] | 722 | |
---|
[1129] | 723 | /*! |
---|
| 724 | Solve reference of all enabled fields even the source fields . |
---|
| 725 | In this step, we do transformations. |
---|
| 726 | */ |
---|
| 727 | void CField::solveAllEnabledFieldsAndTransform() |
---|
[1025] | 728 | { |
---|
| 729 | CContext* context = CContext::getCurrent(); |
---|
| 730 | bool hasClient = context->hasClient; |
---|
| 731 | bool hasServer = context->hasServer; |
---|
[823] | 732 | |
---|
[1129] | 733 | if (!isReferenceSolvedAndTransformed) |
---|
[1025] | 734 | { |
---|
[1129] | 735 | isReferenceSolvedAndTransformed = true; |
---|
[1025] | 736 | |
---|
| 737 | if (hasClient && !hasServer) |
---|
| 738 | { |
---|
| 739 | solveRefInheritance(true); |
---|
[1129] | 740 | if (hasDirectFieldReference()) getDirectFieldReference()->solveAllEnabledFieldsAndTransform(); |
---|
[1025] | 741 | } |
---|
| 742 | |
---|
| 743 | if (hasServer) |
---|
| 744 | solveServerOperation(); |
---|
| 745 | |
---|
| 746 | solveGridReference(); |
---|
| 747 | |
---|
| 748 | if (hasClient && !hasServer) |
---|
| 749 | { |
---|
| 750 | solveGenerateGrid(); |
---|
| 751 | buildGridTransformationGraph(); |
---|
| 752 | } |
---|
| 753 | |
---|
| 754 | solveGridDomainAxisRef(false); |
---|
| 755 | |
---|
| 756 | if (hasClient && !hasServer) |
---|
| 757 | { |
---|
| 758 | solveTransformedGrid(); |
---|
| 759 | } |
---|
| 760 | |
---|
| 761 | solveGridDomainAxisRef(false); |
---|
| 762 | } |
---|
| 763 | } |
---|
| 764 | |
---|
| 765 | void CField::checkGridOfEnabledFields() |
---|
| 766 | { |
---|
| 767 | solveCheckMaskIndex(false); |
---|
| 768 | } |
---|
| 769 | |
---|
| 770 | void CField::sendGridOfEnabledFields() |
---|
| 771 | { |
---|
| 772 | solveGridDomainAxisRef(true); |
---|
| 773 | solveCheckMaskIndex(true); |
---|
| 774 | } |
---|
| 775 | |
---|
| 776 | |
---|
| 777 | void CField::solveOnlyReferenceEnabledField(bool doSending2Server) |
---|
| 778 | { |
---|
| 779 | CContext* context = CContext::getCurrent(); |
---|
| 780 | if (!isReferenceSolved) |
---|
| 781 | { |
---|
| 782 | isReferenceSolved = true; |
---|
| 783 | |
---|
| 784 | if (context->hasClient && !context->hasServer) |
---|
| 785 | { |
---|
| 786 | solveRefInheritance(true); |
---|
| 787 | if (hasDirectFieldReference()) getDirectFieldReference()->solveOnlyReferenceEnabledField(false); |
---|
| 788 | } |
---|
[1144] | 789 | |
---|
[1025] | 790 | if (context->hasServer) |
---|
| 791 | solveServerOperation(); |
---|
| 792 | |
---|
| 793 | solveGridReference(); |
---|
| 794 | |
---|
| 795 | if (context->hasClient && !context->hasServer) |
---|
| 796 | { |
---|
| 797 | solveGenerateGrid(); |
---|
| 798 | buildGridTransformationGraph(); |
---|
| 799 | } |
---|
| 800 | } |
---|
| 801 | } |
---|
| 802 | |
---|
[823] | 803 | void CField::solveAllReferenceEnabledField(bool doSending2Server) |
---|
| 804 | { |
---|
| 805 | CContext* context = CContext::getCurrent(); |
---|
| 806 | solveOnlyReferenceEnabledField(doSending2Server); |
---|
| 807 | |
---|
| 808 | if (!areAllReferenceSolved) |
---|
| 809 | { |
---|
| 810 | areAllReferenceSolved = true; |
---|
[1144] | 811 | |
---|
[983] | 812 | if (context->hasClient && !context->hasServer) |
---|
[823] | 813 | { |
---|
| 814 | solveRefInheritance(true); |
---|
| 815 | if (hasDirectFieldReference()) getDirectFieldReference()->solveAllReferenceEnabledField(false); |
---|
| 816 | } |
---|
[1144] | 817 | else if (context->hasServer) |
---|
[823] | 818 | solveServerOperation(); |
---|
| 819 | |
---|
| 820 | solveGridReference(); |
---|
| 821 | } |
---|
| 822 | |
---|
| 823 | solveGridDomainAxisRef(doSending2Server); |
---|
| 824 | |
---|
[1021] | 825 | if (context->hasClient && !context->hasServer) |
---|
[619] | 826 | { |
---|
| 827 | solveTransformedGrid(); |
---|
| 828 | } |
---|
[687] | 829 | |
---|
[823] | 830 | solveCheckMaskIndex(doSending2Server); |
---|
[509] | 831 | } |
---|
| 832 | |
---|
[731] | 833 | std::map<int, StdSize> CField::getGridAttributesBufferSize() |
---|
[509] | 834 | { |
---|
[731] | 835 | return grid->getAttributesBufferSize(); |
---|
[509] | 836 | } |
---|
| 837 | |
---|
[1099] | 838 | std::vector<std::map<int, StdSize> > CField::getGridDataBufferSize() |
---|
[731] | 839 | { |
---|
| 840 | return grid->getDataBufferSize(getId()); |
---|
| 841 | } |
---|
| 842 | |
---|
[219] | 843 | //---------------------------------------------------------------- |
---|
| 844 | |
---|
[645] | 845 | void CField::solveServerOperation(void) |
---|
[219] | 846 | { |
---|
[640] | 847 | CContext* context = CContext::getCurrent(); |
---|
[509] | 848 | |
---|
[640] | 849 | if (!context->hasServer || !hasOutputFile) return; |
---|
| 850 | |
---|
[645] | 851 | if (freq_op.isEmpty()) |
---|
| 852 | freq_op.setValue(TimeStep); |
---|
[509] | 853 | |
---|
[538] | 854 | if (freq_offset.isEmpty()) |
---|
| 855 | freq_offset.setValue(NoneDu); |
---|
[219] | 856 | |
---|
[645] | 857 | freq_operation_srv = file->output_freq.getValue(); |
---|
| 858 | freq_write_srv = file->output_freq.getValue(); |
---|
[509] | 859 | |
---|
[651] | 860 | lastlast_Write_srv = context->getCalendar()->getInitDate(); |
---|
| 861 | last_Write_srv = context->getCalendar()->getInitDate(); |
---|
| 862 | last_operation_srv = context->getCalendar()->getInitDate(); |
---|
[509] | 863 | |
---|
[645] | 864 | const CDuration toffset = freq_operation_srv - freq_offset.getValue() - context->getCalendar()->getTimeStep(); |
---|
[651] | 865 | last_operation_srv = last_operation_srv - toffset; |
---|
[509] | 866 | |
---|
[645] | 867 | if (operation.isEmpty()) |
---|
| 868 | ERROR("void CField::solveServerOperation(void)", |
---|
| 869 | << "An operation must be defined for field \"" << getId() << "\"."); |
---|
[509] | 870 | |
---|
[645] | 871 | boost::shared_ptr<func::CFunctor> functor; |
---|
| 872 | CArray<double, 1> dummyData; |
---|
[598] | 873 | |
---|
[562] | 874 | #define DECLARE_FUNCTOR(MType, mtype) \ |
---|
[645] | 875 | if (operation.getValue().compare(#mtype) == 0) \ |
---|
[470] | 876 | { \ |
---|
[645] | 877 | functor.reset(new func::C##MType(dummyData)); \ |
---|
| 878 | } |
---|
[509] | 879 | |
---|
[219] | 880 | #include "functor_type.conf" |
---|
[509] | 881 | |
---|
[645] | 882 | if (!functor) |
---|
| 883 | ERROR("void CField::solveServerOperation(void)", |
---|
| 884 | << "\"" << operation << "\" is not a valid operation."); |
---|
| 885 | |
---|
| 886 | operationTimeType = functor->timeType(); |
---|
[219] | 887 | } |
---|
[509] | 888 | |
---|
[219] | 889 | //---------------------------------------------------------------- |
---|
[640] | 890 | |
---|
| 891 | /*! |
---|
| 892 | * Constructs the graph filter for the field, enabling or not the data output. |
---|
| 893 | * This method should not be called more than once with enableOutput equal to true. |
---|
| 894 | * |
---|
| 895 | * \param gc the garbage collector to use when building the filter graph |
---|
| 896 | * \param enableOutput must be true when the field data is to be |
---|
| 897 | * read by the client or/and written to a file |
---|
| 898 | */ |
---|
| 899 | void CField::buildFilterGraph(CGarbageCollector& gc, bool enableOutput) |
---|
[1144] | 900 | { |
---|
[1129] | 901 | if (!isReferenceSolvedAndTransformed) solveAllEnabledFieldsAndTransform(); |
---|
[1025] | 902 | CContext* context = CContext::getCurrent(); |
---|
| 903 | bool hasWriterServer = context->hasServer && !context->hasClient; |
---|
| 904 | bool hasIntermediateServer = context->hasServer && context->hasClient; |
---|
[641] | 905 | |
---|
[1025] | 906 | if (hasWriterServer) |
---|
[640] | 907 | { |
---|
[1025] | 908 | if (!instantDataFilter) |
---|
[1027] | 909 | instantDataFilter = clientSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid)); |
---|
[1025] | 910 | |
---|
| 911 | // If the field data is to be read by the client or/and written to a file |
---|
| 912 | if (enableOutput && !storeFilter && !fileWriterFilter) |
---|
| 913 | { |
---|
| 914 | if (file && (file->mode.isEmpty() || file->mode == CFile::mode_attr::write)) |
---|
| 915 | { |
---|
| 916 | fileServerWriterFilter = boost::shared_ptr<CFileServerWriterFilter>(new CFileServerWriterFilter(gc, this)); |
---|
| 917 | instantDataFilter->connectOutput(fileServerWriterFilter, 0); |
---|
| 918 | } |
---|
| 919 | } |
---|
| 920 | } |
---|
| 921 | else if (hasIntermediateServer) |
---|
| 922 | { |
---|
| 923 | if (!instantDataFilter) |
---|
[1027] | 924 | instantDataFilter = clientSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid)); |
---|
[1025] | 925 | |
---|
| 926 | // If the field data is to be read by the client or/and written to a file |
---|
| 927 | if (enableOutput && !storeFilter && !fileWriterFilter) |
---|
| 928 | { |
---|
| 929 | if (file && (file->mode.isEmpty() || file->mode == CFile::mode_attr::write)) |
---|
| 930 | { |
---|
| 931 | fileWriterFilter = boost::shared_ptr<CFileWriterFilter>(new CFileWriterFilter(gc, this)); |
---|
| 932 | instantDataFilter->connectOutput(fileWriterFilter, 0); |
---|
| 933 | } |
---|
| 934 | } |
---|
| 935 | } |
---|
| 936 | else |
---|
| 937 | { |
---|
| 938 | // Start by building a filter which can provide the field's instant data |
---|
| 939 | if (!instantDataFilter) |
---|
| 940 | { |
---|
| 941 | // Check if we have an expression to parse |
---|
[1021] | 942 | if (hasExpression()) |
---|
[1025] | 943 | { |
---|
[1021] | 944 | boost::scoped_ptr<IFilterExprNode> expr(parseExpr(getExpression() + '\0')); |
---|
| 945 | boost::shared_ptr<COutputPin> filter = expr->reduce(gc, *this); |
---|
| 946 | |
---|
| 947 | // Check if a spatial transformation is needed |
---|
| 948 | if (!field_ref.isEmpty()) |
---|
| 949 | { |
---|
| 950 | CGrid* gridRef = CField::get(field_ref)->grid; |
---|
| 951 | |
---|
| 952 | if (grid && grid != gridRef && grid->hasTransform()) |
---|
| 953 | { |
---|
| 954 | double defaultValue = !default_value.isEmpty() ? default_value : 0.0; |
---|
| 955 | std::pair<boost::shared_ptr<CFilter>, boost::shared_ptr<CFilter> > filters = CSpatialTransformFilter::buildFilterGraph(gc, gridRef, grid, defaultValue); |
---|
| 956 | |
---|
| 957 | filter->connectOutput(filters.first, 0); |
---|
| 958 | filter = filters.second; |
---|
| 959 | } |
---|
| 960 | } |
---|
| 961 | |
---|
| 962 | instantDataFilter = filter; |
---|
[1025] | 963 | } |
---|
| 964 | // Check if we have a reference on another field |
---|
| 965 | else if (!field_ref.isEmpty()) |
---|
| 966 | instantDataFilter = getFieldReference(gc); |
---|
| 967 | // Check if the data is to be read from a file |
---|
| 968 | else if (file && !file->mode.isEmpty() && file->mode == CFile::mode_attr::read) |
---|
[1021] | 969 | instantDataFilter = serverSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid, |
---|
| 970 | freq_offset.isEmpty() ? NoneDu : freq_offset, |
---|
| 971 | true)); |
---|
[1025] | 972 | else // The data might be passed from the model |
---|
[1021] | 973 | instantDataFilter = clientSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid)); |
---|
[1025] | 974 | } |
---|
[640] | 975 | |
---|
[1025] | 976 | // If the field data is to be read by the client or/and written to a file |
---|
| 977 | if (enableOutput && !storeFilter && !fileWriterFilter) |
---|
[640] | 978 | { |
---|
[1025] | 979 | if (!read_access.isEmpty() && read_access) |
---|
| 980 | { |
---|
| 981 | storeFilter = boost::shared_ptr<CStoreFilter>(new CStoreFilter(gc, CContext::getCurrent(), grid)); |
---|
| 982 | instantDataFilter->connectOutput(storeFilter, 0); |
---|
| 983 | } |
---|
[640] | 984 | |
---|
[1025] | 985 | if (file && (file->mode.isEmpty() || file->mode == CFile::mode_attr::write)) |
---|
| 986 | { |
---|
| 987 | fileWriterFilter = boost::shared_ptr<CFileWriterFilter>(new CFileWriterFilter(gc, this)); |
---|
| 988 | getTemporalDataFilter(gc, file->output_freq)->connectOutput(fileWriterFilter, 0); |
---|
| 989 | } |
---|
[640] | 990 | } |
---|
| 991 | } |
---|
| 992 | } |
---|
| 993 | |
---|
[1021] | 994 | |
---|
[642] | 995 | /*! |
---|
[737] | 996 | * Returns the filter needed to handle the field reference. |
---|
| 997 | * This method should only be called when building the filter graph corresponding to the field. |
---|
| 998 | * |
---|
| 999 | * \param gc the garbage collector to use |
---|
| 1000 | * \return the output pin corresponding to the field reference |
---|
| 1001 | */ |
---|
[1021] | 1002 | boost::shared_ptr<COutputPin> CField::getFieldReference(CGarbageCollector& gc) |
---|
| 1003 | { |
---|
| 1004 | if (instantDataFilter || field_ref.isEmpty()) |
---|
| 1005 | ERROR("COutputPin* CField::getFieldReference(CGarbageCollector& gc)", |
---|
| 1006 | "Impossible to get the field reference for a field which has already been parsed or which does not have a field_ref."); |
---|
[737] | 1007 | |
---|
[1021] | 1008 | CField* fieldRef = CField::get(field_ref); |
---|
| 1009 | fieldRef->buildFilterGraph(gc, false); |
---|
[737] | 1010 | |
---|
[1021] | 1011 | std::pair<boost::shared_ptr<CFilter>, boost::shared_ptr<CFilter> > filters; |
---|
| 1012 | // Check if a spatial transformation is needed |
---|
| 1013 | if (grid && grid != fieldRef->grid && grid->hasTransform()) |
---|
| 1014 | { |
---|
| 1015 | double defaultValue = !default_value.isEmpty() ? default_value : 0.0; |
---|
| 1016 | filters = CSpatialTransformFilter::buildFilterGraph(gc, fieldRef->grid, grid, defaultValue); |
---|
| 1017 | } |
---|
| 1018 | else |
---|
| 1019 | filters.first = filters.second = boost::shared_ptr<CFilter>(new CPassThroughFilter(gc)); |
---|
[873] | 1020 | |
---|
[1021] | 1021 | fieldRef->getInstantDataFilter()->connectOutput(filters.first, 0); |
---|
[737] | 1022 | |
---|
[1021] | 1023 | return filters.second; |
---|
| 1024 | } |
---|
[737] | 1025 | |
---|
| 1026 | /*! |
---|
| 1027 | * Returns the filter needed to handle a self reference in the field's expression. |
---|
| 1028 | * If the needed filter does not exist, it is created, otherwise it is reused. |
---|
[642] | 1029 | * This method should only be called when building the filter graph corresponding |
---|
| 1030 | * to the field's expression. |
---|
| 1031 | * |
---|
| 1032 | * \param gc the garbage collector to use |
---|
| 1033 | * \return the output pin corresponding to a self reference |
---|
| 1034 | */ |
---|
| 1035 | boost::shared_ptr<COutputPin> CField::getSelfReference(CGarbageCollector& gc) |
---|
| 1036 | { |
---|
[1021] | 1037 | if (instantDataFilter || !hasExpression()) |
---|
[642] | 1038 | ERROR("COutputPin* CField::getSelfReference(CGarbageCollector& gc)", |
---|
| 1039 | "Impossible to add a self reference to a field which has already been parsed or which does not have an expression."); |
---|
| 1040 | |
---|
[737] | 1041 | if (!selfReferenceFilter) |
---|
| 1042 | { |
---|
[741] | 1043 | if (file && !file->mode.isEmpty() && file->mode == CFile::mode_attr::read) |
---|
| 1044 | { |
---|
| 1045 | if (!serverSourceFilter) |
---|
[1021] | 1046 | serverSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid, |
---|
| 1047 | freq_offset.isEmpty() ? NoneDu : freq_offset, |
---|
| 1048 | true)); |
---|
[741] | 1049 | selfReferenceFilter = serverSourceFilter; |
---|
| 1050 | } |
---|
| 1051 | else if (!field_ref.isEmpty()) |
---|
[1021] | 1052 | { |
---|
| 1053 | CField* fieldRef = CField::get(field_ref); |
---|
| 1054 | fieldRef->buildFilterGraph(gc, false); |
---|
| 1055 | selfReferenceFilter = fieldRef->getInstantDataFilter(); |
---|
| 1056 | } |
---|
[737] | 1057 | else |
---|
| 1058 | { |
---|
| 1059 | if (!clientSourceFilter) |
---|
[1021] | 1060 | clientSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid)); |
---|
[642] | 1061 | |
---|
[737] | 1062 | selfReferenceFilter = clientSourceFilter; |
---|
| 1063 | } |
---|
| 1064 | } |
---|
| 1065 | |
---|
| 1066 | return selfReferenceFilter; |
---|
[642] | 1067 | } |
---|
| 1068 | |
---|
[643] | 1069 | /*! |
---|
| 1070 | * Returns the temporal filter corresponding to the field's temporal operation |
---|
| 1071 | * for the specified operation frequency. The filter is created if it does not |
---|
| 1072 | * exist, otherwise it is reused. |
---|
| 1073 | * |
---|
| 1074 | * \param gc the garbage collector to use |
---|
| 1075 | * \param outFreq the operation frequency, i.e. the frequency at which the output data will be computed |
---|
| 1076 | * \return the output pin corresponding to the requested temporal filter |
---|
| 1077 | */ |
---|
| 1078 | boost::shared_ptr<COutputPin> CField::getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq) |
---|
| 1079 | { |
---|
| 1080 | std::map<CDuration, boost::shared_ptr<COutputPin> >::iterator it = temporalDataFilters.find(outFreq); |
---|
| 1081 | |
---|
| 1082 | if (it == temporalDataFilters.end()) |
---|
| 1083 | { |
---|
| 1084 | if (operation.isEmpty()) |
---|
| 1085 | ERROR("void CField::getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq)", |
---|
| 1086 | << "An operation must be defined for field \"" << getId() << "\"."); |
---|
| 1087 | |
---|
| 1088 | if (freq_op.isEmpty()) |
---|
| 1089 | freq_op.setValue(TimeStep); |
---|
| 1090 | if (freq_offset.isEmpty()) |
---|
| 1091 | freq_offset.setValue(NoneDu); |
---|
| 1092 | |
---|
| 1093 | const bool ignoreMissingValue = (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true); |
---|
| 1094 | |
---|
| 1095 | boost::shared_ptr<CTemporalFilter> temporalFilter(new CTemporalFilter(gc, operation, |
---|
| 1096 | CContext::getCurrent()->getCalendar()->getInitDate(), |
---|
| 1097 | freq_op, freq_offset, outFreq, |
---|
| 1098 | ignoreMissingValue, ignoreMissingValue ? default_value : 0.0)); |
---|
| 1099 | instantDataFilter->connectOutput(temporalFilter, 0); |
---|
| 1100 | |
---|
| 1101 | it = temporalDataFilters.insert(std::make_pair(outFreq, temporalFilter)).first; |
---|
| 1102 | } |
---|
| 1103 | |
---|
| 1104 | return it->second; |
---|
| 1105 | } |
---|
| 1106 | |
---|
[640] | 1107 | //---------------------------------------------------------------- |
---|
[369] | 1108 | /* |
---|
[562] | 1109 | void CField::fromBinary(StdIStream& is) |
---|
[219] | 1110 | { |
---|
| 1111 | SuperClass::fromBinary(is); |
---|
| 1112 | #define CLEAR_ATT(name_)\ |
---|
[369] | 1113 | SuperClassAttribute::operator[](#name_)->reset() |
---|
[219] | 1114 | |
---|
| 1115 | CLEAR_ATT(domain_ref); |
---|
| 1116 | CLEAR_ATT(axis_ref); |
---|
| 1117 | #undef CLEAR_ATT |
---|
| 1118 | |
---|
| 1119 | } |
---|
[369] | 1120 | */ |
---|
[219] | 1121 | //---------------------------------------------------------------- |
---|
| 1122 | |
---|
| 1123 | void CField::solveGridReference(void) |
---|
| 1124 | { |
---|
[887] | 1125 | if (grid_ref.isEmpty() && domain_ref.isEmpty() && axis_ref.isEmpty() && scalar_ref.isEmpty()) |
---|
[742] | 1126 | { |
---|
| 1127 | ERROR("CField::solveGridReference(void)", |
---|
[770] | 1128 | << "A grid must be defined for field '" << getFieldOutputName() << "' ."); |
---|
[742] | 1129 | } |
---|
[887] | 1130 | else if (!grid_ref.isEmpty() && (!domain_ref.isEmpty() || !axis_ref.isEmpty() || !scalar_ref.isEmpty())) |
---|
[219] | 1131 | { |
---|
[744] | 1132 | ERROR("CField::solveGridReference(void)", |
---|
[887] | 1133 | << "Field '" << getFieldOutputName() << "' has both a grid and a domain/axis/scalar." << std::endl |
---|
| 1134 | << "Please define either 'grid_ref' or 'domain_ref'/'axis_ref'/'scalar_ref'."); |
---|
[219] | 1135 | } |
---|
| 1136 | |
---|
[744] | 1137 | if (grid_ref.isEmpty()) |
---|
[219] | 1138 | { |
---|
[744] | 1139 | std::vector<CDomain*> vecDom; |
---|
| 1140 | std::vector<CAxis*> vecAxis; |
---|
[887] | 1141 | std::vector<CScalar*> vecScalar; |
---|
[894] | 1142 | std::vector<int> axisDomainOrderTmp; |
---|
| 1143 | |
---|
[744] | 1144 | if (!domain_ref.isEmpty()) |
---|
| 1145 | { |
---|
[823] | 1146 | StdString tmp = domain_ref.getValue(); |
---|
[744] | 1147 | if (CDomain::has(domain_ref)) |
---|
[894] | 1148 | { |
---|
[744] | 1149 | vecDom.push_back(CDomain::get(domain_ref)); |
---|
[894] | 1150 | axisDomainOrderTmp.push_back(2); |
---|
| 1151 | } |
---|
[744] | 1152 | else |
---|
[219] | 1153 | ERROR("CField::solveGridReference(void)", |
---|
[744] | 1154 | << "Invalid reference to domain '" << domain_ref.getValue() << "'."); |
---|
| 1155 | } |
---|
[219] | 1156 | |
---|
[744] | 1157 | if (!axis_ref.isEmpty()) |
---|
[742] | 1158 | { |
---|
[744] | 1159 | if (CAxis::has(axis_ref)) |
---|
[894] | 1160 | { |
---|
[744] | 1161 | vecAxis.push_back(CAxis::get(axis_ref)); |
---|
[894] | 1162 | axisDomainOrderTmp.push_back(1); |
---|
| 1163 | } |
---|
[744] | 1164 | else |
---|
| 1165 | ERROR("CField::solveGridReference(void)", |
---|
| 1166 | << "Invalid reference to axis '" << axis_ref.getValue() << "'."); |
---|
[742] | 1167 | } |
---|
[744] | 1168 | |
---|
[887] | 1169 | if (!scalar_ref.isEmpty()) |
---|
| 1170 | { |
---|
| 1171 | if (CScalar::has(scalar_ref)) |
---|
[894] | 1172 | { |
---|
[887] | 1173 | vecScalar.push_back(CScalar::get(scalar_ref)); |
---|
[894] | 1174 | axisDomainOrderTmp.push_back(0); |
---|
| 1175 | } |
---|
[887] | 1176 | else |
---|
| 1177 | ERROR("CField::solveGridReference(void)", |
---|
| 1178 | << "Invalid reference to scalar '" << scalar_ref.getValue() << "'."); |
---|
| 1179 | } |
---|
[894] | 1180 | |
---|
| 1181 | CArray<int,1> axisDomainOrder(axisDomainOrderTmp.size()); |
---|
| 1182 | for (int idx = 0; idx < axisDomainOrderTmp.size(); ++idx) |
---|
| 1183 | { |
---|
| 1184 | axisDomainOrder(idx) = axisDomainOrderTmp[idx]; |
---|
| 1185 | } |
---|
[887] | 1186 | |
---|
[745] | 1187 | // Warning: the gridId shouldn't be set as the grid_ref since it could be inherited |
---|
[894] | 1188 | StdString gridId = CGrid::generateId(vecDom, vecAxis, vecScalar,axisDomainOrder); |
---|
[745] | 1189 | if (CGrid::has(gridId)) |
---|
| 1190 | this->grid = CGrid::get(gridId); |
---|
| 1191 | else |
---|
[894] | 1192 | this->grid = CGrid::createGrid(gridId, vecDom, vecAxis, vecScalar,axisDomainOrder); |
---|
[219] | 1193 | } |
---|
[586] | 1194 | else |
---|
| 1195 | { |
---|
[744] | 1196 | if (CGrid::has(grid_ref)) |
---|
| 1197 | this->grid = CGrid::get(grid_ref); |
---|
| 1198 | else |
---|
| 1199 | ERROR("CField::solveGridReference(void)", |
---|
| 1200 | << "Invalid reference to grid '" << grid_ref.getValue() << "'."); |
---|
[586] | 1201 | } |
---|
[509] | 1202 | } |
---|
[459] | 1203 | |
---|
[509] | 1204 | void CField::solveGridDomainAxisRef(bool checkAtt) |
---|
| 1205 | { |
---|
| 1206 | grid->solveDomainAxisRef(checkAtt); |
---|
[219] | 1207 | } |
---|
| 1208 | |
---|
[509] | 1209 | void CField::solveCheckMaskIndex(bool doSendingIndex) |
---|
| 1210 | { |
---|
| 1211 | grid->checkMaskIndex(doSendingIndex); |
---|
| 1212 | } |
---|
[219] | 1213 | |
---|
[619] | 1214 | void CField::solveTransformedGrid() |
---|
| 1215 | { |
---|
[746] | 1216 | if (grid && !grid->isTransformed() && hasDirectFieldReference() && grid != getDirectFieldReference()->grid) |
---|
[790] | 1217 | { |
---|
| 1218 | std::vector<CGrid*> grids; |
---|
| 1219 | // Source grid |
---|
| 1220 | grids.push_back(getDirectFieldReference()->grid); |
---|
| 1221 | // Intermediate grids |
---|
| 1222 | if (!grid_path.isEmpty()) |
---|
| 1223 | { |
---|
| 1224 | std::string gridId; |
---|
| 1225 | size_t start = 0, end; |
---|
| 1226 | |
---|
| 1227 | do |
---|
| 1228 | { |
---|
| 1229 | end = grid_path.getValue().find(',', start); |
---|
| 1230 | if (end != std::string::npos) |
---|
| 1231 | { |
---|
| 1232 | gridId = grid_path.getValue().substr(start, end - start); |
---|
| 1233 | start = end + 1; |
---|
| 1234 | } |
---|
| 1235 | else |
---|
| 1236 | gridId = grid_path.getValue().substr(start); |
---|
| 1237 | |
---|
| 1238 | if (!CGrid::has(gridId)) |
---|
| 1239 | ERROR("void CField::solveTransformedGrid()", |
---|
| 1240 | << "Invalid grid_path, the grid '" << gridId << "' does not exist."); |
---|
| 1241 | |
---|
| 1242 | grids.push_back(CGrid::get(gridId)); |
---|
| 1243 | } |
---|
| 1244 | while (end != std::string::npos); |
---|
| 1245 | } |
---|
| 1246 | // Destination grid |
---|
| 1247 | grids.push_back(grid); |
---|
| 1248 | |
---|
| 1249 | for (size_t i = 0, count = grids.size() - 1; i < count; ++i) |
---|
| 1250 | { |
---|
| 1251 | CGrid *gridSrc = grids[i]; |
---|
| 1252 | CGrid *gridDest = grids[i + 1]; |
---|
| 1253 | if (!gridDest->isTransformed()) |
---|
| 1254 | gridDest->transformGrid(gridSrc); |
---|
| 1255 | } |
---|
| 1256 | } |
---|
[934] | 1257 | else if (grid && grid->hasTransform() && !grid->isTransformed()) |
---|
| 1258 | { |
---|
[1021] | 1259 | // Temporarily deactivate the self-transformation of grid |
---|
| 1260 | //grid->transformGrid(grid); |
---|
[934] | 1261 | } |
---|
[619] | 1262 | } |
---|
| 1263 | |
---|
[687] | 1264 | void CField::solveGenerateGrid() |
---|
| 1265 | { |
---|
[746] | 1266 | if (grid && !grid->isTransformed() && hasDirectFieldReference() && grid != getDirectFieldReference()->grid) |
---|
[687] | 1267 | grid->completeGrid(getDirectFieldReference()->grid); |
---|
[775] | 1268 | else |
---|
| 1269 | grid->completeGrid(); |
---|
[687] | 1270 | } |
---|
| 1271 | |
---|
[775] | 1272 | void CField::solveGridDomainAxisBaseRef() |
---|
| 1273 | { |
---|
| 1274 | grid->solveDomainAxisRef(false); |
---|
| 1275 | grid->solveDomainAxisBaseRef(); |
---|
| 1276 | } |
---|
| 1277 | |
---|
[219] | 1278 | ///------------------------------------------------------------------- |
---|
| 1279 | |
---|
| 1280 | template <> |
---|
[562] | 1281 | void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void) |
---|
[219] | 1282 | { |
---|
| 1283 | if (this->group_ref.isEmpty()) return; |
---|
| 1284 | StdString gref = this->group_ref.getValue(); |
---|
| 1285 | |
---|
[346] | 1286 | if (!CFieldGroup::has(gref)) |
---|
[219] | 1287 | ERROR("CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void)", |
---|
| 1288 | << "[ gref = " << gref << "]" |
---|
| 1289 | << " invalid group name !"); |
---|
| 1290 | |
---|
[347] | 1291 | CFieldGroup* group = CFieldGroup::get(gref); |
---|
| 1292 | CFieldGroup* owner = CFieldGroup::get(boost::polymorphic_downcast<CFieldGroup*>(this)); |
---|
[219] | 1293 | |
---|
[347] | 1294 | std::vector<CField*> allChildren = group->getAllChildren(); |
---|
[562] | 1295 | std::vector<CField*>::iterator it = allChildren.begin(), end = allChildren.end(); |
---|
[509] | 1296 | |
---|
[219] | 1297 | for (; it != end; it++) |
---|
| 1298 | { |
---|
[347] | 1299 | CField* child = *it; |
---|
[562] | 1300 | if (child->hasId()) owner->createChild()->field_ref.setValue(child->getId()); |
---|
[509] | 1301 | |
---|
[219] | 1302 | } |
---|
| 1303 | } |
---|
[509] | 1304 | |
---|
[464] | 1305 | void CField::scaleFactorAddOffset(double scaleFactor, double addOffset) |
---|
| 1306 | { |
---|
[1136] | 1307 | recvDataSrv = (recvDataSrv - addOffset) / scaleFactor; |
---|
[464] | 1308 | } |
---|
[509] | 1309 | |
---|
[599] | 1310 | void CField::invertScaleFactorAddOffset(double scaleFactor, double addOffset) |
---|
| 1311 | { |
---|
[1136] | 1312 | recvDataSrv = recvDataSrv * scaleFactor + addOffset; |
---|
[599] | 1313 | } |
---|
| 1314 | |
---|
[567] | 1315 | void CField::outputField(CArray<double,1>& fieldOut) |
---|
[1136] | 1316 | { |
---|
[1129] | 1317 | CArray<size_t,1>& outIndexClient = grid->localIndexToWriteOnClient; |
---|
| 1318 | CArray<size_t,1>& outIndexServer = grid->localIndexToWriteOnServer; |
---|
| 1319 | for (size_t idx = 0; idx < outIndexServer.numElements(); ++idx) |
---|
| 1320 | { |
---|
| 1321 | fieldOut(outIndexServer(idx)) = recvDataSrv(outIndexClient(idx)); |
---|
| 1322 | } |
---|
[1136] | 1323 | } |
---|
[1129] | 1324 | |
---|
[1136] | 1325 | void CField::inputField(CArray<double,1>& fieldIn) |
---|
| 1326 | { |
---|
| 1327 | CArray<size_t,1>& outIndexClient = grid->localIndexToWriteOnClient; |
---|
| 1328 | CArray<size_t,1>& outIndexServer = grid->localIndexToWriteOnServer; |
---|
| 1329 | for (size_t idx = 0; idx < outIndexServer.numElements(); ++idx) |
---|
[599] | 1330 | { |
---|
[1136] | 1331 | recvDataSrv(outIndexClient(idx)) = fieldIn(outIndexServer(idx)); |
---|
[599] | 1332 | } |
---|
| 1333 | |
---|
| 1334 | } |
---|
| 1335 | |
---|
[676] | 1336 | void CField::outputCompressedField(CArray<double,1>& fieldOut) |
---|
| 1337 | { |
---|
[1143] | 1338 | CArray<size_t,1>& outIndexClient = grid->localIndexToWriteOnClient; |
---|
| 1339 | CArray<size_t,1>& outIndexServer = grid->localIndexToWriteOnServer; |
---|
| 1340 | for (size_t idx = 0; idx < outIndexServer.numElements(); ++idx) |
---|
[676] | 1341 | { |
---|
[1143] | 1342 | fieldOut((idx)) = recvDataSrv(outIndexClient(idx)); |
---|
[676] | 1343 | } |
---|
| 1344 | } |
---|
| 1345 | |
---|
[219] | 1346 | ///------------------------------------------------------------------- |
---|
| 1347 | |
---|
[562] | 1348 | void CField::parse(xml::CXMLNode& node) |
---|
[459] | 1349 | { |
---|
| 1350 | SuperClass::parse(node); |
---|
[562] | 1351 | if (!node.getContent(this->content)) |
---|
[472] | 1352 | { |
---|
[476] | 1353 | if (node.goToChildElement()) |
---|
[472] | 1354 | { |
---|
[476] | 1355 | do |
---|
| 1356 | { |
---|
[562] | 1357 | if (node.getElementName() == "variable" || node.getElementName() == "variable_group") this->getVirtualVariableGroup()->parseChild(node); |
---|
| 1358 | } while (node.goToNextElement()); |
---|
[476] | 1359 | node.goToParentElement(); |
---|
| 1360 | } |
---|
[472] | 1361 | } |
---|
[459] | 1362 | } |
---|
[509] | 1363 | |
---|
| 1364 | /*! |
---|
| 1365 | This function retrieves Id of corresponding domain_ref and axis_ref (if any) |
---|
| 1366 | of a field. In some cases, only domain exists but axis doesn't |
---|
| 1367 | \return pair of Domain and Axis id |
---|
| 1368 | */ |
---|
[887] | 1369 | const std::vector<StdString>& CField::getRefDomainAxisIds() |
---|
[569] | 1370 | { |
---|
| 1371 | CGrid* cgPtr = getRelGrid(); |
---|
| 1372 | if (NULL != cgPtr) |
---|
| 1373 | { |
---|
| 1374 | std::vector<StdString>::iterator it; |
---|
| 1375 | if (!domain_ref.isEmpty()) |
---|
| 1376 | { |
---|
| 1377 | std::vector<StdString> domainList = cgPtr->getDomainList(); |
---|
| 1378 | it = std::find(domainList.begin(), domainList.end(), domain_ref.getValue()); |
---|
[887] | 1379 | if (domainList.end() != it) domAxisScalarIds_[0] = *it; |
---|
[569] | 1380 | } |
---|
[472] | 1381 | |
---|
[569] | 1382 | if (!axis_ref.isEmpty()) |
---|
| 1383 | { |
---|
| 1384 | std::vector<StdString> axisList = cgPtr->getAxisList(); |
---|
| 1385 | it = std::find(axisList.begin(), axisList.end(), axis_ref.getValue()); |
---|
[887] | 1386 | if (axisList.end() != it) domAxisScalarIds_[1] = *it; |
---|
[569] | 1387 | } |
---|
[887] | 1388 | |
---|
| 1389 | if (!scalar_ref.isEmpty()) |
---|
| 1390 | { |
---|
| 1391 | std::vector<StdString> scalarList = cgPtr->getScalarList(); |
---|
| 1392 | it = std::find(scalarList.begin(), scalarList.end(), scalar_ref.getValue()); |
---|
| 1393 | if (scalarList.end() != it) domAxisScalarIds_[2] = *it; |
---|
| 1394 | } |
---|
[569] | 1395 | } |
---|
[887] | 1396 | return (domAxisScalarIds_); |
---|
[569] | 1397 | } |
---|
| 1398 | |
---|
[472] | 1399 | CVariable* CField::addVariable(const string& id) |
---|
| 1400 | { |
---|
[562] | 1401 | return vVariableGroup->createChild(id); |
---|
[472] | 1402 | } |
---|
| 1403 | |
---|
| 1404 | CVariableGroup* CField::addVariableGroup(const string& id) |
---|
| 1405 | { |
---|
[562] | 1406 | return vVariableGroup->createChildGroup(id); |
---|
[472] | 1407 | } |
---|
| 1408 | |
---|
[1021] | 1409 | void CField::sendAddAllVariables(CContextClient* client) |
---|
[1009] | 1410 | { |
---|
| 1411 | std::vector<CVariable*> allVar = getAllVariables(); |
---|
| 1412 | std::vector<CVariable*>::const_iterator it = allVar.begin(); |
---|
| 1413 | std::vector<CVariable*>::const_iterator itE = allVar.end(); |
---|
| 1414 | |
---|
| 1415 | for (; it != itE; ++it) |
---|
| 1416 | { |
---|
[1021] | 1417 | this->sendAddVariable((*it)->getId(), client); |
---|
| 1418 | (*it)->sendAllAttributesToServer(client); |
---|
| 1419 | (*it)->sendValue(client); |
---|
[1009] | 1420 | } |
---|
| 1421 | } |
---|
| 1422 | |
---|
[1021] | 1423 | void CField::sendAddVariable(const string& id, CContextClient* client) |
---|
| 1424 | { |
---|
| 1425 | sendAddItem(id, (int)EVENT_ID_ADD_VARIABLE, client); |
---|
| 1426 | } |
---|
| 1427 | |
---|
[1144] | 1428 | void CField::sendAddVariableGroup(const string& id, CContextClient* client) |
---|
[472] | 1429 | { |
---|
[1144] | 1430 | sendAddItem(id, (int)EVENT_ID_ADD_VARIABLE_GROUP, client); |
---|
[472] | 1431 | } |
---|
[509] | 1432 | |
---|
[472] | 1433 | void CField::recvAddVariable(CEventServer& event) |
---|
| 1434 | { |
---|
[509] | 1435 | |
---|
[562] | 1436 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
[472] | 1437 | string id; |
---|
[562] | 1438 | *buffer >> id; |
---|
| 1439 | get(id)->recvAddVariable(*buffer); |
---|
[472] | 1440 | } |
---|
[509] | 1441 | |
---|
[472] | 1442 | void CField::recvAddVariable(CBufferIn& buffer) |
---|
| 1443 | { |
---|
[562] | 1444 | string id; |
---|
| 1445 | buffer >> id; |
---|
| 1446 | addVariable(id); |
---|
[472] | 1447 | } |
---|
| 1448 | |
---|
| 1449 | void CField::recvAddVariableGroup(CEventServer& event) |
---|
| 1450 | { |
---|
[509] | 1451 | |
---|
[562] | 1452 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
[472] | 1453 | string id; |
---|
[562] | 1454 | *buffer >> id; |
---|
| 1455 | get(id)->recvAddVariableGroup(*buffer); |
---|
[472] | 1456 | } |
---|
[509] | 1457 | |
---|
[472] | 1458 | void CField::recvAddVariableGroup(CBufferIn& buffer) |
---|
| 1459 | { |
---|
[562] | 1460 | string id; |
---|
| 1461 | buffer >> id; |
---|
| 1462 | addVariableGroup(id); |
---|
[472] | 1463 | } |
---|
| 1464 | |
---|
[1021] | 1465 | /*! |
---|
| 1466 | * Returns string arithmetic expression associated to the field. |
---|
| 1467 | * \return if content is defined return content string, otherwise, if "expr" attribute is defined, return expr string. |
---|
| 1468 | */ |
---|
| 1469 | const string& CField::getExpression(void) |
---|
| 1470 | { |
---|
| 1471 | if (!expr.isEmpty() && content.empty()) |
---|
| 1472 | { |
---|
| 1473 | content = expr; |
---|
| 1474 | expr.reset(); |
---|
| 1475 | } |
---|
| 1476 | |
---|
| 1477 | return content; |
---|
| 1478 | } |
---|
| 1479 | |
---|
| 1480 | bool CField::hasExpression(void) const |
---|
| 1481 | { |
---|
| 1482 | return (!expr.isEmpty() || !content.empty()); |
---|
| 1483 | } |
---|
| 1484 | |
---|
| 1485 | |
---|
[540] | 1486 | DEFINE_REF_FUNC(Field,field) |
---|
[335] | 1487 | } // namespace xios |
---|