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 SequenceACSC1 extends InitialCondition { /** 0 = rows */ int rowsOrCols; /** The highest value given to a cell. Cells will be spaced uniformly from initValue to endValue */ float endValue; public SequenceACSC1() { } public SequenceACSC1(String n, int rows, float start_value, float end_value) { node = n; rowsOrCols = rows; initValue = start_value; endValue = end_value; } public void setModel(Cell [] cells) { int x, y; try { float val = initValue, incr; if(rowsOrCols == 0) { incr = (endValue - initValue) / (Cell.arrayWidth - 1); for(x = 0; x < Cell.arrayWidth; x++) { for(y = 0; y < Cell.arrayHeight; y++) { Cell cell = cells[y * Cell.arrayWidth + x]; cell.setInitialValue(node, val); } val += incr; } } else { incr = (endValue - initValue) / (Cell.arrayHeight - 1); for(y = 0; y < Cell.arrayHeight; y++) { for(x = 0; x < Cell.arrayWidth; x++) { Cell cell = cells[y * Cell.arrayWidth + x]; cell.setInitialValue(node, val); } val += incr; } } } 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; } if(info.equals("RowsOrCols")) { GeneralInput.nextToken(tokenizer); rowsOrCols = (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 + "&RowsOrCols\t" + rowsOrCols); } }