Skip to content

Instantly share code, notes, and snippets.

@kenwebb
Last active December 20, 2024 02:48
Show Gist options
  • Save kenwebb/76e0dfc55050cb70b3c32f9a8e12b2e4 to your computer and use it in GitHub Desktop.
Save kenwebb/76e0dfc55050cb70b3c32f9a8e12b2e4 to your computer and use it in GitHub Desktop.
SysDyn with JSO(N) and Acorn
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Thu Dec 19 2024 21:48:19 GMT-0500 (Eastern Standard Time)-->
<XholonWorkbook>
<Notes><![CDATA[
Xholon
------
Title: SysDyn with JSO(N) and Acorn
Description:
Url: http://www.primordion.com/Xholon/gwt/
InternalName: 76e0dfc55050cb70b3c32f9a8e12b2e4
Keywords:
My Notes
--------
18 Dec 2024
new workbook: SysDyn with JSO(N) and Acorn
- use JSON/JSO to define all data for SysDyn Appendix C
- parse individiual segments of code
- using acorn (if needed?)
- directly specifiy whether a segment is L R A C N as in DYNAMO
- the DYNAMO/JavaScript code is the same as in ref [2]
### Comparison with Bigraph approach
- mappings between sets/arrays
- pairs ex: (UOR, {J:0, K:DUR*100})
- networks
- is this a useful thing to do?
### References
(1) http://127.0.0.1:8080/wb/editwb.html?app=JavaScript+-+Abstract+Syntax+Tree+%28AST%29+2&src=lstr
JavaScript - Abstract Syntax Tree (AST) 2
64973dc6f7188262c3072570d48f2ea5
(2) http://127.0.0.1:8080/wb/editwb.html?app=Industrial+Dynamics+-+Appendix+C&src=lstr
Industrial Dynamics - Appendix C
79247e6babf6a1ecbbe6712ab825618d
]]></Notes>
<_-.XholonClass>
<PhysicalSystem/>
<DynamoModel/>
<DynamoModelTester superClass="Script"/>
</_-.XholonClass>
<xholonClassDetails>
</xholonClassDetails>
<PhysicalSystem>
<DynamoModel/>
<DynamoModelTester><![CDATA[
var me, beh = {
postConfigure: function() {
me = this.cnode;
me.println(me.name());
},
act: function() {
/*me.println(me.name() + " ...");
me.println(AIR);
me.println(UOR.K);
me.println(SSR.KL);
me.println(IDR.K);
me.println(TIME);
me.println(STEP);
me.println(STEP());
me.println("..." + me.name());*/
}
}
//# sourceURL=DynamoModelTester.js
]]></DynamoModelTester>
</PhysicalSystem>
<DynamoModelbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
// System Dynamics data
// this is a JavaScript Object (JSO)
const sddata = {
// C constants
constants: `
AIR=3.0;
DIR=2.0;
DRR=2.0;
DT=0.5;
DUD=2.0;
DUR=1.0;`,
// N initializations
inits: `
// levels OK
UOR = {J:0, K:DUR*100};
IAR = {J:0, K:AIR*100};
RSR = {J:0, K:100};
UOD = {J:0, K:DUD*100};
// rates OK
SSR = {JK:0, KL:100};
PDR = {JK:0, KL:1000};
SRR = {JK:0, KL:1000};
RRR = {JK:0, KL:100};
// aux OK
IDR = {J:0, K:300};
ISR = {J:0, K:0};
INSTP = {J:0, K:0};
// time
TIME = 0.0; // should be 0.0
// functions
STEP = () => {TIME += DT; return TIME >= 1.0 ? 20.00 : 0.00;};`,
// L levels
levels: `
UOR.K=UOR.J+(DT)*(RRR.JK-SSR.JK);
IAR.K=IAR.J+(DT)*(SRR.JK-SSR.JK);
RSR.K=RSR.J+(DT)*(1/DRR)*(RRR.JK-RSR.J);
UOD.K=UOD.J+(DT)*(PDR.JK-SRR.JK);`,
// A auxiliaries
auxes: `
IDR.K=(AIR)*(RSR.K);
ISR.K=IDR.K-IAR.K;
INSTP.K=STEP(20,1);`,
// R rates
rates: `
SSR.KL=UOR.K/DUR;
PDR.KL=(ISR.K/DIR)+RSR.K;
SRR.KL=UOD.K/DUD;
RRR.KL=100.0+INSTP.K;`
}
console.log("sddata", sddata);
const sddata2 = {
constants: sddata.constants.trim().split("\n").map((item) => item.trim(), []),
inits: sddata.inits.trim().split("\n").map((item) => item.trim(), []),
levels: sddata.levels.trim().split("\n").map((item) => item.trim(), []),
auxes: sddata.auxes.trim().split("\n").map((item) => item.trim(), []),
rates: sddata.rates.trim().split("\n").map((item) => item.trim(), [])
}
console.log("sddata2", sddata2);
const sddata3 =
sddata.constants.trim()
+ sddata.inits.trim()
+ sddata.levels.trim()
+ sddata.auxes.trim()
+ sddata.rates.trim();
console.log("sddata3", sddata3);
const advance = (sdnode) => sdnode.K ? (sdnode.J = sdnode.K) : sdnode.KL ? (sdnode.JK = sdnode.KL) : sdnode
const SEP = "\t";
const printData = (arr) => arr.map((item) => {
const pdata = item.K ? item.K : item.KL ? item.KL : 0;
return pdata.toFixed(2);
}, []).join(SEP)
let me, levels, rates, auxes
var beh = {
postConfigure: function() {
me = this.cnode.parent();
me.println(JSON.stringify(sddata2));
var script = "<Script>" + sddata3 + "</Script>";
console.log(script);
me.append(script);
//me.println(AIR);
//me.println(UOR.K);
//me.println(SSR.KL);
//me.println(IDR.K);
//me.println(TIME);
//me.println(STEP);
//me.println(STEP());
levels = [UOR,IAR,RSR,UOD];
rates = [SSR,PDR,SRR,RRR];
auxes = [IDR,ISR];
},
act: function() {
//me.println(me.name());
//me.println(TIME);
//me.println(STEP());
},
preAct: function() {
levels.forEach((item) => advance(item));
rates.forEach((item) => advance(item));
auxes.forEach((item) => advance(item));
const pdata = printData([].concat(levels).concat(rates).concat(auxes));
console.log(pdata);
me.println(pdata);
}
}
//# sourceURL=DynamoModelbehavior.js
]]></DynamoModelbehavior>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Block</title>
<rect id="PhysicalSystem/DynamoModel" fill="#98FB98" height="50" width="50" x="25" y="0"/>
<g>
<title>Height</title>
<rect id="PhysicalSystem/DynamoModel" fill="#6AB06A" height="50" width="10" x="80" y="0"/>
</g>
</g>
</svg>
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient>
</XholonWorkbook>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment