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