/* 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.spin.heisenberg;

import etomica.api.IAtomList;
import etomica.api.IVector;
import etomica.api.IVectorMutable;
import etomica.potential.Potential1;
import etomica.potential.PotentialSoft;
import etomica.space.ISpace;
import etomica.space.Tensor;


/**
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 *
 * @author David Kofke
 *
 */
public class P1MagneticField extends Potential1 implements PotentialSoft {

    /**
     * @param space
     */
    public P1MagneticField(ISpace space, double dipoleMagnitude) {
        super(space);
        direction = space.makeVector();
        direction.E(0.0);
        direction.setX(0,1.0);//This one set the direction of atoms, should  I change it????
        
        //TODO
        this.dipoleMagnitude = dipoleMagnitude;
        dr = space.makeVector();
        dr.E(0);
        gradient = new IVectorMutable[1];
        gradient[0] = space.makeVector();
        //TODO
    }

    /* (non-Javadoc)
     * @see etomica.Potential#energy(etomica.AtomSet)
     */
    public double energy(IAtomList atoms) {
        IVectorMutable r = atoms.getAtom(0).getPosition();
        return dipoleMagnitude*h*r.dot(direction);//TODO Add mu here
    }
    
    
    /**
     * @return Returns the direction.
     */
    public IVectorMutable getDirection() {
        return direction;
    }
    /**
     * @param direction The direction to set.
     */
    public void setDirection(IVectorMutable direction) {
        this.direction.E(direction);
        this.direction.normalize();
    }
    /**
     * @return Returns the h.
     */
    public double getH() {
        return h;
    }
    /**
     * @param h The h to set.
     */
    public void setH(double h) {//I didn't set up the electric fields
        this.h = h;
    }

    private static final long serialVersionUID = 1L;
    private double h;
    private final IVectorMutable direction;
    
    //TODO shoudl I add final
    private double dipoleMagnitude;
    private IVectorMutable dr;
    private IVectorMutable [] gradient;
    //TODO
	@Override
	public double virial(IAtomList atoms) {
		
		return 0;
	}

	@Override
	public IVector[] gradient(IAtomList atoms) {//TODO I thought I only need to return one vector not an array??
		gradient[0].Ea1Tv1(-dipoleMagnitude*h, direction);
		return gradient;
	}

	@Override
	public IVector[] gradient(IAtomList atoms, Tensor pressureTensor) {
		return gradient(atoms);
	}
}

@@ -473,135 +473,254 @@
 *%0A *
- TODO To change the template for this g
+%0A *this class is to introduced electric field to the 2D Heis
 en
+b
 er
-ated type comment go to%0A * Window - Preferences - Java - Code Style - Code Templates
+g Model.%0A * Right now the electric filed is set to be zero since we are only interested%0A * in the secondDerivative of free energy w.r.t electric filed when electric field%0A * is zero
 %0A *%0A
@@ -741,16 +741,30 @@
 id Kofke
+ & Weisong Lin
 %0A *%0A */%0A
@@ -866,16 +866,32 @@
 am space
+,dipoleMagnitude
 %0A     */
@@ -1080,94 +1080,17 @@
 .0);
-//This one set the direction of atoms, should  I change it????%0A        %0A        //TODO
+%0A        
 %0A   
@@ -1276,100 +1276,95 @@
     
+%7D%0A%0A
     /
-/TODO
+**
 %0A    
-%7D%0A
+ *
 %0A    
-/* (non-Javadoc)%0A     * @see etomica.Potential#energy(etomica.AtomSet)
+ * @param atoms%0A     * @return energy of dipole in electric field
 %0A   
@@ -1525,26 +1525,8 @@
 on);
-//TODO Add mu here
 %0A   
@@ -2233,38 +2233,8 @@
    %0A
-    //TODO shoudl I add final%0A
     
@@ -2340,29 +2340,97 @@
 nt;%0A
+%0A
     /
-/TODO%0A%09@Override
+**%0A     *%0A     * @param atoms%0A     * @return 0 since no virial is used here%0A     */
 %0A%09pu
@@ -2471,11 +2471,8 @@
 ) %7B%0A
-%09%09%0A
 %09%09re
@@ -2487,128 +2487,127 @@
 %09%7D%0A%0A
-%09@Override%0A%09public IVector%5B%5D gradient(IAtomList atoms) %7B//TODO I thought I only need to return one vector not an array??
+    /**%0A     *%0A     * @param atoms%0A     * @return gradient vector%0A     */%0A%09public IVector%5B%5D gradient(IAtomList atoms) %7B
 %0A%09%09g

add comment: intro of what this class computes remove TODO