From 035c1bc0a0bccf9dd0099b415d089eb55086e690 Mon Sep 17 00:00:00 2001 From: Julen Date: Wed, 22 Apr 2020 15:51:00 +0200 Subject: [PATCH 1/2] Save mko files during simulations --- src/basic/io/Restart.java | 5 ++++ .../kmcCore/growth/AbstractGrowthKmc.java | 24 +++++++++++++++++-- .../simulation/AbstractSimulation.java | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/basic/io/Restart.java b/src/basic/io/Restart.java index d2fcb813..daa3efe3 100644 --- a/src/basic/io/Restart.java +++ b/src/basic/io/Restart.java @@ -238,6 +238,11 @@ public void writeSurfaceBinary(int dimensions, int[] sizes, float[][] data, int String fileName = format("%ssurface%03d.mko", folder, simulationNumber); RestartLow.writeLowBinary(dimensions, sizes, data, fileName); } + + public void writeSurfaceBinary(int dimensions, int[] sizes, float[][] data, int simulationNumber, int coverage) { + String fileName = format("%ssurface%d0%02d.mko", folder, simulationNumber, coverage); + RestartLow.writeLowBinary(dimensions, sizes, data, fileName); + } public void writeSurfaceBinary2D(float[][] data, int simulationNumber) { int sizes[] = new int[2]; diff --git a/src/kineticMonteCarlo/kmcCore/growth/AbstractGrowthKmc.java b/src/kineticMonteCarlo/kmcCore/growth/AbstractGrowthKmc.java index 23f25c7e..3d7a314e 100644 --- a/src/kineticMonteCarlo/kmcCore/growth/AbstractGrowthKmc.java +++ b/src/kineticMonteCarlo/kmcCore/growth/AbstractGrowthKmc.java @@ -22,6 +22,7 @@ import basic.Parser; import basic.io.OutputType; import basic.io.Restart; +import basic.io.OutputType.formatFlag; import kineticMonteCarlo.site.AbstractGrowthSite; import kineticMonteCarlo.kmcCore.growth.devitaAccelerator.DevitaAccelerator; import kineticMonteCarlo.site.ModifiedBuffer; @@ -34,6 +35,7 @@ import javafx.geometry.Point3D; import static kineticMonteCarlo.site.AbstractSite.TERRACE; import kineticMonteCarlo.unitCell.AbstractGrowthUc; +import utils.MathUtils; import utils.StaticRandom; import utils.list.LinearList; @@ -93,9 +95,11 @@ public abstract class AbstractGrowthKmc extends AbstractSurfaceKmc { private long simulatedSteps; private double sumProbabilities; private Restart restart; + private Parser parser; public AbstractGrowthKmc(Parser parser) { super(parser); + this.parser = parser; simulationNumber = 0; justCentralFlake = parser.justCentralFlake(); periodicSingleFlake = parser.isPeriodicSingleFlake(); @@ -475,8 +479,24 @@ private void printData(Integer coverage) { printCoverage = getCoverage(); } if (printCoverage > 0.01 && (int) (printCoverage * 100) % 5 == 0) { //only write when is bigger than 1% and multiple of %5 - int surfaceNumber = 1000 * simulationNumber + (int) (getCoverage() * 100); - restart.writeSvg(surfaceNumber, getLattice(), true); + int surfaceNumber = 1000 * simulationNumber + (int) (getCoverage() * 100); + if (parser.getOutputFormats().contains(formatFlag.SVG)) { + restart.writeSvg(surfaceNumber, getLattice(), true); + } + if (parser.getOutputFormats().contains(formatFlag.MKO) && parser.doPsd()) { + + int[] surfaceSizes = new int[2]; + // More precise (more points) the PSD better precision we get + surfaceSizes[0] = (int) (parser.getCartSizeX() * parser.getPsdScale()); + surfaceSizes[1] = (int) (parser.getCartSizeY() * parser.getPsdScale()); + int[] extentSizes = new int[2]; + extentSizes[0] = (int) (surfaceSizes[0] * parser.getPsdExtend()); + extentSizes[1] = (int) (surfaceSizes[1] * parser.getPsdExtend()); + float[][] sampledSurface = getSampledSurface(surfaceSizes[0], surfaceSizes[1]); + float[][] extentSurface = MathUtils.increaseEmptyArea(sampledSurface, parser.getPsdExtend()); + restart.writeSurfaceBinary(2, extentSizes, extentSurface, simulationNumber, (int) (printCoverage * 100)); + } + } restart.writeExtraOutput(lattice, printCoverage, nucleations, getTime(), (double) (depositionRatePerSite * freeArea), getList().getDiffusionProbability(), simulatedSteps, sumProbabilities); diff --git a/src/kineticMonteCarlo/simulation/AbstractSimulation.java b/src/kineticMonteCarlo/simulation/AbstractSimulation.java index 34ca6e62..8ec4af42 100644 --- a/src/kineticMonteCarlo/simulation/AbstractSimulation.java +++ b/src/kineticMonteCarlo/simulation/AbstractSimulation.java @@ -300,7 +300,7 @@ void printOutput() { restart.writeCatalysisAdsorptionDataText(simulations, data); } if (parser.getOutputFormats().contains(formatFlag.MKO)) { - restart.writeSurfaceBinary(2, extentSizes, extentSurface, simulations); + restart.writeSurfaceBinary(2, extentSizes, extentSurface, simulations,(int) (coverage[0] * 100)); } if (parser.getOutputFormats().contains(formatFlag.TXT)) { restart.writeSurfaceText2D(2, extentSizes, extentSurface, simulations); From 651086e98103ac06e4425ca6854460eedd3739b6 Mon Sep 17 00:00:00 2001 From: Julen Date: Wed, 22 Apr 2020 15:54:15 +0200 Subject: [PATCH 2/2] Create average PSD file when simulations are finished --- src/kineticMonteCarlo/simulation/AbstractSimulation.java | 4 ++-- src/main/PsdFromSurfaces.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/kineticMonteCarlo/simulation/AbstractSimulation.java b/src/kineticMonteCarlo/simulation/AbstractSimulation.java index 8ec4af42..c96a4cc4 100644 --- a/src/kineticMonteCarlo/simulation/AbstractSimulation.java +++ b/src/kineticMonteCarlo/simulation/AbstractSimulation.java @@ -32,6 +32,7 @@ import java.util.logging.Logger; import kineticMonteCarlo.kmcCore.AbstractKmc; import kineticMonteCarlo.kmcCore.catalysis.AbstractCatalysisKmc; +import main.PsdFromSurfaces; import ratesLibrary.IRates; import utils.MathUtils; import utils.StaticRandom; @@ -175,13 +176,12 @@ public void doSimulation() { } else { // simulate until a given coverage or size (single flake) kmc.simulate(); } - printOutput(); totalTime += kmc.getTime(); islands += countIslands(); gyradius += getGyradius(); } - + PsdFromSurfaces pfs = new PsdFromSurfaces(parser, restart.getFolder()); printFooter(); doPsd(); } diff --git a/src/main/PsdFromSurfaces.java b/src/main/PsdFromSurfaces.java index 47d38cbc..2718a62d 100644 --- a/src/main/PsdFromSurfaces.java +++ b/src/main/PsdFromSurfaces.java @@ -33,7 +33,7 @@ */ public class PsdFromSurfaces { - public PsdFromSurfaces(Parser parser) { + public PsdFromSurfaces(Parser parser, String restartFolderName) { System.out.println("This is a utility of morphokinetics program"); String surfaceFileName; boolean showGui; @@ -47,7 +47,7 @@ public PsdFromSurfaces(Parser parser) { showGui = parser.withGui() && parser.visualise(); doTent = !parser.getSurfaceType().equals("plane"); - Restart restart = new Restart("./"); + Restart restart = new Restart(restartFolderName); int[] sizes = null; float[][] surface = null; PsdSignature2D psd = null;