<commit_before>/****************************************************************************
 * Copyright (c) 2012-2018 by the DataTransferKit authors                   *
 * All rights reserved.                                                     *
 *                                                                          *
 * This file is part of the DataTransferKit library. DataTransferKit is     *
 * distributed under a BSD 3-clause license. For the licensing terms see    *
 * the LICENSE file in the top-level directory.                             *
 *                                                                          *
 * SPDX-License-Identifier: BSD-3-Clause                                    *
 ****************************************************************************/
/*!
 * \file
 * \brief C adapter to DTK Maps.
 */
#ifndef DTK_C_API_MAP_HPP
#define DTK_C_API_MAP_HPP

#include <DTK_C_API.h>
#include <DTK_C_API.hpp>
#include <DTK_MovingLeastSquaresOperator.hpp>
#include <DTK_NearestNeighborOperator.hpp>
#include <DTK_ParallelTraits.hpp>
#include <DTK_PointCloudOperator.hpp>
#include <DTK_UserApplication.hpp>

#include <Teuchos_DefaultMpiComm.hpp>

#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>

#include <mpi.h>

#include <memory>
#include <string>
#include <tuple>

namespace DataTransferKit
{
//---------------------------------------------------------------------------//
// Map interface base class. This allows us to hide the device template
// parameter in MapImpl when we do the casting in the C interface
// implementation. We won't know what device type we have in a template when
// calling the C interface and we don't need to - the apply function
// implementation details will dispatch to the correct device type based on
// the construction.
struct DTK_Map
{
    virtual ~DTK_Map() = default;

    virtual void apply( const std::string &source_field_name,
                        const std::string &target_field_name ) = 0;
};

//---------------------------------------------------------------------------//
template <class MapExecSpace, class SourceMemSpace, class TargetMemSpace>
struct DTK_MapImpl : public DTK_Map
{
    using map_device_type = typename MapExecSpace::device_type;

    DTK_MapImpl( MPI_Comm comm, DTK_UserApplicationHandle source,
                 DTK_UserApplicationHandle target,
                 boost::property_tree::ptree const &ptree )
        : _source( reinterpret_cast<DTK_Registry *>( source )->_registry )
        , _target( reinterpret_cast<DTK_Registry *>( target )->_registry )
    {
        // Create a Teuchos comm from the MPI comm.
        auto teuchos_comm = Teuchos::rcp( new Teuchos::MpiComm<int>( comm ) );

        // FOR NOW JUST CREATE A NEAREST NEIGHBOR OPERATOR FOR DEMONSTRATION
        // PURPOSES. THIS WILL BE REPLACED BY A PROPER FACTORY.

        // Get coordinates from the source and target.
        auto source_nodes = _source.getNodeList().coordinates;
        auto target_nodes = _target.getNodeList().coordinates;

        // For now things are layout left in the interface so copy to a
        // matching layout that is compatible with the operator.
        Kokkos::View<Coordinate **, map_device_type> source_nodes_copy(
            "src_nodes_copy", source_nodes.extent( 0 ),
            source_nodes.extent( 1 ) );
        Kokkos::deep_copy( source_nodes_copy, source_nodes );
        Kokkos::View<Coordinate **, map_device_type> target_nodes_copy(
            "tgt_nodes_copy", target_nodes.extent( 0 ),
            target_nodes.extent( 1 ) );
        Kokkos::deep_copy( target_nodes_copy, target_nodes );

        // Create a nearest neighbor operator.
        _map = std::unique_ptr<NearestNeighborOperator<map_device_type>>(
            new NearestNeighborOperator<map_device_type>(
                teuchos_comm, source_nodes_copy, target_nodes_copy ) );
    }
<commit_msg>Get map type to create from the property tree<commit_after>/****************************************************************************
 * Copyright (c) 2012-2018 by the DataTransferKit authors                   *
 * All rights reserved.                                                     *
 *                                                                          *
 * This file is part of the DataTransferKit library. DataTransferKit is     *
 * distributed under a BSD 3-clause license. For the licensing terms see    *
 * the LICENSE file in the top-level directory.                             *
 *                                                                          *
 * SPDX-License-Identifier: BSD-3-Clause                                    *
 ****************************************************************************/
/*!
 * \file
 * \brief C adapter to DTK Maps.
 */
#ifndef DTK_C_API_MAP_HPP
#define DTK_C_API_MAP_HPP

#include <DTK_C_API.h>
#include <DTK_C_API.hpp>
#include <DTK_MovingLeastSquaresOperator.hpp>
#include <DTK_NearestNeighborOperator.hpp>
#include <DTK_ParallelTraits.hpp>
#include <DTK_PointCloudOperator.hpp>
#include <DTK_UserApplication.hpp>

#include <Teuchos_DefaultMpiComm.hpp>

#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>

#include <mpi.h>

#include <memory>
#include <string>
#include <tuple>

namespace DataTransferKit
{
//---------------------------------------------------------------------------//
// Map interface base class. This allows us to hide the device template
// parameter in MapImpl when we do the casting in the C interface
// implementation. We won't know what device type we have in a template when
// calling the C interface and we don't need to - the apply function
// implementation details will dispatch to the correct device type based on
// the construction.
struct DTK_Map
{
    virtual ~DTK_Map() = default;

