Translation of STELLA to FORTRAN

This forum contains all archives from the SD Mailing list (go to http://www.systemdynamics.org/forum/ for more information). This is here as a read-only resource, please post any SD related questions to the SD Discussion forum.
Locked
"Michael J. Radzicki"
Junior Member
Posts: 2
Joined: Fri Mar 29, 2002 3:39 am

Translation of STELLA to FORTRAN

Post by "Michael J. Radzicki" »

Colleagues:

If youre interested in NDTRAN contact John Uhran at:
jju@cse.nd.edu

Cheers.

Mike Radzicki

Michael J. Radzicki, Ph.D.

Associate Professor of Economics
Department of Social Science & Policy Studies
Worcester Polytechnic Institute
Worcester, Massachusetts 01609-2280
United States of America
(508) 831-5767 (Voice)
(508) 831-5896 (Fax)
mjradz@wpi.edu (Email)

and

President
Sustainable Solutions, Inc.
210 Park Avenue
Box 225
Worcester, Massachusetts 01609
United States of America
sustsol@sunspot.tiac.net (Email)
http://www.tiac.net/users/sustsol (Web)
K.Simons@rhbnc.ac.uk (Kenneth L
Newbie
Posts: 1
Joined: Fri Mar 29, 2002 3:39 am

Translation of STELLA to FORTRAN

Post by K.Simons@rhbnc.ac.uk (Kenneth L »

In response to SD1372 and SD1376,

Dear Dierdre,
I built a Stella to Pascal compiler that works for
some Stella models (it does not allow queueing elements,
and it is limited to common functions). I used it to
compile the World3 model as part of the Beyond the Limits
software that I created. If Pascal code will do for your
job, email me and well see if it can work for your model.

Regards,
Ken Simons

Department of Economics
Royal Holloway
University of London
Egham, Surrey TW20 0EX
UK

office: +44 1784 443909
fax: +44 1784 439534
email: K.Simons@rhbnc.ac.uk
Tom Fiddaman
Senior Member
Posts: 55
Joined: Fri Mar 29, 2002 3:39 am

Translation of STELLA to FORTRAN

Post by Tom Fiddaman »

Ive solved translation problems a few too many times, so I hope I can
provide some advice.

Its fairly straightforward to translate even a fairly big model into a
programming language manually. Its something you only want to do once,
though - not every time the model is updated.

>From STELLA, set your equation preferences to display in order of
execution, and save your equations as a text file. See the sample below,
which is a stock (y) with an outflow (z) at a fractional rate that varies
with time (x). The equations come in two sections, by order of execution
(otherwise youd have to sort them manually). The overall idea is to
initialize the stocks and flows, and then iterate calculating stocks then
flows until the time us up.

{initialization equations}
x = GRAPH(Time) (1990, .1), (2000, .2), (2010, .15)
INIT y = 120
z = x*y

{runtime equations}
y(t) = y(t-dt) + (-z)*dt
x = GRAPH(Time) (1990, .1), (2000, .2), (2010, .15)
z = x*y

To make this into code, youd have to do the following:

- Declare all variables (if language requires it) and decide whether to
store values only at the current point or as arrays over time.
- Add a main loop that first calls the initialization routine, then the
runtime routine.
- Write a routine to handle graph interpolation and translate graph data
pairs into some kind of array format.
- Rewrite graph statements in the runtime section to eliminate redundant
data on the shape of the relationship.
- Get rid of the time subscripts on stocks like y(t), or convert them to
arrays.
- Add a variable to integrate time (i.e. time = time+dt).

In generic code, this might look like:

main()
t = initialize()
while t < final_t
t = calculate()

initialize()
time = 0
x_graph[ ] = 1990,.1,2000,.2,2010,.15
x = GRAPH(time,x_graph)
y = 120
z = x*y
return time

calculate()
{stocks}
time = time + dt
y = y + (-z)*dt
{flows}
x = GRAPH(time,x_graph)
z = x*y
return time

graph(x,points)
...

A lot of this can be done by clever search-and-replace using MS Words
advanced features or a code editor with GREP capabilities like BBedit. For
example, its easy to automatically remove all the (t-dt)s on stocks this
way. You can automate the whole procedure using Word macros (a bit of a
pain) or PERL.

There are a few pitfalls.
-In the versions of ithink I own, switches that create uniflows,
non-negative stocks, and discrete-valued table functions are not documented
in the equations, so you either have to avoid these in your model or
manually figure out where they apply.
-Non-negative stocks and some discrete functions (ovens, queues, etc.)
create implicit feedback links that are not apparent in the model
equations, so you should avoid these or implement them according to the
ithink technical documentation.
-If you want to use integration methods other than Euler (e.g. RK4) you
need to get more complex.
-Theres no field delimiter between equations and documentation in ithink
equation text files, so be careful you dont accidentally translate some
documentation into structure if youre using automatic tools.

If youre going to Fortran for speed or huge models, you might look into
Vensim instead. It runs at half-c speeds interpreted, and can run compiled
to c easily for computationally intensive work. DYNAMO is also quite fast.
If its connectivity you need, you might explore running your model in
Vensim as a .DLL or with dynamic data exchange (assuming youre using
windows).

Hope this helps.

-Tom

****************************************************
Thomas Fiddaman, Ph.D.
Ventana Systems http://www.vensim.com
34025 Mann Road Tel (360) 793-0903
Sultan, WA 98294 Fax (360) 793-2911
Tom@Vensim.com http://home1.gte.net/tomfid/
****************************************************
JohnMcNeil
Junior Member
Posts: 2
Joined: Fri Mar 29, 2002 3:39 am

Translation of STELLA to FORTRAN

Post by JohnMcNeil »

I have had some success translating Stella models into Excel. Using rows as
the dTs and incorporating some formulas and a little code to control
calculations goes a long way. Of course all the graphing and other functions
are built in and the latest version will label cells as they go in and out of
range.

Speed is surprising and transparency of the underlying structure is good.

Starting off in Stella is better though: the diagramming helps.

From: JohnMcNeil <JohnMcNeil@aol.com>
Mary Ellen Verona
Newbie
Posts: 1
Joined: Fri Mar 29, 2002 3:39 am

Translation of STELLA to FORTRAN

Post by Mary Ellen Verona »

Check out http://kabir.cbl.umces.edu/PLM/Welcome.html -
They have a system for translating STELLA to C++.

Mary Ellen Verona mverona@mvhs1.mbhs.edu 301-650-6520 FAX: 650-6692
///////////////////////////////////
||<< Maryland Virtual High School of Science and Mathematics >>||
||<< Blair Magnet Program, 313 Wayne Avenue, Silver Spring, 20910 >>||
||<< http://mvhs1.mbhs.edu/mvhs.html >>||
///////////////////////////////////
Karsten Kuchenbecker
Newbie
Posts: 1
Joined: Fri Mar 29, 2002 3:39 am

Translation of STELLA to FORTRAN

Post by Karsten Kuchenbecker »

Hello Deirdre,
(this is my first posting to this mailing list. If I have done something
wrong or this is not the right place for this posting: sorry to all of you)

At our Institute for Economic Research at the University of Karlsruhe,
Germany, we are using the iTHINK (=STELLA) software in the field of
transport infrastructure planning and assessment.
Especially for my dissertation thesis I try to combine a system dynamics
model with our (in C written) transport model. The transport model is
highly disaggregated (over 1000 regions for Europe, infrastructure networks
with over 10,000 links, etc.) and need to be run on a UNIX workstation.
Both models should interact together. They should interchange data and run
automatically over time. So I have to translate the ithink equation system
too.

Half a year ago I asked HPS for informations on this topic. I got the
following answer from Bruce Hannon (thanks for the fast supply of
information!) which may help you, Deirdre:

>DEAR KARSTEN,
>I AM AWARE OF TWO COMPILERS OF STELLA EQUATIONS.
>1. MADONNA. A VERY NICE PROGRAM THAT RUNS ON WINDOWS OR MAC, SPEEDS THE RUN
>TIME IMMENSELY OF COURSE (BY A FACTOR OF 100 OR MORE), PROVIDES SENSITIVITY
>TESTING, CURVE FITTING OF THE MODEL TO GIVEN DATA, ETC. CONTACT "Tim
>Zahnley" <
zahnley@ibm.net>
>I DONT KNOW IF HE PLANS A UNIX VERSION.
>2. TOM MAXWELL HAS WRITTEN A PROGRAM THAT TAKES THE STELLA EQUATIONS FOR
>MODEL WITHIN A SPATIAL CELL AND COMPILES IT FOR ALL CELLS IN A GIVEN SPACE.
>WE HAVE USED IT EXTENSIVELY (SEE:
>http://blizzard.gis.uiuc.edu/htmldocs/TES.html ). THE PROCESS ALLOWS ONE TO
>VARY THE CELL SIZE AND THE TIME STEP ACROSS THE SPACE. IT IS FOR ALL KNOWN
>PLATFORMS. PARAMETER AND INITIAL VALUE DATA IS SUPPLIED FROM MAPS OF THE
>SPACE. TOMS PAGE IS: http://kabir.umd.edu/SMP/MVD/C0.html


Unfortunately both programs seem not to fit well with my research needs:
As far as I know Tom Maxwells program is made primarily for really big
biological models and Madonna is not available to the UNIX platform. But
perhaps I am totally wrong and someone else in this mailing list can give
you better informations. I am sure you can get also more information from
Tim Zahnley and Tom Maxwell. It would be the best to contact them directly.

Well, perhaps there is another possibility available for you:
For my PhD research we have developed (and are still developing) our own
piece of translation software. A friend of mine is a researcher in the
field of computer science at the University of Karlsruhe. With his
knowledge on compilers and programming languages he has developed an
ithink-to-C-cross-compiler for free.
The main idea was to design the system dynamics model itself with ithink
and translate it afterwards to enlarge it for the use with disaggregated
data and to program it for the interaction with other models.
This compiler takes the ithink equation set and produces equivalent C
source code. All data is stored in seperate data and index files. So you
are able to import/export data directly from/to external data sources. The
split of data and model in seperate files is also very usefull if you want
to enlarge the number of array elments additionally (ithinks array
possibilities and performance are limited). A tcl/tk interface is added so
that it is possible to run and analyse the model on the unix machine. (this
interface can also be used as a programming interface).

The compiler is still far away from being a complete software package. It
is still an experimential prototype version and until now only used for my
own research work. There are still a lot of problems, especially because of
the ithink equation syntax. It is written for human readers and not for
machines. So it is quite difficult (and sometimes impossible) to get all
necessary information from the equation file. Two-dimensional arrays are
not implemented yet as well as some internal functions. Because of his own
PhD work my friend has stopped the software development for a while.
Further software development will be continued at our Institute. The
software (as it is) is freeware (nevertheless copyrights of some parts,
like the freeware compiler toolbox "cocktail", which was used to program
the compiler, have to be considered). But there should be no problem to
send you the program on a trial out basis. If you (or someone else in this
mailing list) are interested feel free to send me an email to:
kuchenbecker@iww.uni-karlsruhe.de

Greetings

Karsten Kuchenbecker
From: Karsten Kuchenbecker <kuchenbecker@iww.uni-karlsruhe.de>
Locked