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

Commit

Permalink
Committing progress on refInt port.
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Jay Billings <billingsjj@ornl.gov>
  • Loading branch information
Jay Jay Billings committed Jan 30, 2015
1 parent 1cec4f5 commit efc9943
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/org.eclipse.ice.reflectivity/META-INF/MANIFEST.MF
Expand Up @@ -5,7 +5,9 @@ Bundle-SymbolicName: org.eclipse.ice.reflectivity
Bundle-Version: 2.0.0
Service-Component: OSGI-INF/ReflectivityModelComponent.xml
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: org.eclipse.ice.item,
Import-Package: org.apache.commons.math;version="2.1.0",
org.apache.commons.math.complex;version="2.1.0",
org.eclipse.ice.item,
org.eclipse.ice.item.model,
org.eclipse.ice.materials
Require-Bundle: org.eclipse.ice.datastructures;bundle-version="2.0.0",
Expand Down
Expand Up @@ -11,23 +11,20 @@
*******************************************************************************/
package org.eclipse.ice.reflectivity;

import org.apache.commons.math.complex.Complex;

/**
* This class performs all of the operations necessary to calculate the
* reflectivity of a stack of materials. It follows the code originally
* developed by John Ankner at Oak Ridge National Laboratory.
* developed by John Ankner at Oak Ridge National Laboratory that uses the
* method described in Parratt, Phys. Rev. 95, 359(1954). It has been corrected
* to incorporate incoherent and true absorption.
*
* @author Jay Jay Billings, John Ankner
*
*/
public class ReflectivityCalculator {

/**
* The constructor
*/
public ReflectivityCalculator() {
// TODO Auto-generated constructor stub
}

/**
* This operation returns the value of the squared modulus of the specular
* reflectivity for a single wave vector Q.
Expand All @@ -42,9 +39,64 @@ public ReflectivityCalculator() {
* absorption parameters and thicknesses.
* @return the squared modulus of the specular reflectivity
*/
public double getSpecRefSqrdMod(double waveVectorQ, double wavelength,
public double getModSqrdSpecRef(double waveVectorQ, double wavelength,
Tile[] tiles) {
return 0.0;
}

double modSqrdSpecRef = 0.0;

if (wavelength > 0.0) {
// Variables only needed if we are going to do the work, i.e. -
// wavelength > 0.0.
Tile tile;
Complex aNm1Sq, fNm1N, rNm1N = new Complex(0.0, 0.0), one = new Complex(
1.0, 0.0), qN = new Complex(0.0, 0.0), rNNp1 = new Complex(
0.0, 0.0);
// Get the bottom tile
int nLayers = tiles.length;
tile = tiles[nLayers - 1];
// Starting point--no reflected beam in bottom-most (bulk) layer
double qCSq = 16.0 * Math.PI * tile.scatteringLength;
double muLAbs = tile.trueAbsLength;
double mulInc = tile.incAbsLength;
double thickness = tile.thickness;
// Setup other values for the problem
double betaNm1 = 4.0 * Math.PI * (muLAbs + mulInc / wavelength);
Complex qNm1 = new Complex(waveVectorQ * waveVectorQ - qCSq, -2.0
* betaNm1);
qNm1 = qNm1.multiply(qNm1);
// Loop through to calculate recursion formula described in Parratt.
// Start at the bottom and work up.
for (int i = nLayers - 1; i > 0; i--) {
// Get the tile above tile[i] (started at the bottom
tile = tiles[i - 1];
// Calculate the normal component of Q for layer and layer-1
qN = qNm1;
qCSq = 16.0 * Math.PI * tile.scatteringLength;
muLAbs = tile.trueAbsLength;
mulInc = tile.incAbsLength;
thickness = tile.thickness;
betaNm1 = 4.0 * Math.PI * (muLAbs + mulInc / wavelength);
qNm1 = new Complex(waveVectorQ * waveVectorQ - qCSq, -2.0
* betaNm1);
qNm1 = qNm1.multiply(qNm1);
// Calculate phase factor, e^(-0.5*d*qNm1)
aNm1Sq = (new Complex(qNm1.getImaginary(), qNm1.getReal())
.multiply(-0.5 * thickness)).exp();
// CDiv(qNm1-qN,qNm1+qN)
fNm1N = qNm1.subtract(qN).divide(qNm1.add(qN));
// Calculate the reflectivity amplitude.
// CMult(aNm1Sq, CMult(aNm1Sq, CDiv(CAdd(rNNp1, fNm1N),
// CAdd(CMult(rNNp1, fNm1N), CReal(1)))))
Complex y = rNNp1.multiply(fNm1N).add(one);
Complex z = rNNp1.add(fNm1N);
rNm1N = aNm1Sq.multiply(aNm1Sq).multiply(z.divide((y)));
// Carry over to the next iteration
rNNp1 = rNm1N;
}
modSqrdSpecRef = rNm1N.getReal() * rNm1N.getReal()
+ rNm1N.getImaginary() * rNm1N.getImaginary();
}

return modSqrdSpecRef;
}
}
Expand Up @@ -26,21 +26,21 @@ public class Tile {
/**
* The scattering length of the reflecting tile/layer.
*/
double scatteringLength = 0.0;
public double scatteringLength = 0.0;

/**
* The true absorption length of the reflecting tile/layer.
*/
double trueAbsLength = 0.0;
public double trueAbsLength = 0.0;

/**
* The incoherent absorption length of the reflecting tile/layer.
*/
double incAbsLength = 0.0;
public double incAbsLength = 0.0;

/**
* The thickness of this tile/layer.
*/
double thickness = 0.0;
public double thickness = 0.0;

}
3 changes: 2 additions & 1 deletion tests/org.eclipse.ice.reflectivity.test/META-INF/MANIFEST.MF
Expand Up @@ -11,4 +11,5 @@ Import-Package: org.eclipse.core.resources,
org.eclipse.core.runtime;version="3.4.0",
org.eclipse.ice.io.csv,
org.eclipse.ice.materials,
org.eclipse.ice.reflectivity
org.eclipse.ice.reflectivity,
org.eclipse.ui.forms.widgets
Expand Up @@ -23,7 +23,11 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.ice.datastructures.ICEObject.ListComponent;
import org.eclipse.ice.datastructures.form.Form;
import org.eclipse.ice.io.csv.CSVReader;
import org.eclipse.ice.reflectivity.ReflectivityCalculator;
import org.eclipse.ice.reflectivity.Tile;
import org.junit.BeforeClass;
import org.junit.Test;

