Ignore:
Timestamp:
01/22/21 18:46:08 (10 months ago)
Author:
ymipsl
Message:

Reimplement coupling in the new infrastructure.
Tested for 2-way coupling toy model.

YM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.cpp

    r2016 r2022  
    12071207    gridPtr->sendCreateChild(this->getId(),client); 
    12081208    this->sendAllAttributesToServer(client); 
    1209     distributeGridToFileServer(client) ; 
    1210   } 
    1211  
    1212  
    1213   void CGrid::distributeGridToFileServer(CContextClient* client) 
     1209    distributeGridToServer(client) ; 
     1210  } 
     1211 
     1212 
     1213  void CGrid::sendGridToCouplerOut(CContextClient* client, const string& fieldId) 
     1214  { 
     1215    if (sendGridToCouplerOut_done_.count(client)!=0) return ; 
     1216    else sendGridToCouplerOut_done_.insert(client) ; 
     1217    this->sendAllAttributesToServer(client, getCouplingAlias(fieldId)); 
     1218    distributeGridToServer(client,fieldId) ; 
     1219  } 
     1220 
     1221 
     1222  void CGrid::distributeGridToServer(CContextClient* client, const string& fieldId) 
    12141223  { 
    12151224    CContext* context = CContext::getCurrent(); 
     1225    bool isCoupling = !fieldId.empty() ; 
    12161226    // simple Distribution for now  
    12171227    // distribute over the fisrt element except if it is a scalar 
     
    12611271      if (elements[i].type==TYPE_DOMAIN)  
    12621272      {  
    1263          CDomain* domain = (CDomain*) elements[i].ptr ; 
    1264          sendAddDomain(domain->getId(),client) ; 
    1265          domain->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i), scattererConnector) ; 
    1266          scattererConnectors.push_back(scattererConnector) ; 
     1273        CDomain* domain = (CDomain*) elements[i].ptr ; 
     1274        if (isCoupling) domain->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i), scattererConnector,  domain->getCouplingAlias(fieldId,i)) ; 
     1275        else  
     1276        { 
     1277          sendAddDomain(domain->getId(),client) ; 
     1278          domain->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i), scattererConnector) ; 
     1279        } 
     1280        scattererConnectors.push_back(scattererConnector) ; 
    12671281      } 
    12681282      else if (elements[i].type==TYPE_AXIS) 
    12691283      { 
    12701284        CAxis* axis = (CAxis*) elements[i].ptr ; 
    1271         sendAddAxis(axis->getId(),client) ; 
    1272         axis->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i), scattererConnector) ; 
     1285        if (isCoupling) axis->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i), scattererConnector,  axis->getCouplingAlias(fieldId,i)) ; 
     1286        else  
     1287        { 
     1288          sendAddAxis(axis->getId(),client) ; 
     1289          axis->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i), scattererConnector) ; 
     1290        } 
    12731291        scattererConnectors.push_back(scattererConnector) ; 
    12741292      } 
     
    12761294      { 
    12771295        CScalar* scalar = (CScalar*) elements[i].ptr ; 
    1278         sendAddScalar(scalar->getId(),client) ; 
    1279         scalar->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i), scattererConnector) ; 
     1296        if (isCoupling) scalar->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i), scattererConnector,  scalar->getCouplingAlias(fieldId,i)) ; 
     1297        else  
     1298        { 
     1299          sendAddScalar(scalar->getId(),client) ; 
     1300          scalar->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i), scattererConnector) ; 
     1301        } 
    12801302        scattererConnectors.push_back(scattererConnector) ; 
    12811303      } 
     
    12911313    CEventClient event(getType(), EVENT_ID_SEND_MASK); 
    12921314    CMessage message ; 
    1293     message<<getId() ;  
     1315    if (isCoupling) message<<getCouplingAlias(fieldId) ; 
     1316    else message<<getId() ;  
    12941317    gridScattererConnector.transfer(maskOut, client, event, message) ; 
    12951318    for(auto& it : scattererConnectors) delete it ; 
     
    13211344    clientFromServerConnector_[client] = new CGridGathererConnector(clientFromServerConnectors) ; 
    13221345 
    1323  
    1324   } 
     1346  } 
     1347 
    13251348 
    13261349  void CGrid::recvMask(CEventServer& event) 
     
    13731396  } 
    13741397 
    1375  
    1376   void CGrid::sendGridToCouplerOut(CContextClient* client, const string& fieldId) 
    1377   { 
    1378 /*    if (sendGridToCouplerOut_done_.count(client)!=0) return ; 
    1379     else sendGridToCouplerOut_done_.insert(client) ; 
    1380   
    1381     CContext* context = CContext::getCurrent(); 
    1382     // simple Distribution for now  
    1383     // distribute over the fisrt element except if it is a scalar 
     1398  string CGrid::getCouplingAlias(const string& fieldId) 
     1399  { 
     1400    return "_grid_of_"+fieldId; 
     1401  } 
     1402 
     1403  void CGrid::makeAliasForCoupling(const string& fieldId) 
     1404  { 
     1405    string gridId=getCouplingAlias(fieldId) ; 
     1406    createAlias(gridId) ; 
     1407 
    13841408    auto& elements = getElements() ; 
    1385     int posDistributed = 0 ; 
    1386     for(auto& element : elements) 
    1387     { 
    1388       if (element.type==TYPE_DOMAIN) break ; 
    1389       else if (element.type==TYPE_AXIS) break ; 
    1390       else if (element.type==TYPE_SCALAR) posDistributed++ ; 
    1391     } 
    1392      
    1393     vector<CLocalView*> localViews ; 
    1394     vector<CDistributedView*> remoteViews ; 
    1395  
    13961409    for(int i=0 ; i<elements.size() ; i++) 
    13971410    { 
    1398       if (elements[i].type==TYPE_DOMAIN)  
    1399       {  
    1400          CDomain* domain = (CDomain*) elements[i].ptr ; 
    1401          domain->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; 
    1402          remoteViews.push_back(domain->getRemoteElement(client)->getView(CElementView::FULL)) ; 
    1403          localViews.push_back(domain->getLocalView(CElementView::FULL)) ; 
    1404       } 
    1405       else if (elements[i].type==TYPE_AXIS) 
    1406       { 
    1407         CAxis* axis = (CAxis*) elements[i].ptr ; 
    1408         axis->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; 
    1409         remoteViews.push_back(axis->getRemoteElement(client)->getView(CElementView::FULL)) ; 
    1410         localViews.push_back(axis->getLocalView(CElementView::FULL)) ; 
    1411       } 
    1412       else if (elements[i].type==TYPE_SCALAR) 
    1413       { 
    1414         CScalar* scalar = (CScalar*) elements[i].ptr ; 
    1415         scalar->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; 
    1416         remoteViews.push_back(scalar->getRemoteElement(client)->getView(CElementView::FULL)) ; 
    1417         localViews.push_back(scalar->getLocalView(CElementView::FULL)) ; 
    1418       } 
    1419     } 
    1420     CGridRemoteConnector gridRemoteConnector(localViews, remoteViews, context->getIntraComm(), client->getRemoteSize()) ; 
    1421     gridRemoteConnector.computeConnector() ; 
    1422      
    1423     vector<CScattererConnector*> clientToClientConnectors ; 
    1424     for(int i=0 ; i<elements.size() ; i++) 
    1425     { 
    1426       if (elements[i].type==TYPE_DOMAIN)  
    1427       {  
    1428          CDomain* domain = (CDomain*) elements[i].ptr ; 
    1429          sendAddDomain(domain->getId(),client) ; 
    1430          domain->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; 
    1431          clientToClientConnectors.push_back(domain->getClientToServerConnector(client)) ; 
    1432       } 
    1433       else if (elements[i].type==TYPE_AXIS) 
    1434       { 
    1435         CAxis* axis = (CAxis*) elements[i].ptr ; 
    1436         sendAddAxis(axis->getId(),client) ; 
    1437         axis->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; 
    1438         clientToClientConnectors.push_back(axis->getClientToServerConnector(client)) ; 
    1439       } 
    1440       else if (elements[i].type==TYPE_SCALAR) 
    1441       { 
    1442         CScalar* scalar = (CScalar*) elements[i].ptr ; 
    1443         sendAddScalar(scalar->getId(),client) ; 
    1444         scalar->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; 
    1445         clientToClientConnectors.push_back(scalar->getClientToServerConnector(client)) ; 
    1446       } 
    1447     } 
    1448      
    1449     // compute the grid clientToServerConnector to send flux from client to servers 
    1450     clientToClientConnector_[client] = new CGridScattererConnector(clientToClientConnectors) ;*/ 
    1451   } 
    1452  
    1453   void CGrid::makeAliasForCoupling(const string& fieldId) 
    1454   { 
    1455     string gridId="_grid_of_"+fieldId ; 
    1456     createAlias(gridId) ; 
    1457      
    1458     const auto& domVect = getDomains() ; 
    1459     for (int pos=0; pos<domVect.size();pos++) domVect[pos]->makeAliasForCoupling(fieldId, pos); 
    1460  
    1461     const auto& axisVect=getAxis() ; 
    1462     for (int pos=0; pos<axisVect.size();pos++) axisVect[pos]->makeAliasForCoupling(fieldId, pos); 
    1463  
    1464     const auto& scalVect=getScalars() ; 
    1465     for (int pos=0; pos<scalVect.size();pos++) scalVect[pos]->makeAliasForCoupling(fieldId, pos); 
     1411      if (elements[i].type==TYPE_DOMAIN) elements[i].domain->makeAliasForCoupling(fieldId, i); 
     1412      else if (elements[i].type==TYPE_AXIS) elements[i].axis->makeAliasForCoupling(fieldId, i); 
     1413      else if (elements[i].type==TYPE_SCALAR) elements[i].scalar->makeAliasForCoupling(fieldId, i); 
     1414    } 
    14661415  } 
    14671416 
Note: See TracChangeset for help on using the changeset viewer.