<commit_before>/**
 * << detailed description >>
 *
 * @file PotentialsOrder2.cpp
 * @brief << brief description >>
 * @author clonker
 * @date 09.06.16
 */

#include <readdy/kernel/singlecpu/potentials/PotentialsOrder2.h>
#include <readdy/kernel/singlecpu/SingleCPUKernel.h>

namespace readdy {
    namespace kernel {
        namespace singlecpu {
            namespace potentials {

                double HarmonicRepulsion::calculateEnergy(const vec_t &x_ij) const {
                    auto distanceSquared = x_ij * x_ij;
                    if (distanceSquared < getSumOfParticleRadiiSquared()) {
                        distanceSquared = std::sqrt(distanceSquared);
                        distanceSquared -= getSumOfParticleRadii();
                        distanceSquared *= distanceSquared;
                        return distanceSquared * getForceConstant();
                    } else {
                        return 0;
                    }
                }

                void HarmonicRepulsion::calculateForce(vec_t &force, const vec_t &x_ij) const {
                    auto squared = x_ij * x_ij;
                    if (squared < getSumOfParticleRadiiSquared() && squared > 0) {
                        squared = std::sqrt(squared);
                        force = (2 * getForceConstant() * (squared - getSumOfParticleRadii())) / squared * x_ij;
                    } else {
                        force = {0,0,0};
                    }
                }

                void HarmonicRepulsion::calculateForceAndEnergy(vec_t &force, double &energy, const vec_t &x_ij) const {
                    auto squared = x_ij * x_ij;
                    if (squared < getSumOfParticleRadiiSquared() && squared > 0) {
                        squared = std::sqrt(squared);
                        energy += getForceConstant() * std::pow(squared - getSumOfParticleRadii(), 2);
                        force = (2 * getForceConstant() * (squared - getSumOfParticleRadii())) / squared * x_ij;
                    } else {
                        force = {0,0,0};
                    }
                }

                HarmonicRepulsion::HarmonicRepulsion(const readdy::model::Kernel *const kernel) : readdy::model::potentials::HarmonicRepulsion(kernel) { }

                potentials::HarmonicRepulsion *HarmonicRepulsion::replicate() const {
                    return new HarmonicRepulsion(*this);
                }

                double HarmonicRepulsion::getCutoffRadius() const {
                    return sumOfParticleRadii;
                }
                
<commit_msg>[singlecpu/potentials] changed prefactor of harmonic repulsion. In this way the force constant corresponds to the one of a standard harmonic oscillator (E=0.5*k*x^2)<commit_after>/**
 * SingleCPU implementations of potentials of second order (particle-particle interactions).
 * This is where actual forces and energies are calculated. Second order potentials are
 * currently: harmonic repulsion and piece-wise harmonic interaction (similar to
 * Lennard-Jones).
 *
 * @file PotentialsOrder2.cpp
 * @brief Calculate forces and energies of second-order potentials.
 * @author clonker
 * @date 09.06.16
 */

#include <readdy/kernel/singlecpu/potentials/PotentialsOrder2.h>
#include <readdy/kernel/singlecpu/SingleCPUKernel.h>

namespace readdy {
    namespace kernel {
        namespace singlecpu {
            namespace potentials {

                double HarmonicRepulsion::calculateEnergy(const vec_t &x_ij) const {
                    auto distanceSquared = x_ij * x_ij;
                    if (distanceSquared < getSumOfParticleRadiiSquared()) {
                        distanceSquared = std::sqrt(distanceSquared);
                        distanceSquared -= getSumOfParticleRadii();
                        distanceSquared *= distanceSquared;
                        return 0.5 * distanceSquared * getForceConstant();
                    } else {
                        return 0;
                    }
                }

                void HarmonicRepulsion::calculateForce(vec_t &force, const vec_t &x_ij) const {
                    auto squared = x_ij * x_ij;
                    if (squared < getSumOfParticleRadiiSquared() && squared > 0) {
                        squared = std::sqrt(squared);
                        force = (getForceConstant() * (squared - getSumOfParticleRadii())) / squared * x_ij;
                    } else {
                        force = {0,0,0};
                    }
                }

                void HarmonicRepulsion::calculateForceAndEnergy(vec_t &force, double &energy, const vec_t &x_ij) const {
                    auto squared = x_ij * x_ij;
                    if (squared < getSumOfParticleRadiiSquared() && squared > 0) {
                        squared = std::sqrt(squared);
                        energy += 0.5 * getForceConstant() * std::pow(squared - getSumOfParticleRadii(), 2);
                        force = (getForceConstant() * (squared - getSumOfParticleRadii())) / squared * x_ij;
                    } else {
                        force = {0,0,0};
                    }
                }

                HarmonicRepulsion::HarmonicRepulsion(const readdy::model::Kernel *const kernel) : readdy::model::potentials::HarmonicRepulsion(kernel) { }

                potentials::HarmonicRepulsion *HarmonicRepulsion::replicate() const {
                    return new HarmonicRepulsion(*this);
                }

                double HarmonicRepulsion::getCutoffRadius() const {
                    return sumOfParticleRadii;
                }
                

{'fraction_non_alphanumeric': 0.09052107415970123, 'fraction_numerical': 0.008002845456162191, 'mean_word_length': 1.65533522190746, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, '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': '4038899', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1363, 'n_words': 310}