File: spGlobals.mesa
Copyright (C) 1985 by Xerox Corporation. All rights reserved.
Last Edited by:
Pradeep Sindhu October 21, 1985 5:00:42 pm PDT
Sweetsun Chen, October 21, 1985 3:57:50 pm PDT
DIRECTORY
Ascii USING [SP],
BasicTime USING [GMT, nullGMT],
Buttons USING [Button],
Containers USING [Container],
IO USING [STREAM],
Labels USING [Label],
Rope USING [ROPE],
Plot USING [PlotSpec],
TypeScript USING [TS],
ViewerClasses USING [Viewer];
spGlobals: CEDAR DEFINITIONS = {
types:
itemType: TYPE = {name, comma, semi, colon, rightB, leftB, equal, number, leftC, rightC, eof, leftArrow, slash, upArrow, atSign, vertical, star, plus, minus, leftP, rightP, backSlash, greater, less, pound, squiggle, amperesand, quote, string, implies, greatEqual, lessEqual, maximum, minimum, nullItem};
keys: TYPE = {nodeKey, resKey, capKey, indKey, vsKey, isKey, runKey, printKey, circuitKey, modelKey, plotKey, icKey, dumpKey, assertsKey, checkPointKey, libraryKey, nullKey};
expressionPtr
operators: TYPE = {load, neg, add, sub, mul, div, power, store, abs, exp, num, log, sqrt, not, grt, les, geq, leq, eq, neq, and, or, int, max, min, nullOpr};
expressionPtr: TYPE = REF expressionNode;
expressionNode: TYPE = RECORD [
visited: BOOLFALSE,
next: expressionPtr ← NIL,
operands: SELECT operator: operators FROM
add, sub, mul, div, power, and, or, grt, les, geq, leq, eq, neq, max, min =>
[leftOp: expressionPtr ← NIL,
rightOp: expressionPtr ← NIL],
abs, exp, neg, log, sqrt, not, int =>
[unaryOp: expressionPtr ← NIL],
load, store =>
[var: namePtr ← NIL,
expr: expressionPtr ← NIL],
num =>
[v: REAL ← 0.0],
ENDCASE
];
namePtr
namePtr: TYPE = REF nameBlk;
nameBlk: TYPE = RECORD [
visited: BOOLFALSE,
nextName,
srchLink: namePtr ← NIL,
name: Rope.ROPENIL,
expExpr: expressionPtr ← NIL,
realCopy: realThingPtr ← NIL,
details: REF ANYNIL]; -- cf. the following 8 REF types
RefNodeRec: TYPE = REF NodeRec;
NodeRec: TYPE = RECORD [];
RefBranchRec: TYPE = REF BranchRec;
BranchRec: TYPE = RECORD [
visited: BOOLFALSE,
branchType: elements ← nullElement,
posNode,
negNode,
controller: namePtr ← NIL,
modelIndex: NAT ← 0,
valExpr: expressionPtr ← NIL];
RefCircuitRec: TYPE = REF CircuitRec;
CircuitRec: TYPE = RECORD [
visited: BOOLFALSE,
names,
fakeNodes: namePtr ← NIL,
conCount: NAT ← 0,
parms,
father: namePtr ← NIL,
assertions: expressionPtr ← NIL];
RefConRec: TYPE = REF ConRec;
ConRec: TYPE = RECORD [];
RefParmRec: TYPE = REF ParmRec;
ParmRec: TYPE = RECORD [
visited: BOOLFALSE,
default: BOOLFALSE,
dfltValue: REAL ← 0.0,
nextParm: namePtr ← NIL];
RefCktInstRec: TYPE = REF CktInstance;
CktInstance: TYPE = RECORD [
visited: BOOLFALSE,
of: namePtr ← NIL,
connections: conLinkPtr ← NIL,
actualParms: expressionPtr ← NIL];
RefModelRec: TYPE = REF ModelRec;
ModelRec: TYPE = RECORD [
visited: BOOLFALSE,
modelProc: model ← NIL,
modelResults: argList ← NIL,
modelArgs: argNames ← NIL,
modelArgVec,
modelOldArgVec: argList ← NIL,
modelParms: expressionPtr ← NIL,
data: REF ANYNIL];
RefFunctionRec: TYPE = REF FunctionRec;
FunctionRec: TYPE = RECORD [
visited: BOOLFALSE,
functionProc: function ← NIL,
funcArgs: argNames ← NIL,
funcArgVec: argList ← NIL,
funcParms: expressionPtr ← NIL,
branch: namePtr ← NIL,
data: REF ANYNIL];
nodePtr
nodePtr: TYPE = REF node;
node: TYPE = RECORD [
visited: BOOLFALSE,
nextNode: nodePtr ← NIL,
nodeName: namePtr ← NIL,
treeLevel: instTreePtr ← NIL,
brotherNodes: nodePtr ← NIL,
branches: branchLinkPtr ← NIL,
curPtr: branchPtr ← NIL, -- vSource ptr
nextIntNode: nodePtr ← NIL,
nHist: history ← [],
integrate,
marked,
converged: BOOLFALSE];
branchPtr
elements: TYPE = {resistor, capacitor, inductor, vSource, iSource, nullElement};
branchPtr: TYPE = REF branch;
branch: TYPE = RECORD [
visited: BOOLFALSE,
branchName: namePtr ← NIL,
treeLevel: instTreePtr ← NIL,
brotherBranches: branchPtr ← NIL,
posNode,
negNode: nodePtr ← NIL,
comVal: REAL ← 0.0,
controller: modFuncPtr ← NIL,
modelIndex: NAT ← 0,
body: REF ANYNIL]; -- cf. the following 5 REF types.
RefR: TYPE = REF ResistorBody;
ResistorBody: TYPE = RECORD [];
RefC: TYPE = REF CapacitorBody;
CapacitorBody: TYPE = RECORD [
visited: BOOLFALSE,
nextCapacitor: branchPtr ← NIL];
history: TYPE = RECORD [y, oldy, sumk, oldf, f0, f1, f2, f3, f4: REAL ← 0.0];
RefL: TYPE = REF InductorBody;
InductorBody: TYPE = RECORD [
visited: BOOLFALSE,
nextInductor: branchPtr ← NIL,
iHist: history ← []];
RefV: TYPE = REF VSourceBody;
VSourceBody: TYPE = RECORD [
visited: BOOLFALSE,
nextvSource: branchPtr ← NIL,
vsCurrent: REAL ← 0.0,
oldCurrent: REAL ← 0.0];
RefI: TYPE = REF ISourceBody;
ISourceBody: TYPE = RECORD [
visited: BOOLFALSE,
nextiSource: branchPtr ← NIL];
realThingPtr
realThings: TYPE = {realNode, realBranch, realParm, realModel, unReal};
realThingPtr: TYPE = REF realThing;
realThing: TYPE = RECORD [
visited: BOOLFALSE,
nextThing: realThingPtr ← NIL,
newLevel: BOOLTRUE,
thing: REF ANYNIL]; -- cf. the following 5 REF types
RefRealNode: TYPE = REF RealNode;
RealNode: TYPE = RECORD [
visited: BOOLFALSE,
rn: nodePtr ← NIL];
RefRealBranch: TYPE = REF RealBranch;
RealBranch: TYPE = RECORD [
visited: BOOLFALSE,
rb: branchPtr ← NIL];
RefRealParm: TYPE = REF RealParm;
RealParm: TYPE = RECORD [
visited: BOOLFALSE,
rp: REAL ← 0.0];
RefRealModel: TYPE = REF RealModel;
RealModel: TYPE = RECORD [
visited: BOOLFALSE,
rm: modFuncPtr ← NIL];
RefUnReal: TYPE = REF UnReal;
UnReal: TYPE = RECORD [];
branchLinkPtr, conLinkPtr, and instTreePtr
branchLinkPtr: TYPE = REF branchLink;
branchLink: TYPE = RECORD [
visited: BOOLFALSE,
nextLink: branchLinkPtr ← NIL,
branch: branchPtr ← NIL,
otherNode: nodePtr ← NIL,
pos: BOOLFALSE];
conLinkPtr: TYPE = REF conLink;
conLink: TYPE = RECORD [
visited: BOOLFALSE,
nextLink: conLinkPtr ← NIL,
namedNode: namePtr ← NIL];
instTreePtr: TYPE = REF instTreeNode;
instTreeNode: TYPE = RECORD [
visited: BOOLFALSE,
father,
brothers,
sons: instTreePtr ← NIL,
instance: namePtr ← NIL,
nodes: nodePtr ← NIL,
branches: branchPtr ← NIL];
modelFuncPtr
modFuncPtr: TYPE = REF modFuncBlk;
modFuncBlk: TYPE = RECORD [
visited: BOOLFALSE,
nextMFPtr: modFuncPtr ← NIL,
arguments: argNodes ← NIL,
argVector,
parmVector: argList ← NIL,
actualParms: expressionPtr ← NIL,
data: REF ANYNIL, -- for use by the model or function code
body: REF ANYNIL]; -- cf. the following two.
RefFuncBody: TYPE = REF FunctionBody;
FunctionBody: TYPE = RECORD [
visited: BOOLFALSE,
functionProc: function ← NIL,
branch: branchPtr ← NIL];
RefModBody: TYPE = REF ModelBody;
ModelBody: TYPE = RECORD [
visited: BOOLFALSE,
modelProc: model ← NIL,
modelResults: argList ← NIL,
modelName: namePtr ← NIL,
oldArgVector: argList ← NIL,
modelBranches: modBrPtr ← NIL];
modelBrPtr
modBrPtr: TYPE = REF modelBranch;
modelBranch: TYPE = RECORD [
visited: BOOLFALSE,
nextBranch: modBrPtr,
b: branchPtr];
ModelTablePtr and FuncTablePtr
ModelTable: TYPE = LIST OF REF ModelTableBlk;
ModelTableBlk: TYPE = RECORD [
name: Rope.ROPE,
proc: model,
numArgs, numParms, numResults: NAT,
data: REF ANYNIL];
FuncTable: TYPE = LIST OF REF FuncTableBlk;
FuncTableBlk: TYPE = RECORD [
name: Rope.ROPE,
proc: function,
numArgs, numParms: NAT,
data: REF ANYNIL];
List of model applications, sorted by the nodes that are their args
hashModulus: INT = 253;
HashKey: TYPE = [0..hashModulus);
ModelArgHash: TYPE = ARRAY HashKey OF LIST OF REF ANYALL[NIL];
argList, argNames, argNodes
argList: TYPE = REF ValueSeq;
ValueSeq: TYPE = RECORD [
visited: BOOLFALSE,
handle: Handle ← NIL,
modFunc: modFuncPtr ← NIL,
value: SEQUENCE size: NAT OF REAL];
argNames: TYPE = REF namePtrSeq;
namePtrSeq: TYPE = RECORD [
visited: BOOLFALSE,
names: SEQUENCE size: NAT OF namePtr];
argNodes: TYPE = REF nodePtrSeq;
nodePtrSeq: TYPE = RECORD [
visited: BOOLFALSE,
nodes: SEQUENCE size: NAT OF nodePtr];
model and function
model: TYPE = PROC[args, oldArgs, parms, results: argList];
function: TYPE = PROC[t: REAL, args, parms: argList] RETURNS [v: REAL];
Stages, Handle, ThymeToolRec and Variables
Stages: TYPE = {idle, input, bomb, topo, run};
Handle: TYPE = REF ThymeToolRec;
ThymeToolRec: TYPE = RECORD [
outer: Containers.Container ← NIL,
wDir, input, progress: ViewerClasses.Viewer ← NIL,
output, time, step: Labels.Label ← NIL,
message: TypeScript.TSNIL,
msgStream: IO.STREAMNIL,
showDetailsButton, echoInputButton: Buttons.Button ← NIL,
showTimeStep, echoInput: BOOLTRUE,
stage: Stages ← idle,
checkProcess, simulation: PROCESSNIL,
checkPointCV: CONDITION,
height: NAT ← 0,
vars: REF Variables ← NIL];
Variables: TYPE = RECORD [
simTime: BasicTime.GMT ← BasicTime.nullGMT,
runState: NAT[0..4) ← 0,
forcedDump: BOOLFALSE,
lastTime: REAL ← 0.0,
checkPointInterval: REAL ← 60.0,
spGlobalsImpl
fileStack: REF fileStackSeq ← NIL,
fileNameStack: REF fileNameStackSeq ← NIL,
fileStackTop: NAT ← 0,
line: REF TEXTNIL,
value: REAL ← 0.0,
item: itemType ← nullItem,
newString: REF TEXTNIL,
char: CHAR ← Ascii.SP,
cptr: NAT ← 0, -- pointer to "char" in "line"
genSymCtr: LONG CARDINAL ← 10000,
spInput
gndNodeName,
undefNode,
cktRoot,
currentCkt: namePtr ← NIL,
spBomb
treeRoot: instTreePtr ← NIL,
unusedNodes: nodePtr ← NIL,
nodeCount, branchCount, modelCount, funcCount: LONG CARDINAL ← 0,
modelArgs: REF ModelArgHash ← NIL,
n: nodePtr ← NIL, -- Real ones!!!
b: branchPtr ← NIL,
p: REAL ← 0.0,
m: modFuncPtr ← NIL,
gndNode,
nodeList: nodePtr ← NIL,
capacitorList,
inductorList,
vSourceList,
iSourceList: branchPtr ← NIL,
functionList: modFuncPtr ← NIL,
spErrors
errCount, warnCount: NAT ← 0,
triedOnce: BOOLFALSE,
inStream, thymeDotErrors: IO.STREAMNIL,
topOfMsgStream: INT ← 0,
spExpressions
type: {real, name} ← real,
spOutput
numPrints: NAT ← 0,
prints: REF PrintSeq ← NIL,
numPlots: NAT ← 0,
plots: REF PlotSeq ← NIL,
spSolve
intNodeList: nodePtr ← NIL,
intNodeModFunc,
otherModFunc: modFuncPtr ← NIL,
worstNode: nodePtr ← NIL,
curLog: NAT ← 0,
worstNodeLog: REF WorstNodeLog ← NIL,
lastRetreatCause: Rope.ROPENIL,
icsSet, checkPoint, canned: BOOLFALSE,
numGoodSteps: LONG CARDINAL ← 0,
modelsSkipped: NAT ← 0,
dvdtTrunc, t, dT: REAL ← 0.0,
AMcount, goodNodeCount, numberOfSteps, highStepCount, lowStepCount: INT ← 0,
countsPerStep: INT ← 100000000,
Vmin: REAL ← -100.0,
Vmax: REAL ← 100.0,
dvdtmax: REAL ← 1.0e15,
dfltInts: NAT ← 200,
ignorDvDtBelow: REAL ← 1.0e-9, -- if |dvdt| < this number then set it to 0.0. Temp fix to avoid being trapped into buggy floating point software too frequently.
retRatio: REAL ← 0.5,
RKfac: REAL ← 1.0,
minRatio: REAL ← 0.8,
floor: REAL ← 0.01,
AMerr: REAL ← 0.01,
RKerr: REAL ← 0.01,
tBreak: REAL ← 0.0,
dvdtFac: REAL ← 5.0,
squish: REAL ← 0.2,
initStep: REAL ← 0.1,
tol: REAL ← 0.001,
intTol: REAL ← 0.001,
AMup: REAL ← 1.25,
AMdown: REAL ← 0.8,
printdT: REAL ← 0.0,
tMin: REAL ← 0.0,
tMax: REAL ← 0.0,
maxIter: INT ← 20,
AMiter: NAT ← 2,
AMdelay: NAT ← 5,
printIter, printStep, doRungeKutta, printAll, showRetreat: BOOLFALSE,
checkPointCV: CONDITION
];
misc types and constants
argumentPtr: TYPE = REF argument;
argument: TYPE = RECORD [
visited: BOOLFALSE,
node: nodePtr ← NIL,
branch: branchPtr ← NIL,
getComVal,
dvdt,
current: BOOLFALSE];
fileStackSeq: TYPE = RECORD [f: SEQUENCE numFiles: NAT OF IO.STREAM];
fileNameStackSeq: TYPE = RECORD [f: SEQUENCE numFiles: NAT OF Rope.ROPE];
maxInclude: NAT = 10;
maxPlots: NAT = 10;
maxPrints: NAT = 10;
PlotSeq: TYPE = RECORD [SEQUENCE size: NAT OF PlotRec];
PlotRec: TYPE = RECORD [
plotList: plotBlkPtr ← NIL,
plotTimeRelTo: REAL ← 0,
plotCount: NAT ← 0, -- # curves
plotViewer: ViewerClasses.Viewer ← NIL,
plotSpec: Plot.PlotSpec ← NIL];
plotBlkPtr: TYPE = REF plotBlk;
plotBlk: TYPE = RECORD [
visited: BOOL ← FALSE,
nextBlk: plotBlkPtr ← NIL,
relativeTo: REAL ← 0,
arg: argumentPtr ← NIL];
PrintSeq: TYPE = RECORD [SEQUENCE size: NAT OF PrintRec];
PrintRec: TYPE = RECORD [
printList: printBlkPtr ← NIL,
printTimeRelTo: REAL ← 0.0,
printStream: IO.STREAMNIL];
printBlkPtr: TYPE = REF printBlk;
printBlk: TYPE = RECORD [
visited: BOOLFALSE,
nextBlk: printBlkPtr ← NIL,
relativeTo: REAL ← 0,
arg: argumentPtr ← NIL];
spSolve
maxLog: NAT = 16;
WorstNodeLog: TYPE = RECORD [SEQUENCE size: NAT OF WorstNodeRec];
WorstNodeRec: TYPE = RECORD [
visited: BOOLFALSE,
node: nodePtr ← NIL,
t, v, dvdt: REAL ← 0];
maxCountsPerStep: INT = 1000000000;
signals:
ErrorSignal: SIGNAL[error: NAT, s: Rope.ROPE];
Retreat: SIGNAL[cause: Rope.ROPE];
Failure: SIGNAL[errorNum: NAT];
Aborted: SIGNAL; -- spGlobalsImpl
global variables:
Initialized in ThymeViewers
version: Rope.ROPE;
refNodeRec: READONLY RefNodeRec;
refConRec: READONLY RefConRec;
refR: READONLY RefR;
refUnReal: READONLY RefUnReal;
modelTable: ModelTable;
functionTable: FuncTable;
procs:
Exported by spGlobalsImpl:
openInputFile: PROC[handle: Handle];
OutputFileRoot: PROC[handle: Handle] RETURNS [Rope.ROPE];
WorkingDirectory: PROC[handle: Handle] RETURNS [Rope.ROPE];
FlushCloseNil: PROC[stream: IO.STREAM] RETURNS [IO.STREAMNIL];
MsgTextsWithLook: PROC[handle: Handle, text: Rope.ROPE, look: CHAR['a..'z]];
next: PROC[handle: Handle];
searchKey: PROC[handle: Handle] RETURNS [index: keys];
getSignedNumber: PROC[handle: Handle] RETURNS [n: REAL ← 1.0];
GetLineAndCptr: PROC[handle: Handle] RETURNS [Rope.ROPE, NAT];
Exported by spErrors:
error: PROC[handle: Handle, err: NAT, skip, warning: BOOLFALSE];
error2: PROC[handle: Handle, err: NAT, n: namePtr];
ErrorStrings: PROC[handle: Handle, err: NAT, s1, s2: Rope.ROPE];
ErrorAtNB: PROC[handle: Handle, err: NAT, n: nodePtr, b: branchPtr];
ErrWarnSummary: PROC[handle: Handle];
Exported by spExpressions:
expression: PROC[handle: Handle] RETURNS [e: expressionPtr];
assignExpr: PROC[handle: Handle, leftContext: namePtr] RETURNS [a: expressionPtr];
eval: PROC[handle: Handle, exp: expressionPtr] RETURNS [v: REAL];
Exported by spInput:
variable: PROC[handle: Handle, string: REF TEXT, context: namePtr] RETURNS [nPtr: namePtr ← NIL];
output: PROC[handle: Handle, ckt: namePtr, level: NAT];
defineCircuit: PROC[handle: Handle, ckt: namePtr, root: BOOL];
Exported by spBomb:
bomb: PROC[handle: Handle];
printHole: PROC[handle: Handle];
findNodeOrBranch: PROC[handle: Handle] RETURNS [n: nodePtr, b: branchPtr];
makeStringNB: PROC[handle: Handle, n: nodePtr, b: branchPtr, ok: BOOLTRUE] RETURNS [Rope.ROPE];
getParmValue: PROC[handle: Handle, nPtr: namePtr] RETURNS [REAL];
putParmValue: PROC[handle: Handle, nPtr: namePtr, val: REAL];
Exported by spAnalysis:
topoAnalysis: PROC[handle: Handle];
Exported by spSolve:
runIt: PROC[handle: Handle] RETURNS [REAL];
setICs: PROC[handle: Handle];
Exported by spOutput:
initPlot: PROC[handle: Handle, tMin, tMax: REAL];
plotFromList: PROC[handle: Handle, t: REAL];
makePlotList: PROC[handle: Handle];
initPrint: PROC[handle: Handle, time: BasicTime.GMT];
printFromList: PROC[handle: Handle, ni: INT, t: REAL, printStep: BOOL];
makePrintList: PROC[handle: Handle];
PutMsgLine: PROC[handle: Handle, s: Rope.ROPE];
dumpAll: PROC[handle: Handle, t: REAL];
Exported by spMain:
EnterModels: PROC[entry: ModelTableBlk];
EnterFunctions: PROC[entry: FuncTableBlk];
findModel: PROC[name: Rope.ROPE] RETURNS [REF ModelTableBlk];
findFunction: PROC[name: Rope.ROPE] RETURNS [REF FuncTableBlk];
ResetCheckPoint: PROC[handle: Handle];
Canned: PROC[handle: Handle] RETURNS [BOOL];
ForcedDump: PROC[handle: Handle] RETURNS [BOOL];
CheckPoint: PROC[handle: Handle] RETURNS [BOOL];
ShowDetails: PROC[handle: Handle] RETURNS [BOOL];
EchoInput: PROC[handle: Handle] RETURNS [BOOL];
StopIt: PROC[handle: Handle];
DumpIt: PROC[handle: Handle];
ToggleShowDetails: PROC[handle: Handle];
ToggleEchoInput: PROC[handle: Handle];
NormalRun: PROC[handle: Handle, background, fork: BOOLTRUE];
BatchRun: PROC[handle: Handle, inputFile: Rope.ROPENIL, background, fork: BOOLTRUE];
NextStage: PROC[handle: Handle];
Simulate: PROC[handle: Handle];
Exported by ThymeViewers:
MakeThymeViewers: PROC[wDir: Rope.ROPENIL] RETURNS [handle: spGlobals.Handle ← NIL];
SetCursor: PROC[handle: Handle];
AdvanceStage: PROC[handle: Handle];
Exported by ThymeCleanUp:
CleanUp: PROC[handle: Handle];
Library Models and Functions:
spModels: PROGRAM;
Level2Model: PROGRAM;
spFunctions: PROGRAM;
}.
CHANGE LOG
Wilhelm, April 27, 1982 4:05 PM
Barth, 7-May-82 10:58:25 PDT
Chen, 4/19/83:- modified itemType, operators, and expressionNode to support Max and Min operations.
Chen, 2/12/84:- modified to support oldArgVector.
Chen, June 12, 1984 10:05:25 am PDT, Cedarized.
McCreight, April 1, 1985 4:17:09 pm PST, added:
1. "data" fields in ModelRec and FunctionRec, modFuncBlk, ModelTableBlk, and FuncTableBlk;
2. hashModulus, HashKey, and ModelArgHash;
3. the handle and modFunc fields in ValueSeq;
4. modelArgs.
Chen, May 10, 1985 12:45:56 pm PDT, added ignorDvDtBelow to avoid concurrency problem using floating point software.
Chen, July 22, 1985 8:01:41 pm PDT, => Cedar6.0.