Xyst test code coverage report
Current view: top level - Transfer - Transfer.cpp (source / functions) Coverage Total Hit
Commit: 1fb74642dd9d7732b67f32dec2f2762e238d3fa7 Lines: 9.2 % 65 6
Test Date: 2025-08-13 22:46:33 Functions: 10.0 % 10 1
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 7.8 % 90 7

             Branch data     Line data    Source code
       1                 :             : // *****************************************************************************
       2                 :             : /*!
       3                 :             :   \file      src/Transfer/Transfer.cpp
       4                 :             :   \copyright 2020-2021 Charmworks, Inc.,
       5                 :             :              2022-2025 J. Bakosi
       6                 :             :              All rights reserved. See the LICENSE file for details.
       7                 :             :   \brief     Definitions pertaining to transfer between 3D meshes
       8                 :             : */
       9                 :             : // *****************************************************************************
      10                 :             : 
      11                 :             : #include <cassert>
      12                 :             : #include <iostream>     // NOT NEEDED
      13                 :             : 
      14                 :             : #include "Transfer.hpp"
      15                 :             : #include "NodeSearch.hpp"
      16                 :             : #include "ContainerUtil.hpp"
      17                 :             : 
      18                 :             : namespace transfer {
      19                 :             : 
      20                 :             : #if defined(__clang__)
      21                 :             :   #pragma clang diagnostic push
      22                 :             :   #pragma clang diagnostic ignored "-Wmissing-variable-declarations"
      23                 :             : #endif
      24                 :             : 
      25                 :             : CProxy_Transfer g_transferProxy;
      26                 :             : CollideHandle g_collideHandle;
      27                 :             : 
      28                 :             : #if defined(__clang__)
      29                 :             :   #pragma clang diagnostic pop
      30                 :             : #endif
      31                 :             : 
      32                 :             : static void
      33                 :           0 : collisionHandler( [[maybe_unused]] void *param, int nColl, Collision *colls )
      34                 :             : // *****************************************************************************
      35                 :             : //! ...
      36                 :             : // *****************************************************************************
      37                 :             : {
      38                 :           0 :   g_transferProxy.ckLocalBranch()->distributeCollisions( nColl, colls );
      39                 :           0 : }
      40                 :             : 
      41                 :         259 : LibTransfer::LibTransfer( CkArgMsg* msg )
      42                 :             : // *****************************************************************************
      43                 :             : //  Constructor: initialize mesh-to-mesh transfer
      44                 :             : // *****************************************************************************
      45                 :             : {
      46 [ +  - ][ +  - ]:         259 :   delete msg;
      47                 :             : 
      48 [ +  - ][ +  - ]:         259 :   g_transferProxy = CProxy_Transfer::ckNew();
      49                 :             : 
      50                 :             :   // Need to make sure this is actually correct
      51         [ +  - ]:         259 :   CollideGrid3d gridMap( CkVector3d(0, 0, 0), CkVector3d(2, 100, 2) );
      52 [ +  - ][ +  - ]:         259 :   g_collideHandle = CollideCreate( gridMap,
      53                 :             :                       CollideSerialClient( collisionHandler, nullptr ) );
      54                 :         259 : }
      55                 :             : 
      56                 :             : void
      57                 :           0 : addMesh( CkArrayID p, int nchare, CkCallback cb )
      58                 :             : // *****************************************************************************
      59                 :             : //  API for registering a mesh to be part of mesh-to-mesh transfer
      60                 :             : //! \param[in] p Charm++ host proxy participating in mesh-to-mesh transfer
      61                 :             : //! \param[in] nchare Number of mesh partitions
      62                 :             : //! \param[in] cb Callback to continue with once finished
      63                 :             : // *****************************************************************************
      64                 :             : {
      65 [ -  - ][ -  - ]:           0 :   g_transferProxy[0].addMesh( p, nchare, cb );
      66                 :           0 : }
      67                 :             : 
      68                 :             : void
      69                 :           0 : setSourceTets( CkArrayID p,
      70                 :             :                int chare,
      71                 :             :                const std::vector< std::size_t >& inpoel,
      72                 :             :                const std::array< std::vector< double >, 3 >& coord,
      73                 :             :                const tk::Fields& u,
      74                 :             :                const std::vector< double >& flag,
      75                 :             :                bool dir,
      76                 :             :                CkCallback cb )
      77                 :             : // *****************************************************************************
      78                 :             : //  API for configuring source mesh
      79                 :             : //! \param[in] inpoel Source mesh connectivity
      80                 :             : //! \param[in] coord Source mesh node coordinates
      81                 :             : //! \param[in] u Source solution data
      82                 :             : //! \param[in] flag Transfer flags
      83                 :             : //! \param[in] dir Transfer direction: 0: bg to overset, 1: overset to bg
      84                 :             : //! \param[in] cb Callback to continue with once finished
      85                 :             : // *****************************************************************************
      86                 :             : {
      87                 :             :   g_transferProxy.ckLocalBranch()->
      88         [ -  - ]:           0 :     setSourceTets( p, chare, inpoel, coord, u, flag, dir, cb );
      89                 :           0 : }
      90                 :             : 
      91                 :             : 
      92                 :           0 : void setDestPoints( CkArrayID p,
      93                 :             :                     int chare,
      94                 :             :                     const std::array< std::vector< double >, 3 >& coord,
      95                 :             :                     tk::Fields& u,
      96                 :             :                     std::vector< double >& flag,
      97                 :             :                     bool trflag,
      98                 :             :                     bool dir,
      99                 :             :                     CkCallback cb )
     100                 :             : // *****************************************************************************
     101                 :             : //  API for configuring destination mesh
     102                 :             : //! \param[in] coord Destination mesh node coordinates
     103                 :             : //! \param[in,out] u Destination mesh solution data
     104                 :             : //! \param[in,out] flag Transfer flags
     105                 :             : //! \param[in] trflag Transfer flags if true
     106                 :             : //! \param[in] dir Transfer direction: 0: bg to overset, 1: overset to bg
     107                 :             : //! \param[in] cb Callback to continue with once finished
     108                 :             : // *****************************************************************************
     109                 :             : {
     110                 :             :   g_transferProxy.ckLocalBranch()->
     111         [ -  - ]:           0 :     setDestPoints( p, chare, coord, u, flag, trflag, dir, cb );
     112                 :           0 : }
     113                 :             : 
     114                 :             : void
     115                 :           0 : Transfer::addMesh( CkArrayID p, int nchare, CkCallback cb )
     116                 :             : // *****************************************************************************
     117                 :             : //  Register a mesh to be part of mesh-to-mesh transfer
     118                 :             : //! \param[in] p Charm++ host proxy participating in mesh-to-mesh transfer
     119                 :             : //! \param[in] nchare Number of mesh partitions
     120                 :             : //! \param[in] cb Callback to continue with once finished
     121                 :             : // *****************************************************************************
     122                 :             : {
     123                 :           0 :   auto id = static_cast<std::size_t>(CkGroupID(p).idx);
     124                 :             : //std::cout << "addMesh: " << nchare << ", id:" << id << '\n';
     125 [ -  - ][ -  - ]:           0 :   assert( m_proxyMap.count(id) == 0 );
     126         [ -  - ]:           0 :   CkArrayOptions opts;
     127         [ -  - ]:           0 :   opts.bindTo( p );
     128         [ -  - ]:           0 :   opts.setNumInitial( nchare );
     129                 :           0 :   MeshData mesh;
     130                 :           0 :   mesh.nchare = nchare;
     131                 :           0 :   mesh.firstchunk = m_current_chunk;
     132 [ -  - ][ -  - ]:           0 :   mesh.proxy = CProxy_NodeSearch::ckNew( p, mesh, cb, opts );
     133 [ -  - ][ -  - ]:           0 :   m_proxyMap[ id ] = mesh;
     134                 :           0 :   m_current_chunk += nchare;
     135                 :           0 : }
     136                 :             : 
     137                 :             : void
     138                 :           0 : Transfer::setMesh( CkArrayID p, const MeshData& mesh )
     139                 :             : // *****************************************************************************
     140                 :             : //! \param[in] p Charm++ host proxy participating in mesh-to-mesh transfer
     141                 :             : // *****************************************************************************
     142                 :             : {
     143 [ -  - ][ -  - ]:           0 :   m_proxyMap[static_cast<std::size_t>(CkGroupID(p).idx)] = mesh;
     144                 :             : //std::cout << "setMesh: pe:" << CkMyPe() << ": "; for (const auto& [i,m] : m_proxyMap) std::cout << " groupid:" << i << " firstchunk:" << m.firstchunk << " nchare:" << m.nchare << ' '; std::cout << '\n';
     145                 :           0 : }
     146                 :             : 
     147                 :             : void
     148                 :           0 : Transfer::setSourceTets( CkArrayID p,
     149                 :             :                          int chare,
     150                 :             :                          const std::vector< std::size_t >& inpoel,
     151                 :             :                          const std::array< std::vector< double >, 3 >& coord,
     152                 :             :                          const tk::Fields& u,
     153                 :             :                          const std::vector< double >& flag,
     154                 :             :                          bool dir,
     155                 :             :                          CkCallback cb )
     156                 :             : // *****************************************************************************
     157                 :             : //  Configure source mesh
     158                 :             : //! \param[in] inpoel Source mesh connectivity
     159                 :             : //! \param[in] coord Source mesh node coordinates
     160                 :             : //! \param[in] u Source solution data
     161                 :             : //! \param[in] flag Transfer flags
     162                 :             : //! \param[in] dir Transfer direction: 0: bg to overset, 1: overset to bg
     163                 :             : //! \param[in] cb Callback to continue with once finished
     164                 :             : // *****************************************************************************
     165                 :             : {
     166                 :           0 :   m_src = static_cast< std::size_t >( CkGroupID(p).idx );
     167         [ -  - ]:           0 :   assert( m_proxyMap.count(m_src) );
     168 [ -  - ][ -  - ]:           0 :   NodeSearch* w = tk::cref_find( m_proxyMap, m_src ).proxy[ chare ].ckLocal();
                 [ -  - ]
     169         [ -  - ]:           0 :   assert( w );
     170         [ -  - ]:           0 :   w->setSourceTets( inpoel, coord, u, flag, dir, cb );
     171                 :           0 : }
     172                 :             : 
     173                 :             : void
     174                 :           0 : Transfer::setDestPoints( CkArrayID p,
     175                 :             :                          int chare,
     176                 :             :                          const std::array< std::vector< double >, 3 >& coord,
     177                 :             :                          tk::Fields& u,
     178                 :             :                          std::vector< double >& flag,
     179                 :             :                          bool trflag,
     180                 :             :                          bool dir,
     181                 :             :                          CkCallback cb )
     182                 :             : // *****************************************************************************
     183                 :             : //  Configure destination mesh
     184                 :             : //! \param[in] coord Pointer to the coordinate data for the destination mesh
     185                 :             : //! \param[in,out] u Pointer to the solution data for the destination mesh
     186                 :             : //! \param[in,out] flag Transfer flags
     187                 :             : //! \param[in] trflag Transfer flags if true
     188                 :             : //! \param[in] dir Transfer direction: 0: bg to overset, 1: overset to bg
     189                 :             : //! \param[in] cb Callback to continue with once finished
     190                 :             : // *****************************************************************************
     191                 :             : {
     192                 :           0 :   m_dst = static_cast< std::size_t >( CkGroupID(p).idx );
     193         [ -  - ]:           0 :   assert( m_proxyMap.count(m_dst) );
     194 [ -  - ][ -  - ]:           0 :   NodeSearch* w = tk::cref_find( m_proxyMap, m_dst ).proxy[ chare ].ckLocal();
                 [ -  - ]
     195         [ -  - ]:           0 :   assert( w );
     196         [ -  - ]:           0 :   w->setDestPoints( coord, u, flag, trflag, dir, cb );
     197                 :           0 : }
     198                 :             : 
     199                 :             : void
     200                 :           0 : Transfer::distributeCollisions( int nColl, Collision* colls )
     201                 :             : // *****************************************************************************
     202                 :             : //  Called when all potential collisions have been found, and now need to be
     203                 :             : //  distributed to the chares in the destination mesh to determine actual
     204                 :             : //  collisions.
     205                 :             : //! \param[in] nColl Number of potential collisions found
     206                 :             : //! \param[in] colls The list of potential collisions
     207                 :             : // *****************************************************************************
     208                 :             : {
     209                 :             :   //CkPrintf("Collisions found: %i\n", nColl);
     210         [ -  - ]:           0 :   const auto& dst = tk::cref_find( m_proxyMap, m_dst );
     211                 :           0 :   auto first = static_cast< std::size_t >( dst.firstchunk );
     212                 :           0 :   auto nchare = static_cast< std::size_t >( dst.nchare );
     213         [ -  - ]:           0 :   std::vector< std::vector< Collision > > separated( nchare );
     214                 :             : 
     215                 :             :   // Separate collisions based on the destination mesh chare they belong to
     216         [ -  - ]:           0 :   for (std::size_t i=0; i<static_cast<std::size_t>(nColl); ++i) {
     217                 :           0 :     auto achunk = static_cast< std::size_t >( colls[i].A.chunk );
     218                 :           0 :     auto bchunk = static_cast< std::size_t >( colls[i].B.chunk );
     219 [ -  - ][ -  - ]:           0 :     if (achunk >= first && achunk < first + nchare) {
     220         [ -  - ]:           0 :       separated[ achunk - first ].push_back(colls[i]);
     221                 :             :     } else {
     222         [ -  - ]:           0 :       separated[ bchunk - first ].push_back(colls[i]);
     223                 :             :     }
     224                 :             :   }
     225                 :             : 
     226                 :             :   // Send out each list to the destination chares for further processing
     227         [ -  - ]:           0 :   for (std::size_t i=0; i<nchare; ++i) {
     228                 :             :     //CkPrintf("Dest mesh chunk %i has %lu\n", i, separated[i].size());
     229         [ -  - ]:           0 :     const auto& src = tk::cref_find( m_proxyMap, m_src );
     230 [ -  - ][ -  - ]:           0 :     dst.proxy[ static_cast<int>(i) ].processCollisions( src,
     231                 :           0 :       static_cast< int >( separated[ i ].size() ),
     232                 :           0 :       separated[ i ].data() );
     233                 :             :   }
     234                 :           0 : }
     235                 :             : 
     236                 :             : } // transfer::
     237                 :             : 
     238                 :             : #include "NoWarning/transfer.def.h"
        

Generated by: LCOV version 2.0-1