<commit_before>package etomica.space;

import etomica.api.IVector;
import etomica.api.IVectorMutable;
import etomica.lattice.IndexIteratorRectangular;
import etomica.lattice.IndexIteratorSizable;
import etomica.math.geometry.Parallelepiped;
import etomica.math.geometry.Parallelogram;
import etomica.math.geometry.Parallelotope;
import etomica.math.geometry.Polytope;

/**
 * Boundary shaped as an arbitrary parallelepiped.  Applicable only for a 2D or 3D spaces.
 */

public class BoundaryDeformablePeriodic extends Boundary {

    /**
     * Make a cubic boundary with edges of length equal to the default boxSize and
     * periodic in every direction.
     */
	public BoundaryDeformablePeriodic(ISpace _space) {
		this(_space, 10.0);
	}

    /**
     * Make a cubic boundary of specified edge length and periodicity.
     */
	public BoundaryDeformablePeriodic(ISpace space, double boxSize) {
	    this(space, makeVectors(space, boxSize));
	}
	
    /**
     * Make a parallelepiped boundary of specified shape and periodicity.
     * 
     * @param space the governing space
     * @param vex array of vectors specifying directions for the parallelepiped edges
     * 
     *  @throws IllegalArgumentException if the dimension of space is not 2 or 3
     *  @throws IllegalArgumentException if the vex.length is not equal to the dimension of the space
     */
	public BoundaryDeformablePeriodic(ISpace space, IVector[] vex) {
        super(space, makeShape(space, vex));
        D = space.D();
        if(D != 2 && D != 3) {
            throw new IllegalArgumentException("BoundaryDeformablePeriodic is appropriate only for 2-D or 3-D spaces");
        }
        
        edgeVectors = new IVectorMutable[vex.length];
        for(int i=0; i<edgeVectors.length; i++) {
            edgeVectors[i] = space.makeVector();
            edgeVectors[i].E(vex[i]);
        }

        h = space.makeTensor();
        hCopy = space.makeTensor();
        hInv = space.makeTensor();

        temp1 = space.makeVector();
        temp2 = space.makeVector();
        unit = space.makeVector();
        unit.E(1.0);
        half = space.makeVector();
        half.E(0.5);
        indexIterator = new IndexIteratorRectangular(space.D());
        periodicity = new boolean[space.D()];
        for (int i=0; i<periodicity.length; i++) {
            periodicity[i] = true;
        }
        update();
    }
    
    //used by constructor
    private static IVectorMutable[] makeVectors(ISpace space, double boxSize) {
        IVectorMutable[] vectors = new IVectorMutable[space.D()];
        for(int i=0; i<vectors.length; i++) {
            vectors[i] = space.makeVector();
            vectors[i].setX(i, boxSize);
        }
        return vectors;
    }
	
    //used only by constructor
    private static Polytope makeShape(ISpace space, IVector[] vex) {
        switch(space.D()) {
            case 2: return new Parallelogram(space, vex[0], vex[1]);
            case 3: return new Parallelepiped(space, vex[0], vex[1], vex[2]);
            default: throw new IllegalArgumentException("BoundaryDeformablePeriodic not appropriate to given space");
        }
    }

    /**
     * Returns a vector with each element equal to the length of the corresponding
     * edge of the boundary.
     */
	public IVector getBoxSize() {
        IVector[] vertices = shape.getVertices();
        temp1.E(vertices[0]);
        temp2.E(vertices[0]);
        for(int i=1; i<vertices.length; i++) {
            for (int j=0; j<space.D(); j++) {
                temp1.setX(j,Math.min(vertices[i].getX(j),temp1.getX(j)));
                temp2.setX(j,Math.max(vertices[i].getX(j),temp2.getX(j)));
            }
        }
        temp2.ME(temp1);
        return temp2;
    }

    /**
     * Returns the boundary tensor that fully describes the shape of the boundary.  Each
     * column of the tensor is an edge vector of the boundary.  Manipulation of the
     * returned tensor does not affect the state of the boundary. Shape-changing methods
     * (e.g., deform()) must be used to affect the boundary shape.
     */
    public Tensor getBoundaryTensor() {
        hCopy.E(h);
        return hCopy;
    }<commit_msg>update comment.  getBoxSize returns the bounding box<commit_after>package etomica.space;

import etomica.api.IVector;
import etomica.api.IVectorMutable;
import etomica.lattice.IndexIteratorRectangular;
import etomica.lattice.IndexIteratorSizable;
import etomica.math.geometry.Parallelepiped;
import etomica.math.geometry.Parallelogram;
import etomica.math.geometry.Parallelotope;
import etomica.math.geometry.Polytope;

/**
 * Boundary shaped as an arbitrary parallelepiped.  Applicable only for a 2D or 3D spaces.
 */

public class BoundaryDeformablePeriodic extends Boundary {

