From e2bc92ed3b7defaa80a4bc89251dd4523eee42cc Mon Sep 17 00:00:00 2001 From: Steven Robert Wopschall Date: Wed, 1 Oct 2025 10:57:30 -0700 Subject: [PATCH 1/5] Added interface calls to get number of pairs on rank and total --- src/tribol/interface/tribol.cpp | 21 +++++++++++++++++++++ src/tribol/interface/tribol.hpp | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/tribol/interface/tribol.cpp b/src/tribol/interface/tribol.cpp index 12c00ce7..7f237b67 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 ) +{ +// note this routine is only for host calls +#ifdef TRIBOL_USE_HOST + auto cs = CouplingSchemeManager::getInstance().findData( cs_id ); + 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; +#endif +} + //------------------------------------------------------------------------------ int update( int cycle, RealT t, RealT& dt ) { diff --git a/src/tribol/interface/tribol.hpp b/src/tribol/interface/tribol.hpp index 14f0d766..a7fb07c9 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. * From e2eab39f68af9930f6ee96c99bc4dda963c3b9e2 Mon Sep 17 00:00:00 2001 From: Steven Robert Wopschall Date: Wed, 1 Oct 2025 17:21:38 -0700 Subject: [PATCH 2/5] guarded return of number of contact pairs with null couplingscheme guard --- src/tribol/interface/tribol.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/tribol/interface/tribol.cpp b/src/tribol/interface/tribol.cpp index 7f237b67..618ffe1a 100644 --- a/src/tribol/interface/tribol.cpp +++ b/src/tribol/interface/tribol.cpp @@ -839,12 +839,15 @@ int getTotalNumberOfContactPairs( IndexT cs_id ) // note this routine is only for host calls #ifdef TRIBOL_USE_HOST auto cs = CouplingSchemeManager::getInstance().findData( cs_id ); - 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; + 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; + } #endif + return 0; } //------------------------------------------------------------------------------ From f54b04927d90dd33adc8a5811cc6b420591d4880 Mon Sep 17 00:00:00 2001 From: Steven Robert Wopschall Date: Thu, 2 Oct 2025 09:31:22 -0700 Subject: [PATCH 3/5] style --- src/tribol/interface/tribol.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tribol/interface/tribol.hpp b/src/tribol/interface/tribol.hpp index a7fb07c9..7a291371 100644 --- a/src/tribol/interface/tribol.hpp +++ b/src/tribol/interface/tribol.hpp @@ -498,7 +498,7 @@ void setInterfacePairs( IndexT cs_id, IndexT numPairs, IndexT const* mesh_id1, I * * \param [in] cs_id coupling scheme id * - * \return the number of contact pairs on rank + * \return the number of contact pairs on rank */ int getNumberOfContactPairsOnRank( IndexT cs_id ); From 7ee9c6915627b5c2ed5806b00bbd054a894c2f16 Mon Sep 17 00:00:00 2001 From: Steven Robert Wopschall Date: Thu, 2 Oct 2025 10:01:58 -0700 Subject: [PATCH 4/5] removed host guard on new routine. --- src/tribol/interface/tribol.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/tribol/interface/tribol.cpp b/src/tribol/interface/tribol.cpp index 618ffe1a..5483d8a4 100644 --- a/src/tribol/interface/tribol.cpp +++ b/src/tribol/interface/tribol.cpp @@ -836,8 +836,6 @@ int getNumberOfContactPairsOnRank( IndexT cs_id ) //------------------------------------------------------------------------------ int getTotalNumberOfContactPairs( IndexT cs_id ) { -// note this routine is only for host calls -#ifdef TRIBOL_USE_HOST auto cs = CouplingSchemeManager::getInstance().findData( cs_id ); if ( cs != nullptr ) { auto comm = cs->getProblemComm(); @@ -846,7 +844,6 @@ int getTotalNumberOfContactPairs( IndexT cs_id ) MPI_Allreduce( &local_num_pairs, &global_num_pairs, 1, MPI_INT, MPI_SUM, comm ); return global_num_pairs; } -#endif return 0; } From 1b30ce15cfe95bd2c92da4fdd9f7d8a9a978154b Mon Sep 17 00:00:00 2001 From: Steven Robert Wopschall Date: Fri, 3 Oct 2025 09:17:32 -0700 Subject: [PATCH 5/5] release notes --- RELEASE-NOTES.md | 1 + 1 file changed, 1 insertion(+) 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.