<commit_before>// Copyright (c) 2009-2021 The Regents of the University of Michigan
// This file is part of the HOOMD-blue project, released under the BSD 3-Clause License.

// Maintainer: jglaser

/*! \file SnapshotSystemData.cc
    \brief Implements SnapshotSystemData related functions
 */

#include "SnapshotSystemData.h"
#include <pybind11/pybind11.h>
namespace py = pybind11;

template<class Real>
void SnapshotSystemData<Real>::replicate(unsigned int nx, unsigned int ny, unsigned int nz)
    {
    assert(nx > 0);
    assert(ny > 0);
    assert(nz > 0);

    // Update global box
    BoxDim old_box = global_box;
    Scalar3 L = global_box.getL();
    L.x *= (Scalar)nx;
    L.y *= (Scalar)ny;
    L.z *= (Scalar)nz;
    global_box.setL(L);

    unsigned int old_n = particle_data.size;
    unsigned int n = nx * ny * nz;

    // replicate snapshots
    particle_data.replicate(nx, ny, nz, old_box, global_box);
    bond_data.replicate(n, old_n);
    angle_data.replicate(n, old_n);
    dihedral_data.replicate(n, old_n);
    improper_data.replicate(n, old_n);
    constraint_data.replicate(n, old_n);
    pair_data.replicate(n, old_n);
    }

template<class Real> void SnapshotSystemData<Real>::wrap()
    {
    vec3<double> frac;
    vec3<double> wrapped;
    vec3<double> pos;
    vec3<double> fin;
    int3 img;

    for (unsigned int i = 0; i < particle_data.size; i++)
        {
        pos = particle_data.pos[i];
        frac = global_box.makeFraction(particle_data.pos[i]);
        auto modulus_positive = [](auto x){ return std::fmod(std::fmod(x, Real(1.0)) + Real(1.0), Real(1.0)); };
        wrapped = vec3<Real>(
            modulus_positive(frac.x),
            modulus_positive(frac.y),
            modulus_positive(frac.z)
            );
        particle_data.pos[i] = global_box.makeCoordinates(wrapped);
        img.x = static_cast<int>(frac.x);
        img.y = static_cast<int>(frac.y);
        img.z = static_cast<int>(frac.z);
        particle_data.image[i] = img;
        // TODO: test image update

        std::cout << "Particle " << '[' << pos.x << ", " << pos.y << ", " << pos.z << "] --> ";
        std::cout << "[" << fin.x << ", " << fin.y << ", " << fin.z << "]\n";
        std::cout << "Fraction [" << frac.x << ", " << frac.y << ", " << frac.z << "]\n";
        std::cout << "Image [" << img.x << ", " << img.y << ", " << img.z << "]\n";
        std::cout << "Fraction wrapped is [" << wrapped.x << ", " << wrapped.y << ", " << wrapped.z << "]\n\n";

        }
    }

template<class Real>
void SnapshotSystemData<Real>::broadcast_box(std::shared_ptr<MPIConfiguration> mpi_conf)
    {
#ifdef ENABLE_MPI
    if (mpi_conf->getNRanks() > 1)
        {
        bcast(global_box, 0, mpi_conf->getCommunicator());
        bcast(dimensions, 0, mpi_conf->getCommunicator());
        }
#endif<commit_msg>remove print debugging<commit_after>// Copyright (c) 2009-2021 The Regents of the University of Michigan
// This file is part of the HOOMD-blue project, released under the BSD 3-Clause License.

// Maintainer: jglaser

/*! \file SnapshotSystemData.cc
    \brief Implements SnapshotSystemData related functions
 */

#include "SnapshotSystemData.h"
#include <pybind11/pybind11.h>
namespace py = pybind11;

template<class Real>
void SnapshotSystemData<Real>::replicate(unsigned int nx, unsigned int ny, unsigned int nz)
    {
    assert(nx > 0);
    assert(ny > 0);
    assert(nz > 0);

    // Update global box
    BoxDim old_box = global_box;
    Scalar3 L = global_box.getL();
    L.x *= (Scalar)nx;
    L.y *= (Scalar)ny;
    L.z *= (Scalar)nz;
    global_box.setL(L);

    unsigned int old_n = particle_data.size;
    unsigned int n = nx * ny * nz;

    // replicate snapshots
    particle_data.replicate(nx, ny, nz, old_box, global_box);
    bond_data.replicate(n, old_n);
    angle_data.replicate(n, old_n);
    dihedral_data.replicate(n, old_n);
    improper_data.replicate(n, old_n);
    constraint_data.replicate(n, old_n);
    pair_data.replicate(n, old_n);
    }

template<class Real> void SnapshotSystemData<Real>::wrap()
    {
    vec3<double> frac;
    vec3<double> wrapped;
    vec3<double> pos;
    int3 img;

    for (unsigned int i = 0; i < particle_data.size; i++)
        {
        pos = particle_data.pos[i];
        frac = global_box.makeFraction(particle_data.pos[i]);
        auto modulus_positive = [](auto x){ return std::fmod(std::fmod(x, Real(1.0)) + Real(1.0), Real(1.0)); };
        wrapped = vec3<Real>(
            modulus_positive(frac.x),
            modulus_positive(frac.y),
            modulus_positive(frac.z)
            );
        particle_data.pos[i] = global_box.makeCoordinates(wrapped);
        img.x = static_cast<int>(frac.x);
        img.y = static_cast<int>(frac.y);
        img.z = static_cast<int>(frac.z);
        particle_data.image[i] = img;
        // TODO: test image update
        }
    }

template<class Real>
void SnapshotSystemData<Real>::broadcast_box(std::shared_ptr<MPIConfiguration> mpi_conf)
    {
#ifdef ENABLE_MPI
    if (mpi_conf->getNRanks() > 1)
        {
        bcast(global_box, 0, mpi_conf->getCommunicator());
        bcast(dimensions, 0, mpi_conf->getCommunicator());
        }
#endif
{'fraction_non_alphanumeric': 0.15314968214216915, 'fraction_numerical': 0.013292236563282605, 'mean_word_length': 2.851632047477745, 'pattern_counts': {'":': 0, '<': 108, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '330495', 'n_tokens_mistral': 1879, 'n_tokens_neox': 1811, 'n_words': 379}