<commit_before>"""Collection of pre-built interaction kernels"""
import math
import numpy as np

from parcels.tools.statuscodes import OperationCode, StateCode
from parcels.interaction.spherical_utils import relative_3d_distance


__all__ = ['DummyMoveNeighbour']


def DummyMoveNeighbour(particle, fieldset, time, neighbours, mutator):
    """A particle boosts the movement of its nearest neighbour, by adding
    0.1 to its lat position.
    """
    distances = []
    neighbour_ids = []
    for n in neighbours:
        distances.append(
            relative_3d_distance(particle.lat, particle.lon, particle.depth,
                                 n.lat, n.lon, n.depth))
        neighbour_ids.append(n.id)

    if len(distances):
        i_min_dist = np.argmin(distances)

        def f(p):
            p.lat += 0.1
        mutator[neighbour_ids[i_min_dist]].append(f)

    return StateCode.Success


def AsymmetricAttraction(particle, fieldset, time, neighbours, mutator):
    distances = []
    na_neighbors = []
    if not particle.attractor:
        return StateCode.Success

    for n in neighbours:
        if n.attractor:
            continue
        distances.append(
            relative_3d_distance(particle.lat, particle.lon, particle.depth,
                                 n.lat, n.lon, n.depth))
        na_neighbors.append(n)

    assert fieldset.mesh == "flat"
    velocity_param = 0.01
    for n in na_neighbors:
        assert n.dt == particle.dt
        dx = np.array([particle.lat-n.lat, particle.long-n.long,
                       particle.depth-n.depth])
        dx_norm = np.linalg.norm(dx)
        velocity = velocity_param/(dx_norm**2)

        distance = velocity*n.dt
        d_vec = distance*dx/dx_norm

        def f(n):
            n.lat += d_vec[0]
            n.long += d_vec[1]
            n.depth += d_vec[2]

        mutator[n.id].append(f)

    return StateCode.Success
<commit_msg>Small Attraction kernel fixes<commit_after>"""Collection of pre-built interaction kernels"""
import math
import numpy as np

from parcels.tools.statuscodes import OperationCode, StateCode
from parcels.interaction.spherical_utils import relative_3d_distance


__all__ = ['DummyMoveNeighbour', 'AsymmetricAttraction']


def DummyMoveNeighbour(particle, fieldset, time, neighbours, mutator):
    """A particle boosts the movement of its nearest neighbour, by adding
    0.1 to its lat position.
    """
    distances = []
    neighbour_ids = []
    for n in neighbours:
        distances.append(
            relative_3d_distance(particle.lat, particle.lon, particle.depth,
                                 n.lat, n.lon, n.depth))
        neighbour_ids.append(n.id)

    if len(distances):
        i_min_dist = np.argmin(distances)

        def f(p):
            p.lat += 0.1
        mutator[neighbour_ids[i_min_dist]].append(f)

    return StateCode.Success


def AsymmetricAttraction(particle, fieldset, time, neighbours, mutator):
    distances = []
    na_neighbors = []
    if not particle.attractor:
        return StateCode.Success

    for n in neighbours:
        if n.attractor:
            continue
        distances.append(
            relative_3d_distance(particle.lat, particle.lon, particle.depth,
                                 n.lat, n.lon, n.depth))
        na_neighbors.append(n)

    assert fieldset.mesh == "flat"
    velocity_param = 0.01
    for n in na_neighbors:
        assert n.dt == particle.dt
        dx = np.array([particle.lat-n.lat, particle.lon-n.lon,
                       particle.depth-n.depth])
        dx_norm = np.linalg.norm(dx)
        velocity = velocity_param/(dx_norm**2)

        distance = velocity*n.dt
        d_vec = distance*dx/dx_norm

        def f(n):
            n.lat += d_vec[0]
            n.lon += d_vec[1]
            n.depth += d_vec[2]

        mutator[n.id].append(f)

    return StateCode.Success

{'fraction_non_alphanumeric': 0.1006953386556786, 'fraction_numerical': 0.0072109193922225085, 'mean_word_length': 2.2178956089478046, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4321303', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1186, 'n_words': 268}