GeomConverter/src/org/lcsim/material
diff -u -r1.3 -r1.4
--- Material.java 30 Jun 2005 00:53:16 -0000 1.3
+++ Material.java 30 Jun 2005 23:21:01 -0000 1.4
@@ -17,8 +17,8 @@
double _pressure;
double _density;
boolean _isElement;
- public double _Zeff;
- public double _Aeff;
+ public double _Z;
+ public double _A;
public double _Neff;
MaterialState _state;
String _name;
@@ -34,20 +34,20 @@
public Material()
{
- _Zeff=0;
+ _Z=0;
_state = MaterialState.UNKNOWN;
_isElement = false;
_name = "Vacuum";
- }
+ }
- /* Construct base material with all info. */
+ /* Construct base material with all info, creating a MaterialElement, also. */
public Material(String name,
- double z,
- double a,
- double density,
- MaterialState state,
- double temp,
- double pressure)
+ double z,
+ double a,
+ double density,
+ MaterialState state,
+ double temp,
+ double pressure)
{
_name = name;
_density = density;
@@ -55,45 +55,36 @@
_temp = temp;
_pressure = pressure;
_formula = " ";
-
+
if ( z <= 0 )
{
throw new IllegalArgumentException("Z must be >= 0.");
}
- _Zeff = z;
+ _Z = z;
if ( a <= 0 )
{
- throw new IllegalArgumentException("A must be >= 0.");
+ throw new IllegalArgumentException("A must be >= 0.");
}
- _Aeff = a;
+ _A = a;
_nComponents = _nComponentsMax = _nElements = 1;
_isElement = true;
- //MaterialElement element = MaterialManager.getElement(name);
-
- //if ( element == null )
- //{
- // throw new RuntimeException("Corresponding element not found for material by name: " + name);
- //}
-
- //_elements.add(element);
- MaterialManager.addElement(new MaterialElement(_name, _Zeff, _Aeff) );
- _massFractions.add(1.0);
+ MaterialManager.addElement(new MaterialElement(_name, _Z, _A) );
+ _massFractions.add(1.0);
MaterialManager.addMaterial(this);
}
public Material(String name,
- int nComponents,
- double density,
- MaterialState state,
- double temp,
- double pressure
- )
+ int nComponents,
+ double density,
+ MaterialState state,
+ double temp,
+ double pressure)
{
_name = name;
_density = density;
@@ -109,7 +100,7 @@
_nComponentsMax = nComponents;
_nComponents = _nElements = 0;
- _isElement = false;
+ _isElement = false;
MaterialManager.addMaterial(this);
}
@@ -135,13 +126,17 @@
* Based on G4Material::AddElement() .
*/
void addElement(MaterialElement element,
- int nAtoms)
+ int nAtoms)
{
+ System.out.println("Material.addElement() - composite add " + element.getName() + " to " + getName() );
+
if ( _nElements < _nComponentsMax )
{
_elements.add(element);
_atoms.add( _nElements, nAtoms);
_nComponents = ++_nElements;
+
+ System.out.println("ncomp, nelem: " + _nComponents + " " + _nElements);
}
else
{
@@ -150,6 +145,8 @@
if ( isFilled() )
{
+ System.out.println("setting mass fractions");
+
double Zmol = 0;
double Amol = 0;
@@ -165,14 +162,16 @@
{
_massFractions.add(_atoms.get(massCnt) * ee.getA() / Amol);
++massCnt;
- }
+ }
}
}
/** Add element by fraction of mass. */
void addElement(MaterialElement element,
- double fraction)
+ double fraction)
{
+ System.out.println("Material.addElement() - fraction add " + element.getName() + " to " + getName() );
+
if ( _nComponents < _nComponentsMax )
{
int elCnt = 0;
@@ -190,8 +189,9 @@
{
_elements.add(element);
_massFractions.add(elCnt, fraction);
- ++_nElements;
+ ++_nElements;
}
+ ++_nComponents;
}
else
{
@@ -200,14 +200,16 @@
if ( isFilled() )
{
- checkMassSum();
+ checkMassSum();
}
}
/** Add material by fraction of mass. */
void addMaterial(Material material,
- double fraction)
+ double fraction)
{
+ System.out.println("Material.addElement() - fraction add " + material.getName() + " to " + getName() );
+
if ( _atoms.size() > 0 )
{
throw new RuntimeException("Material is already defined by atoms: " + getName());
@@ -221,22 +223,27 @@
MaterialElement element = material.getElements().get(i);
int elCnt = 0;
/* Find the element. */
- while (elCnt < _nElements && element != _elements.get(elCnt))
+ while ((elCnt < _nElements) && (element != _elements.get(elCnt)))
{
++elCnt;
}
+
+ /* Add fraction to existing element. */
if ( elCnt < _nElements )
{
double currFrac = _massFractions.get(elCnt);
- currFrac += fraction;
- _massFractions.add(elCnt, currFrac);
+ currFrac += fraction * material.getMassFractions().get(i) ;
+ _massFractions.set(elCnt, currFrac);
}
+ /* Add a new element. */
else
{
+ System.out.println("adding mass fraction: " + element.getName() + "=" + fraction * material.getMassFractions().get(i) );
+
_elements.add(element);
/**
- * Add the fraction of this element, normalized to the percentage in the material's
+ * Add the mass fraction of this element, scaled by its percentage in the material's
* mass fraction list.
*/
_massFractions.add(elCnt, fraction * material.getMassFractions().get(i));
@@ -244,6 +251,7 @@
}
}
++_nComponents;
+ System.out.println("ncomp, ncompmax: " + _nComponents + " " +_nComponentsMax);
}
else
{
@@ -252,18 +260,18 @@
if ( isFilled() )
{
- checkMassSum();
+ checkMassSum();
}
}
private boolean isFilled()
{
- return _nElements == _nComponentsMax;
+ return (_nComponents == _nComponentsMax);
}
private void checkMassSum()
{
-
+ System.out.println("checking mass sum for: " + getName() );
double weightSum = 0;
for ( int i = 0; i < _massFractions.size(); i++)
{
@@ -272,6 +280,14 @@
if ( abs(1 - weightSum) > 0.001 )
{
+ System.err.println("bad weight sum: " + weightSum);
+
+ System.out.println("listing weights...");
+ for ( int i = 0; i < _massFractions.size(); i++)
+ {
+ System.out.println(_elements.get(i).getName() + " = " + _massFractions.get(i));
+ }
+
throw new RuntimeException("Mass fractions do not sum to 1 within 0.001 tolerance for this material: " + getName() );
}
}
@@ -286,6 +302,21 @@
_formula = formula;
}
+ public int getNComponents()
+ {
+ return _nComponents;
+ }
+
+ public int getNComponentsMax()
+ {
+ return _nComponentsMax;
+ }
+
+ public int getNElements()
+ {
+ return _nElements;
+ }
+
// 1 mole
//public static double AvogN = 6.022136736e23;
}
\ No newline at end of file