Expand Down Expand Up @@ -105,7 +109,57 @@ public static void setUpBeforeClass() throws Exception {
*/
@Test
public void testGetSpecRefSqrdMod() {

// Load the file
Form form = reader.read(project.getFile("getSpecRefSqrdMod_q841.csv"));
ListComponent<String[]> lines = (ListComponent<String[]>) form
.getComponent(1);

// Get the two single parameters and the final result out of the data
String[] line = lines.get(0);
double waveVectorQ, wavelength, expectedSpecRefSqrd;
waveVectorQ = Double.valueOf(line[0]);
wavelength = Double.valueOf(line[1]);
expectedSpecRefSqrd = Double.valueOf(line[2]);

// Load the tiles from the rest of the data
Tile[] tiles = loadTiles(lines);

// Get the squared modulus of the specular reflectivity
ReflectivityCalculator calculator = new ReflectivityCalculator();
double specRefSqrd = calculator.getModSqrdSpecRef(waveVectorQ,
wavelength, tiles);
assertEquals(expectedSpecRefSqrd, specRefSqrd,1.0e-4);

fail("Not yet implemented");
return;
}

/**
* This operation loads the set of Tiles from the reference file, ignoring
* the first line that stores the reference values.
*
* @param lines The ListComponent with the lines from the file
* @return the list of Tiles from the file
*/
private Tile[] loadTiles(ListComponent<String[]> lines) {

// Load all of the tiles
Tile [] tiles = new Tile[lines.size()-1];
for (int i = 1; i < lines.size(); i++) {
// Load the line
String [] line = lines.get(i);
// Create the tile and load the data from the line
Tile tile = new Tile();
tile.scatteringLength = Double.valueOf(line[0]);
tile.trueAbsLength = Double.valueOf(line[1]);
tile.incAbsLength = Double.valueOf(line[2]);
tile.thickness = Double.valueOf(line[3]);
// Load the tile into the array
tiles[i-1] = tile;
}

return tiles;
}

}

0 comments on commit efc9943

Please sign in to comment.