    /**
     * Make a cubic boundary with edges of length equal to the default boxSize and
     * periodic in every direction.
     */
	public BoundaryDeformablePeriodic(ISpace _space) {
		this(_space, 10.0);
	}

    /**
     * Make a cubic boundary of specified edge length and periodicity.
     */
	public BoundaryDeformablePeriodic(ISpace space, double boxSize) {
	    this(space, makeVectors(space, boxSize));
	}
	
    /**
     * Make a parallelepiped boundary of specified shape and periodicity.
     * 
     * @param space the governing space
     * @param vex array of vectors specifying directions for the parallelepiped edges
     * 
     *  @throws IllegalArgumentException if the dimension of space is not 2 or 3
     *  @throws IllegalArgumentException if the vex.length is not equal to the dimension of the space
     */
	public BoundaryDeformablePeriodic(ISpace space, IVector[] vex) {
        super(space, makeShape(space, vex));
        D = space.D();
        if(D != 2 && D != 3) {
            throw new IllegalArgumentException("BoundaryDeformablePeriodic is appropriate only for 2-D or 3-D spaces");
        }
        
        edgeVectors = new IVectorMutable[vex.length];
        for(int i=0; i<edgeVectors.length; i++) {
            edgeVectors[i] = space.makeVector();
            edgeVectors[i].E(vex[i]);
        }

        h = space.makeTensor();
        hCopy = space.makeTensor();
        hInv = space.makeTensor();

        temp1 = space.makeVector();
        temp2 = space.makeVector();
        unit = space.makeVector();
        unit.E(1.0);
        half = space.makeVector();
        half.E(0.5);
        indexIterator = new IndexIteratorRectangular(space.D());
        periodicity = new boolean[space.D()];
        for (int i=0; i<periodicity.length; i++) {
            periodicity[i] = true;
        }
        update();
    }
    
    //used by constructor
    private static IVectorMutable[] makeVectors(ISpace space, double boxSize) {
        IVectorMutable[] vectors = new IVectorMutable[space.D()];
        for(int i=0; i<vectors.length; i++) {
            vectors[i] = space.makeVector();
            vectors[i].setX(i, boxSize);
        }
        return vectors;
    }
	
    //used only by constructor
    private static Polytope makeShape(ISpace space, IVector[] vex) {
        switch(space.D()) {
            case 2: return new Parallelogram(space, vex[0], vex[1]);
            case 3: return new Parallelepiped(space, vex[0], vex[1], vex[2]);
            default: throw new IllegalArgumentException("BoundaryDeformablePeriodic not appropriate to given space");
        }
    }

    /**
     * Returns the length of the sides of a rectangular box oriented in the lab
     * frame and in which the boundary is inscribed.
     */
	public IVector getBoxSize() {
        IVector[] vertices = shape.getVertices();
        temp1.E(vertices[0]);
        temp2.E(vertices[0]);
        for(int i=1; i<vertices.length; i++) {
            for (int j=0; j<space.D(); j++) {
                temp1.setX(j,Math.min(vertices[i].getX(j),temp1.getX(j)));
                temp2.setX(j,Math.max(vertices[i].getX(j),temp2.getX(j)));
            }
        }
        temp2.ME(temp1);
        return temp2;
    }

    /**
     * Returns the boundary tensor that fully describes the shape of the boundary.  Each
     * column of the tensor is an edge vector of the boundary.  Manipulation of the
     * returned tensor does not affect the state of the boundary. Shape-changing methods
     * (e.g., deform()) must be used to affect the boundary shape.
     */
    public Tensor getBoundaryTensor() {
        hCopy.E(h);
        return hCopy;
    }
{'fraction_non_alphanumeric': 0.10764300973178258, 'fraction_numerical': 0.009494422027059102, 'mean_word_length': 2.5407563025210083, 'pattern_counts': {'":': 0, '<': 13, '<?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': '5517323', 'n_tokens_mistral': 2612, 'n_tokens_neox': 2479, 'n_words': 707}