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