package initialconditions; import java.lang.*; import java.io.*; import main.BetterTokenizer; import main.Cell; import main.GeneralInput; /** An initial condition class that sets a middle cell to one value and then the cells immediately surrounding that middle cell to a second value.
Input Parameters:
Node
Value
SurroundValue
XPos
YPos

*/ public class CenterIC extends InitialCondition { /** The x,y position of the center cell */ int xPos, yPos; /** The value given to the surrounding cells. The center cell is set equal to initValue. */ float surroundValue; public final boolean noiseAware = true; public CenterIC() { super(); } public CenterIC(String n, int x, int y, float init_value, float surround_value) { super(); node = n; xPos = x; yPos = y; initValue = init_value; surroundValue = surround_value; } public void setModel(Cell [] cells) { float cval = initValue; float sval = surroundValue; if(noiseLevel > 0.0f) { cval += noiseLevel * (float)rng.nextGaussian(); if(cval < 0.0f) cval = 0.0f; } try { Cell cell = cells[yPos * Cell.arrayWidth + xPos]; cell.setInitialValue(node, cval); for(int i = 0; i < cell.neighbors.length; i++) { if(noiseLevel > 0.0f) { sval = surroundValue + noiseLevel * (float)rng.nextGaussian(); while(sval >= cval) sval = surroundValue + noiseLevel * (float)rng.nextGaussian(); if(sval < 0.0f) sval = 0.0f; } cell.neighbors[i].setInitialValue(node, sval); } } catch(Exception e) { System.out.println(e.toString()); return; } } protected void loadParameter(String info, BetterTokenizer tokenizer) throws Exception { if(info.equals("XPos")) { GeneralInput.nextToken(tokenizer); xPos = (int)tokenizer.nval; } if(info.equals("YPos")) { GeneralInput.nextToken(tokenizer); yPos = (int)tokenizer.nval; } if(info.equals("SurroundValue")) { GeneralInput.nextToken(tokenizer); surroundValue = (float)tokenizer.nval; } else super.loadParameter(info, tokenizer); } public void toString(PrintWriter pw, String indent) { super.toString(pw, indent); pw.println(indent + "&XPos\t" + xPos); pw.println(indent + "&YPos\t" + yPos); pw.println(indent + "&SurroundValue\t" + surroundValue); } }