package initialconditions; import java.lang.*; import java.io.*; import main.BetterTokenizer; import main.Cell; import main.GeneralInput; public class ColumnIC extends InitialCondition { int pos=-1; public final boolean noiseAware = true; public ColumnIC() { super() ; } public ColumnIC(String n, float iv, int p) { super(); node = n; initValue = iv; pos = p; } public void setModel(Cell [] cells) { for(int i = 0; i < Cell.arrayHeight; i++) { float val = initValue; if(noiseLevel > 0.0f) { val += noiseLevel * (float)rng.nextGaussian(); if(val < 0.0f) val = 0.0f; } try { cells[(i*Cell.arrayWidth)+pos].setInitialValue(node, val); } catch(Exception e) { System.out.println(e.toString()); return; } } } public void setFrom(Cell [] cells, boolean takePresentValue) throws Exception { if(!takePresentValue) { initValue = cells[pos].getInitialValue(node); for(int i = 1; i < Cell.arrayHeight; i++) { if(initValue != cells[(i*Cell.arrayWidth)+pos].getInitialValue(node)) { throw new UnsuitableICException(); } } } else { initValue = cells[pos].nodePeek(node); for(int i = 1; i < Cell.arrayHeight; i++) { if(initValue != cells[(i*Cell.arrayWidth)+pos].nodePeek(node)) { throw new UnsuitableICException(); } } } } public void print() { System.out.println("Column of " + node + " = " + initValue + " in position " + pos + "; "); } protected void loadParameter(String info, BetterTokenizer tokenizer) throws Exception { if(info.equals("Column")) { GeneralInput.nextToken(tokenizer); pos = (int)tokenizer.nval; } else if(info.equals("XPos")) { GeneralInput.nextToken(tokenizer); pos = (int)tokenizer.nval; } else super.loadParameter(info, tokenizer); } public void toString(PrintWriter pw, String indent) { super.toString(pw, indent); pw.println(indent + "&Column\t" + pos); } }