package adlsim;
/**
*
Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author unascribed
* @version 1.0
*/
public class Solver {
String vars[];// = new String[1];
String varsLogic[];
String varsAnalog[];
VCD vcd = new VCD();
XLS xls = new XLS();
boolean[][] valLogic;
long[][] val;
double[][] valAnalog;
byte PORTCInit = 0;
byte PORTCFinal = 0;
int dummy = 0;//DEBUG*********************************
double temp = 0;//DEBUG*****************************************
long[] cTime = new long[100];//********************Debug
int cTimeIndex = 0;
double tempPort = 0;
public double[] Solve(double[][]A0,double[]z0){
int maxrow;
int n= A0.length;
double tmp;
double[]x = new double[A0.length];
double[][]a = new double[A0.length][A0.length+1];
for(int i = 0; i Math.abs(a[maxrow][i]))
maxrow = j;
}
/* Swap the maxrow and ith row */
for (int k=i;k=i;k--) {
a[j][k] -= a[i][k] * a[j][i] / a[i][i];
}
}
}
/* Do the back substitution */
for (int j=n-1;j>=0;j--) {
tmp = 0;
for (int k=j+1;k noOfNodes){
noOfNodes = Math.max(Math.max(e[i].nj,e[i].nk),Math.max(e[i].np,e[i].nq));
}
}
for(int i = 0; i< e.length; i++){
//Element processed is a diode
if(e[i].TYPE == C.D){
//Guess the initial diode voltage as 0.7
double vd = 0.7;
//Calculate Gd for this iteration
double Gd = e[i].pnl1*e[i].pnl2*Math.exp(e[i].pnl2*vd);
//Calculate Ids for this iteration
double Ids = e[i].pnl1*(Math.exp(e[i].pnl2*vd)-1)-Gd*vd;
//Generate linear model of the diode for the next iteration
//and update the array of elements
e[i] = new Element(C.D,e[i].nj,e[i].nk,e[i].np,e[i].nq,Gd,Ids,e[i].pnl1,e[i].pnl2);
}
}
//Keep on iterating until the results converge to within +/- epsilon
//of the actual values
while(!Done){
//Compile the circuit using the new element array
A = C.Compile(e,noOfNodes);
//Update previous results
for(int i = 0; iepsilon)
Done = false;
}
//Process the element list & recompile
for(int i = 0; i< e.length; i++){
//Element processed is a diode
if(e[i].TYPE == C.D){
//Value of the positive terminal voltage
double tempIn = 0;
//Value of the negative terminal voltage
double tempOut = 0;
//voltage accross the diode
double vd = 0;
//Get the voltages on the +/- terminals
if(e[i].nk >0)
tempIn = x[e[i].nk-1];
if(e[i].nj >0)
tempOut = x[e[i].nj-1];
//Calculate diode voltage
vd = tempIn - tempOut;
//Calculate Gd for this iteration
double Gd = e[i].pnl1*e[i].pnl2*Math.exp(e[i].pnl2*vd);
//Calculate Ids for this iteration
double Ids = e[i].pnl1*(Math.exp(e[i].pnl2*vd)-1)-Gd*vd;
//Generate linear model of the diode for the next iteration
//and update the array of elements
e[i] = new Element(C.D,e[i].nj,e[i].nk,e[i].np,e[i].nq,Gd,Ids,e[i].pnl1,e[i].pnl2);
}
}
}
return(x);
}
//Perfrom AC analyses with time-step h
public double[] SolveAC(double[][]A,double[]z, double epsilon, double h, double t, Element[] e,
ADLSimulator MCUs[], String[] ID, int[] addr, int IDIndex,String[] mcuName,
String[] IDAnalog, int[] nodeNum, int IDIndexAnalog,
String[] IDLogic, int[] nodeNumLogic, int IDIndexLogic, Logic logic){
if(IDIndexAnalog!=0)
valAnalog = new double[10001][IDIndexAnalog+1];
else
valAnalog = new double[1][2];
if(IDIndex!=0)
val = new long[IDIndex][10001];
else
val = new long[1][2];
if(IDIndexLogic!=0)
valLogic = new boolean[IDIndexLogic][10001];
else
valLogic = new boolean[1][2];
Element[] element = new Element[e.length];
Compiler C = new Compiler();
double x[] = new double[A.length];
double currentTime = 0;
int noOfNodes = 0;
for(int i = 0; i< element.length; i++){
element[i] = new Element(e[i].TYPE, e[i].nj, e[i].nk, e[i].np, e[i].nq,
e[i].p, e[i].pnl0, e[i].pnl1, e[i].pnl2);
element[i].MCU = e[i].MCU;
}
for(int i = 0; i< e.length; i++){
//Determine the number of nodes
if( Math.max( Math.max(e[i].nj,e[i].nk),Math.max(e[i].np,e[i].nq)) > noOfNodes){
noOfNodes = Math.max(Math.max(e[i].nj,e[i].nk),Math.max(e[i].np,e[i].nq));
}
}
for(int i = 0; i < MCUs.length; i++)
MCUs[0].init();
while(currentTime < t){
for(int i = 0; i 0)
tempPlus=x[element[i].nj -1];
if(element[i].nk > 0){
tempMinus = x[element[i].nk - 1];
}
//Subtract the voltages to get Vcap.
double v = tempPlus - tempMinus;
//Generate a new linear capacitor model for the next iteration
//based on the capacitor voltage.
element[i] = new Element(element[i].TYPE, element[i].nj,element[i].nk,element[i].np,element[i].nq,
element[i].p,-1*element[i].p*v,element[i].pnl1,element[i].pnl2);
}
//VAC
if(element[i].TYPE == C.VAC){
temp = Math.cos(currentTime);
element[i] = new Element(element[i].TYPE, element[i].nj,element[i].nk,element[i].np,element[i].nq,
temp,element[i].pnl0,element[i].pnl1,element[i].pnl2);
}
//PORT
if((element[i].TYPE == C.VSRC)&(element[i].pnl0==1)){
ADLSimulator MCU = null;
for(int j = 0; j < MCUs.length; j++){
//String[] s0 = MCUs[j].toString().split("@");
String s1 = MCUs[j].name;//s0[0].substring(7);
// System.out.println(element[i].MCU+"-----------------------------------------element"+j);
// System.out.println(s1+"-----------------------------------------s1");
if(element[i].MCU.equals(s1)){
MCU = MCUs[j];
break;
}
}
//System.out.println("PORT DONE");
if(MCU.getBit(MCU.DMEM[(byte)element[i].pnl2],(int)element[i].pnl1)){
tempPort = 5;
}
else{
tempPort = 0;
}
String mcu = element[i].MCU;
element[i] = new Element(element[i].TYPE,element[i].nj,element[i].nk,element[i].np,element[i].nq,
tempPort,element[i].pnl0,element[i].pnl1,element[i].pnl2);
element[i].MCU = mcu;
}
}
/*******INITIAL Values of PORTC*******/
// PORTCInit = MCU.regFileIO[21];
/***********************************/
for(int i = 0 ; i < MCUs.length; i++){
if (currentTime >= MCUs[i].cycleNum) {
MCUs[i].run();
}
}
/*******FINAL Value of PORTC*******/
// PORTCFinal = MCU.regFileIO[21];
/***********************************/
double tempX = x[17];
A = C.Compile(element,noOfNodes);
x = SolveNL(A,C.z,epsilon,element);
// x = Solve(A,C.z);
currentTime = currentTime + h;
dummy++;
//System.out.println("TEST");
///*****HANDLE DUMPS***********************////////////
String propogate = null;
for(int i = 0 ; i < mcuName.length; i++){
if(mcuName[i] != null){
propogate = mcuName[i];
}
else{
mcuName[i] = propogate;
}
}
if(IDIndex!=0){
for(int i=0; i0)){
newLogicVals[i] = (x[i-1]>3.5);
}
}
boolean currentVals[] = logic.SolveLogic(newLogicVals);
for(int i= 0; i