package etomica.modules.materialfracture;

import etomica.action.BoxImposePbc;
import etomica.action.activity.ActivityIntegrate;
import etomica.api.IAtomTypeLeaf;
import etomica.api.IAtomTypeSphere;
import etomica.api.IBox;
import etomica.api.IVector;
import etomica.box.Box;
import etomica.chem.elements.ElementSimple;
import etomica.config.ConfigurationLattice;
import etomica.integrator.IntegratorMD;
import etomica.integrator.IntegratorVelocityVerlet;
import etomica.lattice.BravaisLatticeCrystal;
import etomica.lattice.crystal.BasisOrthorhombicHexagonal;
import etomica.lattice.crystal.PrimitiveGeneral;
import etomica.potential.P2LennardJones;
import etomica.potential.P2SoftSphericalTruncated;
import etomica.potential.PotentialMaster;
import etomica.simulation.Simulation;
import etomica.space.BoundaryRectangularSlit;
import etomica.space2d.Space2D;
import etomica.species.SpeciesSpheresMono;

public class MaterialFracture extends Simulation {

    public final Box box;
    public final ConfigurationLattice config;
    public final SpeciesSpheresMono species;
    public final IntegratorVelocityVerlet integrator;
    public final PotentialCalculationForceStress pc;
    public final P1Tension p1Tension;
    
    public MaterialFracture() {
        super(Space2D.getInstance());
        PotentialMaster potentialMaster = new PotentialMaster(space);
        box = new Box(this, space);
        box.setBoundary(new BoundaryRectangularSlit(this, 0, space));
        box.getBoundary().setDimensions(space.makeVector(new double[]{80,30}));
        addBox(box);
        integrator = new IntegratorVelocityVerlet(this, potentialMaster, space);
        integrator.setIsothermal(true);
        integrator.setTemperature(300.0);
        integrator.setTimeStep(0.007);
        integrator.setThermostatInterval(1);
        integrator.setThermostat(IntegratorMD.ThermostatType.ANDERSEN_SINGLE);
        integrator.setBox(box);
        pc = new PotentialCalculationForceStress();
        integrator.setForceSum(pc);
        getController().addAction(new ActivityIntegrate(integrator));
        P2LennardJones p2LJ = new P2LennardJones(space, 3, 2000);
        P2SoftSphericalTruncated pt = new P2SoftSphericalTruncated(space, p2LJ, 7.5);
        
        p1Tension = new P1Tension(space); 
        p1Tension.setSpringConstant(1);
        species = new SpeciesSpheresMono(this, space);
        ((ElementSimple)species.getLeafType().getElement()).setMass(40);
        ((IAtomTypeSphere)species.getLeafType()).setDiameter(3.0);
        getSpeciesManager().addSpecies(species);
        box.setNMolecules(species, 198);
        
        potentialMaster.addPotential(pt, new IAtomTypeLeaf[]{species.getLeafType(), species.getLeafType()});
        potentialMaster.addPotential(p1Tension, new IAtomTypeLeaf[]{species.getLeafType()});
        
        PrimitiveGeneral primitive = new PrimitiveGeneral(space, new IVector[]{space.makeVector(new double[]{Math.sqrt(3),0}), space.makeVector(new double[]{0,1})});
        config = new ConfigurationLattice(new BravaisLatticeCrystal(primitive, new BasisOrthorhombicHexagonal()), space) {
            public void initializeCoordinates(IBox box) {
                IVector d = box.getBoundary().getDimensions();
                d.setX(0, 60);
                box.getBoundary().setDimensions(d);
                super.initializeCoordinates(box);
                d.setX(0, 80);
                box.getBoundary().setDimensions(d);
            }
        };
        config.initializeCoordinates(box);

        integrator.addIntervalAction(new BoxImposePbc(box, space));
    }
}

@@ -1211,20 +1211,16 @@
 ension;%0A
-    
 %0A    pub
@@ -1528,17 +1528,17 @@
 ouble%5B%5D%7B
-8
+9
 0,30%7D));
@@ -1802,17 +1802,19 @@
 nterval(
-1
+400
 );%0A     
@@ -1882,14 +1882,15 @@
 SEN_
-SINGLE
+NODRIFT
 );%0A 
@@ -1969,16 +1969,21 @@
 eStress(
+space
 );%0A     
@@ -2235,24 +2235,16 @@
 , 7.5);%0A
-        
 %0A       
@@ -2283,48 +2283,8 @@
 ); %0A
-        p1Tension.setSpringConstant(1);%0A
     
@@ -2564,24 +2564,16 @@
 , 198);%0A
-        
 %0A       
@@ -2767,24 +2767,16 @@
 pe()%7D);%0A
-        
 %0A       
@@ -3108,17 +3108,18 @@
 es(IBox 
-b
+aB
 ox) %7B%0A  
@@ -3144,17 +3144,18 @@
 tor d = 
-b
+aB
 ox.getBo
@@ -3207,17 +3207,19 @@
 etX(0, 6
-0
+4.7
 );%0A     
@@ -3221,33 +3221,34 @@
                 
-b
+aB
 ox.getBoundary()
@@ -3306,25 +3306,26 @@
 Coordinates(
-b
+aB
 ox);%0A       
@@ -3343,17 +3343,17 @@
 setX(0, 
-8
+9
 0);%0A    
@@ -3356,33 +3356,34 @@
                 
-b
+aB
 ox.getBoundary()

use nodrift thermostat display a wider box, initialize config that's happy at T=300