Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Merge branch 'jay/reflectivity' of https://github.com/eclipse/ice int…
Browse files Browse the repository at this point in the history
…o jay/reflectivity
  • Loading branch information
Jay Jay Billings committed Jun 18, 2015
2 parents ba09639 + a15b399 commit e138054
Show file tree
Hide file tree
Showing 11 changed files with 488 additions and 62 deletions.
Expand Up @@ -22,6 +22,8 @@
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import org.eclipse.ice.datastructures.form.MaterialStack;

/**
* This class represents physical Materials.
*
Expand Down Expand Up @@ -117,16 +119,16 @@ public class Material implements Cloneable, Comparable<Material> {
/**
* The list of components that comprise this material.
*/
@XmlElement(name = "Material")
private List<Material> components;
//@XmlElement(name = "Material")
private List<MaterialStack> components;

/**
* The constructor.
*/
public Material() {
name = "";
properties = new HashMap<String, Double>();
components = new ArrayList<Material>();
components = new ArrayList<MaterialStack>();
}

/**
Expand Down Expand Up @@ -205,19 +207,70 @@ public Map<String, Double> getProperties() {
* @return The list of Materials that make up this one. Changing this list
* will not affect list stored by the Material.
*/
public List<Material> getComponents() {
return new ArrayList<Material>(components);
public List<MaterialStack> getComponents() {
return new ArrayList<MaterialStack>(components);
}

/**
* This operation adds a component to this material, effectively marking
* this Materials as being a composite of others.
* this Material as being a composite of others. It tries to see if the
* material added already exists in this material's components, and if so
* just increments the amount. Otherwise, adds the new material as a
* material stack with an amount of 1.
*
* @param component
* The material that is a component of this material.
* The material that is a component of this material to be added.
*/
public void addComponent(Material component) {
components.add(component);
// Do not want to make a new stack if the material already is a
// component
// of this one.
boolean added = false;
// Iterate over stacks to try to find the material
for (MaterialStack stack : components) {
Material m = stack.getMaterial();
if (component.equals(m)) {
// Add the material
stack.setAmount(stack.getAmount() + 1);
added = true;
break;
}
}
// Not found already, create a new material stack and add to components
if (!added) {
components.add(new MaterialStack(component, 1));
}
}

/**
* This operation adds a component to this material, effectivly marking this
* Material as being a composite of others. It tries to see if the material
* stack given is a stack of an existing compoenent of this material, and if
* so updates the amount for that stack. Otherwise, adds the new stack to
* the list of components.
*
* @param stack
*/
public void addComponent(MaterialStack stack) {
// Do not want to add a new stack if the material in the stack already
// is a component of this one.
boolean added = false;
Material mat = stack.getMaterial();
// Iterate over stacks to try to find the material that fits the new
// stack
for (MaterialStack matStack : components) {
Material m = matStack.getMaterial();
if (mat.equals(m)) {
// Add the stack amount to the existing stack
matStack.setAmount(matStack.getAmount() + stack.getAmount());
added = true;
break;
}
}
// Not found already, then just add the stack to the components
if (!added) {
components.add(stack);
}
}

/**
Expand Down Expand Up @@ -280,7 +333,7 @@ public void copy(Material material) {
if (material != null && material != this) {
this.name = material.name;
this.properties = new HashMap<String, Double>(material.properties);
this.components = new ArrayList<Material>(material.components);
this.components = new ArrayList<MaterialStack>(material.components);
}
}

Expand Down
@@ -0,0 +1,168 @@
/*******************************************************************************
* Copyright (c) 2013, 2014 UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation -
* Kasper Gammeltoft
*******************************************************************************/
package org.eclipse.ice.datastructures.form;

/**
* A class to encapsulate a multitude of the same material. This is a much
* better solution than having a material hold information about its own amount
* in a stack.
*
*
* @author Kasper Gammeltoft
*
*/
public class MaterialStack implements Comparable<MaterialStack> {

/**
* The material in this material stack
*/
private Material material;

/**
* The amount in this material stack
*/
private int number;

/**
* Null constructor.
*/
public MaterialStack() {
material = null;
number = 0;
}

/**
* Create a new material stack for holding a material.
*
* @param material
* The material to hold.
* @param amount
* How many to hold.
*/
public MaterialStack(Material material, int amount) {
this.material = material;
number = amount;

}

/**
* Gets the material held in this stack.
*
* @return The material
*/
public Material getMaterial() {
return material;
}

/**
* Sets the material that should be held in this stack. Note- does not reset
* the amount held.
*
* @param material
* The material to take over the stack.
*/
public void setMaterial(Material material) {
this.material = material;
}

/**
* The amount of the material held in this stack.
*
* @return The amount in the stack
*/
public int getAmount() {
return number;
}

/**
* Sets the amount of the material in the stack.
*
* @param amount
* The amount
*/
public void setAmount(int amount) {
number = amount;
}

/**
* Adds one to the amount on the stack. A convenience method. The same
* effect could be achieved by writing MaterialStack.add(1).
*/
public void incrimentAmount() {
number++;
}

/**
* Adds the amount specified to the stacks existing amount.
*
* @param amount
* The amount to add
*/
public void addAmount(int amount) {
number += amount;
}

/**
* Compares two material stacks to tell if they are equal to one another.
*
* @param stack
* The stack to compare this one with
* @return Returns true if the stacks are equal (same material, same amount)
* and false if otherwise.
*/
public boolean equals(MaterialStack stack) {
return number == stack.getAmount()
&& material.equals(stack.getMaterial());
}

/**
* Compares two material stacks to see which should be first in a list
* containing material stacks. Compares based on the same logic for the
* materials, but will list lesser (in amount) material stacks before
* greater if the materials are the same when compared.
*
* @param
* stack The material stack to compare to this one.
*/
@Override
public int compareTo(MaterialStack stack) {
int retVal = 0;
// The material names are the same. Order from less amount to greater
// amount.
if (material.getName().toLowerCase()
.equals(stack.getMaterial().getName().toLowerCase())) {
if (number < stack.getAmount()) {
retVal = -1;
} else if (number == stack.getAmount()) {
retVal = 0;
} else {
retVal = 1;
}
} else {
retVal = material.compareTo(stack.getMaterial());
}

return retVal;
}

/**
* Gets this material stack as a string. In the format [Material Stack:[ of
* Material[some material name] and amount[#]]
*/
@Override
public String toString() {
String str = "Material Stack:[ of Material[" + material.getName()
+ "] and amount[" + number + "]";
return str;
}

}
Expand Up @@ -18,7 +18,7 @@
import org.eclipse.ice.datastructures.ICEObject.IElementSource;
import org.eclipse.ice.datastructures.ICEObject.ListComponent;
import org.eclipse.ice.datastructures.form.Material;
import org.eclipse.ice.materials.MaterialStack;
import org.eclipse.ice.datastructures.form.MaterialStack;
import org.eclipse.ice.materials.MaterialStackWritableTableFormat;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.window.Window;
Expand Down Expand Up @@ -156,16 +156,15 @@ public Material getMaterial() {

// Add the stoichiometric components as components of the new material.
for (MaterialStack stack : list) {
Material m = stack.getMaterial();
matList.add(m);
material.addComponent(m);
material.addComponent(stack);
}

// Following John Ankner's code ported from Visual Basic
int molMass = 0;

for(MaterialStack stack: list){
//molMass+=stack.getAmount()*(stack.getMaterial().getProperty(key))
molMass+=stack.getAmount()*(stack.getMaterial().getProperty(Material.ATOMIC_MASS));

}

return material;
Expand Down

0 comments on commit e138054

Please sign in to comment.