- Timestamp:
- 08/20/21 14:38:23 (3 years ago)
- Location:
- XIOS/dev/dev_ym/XIOS_COUPLING/src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_ym/XIOS_COUPLING/src/declare_ref_func.hpp
r1984 r2203 50 50 refObjects.push_back(refer_ptr); \ 51 51 SuperClassAttribute::setAttributes(refer_ptr, apply); \ 52 setInheritedId(refer_ptr) ; \ 52 53 } \ 53 54 } \ -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/axis.cpp
r2196 r2203 13 13 #include "client_server_mapping_distributed.hpp" 14 14 #include "distribution_client.hpp" 15 16 #include <algorithm> 17 #include <regex> 15 18 16 19 namespace xios { … … 217 220 } 218 221 CATCH 222 223 CAxis* CAxis::get(const string& id) 224 { 225 const regex r("::"); 226 smatch m; 227 if (regex_search(id, m, r)) 228 { 229 if (m.size()!=1) ERROR("CAxis* CAxis::get(string& id)", <<" id = "<<id<< " -> bad format id, separator :: append more than one time"); 230 string fieldId=m.prefix() ; 231 if (fieldId.empty()) ERROR("CAxis* CAxis::get(string& id)", <<" id = "<<id<< " -> bad format id, field name is empty"); 232 string suffix=m.suffix() ; 233 CField* field=CField::get(fieldId) ; 234 return field->getAssociatedAxis(suffix) ; 235 } 236 else return CObjectFactory::GetObject<CAxis>(id).get(); 237 } 219 238 220 239 /*! -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/axis.hpp
r2022 r2203 69 69 70 70 static CAxis* createAxis(); 71 static CAxis* get(const string& id) ; //<! return axis pointer using id 71 72 72 73 /// Accesseurs /// -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/domain.cpp
r2196 r2203 26 26 #include "transformation_path.hpp" 27 27 28 29 30 31 28 #include <algorithm> 29 #include <regex> 30 32 31 33 32 namespace xios { … … 79 78 } 80 79 CATCH 80 81 CDomain* CDomain::get(const string& id) 82 { 83 const regex r("::"); 84 smatch m; 85 if (regex_search(id, m, r)) 86 { 87 if (m.size()!=1) ERROR("CDomain* CDomain::get(string& id)", <<" id = "<<id<< " -> bad format id, separator :: append more than one time"); 88 string fieldId=m.prefix() ; 89 if (fieldId.empty()) ERROR("CDomain* CDomain::get(string& id)", <<" id = "<<id<< " -> bad format id, field name is empty"); 90 string suffix=m.suffix() ; 91 CField* field=CField::get(fieldId) ; 92 return field->getAssociatedDomain(suffix) ; 93 } 94 else return CObjectFactory::GetObject<CDomain>(id).get(); 95 } 96 81 97 82 98 const std::set<StdString> & CDomain::getRelFiles(void) const -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/domain.hpp
r2022 r2203 70 70 CDomain(const CDomain & domain); // Not implemented yet. 71 71 CDomain(const CDomain * const domain); // Not implemented yet. 72 72 73 73 static CDomain* createDomain(); 74 74 static CDomain* get(const string& id) ; //<! return domain pointer using id 75 // static bool has(const string& id) ; //<! return true if domain with identifier id exist 76 75 77 CMesh* mesh; 76 78 void assignMesh(const StdString, const int); -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.cpp
r2193 r2203 326 326 } 327 327 CATCH 328 329 CDomain* CField::getAssociatedDomain(const string& domainId) const 330 { 331 if (grid_==nullptr) ERROR("CDomain* CField::getAssociatedDomain(const string& domainId)", <<" field with id="<<getId()<<" has no associated grid, " 332 <<"check if the worklfow is enabled for this field"); 333 grid_->getAssociatedDomain(domainId) ; 334 } 335 336 CAxis* CField::getAssociatedAxis(const string& axisId) const 337 { 338 if (grid_==nullptr) ERROR("CAxis* CField::getAssociatedAxis(const string& axisId)", <<" field with id="<<getId()<<" has no associated grid, " 339 <<"check if the worklfow is enabled for this field"); 340 grid_->getAssociatedAxis(axisId) ; 341 } 342 343 CScalar* CField::getAssociatedScalar(const string& scalarId) const 344 { 345 if (grid_==nullptr) ERROR("CScalar* CField::getAssociatedScalar(const string& scalarId)", <<" field with id="<<getId()<<" has no associated grid, " 346 <<"check if the worklfow is enabled for this field"); 347 grid_->getAssociatedScalar(scalarId) ; 348 } 349 328 350 329 351 func::CFunctor::ETimeType CField::getOperationTimeType() const -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.hpp
r2182 r2203 48 48 class CContext; 49 49 class CGenericFilter; 50 class CDomain ; 51 class CAxis ; 52 class CScalar ; 50 53 51 54 class CGarbageCollector; … … 101 104 CGrid* getRelGrid(void) const; 102 105 CFile* getRelFile(void) const; 106 CDomain* getAssociatedDomain(const std::string& domainId) const; 107 CAxis* getAssociatedAxis(const std::string& axisId) const; 108 CScalar* getAssociatedScalar(const std::string& scalarId) const; 103 109 104 110 func::CFunctor::ETimeType getOperationTimeType() const; -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.cpp
r2144 r2203 30 30 #include "algo_types.hpp" 31 31 32 #include <regex> 32 33 33 34 namespace xios … … 398 399 } 399 400 CATCH_DUMP_ATTR 401 402 CDomain* CGrid::getAssociatedDomain(const string& domainId) 403 { 404 const regex r("\\[[0-9]*\\]"); 405 smatch m; 406 string id=domainId ; 407 int pos=-1 ; 408 if (regex_search(domainId, m, r)) 409 { 410 if (m.size()!=1) ERROR("CGrid::getAssociatedDomain(const string& domainId)", <<" domainId = "<<domainId<< " -> bad format id, separator [] append more than one time"); 411 id=m.prefix() ; 412 pos = stoi(m.str(0).substr(1,m.str(0).size()-2)) ; 413 } 414 std::vector<CDomain*> domainList = this->getDomains(); 415 if (domainList.empty()) ERROR("CGrid::getAssociatedDomain(const string& domainId)", <<"no domain is compsing the grid"); 416 if (id.empty()) 417 { 418 if (pos==-1) 419 { 420 if (domainList.size()==1) return domainList[0] ; 421 else ERROR("CGrid::getAssociatedDomain(const string& domainId)", <<"the grid contain more than 1 domain, use [#n] to specify which one must be retrieved"); 422 } 423 else 424 { 425 if (domainList.size()>pos) return domainList[pos] ; 426 else ERROR("CGrid::getAssociatedDomain(const string& domainId)", <<"the position of the requested domain [ pos = "<<pos 427 <<" ] is greater than the number of domain composing the grid [ numDomain = "<<domainList.size()<<" ]"); 428 } 429 } 430 else 431 { 432 if (pos==-1) 433 { 434 int nbDomain=0 ; 435 for(int i=0; i<domainList.size();i++) if (domainList[i]->getTemplateId()==id) nbDomain++ ; 436 if (nbDomain>1) ERROR("CGrid::getAssociatedDomain(const string& domainId)", <<"no domain with the id = "<<id 437 <<" is composing the grid") ; 438 if (nbDomain==0) ERROR("CGrid::getAssociatedDomain(const string& domainId)", <<"the grid contain more than 1 domain with the id = " 439 <<id<<" , use [#n] to specify which one must be retrieved") ; 440 for(int i=0; i<domainList.size();i++) if (domainList[i]->getTemplateId()==id) return domainList[i] ; 441 } 442 else 443 { 444 int currentPos=0 ; 445 for(int i=0; i<domainList.size();i++) 446 { 447 if (domainList[i]->getTemplateId()==id && pos==currentPos) return domainList[i] ; 448 currentPos++ ; 449 } 450 ERROR("CGrid::getAssociatedDomain(const string& domainId)",<<"Cannot find domain with [ id = "<< id <<" ] at [ pos = "<<pos<<" ] in the grid"); 451 } 452 } 453 } 454 455 CAxis* CGrid::getAssociatedAxis(const string& axisId) 456 { 457 const regex r("\\[[0-9]*\\]"); 458 smatch m; 459 string id=axisId ; 460 int pos=-1 ; 461 if (regex_search(axisId, m, r)) 462 { 463 if (m.size()!=1) ERROR("CGrid::getAssociatedAxis(const string& axisId)", <<" axisId = "<<axisId<< " -> bad format id, separator [] append more than one time"); 464 id=m.prefix() ; 465 pos = stoi(m.str(0).substr(1,m.str(0).size()-2)) ; 466 } 467 std::vector<CAxis*> axisList = this->getAxis(); 468 if (axisList.empty()) ERROR("CGrid::getAssociatedAxis(const string& AxisId)", <<"no axis is composing the grid"); 469 if (id.empty()) 470 { 471 if (pos==-1) 472 { 473 if (axisList.size()==1) return axisList[0] ; 474 else ERROR("CGrid::getAssociatedAxis(const string& axisId)", <<"the grid contain more than 1 axis, use [#n] to specify which one must be retrieved"); 475 } 476 else 477 { 478 if (axisList.size()>pos) return axisList[pos] ; 479 else ERROR("CGrid::getAssociatedAxis(const string& axisId)", <<"the position of the requested axis [ pos = "<<pos 480 <<" ] is greater than the number of axis composing the grid [ numAxis = "<<axisList.size()<<" ]"); 481 } 482 } 483 else 484 { 485 if (pos==-1) 486 { 487 int nbAxis=0 ; 488 for(int i=0; i<axisList.size();i++) if (axisList[i]->getTemplateId()==id) nbAxis++ ; 489 if (nbAxis>1) ERROR("CGrid::getAssociatedAxis(const string& axisId)", <<"no axis with the id = "<<id 490 <<" is composing the grid") ; 491 if (nbAxis==0) ERROR("CGrid::getAssociatedAxis(const string& axisId)", <<"the grid contain more than 1 axis with the id = " 492 <<id<<" , use [#n] to specify which one must be retrieved") ; 493 for(int i=0; i<axisList.size();i++) if (axisList[i]->getTemplateId()==id) return axisList[i] ; 494 } 495 else 496 { 497 int currentPos=0 ; 498 for(int i=0; i<axisList.size();i++) 499 { 500 if (axisList[i]->getTemplateId()==id && pos==currentPos) return axisList[i] ; 501 currentPos++ ; 502 } 503 ERROR("CGrid::getAssociatedAxis(const string& axisId)",<<"Cannot find axis with [ id = "<< id <<" ] at [ pos = "<<pos<<" ] in the grid"); 504 } 505 } 506 } 507 508 CScalar* CGrid::getAssociatedScalar(const string& scalarId) 509 { 510 const regex r("\\[[0-9]*\\]"); 511 smatch m; 512 string id=scalarId ; 513 int pos=-1 ; 514 if (regex_search(scalarId, m, r)) 515 { 516 if (m.size()!=1) ERROR("CGrid::getAssociatedScalar(const string& scalarId)", <<" scalarId = "<<scalarId<< " -> bad format id, separator [] append more than one time"); 517 id=m.prefix() ; 518 pos = stoi(m.str(0).substr(1,m.str(0).size()-2)) ; 519 } 520 std::vector<CScalar*> scalarList = this->getScalars(); 521 if (scalarList.empty()) ERROR("CGrid::getAssociatedScalar(const string& scalarId)", <<"no scalar is composing the grid"); 522 if (id.empty()) 523 { 524 if (pos==-1) 525 { 526 if (scalarList.size()==1) return scalarList[0] ; 527 else ERROR("CGrid::getAssociatedScalar(const string& scalarId)", <<"the grid contain more than 1 scalar, use [#n] to specify which one must be retrieved"); 528 } 529 else 530 { 531 if (scalarList.size()>pos) return scalarList[pos] ; 532 else ERROR("CGrid::getAssociatedScalar(const string& scalarId)", <<"the position of the requested scalar [ pos = "<<pos 533 <<" ] is greater than the number of scalar composing the grid [ numScalar = "<<scalarList.size()<<" ]"); 534 } 535 } 536 else 537 { 538 if (pos==-1) 539 { 540 int nbScalar=0 ; 541 for(int i=0; i<scalarList.size();i++) if (scalarList[i]->getTemplateId()==id) nbScalar++ ; 542 if (nbScalar>1) ERROR("CGrid::getAssociatedScalar(const string& scalarId)", <<"no scalar with the id = "<<id 543 <<" is composing the grid") ; 544 if (nbScalar==0) ERROR("CGrid::getAssociatedScalar(const string& scalarId)", <<"the grid contain more than 1 scalar with the id = " 545 <<id<<" , use [#n] to specify which one must be retrieved") ; 546 for(int i=0; i<scalarList.size();i++) if (scalarList[i]->getTemplateId()==id) return scalarList[i] ; 547 } 548 else 549 { 550 int currentPos=0 ; 551 for(int i=0; i<scalarList.size();i++) 552 { 553 if (scalarList[i]->getTemplateId()==id && pos==currentPos) return scalarList[i] ; 554 currentPos++ ; 555 } 556 ERROR("CGrid::getAssociatedScalar(const string& scalarId)",<<"Cannot find scalar with [ id = "<< id <<" ] at [ pos = "<<pos<<" ] in the grid"); 557 } 558 } 559 } 560 400 561 401 562 /*! … … 1737 1898 cout<<"Create new domain : "<<dstDomain->getId()<<" with alias : "<<dstElementId<<endl ; 1738 1899 1739 if (isGenerate) dstDomain->duplicateAttributes(lastDstDomain) ; 1740 else if (srcElementId=="" && srcElement.type==TYPE_DOMAIN) dstDomain->duplicateAttributes(srcElement.domain) ; // make a copy 1741 else dstDomain->duplicateAttributes(dstElement.domain) ; // make a copy 1900 if (isGenerate) 1901 { 1902 dstDomain->duplicateAttributes(lastDstDomain) ; 1903 dstDomain->setTemplateId(lastDstDomain) ; 1904 } 1905 else if (srcElementId=="" && srcElement.type==TYPE_DOMAIN) 1906 { 1907 dstDomain->duplicateAttributes(srcElement.domain) ; // make a copy 1908 dstDomain->setTemplateId(srcElement.domain) ; 1909 } 1910 else 1911 { 1912 dstDomain->duplicateAttributes(dstElement.domain) ; // make a copy 1913 dstDomain->setTemplateId(dstElement.domain) ; 1914 } 1742 1915 CTransformation<CDomain>* transformation = CTransformation<CDomain>::createTransformation(transType,"") ; 1743 1916 auto srcTransform = CTransformation<CDomain>::getTransformation(transType, transId) ; … … 1787 1960 cout<<"Create new axis : "<<dstAxis->getId()<<" with alias : "<<dstElementId<<endl ; 1788 1961 1789 if (isGenerate) dstAxis->duplicateAttributes(lastDstAxis) ; 1790 else if (srcElementId=="" && srcElement.type==TYPE_AXIS) dstAxis->duplicateAttributes(srcElement.axis) ; // make a copy 1791 else dstAxis->duplicateAttributes(dstElement.axis) ; // make a copy 1962 if (isGenerate) 1963 { 1964 dstAxis->duplicateAttributes(lastDstAxis) ; 1965 dstAxis->setTemplateId(lastDstAxis) ; 1966 } 1967 else if (srcElementId=="" && srcElement.type==TYPE_AXIS) 1968 { 1969 dstAxis->duplicateAttributes(srcElement.axis) ; // make a copy 1970 dstAxis->setTemplateId(srcElement.axis) ; 1971 } 1972 else 1973 { 1974 dstAxis->duplicateAttributes(dstElement.axis) ; // make a copy$ 1975 dstAxis->setTemplateId(dstElement.axis) ; 1976 } 1792 1977 CTransformation<CAxis>* transformation = CTransformation<CAxis>::createTransformation(transType,"") ; 1793 1978 auto srcTransform = CTransformation<CAxis>::getTransformation(transType, transId) ; … … 1836 2021 cout<<"Create new scalar : "<<dstScalar->getId()<<" with alias : "<<dstElementId<<endl ; 1837 2022 1838 if (isGenerate) dstScalar->duplicateAttributes(lastDstScalar) ; 1839 else if (srcElementId=="" && srcElement.type==TYPE_SCALAR) dstScalar->duplicateAttributes(srcElement.scalar) ; // make a copy 1840 else dstScalar->duplicateAttributes(dstElement.scalar) ; // make a copy 2023 if (isGenerate) 2024 { 2025 dstScalar->duplicateAttributes(lastDstScalar) ; 2026 dstScalar->setTemplateId(lastDstScalar) ; 2027 } 2028 else if (srcElementId=="" && srcElement.type==TYPE_SCALAR) 2029 { 2030 dstScalar->duplicateAttributes(srcElement.scalar) ; // make a copy 2031 dstScalar->setTemplateId(srcElement.scalar) ; 2032 } 2033 else 2034 { 2035 dstScalar->duplicateAttributes(dstElement.scalar) ; // make a copy 2036 dstScalar->setTemplateId(dstElement.scalar) ; 2037 } 1841 2038 CTransformation<CScalar>* transformation = CTransformation<CScalar>::createTransformation(transType,"") ; 1842 2039 auto srcTransform = CTransformation<CScalar>::getTransformation(transType, transId) ; … … 1993 2190 CDomain* domain = CDomain::create(); 1994 2191 domain->duplicateAttributes(element.domain) ; 2192 domain->setTemplateId(element.domain) ; 1995 2193 domain->name = element.domain->getId() ; 1996 2194 newGrid->addDomain(domain->getId()) ; … … 2000 2198 CAxis* axis = CAxis::create(); 2001 2199 axis->duplicateAttributes(element.axis) ; 2200 axis->setTemplateId(element.axis) ; 2002 2201 axis->name = element.axis->getId() ; 2003 2202 newGrid->addAxis(axis->getId()) ; … … 2007 2206 CScalar* scalar = CScalar::create(); 2008 2207 scalar->duplicateAttributes(element.scalar) ; 2208 scalar->setTemplateId(element.scalar) ; 2009 2209 scalar->name = element.scalar->getId() ; 2010 2210 newGrid->addScalar(scalar->getId()) ; -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.hpp
r2144 r2203 147 147 static CGrid* cloneGrid(const StdString& idNewGrid, CGrid* gridSrc); 148 148 149 CDomain* getAssociatedDomain(const string& domainId) ; 150 CAxis* getAssociatedAxis(const string& axisId) ; 151 CScalar* getAssociatedScalar(const string& scalarId) ; 149 152 public: 150 153 void solveDomainAxisRef(bool areAttributesChecked); -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/scalar.cpp
r2196 r2203 9 9 #include "context.hpp" 10 10 11 #include <algorithm> 12 #include <regex> 13 11 14 namespace xios 12 15 { … … 48 51 CScalar* scalar = CScalarGroup::get("scalar_definition")->createChild(); 49 52 return scalar; 53 } 54 55 CScalar* CScalar::get(const string& id) 56 { 57 const regex r("::"); 58 smatch m; 59 if (regex_search(id, m, r)) 60 { 61 if (m.size()!=1) ERROR("CScalar* CScalar::get(string& id)", <<" id = "<<id<< " -> bad format id, separator :: append more than one time"); 62 string fieldId=m.prefix() ; 63 if (fieldId.empty()) ERROR("CScalar* CScalar::get(string& id)", <<" id = "<<id<< " -> bad format id, field name is empty"); 64 string suffix=m.suffix() ; 65 CField* field=CField::get(fieldId) ; 66 return field->getAssociatedScalar(suffix) ; 67 } 68 else return CObjectFactory::GetObject<CScalar>(id).get(); 50 69 } 51 70 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/scalar.hpp
r2022 r2203 78 78 public: 79 79 static CScalar* createScalar(); 80 static CScalar* get(const string& id) ; //<! return scalar pointer using id 80 81 81 82 public: -
XIOS/dev/dev_ym/XIOS_COUPLING/src/object_template.hpp
r1984 r2203 85 85 static T* createAlias(const string& id, const string& alias) ; 86 86 void createAlias(const string& alias) ; 87 87 88 88 static const vector<T*> getAll() ; 89 89 static const vector<T*> getAll(const string& contextId) ; … … 92 92 void generateFortran2003Interface(ostream& oss) ; 93 93 void generateFortranInterface(ostream& oss) ; 94 95 // manage inherited id which is herited by reference 96 void setInheritedId(T* obj) ; 97 bool hasInheritedId(void) { return hasInheritedId_ ;} 98 string getInheritedId(void) { return inheritedId_ ;} 94 99 100 private: 101 std::string inheritedId_ ; 102 bool hasInheritedId_ = false; 103 104 // manage the template id 105 public: 106 void setTemplateId(T* obj) ; //<! set the id of the object that served as template 107 bool hasTemplateId(void) {return hasTemplateId_;} //<! return hasTemplateId_ 108 string getTemplateId(void) 109 { 110 if (hasTemplateId_) return templateId_ ; 111 else if (hasId() && !hasAutoGeneratedId()) return getId() ; 112 else if (hasInheritedId()) return getInheritedId() ; 113 else return getId() ; 114 } 115 private: 116 std::string templateId_ ; //<! the id of the object that served as template 117 bool hasTemplateId_ = false; //<! true if templateId is set 118 95 119 protected : 96 120 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/object_template_impl.hpp
r1875 r2203 157 157 } 158 158 159 // --------------------------------------------------------------- 160 template <class T> 161 void CObjectTemplate<T>::setInheritedId(T* obj) 162 { 163 if (!hasInheritedId_) 164 { 165 if (!(hasId() && !hasAutoGeneratedId())) 166 if (obj->hasId() && !obj->hasAutoGeneratedId()) 167 { 168 hasInheritedId_=true ; 169 inheritedId_=obj->getId() ; 170 } 171 } 172 } 173 174 template <class T> 175 void CObjectTemplate<T>::setTemplateId(T* obj) 176 { 177 if (hasId() && !hasAutoGeneratedId()) 178 { 179 templateId_ = getId() ; 180 hasTemplateId_ = true ; 181 } 182 else if (obj->hasId() && !obj->hasAutoGeneratedId()) 183 { 184 templateId_ = obj->getId() ; 185 hasTemplateId_ = true ; 186 } 187 else if (obj->hasTemplateId()) 188 { 189 templateId_= obj->getTemplateId() ; 190 hasTemplateId_=true ; 191 } 192 } 193 194 159 195 //--------------------------------------------------------------- 160 196
Note: See TracChangeset
for help on using the changeset viewer.