[266] | 1 | |
---|
[219] | 2 | #include "grid.hpp" |
---|
| 3 | |
---|
[352] | 4 | #include "attribute_template.hpp" |
---|
| 5 | #include "object_template.hpp" |
---|
| 6 | #include "group_template.hpp" |
---|
| 7 | #include "message.hpp" |
---|
[286] | 8 | #include <iostream> |
---|
[352] | 9 | #include "xmlioserver_spl.hpp" |
---|
| 10 | #include "type.hpp" |
---|
| 11 | #include "context.hpp" |
---|
| 12 | #include "context_client.hpp" |
---|
[219] | 13 | |
---|
[335] | 14 | namespace xios { |
---|
[219] | 15 | |
---|
| 16 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 17 | |
---|
| 18 | CGrid::CGrid(void) |
---|
| 19 | : CObjectTemplate<CGrid>(), CGridAttributes() |
---|
| 20 | , withAxis(false), isChecked(false), axis(), domain() |
---|
| 21 | , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1) |
---|
| 22 | { /* Ne rien faire de plus */ } |
---|
| 23 | |
---|
| 24 | CGrid::CGrid(const StdString & id) |
---|
| 25 | : CObjectTemplate<CGrid>(id), CGridAttributes() |
---|
| 26 | , withAxis(false), isChecked(false), axis(), domain() |
---|
| 27 | , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1) |
---|
| 28 | { /* Ne rien faire de plus */ } |
---|
| 29 | |
---|
| 30 | CGrid::~CGrid(void) |
---|
| 31 | { |
---|
[347] | 32 | // this->axis.reset() ; |
---|
| 33 | // this->domain.reset() ; |
---|
[219] | 34 | |
---|
| 35 | for (StdSize i = 0; i < this->storeIndex.size(); i++) |
---|
| 36 | { |
---|
| 37 | this->storeIndex[i].reset(); |
---|
| 38 | this->out_i_index[i].reset(); |
---|
| 39 | this->out_j_index[i].reset(); |
---|
| 40 | this->out_l_index[i].reset(); |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | ///--------------------------------------------------------------- |
---|
| 45 | |
---|
| 46 | StdString CGrid::GetName(void) { return (StdString("grid")); } |
---|
| 47 | StdString CGrid::GetDefName(void) { return (CGrid::GetName()); } |
---|
| 48 | ENodeType CGrid::GetType(void) { return (eGrid); } |
---|
| 49 | |
---|
| 50 | //---------------------------------------------------------------- |
---|
| 51 | |
---|
| 52 | const std::deque<ARRAY(int, 1)> & CGrid::getStoreIndex(void) const |
---|
| 53 | { |
---|
| 54 | return (this->storeIndex ); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | //--------------------------------------------------------------- |
---|
| 58 | |
---|
| 59 | const std::deque<ARRAY(int, 1)> & CGrid::getOutIIndex(void) const |
---|
| 60 | { |
---|
| 61 | return (this->out_i_index ); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | //--------------------------------------------------------------- |
---|
| 65 | |
---|
| 66 | const std::deque<ARRAY(int, 1)> & CGrid::getOutJIndex(void) const |
---|
| 67 | { |
---|
| 68 | return (this->out_j_index ); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | //--------------------------------------------------------------- |
---|
| 72 | |
---|
| 73 | const std::deque<ARRAY(int, 1)> & CGrid::getOutLIndex(void) const |
---|
| 74 | { |
---|
| 75 | return (this->out_l_index ); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | //--------------------------------------------------------------- |
---|
| 79 | |
---|
[347] | 80 | const CAxis* CGrid::getRelAxis (void) const |
---|
[219] | 81 | { |
---|
| 82 | return (this->axis ); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | //--------------------------------------------------------------- |
---|
| 86 | |
---|
[347] | 87 | const CDomain* CGrid::getRelDomain(void) const |
---|
[219] | 88 | { |
---|
| 89 | return (this->domain ); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | //--------------------------------------------------------------- |
---|
| 93 | |
---|
| 94 | bool CGrid::hasAxis(void) const |
---|
| 95 | { |
---|
| 96 | return (this->withAxis); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | //--------------------------------------------------------------- |
---|
| 100 | |
---|
| 101 | StdSize CGrid::getDimension(void) const |
---|
| 102 | { |
---|
| 103 | return ((this->withAxis)?3:2); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | //--------------------------------------------------------------- |
---|
| 107 | |
---|
[351] | 108 | /* |
---|
[266] | 109 | std::vector<StdSize> CGrid::getLocalShape(void) const |
---|
[219] | 110 | { |
---|
| 111 | std::vector<StdSize> retvalue; |
---|
[266] | 112 | retvalue.push_back(domain->zoom_ni_loc.getValue()); |
---|
| 113 | retvalue.push_back(domain->zoom_nj_loc.getValue()); |
---|
[219] | 114 | if (this->withAxis) |
---|
[351] | 115 | retvalue.push_back(this->axis->zoom_size.getValue()); |
---|
[219] | 116 | return (retvalue); |
---|
| 117 | } |
---|
[351] | 118 | */ |
---|
[219] | 119 | //--------------------------------------------------------------- |
---|
| 120 | |
---|
[351] | 121 | /* |
---|
[266] | 122 | StdSize CGrid::getLocalSize(void) const |
---|
[219] | 123 | { |
---|
| 124 | StdSize retvalue = 1; |
---|
[266] | 125 | std::vector<StdSize> shape_ = this->getLocalShape(); |
---|
[219] | 126 | for (StdSize s = 0; s < shape_.size(); s++) |
---|
| 127 | retvalue *= shape_[s]; |
---|
| 128 | return (retvalue); |
---|
| 129 | } |
---|
[351] | 130 | */ |
---|
[266] | 131 | //--------------------------------------------------------------- |
---|
[351] | 132 | /* |
---|
[266] | 133 | std::vector<StdSize> CGrid::getGlobalShape(void) const |
---|
| 134 | { |
---|
| 135 | std::vector<StdSize> retvalue; |
---|
| 136 | retvalue.push_back(domain->ni.getValue()); |
---|
| 137 | retvalue.push_back(domain->nj.getValue()); |
---|
| 138 | if (this->withAxis) |
---|
| 139 | retvalue.push_back(this->axis->size.getValue()); |
---|
| 140 | return (retvalue); |
---|
| 141 | } |
---|
[351] | 142 | */ |
---|
[219] | 143 | //--------------------------------------------------------------- |
---|
[351] | 144 | |
---|
| 145 | /* |
---|
[266] | 146 | StdSize CGrid::getGlobalSize(void) const |
---|
| 147 | { |
---|
| 148 | StdSize retvalue = 1; |
---|
| 149 | std::vector<StdSize> shape_ = this->getGlobalShape(); |
---|
| 150 | for (StdSize s = 0; s < shape_.size(); s++) |
---|
| 151 | retvalue *= shape_[s]; |
---|
| 152 | return (retvalue); |
---|
| 153 | } |
---|
[351] | 154 | */ |
---|
[286] | 155 | StdSize CGrid::getDataSize(void) const |
---|
| 156 | { |
---|
| 157 | StdSize retvalue ; |
---|
| 158 | retvalue=domain->data_ni.getValue() ; |
---|
| 159 | if (domain->data_dim.getValue()==2) retvalue*=domain->data_nj.getValue() ; |
---|
| 160 | if (this->withAxis) retvalue*=this->axis->size.getValue() ; |
---|
| 161 | |
---|
| 162 | return (retvalue); |
---|
| 163 | } |
---|
| 164 | |
---|
[266] | 165 | //--------------------------------------------------------------- |
---|
| 166 | |
---|
[219] | 167 | void CGrid::solveReference(void) |
---|
| 168 | { |
---|
| 169 | if (this->isChecked) return; |
---|
[347] | 170 | CContext* context = CContext::getCurrent() ; |
---|
[300] | 171 | CContextClient* client=context->client ; |
---|
| 172 | |
---|
[219] | 173 | this->solveDomainRef() ; |
---|
| 174 | this->solveAxisRef() ; |
---|
[300] | 175 | if (context->hasClient) |
---|
[219] | 176 | { |
---|
[266] | 177 | |
---|
[219] | 178 | this->computeIndex() ; |
---|
[266] | 179 | ARRAY_CREATE(storeIndex_ , int, 1, [0]); |
---|
| 180 | ARRAY_CREATE(out_l_index_, int, 1, [0]); |
---|
| 181 | ARRAY_CREATE(out_i_index_, int, 1, [0]); |
---|
| 182 | ARRAY_CREATE(out_j_index_, int, 1, [0]); |
---|
| 183 | |
---|
| 184 | this->storeIndex .push_front(storeIndex_); |
---|
| 185 | this->out_i_index.push_front(out_i_index_); |
---|
| 186 | this->out_j_index.push_front(out_j_index_); |
---|
| 187 | this->out_l_index.push_front(out_l_index_); |
---|
[219] | 188 | } |
---|
[300] | 189 | // this->computeIndexServer(); |
---|
[219] | 190 | this->isChecked = true; |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | //--------------------------------------------------------------- |
---|
| 194 | |
---|
| 195 | void CGrid::solveDomainRef(void) |
---|
| 196 | { |
---|
| 197 | if (!domain_ref.isEmpty()) |
---|
| 198 | { |
---|
[346] | 199 | if (CDomain::has(domain_ref.getValue())) |
---|
[219] | 200 | { |
---|
[346] | 201 | this->domain = CDomain::get(domain_ref.getValue()) ; |
---|
[219] | 202 | domain->checkAttributes() ; |
---|
| 203 | } |
---|
| 204 | else ERROR("CGrid::solveDomainRef(void)", |
---|
| 205 | << "Référence au domaine incorrecte") ; |
---|
| 206 | } |
---|
| 207 | else ERROR("CGrid::solveDomainRef(void)", |
---|
| 208 | << "Domaine non défini") ; |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | //--------------------------------------------------------------- |
---|
| 212 | |
---|
| 213 | void CGrid::solveAxisRef(void) |
---|
| 214 | { |
---|
| 215 | if (!axis_ref.isEmpty()) |
---|
| 216 | { |
---|
| 217 | this->withAxis = true ; |
---|
[346] | 218 | if (CAxis::get(axis_ref.getValue())) |
---|
[219] | 219 | { |
---|
[346] | 220 | this->axis = CAxis::get(axis_ref.getValue()) ; |
---|
[219] | 221 | axis->checkAttributes() ; |
---|
| 222 | } |
---|
| 223 | else ERROR("CGrid::solveAxisRef(void)", |
---|
| 224 | << "Référence a l'axe incorrecte") ; |
---|
| 225 | } |
---|
| 226 | else withAxis = false ; |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | //--------------------------------------------------------------- |
---|
| 230 | |
---|
| 231 | void CGrid::computeIndex(void) |
---|
[266] | 232 | { |
---|
| 233 | |
---|
[219] | 234 | const int ni = domain->ni.getValue() , |
---|
| 235 | nj = domain->nj.getValue() , |
---|
[351] | 236 | size = (this->hasAxis()) ? axis->size.getValue() : 1 , |
---|
| 237 | lbegin = (this->hasAxis()) ? axis->zoom_begin.getValue()-1 : 0 , |
---|
| 238 | lend = (this->hasAxis()) ? axis->zoom_end.getValue()-1 : 0 ; |
---|
[219] | 239 | |
---|
| 240 | |
---|
| 241 | const int data_dim = domain->data_dim.getValue() , |
---|
| 242 | data_n_index = domain->data_n_index.getValue() , |
---|
| 243 | data_ibegin = domain->data_ibegin.getValue() , |
---|
| 244 | data_jbegin = (data_dim == 2) |
---|
| 245 | ? domain->data_jbegin.getValue() : -1; |
---|
| 246 | |
---|
| 247 | ARRAY(int, 1) data_i_index = domain->data_i_index.getValue() , |
---|
| 248 | data_j_index = domain->data_j_index.getValue() ; |
---|
| 249 | |
---|
| 250 | |
---|
| 251 | ARRAY(bool, 2) mask = domain->mask.getValue() ; |
---|
[266] | 252 | ARRAY(int, 2) local_mask = this->domain->getLocalMask(); |
---|
[219] | 253 | |
---|
| 254 | int indexCount = 0; |
---|
| 255 | |
---|
| 256 | for(int l = 0; l < size ; l++) |
---|
| 257 | { |
---|
| 258 | for(int n = 0, i = 0, j = 0; n < data_n_index; n++) |
---|
| 259 | { |
---|
| 260 | int temp_i = (*data_i_index)[n] + data_ibegin, |
---|
| 261 | temp_j = (data_dim == 1) ? -1 |
---|
| 262 | : (*data_j_index)[n] + data_jbegin; |
---|
[266] | 263 | i = (data_dim == 1) ? (temp_i - 1) % ni |
---|
[219] | 264 | : (temp_i - 1) ; |
---|
[266] | 265 | j = (data_dim == 1) ? (temp_i - 1) / ni |
---|
[219] | 266 | : (temp_j - 1) ; |
---|
| 267 | |
---|
[351] | 268 | if ((l >=lbegin && l<= lend) && |
---|
| 269 | (i >= 0 && i < ni) && |
---|
[219] | 270 | (j >= 0 && j < nj) && (*mask)[i][j]) |
---|
| 271 | indexCount++ ; |
---|
| 272 | } |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | ARRAY_ASSIGN(this->storeIndex[0] , int, 1, [indexCount]); |
---|
| 276 | ARRAY_ASSIGN(this->out_l_index[0], int, 1, [indexCount]); |
---|
| 277 | ARRAY_ASSIGN(this->out_i_index[0], int, 1, [indexCount]); |
---|
| 278 | ARRAY_ASSIGN(this->out_j_index[0], int, 1, [indexCount]); |
---|
[266] | 279 | |
---|
[300] | 280 | ARRAY_ASSIGN(storeIndex_client,int,1,[indexCount]); |
---|
| 281 | ARRAY_ASSIGN(out_i_client,int,1,[indexCount]); |
---|
| 282 | ARRAY_ASSIGN(out_j_client,int,1,[indexCount]); |
---|
| 283 | ARRAY_ASSIGN(out_l_client,int,1,[indexCount]); |
---|
[266] | 284 | |
---|
[300] | 285 | |
---|
[219] | 286 | for(int count = 0, indexCount = 0, l = 0; l < size; l++) |
---|
| 287 | { |
---|
| 288 | for(int n = 0, i = 0, j = 0; n < data_n_index; n++, count++) |
---|
| 289 | { |
---|
| 290 | int temp_i = (*data_i_index)[n] + data_ibegin, |
---|
| 291 | temp_j = (data_dim == 1) ? -1 |
---|
| 292 | : (*data_j_index)[n] + data_jbegin; |
---|
[266] | 293 | i = (data_dim == 1) ? (temp_i - 1) % ni |
---|
[219] | 294 | : (temp_i - 1) ; |
---|
[266] | 295 | j = (data_dim == 1) ? (temp_i - 1) / ni |
---|
[219] | 296 | : (temp_j - 1) ; |
---|
| 297 | |
---|
[351] | 298 | if ((l >= lbegin && l <= lend) && |
---|
| 299 | (i >= 0 && i < ni) && |
---|
[219] | 300 | (j >= 0 && j < nj) && (*mask)[i][j]) |
---|
| 301 | { |
---|
| 302 | (*this->storeIndex[0]) [indexCount] = count ; |
---|
| 303 | (*this->out_l_index[0])[indexCount] = l ; |
---|
| 304 | (*this->out_i_index[0])[indexCount] = i ; |
---|
| 305 | (*this->out_j_index[0])[indexCount] = j ; |
---|
[300] | 306 | |
---|
| 307 | (*storeIndex_client)[indexCount] = count ; |
---|
| 308 | (*out_i_client)[indexCount]=i+domain->ibegin_client-1 ; |
---|
| 309 | (*out_j_client)[indexCount]=j+domain->jbegin_client-1 ; |
---|
[351] | 310 | (*out_l_client)[indexCount]=l-lbegin ; |
---|
[219] | 311 | indexCount++ ; |
---|
| 312 | } |
---|
| 313 | } |
---|
| 314 | } |
---|
[300] | 315 | sendIndex() ; |
---|
[266] | 316 | |
---|
| 317 | |
---|
[219] | 318 | } |
---|
| 319 | |
---|
| 320 | //---------------------------------------------------------------- |
---|
| 321 | |
---|
[347] | 322 | CGrid* CGrid::createGrid(CDomain* domain) |
---|
[219] | 323 | { |
---|
| 324 | StdString new_id = StdString("__") + domain->getId() + StdString("__") ; |
---|
[347] | 325 | CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id) ; |
---|
[219] | 326 | grid->domain_ref.setValue(domain->getId()); |
---|
| 327 | return (grid); |
---|
| 328 | } |
---|
| 329 | |
---|
[347] | 330 | CGrid* CGrid::createGrid(CDomain* domain, CAxis* axis) |
---|
[219] | 331 | { |
---|
| 332 | StdString new_id = StdString("__") + domain->getId() + |
---|
| 333 | StdString("_") + axis->getId() + StdString("__") ; |
---|
[347] | 334 | CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id) ; |
---|
[219] | 335 | grid->domain_ref.setValue(domain->getId()); |
---|
| 336 | grid->axis_ref.setValue(axis->getId()); |
---|
| 337 | return (grid); |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | //---------------------------------------------------------------- |
---|
| 341 | |
---|
[300] | 342 | void CGrid::outputField(int rank, const ARRAY(double, 1) stored, ARRAY(double, 3) field) |
---|
[219] | 343 | { |
---|
[300] | 344 | ARRAY(int,1) out_i=out_i_fromClient[rank] ; |
---|
| 345 | ARRAY(int,1) out_j=out_j_fromClient[rank] ; |
---|
| 346 | ARRAY(int,1) out_l=out_l_fromClient[rank] ; |
---|
| 347 | |
---|
| 348 | for(StdSize n = 0; n < stored->num_elements(); n++) |
---|
| 349 | (*field)[(*out_i)[n]][(*out_j)[n]][(*out_l)[n]] = (*stored)[n] ; |
---|
[219] | 350 | } |
---|
| 351 | |
---|
[300] | 352 | void CGrid::outputField(int rank, const ARRAY(double, 1) stored, ARRAY(double, 2) field) |
---|
| 353 | { |
---|
| 354 | ARRAY(int,1) out_i=out_i_fromClient[rank] ; |
---|
| 355 | ARRAY(int,1) out_j=out_j_fromClient[rank] ; |
---|
[219] | 356 | |
---|
[300] | 357 | for(StdSize n = 0; n < stored->num_elements(); n++) |
---|
| 358 | (*field)[(*out_i)[n]][(*out_j)[n]] = (*stored)[n] ; |
---|
[219] | 359 | } |
---|
| 360 | |
---|
| 361 | //--------------------------------------------------------------- |
---|
| 362 | |
---|
[300] | 363 | void CGrid::outputField(int rank,const ARRAY(double, 1) stored, ARRAY(double, 1) field) |
---|
[219] | 364 | { |
---|
[300] | 365 | ARRAY(int,1) out_i = out_i_fromClient[rank] ; |
---|
| 366 | for(StdSize n = 0; n < stored->num_elements(); n++) |
---|
| 367 | (*field)[(*out_i)[n]] = (*stored)[n] ; |
---|
[219] | 368 | } |
---|
| 369 | |
---|
| 370 | //---------------------------------------------------------------- |
---|
[300] | 371 | |
---|
[219] | 372 | |
---|
| 373 | void CGrid::storeField_arr |
---|
| 374 | (const double * const data, ARRAY(double, 1) stored) const |
---|
| 375 | { |
---|
[300] | 376 | const StdSize size = (this->storeIndex_client)->num_elements() ; |
---|
| 377 | |
---|
[219] | 378 | stored->resize(boost::extents[size]) ; |
---|
| 379 | for(StdSize i = 0; i < size; i++) |
---|
[300] | 380 | (*stored)[i] = data[(*storeIndex_client)[i]] ; |
---|
[219] | 381 | } |
---|
| 382 | |
---|
| 383 | //--------------------------------------------------------------- |
---|
| 384 | |
---|
| 385 | void CGrid::toBinary (StdOStream & os) const |
---|
| 386 | { |
---|
| 387 | SuperClass::toBinary(os); |
---|
| 388 | |
---|
| 389 | os.write (reinterpret_cast<const char*>(&this->isChecked), sizeof(bool)); |
---|
| 390 | |
---|
| 391 | if (this->isChecked) |
---|
| 392 | { |
---|
| 393 | this->storeIndex [0]->toBinary(os); |
---|
| 394 | this->out_i_index[0]->toBinary(os); |
---|
| 395 | this->out_j_index[0]->toBinary(os); |
---|
| 396 | this->out_l_index[0]->toBinary(os); |
---|
| 397 | } |
---|
| 398 | } |
---|
| 399 | |
---|
| 400 | //--------------------------------------------------------------- |
---|
| 401 | |
---|
| 402 | void CGrid::fromBinary(StdIStream & is) |
---|
| 403 | { |
---|
| 404 | bool hasIndex = false; |
---|
| 405 | SuperClass::fromBinary(is); |
---|
| 406 | is.read (reinterpret_cast<char*>(&hasIndex), sizeof(bool)); |
---|
| 407 | |
---|
| 408 | if (hasIndex) |
---|
| 409 | { |
---|
| 410 | ARRAY_CREATE(storeIndex_ , int, 1, [0]); |
---|
| 411 | ARRAY_CREATE(out_l_index_, int, 1, [0]); |
---|
| 412 | ARRAY_CREATE(out_i_index_, int, 1, [0]); |
---|
| 413 | ARRAY_CREATE(out_j_index_, int, 1, [0]); |
---|
| 414 | |
---|
| 415 | storeIndex_ ->fromBinary(is); |
---|
| 416 | out_i_index_->fromBinary(is); |
---|
| 417 | out_j_index_->fromBinary(is); |
---|
| 418 | out_l_index_->fromBinary(is); |
---|
| 419 | |
---|
| 420 | this->storeIndex .push_back(storeIndex_); |
---|
| 421 | this->out_i_index.push_back(out_i_index_); |
---|
| 422 | this->out_j_index.push_back(out_j_index_); |
---|
| 423 | this->out_l_index.push_back(out_l_index_); |
---|
| 424 | } |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | //--------------------------------------------------------------- |
---|
[300] | 428 | void CGrid::sendIndex(void) |
---|
| 429 | { |
---|
[347] | 430 | CContext* context = CContext::getCurrent() ; |
---|
[300] | 431 | CContextClient* client=context->client ; |
---|
| 432 | |
---|
| 433 | CEventClient event(getType(),EVENT_ID_INDEX) ; |
---|
| 434 | int rank ; |
---|
| 435 | list<shared_ptr<CMessage> > list_msg ; |
---|
| 436 | list<ARRAY(int,1) > list_out_i,list_out_j,list_out_l ; |
---|
| 437 | |
---|
| 438 | for(int ns=0;ns<domain->connectedServer.size();ns++) |
---|
| 439 | { |
---|
| 440 | rank=domain->connectedServer[ns] ; |
---|
| 441 | int ib=domain->ib_srv[ns] ; |
---|
| 442 | int ie=domain->ie_srv[ns] ; |
---|
| 443 | int jb=domain->jb_srv[ns] ; |
---|
| 444 | int je=domain->je_srv[ns] ; |
---|
| 445 | |
---|
| 446 | int i,j ; |
---|
| 447 | int nb=0 ; |
---|
| 448 | for(int k=0;k<storeIndex_client->num_elements();k++) |
---|
| 449 | { |
---|
| 450 | i=(*out_i_client)[k] ; |
---|
| 451 | j=(*out_j_client)[k] ; |
---|
| 452 | if (i>=ib-1 && i<=ie-1 && j>=jb-1 && j<=je-1) nb++ ; |
---|
| 453 | } |
---|
| 454 | |
---|
| 455 | ARRAY_CREATE(storeIndex,int,1,[nb]) ; |
---|
| 456 | ARRAY_CREATE(out_i,int,1,[nb]) ; |
---|
| 457 | ARRAY_CREATE(out_j,int,1,[nb]) ; |
---|
| 458 | ARRAY_CREATE(out_l,int,1,[nb]) ; |
---|
| 459 | |
---|
| 460 | nb=0 ; |
---|
| 461 | for(int k=0;k<storeIndex_client->num_elements();k++) |
---|
| 462 | { |
---|
| 463 | i=(*out_i_client)[k] ; |
---|
| 464 | j=(*out_j_client)[k] ; |
---|
| 465 | if (i>=ib-1 && i<=ie-1 && j>=jb-1 && j<=je-1) |
---|
| 466 | { |
---|
| 467 | (*storeIndex)[nb]=k ; |
---|
| 468 | (*out_i)[nb]=(*out_i_client)[k] ; |
---|
| 469 | (*out_j)[nb]=(*out_j_client)[k] ; |
---|
| 470 | (*out_l)[nb]=(*out_l_client)[k] ; |
---|
| 471 | nb++ ; |
---|
| 472 | } |
---|
| 473 | } |
---|
| 474 | |
---|
| 475 | storeIndex_toSrv.insert(pair<int,ARRAY(int,1) >(rank,storeIndex)) ; |
---|
| 476 | nbSenders.insert(pair<int,int>(rank,domain->nbSenders[ns])) ; |
---|
| 477 | list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ; |
---|
| 478 | list_out_i.push_back(out_i) ; |
---|
| 479 | list_out_j.push_back(out_j) ; |
---|
| 480 | list_out_l.push_back(out_l) ; |
---|
| 481 | |
---|
| 482 | *list_msg.back()<<getId()<<list_out_i.back()<<list_out_j.back()<<list_out_l.back() ; |
---|
| 483 | event.push(rank,domain->nbSenders[ns],*list_msg.back()) ; |
---|
| 484 | } |
---|
| 485 | client->sendEvent(event) ; |
---|
| 486 | } |
---|
| 487 | |
---|
| 488 | void CGrid::recvIndex(CEventServer& event) |
---|
| 489 | { |
---|
| 490 | list<CEventServer::SSubEvent>::iterator it ; |
---|
| 491 | for (it=event.subEvents.begin();it!=event.subEvents.end();++it) |
---|
| 492 | { |
---|
| 493 | int rank=it->rank; |
---|
| 494 | CBufferIn* buffer=it->buffer; |
---|
| 495 | string domainId ; |
---|
| 496 | *buffer>>domainId ; |
---|
| 497 | get(domainId)->recvIndex(rank,*buffer) ; |
---|
| 498 | } |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | void CGrid::recvIndex(int rank, CBufferIn& buffer) |
---|
| 502 | { |
---|
| 503 | ARRAY_CREATE(out_i,int,1,[0]) ; |
---|
| 504 | ARRAY_CREATE(out_j,int,1,[0]) ; |
---|
| 505 | ARRAY_CREATE(out_l,int,1,[0]) ; |
---|
| 506 | |
---|
| 507 | buffer>>out_i>>out_j>>out_l ; |
---|
| 508 | int offset ; |
---|
| 509 | |
---|
| 510 | offset=domain->zoom_ibegin_srv-1 ; |
---|
| 511 | for(int k=0;k<out_i->num_elements();k++) (*out_i)[k]=(*out_i)[k]-offset ; |
---|
| 512 | |
---|
| 513 | offset=domain->zoom_jbegin_srv-1 ; |
---|
| 514 | for(int k=0;k<out_i->num_elements();k++) (*out_j)[k]=(*out_j)[k]-offset ; |
---|
| 515 | |
---|
| 516 | out_i_fromClient.insert(pair< int,ARRAY(int,1) >(rank,out_i)) ; |
---|
| 517 | out_j_fromClient.insert(pair< int,ARRAY(int,1) >(rank,out_j)) ; |
---|
| 518 | out_l_fromClient.insert(pair< int,ARRAY(int,1) >(rank,out_l)) ; |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | bool CGrid::dispatchEvent(CEventServer& event) |
---|
| 522 | { |
---|
| 523 | |
---|
| 524 | if (SuperClass::dispatchEvent(event)) return true ; |
---|
| 525 | else |
---|
| 526 | { |
---|
| 527 | switch(event.type) |
---|
| 528 | { |
---|
| 529 | case EVENT_ID_INDEX : |
---|
| 530 | recvIndex(event) ; |
---|
| 531 | return true ; |
---|
| 532 | break ; |
---|
| 533 | |
---|
| 534 | default : |
---|
| 535 | ERROR("bool CDomain::dispatchEvent(CEventServer& event)", |
---|
| 536 | <<"Unknown Event") ; |
---|
| 537 | return false ; |
---|
| 538 | } |
---|
| 539 | } |
---|
| 540 | } |
---|
| 541 | |
---|
| 542 | |
---|
[314] | 543 | /* |
---|
[219] | 544 | void CGrid::computeIndexServer(void) |
---|
| 545 | { |
---|
| 546 | ARRAY(int, 2) local_mask = this->domain->getLocalMask(); |
---|
| 547 | |
---|
| 548 | const std::vector<int> & ibegin = this->domain->getIBeginSub(); |
---|
| 549 | const std::vector<int> & jbegin = this->domain->getJBeginSub(); |
---|
[286] | 550 | const std::vector<int> & iend = this->domain->getIEndSub(); |
---|
| 551 | const std::vector<int> & jend = this->domain->getJEndSub(); |
---|
[274] | 552 | const std::vector<int> & ibegin_zoom = this->domain->getIBeginZoomSub(); |
---|
| 553 | const std::vector<int> & jbegin_zoom = this->domain->getJBeginZoomSub(); |
---|
[286] | 554 | const std::vector<int> & ni_zoom = this->domain->getNiZoomSub(); |
---|
| 555 | const std::vector<int> & nj_zoom = this->domain->getNjZoomSub(); |
---|
[219] | 556 | |
---|
[266] | 557 | const int ibegin_srv = this->domain->ibegin.getValue(); |
---|
| 558 | const int jbegin_srv = this->domain->jbegin.getValue(); |
---|
[286] | 559 | const int iend_srv = this->domain->iend.getValue(); |
---|
| 560 | const int jend_srv = this->domain->jend.getValue(); |
---|
[266] | 561 | const int zoom_ni_srv = this->domain->zoom_ni_loc.getValue(); |
---|
| 562 | const int zoom_nj_srv = this->domain->zoom_nj_loc.getValue(); |
---|
[219] | 563 | |
---|
| 564 | const int ibegin_zoom_srv = this->domain->zoom_ibegin_loc.getValue(); |
---|
| 565 | const int jbegin_zoom_srv = this->domain->zoom_jbegin_loc.getValue(); |
---|
[286] | 566 | const int iend_zoom_srv = ibegin_zoom_srv + zoom_ni_srv-1 ; |
---|
| 567 | const int jend_zoom_srv = jbegin_zoom_srv + zoom_nj_srv-1 ; |
---|
| 568 | |
---|
[219] | 569 | StdSize dn = 0; |
---|
| 570 | for (StdSize j = 1; j < this->out_i_index.size(); j++) |
---|
| 571 | dn += this->out_i_index[j]->size(); |
---|
| 572 | |
---|
[266] | 573 | ARRAY_CREATE(storeIndex_srv , int, 1, [dn]); |
---|
| 574 | ARRAY_CREATE(out_i_index_srv, int, 1, [dn]); |
---|
| 575 | ARRAY_CREATE(out_j_index_srv, int, 1, [dn]); |
---|
| 576 | ARRAY_CREATE(out_l_index_srv, int, 1, [dn]); |
---|
[219] | 577 | |
---|
| 578 | for (StdSize i = 0, dn = 0; i < ibegin.size(); i++) |
---|
| 579 | { |
---|
| 580 | ARRAY(int, 1) storeIndex_cl = this->storeIndex [i + 1]; |
---|
| 581 | ARRAY(int, 1) out_i_index_cl = this->out_i_index[i + 1]; |
---|
| 582 | ARRAY(int, 1) out_j_index_cl = this->out_j_index[i + 1]; |
---|
| 583 | ARRAY(int, 1) out_l_index_cl = this->out_l_index[i + 1]; |
---|
[278] | 584 | |
---|
[274] | 585 | int ibegin_zoom_cl = ibegin[i]; //ibegin_zoom[i]; |
---|
| 586 | int jbegin_zoom_cl = jbegin[i]; //jbegin_zoom[i]; |
---|
[286] | 587 | int iend_zoom_cl = iend[i]; //ibegin_zoom[i]; |
---|
| 588 | int jend_zoom_cl = jend[i]; //jbegin_zoom[i]; |
---|
| 589 | |
---|
| 590 | int ibegin_cl = ibegin[i]; //ibegin[i]; |
---|
| 591 | int jbegin_cl = jbegin[i]; //jbegin[i]; |
---|
| 592 | int iend_cl = iend[i]; //ibegin[i]; |
---|
| 593 | int jend_cl = jend[i]; //jbegin[i]; |
---|
[274] | 594 | |
---|
| 595 | if (ibegin_zoom.size() != 0) |
---|
| 596 | { |
---|
| 597 | ibegin_zoom_cl = ibegin_zoom[i]; |
---|
| 598 | jbegin_zoom_cl = jbegin_zoom[i]; |
---|
[286] | 599 | iend_zoom_cl = ibegin_zoom[i]+ni_zoom[i]-1; |
---|
| 600 | jend_zoom_cl = jbegin_zoom[i]+nj_zoom[i]-1; |
---|
[274] | 601 | } |
---|
| 602 | |
---|
[286] | 603 | |
---|
| 604 | if (comm::CMPIManager::IsClient()) |
---|
[219] | 605 | { |
---|
[286] | 606 | for (StdSize n = dn, m = 0; n < (dn + storeIndex_cl->size()); n++, m++) |
---|
| 607 | { |
---|
| 608 | (*storeIndex_srv)[n] = (*storeIndex_cl)[m]; // Faux mais inutile dans le cas serveur. |
---|
| 609 | |
---|
| 610 | (*out_i_index_srv)[n] = (*out_i_index_cl)[m] + ibegin_cl - 1 - (ibegin_srv + ibegin_zoom_srv - 1) + 1 ; |
---|
| 611 | (*out_j_index_srv)[n] = (*out_j_index_cl)[m] + jbegin_cl - 1 - (jbegin_srv + jbegin_zoom_srv - 1) + 1 ; |
---|
| 612 | (*out_l_index_srv)[n] = (*out_l_index_cl)[m]; |
---|
| 613 | } |
---|
| 614 | } |
---|
| 615 | else |
---|
| 616 | { |
---|
| 617 | for (StdSize n = dn, m = 0; n < (dn + storeIndex_cl->size()); n++, m++) |
---|
| 618 | { |
---|
| 619 | (*storeIndex_srv)[n] = (*storeIndex_cl)[m]; // Faux mais inutile dans le cas serveur. |
---|
[219] | 620 | (*out_i_index_srv)[n] = (*out_i_index_cl)[m] |
---|
[286] | 621 | + (ibegin_cl - 1) - (ibegin_srv - 1) + (ibegin_zoom_cl - 1) - (ibegin_zoom_srv - 1); |
---|
[219] | 622 | (*out_j_index_srv)[n] = (*out_j_index_cl)[m] |
---|
[286] | 623 | + (jbegin_cl - 1) - (jbegin_srv - 1) + (jbegin_zoom_cl - 1) - (jbegin_zoom_srv - 1); |
---|
[219] | 624 | (*out_l_index_srv)[n] = (*out_l_index_cl)[m]; |
---|
[286] | 625 | } |
---|
| 626 | |
---|
[219] | 627 | } |
---|
| 628 | |
---|
[286] | 629 | dn += storeIndex_cl->size(); |
---|
[219] | 630 | } |
---|
[286] | 631 | |
---|
[219] | 632 | if (storeIndex_srv->size() != 0) |
---|
| 633 | { |
---|
| 634 | const int ibegin_t = |
---|
| 635 | *std::min_element(out_i_index_srv->begin(), out_i_index_srv->end()); |
---|
| 636 | const int iend_t = |
---|
| 637 | *std::max_element(out_i_index_srv->begin(), out_i_index_srv->end()); |
---|
| 638 | const int jbegin_t = |
---|
| 639 | *std::min_element(out_j_index_srv->begin(), out_j_index_srv->end()); |
---|
| 640 | const int jend_t = |
---|
| 641 | *std::max_element(out_j_index_srv->begin(), out_j_index_srv->end()); |
---|
[286] | 642 | |
---|
| 643 | |
---|
[219] | 644 | if ((ibegin_t < 0) || (jbegin_t < 0) || |
---|
| 645 | (iend_t >= zoom_ni_srv) || (jend_t >= zoom_nj_srv)) |
---|
| 646 | { |
---|
| 647 | ERROR("CGrid::computeIndexServer(void)", |
---|
[274] | 648 | << "[ grille = " << this->getId() |
---|
| 649 | << ", ibegin_t = " << ibegin_t |
---|
| 650 | << ", jbegin_t = " << jbegin_t |
---|
| 651 | << ", iend_t = " << iend_t |
---|
| 652 | << ", jend_t = " << jend_t |
---|
| 653 | << ", zoom_ni_srv = " << zoom_ni_srv |
---|
| 654 | << ", zoom_nj_srv = " << zoom_nj_srv |
---|
[286] | 655 | << ", nb subdomain = " << out_i_index.size()-1 |
---|
[274] | 656 | <<" ] Erreur d'indexation de la grille au niveau du serveur") ; |
---|
[219] | 657 | } |
---|
| 658 | } |
---|
| 659 | |
---|
| 660 | if (storeIndex_srv->size() != 0) |
---|
| 661 | for (StdSize u = 0; u < storeIndex_srv->size(); u++) |
---|
| 662 | (*local_mask)[(*out_i_index_srv)[u]][(*out_j_index_srv)[u]] = 1; |
---|
| 663 | |
---|
[266] | 664 | // StdOFStream ofs(("log_server_"+this->getId()).c_str()); |
---|
| 665 | // for (StdSize h = 0; h < storeIndex_srv->size(); h++) |
---|
| 666 | // { |
---|
| 667 | // ofs << "(" << (*storeIndex_srv)[h] << ";" |
---|
| 668 | // << (*out_i_index_srv)[h] << "," |
---|
| 669 | // << (*out_j_index_srv)[h] << "," |
---|
| 670 | // << (*out_l_index_srv)[h] << ")" << std::endl; |
---|
| 671 | // } |
---|
| 672 | // ofs.close(); |
---|
| 673 | |
---|
| 674 | this->storeIndex [0] = storeIndex_srv ; |
---|
| 675 | this->out_i_index[0] = out_i_index_srv; |
---|
| 676 | this->out_j_index[0] = out_j_index_srv; |
---|
[278] | 677 | this->out_l_index[0] = out_l_index_srv; |
---|
[219] | 678 | } |
---|
[314] | 679 | */ |
---|
[219] | 680 | |
---|
| 681 | void CGrid::inputFieldServer |
---|
| 682 | (const std::deque<ARRAY(double, 1)> storedClient, |
---|
| 683 | ARRAY(double, 1) storedServer) const |
---|
| 684 | { |
---|
| 685 | if ((this->storeIndex.size()-1 ) != storedClient.size()) |
---|
| 686 | ERROR("CGrid::inputFieldServer(...)", |
---|
| 687 | << "[ Nombre de tableau attendu = " << (this->storeIndex.size()-1) << ", " |
---|
| 688 | << "[ Nombre de tableau reçu = " << storedClient.size() << "] " |
---|
| 689 | << "Les données d'un client sont manquantes !") ; |
---|
| 690 | if (storedServer.get() != NULL) |
---|
[278] | 691 | storedServer->resize(boost::extents[this->storeIndex[0]->num_elements()]); |
---|
[219] | 692 | else |
---|
[278] | 693 | ARRAY_ASSIGN(storedServer, double, 1, [this->storeIndex[0]->num_elements()]); |
---|
[219] | 694 | |
---|
| 695 | for (StdSize i = 0, n = 0; i < storedClient.size(); i++) |
---|
| 696 | for (StdSize j = 0; j < storedClient[i]->num_elements(); j++) |
---|
| 697 | (*storedServer)[n++] = (*storedClient[i])[j]; |
---|
| 698 | } |
---|
| 699 | |
---|
[300] | 700 | void CGrid::outputFieldToServer(ARRAY(double, 1) fieldIn, int rank, ARRAY(double, 1) fieldOut) |
---|
| 701 | { |
---|
| 702 | ARRAY(int,1) index=storeIndex_toSrv[rank] ; |
---|
| 703 | int nb=index->num_elements() ; |
---|
| 704 | fieldOut->resize(extents[nb]) ; |
---|
| 705 | |
---|
| 706 | for(int k=0;k<nb;k++) (*fieldOut)[k]=(*fieldIn)[(*index)[k]] ; |
---|
| 707 | } |
---|
[219] | 708 | ///--------------------------------------------------------------- |
---|
| 709 | |
---|
[335] | 710 | } // namespace xios |
---|