[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" |
---|
[369] | 13 | #include "array_new.hpp" |
---|
[219] | 14 | |
---|
[335] | 15 | namespace xios { |
---|
[219] | 16 | |
---|
| 17 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 18 | |
---|
| 19 | CGrid::CGrid(void) |
---|
| 20 | : CObjectTemplate<CGrid>(), CGridAttributes() |
---|
| 21 | , withAxis(false), isChecked(false), axis(), domain() |
---|
| 22 | , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1) |
---|
| 23 | { /* Ne rien faire de plus */ } |
---|
| 24 | |
---|
| 25 | CGrid::CGrid(const StdString & id) |
---|
| 26 | : CObjectTemplate<CGrid>(id), CGridAttributes() |
---|
| 27 | , withAxis(false), isChecked(false), axis(), domain() |
---|
| 28 | , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1) |
---|
| 29 | { /* Ne rien faire de plus */ } |
---|
| 30 | |
---|
| 31 | CGrid::~CGrid(void) |
---|
| 32 | { |
---|
[347] | 33 | // this->axis.reset() ; |
---|
| 34 | // this->domain.reset() ; |
---|
[369] | 35 | deque< CArray<int, 1>* >::iterator it ; |
---|
| 36 | |
---|
| 37 | for(deque< CArray<int,1>* >::iterator it=storeIndex.begin(); it!=storeIndex.end();it++) delete *it ; |
---|
| 38 | for(deque< CArray<int,1>* >::iterator it=out_i_index.begin();it!=out_i_index.end();it++) delete *it ; |
---|
| 39 | for(deque< CArray<int,1>* >::iterator it=out_j_index.begin();it!=out_j_index.end();it++) delete *it ; |
---|
| 40 | for(deque< CArray<int,1>* >::iterator it=out_l_index.begin();it!=out_l_index.end();it++) delete *it ; |
---|
| 41 | |
---|
| 42 | for(map<int,CArray<int,1>* >::iterator it=out_i_fromClient.begin();it!=out_i_fromClient.end();it++) delete it->second ; |
---|
| 43 | for(map<int,CArray<int,1>* >::iterator it=out_j_fromClient.begin();it!=out_j_fromClient.end();it++) delete it->second ; |
---|
| 44 | for(map<int,CArray<int,1>* >::iterator it=out_l_fromClient.begin();it!=out_l_fromClient.end();it++) delete it->second ; |
---|
| 45 | |
---|
[219] | 46 | } |
---|
| 47 | |
---|
| 48 | ///--------------------------------------------------------------- |
---|
| 49 | |
---|
| 50 | StdString CGrid::GetName(void) { return (StdString("grid")); } |
---|
| 51 | StdString CGrid::GetDefName(void) { return (CGrid::GetName()); } |
---|
| 52 | ENodeType CGrid::GetType(void) { return (eGrid); } |
---|
| 53 | |
---|
| 54 | //---------------------------------------------------------------- |
---|
| 55 | |
---|
[369] | 56 | const std::deque< CArray<int,1>* > & CGrid::getStoreIndex(void) const |
---|
[219] | 57 | { |
---|
| 58 | return (this->storeIndex ); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | //--------------------------------------------------------------- |
---|
| 62 | |
---|
[369] | 63 | const std::deque< CArray<int,1>* > & CGrid::getOutIIndex(void) const |
---|
[219] | 64 | { |
---|
| 65 | return (this->out_i_index ); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | //--------------------------------------------------------------- |
---|
| 69 | |
---|
[369] | 70 | const std::deque< CArray<int,1>* > & CGrid::getOutJIndex(void) const |
---|
[219] | 71 | { |
---|
| 72 | return (this->out_j_index ); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | //--------------------------------------------------------------- |
---|
| 76 | |
---|
[369] | 77 | const std::deque< CArray<int,1>* > & CGrid::getOutLIndex(void) const |
---|
[219] | 78 | { |
---|
| 79 | return (this->out_l_index ); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | //--------------------------------------------------------------- |
---|
| 83 | |
---|
[347] | 84 | const CAxis* CGrid::getRelAxis (void) const |
---|
[219] | 85 | { |
---|
| 86 | return (this->axis ); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | //--------------------------------------------------------------- |
---|
| 90 | |
---|
[347] | 91 | const CDomain* CGrid::getRelDomain(void) const |
---|
[219] | 92 | { |
---|
| 93 | return (this->domain ); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | //--------------------------------------------------------------- |
---|
| 97 | |
---|
| 98 | bool CGrid::hasAxis(void) const |
---|
| 99 | { |
---|
| 100 | return (this->withAxis); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | //--------------------------------------------------------------- |
---|
| 104 | |
---|
| 105 | StdSize CGrid::getDimension(void) const |
---|
| 106 | { |
---|
| 107 | return ((this->withAxis)?3:2); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | //--------------------------------------------------------------- |
---|
| 111 | |
---|
[351] | 112 | /* |
---|
[266] | 113 | std::vector<StdSize> CGrid::getLocalShape(void) const |
---|
[219] | 114 | { |
---|
| 115 | std::vector<StdSize> retvalue; |
---|
[266] | 116 | retvalue.push_back(domain->zoom_ni_loc.getValue()); |
---|
| 117 | retvalue.push_back(domain->zoom_nj_loc.getValue()); |
---|
[219] | 118 | if (this->withAxis) |
---|
[351] | 119 | retvalue.push_back(this->axis->zoom_size.getValue()); |
---|
[219] | 120 | return (retvalue); |
---|
| 121 | } |
---|
[351] | 122 | */ |
---|
[219] | 123 | //--------------------------------------------------------------- |
---|
| 124 | |
---|
[351] | 125 | /* |
---|
[266] | 126 | StdSize CGrid::getLocalSize(void) const |
---|
[219] | 127 | { |
---|
| 128 | StdSize retvalue = 1; |
---|
[266] | 129 | std::vector<StdSize> shape_ = this->getLocalShape(); |
---|
[219] | 130 | for (StdSize s = 0; s < shape_.size(); s++) |
---|
| 131 | retvalue *= shape_[s]; |
---|
| 132 | return (retvalue); |
---|
| 133 | } |
---|
[351] | 134 | */ |
---|
[266] | 135 | //--------------------------------------------------------------- |
---|
[351] | 136 | /* |
---|
[266] | 137 | std::vector<StdSize> CGrid::getGlobalShape(void) const |
---|
| 138 | { |
---|
| 139 | std::vector<StdSize> retvalue; |
---|
| 140 | retvalue.push_back(domain->ni.getValue()); |
---|
| 141 | retvalue.push_back(domain->nj.getValue()); |
---|
| 142 | if (this->withAxis) |
---|
| 143 | retvalue.push_back(this->axis->size.getValue()); |
---|
| 144 | return (retvalue); |
---|
| 145 | } |
---|
[351] | 146 | */ |
---|
[219] | 147 | //--------------------------------------------------------------- |
---|
[351] | 148 | |
---|
| 149 | /* |
---|
[266] | 150 | StdSize CGrid::getGlobalSize(void) const |
---|
| 151 | { |
---|
| 152 | StdSize retvalue = 1; |
---|
| 153 | std::vector<StdSize> shape_ = this->getGlobalShape(); |
---|
| 154 | for (StdSize s = 0; s < shape_.size(); s++) |
---|
| 155 | retvalue *= shape_[s]; |
---|
| 156 | return (retvalue); |
---|
| 157 | } |
---|
[351] | 158 | */ |
---|
[286] | 159 | StdSize CGrid::getDataSize(void) const |
---|
| 160 | { |
---|
[369] | 161 | StdSize retvalue=domain->data_ni.getValue() ; |
---|
[286] | 162 | if (domain->data_dim.getValue()==2) retvalue*=domain->data_nj.getValue() ; |
---|
| 163 | if (this->withAxis) retvalue*=this->axis->size.getValue() ; |
---|
| 164 | |
---|
| 165 | return (retvalue); |
---|
| 166 | } |
---|
| 167 | |
---|
[266] | 168 | //--------------------------------------------------------------- |
---|
| 169 | |
---|
[219] | 170 | void CGrid::solveReference(void) |
---|
| 171 | { |
---|
| 172 | if (this->isChecked) return; |
---|
[347] | 173 | CContext* context = CContext::getCurrent() ; |
---|
[300] | 174 | CContextClient* client=context->client ; |
---|
| 175 | |
---|
[219] | 176 | this->solveDomainRef() ; |
---|
| 177 | this->solveAxisRef() ; |
---|
[415] | 178 | |
---|
[300] | 179 | if (context->hasClient) |
---|
[219] | 180 | { |
---|
[415] | 181 | checkMask() ; |
---|
[219] | 182 | this->computeIndex() ; |
---|
[369] | 183 | |
---|
| 184 | this->storeIndex.push_front(new CArray<int,1>() ); |
---|
| 185 | this->out_i_index.push_front(new CArray<int,1>()); |
---|
| 186 | this->out_j_index.push_front(new CArray<int,1>()); |
---|
| 187 | this->out_l_index.push_front(new CArray<int,1>()); |
---|
[219] | 188 | } |
---|
[300] | 189 | // this->computeIndexServer(); |
---|
[219] | 190 | this->isChecked = true; |
---|
| 191 | } |
---|
| 192 | |
---|
[415] | 193 | |
---|
| 194 | void CGrid::checkMask(void) |
---|
| 195 | { |
---|
| 196 | using namespace std; |
---|
| 197 | |
---|
| 198 | unsigned int niu = domain->ni, nju = domain->nj; |
---|
| 199 | unsigned int nlu = 1 ; |
---|
| 200 | if (hasAxis()) nlu=axis->size ; |
---|
| 201 | |
---|
| 202 | if (!mask.isEmpty()) |
---|
| 203 | { |
---|
| 204 | if ((mask.extent(0) != niu) || |
---|
| 205 | (mask.extent(1) != nju) || |
---|
| 206 | (mask.extent(2) != nlu)) |
---|
| 207 | ERROR("CGrid::checkAttributes(void)", |
---|
[435] | 208 | <<"The mask has not the same size than the local grid"<<endl |
---|
| 209 | <<"Local size is "<<niu<<"x"<<nju<<"x"<<nlu<<endl |
---|
| 210 | <<"Mask size is "<<mask.extent(0)<<"x"<<mask.extent(1)<<"x"<<mask.extent(2)); |
---|
[415] | 211 | } |
---|
| 212 | else |
---|
| 213 | { |
---|
| 214 | mask.resize(niu,nju,nlu) ; |
---|
| 215 | mask=true ; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | CArray<bool,2>& domainMask = domain->mask ; |
---|
| 219 | for (int l=0; l < nlu ; l++) |
---|
| 220 | for (int j=0; j < nju ; j++) |
---|
| 221 | for(int i=0; i<niu ; i++) mask(i,j,l) = mask(i,j,l) && domainMask(i,j) ; |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | } |
---|
| 225 | |
---|
[219] | 226 | //--------------------------------------------------------------- |
---|
| 227 | |
---|
| 228 | void CGrid::solveDomainRef(void) |
---|
| 229 | { |
---|
| 230 | if (!domain_ref.isEmpty()) |
---|
| 231 | { |
---|
[346] | 232 | if (CDomain::has(domain_ref.getValue())) |
---|
[219] | 233 | { |
---|
[346] | 234 | this->domain = CDomain::get(domain_ref.getValue()) ; |
---|
[219] | 235 | domain->checkAttributes() ; |
---|
| 236 | } |
---|
| 237 | else ERROR("CGrid::solveDomainRef(void)", |
---|
[421] | 238 | << "Wrong domain reference") ; |
---|
[219] | 239 | } |
---|
| 240 | else ERROR("CGrid::solveDomainRef(void)", |
---|
[421] | 241 | << "Domain reference is not defined") ; |
---|
[219] | 242 | } |
---|
| 243 | |
---|
| 244 | //--------------------------------------------------------------- |
---|
| 245 | |
---|
| 246 | void CGrid::solveAxisRef(void) |
---|
| 247 | { |
---|
| 248 | if (!axis_ref.isEmpty()) |
---|
| 249 | { |
---|
| 250 | this->withAxis = true ; |
---|
[346] | 251 | if (CAxis::get(axis_ref.getValue())) |
---|
[219] | 252 | { |
---|
[346] | 253 | this->axis = CAxis::get(axis_ref.getValue()) ; |
---|
[219] | 254 | axis->checkAttributes() ; |
---|
| 255 | } |
---|
| 256 | else ERROR("CGrid::solveAxisRef(void)", |
---|
[421] | 257 | << "Wrong axis reference") ; |
---|
[219] | 258 | } |
---|
| 259 | else withAxis = false ; |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | //--------------------------------------------------------------- |
---|
| 263 | |
---|
| 264 | void CGrid::computeIndex(void) |
---|
[266] | 265 | { |
---|
| 266 | |
---|
[219] | 267 | const int ni = domain->ni.getValue() , |
---|
| 268 | nj = domain->nj.getValue() , |
---|
[351] | 269 | size = (this->hasAxis()) ? axis->size.getValue() : 1 , |
---|
| 270 | lbegin = (this->hasAxis()) ? axis->zoom_begin.getValue()-1 : 0 , |
---|
| 271 | lend = (this->hasAxis()) ? axis->zoom_end.getValue()-1 : 0 ; |
---|
[219] | 272 | |
---|
| 273 | |
---|
| 274 | const int data_dim = domain->data_dim.getValue() , |
---|
| 275 | data_n_index = domain->data_n_index.getValue() , |
---|
| 276 | data_ibegin = domain->data_ibegin.getValue() , |
---|
| 277 | data_jbegin = (data_dim == 2) |
---|
| 278 | ? domain->data_jbegin.getValue() : -1; |
---|
| 279 | |
---|
[369] | 280 | CArray<int,1> data_i_index = domain->data_i_index ; |
---|
| 281 | CArray<int,1> data_j_index = domain->data_j_index ; |
---|
| 282 | |
---|
[219] | 283 | |
---|
| 284 | int indexCount = 0; |
---|
| 285 | |
---|
| 286 | for(int l = 0; l < size ; l++) |
---|
| 287 | { |
---|
| 288 | for(int n = 0, i = 0, j = 0; n < data_n_index; n++) |
---|
| 289 | { |
---|
[369] | 290 | int temp_i = data_i_index(n) + data_ibegin, |
---|
[219] | 291 | temp_j = (data_dim == 1) ? -1 |
---|
[369] | 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) && |
---|
[415] | 300 | (j >= 0 && j < nj) && mask(i,j,l)) |
---|
[219] | 301 | indexCount++ ; |
---|
| 302 | } |
---|
| 303 | } |
---|
| 304 | |
---|
[369] | 305 | storeIndex[0] = new CArray<int,1>(indexCount) ; |
---|
| 306 | out_i_index[0] = new CArray<int,1>(indexCount) ; |
---|
| 307 | out_j_index[0] = new CArray<int,1>(indexCount) ; |
---|
| 308 | out_l_index[0] = new CArray<int,1>(indexCount) ; |
---|
[266] | 309 | |
---|
[369] | 310 | storeIndex_client.resize(indexCount) ; |
---|
| 311 | out_i_client.resize(indexCount) ; |
---|
| 312 | out_j_client.resize(indexCount) ; |
---|
| 313 | out_l_client.resize(indexCount) ; |
---|
[266] | 314 | |
---|
[300] | 315 | |
---|
[219] | 316 | for(int count = 0, indexCount = 0, l = 0; l < size; l++) |
---|
| 317 | { |
---|
| 318 | for(int n = 0, i = 0, j = 0; n < data_n_index; n++, count++) |
---|
| 319 | { |
---|
[369] | 320 | int temp_i = data_i_index(n) + data_ibegin, |
---|
[219] | 321 | temp_j = (data_dim == 1) ? -1 |
---|
[369] | 322 | : data_j_index(n) + data_jbegin; |
---|
[266] | 323 | i = (data_dim == 1) ? (temp_i - 1) % ni |
---|
[219] | 324 | : (temp_i - 1) ; |
---|
[266] | 325 | j = (data_dim == 1) ? (temp_i - 1) / ni |
---|
[219] | 326 | : (temp_j - 1) ; |
---|
| 327 | |
---|
[351] | 328 | if ((l >= lbegin && l <= lend) && |
---|
| 329 | (i >= 0 && i < ni) && |
---|
[415] | 330 | (j >= 0 && j < nj) && mask(i,j,l)) |
---|
[219] | 331 | { |
---|
[369] | 332 | (*storeIndex[0])(indexCount) = count ; |
---|
| 333 | (*out_l_index[0])(indexCount) = l ; |
---|
| 334 | (*out_i_index[0])(indexCount) = i ; |
---|
| 335 | (*out_j_index[0])(indexCount) = j ; |
---|
[300] | 336 | |
---|
[369] | 337 | storeIndex_client(indexCount) = count ; |
---|
| 338 | out_i_client(indexCount)=i+domain->ibegin_client-1 ; |
---|
| 339 | out_j_client(indexCount)=j+domain->jbegin_client-1 ; |
---|
| 340 | out_l_client(indexCount)=l-lbegin ; |
---|
[219] | 341 | indexCount++ ; |
---|
| 342 | } |
---|
| 343 | } |
---|
| 344 | } |
---|
[300] | 345 | sendIndex() ; |
---|
[266] | 346 | |
---|
| 347 | |
---|
[219] | 348 | } |
---|
| 349 | |
---|
| 350 | //---------------------------------------------------------------- |
---|
| 351 | |
---|
[347] | 352 | CGrid* CGrid::createGrid(CDomain* domain) |
---|
[219] | 353 | { |
---|
| 354 | StdString new_id = StdString("__") + domain->getId() + StdString("__") ; |
---|
[347] | 355 | CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id) ; |
---|
[219] | 356 | grid->domain_ref.setValue(domain->getId()); |
---|
| 357 | return (grid); |
---|
| 358 | } |
---|
| 359 | |
---|
[347] | 360 | CGrid* CGrid::createGrid(CDomain* domain, CAxis* axis) |
---|
[219] | 361 | { |
---|
| 362 | StdString new_id = StdString("__") + domain->getId() + |
---|
| 363 | StdString("_") + axis->getId() + StdString("__") ; |
---|
[347] | 364 | CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id) ; |
---|
[219] | 365 | grid->domain_ref.setValue(domain->getId()); |
---|
| 366 | grid->axis_ref.setValue(axis->getId()); |
---|
| 367 | return (grid); |
---|
| 368 | } |
---|
| 369 | |
---|
| 370 | //---------------------------------------------------------------- |
---|
| 371 | |
---|
[369] | 372 | void CGrid::outputField(int rank, const CArray<double, 1>& stored, CArray<double, 3>& field) |
---|
[219] | 373 | { |
---|
[369] | 374 | CArray<int,1>& out_i=*out_i_fromClient[rank] ; |
---|
| 375 | CArray<int,1>& out_j=*out_j_fromClient[rank] ; |
---|
| 376 | CArray<int,1>& out_l=*out_l_fromClient[rank] ; |
---|
[300] | 377 | |
---|
[369] | 378 | for(StdSize n = 0; n < stored.numElements(); n++) |
---|
| 379 | field(out_i(n), out_j(n), out_l(n)) = stored(n) ; |
---|
[219] | 380 | } |
---|
| 381 | |
---|
[369] | 382 | void CGrid::outputField(int rank, const CArray<double, 1>& stored, CArray<double, 2>& field) |
---|
[300] | 383 | { |
---|
[369] | 384 | CArray<int,1>& out_i=*out_i_fromClient[rank] ; |
---|
| 385 | CArray<int,1>& out_j=*out_j_fromClient[rank] ; |
---|
| 386 | |
---|
| 387 | for(StdSize n = 0; n < stored.numElements(); n++) |
---|
| 388 | field(out_i(n), out_j(n)) = stored(n) ; } |
---|
[219] | 389 | |
---|
| 390 | //--------------------------------------------------------------- |
---|
| 391 | |
---|
[369] | 392 | void CGrid::outputField(int rank,const CArray<double, 1>& stored, CArray<double, 1>& field) |
---|
[219] | 393 | { |
---|
[369] | 394 | CArray<int,1>& out_i=*out_i_fromClient[rank] ; |
---|
| 395 | |
---|
| 396 | for(StdSize n = 0; n < stored.numElements(); n++) |
---|
| 397 | field(out_i(n)) = stored(n) ; |
---|
[219] | 398 | } |
---|
| 399 | |
---|
| 400 | //---------------------------------------------------------------- |
---|
[300] | 401 | |
---|
[219] | 402 | |
---|
| 403 | void CGrid::storeField_arr |
---|
[369] | 404 | (const double * const data, CArray<double, 1>& stored) const |
---|
[219] | 405 | { |
---|
[369] | 406 | const StdSize size = storeIndex_client.numElements() ; |
---|
[300] | 407 | |
---|
[369] | 408 | stored.resize(size) ; |
---|
| 409 | for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)] ; |
---|
[219] | 410 | } |
---|
| 411 | |
---|
| 412 | //--------------------------------------------------------------- |
---|
| 413 | |
---|
[300] | 414 | void CGrid::sendIndex(void) |
---|
| 415 | { |
---|
[347] | 416 | CContext* context = CContext::getCurrent() ; |
---|
[300] | 417 | CContextClient* client=context->client ; |
---|
| 418 | |
---|
| 419 | CEventClient event(getType(),EVENT_ID_INDEX) ; |
---|
| 420 | int rank ; |
---|
| 421 | list<shared_ptr<CMessage> > list_msg ; |
---|
[369] | 422 | list< CArray<int,1>* > list_out_i,list_out_j,list_out_l ; |
---|
[300] | 423 | |
---|
| 424 | for(int ns=0;ns<domain->connectedServer.size();ns++) |
---|
| 425 | { |
---|
| 426 | rank=domain->connectedServer[ns] ; |
---|
| 427 | |
---|
| 428 | int i,j ; |
---|
| 429 | int nb=0 ; |
---|
[369] | 430 | for(int k=0;k<storeIndex_client.numElements();k++) |
---|
[300] | 431 | { |
---|
[467] | 432 | i=out_i_client(k)- domain->ibegin +1; |
---|
| 433 | j=out_j_client(k)- domain->jbegin +1; |
---|
| 434 | if (domain->mapConnectedServer(i,j)==ns) nb++ ; |
---|
[300] | 435 | } |
---|
| 436 | |
---|
[369] | 437 | CArray<int,1> storeIndex(nb) ; |
---|
| 438 | CArray<int,1> out_i(nb) ; |
---|
| 439 | CArray<int,1> out_j(nb) ; |
---|
| 440 | CArray<int,1> out_l(nb) ; |
---|
| 441 | |
---|
[300] | 442 | |
---|
| 443 | nb=0 ; |
---|
[369] | 444 | for(int k=0;k<storeIndex_client.numElements();k++) |
---|
[300] | 445 | { |
---|
[467] | 446 | i=out_i_client(k)- domain->ibegin +1 ; |
---|
| 447 | j=out_j_client(k)- domain->jbegin +1 ; |
---|
| 448 | if (domain->mapConnectedServer(i,j)==ns) |
---|
[300] | 449 | { |
---|
[369] | 450 | storeIndex(nb)=k ; |
---|
[467] | 451 | out_i(nb)=domain->i_index(i,j) + domain->ibegin-1; |
---|
| 452 | out_j(nb)=domain->j_index(i,j) + domain->jbegin-1; |
---|
[369] | 453 | out_l(nb)=out_l_client(k) ; |
---|
[300] | 454 | nb++ ; |
---|
| 455 | } |
---|
| 456 | } |
---|
| 457 | |
---|
[369] | 458 | storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(storeIndex) )) ; |
---|
[300] | 459 | nbSenders.insert(pair<int,int>(rank,domain->nbSenders[ns])) ; |
---|
| 460 | list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ; |
---|
[369] | 461 | list_out_i.push_back(new CArray<int,1>(out_i)) ; |
---|
| 462 | list_out_j.push_back(new CArray<int,1>(out_j)) ; |
---|
| 463 | list_out_l.push_back(new CArray<int,1>(out_l)) ; |
---|
[300] | 464 | |
---|
[369] | 465 | *list_msg.back()<<getId()<<*list_out_i.back()<<*list_out_j.back()<<*list_out_l.back() ; |
---|
[300] | 466 | event.push(rank,domain->nbSenders[ns],*list_msg.back()) ; |
---|
| 467 | } |
---|
| 468 | client->sendEvent(event) ; |
---|
[369] | 469 | |
---|
| 470 | for(list<CArray<int,1>* >::iterator it=list_out_i.begin();it!=list_out_i.end();it++) delete *it ; |
---|
| 471 | for(list<CArray<int,1>* >::iterator it=list_out_j.begin();it!=list_out_j.end();it++) delete *it ; |
---|
| 472 | for(list<CArray<int,1>* >::iterator it=list_out_l.begin();it!=list_out_l.end();it++) delete *it ; |
---|
| 473 | |
---|
[300] | 474 | } |
---|
| 475 | |
---|
| 476 | void CGrid::recvIndex(CEventServer& event) |
---|
| 477 | { |
---|
| 478 | list<CEventServer::SSubEvent>::iterator it ; |
---|
| 479 | for (it=event.subEvents.begin();it!=event.subEvents.end();++it) |
---|
| 480 | { |
---|
| 481 | int rank=it->rank; |
---|
| 482 | CBufferIn* buffer=it->buffer; |
---|
| 483 | string domainId ; |
---|
| 484 | *buffer>>domainId ; |
---|
| 485 | get(domainId)->recvIndex(rank,*buffer) ; |
---|
| 486 | } |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | void CGrid::recvIndex(int rank, CBufferIn& buffer) |
---|
| 490 | { |
---|
[369] | 491 | CArray<int,1> out_i ; |
---|
| 492 | CArray<int,1> out_j ; |
---|
| 493 | CArray<int,1> out_l ; |
---|
[300] | 494 | |
---|
| 495 | buffer>>out_i>>out_j>>out_l ; |
---|
| 496 | |
---|
[369] | 497 | out_i -= domain->zoom_ibegin_srv-1 ; |
---|
| 498 | out_j -= domain->zoom_jbegin_srv-1 ; |
---|
[300] | 499 | |
---|
[369] | 500 | out_i_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_i) )) ; |
---|
| 501 | out_j_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_j) )) ; |
---|
| 502 | out_l_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_l) )) ; |
---|
[300] | 503 | } |
---|
| 504 | |
---|
| 505 | bool CGrid::dispatchEvent(CEventServer& event) |
---|
| 506 | { |
---|
| 507 | |
---|
| 508 | if (SuperClass::dispatchEvent(event)) return true ; |
---|
| 509 | else |
---|
| 510 | { |
---|
| 511 | switch(event.type) |
---|
| 512 | { |
---|
| 513 | case EVENT_ID_INDEX : |
---|
| 514 | recvIndex(event) ; |
---|
| 515 | return true ; |
---|
| 516 | break ; |
---|
| 517 | |
---|
| 518 | default : |
---|
| 519 | ERROR("bool CDomain::dispatchEvent(CEventServer& event)", |
---|
| 520 | <<"Unknown Event") ; |
---|
| 521 | return false ; |
---|
| 522 | } |
---|
| 523 | } |
---|
| 524 | } |
---|
| 525 | |
---|
[369] | 526 | void CGrid::inputFieldServer(const std::deque< CArray<double, 1>* > storedClient, CArray<double, 1>& storedServer) const |
---|
[219] | 527 | { |
---|
| 528 | if ((this->storeIndex.size()-1 ) != storedClient.size()) |
---|
[369] | 529 | ERROR("void CGrid::inputFieldServer(const std::deque< CArray<double, 1>* > storedClient, CArray<double, 1>& storedServer) const", |
---|
[421] | 530 | << "[ Expected received field = " << (this->storeIndex.size()-1) << ", " |
---|
| 531 | << "[ received fiedl = " << storedClient.size() << "] " |
---|
| 532 | << "Data from clients are missing!") ; |
---|
[369] | 533 | storedServer.resize(storeIndex[0]->numElements()); |
---|
[219] | 534 | |
---|
| 535 | for (StdSize i = 0, n = 0; i < storedClient.size(); i++) |
---|
[369] | 536 | for (StdSize j = 0; j < storedClient[i]->numElements(); j++) |
---|
| 537 | storedServer(n++) = (*storedClient[i])(j); |
---|
[219] | 538 | } |
---|
| 539 | |
---|
[369] | 540 | void CGrid::outputFieldToServer(CArray<double,1>& fieldIn, int rank, CArray<double,1>& fieldOut) |
---|
[300] | 541 | { |
---|
[369] | 542 | CArray<int,1>& index = *storeIndex_toSrv[rank] ; |
---|
| 543 | int nb=index.numElements() ; |
---|
| 544 | fieldOut.resize(nb) ; |
---|
[300] | 545 | |
---|
[369] | 546 | for(int k=0;k<nb;k++) fieldOut(k)=fieldIn(index(k)) ; |
---|
[300] | 547 | } |
---|
[219] | 548 | ///--------------------------------------------------------------- |
---|
| 549 | |
---|
[335] | 550 | } // namespace xios |
---|