Skip to content

Commit

Permalink
Fixes spikes when importing fractures in parallel (#3020)
Browse files Browse the repository at this point in the history
  • Loading branch information
TotoGaz authored Mar 15, 2024
1 parent 965ea17 commit bc0f67a
Show file tree
Hide file tree
Showing 6 changed files with 439 additions and 133 deletions.
48 changes: 43 additions & 5 deletions src/coreComponents/codingUtilities/Utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,31 @@ VAL findOption( mapBase< KEY, VAL, SORTED > const & map,
return iter->second;
}

namespace
{

/**
* @brief Apply functor @p transformer onto the map elements and store the results into a container of type @p C.
* @tparam MAP Type of the considered map.
* @tparam C Type of the container holding the keys.
* @tparam TRANSFORMER Type of the unary functor.
* @param[in] map The map from which keys will be extracted.
* @param transformer Which unary functor to apply to the @p map elements.
* @return The container with the results for the @p transformer application.
*/
template< template< typename ... > class C, typename MAP, typename TRANSFORMER >
auto mapTransformer( MAP const & map,
TRANSFORMER const & transformer )
{
using v = typename std::result_of< TRANSFORMER( typename MAP::const_reference ) >::type;
C< v > result;
auto inserter = std::inserter( result, result.end() );
std::transform( map.begin(), map.end(), inserter, transformer );
return result;
}

}

/**
* @brief Extract the keys from the given map.
* @tparam MAP Type of the considered map.
Expand All @@ -219,11 +244,24 @@ VAL findOption( mapBase< KEY, VAL, SORTED > const & map,
template< template< typename ... > class C = std::vector, typename MAP >
C< typename MAP::key_type > mapKeys( MAP const & map )
{
C< typename MAP::key_type > keys;
auto transformer = []( auto const & p ) { return p.first; };
auto inserter = std::inserter( keys, keys.end() );
std::transform( map.begin(), map.end(), inserter, transformer );
return keys;
auto transformer = []( auto const & p ) -> typename MAP::key_type
{ return p.first; };
return mapTransformer< C >( map, transformer );
}

/**
* @brief Extract the values from the given map.
* @tparam MAP Type of the considered map.
* @tparam C Type of the container holding the values.
* @param[in] map The map from which values will be extracted.
* @return The container with the values.
*/
template< template< typename ... > class C = std::vector, typename MAP >
C< typename MAP::mapped_type > mapValues( MAP const & map )
{
auto transformer = []( typename MAP::const_reference p ) -> typename MAP::mapped_type
{ return p.second; };
return mapTransformer< C >( map, transformer );
}

namespace internal
Expand Down
3 changes: 2 additions & 1 deletion src/coreComponents/codingUtilities/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
set( testSources
testGeosxTraits.cpp
testStringUtilities.cpp
testParsing.cpp )
testParsing.cpp
testUtilities.cpp )

set( dependencyList gtest codingUtilities ${parallelDeps} )

Expand Down
35 changes: 35 additions & 0 deletions src/coreComponents/codingUtilities/tests/testUtilities.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* ------------------------------------------------------------------------------------------------------------
* SPDX-License-Identifier: LGPL-2.1-only
*
* Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
* Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
* Copyright (c) 2018-2020 TotalEnergies
* Copyright (c) 2019- GEOSX Contributors
* All rights reserved
*
* See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
* ------------------------------------------------------------------------------------------------------------
*/

#include "codingUtilities/Utilities.hpp"

#include <gtest/gtest.h>

#include <map>

using namespace geos;

TEST( Utilities, MapExtraction )
{
std::map< string, int > const m{
{ "k0", 0 },
{ "k1", 1 },
{ "k2", 2 }
};

EXPECT_EQ( mapKeys( m ), std::vector< string >( { "k0", "k1", "k2" } ) );
EXPECT_EQ( mapKeys< std::set >( m ), std::set< string >( { "k0", "k1", "k2" } ) );
EXPECT_EQ( mapValues( m ), std::vector< int >( { 0, 1, 2 } ) );
EXPECT_EQ( mapValues< std::set >( m ), std::set< int >( { 0, 1, 2 } ) );
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static std::vector< int > getVtkConnectivity( ElementType const elementType, loc
case ElementType::Vertex: return { 0 };
case ElementType::Line: return { 0, 1 };
case ElementType::Triangle: return { 0, 1, 2 };
case ElementType::Quadrilateral: return { 0, 1, 3, 2 };
case ElementType::Quadrilateral: return { 0, 1, 2, 3 };
case ElementType::Polygon: return { }; // TODO
case ElementType::Tetrahedron: return { 0, 1, 2, 3 };
case ElementType::Pyramid: return { 0, 1, 3, 2, 4 };
Expand Down
Loading

0 comments on commit bc0f67a

Please sign in to comment.