minor fixes. Updated libraries

This commit is contained in:
darksnake 2016-03-30 17:01:27 +03:00
parent b768fe6186
commit 42ffb6c8c3
3 changed files with 38 additions and 36 deletions

View File

@ -4,7 +4,10 @@
*/
package hep.dataforge.trapping;
import java.util.ArrayList;
import java.io.PrintStream;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
import org.apache.commons.math3.geometry.euclidean.threed.SphericalCoordinates;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
@ -52,15 +55,14 @@ public class ElectronTrappingSimulator {
if (initTheta < this.thetaPinch) {
if (generator.heads()) {
return new SimulaionResult(EndState.PASS, initEnergy, initTheta, 0);
return new SimulaionResult(EndState.PASS, initEnergy, initTheta, initTheta, 0);
} else {
return new SimulaionResult(EndState.REJECTED, initEnergy, initTheta, 0);
return new SimulaionResult(EndState.REJECTED, initEnergy, initTheta, initTheta, 0);
}
} else if (initTheta < this.thetaTransport) {
return new SimulaionResult(EndState.REJECTED, initEnergy, initTheta, 0);
return new SimulaionResult(EndState.REJECTED, initEnergy, initTheta, initTheta, 0);
}
double E = initEnergy;
double theta = initTheta;
int colNum = 0;
@ -73,7 +75,6 @@ public class ElectronTrappingSimulator {
DoubleValue dE = new DoubleValue(0);
DoubleValue dTheta = new DoubleValue(0);
//Вычисляем сечения и нормируем их на полное сечение
double sigmaIon = Scatter.sigmaion(E);
double sigmaEl = Scatter.sigmael(E);
@ -130,7 +131,11 @@ public class ElectronTrappingSimulator {
state = EndState.LOWENERGY;
}
}
return new SimulaionResult(state, E, theta, colNum);
SimulaionResult res = new SimulaionResult(state, E, theta, initTheta, colNum);
if (state == EndState.ACCEPTED) {
printOne(System.out, res);
}
return res;
}
@ -155,7 +160,6 @@ public class ElectronTrappingSimulator {
// assert Vector3D.angle(result, rotate.getCartesian()) == dTheta;
return Math.acos(result.getZ());
}
/**
@ -165,17 +169,16 @@ public class ElectronTrappingSimulator {
* @param num
* @return
*/
public ArrayList<SimulaionResult> simulateAll(double E, int num) {
ArrayList<SimulaionResult> res = new ArrayList();
double theta;
public List<SimulaionResult> simulateAll(double E, int num) {
System.out.printf("%nStarting sumulation with initial energy %g and %d electrons.%n%n", E, num);
for (int i = 0; i < num; i++) {
// System.out.printf("Running electron number %d", i);
theta = this.getRandomTheta();
res.add(this.simulateOne(E, theta));
return Stream.generate(() -> getRandomTheta()).limit(num).parallel()
.map(theta -> simulateOne(E, theta))
.collect(Collectors.toList());
}
return res;
public static void printOne(PrintStream out, SimulaionResult res) {
out.printf("%g\t%g\t%g\t%d\t%s%n", res.E, res.theta * 180 / Math.PI, res.initTheta * 180 / Math.PI, res.collisionNumber, res.state.toString());
}
private double normalizeTheta(double theta) {
@ -201,14 +204,16 @@ public class ElectronTrappingSimulator {
public class SimulaionResult {
public SimulaionResult(EndState state, double E, double theta, int collisionNumber) {
public SimulaionResult(EndState state, double E, double theta, double initTheta, int collisionNumber) {
this.state = state;
this.E = E;
this.theta = theta;
this.initTheta = initTheta;
this.collisionNumber = collisionNumber;
}
public EndState state;
public double E;
public double initTheta;
public double theta;
public int collisionNumber;
}

View File

@ -2,9 +2,8 @@ package hep.dataforge.trapping;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.io.PrintStream;
import java.util.List;
/**
* Hello world!
@ -13,10 +12,10 @@ import java.util.Iterator;
public class Trapping {
public static void main(String[] args) throws FileNotFoundException {
PrintWriter out = null;
PrintStream out = null;
if ((args.length > 0) && (args[0] != null)) {
File file = new File(args[0]);
out = new PrintWriter(file);
out = new PrintStream(file);
} else {
}
@ -33,18 +32,15 @@ public class Trapping {
int rejected = 0;
int lowE = 0;
ArrayList<ElectronTrappingSimulator.SimulaionResult> results = simulator.simulateAll(E, 50000);
for (Iterator<ElectronTrappingSimulator.SimulaionResult> it = results.iterator(); it.hasNext();) {
ElectronTrappingSimulator.SimulaionResult res = it.next();
List<ElectronTrappingSimulator.SimulaionResult> results = simulator.simulateAll(E, 500000);
for (ElectronTrappingSimulator.SimulaionResult res : results) {
if (out != null) {
out.printf("%g\t%g\t%d\t%s%n", res.E, res.theta * 180 / Math.PI, res.collisionNumber, res.state.toString());
ElectronTrappingSimulator.printOne(System.out, res);
}
switch (res.state) {
case ACCEPTED:
System.out.printf("%g\t%g\t%d\t%s%n", res.E, res.theta * 180 / Math.PI, res.collisionNumber, res.state.toString());
// ElectronTrappingSimulator.printOne(System.out, res);
accepted++;
break;
case LOWENERGY:

View File

@ -4,8 +4,9 @@
*/
package hep.dataforge.trapping;
import org.apache.commons.math3.random.JDKRandomGenerator;
import org.apache.commons.math3.random.MersenneTwister;
import org.apache.commons.math3.random.RandomGenerator;
import org.apache.commons.math3.random.SynchronizedRandomGenerator;
/**
*
@ -15,7 +16,7 @@ public class TrappingRandomGenerator {
RandomGenerator generator;
public TrappingRandomGenerator() {
this.generator = new JDKRandomGenerator();
this.generator = new SynchronizedRandomGenerator(new MersenneTwister());
}
public TrappingRandomGenerator(RandomGenerator generator) {