gov.nist.microanalysis.EPQLibrary
Class Composition

java.lang.Object
  extended by gov.nist.microanalysis.EPQLibrary.Composition
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable
Direct Known Subclasses:
Material

public class Composition
extends java.lang.Object
implements java.lang.Comparable, java.lang.Cloneable, java.io.Serializable

Composition - A class implementing a mechanism for describing the elemental composition of a material.

See Also:
Serialized Form

Field Summary
protected  int mHashCode
           
static int STOICIOMETRY
           
static int UNDETERMINED
           
static int WEIGHT_PCT
           
 
Constructor Summary
Composition()
          Material - Constructs a Material that is equivalent to a pure vacuum.
Composition(Element[] elms, double[] weightFracs)
          Constructs a Composition with the specified elements in the specified weight fractions.
Composition(Element[] elms, double[] weightFracs, java.lang.String name)
          Constructs a Composition with the specified weight fractions.
 
Method Summary
 void addElement(Element elm, double wgtFrac)
          addElement - Add a specified weight fraction of the specified element to the Material.
 void addElement(int atomicNo, double wgtFrac)
          addElement - Add a specified weight fraction of the specified element to the Material.
 void addElementByStoiciometry(Element elm, double moleFrac)
          addElementUsingMoleFractions - Add a specified mole fraction of the specified element to the material
protected  void clear()
          clear - Clear all consistuent elements.
 java.lang.Object clone()
           
 int compareTo(java.lang.Object o)
           
 boolean containsElement(Element el)
          containsElement - Determines whether the Material contains the specified Element.
 void defineByMaterialFraction(Composition[] compositions, double[] matFracs)
          defineByMaterialFraction - Define a new material out of certain fractions (by weight) of other materials.
 void defineByMoleFraction(Element[] elms, double[] moleFracs)
          defineByMoleFraction - Define a material by the mole fraction of the constituent elements.
 void defineByWeightFraction(Element[] elms, double[] wgtFracs)
          defineByWeightFraction - Define the material composition by weigh fraction from the array of atomic numbers and weight fractions.
 void defineByWeightFraction(java.util.Map map)
          defineByWeightFraction - Define the composition of this material by weight fraction.
 java.lang.String descriptiveString(boolean normalize)
          descriptiveId - A string describing this material terms of the constituent element's (normalized) weight percent and the material density.
 double difference(Composition comp)
          difference - Returns a measure (not necessarily the 'optimal' measure) of the difference between this Material and the argument Material.
static java.util.Set elementSet(Composition[] compositions)
          elementSet - Get the set of all elements in specified array of Materials.
 boolean equals(java.lang.Object obj)
          equals - Checks whether the value of this object exactly equals the value of the argument object.
static Composition fromXML(java.lang.String comp)
          fromXML - The inverse operation for toXML.
 int getElementCount()
          getElementCount - Returns the number of elements in this material.
 java.util.Set getElementSet()
          getElementSet - Returns a Set containing the Element objects that make up this Material.
 java.lang.String getName()
          getName - Gets either the name provided by the user (setName()) or the default name for this material if no name was specified.
 Element getNthElementByAtomicFraction(int n)
          getNthElementByAtomicFraction - Returns the n-th largest constituent by atomic fraction
 Element getNthElementByWeight(int n)
          getNthElementByWeight - Returns the n-th largest constituent by weight percent.
 int getOptimalRepresentation()
          getOptimalRepresentation - Returns one of STOICIOMETRY, WEIGHT_PCT or UNDETERMINED
 int hashCode()
           
 double massAbsorptionCoefficient(double energy)
          massAbsorptionCoefficient - Calculates the mass absorption coefficient for this material at the specified energy.
 double moleFraction(Element elm)
          moleFraction - Returns the moleFraction of the specified element.
 void removeElement(Element el)
          removeElement - Entirely remove the specified element from the Material.
protected  void renormalize()
           
