diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index da912bd9..f2cc1937 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -37,6 +37,7 @@ Changelog](http://keepachangelog.com/en/1.0.0/). - Added a lot more 2D and 3D computational geometry unit tests covering more face/edge configurations - Support for linear triangle meshes in Tribol's SINGLE_MORTAR method (exact Jacobians through Enzyme or approximate Jacobians) +- Added API function to get the number of active contact pairs on a coupling scheme. ### Changed - Return negative timestep vote for non-null meshes with null velocity pointers. diff --git a/src/tribol/interface/tribol.cpp b/src/tribol/interface/tribol.cpp index 236ab8cb..ce5d5fc3 100644 --- a/src/tribol/interface/tribol.cpp +++ b/src/tribol/interface/tribol.cpp @@ -826,6 +826,27 @@ void setInterfacePairs( IndexT cs_id, IndexT numPairs, IndexT const* const pairI } // end setInterfacePairs() +//------------------------------------------------------------------------------ +int getNumberOfContactPairsOnRank( IndexT cs_id ) +{ + auto cs = CouplingSchemeManager::getInstance().findData( cs_id ); + return cs->getNumActivePairs(); +} + +//------------------------------------------------------------------------------ +int getTotalNumberOfContactPairs( IndexT cs_id ) +{ + auto cs = CouplingSchemeManager::getInstance().findData( cs_id ); + if ( cs != nullptr ) { + auto comm = cs->getProblemComm(); + int local_num_pairs = cs->getNumActivePairs(); + int global_num_pairs = 0; + MPI_Allreduce( &local_num_pairs, &global_num_pairs, 1, MPI_INT, MPI_SUM, comm ); + return global_num_pairs; + } + return 0; +} + //------------------------------------------------------------------------------ int update( int cycle, RealT t, RealT& dt ) { diff --git a/src/tribol/interface/tribol.hpp b/src/tribol/interface/tribol.hpp index 14f0d766..7a291371 100644 --- a/src/tribol/interface/tribol.hpp +++ b/src/tribol/interface/tribol.hpp @@ -493,6 +493,26 @@ void setInterfacePairs( IndexT cs_id, IndexT numPairs, IndexT const* mesh_id1, I IndexT const* pairIndex1, IndexT const* mesh_id2, IndexT const* pairType2, IndexT const* pairIndex2 ); +/*! + * \brief Get the number of contact pairs on rank for the given coupling scheme + * + * \param [in] cs_id coupling scheme id + * + * \return the number of contact pairs on rank + */ +int getNumberOfContactPairsOnRank( IndexT cs_id ); + +/*! + * \brief Get the total number of contact pairs across all ranks for the given coupling scheme + * + * \param [in] cs_id coupling scheme id + * + * \return the total number of contact pairs across all rank + * + * \note this routine only works on host + */ +int getTotalNumberOfContactPairs( IndexT cs_id ); + /*! * \brief Computes the contact response at the given cycle. *