[219] | 1 | #include "domain.hpp" |
---|
| 2 | |
---|
[352] | 3 | #include "attribute_template.hpp" |
---|
| 4 | #include "object_template.hpp" |
---|
| 5 | #include "group_template.hpp" |
---|
[219] | 6 | |
---|
[591] | 7 | #include "xios_spl.hpp" |
---|
[300] | 8 | #include "event_client.hpp" |
---|
| 9 | #include "event_server.hpp" |
---|
| 10 | #include "buffer_in.hpp" |
---|
[352] | 11 | #include "message.hpp" |
---|
| 12 | #include "type.hpp" |
---|
| 13 | #include "context.hpp" |
---|
| 14 | #include "context_client.hpp" |
---|
[369] | 15 | #include "array_new.hpp" |
---|
[553] | 16 | #include "server_distribution_description.hpp" |
---|
[569] | 17 | #include "client_server_mapping_distributed.hpp" |
---|
[274] | 18 | |
---|
[335] | 19 | namespace xios { |
---|
[509] | 20 | |
---|
[219] | 21 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 22 | |
---|
| 23 | CDomain::CDomain(void) |
---|
| 24 | : CObjectTemplate<CDomain>(), CDomainAttributes() |
---|
[584] | 25 | , isChecked(false), relFiles(), isClientChecked(false), nbConnectedClients_(), indSrv_(), connectedServerRank_() |
---|
[611] | 26 | , hasBounds(false), hasArea(false), isDistributed_(false) |
---|
[219] | 27 | { /* Ne rien faire de plus */ } |
---|
| 28 | |
---|
| 29 | CDomain::CDomain(const StdString & id) |
---|
| 30 | : CObjectTemplate<CDomain>(id), CDomainAttributes() |
---|
[584] | 31 | , isChecked(false), relFiles(), isClientChecked(false), nbConnectedClients_(), indSrv_(), connectedServerRank_() |
---|
[611] | 32 | , hasBounds(false), hasArea(false), isDistributed_(false) |
---|
[449] | 33 | { /* Ne rien faire de plus */ } |
---|
[219] | 34 | |
---|
| 35 | CDomain::~CDomain(void) |
---|
[509] | 36 | { |
---|
[219] | 37 | } |
---|
| 38 | |
---|
| 39 | ///--------------------------------------------------------------- |
---|
| 40 | |
---|
[622] | 41 | CDomain* CDomain::createDomain() |
---|
| 42 | { |
---|
| 43 | CDomain* domain = CDomainGroup::get("domain_definition")->createChild(); |
---|
| 44 | return domain; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | void CDomain::duplicateAttributes(CDomain* domain) |
---|
| 48 | { |
---|
| 49 | domain->setAttributes(this); |
---|
| 50 | } |
---|
| 51 | |
---|
[219] | 52 | const std::set<StdString> & CDomain::getRelFiles(void) const |
---|
| 53 | { |
---|
[509] | 54 | return (this->relFiles); |
---|
[219] | 55 | } |
---|
| 56 | |
---|
| 57 | //---------------------------------------------------------------- |
---|
[509] | 58 | |
---|
[219] | 59 | bool CDomain::hasZoom(void) const |
---|
| 60 | { |
---|
[509] | 61 | return ((this->zoom_ni.getValue() != this->ni_glo.getValue()) && |
---|
[219] | 62 | (this->zoom_nj.getValue() != this->nj_glo.getValue())); |
---|
| 63 | } |
---|
[509] | 64 | |
---|
[219] | 65 | //---------------------------------------------------------------- |
---|
[509] | 66 | |
---|
[219] | 67 | bool CDomain::isEmpty(void) const |
---|
| 68 | { |
---|
[509] | 69 | return ((this->zoom_ni_srv == 0) || |
---|
[300] | 70 | (this->zoom_nj_srv == 0)); |
---|
[219] | 71 | } |
---|
| 72 | |
---|
| 73 | //---------------------------------------------------------------- |
---|
| 74 | |
---|
| 75 | bool CDomain::IsWritten(const StdString & filename) const |
---|
| 76 | { |
---|
| 77 | return (this->relFiles.find(filename) != this->relFiles.end()); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | //---------------------------------------------------------------- |
---|
| 81 | |
---|
[594] | 82 | bool CDomain::isDistributed(void) const |
---|
| 83 | { |
---|
| 84 | return isDistributed_; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | //---------------------------------------------------------------- |
---|
| 88 | |
---|
[219] | 89 | void CDomain::addRelFile(const StdString & filename) |
---|
| 90 | { |
---|
| 91 | this->relFiles.insert(filename); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | StdString CDomain::GetName(void) { return (StdString("domain")); } |
---|
| 96 | StdString CDomain::GetDefName(void){ return (CDomain::GetName()); } |
---|
| 97 | ENodeType CDomain::GetType(void) { return (eDomain); } |
---|
| 98 | |
---|
| 99 | //---------------------------------------------------------------- |
---|
| 100 | |
---|
[467] | 101 | void CDomain::checkDomain(void) |
---|
[219] | 102 | { |
---|
[449] | 103 | if (!type.isEmpty() && type==type_attr::unstructured) |
---|
| 104 | { |
---|
| 105 | if (ni_glo.isEmpty() || ni_glo <= 0 ) |
---|
| 106 | { |
---|
| 107 | ERROR("CDomain::checkAttributes(void)", |
---|
| 108 | << "[ Id = " << this->getId() << " ] " |
---|
| 109 | << "The global domain is badly defined," |
---|
[509] | 110 | << " check the \'ni_glo\' value !") |
---|
[449] | 111 | } |
---|
| 112 | nj_glo=ni_glo ; |
---|
| 113 | ni_glo=1 ; |
---|
| 114 | if (!ni.isEmpty()) nj=ni ; |
---|
| 115 | if (!ibegin.isEmpty()) jbegin=ibegin ; |
---|
| 116 | if (!iend.isEmpty()) jend=iend ; |
---|
[467] | 117 | if (!i_index.isEmpty()) |
---|
| 118 | { |
---|
| 119 | j_index.resize(1,nj) ; |
---|
| 120 | for(int i=0;i<ni;i++) j_index(0,i)=i_index(i,0) ; |
---|
| 121 | i_index.resize(1,nj) ; |
---|
| 122 | for(int j=0;j<nj;j++) i_index(0,j)=0 ; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | if (!mask.isEmpty()) |
---|
| 126 | { |
---|
| 127 | CArray<int,2> mask_tmp(nj,1) ; |
---|
| 128 | mask_tmp = mask ; |
---|
| 129 | mask.resize(1,nj) ; |
---|
| 130 | for(int j=0;j<nj;j++) mask(0,j)=mask_tmp(j,0) ; |
---|
| 131 | } |
---|
[611] | 132 | |
---|
| 133 | if (!area.isEmpty()) |
---|
| 134 | area.transposeSelf(1, 0); |
---|
| 135 | |
---|
[449] | 136 | ni=1 ; |
---|
[551] | 137 | ibegin=0 ; |
---|
| 138 | iend=0 ; |
---|
[509] | 139 | |
---|
[449] | 140 | } |
---|
| 141 | else if ((ni_glo.isEmpty() || ni_glo.getValue() <= 0 ) || |
---|
[274] | 142 | (nj_glo.isEmpty() || nj_glo.getValue() <= 0 )) |
---|
| 143 | { |
---|
[219] | 144 | ERROR("CDomain::checkAttributes(void)", |
---|
| 145 | << "[ Id = " << this->getId() << " ] " |
---|
[421] | 146 | << "The global domain is badly defined," |
---|
[509] | 147 | << " check the \'ni_glo\' et \'nj_glo\' values !") |
---|
[274] | 148 | } |
---|
[509] | 149 | |
---|
[594] | 150 | isDistributed_ = !ibegin.isEmpty() || !iend.isEmpty() || !ni.isEmpty() || !jbegin.isEmpty() || !jend.isEmpty() || !nj.isEmpty(); |
---|
[509] | 151 | |
---|
[594] | 152 | checkLocalIDomain(); |
---|
| 153 | checkLocalJDomain(); |
---|
[509] | 154 | |
---|
[594] | 155 | ibegin_client = ibegin; iend_client = iend; ni_client = ni; |
---|
| 156 | jbegin_client = jbegin; jend_client = jend; nj_client = nj; |
---|
| 157 | |
---|
| 158 | if (i_index.isEmpty()) |
---|
| 159 | { |
---|
| 160 | i_index.resize(ni,nj); |
---|
| 161 | for (int j = 0; j < nj; j++) |
---|
| 162 | for (int i = 0; i < ni; i++) i_index(i,j) = i; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | if (j_index.isEmpty()) |
---|
| 166 | { |
---|
| 167 | j_index.resize(ni,nj); |
---|
| 168 | for (int j = 0; j < nj; j++) |
---|
| 169 | for (int i = 0; i < ni; i++) j_index(i,j) = j; |
---|
| 170 | } |
---|
[219] | 171 | } |
---|
| 172 | |
---|
| 173 | //---------------------------------------------------------------- |
---|
| 174 | |
---|
| 175 | void CDomain::checkLocalIDomain(void) |
---|
| 176 | { |
---|
| 177 | if (!ni.isEmpty() && !ibegin.isEmpty() && iend.isEmpty()) |
---|
[594] | 178 | iend.setValue(ibegin.getValue() + ni.getValue() - 1); |
---|
| 179 | else if (!ni.isEmpty() && !iend.isEmpty() && ibegin.isEmpty()) |
---|
| 180 | ibegin.setValue(iend.getValue() - ni.getValue() + 1); |
---|
[219] | 181 | else if (!ibegin.isEmpty() && !iend.isEmpty() && ni.isEmpty()) |
---|
[594] | 182 | ni.setValue(iend.getValue() - ibegin.getValue() + 1); |
---|
| 183 | else if (!ibegin.isEmpty() && !iend.isEmpty() && !ni.isEmpty()) |
---|
[219] | 184 | { |
---|
[594] | 185 | if (iend.getValue() != ibegin.getValue() + ni.getValue() - 1) |
---|
| 186 | ERROR("CDomain::checkLocalIDomain(void)", |
---|
| 187 | << "[ Id = " << this->getId() << " ] " |
---|
| 188 | << "The local domain is wrongly defined," |
---|
| 189 | << " iend is different from (ibegin + ni - 1)"); |
---|
[219] | 190 | } |
---|
[594] | 191 | else if (ibegin.isEmpty() && iend.isEmpty() && ni.isEmpty()) |
---|
| 192 | { |
---|
| 193 | ibegin = 0; |
---|
| 194 | iend = ni_glo - 1; |
---|
| 195 | ni = ni_glo; |
---|
| 196 | } |
---|
[219] | 197 | else |
---|
| 198 | { |
---|
[594] | 199 | ERROR("CDomain::checkLocalIDomain(void)", |
---|
| 200 | << "[ Id = " << this->getId() << " ] " |
---|
| 201 | << "The local domain is wrongly defined," |
---|
| 202 | << " defining just one attribute among 'ibegin', 'iend' or 'ni' is invalid"); |
---|
[219] | 203 | } |
---|
| 204 | |
---|
| 205 | if (ni.getValue() < 0 || ibegin.getValue() > iend.getValue() || |
---|
[594] | 206 | ibegin.getValue() < 0 || iend.getValue() > (ni_glo.getValue() - 1)) |
---|
| 207 | { |
---|
| 208 | ERROR("CDomain::checkLocalIDomain(void)", |
---|
| 209 | << "[ Id = " << this->getId() << " ] " |
---|
| 210 | << "The local domain is wrongly defined," |
---|
| 211 | << " check the attributes 'ni_glo', 'ni', 'ibegin' and 'iend'"); |
---|
| 212 | } |
---|
[219] | 213 | } |
---|
| 214 | |
---|
| 215 | //---------------------------------------------------------------- |
---|
| 216 | |
---|
| 217 | void CDomain::checkLocalJDomain(void) |
---|
| 218 | { |
---|
| 219 | if (!nj.isEmpty() && !jbegin.isEmpty() && jend.isEmpty()) |
---|
[594] | 220 | jend.setValue(jbegin.getValue() + nj.getValue() - 1); |
---|
[219] | 221 | else if (!nj.isEmpty() && !jend.isEmpty() && jbegin.isEmpty()) |
---|
[594] | 222 | jbegin.setValue(jend.getValue() - nj.getValue() + 1); |
---|
[219] | 223 | else if (!jbegin.isEmpty() && !jend.isEmpty() && nj.isEmpty()) |
---|
[594] | 224 | nj.setValue(jend.getValue() - jbegin.getValue() + 1); |
---|
| 225 | else if (!jbegin.isEmpty() && !jend.isEmpty() && !nj.isEmpty()) |
---|
[219] | 226 | { |
---|
[594] | 227 | if (jend.getValue() != jbegin.getValue() + nj.getValue() - 1) |
---|
| 228 | ERROR("CDomain::checkLocalJDomain(void)", |
---|
| 229 | << "[ Id = " << this->getId() << " ] " |
---|
| 230 | << "The local domain is wrongly defined," |
---|
| 231 | << " jend is different from (jbegin + nj - 1)"); |
---|
[219] | 232 | } |
---|
[594] | 233 | else if (jbegin.isEmpty() && jend.isEmpty() && nj.isEmpty()) |
---|
| 234 | { |
---|
| 235 | jbegin = 0; |
---|
| 236 | jend = nj_glo - 1; |
---|
| 237 | nj = nj_glo; |
---|
| 238 | } |
---|
[219] | 239 | else |
---|
| 240 | { |
---|
[594] | 241 | ERROR("CDomain::checkLocalJDomain(void)", |
---|
| 242 | << "[ Id = " << this->getId() << " ] " |
---|
| 243 | << "The local domain is wrongly defined," |
---|
| 244 | << " defining just one attribute among 'jbegin', 'jend' or 'nj' is invalid"); |
---|
[219] | 245 | } |
---|
| 246 | |
---|
| 247 | if (nj.getValue() < 0 || jbegin.getValue() > jend.getValue() || |
---|
[594] | 248 | jbegin.getValue() < 0 || jend.getValue() > (nj_glo.getValue() - 1)) |
---|
| 249 | { |
---|
| 250 | ERROR("CDomain::checkLocalJDomain(void)", |
---|
| 251 | << "[ Id = " << this->getId() << " ] " |
---|
| 252 | << "The local domain is wrongly defined," |
---|
| 253 | << " check the attributes 'nj_glo', 'nj', 'jbegin' and 'jend'"); |
---|
| 254 | } |
---|
[219] | 255 | } |
---|
| 256 | |
---|
| 257 | //---------------------------------------------------------------- |
---|
| 258 | |
---|
| 259 | void CDomain::checkMask(void) |
---|
| 260 | { |
---|
| 261 | using namespace std; |
---|
[509] | 262 | |
---|
[219] | 263 | int ibegin_mask = 0, |
---|
| 264 | jbegin_mask = 0, |
---|
| 265 | iend_mask = iend.getValue() - ibegin.getValue(), |
---|
| 266 | jend_mask = jend.getValue() - jbegin.getValue(); |
---|
[509] | 267 | |
---|
[219] | 268 | if (!zoom_ibegin.isEmpty()) |
---|
| 269 | { |
---|
| 270 | int zoom_iend = zoom_ibegin.getValue() + zoom_ni.getValue() - 1; |
---|
| 271 | int zoom_jend = zoom_jbegin.getValue() + zoom_nj.getValue() - 1; |
---|
[509] | 272 | |
---|
[219] | 273 | ibegin_mask = max (ibegin.getValue(), zoom_ibegin.getValue()); |
---|
| 274 | jbegin_mask = max (jbegin.getValue(), zoom_jbegin.getValue()); |
---|
| 275 | iend_mask = min (iend.getValue(), zoom_iend); |
---|
| 276 | jend_mask = min (jend.getValue(), zoom_jend); |
---|
[509] | 277 | |
---|
[219] | 278 | ibegin_mask -= ibegin.getValue(); |
---|
| 279 | jbegin_mask -= jbegin.getValue(); |
---|
| 280 | iend_mask -= ibegin.getValue(); |
---|
| 281 | jend_mask -= jbegin.getValue(); |
---|
| 282 | } |
---|
| 283 | |
---|
[509] | 284 | |
---|
[219] | 285 | if (!mask.isEmpty()) |
---|
| 286 | { |
---|
[467] | 287 | if ((mask.extent(0) != ni) || |
---|
| 288 | (mask.extent(1) != nj)) |
---|
[219] | 289 | ERROR("CDomain::checkAttributes(void)", |
---|
[435] | 290 | <<"the mask has not the same size than the local domain"<<endl |
---|
[467] | 291 | <<"Local size is "<<ni<<"x"<<nj<<endl |
---|
[509] | 292 | <<"Mask size is "<<mask.extent(0)<<"x"<<mask.extent(1)); |
---|
[467] | 293 | for (int i = 0; i < ni; i++) |
---|
[219] | 294 | { |
---|
[467] | 295 | for (int j = 0; j < nj; j++) |
---|
[219] | 296 | { |
---|
| 297 | if (i < ibegin_mask && i > iend_mask && |
---|
| 298 | j < jbegin_mask && j > jend_mask ) |
---|
[369] | 299 | mask(i,j) = false; |
---|
[219] | 300 | } |
---|
| 301 | } |
---|
| 302 | } |
---|
| 303 | else // (!mask.hasValue()) |
---|
| 304 | { // Si aucun masque n'est défini, |
---|
| 305 | // on en crée un nouveau qui valide l'intégralité du domaine. |
---|
[369] | 306 | mask.resize(ni,nj) ; |
---|
[219] | 307 | for (int i = 0; i < ni.getValue(); i++) |
---|
| 308 | { |
---|
| 309 | for (int j = 0; j < nj.getValue(); j++) |
---|
| 310 | { |
---|
| 311 | if (i >= ibegin_mask && i <= iend_mask && |
---|
| 312 | j >= jbegin_mask && j <= jend_mask ) |
---|
[369] | 313 | mask(i,j) = true; |
---|
| 314 | else mask(i,j) = false; |
---|
[219] | 315 | } |
---|
| 316 | } |
---|
| 317 | } |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | |
---|
| 321 | //---------------------------------------------------------------- |
---|
| 322 | |
---|
| 323 | void CDomain::checkDomainData(void) |
---|
[509] | 324 | { |
---|
[219] | 325 | if (!data_dim.isEmpty() && |
---|
| 326 | !(data_dim.getValue() == 1 || data_dim.getValue() == 2)) |
---|
| 327 | { |
---|
| 328 | ERROR("CDomain::checkAttributes(void)", |
---|
[421] | 329 | << "Data dimension incompatible (must be 1 or 2) !") ; |
---|
[219] | 330 | } |
---|
| 331 | else if (data_dim.isEmpty()) |
---|
| 332 | { |
---|
| 333 | ERROR("CDomain::checkAttributes(void)", |
---|
[421] | 334 | << "Data dimension undefined !") ; |
---|
[219] | 335 | } |
---|
| 336 | |
---|
| 337 | if (data_ibegin.isEmpty()) |
---|
| 338 | data_ibegin.setValue(0) ; |
---|
| 339 | if (data_jbegin.isEmpty() && (data_dim.getValue() == 2)) |
---|
| 340 | data_jbegin.setValue(0) ; |
---|
| 341 | |
---|
| 342 | if (!data_ni.isEmpty() && (data_ni.getValue() <= 0)) |
---|
| 343 | { |
---|
| 344 | ERROR("CDomain::checkAttributes(void)", |
---|
[421] | 345 | << "Data dimension is negative (data_ni).") ; |
---|
[219] | 346 | } |
---|
| 347 | else if (data_ni.isEmpty()) |
---|
| 348 | { |
---|
| 349 | data_ni.setValue((data_dim.getValue() == 1) |
---|
| 350 | ? (ni.getValue() * nj.getValue()) |
---|
| 351 | : ni.getValue()); |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | if (data_dim.getValue() == 2) |
---|
| 355 | { |
---|
| 356 | if (!data_nj.isEmpty() && (data_nj.getValue() <= 0) ) |
---|
| 357 | { |
---|
| 358 | ERROR("CDomain::checkAttributes(void)", |
---|
[421] | 359 | << "Data dimension is negative (data_nj).") ; |
---|
[219] | 360 | } |
---|
| 361 | else if (data_nj.isEmpty()) |
---|
| 362 | data_nj.setValue(nj.getValue()) ; |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | } |
---|
| 366 | |
---|
| 367 | //---------------------------------------------------------------- |
---|
| 368 | |
---|
| 369 | void CDomain::checkCompression(void) |
---|
| 370 | { |
---|
| 371 | if (!data_i_index.isEmpty()) |
---|
| 372 | { |
---|
[369] | 373 | int ssize = data_i_index.numElements(); |
---|
[219] | 374 | if (!data_n_index.isEmpty() && |
---|
| 375 | (data_n_index.getValue() != ssize)) |
---|
| 376 | { |
---|
| 377 | ERROR("CDomain::checkAttributes(void)", |
---|
[421] | 378 | <<"Dimension data_i_index incompatible with data_n_index.") ; |
---|
[219] | 379 | } |
---|
| 380 | else if (data_n_index.isEmpty()) |
---|
| 381 | data_n_index.setValue(ssize) ; |
---|
| 382 | |
---|
| 383 | if (data_dim.getValue() == 2) |
---|
| 384 | { |
---|
| 385 | if (!data_j_index.isEmpty() && |
---|
[369] | 386 | (data_j_index.numElements() != data_i_index.numElements())) |
---|
[219] | 387 | { |
---|
| 388 | ERROR("CDomain::checkAttributes(void)", |
---|
[421] | 389 | <<"Dimension data_j_index incompatible with data_i_index.") ; |
---|
[219] | 390 | } |
---|
| 391 | else if (data_j_index.isEmpty()) |
---|
| 392 | { |
---|
| 393 | ERROR("CDomain::checkAttributes(void)", |
---|
[421] | 394 | <<"data_j_index must be defined !") ; |
---|
[219] | 395 | } |
---|
| 396 | } |
---|
| 397 | } |
---|
| 398 | else |
---|
| 399 | { |
---|
| 400 | if (!data_n_index.isEmpty() || |
---|
| 401 | ((data_dim.getValue() == 2) && (!data_j_index.isEmpty()))) |
---|
[421] | 402 | ERROR("CDomain::checkAttributes(void)", << "data_i_index undefined") ; |
---|
[219] | 403 | } |
---|
| 404 | |
---|
| 405 | if (data_n_index.isEmpty()) |
---|
| 406 | { // -> bloc re-vérifié OK |
---|
| 407 | if (data_dim.getValue() == 1) |
---|
| 408 | { |
---|
| 409 | const int dni = data_ni.getValue(); |
---|
[369] | 410 | data_i_index.resize(dni) ; |
---|
[219] | 411 | data_n_index.setValue(dni); |
---|
[369] | 412 | for (int i = 0; i < dni; i++) data_i_index(i) = i+1 ; |
---|
[219] | 413 | } |
---|
| 414 | else // (data_dim == 2) |
---|
| 415 | { |
---|
| 416 | const int dni = data_ni.getValue() * data_nj.getValue(); |
---|
[369] | 417 | data_i_index.resize(dni) ; |
---|
| 418 | data_j_index.resize(dni) ; |
---|
[509] | 419 | |
---|
[219] | 420 | data_n_index.setValue(dni); |
---|
[509] | 421 | |
---|
[266] | 422 | for(int count = 0, j = 0; j < data_nj.getValue(); j++) |
---|
[219] | 423 | { |
---|
[266] | 424 | for(int i = 0; i < data_ni.getValue(); i++, count++) |
---|
[219] | 425 | { |
---|
[369] | 426 | data_i_index(count) = i+1 ; |
---|
| 427 | data_j_index(count) = j+1 ; |
---|
[219] | 428 | } |
---|
| 429 | } |
---|
| 430 | } |
---|
| 431 | } |
---|
| 432 | } |
---|
| 433 | |
---|
| 434 | //---------------------------------------------------------------- |
---|
[509] | 435 | |
---|
[266] | 436 | void CDomain::completeLonLatClient(void) |
---|
[219] | 437 | { |
---|
[384] | 438 | int i,j,k ; |
---|
| 439 | CArray<double,1> lonvalue_temp(ni*nj) ; |
---|
| 440 | CArray<double,1> latvalue_temp(ni*nj) ; |
---|
[449] | 441 | CArray<double,2> bounds_lon_temp(nvertex,ni*nj) ; |
---|
| 442 | CArray<double,2> bounds_lat_temp(nvertex,ni*nj) ; |
---|
[509] | 443 | |
---|
[449] | 444 | if (type.isEmpty()) |
---|
[384] | 445 | { |
---|
[509] | 446 | if ( lonvalue.numElements() == ni*nj && latvalue.numElements() == ni*nj ) |
---|
[449] | 447 | { |
---|
| 448 | type.setValue(type_attr::curvilinear) ; |
---|
| 449 | isCurvilinear=true ; |
---|
| 450 | } |
---|
[509] | 451 | else if ( lonvalue.numElements() == ni && latvalue.numElements() == nj ) |
---|
[449] | 452 | { |
---|
| 453 | type.setValue(type_attr::regular) ; |
---|
| 454 | isCurvilinear=false ; |
---|
| 455 | } |
---|
| 456 | else ERROR("void CDomain::completeLonLatClient(void)",<<"the grid is nor curvilinear, nor cartesian, because the size of longitude and latitude array is not coherent with the domain size"<<endl |
---|
| 457 | <<"lonvalue size = " << lonvalue.numElements() << "different of ni or ni*nj"<<endl |
---|
| 458 | <<"latvalue size = " << latvalue.numElements() << "different of nj or ni*nj" ) ; |
---|
| 459 | } |
---|
| 460 | if (type==type_attr::curvilinear || type==type_attr::unstructured) |
---|
| 461 | { |
---|
[384] | 462 | lonvalue_temp=lonvalue ; |
---|
| 463 | latvalue_temp=latvalue ; |
---|
[449] | 464 | if (hasBounds) bounds_lon_temp=bounds_lon ; |
---|
| 465 | if (hasBounds) bounds_lat_temp=bounds_lat ; |
---|
[384] | 466 | } |
---|
| 467 | else |
---|
| 468 | { |
---|
| 469 | for(j=0;j<nj;j++) |
---|
[509] | 470 | for(i=0;i<ni;i++) |
---|
[384] | 471 | { |
---|
| 472 | k=j*ni+i ; |
---|
| 473 | lonvalue_temp(k)=lonvalue(i) ; |
---|
| 474 | latvalue_temp(k)=latvalue(j) ; |
---|
[449] | 475 | if (hasBounds) |
---|
| 476 | { |
---|
[509] | 477 | for(int n=0;n<nvertex;n++) |
---|
[449] | 478 | { |
---|
| 479 | bounds_lon_temp(n,k)=bounds_lon(n,i) ; |
---|
| 480 | bounds_lat_temp(n,k)=bounds_lat(n,j) ; |
---|
| 481 | } |
---|
| 482 | } |
---|
[384] | 483 | } |
---|
| 484 | } |
---|
[509] | 485 | |
---|
[384] | 486 | StdSize dm = zoom_ni_client * zoom_nj_client; |
---|
[266] | 487 | |
---|
[584] | 488 | // Make sure that this attribute is non-empty for every client. |
---|
| 489 | if (0 != dm) |
---|
| 490 | { |
---|
| 491 | lonvalue.resize(dm); |
---|
| 492 | latvalue.resize(dm); |
---|
| 493 | } |
---|
[509] | 494 | |
---|
[584] | 495 | |
---|
[384] | 496 | for (int i = 0; i < zoom_ni_client; i++) |
---|
| 497 | { |
---|
| 498 | for (int j = 0; j < zoom_nj_client; j++) |
---|
| 499 | { |
---|
[509] | 500 | lonvalue(i + j * zoom_ni_client) = lonvalue_temp( (i + zoom_ibegin_client-ibegin) + (j + zoom_jbegin_client -jbegin)*ni ); |
---|
[449] | 501 | latvalue(i + j * zoom_ni_client) = latvalue_temp( (i + zoom_ibegin_client - ibegin)+(j + zoom_jbegin_client - jbegin)*ni ); |
---|
| 502 | if (hasBounds) |
---|
| 503 | { |
---|
[509] | 504 | for(int n=0;n<nvertex;n++) |
---|
[449] | 505 | { |
---|
[509] | 506 | bounds_lon(n,i + j * zoom_ni_client) = bounds_lon_temp( n, (i + zoom_ibegin_client - ibegin) + (j + zoom_jbegin_client -jbegin)*ni ); |
---|
[449] | 507 | bounds_lat(n,i + j * zoom_ni_client) = bounds_lat_temp( n, (i + zoom_ibegin_client - ibegin)+(j + zoom_jbegin_client -jbegin)*ni ); |
---|
| 508 | } |
---|
| 509 | } |
---|
[384] | 510 | } |
---|
[266] | 511 | } |
---|
[449] | 512 | } |
---|
[219] | 513 | |
---|
[509] | 514 | |
---|
[219] | 515 | //---------------------------------------------------------------- |
---|
| 516 | |
---|
| 517 | void CDomain::checkZoom(void) |
---|
| 518 | { |
---|
| 519 | // Résolution et vérification des données globales de zoom. |
---|
| 520 | if (!this->zoom_ni.isEmpty() || !this->zoom_nj.isEmpty() || |
---|
| 521 | !this->zoom_ibegin.isEmpty() || !this->zoom_jbegin.isEmpty()) |
---|
| 522 | { |
---|
[384] | 523 | if (this->zoom_ni.isEmpty() || this->zoom_nj.isEmpty() || |
---|
| 524 | this->zoom_ibegin.isEmpty() || this->zoom_jbegin.isEmpty()) |
---|
[219] | 525 | { |
---|
| 526 | ERROR("CDomain::checkZoom(void)", |
---|
[384] | 527 | <<"if one of zoom attributes is defined then all zoom attributes must be defined") ; |
---|
[219] | 528 | } |
---|
| 529 | else |
---|
| 530 | { |
---|
[449] | 531 | int zoom_iend = zoom_ibegin + zoom_ni - 1; |
---|
| 532 | int zoom_jend = zoom_jbegin + zoom_nj - 1; |
---|
[509] | 533 | |
---|
[551] | 534 | if (zoom_ibegin < 0 || zoom_jbegin < 0 || zoom_iend > (ni_glo-1) || zoom_jend > (nj_glo-1)) |
---|
[219] | 535 | ERROR("CDomain::checkZoom(void)", |
---|
[594] | 536 | << "Zoom is wrongly defined," |
---|
[479] | 537 | << " Check the values : zoom_ni, zoom_nj, zoom_ibegin, zoom_jbegin") ; |
---|
[219] | 538 | } |
---|
| 539 | } |
---|
| 540 | else |
---|
| 541 | { |
---|
[509] | 542 | zoom_ni = ni_glo; |
---|
[449] | 543 | zoom_nj = nj_glo; |
---|
[551] | 544 | zoom_ibegin = 0; |
---|
| 545 | zoom_jbegin = 0; |
---|
[219] | 546 | } |
---|
[509] | 547 | |
---|
[449] | 548 | // compute client zoom indices |
---|
| 549 | |
---|
| 550 | int zoom_iend=zoom_ibegin+zoom_ni-1 ; |
---|
| 551 | zoom_ibegin_client = ibegin_client > zoom_ibegin ? ibegin_client : zoom_ibegin ; |
---|
| 552 | zoom_iend_client = iend_client < zoom_iend ? iend_client : zoom_iend ; |
---|
| 553 | zoom_ni_client=zoom_iend_client-zoom_ibegin_client+1 ; |
---|
| 554 | if (zoom_ni_client<0) zoom_ni_client=0 ; |
---|
| 555 | |
---|
[509] | 556 | |
---|
[449] | 557 | int zoom_jend=zoom_jbegin+zoom_nj-1 ; |
---|
| 558 | zoom_jbegin_client = jbegin_client > zoom_jbegin ? jbegin_client : zoom_jbegin ; |
---|
| 559 | zoom_jend_client = jend_client < zoom_jend ? jend_client : zoom_jend ; |
---|
| 560 | zoom_nj_client=zoom_jend_client-zoom_jbegin_client+1 ; |
---|
| 561 | if (zoom_nj_client<0) zoom_nj_client=0 ; |
---|
[467] | 562 | |
---|
[219] | 563 | } |
---|
[509] | 564 | |
---|
[449] | 565 | void CDomain::checkBounds(void) |
---|
| 566 | { |
---|
| 567 | if (!nvertex.isEmpty() && !bounds_lon.isEmpty() && !bounds_lat.isEmpty()) |
---|
| 568 | { |
---|
| 569 | hasBounds=true ; |
---|
| 570 | } |
---|
[509] | 571 | else |
---|
[449] | 572 | { |
---|
| 573 | hasBounds=false; |
---|
| 574 | nvertex=0 ; |
---|
| 575 | } |
---|
| 576 | } |
---|
[509] | 577 | |
---|
[611] | 578 | void CDomain::checkArea(void) |
---|
| 579 | { |
---|
| 580 | hasArea = !area.isEmpty(); |
---|
| 581 | if (hasArea) |
---|
| 582 | { |
---|
| 583 | if (area.extent(0) != ni || area.extent(1) != nj) |
---|
| 584 | { |
---|
| 585 | ERROR("void CDomain::checkArea(void)", |
---|
| 586 | "The area attribute must be of size ni x nj."); |
---|
| 587 | } |
---|
| 588 | } |
---|
| 589 | } |
---|
| 590 | |
---|
[219] | 591 | //---------------------------------------------------------------- |
---|
[509] | 592 | // Divide function checkAttributes into 2 seperate ones |
---|
| 593 | // This function only checks all attributes of current domain |
---|
| 594 | void CDomain::checkAttributesOnClient() |
---|
| 595 | { |
---|
| 596 | if (this->isClientChecked) return; |
---|
| 597 | CContext* context=CContext::getCurrent(); |
---|
[219] | 598 | |
---|
[509] | 599 | this->checkDomain(); |
---|
| 600 | this->checkZoom(); |
---|
| 601 | this->checkBounds(); |
---|
[611] | 602 | this->checkArea(); |
---|
[509] | 603 | |
---|
| 604 | if (context->hasClient) |
---|
| 605 | { // CÎté client uniquement |
---|
| 606 | this->checkMask(); |
---|
| 607 | this->checkDomainData(); |
---|
| 608 | this->checkCompression(); |
---|
| 609 | this->completeLonLatClient(); |
---|
| 610 | this->computeConnectedServer() ; |
---|
| 611 | } |
---|
| 612 | else |
---|
| 613 | { // CÎté serveur uniquement |
---|
| 614 | // if (!this->isEmpty()) |
---|
| 615 | // ne sert plus // this->completeLonLatServer(); |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | this->isClientChecked = true; |
---|
| 619 | } |
---|
| 620 | |
---|
| 621 | // Send all checked attributes to server |
---|
| 622 | void CDomain::sendCheckedAttributes() |
---|
| 623 | { |
---|
| 624 | if (!this->isClientChecked) checkAttributesOnClient(); |
---|
| 625 | CContext* context=CContext::getCurrent() ; |
---|
| 626 | |
---|
| 627 | if (this->isChecked) return; |
---|
| 628 | if (context->hasClient) |
---|
| 629 | { |
---|
| 630 | sendServerAttribut() ; |
---|
[611] | 631 | sendLonLatArea() ; |
---|
[509] | 632 | } |
---|
| 633 | |
---|
| 634 | this->isChecked = true; |
---|
| 635 | } |
---|
| 636 | |
---|
[219] | 637 | void CDomain::checkAttributes(void) |
---|
| 638 | { |
---|
| 639 | if (this->isChecked) return; |
---|
[347] | 640 | CContext* context=CContext::getCurrent() ; |
---|
[219] | 641 | |
---|
[467] | 642 | this->checkDomain(); |
---|
[219] | 643 | this->checkZoom(); |
---|
[449] | 644 | this->checkBounds(); |
---|
[611] | 645 | this->checkArea(); |
---|
[509] | 646 | |
---|
[300] | 647 | if (context->hasClient) |
---|
[219] | 648 | { // CÎté client uniquement |
---|
| 649 | this->checkMask(); |
---|
| 650 | this->checkDomainData(); |
---|
| 651 | this->checkCompression(); |
---|
[449] | 652 | this->completeLonLatClient(); |
---|
[219] | 653 | } |
---|
| 654 | else |
---|
| 655 | { // CÎté serveur uniquement |
---|
[286] | 656 | // if (!this->isEmpty()) |
---|
[300] | 657 | // ne sert plus // this->completeLonLatServer(); |
---|
[219] | 658 | } |
---|
[509] | 659 | |
---|
[300] | 660 | if (context->hasClient) |
---|
| 661 | { |
---|
| 662 | computeConnectedServer() ; |
---|
| 663 | sendServerAttribut() ; |
---|
[611] | 664 | sendLonLatArea() ; |
---|
[300] | 665 | } |
---|
[509] | 666 | |
---|
[219] | 667 | this->isChecked = true; |
---|
| 668 | } |
---|
[509] | 669 | |
---|
[300] | 670 | void CDomain::sendServerAttribut(void) |
---|
| 671 | { |
---|
[553] | 672 | std::vector<int> nGlobDomain(2); |
---|
| 673 | nGlobDomain[0] = ni_glo.getValue(); |
---|
| 674 | nGlobDomain[1] = nj_glo.getValue(); |
---|
| 675 | CServerDistributionDescription serverDescription(nGlobDomain); |
---|
| 676 | |
---|
[595] | 677 | CContext* context = CContext::getCurrent(); |
---|
| 678 | CContextClient* client = context->client; |
---|
| 679 | int nbServer = client->serverSize; |
---|
[509] | 680 | |
---|
[595] | 681 | serverDescription.computeServerDistribution(nbServer); |
---|
| 682 | std::vector<std::vector<int> > serverIndexBegin = serverDescription.getServerIndexBegin(); |
---|
| 683 | std::vector<std::vector<int> > serverDimensionSizes = serverDescription.getServerDimensionSizes(); |
---|
[509] | 684 | |
---|
[595] | 685 | CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT); |
---|
| 686 | if (client->isServerLeader()) |
---|
| 687 | { |
---|
| 688 | std::list<CMessage> msgs; |
---|
[509] | 689 | |
---|
[595] | 690 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 691 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 692 | { |
---|
| 693 | // Use const int to ensure CMessage holds a copy of the value instead of just a reference |
---|
| 694 | const int ibegin_srv = serverIndexBegin[*itRank][0]; |
---|
| 695 | const int jbegin_srv = serverIndexBegin[*itRank][1]; |
---|
| 696 | const int ni_srv = serverDimensionSizes[*itRank][0]; |
---|
| 697 | const int nj_srv = serverDimensionSizes[*itRank][1]; |
---|
| 698 | const int iend_srv = ibegin_srv + ni_srv - 1; |
---|
| 699 | const int jend_srv = jbegin_srv + nj_srv - 1; |
---|
[509] | 700 | |
---|
[595] | 701 | msgs.push_back(CMessage()); |
---|
| 702 | CMessage& msg = msgs.back(); |
---|
| 703 | msg << this->getId() ; |
---|
| 704 | msg << ni_srv << ibegin_srv << iend_srv << nj_srv << jbegin_srv << jend_srv; |
---|
| 705 | |
---|
| 706 | event.push(*itRank,1,msg); |
---|
| 707 | } |
---|
| 708 | client->sendEvent(event); |
---|
| 709 | } |
---|
| 710 | else client->sendEvent(event); |
---|
[300] | 711 | } |
---|
[467] | 712 | |
---|
[300] | 713 | void CDomain::computeConnectedServer(void) |
---|
| 714 | { |
---|
[467] | 715 | ibegin_client=ibegin ; iend_client=iend ; ni_client=ni ; |
---|
| 716 | jbegin_client=jbegin ; jend_client=jend ; nj_client=nj ; |
---|
[509] | 717 | |
---|
[553] | 718 | CContext* context=CContext::getCurrent() ; |
---|
[300] | 719 | CContextClient* client=context->client ; |
---|
[553] | 720 | int nbServer=client->serverSize; |
---|
| 721 | bool doComputeGlobalIndexServer = true; |
---|
[449] | 722 | |
---|
[553] | 723 | int i,j,i_ind,j_ind ; |
---|
[449] | 724 | int zoom_iend=zoom_ibegin+zoom_ni-1 ; |
---|
| 725 | int zoom_jend=zoom_jbegin+zoom_nj-1 ; |
---|
[509] | 726 | |
---|
[553] | 727 | // Precompute number of index |
---|
[584] | 728 | int globalIndexCountZoom = 0; |
---|
[467] | 729 | for(j=0;j<nj;j++) |
---|
| 730 | for(i=0;i<ni;i++) |
---|
| 731 | { |
---|
[551] | 732 | i_ind=ibegin+i_index(i,j) ; |
---|
| 733 | j_ind=jbegin+j_index(i,j) ; |
---|
[509] | 734 | |
---|
[551] | 735 | if (i_ind >= zoom_ibegin && i_ind <= zoom_iend && j_ind >= zoom_jbegin && j_ind <= zoom_jend) |
---|
[300] | 736 | { |
---|
[584] | 737 | ++globalIndexCountZoom; |
---|
[300] | 738 | } |
---|
[467] | 739 | } |
---|
| 740 | |
---|
[553] | 741 | // Fill in index |
---|
[584] | 742 | CArray<size_t,1> globalIndexDomainZoom(globalIndexCountZoom); |
---|
| 743 | CArray<size_t,1> globalIndexDomain(ni*nj); |
---|
[553] | 744 | size_t globalIndex; |
---|
[584] | 745 | int globalIndexCount = 0; |
---|
| 746 | globalIndexCountZoom = 0; |
---|
[467] | 747 | |
---|
[553] | 748 | for(j=0;j<nj;j++) |
---|
| 749 | for(i=0;i<ni;i++) |
---|
[467] | 750 | { |
---|
[553] | 751 | i_ind=ibegin+i_index(i,j) ; |
---|
| 752 | j_ind=jbegin+j_index(i,j) ; |
---|
[509] | 753 | |
---|
[584] | 754 | globalIndex = i_ind + j_ind * ni_glo; |
---|
| 755 | globalIndexDomain(globalIndexCount) = globalIndex; |
---|
| 756 | ++globalIndexCount; |
---|
[553] | 757 | if (i_ind >= zoom_ibegin && i_ind <= zoom_iend && j_ind >= zoom_jbegin && j_ind <= zoom_jend) |
---|
[300] | 758 | { |
---|
[584] | 759 | globalIndexDomainZoom(globalIndexCountZoom) = globalIndex; |
---|
| 760 | ++globalIndexCountZoom; |
---|
[300] | 761 | } |
---|
| 762 | } |
---|
[509] | 763 | |
---|
[569] | 764 | std::vector<int> nGlobDomain(2); |
---|
| 765 | nGlobDomain[0] = ni_glo.getValue(); |
---|
| 766 | nGlobDomain[1] = nj_glo.getValue(); |
---|
| 767 | size_t globalSizeIndex = 1, indexBegin, indexEnd; |
---|
| 768 | int range, clientSize = client->clientSize; |
---|
| 769 | for (int i = 0; i < nGlobDomain.size(); ++i) globalSizeIndex *= nGlobDomain[i]; |
---|
| 770 | indexBegin = 0; |
---|
| 771 | for (int i = 0; i < clientSize; ++i) |
---|
| 772 | { |
---|
| 773 | range = globalSizeIndex / clientSize; |
---|
| 774 | if (i < (globalSizeIndex%clientSize)) ++range; |
---|
| 775 | if (i == client->clientRank) break; |
---|
| 776 | indexBegin += range; |
---|
| 777 | } |
---|
| 778 | indexEnd = indexBegin + range - 1; |
---|
| 779 | |
---|
| 780 | CServerDistributionDescription serverDescription(nGlobDomain); |
---|
| 781 | serverDescription.computeServerGlobalIndexInRange(nbServer, std::make_pair<size_t,size_t>(indexBegin, indexEnd)); |
---|
| 782 | CClientServerMapping* clientServerMap = new CClientServerMappingDistributed(serverDescription.getGlobalIndexRange(), |
---|
| 783 | client->intraComm); |
---|
| 784 | clientServerMap->computeServerIndexMapping(globalIndexDomain); |
---|
| 785 | const std::map<int, std::vector<size_t> >& globalIndexDomainOnServer = clientServerMap->getGlobalIndexOnServer(); |
---|
[584] | 786 | |
---|
| 787 | std::map<int, std::vector<size_t> >::const_iterator it = globalIndexDomainOnServer.begin(), |
---|
| 788 | ite = globalIndexDomainOnServer.end(); |
---|
| 789 | indSrv_.clear(); |
---|
| 790 | for (; it != ite; ++it) |
---|
| 791 | { |
---|
| 792 | int rank = it->first; |
---|
| 793 | std::vector<size_t>::const_iterator itbVec = (it->second).begin(), |
---|
| 794 | iteVec = (it->second).end(); |
---|
| 795 | int nb = globalIndexDomainZoom.numElements(); |
---|
| 796 | for (int i = 0; i < nb; ++i) |
---|
| 797 | { |
---|
[585] | 798 | if (iteVec != std::find(itbVec, iteVec, globalIndexDomainZoom(i))) |
---|
[584] | 799 | { |
---|
| 800 | indSrv_[rank].push_back(globalIndexDomainZoom(i)); |
---|
| 801 | } |
---|
| 802 | } |
---|
[553] | 803 | } |
---|
[569] | 804 | |
---|
[584] | 805 | connectedServerRank_.clear(); |
---|
| 806 | for (it = globalIndexDomainOnServer.begin(); it != ite; ++it) { |
---|
| 807 | connectedServerRank_.push_back(it->first); |
---|
| 808 | } |
---|
| 809 | |
---|
| 810 | if (!indSrv_.empty()) |
---|
| 811 | { |
---|
| 812 | connectedServerRank_.clear(); |
---|
| 813 | for (it = indSrv_.begin(); it != indSrv_.end(); ++it) |
---|
| 814 | connectedServerRank_.push_back(it->first); |
---|
| 815 | } |
---|
| 816 | nbConnectedClients_ = clientServerMap->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); |
---|
| 817 | |
---|
[569] | 818 | delete clientServerMap; |
---|
[300] | 819 | } |
---|
[467] | 820 | |
---|
[611] | 821 | void CDomain::sendLonLatArea(void) |
---|
[300] | 822 | { |
---|
[610] | 823 | int ns, n, i, j, ind, nv, idx; |
---|
| 824 | CContext* context = CContext::getCurrent(); |
---|
| 825 | CContextClient* client=context->client; |
---|
| 826 | |
---|
[300] | 827 | // send lon lat for each connected server |
---|
[610] | 828 | CEventClient eventIndex(getType(), EVENT_ID_INDEX); |
---|
| 829 | CEventClient eventLon(getType(), EVENT_ID_LON); |
---|
| 830 | CEventClient eventLat(getType(), EVENT_ID_LAT); |
---|
[611] | 831 | CEventClient eventArea(getType(), EVENT_ID_AREA); |
---|
[509] | 832 | |
---|
[611] | 833 | list<CMessage> list_msgsIndex, list_msgsLon, list_msgsLat, list_msgsArea; |
---|
[610] | 834 | list<CArray<int,1> > list_indi, list_indj; |
---|
| 835 | list<CArray<double,1> > list_lon, list_lat; |
---|
| 836 | list<CArray<double,2> > list_boundslon, list_boundslat; |
---|
[611] | 837 | list<CArray<double,1> > list_area; |
---|
[518] | 838 | |
---|
[610] | 839 | std::map<int, std::vector<size_t> >::const_iterator it, iteMap; |
---|
[553] | 840 | iteMap = indSrv_.end(); |
---|
[584] | 841 | for (int k = 0; k < connectedServerRank_.size(); ++k) |
---|
[300] | 842 | { |
---|
[584] | 843 | int nbData = 0; |
---|
| 844 | int rank = connectedServerRank_[k]; |
---|
| 845 | it = indSrv_.find(rank); |
---|
| 846 | if (iteMap != it) |
---|
[610] | 847 | nbData = it->second.size(); |
---|
[584] | 848 | |
---|
[610] | 849 | list_indi.push_back(CArray<int,1>(nbData)); |
---|
| 850 | list_indj.push_back(CArray<int,1>(nbData)); |
---|
| 851 | list_lon.push_back(CArray<double,1>(nbData)); |
---|
| 852 | list_lat.push_back(CArray<double,1>(nbData)); |
---|
[509] | 853 | |
---|
[610] | 854 | if (hasBounds) |
---|
| 855 | { |
---|
| 856 | list_boundslon.push_back(CArray<double,2>(nvertex, nbData)); |
---|
| 857 | list_boundslat.push_back(CArray<double,2>(nvertex, nbData)); |
---|
| 858 | } |
---|
[611] | 859 | if (hasArea) |
---|
| 860 | list_area.push_back(CArray<double,1>(nbData)); |
---|
[610] | 861 | |
---|
| 862 | CArray<int,1>& indi = list_indi.back(); |
---|
| 863 | CArray<int,1>& indj = list_indj.back(); |
---|
| 864 | CArray<double,1>& lon = list_lon.back(); |
---|
| 865 | CArray<double,1>& lat = list_lat.back(); |
---|
| 866 | |
---|
[553] | 867 | for (n = 0; n < nbData; ++n) |
---|
[467] | 868 | { |
---|
[610] | 869 | idx = static_cast<int>(it->second[n]); |
---|
| 870 | i = idx % ni_glo; |
---|
| 871 | j = idx / ni_glo; |
---|
| 872 | ind = (i - zoom_ibegin_client) + (j - zoom_jbegin_client) * zoom_ni_client; |
---|
[509] | 873 | |
---|
[610] | 874 | lon(n) = lonvalue(ind); |
---|
| 875 | lat(n) = latvalue(ind); |
---|
| 876 | |
---|
[467] | 877 | if (hasBounds) |
---|
[300] | 878 | { |
---|
[610] | 879 | CArray<double,2>& boundslon = list_boundslon.back(); |
---|
| 880 | CArray<double,2>& boundslat = list_boundslat.back(); |
---|
| 881 | |
---|
| 882 | for (nv = 0; nv < nvertex; nv++) |
---|
[449] | 883 | { |
---|
[610] | 884 | boundslon(nv, n) = bounds_lon(nv, ind); |
---|
| 885 | boundslat(nv, n) = bounds_lat(nv, ind); |
---|
[449] | 886 | } |
---|
[300] | 887 | } |
---|
[610] | 888 | |
---|
| 889 | indi(n) = ibegin + i_index(i - ibegin, j - jbegin); |
---|
| 890 | indj(n) = jbegin + j_index(i - ibegin, j - jbegin); |
---|
[611] | 891 | |
---|
| 892 | if (hasArea) |
---|
| 893 | list_area.back()(n) = area(i - ibegin, j - jbegin); |
---|
[467] | 894 | } |
---|
[509] | 895 | |
---|
[610] | 896 | list_msgsIndex.push_back(CMessage()); |
---|
[369] | 897 | |
---|
[610] | 898 | list_msgsIndex.back() << this->getId() << (int)type; // enum ne fonctionne pour les message => ToFix |
---|
| 899 | list_msgsIndex.back() << isCurvilinear; |
---|
| 900 | list_msgsIndex.back() << list_indi.back() << list_indj.back(); |
---|
[300] | 901 | |
---|
[610] | 902 | list_msgsLon.push_back(CMessage()); |
---|
| 903 | list_msgsLat.push_back(CMessage()); |
---|
[518] | 904 | |
---|
[610] | 905 | list_msgsLon.back() << this->getId() << list_lon.back(); |
---|
| 906 | list_msgsLat.back() << this->getId() << list_lat.back(); |
---|
| 907 | |
---|
[518] | 908 | if (hasBounds) |
---|
| 909 | { |
---|
[610] | 910 | list_msgsLon.back() << list_boundslon.back(); |
---|
| 911 | list_msgsLat.back() << list_boundslat.back(); |
---|
[518] | 912 | } |
---|
[584] | 913 | |
---|
[610] | 914 | eventIndex.push(rank, nbConnectedClients_[rank], list_msgsIndex.back()); |
---|
| 915 | eventLon.push(rank, nbConnectedClients_[rank], list_msgsLon.back()); |
---|
| 916 | eventLat.push(rank, nbConnectedClients_[rank], list_msgsLat.back()); |
---|
[611] | 917 | |
---|
| 918 | if (hasArea) |
---|
| 919 | { |
---|
| 920 | list_msgsArea.push_back(CMessage()); |
---|
| 921 | list_msgsArea.back() << this->getId() << list_area.back(); |
---|
| 922 | eventArea.push(rank, nbConnectedClients_[rank], list_msgsArea.back()); |
---|
| 923 | } |
---|
[300] | 924 | } |
---|
| 925 | |
---|
[610] | 926 | client->sendEvent(eventIndex); |
---|
| 927 | client->sendEvent(eventLon); |
---|
| 928 | client->sendEvent(eventLat); |
---|
[611] | 929 | if (hasArea) |
---|
| 930 | client->sendEvent(eventArea); |
---|
[300] | 931 | } |
---|
[509] | 932 | |
---|
[300] | 933 | bool CDomain::dispatchEvent(CEventServer& event) |
---|
[610] | 934 | { |
---|
| 935 | if (SuperClass::dispatchEvent(event)) return true; |
---|
| 936 | else |
---|
| 937 | { |
---|
| 938 | switch(event.type) |
---|
[300] | 939 | { |
---|
[610] | 940 | case EVENT_ID_SERVER_ATTRIBUT: |
---|
| 941 | recvServerAttribut(event); |
---|
| 942 | return true; |
---|
| 943 | break; |
---|
| 944 | case EVENT_ID_INDEX: |
---|
| 945 | recvIndex(event); |
---|
| 946 | return true; |
---|
| 947 | break; |
---|
| 948 | case EVENT_ID_LON: |
---|
| 949 | recvLon(event); |
---|
| 950 | return true; |
---|
| 951 | break; |
---|
| 952 | case EVENT_ID_LAT: |
---|
| 953 | recvLat(event); |
---|
| 954 | return true; |
---|
| 955 | break; |
---|
[611] | 956 | case EVENT_ID_AREA: |
---|
| 957 | recvArea(event); |
---|
| 958 | return true; |
---|
| 959 | break; |
---|
[610] | 960 | default: |
---|
| 961 | ERROR("bool CContext::dispatchEvent(CEventServer& event)", |
---|
| 962 | << "Unknown Event"); |
---|
| 963 | return false; |
---|
| 964 | } |
---|
| 965 | } |
---|
| 966 | } |
---|
[509] | 967 | |
---|
[300] | 968 | void CDomain::recvServerAttribut(CEventServer& event) |
---|
| 969 | { |
---|
| 970 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 971 | string domainId ; |
---|
| 972 | *buffer>>domainId ; |
---|
| 973 | get(domainId)->recvServerAttribut(*buffer) ; |
---|
| 974 | } |
---|
[509] | 975 | |
---|
[300] | 976 | void CDomain::recvServerAttribut(CBufferIn& buffer) |
---|
| 977 | { |
---|
[595] | 978 | int zoom_iend = zoom_ibegin.getValue() + zoom_ni.getValue() - 1; |
---|
| 979 | int zoom_jend = zoom_jbegin.getValue() + zoom_nj.getValue() - 1; |
---|
[300] | 980 | |
---|
[595] | 981 | buffer >> ni_srv >> ibegin_srv >> iend_srv >> nj_srv >> jbegin_srv >> jend_srv; |
---|
[509] | 982 | |
---|
[300] | 983 | zoom_ibegin_srv = zoom_ibegin.getValue() > ibegin_srv ? zoom_ibegin.getValue() : ibegin_srv ; |
---|
| 984 | zoom_iend_srv = zoom_iend < iend_srv ? zoom_iend : iend_srv ; |
---|
| 985 | zoom_ni_srv=zoom_iend_srv-zoom_ibegin_srv+1 ; |
---|
[509] | 986 | |
---|
[300] | 987 | zoom_jbegin_srv = zoom_jbegin.getValue() > jbegin_srv ? zoom_jbegin.getValue() : jbegin_srv ; |
---|
| 988 | zoom_jend_srv = zoom_jend < jend_srv ? zoom_jend : jend_srv ; |
---|
| 989 | zoom_nj_srv=zoom_jend_srv-zoom_jbegin_srv+1 ; |
---|
| 990 | |
---|
[509] | 991 | if (zoom_ni_srv<=0 || zoom_nj_srv<=0) |
---|
[300] | 992 | { |
---|
[551] | 993 | zoom_ibegin_srv=0 ; zoom_iend_srv=0 ; zoom_ni_srv=0 ; |
---|
| 994 | zoom_jbegin_srv=0 ; zoom_jend_srv=0 ; zoom_nj_srv=0 ; |
---|
[300] | 995 | } |
---|
[369] | 996 | lonvalue_srv.resize(zoom_ni_srv*zoom_nj_srv) ; |
---|
[456] | 997 | lonvalue_srv = 0. ; |
---|
[369] | 998 | latvalue_srv.resize(zoom_ni_srv*zoom_nj_srv) ; |
---|
[456] | 999 | latvalue_srv = 0. ; |
---|
[509] | 1000 | if (hasBounds) |
---|
[456] | 1001 | { |
---|
| 1002 | bounds_lon_srv.resize(nvertex,zoom_ni_srv*zoom_nj_srv) ; |
---|
| 1003 | bounds_lon_srv = 0. ; |
---|
| 1004 | bounds_lat_srv.resize(nvertex,zoom_ni_srv*zoom_nj_srv) ; |
---|
| 1005 | bounds_lat_srv = 0. ; |
---|
| 1006 | } |
---|
[611] | 1007 | |
---|
| 1008 | if (hasArea) |
---|
| 1009 | area_srv.resize(zoom_ni_srv * zoom_nj_srv); |
---|
[300] | 1010 | } |
---|
[509] | 1011 | |
---|
[610] | 1012 | void CDomain::recvIndex(CEventServer& event) |
---|
| 1013 | { |
---|
| 1014 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 1015 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
| 1016 | { |
---|
| 1017 | CBufferIn* buffer = it->buffer; |
---|
| 1018 | string domainId; |
---|
| 1019 | *buffer >> domainId; |
---|
| 1020 | get(domainId)->recvIndex(it->rank, *buffer); |
---|
| 1021 | } |
---|
| 1022 | } |
---|
| 1023 | |
---|
| 1024 | void CDomain::recvIndex(int rank, CBufferIn& buffer) |
---|
| 1025 | { |
---|
| 1026 | int type_int; |
---|
| 1027 | buffer >> type_int >> isCurvilinear >> indiSrv[rank] >> indjSrv[rank]; |
---|
| 1028 | type.setValue((type_attr::t_enum)type_int); // probleme des type enum avec les buffers : ToFix |
---|
| 1029 | } |
---|
| 1030 | |
---|
[518] | 1031 | void CDomain::recvLon(CEventServer& event) |
---|
[300] | 1032 | { |
---|
[610] | 1033 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 1034 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
[300] | 1035 | { |
---|
[610] | 1036 | CBufferIn* buffer = it->buffer; |
---|
| 1037 | string domainId; |
---|
| 1038 | *buffer >> domainId; |
---|
| 1039 | get(domainId)->recvLon(it->rank, *buffer); |
---|
[300] | 1040 | } |
---|
| 1041 | } |
---|
[509] | 1042 | |
---|
[610] | 1043 | void CDomain::recvLon(int rank, CBufferIn& buffer) |
---|
[300] | 1044 | { |
---|
[610] | 1045 | CArray<int,1> &indi = indiSrv[rank], &indj = indjSrv[rank]; |
---|
| 1046 | CArray<double,1> lon; |
---|
| 1047 | CArray<double,2> boundslon; |
---|
[518] | 1048 | |
---|
[610] | 1049 | buffer >> lon; |
---|
| 1050 | if (hasBounds) buffer >> boundslon; |
---|
[518] | 1051 | |
---|
[610] | 1052 | int i, j, ind_srv; |
---|
| 1053 | for (int ind = 0; ind < indi.numElements(); ind++) |
---|
[518] | 1054 | { |
---|
[610] | 1055 | i = indi(ind); j = indj(ind); |
---|
| 1056 | ind_srv = (i - zoom_ibegin_srv) + (j - zoom_jbegin_srv) * zoom_ni_srv; |
---|
| 1057 | lonvalue_srv(ind_srv) = lon(ind); |
---|
[518] | 1058 | if (hasBounds) |
---|
| 1059 | { |
---|
[610] | 1060 | for (int nv = 0; nv < nvertex; nv++) |
---|
| 1061 | bounds_lon_srv(nv, ind_srv) = boundslon(nv, ind); |
---|
[518] | 1062 | } |
---|
| 1063 | } |
---|
| 1064 | } |
---|
| 1065 | |
---|
| 1066 | void CDomain::recvLat(CEventServer& event) |
---|
| 1067 | { |
---|
[610] | 1068 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 1069 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
[518] | 1070 | { |
---|
[610] | 1071 | CBufferIn* buffer = it->buffer; |
---|
| 1072 | string domainId; |
---|
| 1073 | *buffer >> domainId; |
---|
| 1074 | get(domainId)->recvLat(it->rank, *buffer); |
---|
[518] | 1075 | } |
---|
| 1076 | } |
---|
| 1077 | |
---|
[610] | 1078 | void CDomain::recvLat(int rank, CBufferIn& buffer) |
---|
[518] | 1079 | { |
---|
[610] | 1080 | CArray<int,1> &indi = indiSrv[rank], &indj = indjSrv[rank]; |
---|
| 1081 | CArray<double,1> lat; |
---|
| 1082 | CArray<double,2> boundslat; |
---|
[509] | 1083 | |
---|
[610] | 1084 | buffer >> lat; |
---|
| 1085 | if (hasBounds) buffer >> boundslat; |
---|
| 1086 | |
---|
| 1087 | int i, j, ind_srv; |
---|
| 1088 | for (int ind = 0; ind < indi.numElements(); ind++) |
---|
[300] | 1089 | { |
---|
[610] | 1090 | i = indi(ind); j = indj(ind); |
---|
| 1091 | ind_srv = (i - zoom_ibegin_srv) + (j - zoom_jbegin_srv) * zoom_ni_srv; |
---|
| 1092 | latvalue_srv(ind_srv) = lat(ind); |
---|
[509] | 1093 | if (hasBounds) |
---|
[449] | 1094 | { |
---|
[610] | 1095 | for (int nv = 0; nv < nvertex; nv++) |
---|
| 1096 | bounds_lat_srv(nv, ind_srv) = boundslat(nv, ind); |
---|
[449] | 1097 | } |
---|
[300] | 1098 | } |
---|
| 1099 | } |
---|
[553] | 1100 | |
---|
[611] | 1101 | void CDomain::recvArea(CEventServer& event) |
---|
| 1102 | { |
---|
| 1103 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 1104 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
| 1105 | { |
---|
| 1106 | CBufferIn* buffer = it->buffer; |
---|
| 1107 | string domainId; |
---|
| 1108 | *buffer >> domainId; |
---|
| 1109 | get(domainId)->recvArea(it->rank, *buffer); |
---|
| 1110 | } |
---|
| 1111 | } |
---|
| 1112 | |
---|
| 1113 | void CDomain::recvArea(int rank, CBufferIn& buffer) |
---|
| 1114 | { |
---|
| 1115 | CArray<int,1> &indi = indiSrv[rank], &indj = indjSrv[rank]; |
---|
| 1116 | CArray<double,1> clientArea; |
---|
| 1117 | |
---|
| 1118 | buffer >> clientArea; |
---|
| 1119 | |
---|
| 1120 | int i, j, ind_srv; |
---|
| 1121 | for (int ind = 0; ind < indi.numElements(); ind++) |
---|
| 1122 | { |
---|
| 1123 | i = indi(ind); j = indj(ind); |
---|
| 1124 | ind_srv = (i - zoom_ibegin_srv) + (j - zoom_jbegin_srv) * zoom_ni_srv; |
---|
| 1125 | area_srv(ind_srv) = clientArea(ind); |
---|
| 1126 | } |
---|
| 1127 | } |
---|
| 1128 | |
---|
[219] | 1129 | //---------------------------------------------------------------- |
---|
[509] | 1130 | |
---|
[540] | 1131 | DEFINE_REF_FUNC(Domain,domain) |
---|
[509] | 1132 | |
---|
[219] | 1133 | ///--------------------------------------------------------------- |
---|
| 1134 | |
---|
[335] | 1135 | } // namespace xios |
---|