minor fixes. Updated libraries
This commit is contained in:
parent
b768fe6186
commit
42ffb6c8c3
@ -4,7 +4,10 @@
|
|||||||
*/
|
*/
|
||||||
package hep.dataforge.trapping;
|
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.Rotation;
|
||||||
import org.apache.commons.math3.geometry.euclidean.threed.SphericalCoordinates;
|
import org.apache.commons.math3.geometry.euclidean.threed.SphericalCoordinates;
|
||||||
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
|
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
|
||||||
@ -52,15 +55,14 @@ public class ElectronTrappingSimulator {
|
|||||||
|
|
||||||
if (initTheta < this.thetaPinch) {
|
if (initTheta < this.thetaPinch) {
|
||||||
if (generator.heads()) {
|
if (generator.heads()) {
|
||||||
return new SimulaionResult(EndState.PASS, initEnergy, initTheta, 0);
|
return new SimulaionResult(EndState.PASS, initEnergy, initTheta, initTheta, 0);
|
||||||
} else {
|
} else {
|
||||||
return new SimulaionResult(EndState.REJECTED, initEnergy, initTheta, 0);
|
return new SimulaionResult(EndState.REJECTED, initEnergy, initTheta, initTheta, 0);
|
||||||
}
|
}
|
||||||
} else if(initTheta<this.thetaTransport){
|
} 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 E = initEnergy;
|
||||||
double theta = initTheta;
|
double theta = initTheta;
|
||||||
int colNum = 0;
|
int colNum = 0;
|
||||||
@ -73,7 +75,6 @@ public class ElectronTrappingSimulator {
|
|||||||
DoubleValue dE = new DoubleValue(0);
|
DoubleValue dE = new DoubleValue(0);
|
||||||
DoubleValue dTheta = new DoubleValue(0);
|
DoubleValue dTheta = new DoubleValue(0);
|
||||||
|
|
||||||
|
|
||||||
//Вычисляем сечения и нормируем их на полное сечение
|
//Вычисляем сечения и нормируем их на полное сечение
|
||||||
double sigmaIon = Scatter.sigmaion(E);
|
double sigmaIon = Scatter.sigmaion(E);
|
||||||
double sigmaEl = Scatter.sigmael(E);
|
double sigmaEl = Scatter.sigmael(E);
|
||||||
@ -130,7 +131,11 @@ public class ElectronTrappingSimulator {
|
|||||||
state = EndState.LOWENERGY;
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +150,7 @@ public class ElectronTrappingSimulator {
|
|||||||
//Генерируем случайный фи
|
//Генерируем случайный фи
|
||||||
double phi = generator.next() * 2 * Math.PI;
|
double phi = generator.next() * 2 * Math.PI;
|
||||||
//Создаем начальный вектор в сферических координатах
|
//Создаем начальный вектор в сферических координатах
|
||||||
SphericalCoordinates init = new SphericalCoordinates(1, 0, theta+dTheta);
|
SphericalCoordinates init = new SphericalCoordinates(1, 0, theta + dTheta);
|
||||||
// Задаем вращение относительно оси, перпендикулярной исходному вектору
|
// Задаем вращение относительно оси, перпендикулярной исходному вектору
|
||||||
SphericalCoordinates rotate = new SphericalCoordinates(1, 0, theta);
|
SphericalCoordinates rotate = new SphericalCoordinates(1, 0, theta);
|
||||||
// поворачиваем исходный вектор на dTheta
|
// поворачиваем исходный вектор на dTheta
|
||||||
@ -153,9 +158,8 @@ public class ElectronTrappingSimulator {
|
|||||||
|
|
||||||
Vector3D result = rot.applyTo(init.getCartesian());
|
Vector3D result = rot.applyTo(init.getCartesian());
|
||||||
|
|
||||||
// assert Vector3D.angle(result, rotate.getCartesian()) == dTheta;
|
// assert Vector3D.angle(result, rotate.getCartesian()) == dTheta;
|
||||||
return Math.acos(result.getZ());
|
return Math.acos(result.getZ());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -165,17 +169,16 @@ public class ElectronTrappingSimulator {
|
|||||||
* @param num
|
* @param num
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public ArrayList<SimulaionResult> simulateAll(double E, int num) {
|
public List<SimulaionResult> simulateAll(double E, int num) {
|
||||||
ArrayList<SimulaionResult> res = new ArrayList();
|
|
||||||
double theta;
|
|
||||||
|
|
||||||
System.out.printf("%nStarting sumulation with initial energy %g and %d electrons.%n%n", E, 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);
|
return Stream.generate(() -> getRandomTheta()).limit(num).parallel()
|
||||||
theta = this.getRandomTheta();
|
.map(theta -> simulateOne(E, theta))
|
||||||
res.add(this.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) {
|
private double normalizeTheta(double theta) {
|
||||||
@ -201,14 +204,16 @@ public class ElectronTrappingSimulator {
|
|||||||
|
|
||||||
public class SimulaionResult {
|
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.state = state;
|
||||||
this.E = E;
|
this.E = E;
|
||||||
this.theta = theta;
|
this.theta = theta;
|
||||||
|
this.initTheta = initTheta;
|
||||||
this.collisionNumber = collisionNumber;
|
this.collisionNumber = collisionNumber;
|
||||||
}
|
}
|
||||||
public EndState state;
|
public EndState state;
|
||||||
public double E;
|
public double E;
|
||||||
|
public double initTheta;
|
||||||
public double theta;
|
public double theta;
|
||||||
public int collisionNumber;
|
public int collisionNumber;
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,8 @@ package hep.dataforge.trapping;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintStream;
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hello world!
|
* Hello world!
|
||||||
@ -13,10 +12,10 @@ import java.util.Iterator;
|
|||||||
public class Trapping {
|
public class Trapping {
|
||||||
|
|
||||||
public static void main(String[] args) throws FileNotFoundException {
|
public static void main(String[] args) throws FileNotFoundException {
|
||||||
PrintWriter out = null;
|
PrintStream out = null;
|
||||||
if ((args.length > 0) && (args[0] != null)) {
|
if ((args.length > 0) && (args[0] != null)) {
|
||||||
File file = new File(args[0]);
|
File file = new File(args[0]);
|
||||||
out = new PrintWriter(file);
|
out = new PrintStream(file);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -33,18 +32,15 @@ public class Trapping {
|
|||||||
int rejected = 0;
|
int rejected = 0;
|
||||||
int lowE = 0;
|
int lowE = 0;
|
||||||
|
|
||||||
ArrayList<ElectronTrappingSimulator.SimulaionResult> results = simulator.simulateAll(E, 50000);
|
List<ElectronTrappingSimulator.SimulaionResult> results = simulator.simulateAll(E, 500000);
|
||||||
|
|
||||||
for (Iterator<ElectronTrappingSimulator.SimulaionResult> it = results.iterator(); it.hasNext();) {
|
|
||||||
ElectronTrappingSimulator.SimulaionResult res = it.next();
|
|
||||||
|
|
||||||
|
for (ElectronTrappingSimulator.SimulaionResult res : results) {
|
||||||
if (out != null) {
|
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) {
|
switch (res.state) {
|
||||||
|
|
||||||
case ACCEPTED:
|
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++;
|
accepted++;
|
||||||
break;
|
break;
|
||||||
case LOWENERGY:
|
case LOWENERGY:
|
||||||
|
@ -4,8 +4,9 @@
|
|||||||
*/
|
*/
|
||||||
package hep.dataforge.trapping;
|
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.RandomGenerator;
|
||||||
|
import org.apache.commons.math3.random.SynchronizedRandomGenerator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -15,7 +16,7 @@ public class TrappingRandomGenerator {
|
|||||||
RandomGenerator generator;
|
RandomGenerator generator;
|
||||||
|
|
||||||
public TrappingRandomGenerator() {
|
public TrappingRandomGenerator() {
|
||||||
this.generator = new JDKRandomGenerator();
|
this.generator = new SynchronizedRandomGenerator(new MersenneTwister());
|
||||||
}
|
}
|
||||||
|
|
||||||
public TrappingRandomGenerator(RandomGenerator generator) {
|
public TrappingRandomGenerator(RandomGenerator generator) {
|
||||||
|
Loading…
Reference in New Issue
Block a user