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

Commit

Permalink
Finished GenTiles! That was a beast of a routine, but now the tile
Browse files Browse the repository at this point in the history
generation is correct and agrees out to a ridiculous precision.

Signed-off-by: Jay Jay Billings <billingsjj@ornl.gov>
  • Loading branch information
Jay Jay Billings committed Apr 8, 2015
1 parent 1606309 commit d9ddc43
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 56 deletions.
Expand Up @@ -41,7 +41,7 @@ public class ReflectivityCalculator {
/**
* A factor used in computing tile updates
*/
private static final double cE = 1.655;
private static final double cE = 1.665;

/**
* This operation returns the value of the squared modulus of the specular
Expand Down Expand Up @@ -391,22 +391,23 @@ public Tile[] generateTiles(Slab[] slabs, int numRough, double[] zInt,
double[] rufInt) throws MathException {

// Local Declarations
int nGlay = 0, step = 0, dist = 0;
double totalThickness = 0.0, gDMid = 0.0;
int nGlay = 0;
double totalThickness = 0.0, gDMid = 0.0, step = 0.0, dist = 0.0;
// The number of slabs was not defined in the original code. I computed
// it by counting up the loops. This formula is currently off a little
// bit.
int numSlabs = 2 + 2 * (numRough / 2 + 1) + (slabs.length - 2)
* (2 + numRough);
Slab[] generatedSlabs = new Slab[numSlabs];
Tile[] generatedSlabs = new Tile[numSlabs];
// Create the slabs
for (int i = 0; i < numSlabs; i++) {
generatedSlabs[i] = new Slab();
}

// Evaluate the first half of the vacuum interface. Create the first
// slab.
Slab tmpSlab = generatedSlabs[0], refSlab = slabs[0], secondRefSlab = slabs[1], thirdRefSlab;
Tile tmpSlab = generatedSlabs[0];
Slab refSlab = slabs[0], secondRefSlab = slabs[1], thirdRefSlab;
tmpSlab.scatteringLength = refSlab.scatteringLength;
tmpSlab.trueAbsLength = refSlab.trueAbsLength;
tmpSlab.incAbsLength = refSlab.incAbsLength;
Expand All @@ -425,76 +426,102 @@ public Tile[] generateTiles(Slab[] slabs, int numRough, double[] zInt,
for (int i = 0; i < numRough + 1; i++) {
totalThickness += zInt[i];
}
System.out.println("zTot = " + totalThickness);

// Calculate gradation of layers. Using slabs.length - 1 because the
// last layer is at index 4.
for (int i = 1; i < slabs.length - 1; i++) {
refSlab = slabs[i];
secondRefSlab = slabs[i + 1];
thirdRefSlab = slabs[i - 1];
// FIXME! Review gDMid calculation with John because it can be
// negative.
gDMid = refSlab.thickness - 0.5 * totalThickness
* refSlab.interfaceWidth;
* (refSlab.interfaceWidth + secondRefSlab.interfaceWidth);
System.out.println("GDMid[" + i + "] = " + gDMid + ", " + refSlab.thickness
+ ", " + refSlab.interfaceWidth + ", "
+ secondRefSlab.interfaceWidth);
if (gDMid <= 1.0e-10) {
// The interfaces are overlapping. Step through the entire slab
step = (int) refSlab.thickness / (numRough + 1);
step = refSlab.thickness / ((double) (numRough + 1));
System.out.println("Step at i = " + i + " = " + step);
// Take the first half step
tmpSlab = generatedSlabs[nGlay];
tmpSlab.thickness = (double) step / 2;
dist = step / 4;
System.out.println("NGLAY in loop at i = " + i + " = " + nGlay);
tmpSlab.thickness = step / 2.0;
dist = step / 4.0;
updateTileByLayer(tmpSlab, thirdRefSlab, refSlab,
secondRefSlab, dist);
++nGlay;
dist += 0.75 * ((double) step);
dist += 0.75 * step;
// Take the remaining steps
for (int j = 0; j < numRough - 1; j++) {
for (int j = 0; j < numRough; j++) {
tmpSlab = generatedSlabs[nGlay + j];
tmpSlab.thickness = (double) step;
tmpSlab.thickness = step;
updateTileByLayer(tmpSlab, thirdRefSlab, refSlab,
secondRefSlab, dist);
dist += step;
System.out.println("q = " + (nGlay + j) + " "
+ tmpSlab.scatteringLength);
}
nGlay += numRough;
System.out.println("NGLAY = " + nGlay);
// Take final half step
tmpSlab = generatedSlabs[nGlay + 1];
tmpSlab.thickness = (double) step / 2;
dist = ((int) refSlab.thickness) - step / 4;
tmpSlab = generatedSlabs[nGlay];
tmpSlab.thickness = step / 2.0;
dist = refSlab.thickness - step / 4.0;
System.out.println("dist " + dist);
updateTileByLayer(tmpSlab, thirdRefSlab, refSlab,
secondRefSlab, dist);
System.out.println("q = " + (nGlay) + " "
+ tmpSlab.scatteringLength);
++nGlay;
System.out.println("Exiting if " + i);
} else {
// Evaluate contributions from interfaces separately.
// Top interface
for (int j = numRough / 2 + 1; j < numRough + 1; j++) {
// Get the next slab and update it by considering the
// interface contribution.
tmpSlab = generatedSlabs[nGlay + j - numRough / 2 - 2];
tmpSlab = generatedSlabs[nGlay + j - numRough / 2 - 1];
updateTileByInterface(tmpSlab, thirdRefSlab, refSlab,
zInt[j], rufInt[j]);
System.out.println("q = " + (nGlay + j - numRough/2 -1) + " "
+ tmpSlab.scatteringLength);
}
nGlay += numRough / 2 + 1;
// Central, bulk-like portion
tmpSlab = generatedSlabs[nGlay + 1];
tmpSlab.interfaceWidth = gDMid;
tmpSlab = generatedSlabs[nGlay];
tmpSlab.scatteringLength = refSlab.scatteringLength;
tmpSlab.thickness = gDMid;
tmpSlab.trueAbsLength = refSlab.trueAbsLength;
tmpSlab.incAbsLength = refSlab.incAbsLength;
System.out.println("q = " + (nGlay) + " "
+ tmpSlab.scatteringLength);
++nGlay;
// Bottom interface
for (int j = 1; j < numRough / 2 + 1; j++) {
for (int j = 0; j < numRough / 2 + 1; j++) {
tmpSlab = generatedSlabs[nGlay + j];
updateTileByInterface(tmpSlab, refSlab, secondRefSlab,
zInt[j], rufInt[j]);
System.out.println("q = " + (nGlay + j) + " "
+ tmpSlab.scatteringLength);
}
nGlay += numRough / 2 + 1;
System.out.println("Exiting else " + i);
}
}

// Evaluate substrate gradation
refSlab = slabs[slabs.length - 2];
secondRefSlab = slabs[slabs.length - 3];
for (int i = numRough / 2 + 2; i < numRough + 1; i++) {
refSlab = slabs[slabs.length - 1];
secondRefSlab = slabs[slabs.length - 2];
System.out.println("Entering substrate gradation");
for (int i = numRough / 2 + 1; i < numRough + 1; i++) {
tmpSlab = generatedSlabs[nGlay + i - numRough / 2 - 1];
updateTileByInterface(tmpSlab, secondRefSlab, refSlab, zInt[i],
rufInt[i]);
System.out.println("q = " + (nGlay + i - numRough/2 - 1) + " "
+ tmpSlab.scatteringLength);
}
nGlay += numRough / 2 + 1;
// Handle the last layer
Expand Down Expand Up @@ -522,7 +549,7 @@ public Tile[] generateTiles(Slab[] slabs, int numRough, double[] zInt,
* @param dist
* the step distance
*/
private void updateTileByInterface(Slab tile, Slab slabM1, Slab slab,
private void updateTileByInterface(Tile tile, Slab slabM1, Slab slab,
double zInt, double rufInt) {

// Update the tile
Expand Down Expand Up @@ -555,7 +582,7 @@ private void updateTileByInterface(Slab tile, Slab slabM1, Slab slab,
* @throws MathException
* Thrown if the error function cannot be evaluated
*/
private void updateTileByLayer(Slab updateSlab, Slab slabM1, Slab slab,
private void updateTileByLayer(Tile updateSlab, Slab slabM1, Slab slab,
Slab slabP1, double dist) throws MathException {

// Compute the exponentials
Expand Down
Expand Up @@ -365,81 +365,96 @@ public void testGetInterfacialProfile() throws MathException {
return;
}


/**
* This operation tests
* {@link ReflectivityCalculator#generateTiles()}.
* @throws MathException
* This operation tests {@link ReflectivityCalculator#generateTiles()}.
*
* @throws MathException
*/
@Test
public void testGenerateTiles() throws MathException {

// Create the calculator
ReflectivityCalculator calculator = new ReflectivityCalculator();

// Create the slabs, starting with air
Slab air = new Slab();
air.thickness = 200.0;

// NiOx
Slab niOx = new Slab();
niOx.scatteringLength = 7.005e-6;
niOx.trueAbsLength = 2.28e-9;
niOx.incAbsLength = 4.75e-9;
niOx.scatteringLength = (0.00000686 + 0.00000715) / 2.0;
niOx.trueAbsLength = 2.27931868269305E-09;
niOx.incAbsLength = 4.74626235093697E-09;
niOx.thickness = 22.0;
niOx.interfaceWidth = 9.4;
niOx.interfaceWidth = 4.0 * 2.35;

// Ni
Slab ni = new Slab();
ni.scatteringLength = 9.31e-6;
ni.trueAbsLength = 2.28e-9;
ni.incAbsLength = 4.75e-9;
ni.trueAbsLength = 2.27931868269305E-09;
ni.incAbsLength = 4.74626235093697E-09;
ni.thickness = 551.0;
ni.interfaceWidth = 10.1;
ni.interfaceWidth = 4.3 * 2.35;

// SiNiOx
Slab siNiOx = new Slab();
siNiOx.scatteringLength = 5.695e-6;
siNiOx.trueAbsLength = 2.28e-9;
siNiOx.incAbsLength = 4.75e-9;
siNiOx.scatteringLength = (0.00000554 + 0.00000585) / 2.0;
siNiOx.trueAbsLength = 2.27931868269305E-09;
siNiOx.incAbsLength = 4.74626235093697E-09;
siNiOx.thickness = 42.0;
siNiOx.interfaceWidth = 16.5;
siNiOx.interfaceWidth = 7.0 * 2.35;

// SiOx
Slab si = new Slab();
si.scatteringLength = 2.070e-6;
si.trueAbsLength = 4.75e-11;
si.incAbsLength = 2.0e-12;
si.trueAbsLength = 4.74981478870069E-11;
si.incAbsLength = 1.99769988072137E-12;
si.thickness = 100.0;
si.interfaceWidth = 17.5;

// Create the slab list
Slab [] slabs = {air,niOx,ni,siNiOx,si};
Slab[] slabs = { air, niOx, ni, siNiOx, si };

// Create the test arrays
double[] zInt = new double[ReflectivityCalculator.maxRoughSize];
double[] rufInt = new double[ReflectivityCalculator.maxRoughSize];

// Get the interfacial profile
int numRough = 41;
calculator.getInterfacialProfile(numRough, zInt, rufInt);

// Generate the tiles
Tile[] genTiles = calculator.generateTiles(slabs,numRough,zInt,rufInt);

Tile[] genTiles = calculator.generateTiles(slabs, numRough, zInt,
rufInt);

// Load the reference tiles
Form form = reader.read(project.getFile("getSpecRefSqrdMod_q841.csv"));
ListComponent<String[]> tileLines = (ListComponent<String[]>) form
.getComponent(1);
Tile[] refTiles = loadTiles(tileLines);
assertEquals(173, refTiles.length);

// Check the generated tiles against the reference data
assertEquals(refTiles.length,genTiles.length);
assertEquals(refTiles.length, genTiles.length);
for (int i = 0; i < refTiles.length; i++) {
System.out.println("Tile = " + i);
// Scattering length
assertEquals(refTiles[i].scatteringLength,
genTiles[i].scatteringLength,
Math.abs(refTiles[i].scatteringLength * tol));
// True absorption cross section
assertEquals(refTiles[i].trueAbsLength, genTiles[i].trueAbsLength,
Math.abs(refTiles[i].trueAbsLength * tol));
// Incoherent absorption cross section
assertEquals(refTiles[i].incAbsLength, genTiles[i].incAbsLength,
Math.abs(refTiles[i].incAbsLength * tol));
// Thickness
assertEquals(refTiles[i].thickness, genTiles[i].thickness,
Math.abs(refTiles[i].thickness * tol));
}
System.out.println(refTiles.length + " " + genTiles.length);

fail();

return;
}

}

0 comments on commit d9ddc43

Please sign in to comment.