    virtual void apply( const std::string &source_field_name,
                        const std::string &target_field_name ) = 0;
};

//---------------------------------------------------------------------------//
template <class MapExecSpace, class SourceMemSpace, class TargetMemSpace>
struct DTK_MapImpl : public DTK_Map
{
    using map_device_type = typename MapExecSpace::device_type;

    DTK_MapImpl( MPI_Comm comm, DTK_UserApplicationHandle source,
                 DTK_UserApplicationHandle target,
                 boost::property_tree::ptree const &ptree )
        : _source( reinterpret_cast<DTK_Registry *>( source )->_registry )
        , _target( reinterpret_cast<DTK_Registry *>( target )->_registry )
    {
        // Create a Teuchos comm from the MPI comm.
        auto teuchos_comm = Teuchos::rcp( new Teuchos::MpiComm<int>( comm ) );

        // FOR NOW JUST CREATE A NEAREST NEIGHBOR OPERATOR FOR DEMONSTRATION
        // PURPOSES. THIS WILL BE REPLACED BY A PROPER FACTORY.

        // Get coordinates from the source and target.
        auto source_nodes = _source.getNodeList().coordinates;
        auto target_nodes = _target.getNodeList().coordinates;

        // For now things are layout left in the interface so copy to a
        // matching layout that is compatible with the operator.
        Kokkos::View<Coordinate **, map_device_type> source_nodes_copy(
            "src_nodes_copy", source_nodes.extent( 0 ),
            source_nodes.extent( 1 ) );
        Kokkos::deep_copy( source_nodes_copy, source_nodes );
        Kokkos::View<Coordinate **, map_device_type> target_nodes_copy(
            "tgt_nodes_copy", target_nodes.extent( 0 ),
            target_nodes.extent( 1 ) );
        Kokkos::deep_copy( target_nodes_copy, target_nodes );

        auto const which_map = ptree.get<std::string>( "Map Type" );
        if ( which_map == "Nearest Neighbor" || which_map == "NN" )
            _map = std::unique_ptr<NearestNeighborOperator<map_device_type>>(
                new NearestNeighborOperator<map_device_type>(
                    teuchos_comm, source_nodes_copy, target_nodes_copy ) );
    }

{'fraction_non_alphanumeric': 0.15403850962740684, 'fraction_numerical': 0.0037509377344336083, 'mean_word_length': 2.2569218241042344, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7474890', 'n_tokens_mistral': 2166, 'n_tokens_neox': 2080, 'n_words': 601}