<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package etomica.potential;

import etomica.space.Space;
import etomica.units.dimensions.CompoundDimension;
import etomica.units.dimensions.Dimension;
import etomica.units.dimensions.Energy;
import etomica.units.dimensions.Length;

/**
 * Harmonic Well interatomic potential.
 * Spherically symmetric potential of the form u(r) = 0.5*springConstant*(r-r0)^2 
 * where springConstant describes the strength of the pair interaction.
 *
 * @author <NAME>
 * @author <NAME>
 */
public class P2Harmonic extends Potential2SoftSpherical {

    private double w = 100.0;// Spring constant gives a measure of the strength of harmonic interaction
	private final boolean r0Zero;
	private double r0;
    
    public P2Harmonic(Space space, double w) {
    	this(space, w, 0.0);
    }
    /**
     * 
     * @param space
     * @param w spring constant
     * @param r0  Separation at which potential is at its minimum.  Default is
     * zero.
     */
    public P2Harmonic(Space space, double w, double r0) {
        super(space);
        setSpringConstant(w);
        r0Zero = (r0 == 0.0);
        setR0(r0);
    }

    public double u(double r2) {
    	if(r0Zero) return 0.5*w*r2;
    	double dx = Math.sqrt(r2) - r0;
    	return 0.5*w*dx*dx;
    }

    /**
     * The derivative r*du/dr.
     */
    public double du(double r2) {
    	if(r0Zero) return w*r2;
    	double r = Math.sqrt(r2);
    	return w*r*(r-r0);
    }

   /**
    * The second derivative of the pair energy, times the square of the
    * separation:  r^2 d^2u/dr^2.
    */
    public double d2u(double r2) {
        return w*r2;
    }
            <commit_msg>implement u012add for P2Harmonic<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package etomica.potential;

import etomica.space.Space;
import etomica.units.dimensions.CompoundDimension;
import etomica.units.dimensions.Dimension;
import etomica.units.dimensions.Energy;
import etomica.units.dimensions.Length;

/**
 * Harmonic Well interatomic potential.
 * Spherically symmetric potential of the form u(r) = 0.5*springConstant*(r-r0)^2 
 * where springConstant describes the strength of the pair interaction.
 *
 * @author <NAME>
 * @author <NAME>
 */
public class P2Harmonic extends Potential2SoftSpherical {

    private double w = 100.0;// Spring constant gives a measure of the strength of harmonic interaction
	private final boolean r0Zero;
	private double r0;
    
    public P2Harmonic(Space space, double w) {
    	this(space, w, 0.0);
    }
    /**
     * 
     * @param space
     * @param w spring constant
     * @param r0  Separation at which potential is at its minimum.  Default is
     * zero.
     */
    public P2Harmonic(Space space, double w, double r0) {
        super(space);
        setSpringConstant(w);
        r0Zero = (r0 == 0.0);
        setR0(r0);
    }

    public void u012add(double r2, double[] u012) {
        if (r0Zero) {
            u012[0] = u012[1] = u012[2] = w*r2;
            u012[0] *= 0.5;
            return;
        }
        double r = Math.sqrt(r2);
        double dx = r - r0;
        u012[0] = 0.5*w*dx*dx;
        u012[1] = w*r*dx;
        u012[2] = w*r2;
    }

    public double u(double r2) {
    	if(r0Zero) return 0.5*w*r2;
    	double dx = Math.sqrt(r2) - r0;
    	return 0.5*w*dx*dx;
    }

    /**
     * The derivative r*du/dr.
     */
    public double du(double r2) {
    	if(r0Zero) return w*r2;
    	double r = Math.sqrt(r2);
    	return w*r*(r-r0);
    }

   /**
    * The second derivative of the pair energy, times the square of the
    * separation:  r^2 d^2u/dr^2.
    */
    public double d2u(double r2) {
        return w*r2;
    }
            
{'fraction_non_alphanumeric': 0.11224236404271169, 'fraction_numerical': 0.03575862925254532, 'mean_word_length': 2.439795046968403, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5215470', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1373, 'n_words': 407}