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 IncrementingACSC1 extends InitialCondition { /** Number of times to do a particular value before moving to next value */ int numTimesAtValue; /** The number of increments between start and end values */ int numIncr; /** The highest value given to a cell. Cells will be spaced uniformly from initValue to endValue */ float endValue; float curValue = 0; int numTimes = 0; public IncrementingACSC1() { } public IncrementingACSC1(String n, int num_times_at_value, int num_incr, float start_value, float end_value) { node = n; numTimesAtValue = num_times_at_value; initValue = start_value; endValue = end_value; numIncr = num_incr; curValue = initValue; } public void setModel(Cell [] cells) { int x, y; try { if(numTimes == numTimesAtValue) { numTimes = 0; curValue += (endValue - initValue) / (numIncr - 1); if(curValue > endValue + 0.00000001) { curValue = initValue; } } for(x = 0; x < Cell.arrayWidth; x++) { for(y = 0; y < Cell.arrayHeight; y++) { Cell cell = cells[y * Cell.arrayWidth + x]; cell.setInitialValue(node, curValue); } } } catch(Exception e) { System.out.println(e.toString()); return; } } protected void loadParameter(String info, BetterTokenizer tokenizer) throws Exception { if(info.equals("EndValue")) { GeneralInput.nextToken(tokenizer); endValue = (float)tokenizer.nval; curValue = initValue; // Should be somewhere else, but oh well } if(info.equals("NumTimesAtValue")) { GeneralInput.nextToken(tokenizer); numTimesAtValue = (int)tokenizer.nval; } if(info.equals("NumIncr")) { GeneralInput.nextToken(tokenizer); numIncr = (int)tokenizer.nval; } else super.loadParameter(info, tokenizer); } public void toString(PrintWriter pw, String indent) { super.toString(pw, indent); pw.println(indent + "&EndValue\t" + endValue); pw.println(indent + "&NumTimesAtValue\t" + numTimesAtValue); pw.println(indent + "&NumIncr\t" + numIncr); } }