protected  void replicate(Composition comp)
           
 void setName(java.lang.String name)
          setName - Provide a name for this material.
 double stoiciometryAvgAtomicNumber()
          Computes the mean atomic number for the elemental constituents comprising this Material based on their stoichiometric fraction.
 double sumWeightPercent()
          sumWeightPercent - The un-normalized sum of the weight percents of each element.
 java.lang.String toString()
           
 java.lang.String toXML()
          toXML - A matched pair with fromXML.
 double weightAvgAtomicNumber()
          Computes the mean atomic number for the elemental constituents comprising this Material based on their weight fraction.
 double weightPercent(Element elm, boolean normalized)
          weightPercent - Computes the weight percent of the specified element in this Material.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

UNDETERMINED

public static final int UNDETERMINED
See Also:
Constant Field Values

WEIGHT_PCT

public static final int WEIGHT_PCT
See Also:
Constant Field Values

STOICIOMETRY

public static final int STOICIOMETRY
See Also:
Constant Field Values

mHashCode

protected transient int mHashCode
Constructor Detail

Composition

public Composition()
Material - Constructs a Material that is equivalent to a pure vacuum.


Composition

public Composition(Element[] elms,
                   double[] weightFracs)
Constructs a Composition with the specified elements in the specified weight fractions.

Parameters:
elms - Element[] - The elements
weightFracs - double[] - The associated weight fractions

Composition

public Composition(Element[] elms,
                   double[] weightFracs,
                   java.lang.String name)
Constructs a Composition with the specified weight fractions. If the length of weighFracs is one less than the weight of elms then the last weight fraction is calculated from the others assuming that the sum is 1.0.

Parameters:
elms - Element[] - The elements
weightFracs - double[] - The associated weight fractions
name - String - User friendly
Method Detail

renormalize

protected void renormalize()

getElementSet

public java.util.Set getElementSet()
getElementSet - Returns a Set containing the Element objects that make up this Material.

Returns:
Set - A set containing Element objects

getElementCount

public int getElementCount()
getElementCount - Returns the number of elements in this material.

Returns:
int

addElement

public void addElement(int atomicNo,
                       double wgtFrac)
addElement - Add a specified weight fraction of the specified element to the Material.

Parameters:
atomicNo - int
wgtFrac - double

addElement

public void addElement(Element elm,
                       double wgtFrac)
addElement - Add a specified weight fraction of the specified element to the Material.

Parameters:
elm - Element
wgtFrac - double

addElementByStoiciometry

public void addElementByStoiciometry(Element elm,
                                     double moleFrac)
addElementUsingMoleFractions - Add a specified mole fraction of the specified element to the material

Parameters:
elm - Element
moleFrac - double

defineByWeightFraction

public void defineByWeightFraction(Element[] elms,
                                   double[] wgtFracs)
defineByWeightFraction - Define the material composition by weigh fraction from the array of atomic numbers and weight fractions.

Parameters:
elms - Element[]
wgtFracs - double[]

defineByWeightFraction

public void defineByWeightFraction(java.util.Map map)
defineByWeightFraction - Define the composition of this material by weight fraction. The map argument contains a map where the key may be an Integer containing the atomic number, a String containing the abbreviation or full name of the element or an Element object. The value is the weight fraction as a Double.

Parameters:
map - Map - keys are either Integer, String or Element types, values are Double

defineByMoleFraction

public void defineByMoleFraction(Element[] elms,
                                 double[] moleFracs)
defineByMoleFraction - Define a material by the mole fraction of the constituent elements. If a Material has N atoms in a volume V and the mole fraction of element i is m_i then there are N*m_i atoms of element i in the volume V.

Parameters:
elms - Element[]
moleFracs - double[]

elementSet

public static java.util.Set elementSet(Composition[] compositions)
elementSet - Get the set of all elements in specified array of Materials.

Parameters:
compositions - Composition[]
Returns:
Set[]

massAbsorptionCoefficient

public double massAbsorptionCoefficient(double energy)
massAbsorptionCoefficient - Calculates the mass absorption coefficient for this material at the specified energy.

Parameters:
energy - double - In Joules
Returns:
double - Absorption per unit length (meter)

defineByMaterialFraction

