From ca59a325f38c4421d3ec17131f62b62d446cd78c Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 11 Jan 2017 14:49:10 +0300 Subject: [PATCH] Minor accessibility fixes --- build.gradle | 36 +++++++++---------- .../numass/trapping/SimulationManager.java | 34 +++++++++++++++--- .../java/inr/numass/trapping/Trapping.java | 14 ++++---- 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/build.gradle b/build.gradle index a01dfec..e6295ce 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ apply plugin: 'java' -apply plugin: 'c' +//apply plugin: 'c' apply plugin: 'idea' apply plugin: 'application' @@ -42,20 +42,20 @@ task runTrap(type: JavaExec) { // native component -model { - components { - 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" - } - - } -} +//model { +// components { +// 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 bc04b3b..46145f5 100644 --- a/src/main/java/inr/numass/trapping/SimulationManager.java +++ b/src/main/java/inr/numass/trapping/SimulationManager.java @@ -20,14 +20,34 @@ public class SimulationManager { RandomGenerator generator = new JDKRandomGenerator(); Simulator simulator = new Simulator(); + private double initialE = 18000; + private double range = 4000; + private PrintStream output = System.out; private PrintStream statisticOutput = System.out; + private Predicate reportFileter = (res) -> res.state == Simulator.EndState.ACCEPTED; +// public SimulationManager withParameters(double bSource, double bTransport, double bPinch, double initialE, double energyRange) { +// this.simulator = new Simulator(bSource, bTransport, bPinch, initialE - energyRange); +// this.initialE = initialE; +// return this; +// } - public SimulationManager withParameters(double bSource, double bTransport, double bPinch, double initialE, double energyRange) { - this.simulator = new Simulator(bSource, bTransport, bPinch, initialE - energyRange); + public SimulationManager withInitialE(double initialE){ this.initialE = initialE; + simulator.setELow(initialE-range); + return this; + } + + public SimulationManager withRange(double range){ + this.range = range; + simulator.setELow(initialE-range); + return this; + } + + public SimulationManager withFields(double bSource, double bTransport, double bPinch){ + this.simulator.setFields(bSource,bTransport,bPinch); return this; } @@ -63,6 +83,11 @@ public class SimulationManager { return this; } + public SimulationManager withReportFilter(Predicate filter) { + this.reportFileter = filter; + return this; + } + /** * Set field map as function * @@ -93,7 +118,7 @@ public class SimulationManager { * @param density * @return */ - public SimulationManager withDensity(double density) { + public SimulationManager withGasDensity(double density) { this.simulator.setGasDensity(density); return this; } @@ -106,14 +131,13 @@ public class SimulationManager { */ public synchronized Counter simulateAll(int num) { Counter counter = new Counter(); - Predicate reportIf = (res) -> res.state == Simulator.EndState.ACCEPTED; System.out.printf("%nStarting sumulation with initial energy %g and %d electrons.%n%n", initialE, num); output.printf("%s\t%s\t%s\t%s\t%s\t%s%n", "E", "theta", "theta_start", "colNum", "L", "state"); Stream.generate(() -> getRandomTheta()).limit(num).parallel() .forEach((theta) -> { double initZ = (generator.nextDouble() - 0.5) * Simulator.SOURCE_LENGTH; Simulator.SimulationResult res = simulator.simulate(initialE, theta, initZ); - if (reportIf.test(res)) { + if (reportFileter.test(res)) { if (output != null) { printOne(output, res); } diff --git a/src/main/java/inr/numass/trapping/Trapping.java b/src/main/java/inr/numass/trapping/Trapping.java index 235eefa..a22bf8f 100644 --- a/src/main/java/inr/numass/trapping/Trapping.java +++ b/src/main/java/inr/numass/trapping/Trapping.java @@ -1,27 +1,27 @@ package inr.numass.trapping; -import java.io.FileNotFoundException; import java.io.IOException; import java.time.Duration; import java.time.Instant; +import java.util.function.Predicate; public class Trapping { public static void main(String[] args) throws IOException { -// new SimulationManager().withParameters(0.6, 3.7, 7.2, 18000d, 4000).simulateAll((int) 1e6); double[] z = {-1.736, -1.27, -0.754, -0.238, 0.278, 0.794, 1.31, 1.776}; double[] b = {3.70754, 0.62786, 0.60474, 0.60325, 0.60333, 0.60503, 0.6285, 3.70478}; - System.out.println("Press any key to start..."); - System.in.read(); +// System.out.println("Press any key to start..."); +// System.in.read(); Instant startTime = Instant.now(); System.out.printf("Starting at %s%n%n", startTime.toString()); new SimulationManager() - .withParameters(0.6, 3.7, 4.84, 18000d, 4000) .withOutputFile("D:\\Work\\Numass\\trapping\\test1.out") + .withFields(0.6, 3.7, 7.2) // .withFieldMap(z, b) - .withDensity(1e19) + .withGasDensity(1e19) // per m^3 + .withReportFilter(res -> true) .simulateAll((int) 1e6); Instant finishTime = Instant.now(); System.out.printf("%nFinished at %s%n", finishTime.toString()); - System.out.printf("Calculation took %s%n", Duration.between(startTime,finishTime).toString()); + System.out.printf("Calculation took %s%n", Duration.between(startTime, finishTime).toString()); } }