<commit_before>package etomica.modules.pistoncylinder;

import etomica.data.DataSourceScalar;
import etomica.data.meter.Meter;
import etomica.phase.Phase;
import etomica.potential.P1HardMovingBoundary;
import etomica.space.Vector;
import etomica.units.DimensionRatio;
import etomica.units.Quantity;
import etomica.units.Volume;

/**
 * Specialized density meter for piston/cylinder system
 */
public class MeterPistonDensity extends DataSourceScalar implements Meter {
    public MeterPistonDensity(P1HardMovingBoundary potential, int wallDim, double atomDiameter) {
        super("Density",new DimensionRatio(Quantity.DIMENSION, Volume.DIMENSION));
        pistonPotential = potential;
        wallD = wallDim;
        collisionDiameter = atomDiameter;
    }

    public void setAtomDiameter(double d) {
        collisionDiameter = d;
    }
    
    public double getDataAsScalar() {
        double volume = 1;
        final Vector dimensions = phase.getBoundary().getDimensions();
        for (int i=0; i<dimensions.D(); i++) {
            double d = dimensions.x(i) - collisionDiameter;
            if (i==wallD) {
                d -= pistonPotential.getWallPosition();
            }
            volume *= d;
        }
        return phase.moleculeCount()/volume;
    }
    
    /**<commit_msg>Fixed dimensions based on origin at center of simulation boundary.<commit_after>package etomica.modules.pistoncylinder;

import etomica.data.DataSourceScalar;
import etomica.data.meter.Meter;
import etomica.phase.Phase;
import etomica.potential.P1HardMovingBoundary;
import etomica.space.Vector;
import etomica.units.DimensionRatio;
import etomica.units.Quantity;
import etomica.units.Volume;

/**
 * Specialized density meter for piston/cylinder system
 */
public class MeterPistonDensity extends DataSourceScalar implements Meter {
    public MeterPistonDensity(P1HardMovingBoundary potential, int wallDim, double atomDiameter) {
        super("Density",new DimensionRatio(Quantity.DIMENSION, Volume.DIMENSION));
        pistonPotential = potential;
        wallD = wallDim;
        collisionDiameter = atomDiameter;
    }

    public void setAtomDiameter(double d) {
        collisionDiameter = d;
    }
    
    public double getDataAsScalar() {
        double volume = 1;
        final Vector dimensions = phase.getBoundary().getDimensions();
        for (int i=0; i<dimensions.D(); i++) {
            double d = dimensions.x(i)*0.5 - collisionDiameter;
            if (i==wallD) {
                d -= pistonPotential.getWallPosition();
            }
            volume *= d;
        }
        return phase.moleculeCount()/volume;
    }
    
    /**
{'fraction_non_alphanumeric': 0.09460987561251413, 'fraction_numerical': 0.003769317753486619, 'mean_word_length': 3.009063444108761, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4045800', 'n_tokens_mistral': 813, 'n_tokens_neox': 778, 'n_words': 169}