org.miv.pherd
Class Particle

java.lang.Object
  extended by org.miv.pherd.Particle

public abstract class Particle
extends Object

Base class for particles.

This class is the basis used to build particles classes. It has a unique identifier, a position as a point in space, a weight as a scalar, and references a cell that contains it.

This class is abstract, the only method that must be implemented is the move(int) method. This method must store in the nextPos field the position of the particle at the next time step. The current time step is given as argument.

Since:
2007
Author:
Antoine Dutot

Field Summary
protected  HashMap<String,Object> attributes
          The particle attributes.
protected  ParticleBox box
          The particle box containing this particle.
protected  Cell cell
          Cell containing this particle.
protected  Object id
          Particle identifier.
protected  boolean moved
          Flag used to avoid doing work on a particle that did not moved.
protected  Point3 nextPos
          The computed next particle position.
protected  Point3 pos
          Particle position.
protected  double weight
          The particle importance.
 
Constructor Summary
Particle(Object id)
          Particle at (0,0,0).
Particle(Object id, double x, double y, double z)
          New particle at (x,y,z).
 
Method Summary
 boolean closeTo(Particle other)
          Like closeTo(Particle, double) with a delta of 0.001f.
 boolean closeTo(Particle other, double delta)
          Is the given particle close to this one.
 Object getAttribute(String attribute)
          The value associated with one of the particle attributes.
 Iterator<String> getAttributeKeyIterator()
          Iterator on the set of attribute keys.
 Cell getCell()
          The cell actually responsible for this particle.
 Object getId()
          The particle unique identifier.
 Point3 getPosition()
          Particle position.
 double getWeight()
          Particle importance, or weight or mass.
protected  void initPos(double x, double y, double z)
          Can be used in the constructor to initialise a first position.
abstract  void inserted()
          The particle was just inserted in a particle box.
abstract  void move(int time)
          Should compute the next position from the current position.
 void nextStep(int time)
          Copy the next computed position from the current position.
 void removeAttribute(String attribute)
           
abstract  void removed()
          The particle is about to be removed from the particle box.
 void setAttribute(String attribute, Object... values)
           
protected  void setBox(ParticleBox box)
          Called by the particle box when this particle is inserted in it.
 void setCell(Cell responsible)
          Cell of the n-tree that handles this particle.
 void setWeight(double newWeight)
          The importance (weight, mass, etc.) of the particle.
 void suicide()
          Make this particle disappear from its particle box.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

protected Object id
Particle identifier.


pos

protected Point3 pos
Particle position.


nextPos

protected Point3 nextPos
The computed next particle position.


weight

protected double weight
The particle importance.


cell

protected Cell cell
Cell containing this particle.


box

protected ParticleBox box
The particle box containing this particle.


attributes

protected HashMap<String,Object> attributes
The particle attributes.


moved

protected boolean moved
Flag used to avoid doing work on a particle that did not moved. This flag is set to false in nextStep(int), and should be set to true in move(int) in order to effectively move the particle.

Constructor Detail

Particle

public Particle(Object id,
                double x,
                double y,
                double z)
New particle at (x,y,z).

Parameters:
id - Particle identifier.
x - Abscissa position.
y - Ordinate position.
z - Depth position.

Particle

public Particle(Object id)
Particle at (0,0,0).

Parameters:
id - Particle identifier.
Method Detail

initPos

protected void initPos(double x,
                       double y,
                       double z)
Can be used in the constructor to initialise a first position. Use it only in the constructor !! It is provided for the case you do not have the position when constructing a sub class of Particle and calling "super()".

Parameters:
x - Abscissa position.
y - Ordinate position.
z - Depth position.

getId

public Object getId()
The particle unique identifier.

Returns:
An identifier object.

getPosition

public Point3 getPosition()
Particle position.

Returns:
The three particle coordinates.

getCell

public Cell getCell()
The cell actually responsible for this particle.

Returns:
The particle cell.

closeTo

public boolean closeTo(Particle other)
Like closeTo(Particle, double) with a delta of 0.001f.

Parameters:
other - The other particle to test.
Returns:
True if both particles are close to each other.

closeTo

public boolean closeTo(Particle other,
                       double delta)
Is the given particle close to this one.

Parameters:
other - The other particle to test.
delta - The distance threshold (included) to consider the other particle is close to this one.
Returns:
True if both particles are close to each other.

getWeight

public double getWeight()
Particle importance, or weight or mass.

Returns:
The particle weight or mass.

getAttribute

public Object getAttribute(String attribute)
The value associated with one of the particle attributes.

Parameters:
attribute - The attribute.
Returns:
The attribute value or null if not found (or the attribute value is null).

getAttributeKeyIterator

public Iterator<String> getAttributeKeyIterator()
Iterator on the set of attribute keys. Null if there are no attributes.

Returns:
An iterator on strings.

setCell

public void setCell(Cell responsible)
Cell of the n-tree that handles this particle.

Parameters:
responsible - The cell that is now responsible for this particle.

setWeight

public void setWeight(double newWeight)
The importance (weight, mass, etc.) of the particle.

Parameters:
newWeight - The new value.

setAttribute

public void setAttribute(String attribute,
                         Object... values)

removeAttribute

public void removeAttribute(String attribute)

move

public abstract void move(int time)
Should compute the next position from the current position. Be careful, the flag moved must be set to "true" if this method did something and to false to avoid processing this particle any further if nothing has been done. This allows to avoid unwanted computation for particles that do not move.

Parameters:
time - The current iteration.

inserted

public abstract void inserted()
The particle was just inserted in a particle box.


removed

public abstract void removed()
The particle is about to be removed from the particle box.


nextStep

public void nextStep(int time)
Copy the next computed position from the current position.

Parameters:
time - The current iteration.

setBox

protected void setBox(ParticleBox box)
Called by the particle box when this particle is inserted in it.

Parameters:
box - The particle box that now contains this particle.

suicide

public void suicide()
Make this particle disappear from its particle box.



Copyright © 2011. All Rights Reserved.