Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP save mko files during simulations and create avg PSD file at the end #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/basic/io/Restart.java
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
24 changes: 22 additions & 2 deletions src/kineticMonteCarlo/kmcCore/growth/AbstractGrowthKmc.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/kineticMonteCarlo/simulation/AbstractSimulation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/main/PsdFromSurfaces.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down