From efc9943b3ff67ca76e7fd59e7b87aaa80723e065 Mon Sep 17 00:00:00 2001 From: Jay Jay Billings Date: Fri, 30 Jan 2015 15:41:38 -0500 Subject: [PATCH] Committing progress on refInt port. Signed-off-by: Jay Jay Billings --- .../META-INF/MANIFEST.MF | 4 +- .../reflectivity/ReflectivityCalculator.java | 74 ++++++++++++++++--- .../org/eclipse/ice/reflectivity/Tile.java | 8 +- .../META-INF/MANIFEST.MF | 3 +- .../test/ReflectivityCalculatorTester.java | 54 ++++++++++++++ 5 files changed, 126 insertions(+), 17 deletions(-) diff --git a/src/org.eclipse.ice.reflectivity/META-INF/MANIFEST.MF b/src/org.eclipse.ice.reflectivity/META-INF/MANIFEST.MF index 1ae92a6a1..529c04f7c 100644 --- a/src/org.eclipse.ice.reflectivity/META-INF/MANIFEST.MF +++ b/src/org.eclipse.ice.reflectivity/META-INF/MANIFEST.MF @@ -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", diff --git a/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityCalculator.java b/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityCalculator.java index 993a3b4bf..8c08ea04e 100644 --- a/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityCalculator.java +++ b/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityCalculator.java @@ -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. @@ -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; + } } diff --git a/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/Tile.java b/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/Tile.java index 6940eeb8b..4c651b76e 100644 --- a/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/Tile.java +++ b/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/Tile.java @@ -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; } diff --git a/tests/org.eclipse.ice.reflectivity.test/META-INF/MANIFEST.MF b/tests/org.eclipse.ice.reflectivity.test/META-INF/MANIFEST.MF index 9fe3b2ab7..15583c82a 100644 --- a/tests/org.eclipse.ice.reflectivity.test/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.ice.reflectivity.test/META-INF/MANIFEST.MF @@ -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 diff --git a/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityCalculatorTester.java b/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityCalculatorTester.java index 169efff38..ff86b97d8 100644 --- a/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityCalculatorTester.java +++ b/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityCalculatorTester.java @@ -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; @@ -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 lines = (ListComponent) 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 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; } }