diff --git a/build.gradle b/build.gradle index 605d6ad..a01dfec 100644 --- a/build.gradle +++ b/build.gradle @@ -47,9 +47,15 @@ model { scatter(NativeLibrarySpec) } toolChains { + visualCpp(VisualCpp) { + // Specify the installDir if Visual Studio cannot be located + // installDir "C:/Apps/Microsoft Visual Studio 10.0" + installDir "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0" + } gcc(Gcc) { // Uncomment to use a GCC install that is not in the PATH // path "/usr/bin/gcc" } + } } diff --git a/src/main/java/inr/numass/trapping/SimulationManager.java b/src/main/java/inr/numass/trapping/SimulationManager.java index 207121f..bc04b3b 100644 --- a/src/main/java/inr/numass/trapping/SimulationManager.java +++ b/src/main/java/inr/numass/trapping/SimulationManager.java @@ -131,13 +131,16 @@ public class SimulationManager { } private void printStatistics(Counter counter) { + output.println(); + output.println("***RESULT***"); output.printf("The total number of events is %d.%n%n", counter.count); - output.printf("The spectrometer acceptance angle is %g.%n", simulator.thetaPinch * 180 / Math.PI); output.printf("The transport reflection angle is %g.%n", simulator.thetaTransport * 180 / Math.PI); output.printf("The starting energy is %g.%n", initialE); - output.printf("The lower energy boundary is %g.%n%n", simulator.eLow); + output.printf("The lower energy boundary is %g.%n", simulator.eLow); + output.printf("The source density is %g.%n", simulator.gasDensity); + output.println(); output.printf("The total number of ACCEPTED events is %d.%n", counter.accepted); output.printf("The total number of PASS events is %d.%n", counter.pass); output.printf("The total number of REJECTED events is %d.%n", counter.rejected); diff --git a/src/main/java/inr/numass/trapping/Simulator.java b/src/main/java/inr/numass/trapping/Simulator.java index ad8d987..b90ead9 100644 --- a/src/main/java/inr/numass/trapping/Simulator.java +++ b/src/main/java/inr/numass/trapping/Simulator.java @@ -29,7 +29,7 @@ public class Simulator { double eLow = 14000d;//default value double thetaTransport = 24.107064 / 180 * Math.PI;// default value double thetaPinch = 19.481097 / 180 * Math.PI;// default value - double gasDensity = 5e18;// m^-3 + double gasDensity = 5e20;// m^-3 double bSource = 0.6; private UnivariateFunction magneticField; @@ -147,7 +147,7 @@ public class Simulator { // if magnetic field not defined, consider it to be uniform and equal bSource if (magneticField == null) { double deltaZ = deltaL * cos(pos.theta); // direction already included in cos(theta) - double z0 = pos.z; +// double z0 = pos.z; pos.addZ(deltaZ); pos.l += deltaL; @@ -375,12 +375,11 @@ public class Simulator { double addZ(double dZ) { this.z += dZ; while (abs(this.z) > SOURCE_LENGTH / 2d && !isFinished()) { - checkEndState(); - if (!isFinished()) { - flip(); - } // reflecting from back wall if (z < 0) { + if (theta >= PI - thetaTransport) { + setEndState(EndState.REJECTED); + } if (isFinished()) { z = -SOURCE_LENGTH / 2d; } else { @@ -388,6 +387,14 @@ public class Simulator { z = -SOURCE_LENGTH - z; } } else { + if (theta < thetaPinch) { + if (colNum == 0) { + //counting pass electrons + setEndState(EndState.PASS); + } else { + setEndState(EndState.ACCEPTED); + } + } if (isFinished()) { z = SOURCE_LENGTH / 2d; } else { @@ -395,36 +402,42 @@ public class Simulator { z = SOURCE_LENGTH - z; } } + if (!isFinished()) { + flip(); + } } return z; } - /** - * Check if this position is an end state and apply it if necessary. Does not check z position. - * - * @return - */ - private void checkEndState() { - //accepted by spectrometer - if (theta < thetaPinch) { - if (colNum == 0) { - //counting pass electrons - setEndState(EndState.PASS); - } else { - setEndState(EndState.ACCEPTED); - } - } - - //through the rear magnetic pinch - if (theta >= PI - thetaTransport) { - setEndState(EndState.REJECTED); - } - } +// /** +// * Check if this position is an end state and apply it if necessary. Does not check z position. +// * +// * @return +// */ +// private void checkEndState() { +// //accepted by spectrometer +// if (theta < thetaPinch) { +// if (colNum == 0) { +// //counting pass electrons +// setEndState(EndState.PASS); +// } else { +// setEndState(EndState.ACCEPTED); +// } +// } +// +// //through the rear magnetic pinch +// if (theta >= PI - thetaTransport) { +// setEndState(EndState.REJECTED); +// } +// } /** * Reverse electron direction */ void flip() { + if(theta<0||theta>PI){ + throw new Error(); + } theta = PI - theta; } diff --git a/src/main/java/inr/numass/trapping/Trapping.java b/src/main/java/inr/numass/trapping/Trapping.java index dd357bf..235eefa 100644 --- a/src/main/java/inr/numass/trapping/Trapping.java +++ b/src/main/java/inr/numass/trapping/Trapping.java @@ -15,10 +15,10 @@ public class Trapping { Instant startTime = Instant.now(); System.out.printf("Starting at %s%n%n", startTime.toString()); new SimulationManager() - .withParameters(0.6, 3.7, 4.84, 14000d, 4000) - .withOutputFile("D:\\Work\\Numass\\trapping\\trap 14, pinch 100A.out") + .withParameters(0.6, 3.7, 4.84, 18000d, 4000) + .withOutputFile("D:\\Work\\Numass\\trapping\\test1.out") // .withFieldMap(z, b) -// .withDensity(5e20) + .withDensity(1e19) .simulateAll((int) 1e6); Instant finishTime = Instant.now(); System.out.printf("%nFinished at %s%n", finishTime.toString()); diff --git a/src/scatter/c/scatter.c b/src/scatter/c/scatter.c index edc65fd..20b740a 100644 --- a/src/scatter/c/scatter.c +++ b/src/scatter/c/scatter.c @@ -11,6 +11,7 @@ */ //#include "scatter.h" +#define _USE_MATH_DEFINES // for C #include #include