Translate russian captions.
This commit is contained in:
parent
c4f251a148
commit
656f16af70
@ -26,7 +26,8 @@ class SimulationManager() {
|
|||||||
/**
|
/**
|
||||||
* A supplier for random generator. Each track has its own generator
|
* A supplier for random generator. Each track has its own generator
|
||||||
*/
|
*/
|
||||||
var generatorFactory: (Long) -> UniformRandomProvider = { RandomSource.create(RandomSource.MT_64, seedGenerator.nextInt()) }
|
var generatorFactory: (Long) -> UniformRandomProvider =
|
||||||
|
{ RandomSource.create(RandomSource.MT_64, seedGenerator.nextInt()) }
|
||||||
var reportFilter: (Simulator.SimulationResult) -> Boolean = { it.state == Simulator.EndState.ACCEPTED }
|
var reportFilter: (Simulator.SimulationResult) -> Boolean = { it.state == Simulator.EndState.ACCEPTED }
|
||||||
|
|
||||||
var initialE = 18000.0
|
var initialE = 18000.0
|
||||||
@ -107,26 +108,35 @@ class SimulationManager() {
|
|||||||
|
|
||||||
val outputPath = outputDirectory.toPath().resolve("$fileName.out")
|
val outputPath = outputDirectory.toPath().resolve("$fileName.out")
|
||||||
|
|
||||||
PrintStream(Files.newOutputStream(outputPath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)).use { output ->
|
PrintStream(
|
||||||
|
Files.newOutputStream(
|
||||||
|
outputPath,
|
||||||
|
StandardOpenOption.CREATE,
|
||||||
|
StandardOpenOption.TRUNCATE_EXISTING,
|
||||||
|
StandardOpenOption.WRITE
|
||||||
|
)
|
||||||
|
).use { output ->
|
||||||
output.println("# " + header.replace("\n", "\n# "))//adding comment symbols
|
output.println("# " + header.replace("\n", "\n# "))//adding comment symbols
|
||||||
|
|
||||||
System.out.printf("%nStarting simulation with initial energy %g and %d electrons.%n%n", initialE, num.toLong())
|
System.out.printf("%nStarting simulation with initial energy %g and %d electrons.%n%n",
|
||||||
|
initialE,
|
||||||
|
num.toLong())
|
||||||
output.printf("%s\t%s\t%s\t%s\t%s\t%s\t%s%n", "id", "E", "theta", "theta_start", "colNum", "L", "state")
|
output.printf("%s\t%s\t%s\t%s\t%s\t%s\t%s%n", "id", "E", "theta", "theta_start", "colNum", "L", "state")
|
||||||
LongStream.rangeClosed(1, num.toLong()).parallel()
|
LongStream.rangeClosed(1, num.toLong()).parallel().mapToObj { id ->
|
||||||
.mapToObj { id ->
|
val generator = RandomGeneratorBridge(generatorFactory(id))
|
||||||
val generator = RandomGeneratorBridge(generatorFactory(id))
|
val theta = Math.acos(1 - 2 * generator.nextDouble())// from 0 to Pi
|
||||||
val theta = Math.acos(1 - 2 * generator.nextDouble())// from 0 to Pi
|
val z = (generator.nextDouble() - 0.5) * Simulator.SOURCE_LENGTH
|
||||||
val z = (generator.nextDouble() - 0.5) * Simulator.SOURCE_LENGTH
|
simulator.simulate(id, generator, initialE, theta, z).also { counter.count(it) }
|
||||||
simulator.simulate(id, generator, initialE, theta, z).also { counter.count(it) }
|
}.filter(reportFilter).forEach { res ->
|
||||||
}
|
printOne(output, res)
|
||||||
.filter(reportFilter)
|
}
|
||||||
.forEach { res ->
|
|
||||||
printOne(output, res)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val statisticsPath = outputDirectory.toPath().resolve("$fileName.stat")
|
val statisticsPath = outputDirectory.toPath().resolve("$fileName.stat")
|
||||||
PrintStream(Files.newOutputStream(statisticsPath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)).use {
|
PrintStream(Files.newOutputStream(statisticsPath,
|
||||||
|
StandardOpenOption.CREATE,
|
||||||
|
StandardOpenOption.TRUNCATE_EXISTING,
|
||||||
|
StandardOpenOption.WRITE)).use {
|
||||||
it.println(header + "\n")
|
it.println(header + "\n")
|
||||||
printStatistics(it, simulator, counter)
|
printStatistics(it, simulator, counter)
|
||||||
|
|
||||||
@ -155,7 +165,14 @@ class SimulationManager() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun printOne(out: PrintStream, res: Simulator.SimulationResult) {
|
private fun printOne(out: PrintStream, res: Simulator.SimulationResult) {
|
||||||
out.printf("%d\t%g\t%g\t%g\t%d\t%g\t%s%n", res.id, res.E, res.theta * 180 / Math.PI, res.initTheta * 180 / Math.PI, res.collisionNumber, res.l, res.state.toString())
|
out.printf("%d\t%g\t%g\t%g\t%d\t%g\t%s%n",
|
||||||
|
res.id,
|
||||||
|
res.E,
|
||||||
|
res.theta * 180 / Math.PI,
|
||||||
|
res.initTheta * 180 / Math.PI,
|
||||||
|
res.collisionNumber,
|
||||||
|
res.l,
|
||||||
|
res.state.toString())
|
||||||
out.flush()
|
out.flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,11 +29,10 @@ class Simulator(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
enum class EndState {
|
enum class EndState {
|
||||||
|
ACCEPTED, // escaped to the spectrometer
|
||||||
ACCEPTED, //трэппинговый электрон попал в аксептанс
|
REJECTED, // escaped to the rear side
|
||||||
REJECTED, //трэппинговый электрон вылетел через заднюю пробку
|
LOWENERGY, // energy below lower border
|
||||||
LOWENERGY, //потерял слишком много энергии
|
PASS, // Electron never trapped
|
||||||
PASS, //электрон никогда не запирался и прошел напрямую, нужно для нормировки
|
|
||||||
NONE
|
NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +44,7 @@ class Simulator(
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private fun scatter(pos: State): State {
|
private fun scatter(pos: State): State {
|
||||||
//Вычисляем сечения и нормируем их на полное сечение
|
//Computing cross-sections and normalizing them
|
||||||
var sigmaIon = Scatter.sigmaion(pos.e)
|
var sigmaIon = Scatter.sigmaion(pos.e)
|
||||||
var sigmaEl = Scatter.sigmael(pos.e)
|
var sigmaEl = Scatter.sigmael(pos.e)
|
||||||
var sigmaExc = Scatter.sigmaexc(pos.e)
|
var sigmaExc = Scatter.sigmaexc(pos.e)
|
||||||
@ -54,20 +53,19 @@ class Simulator(
|
|||||||
sigmaEl /= sigmaTotal
|
sigmaEl /= sigmaTotal
|
||||||
sigmaExc /= sigmaTotal
|
sigmaExc /= sigmaTotal
|
||||||
|
|
||||||
//проверяем нормировку
|
//Checking norming
|
||||||
assert(Precision.equals(sigmaEl + sigmaExc + sigmaIon, 1.0, 1e-2))
|
assert(Precision.equals(sigmaEl + sigmaExc + sigmaIon, 1.0, 1e-2))
|
||||||
|
|
||||||
val alpha = pos.generator.nextDouble()
|
val alpha = pos.generator.nextDouble()
|
||||||
|
|
||||||
val delta: Pair<Double, Double> = when {
|
val delta: Pair<Double, Double> = when {
|
||||||
alpha < sigmaEl -> Scatter.randomel(pos.e, pos.generator)// elastic
|
alpha < sigmaEl -> Scatter.randomel(pos.e, pos.generator) // elastic
|
||||||
alpha > sigmaEl + sigmaExc -> Scatter.randomion(pos.e, pos.generator)//ionization case
|
alpha > sigmaEl + sigmaExc -> Scatter.randomion(pos.e, pos.generator) //ionization case
|
||||||
else -> Scatter.randomexc(pos.e, pos.generator)//excitation case
|
else -> Scatter.randomexc(pos.e, pos.generator) //excitation case
|
||||||
}
|
}
|
||||||
|
|
||||||
//Обновляем значени угла и энергии независимо ни от чего
|
// updating energy and angle
|
||||||
pos.substractE(delta.first)
|
pos.substractE(delta.first)
|
||||||
//Изменение угла
|
|
||||||
pos.addTheta(delta.second / 180 * Math.PI)
|
pos.addTheta(delta.second / 180 * Math.PI)
|
||||||
|
|
||||||
return pos
|
return pos
|
||||||
@ -389,13 +387,13 @@ class Simulator(
|
|||||||
//Генерируем случайный фи
|
//Генерируем случайный фи
|
||||||
val phi = generator.nextDouble() * 2.0 * Math.PI
|
val phi = generator.nextDouble() * 2.0 * Math.PI
|
||||||
|
|
||||||
//change to real angles
|
// change to real angles
|
||||||
val realTheta = realTheta()
|
val realTheta = realTheta()
|
||||||
//Создаем начальный вектор в сферических координатах
|
// Initial vector in spherical coordinates
|
||||||
val init = SphericalCoordinates(1.0, 0.0, realTheta + dTheta)
|
val init = SphericalCoordinates(1.0, 0.0, realTheta + dTheta)
|
||||||
// Задаем вращение относительно оси, перпендикулярной исходному вектору
|
// Rotating on an axis perpendicular to the initial vector
|
||||||
val rotate = SphericalCoordinates(1.0, 0.0, realTheta)
|
val rotate = SphericalCoordinates(1.0, 0.0, realTheta)
|
||||||
// поворачиваем исходный вектор на dTheta
|
// Rotation the initial vector
|
||||||
val rot = Rotation(rotate.cartesian, phi, null)
|
val rot = Rotation(rotate.cartesian, phi, null)
|
||||||
|
|
||||||
val result = rot.applyTo(init.cartesian)
|
val result = rot.applyTo(init.cartesian)
|
||||||
|
@ -18,6 +18,9 @@ infix fun ClosedFloatingPointRange<Double>.step(step: Double): Sequence<Double>
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract cross-sections from the code
|
||||||
|
*/
|
||||||
fun main() {
|
fun main() {
|
||||||
|
|
||||||
val energies = ((1.0..20.0) step 0.2).toList() // energy in keV
|
val energies = ((1.0..20.0) step 0.2).toList() // energy in keV
|
||||||
|
29
src/main/kotlin/ru/inr/mass/trapping/simulateFullRange.kt
Normal file
29
src/main/kotlin/ru/inr/mass/trapping/simulateFullRange.kt
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package ru.inr.mass.trapping
|
||||||
|
|
||||||
|
import java.time.Duration
|
||||||
|
import java.time.Instant
|
||||||
|
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
//val z = doubleArrayOf(-1.736, -1.27, -0.754, -0.238, 0.278, 0.794, 1.31, 1.776)
|
||||||
|
//val b = doubleArrayOf(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();
|
||||||
|
|
||||||
|
val startTime = Instant.now()
|
||||||
|
System.out.printf("Starting at %s%n%n", startTime.toString())
|
||||||
|
|
||||||
|
SimulationManager().apply {
|
||||||
|
comment = "Out of the box cross-sections"
|
||||||
|
fileName = "trap-full-range"
|
||||||
|
setFields(0.6, 3.6, 7.2)
|
||||||
|
gasDensity = 1e19 // m^-3
|
||||||
|
initialE = 18500.0
|
||||||
|
range = 16000.0
|
||||||
|
}.simulateAll(1_000_001)
|
||||||
|
|
||||||
|
val finishTime = Instant.now()
|
||||||
|
System.out.printf("%nFinished at %s%n", finishTime.toString())
|
||||||
|
System.out.printf("Calculation took %s%n", Duration.between(startTime, finishTime).toString())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user