public void defineByMaterialFraction(Composition[] compositions,
                                     double[] matFracs)
defineByMaterialFraction - Define a new material out of certain fractions (by weight) of other materials. For example, you may construct Material to represent K3189 as 40% of SiO2, 14% of Al2O3, 14% of CaO, 10% of MgO, 2% of TiO2 and 20% of Fe2O3.

Parameters:
compositions - Material[] - The base materials (ie SiO2, MgO,...)
matFracs - double[] - The proportion of each

removeElement

public void removeElement(Element el)
removeElement - Entirely remove the specified element from the Material.

Parameters:
el - Element

containsElement

public boolean containsElement(Element el)
containsElement - Determines whether the Material contains the specified Element.

Parameters:
el - Element
Returns:
boolean

clear

protected void clear()
clear - Clear all consistuent elements. Material -> pure vacuum


moleFraction

public double moleFraction(Element elm)
moleFraction - Returns the moleFraction of the specified element. This is the number of atoms of the specified atom as a fraction of the total number of atoms (in an arbitrary volume).

Parameters:
elm - Element
Returns:
double

weightPercent

public double weightPercent(Element elm,
                            boolean normalized)
weightPercent - Computes the weight percent of the specified element in this Material. If normalized=true then the sum of the weightPercent for all elements in the Material will equal 1.0.

Parameters:
elm - Element
normalized - boolean
Returns:
double

stoiciometryAvgAtomicNumber

public double stoiciometryAvgAtomicNumber()
Computes the mean atomic number for the elemental constituents comprising this Material based on their stoichiometric fraction.

Returns:
double

weightAvgAtomicNumber

public double weightAvgAtomicNumber()
Computes the mean atomic number for the elemental constituents comprising this Material based on their weight fraction.

Returns:
double

sumWeightPercent

public double sumWeightPercent()
sumWeightPercent - The un-normalized sum of the weight percents of each element.

Returns:
A number that is typically ~1.0

equals

public boolean equals(java.lang.Object obj)
equals - Checks whether the value of this object exactly equals the value of the argument object.

Overrides:
equals in class java.lang.Object
Parameters:
obj - Object
Returns:
boolean

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

descriptiveString

public java.lang.String descriptiveString(boolean normalize)
descriptiveId - A string describing this material terms of the constituent element's (normalized) weight percent and the material density.

Parameters:
normalize - Normalize weight percentages to 100%
Returns:
String

toXML

public java.lang.String toXML()
toXML - A matched pair with fromXML. Converts the Composition into an XML string. Also converts classes derived from Composition too.

Returns:
String

fromXML

public static Composition fromXML(java.lang.String comp)
                           throws EPQException
fromXML - The inverse operation for toXML. Takes the String created by toXML and parses it to return a Composition. The returned object might be a class derived from Composition.

Parameters:
comp - String
Returns:
Composition
Throws:
EPQException

getNthElementByWeight

public Element getNthElementByWeight(int n)
getNthElementByWeight - Returns the n-th largest constituent by weight percent.

Parameters:
n - - 1 to getElementCount()
Returns:
Element

getNthElementByAtomicFraction

public Element getNthElementByAtomicFraction(int n)
getNthElementByAtomicFraction - Returns the n-th largest constituent by atomic fraction

Parameters:
n - - 1 to getElementCount()
Returns:
Element

setName

public void setName(java.lang.String name)
setName - Provide a name for this material.

Parameters:
name - String

getName

public java.lang.String getName()
getName - Gets either the name provided by the user (setName()) or the default name for this material if no name was specified.

Returns:
String

compareTo

public int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable

replicate

protected void replicate(Composition comp)

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

difference

public double difference(Composition comp)
difference - Returns a measure (not necessarily the 'optimal' measure) of the difference between this Material and the argument Material.

Parameters:
comp - Composition
Returns:
double

getOptimalRepresentation

public int getOptimalRepresentation()
getOptimalRepresentation - Returns one of STOICIOMETRY, WEIGHT_PCT or UNDETERMINED

Returns:
STOICIOMETRY, WEIGHT_PCT or UNDETERMINED