How to do System Dynamics simulations / diagrams in Mathematica?
The limitation you quote is not a general limitation of Modelica. It is possible to define a Modelica component that has a variable number of inputs/outputs. Typically the number of inputs/outputs is then given by a parameter to that component.
For example, the following component has one input but 2 outputs, varied with the parameter nout
:
model SIMO "Single input, multiple output"
parameter Integer nout=2 "Number of outputs";
RealInput u "Connector of Real input signal";
RealOutput y[nout] "Connector of Real output signals";
equation
{{{your equations}}}
end SIMO;
I have not used the System Dynamics modelica library, so cannot speak to how they have chosen to implement their interfaces.
It would be fully possible to create your custom models in Mathematica by defining equations from the ground up, and then simulating them using for example NDSolve
. This would however require a significant amount of manual labor.
If you want to stay in the Wolfram product universe, SystemModeler would be the way to go. It allows you to simulate and interact with models from Mathematica, using a Mathematica package bundled with the product.
An overview of features of the Mathematica package, called WSMLink
, can be found at http://wolfram.com/system-modeler/features/analysis-mathematica.html.
Documentation to see how the package actually is used is found at http://reference.wolfram.com/system-modeler/WSMLink/guide/WSMLink.html.
Update:
The SystemDynamics library mentioned in the original question is now available for download in a version compatible with Wolfram SystemModeler at the bottom of this blog post: http://blog.wolfram.com/2013/06/11/energy-resource-dynamics-with-the-new-system-dynamics-library-for-systemmodeler/
One possible alternative might be Control Systems in Mathematica.
With Control Systems you can carry out analysis, design, and simulation of time control systems.
For an example here an automated house heating system controlled by a thermostat. (Sorry. I really tried to use the drawing tools for a nifty graphic, but...alas...i'm not even able to draw a simple house, so I count on your imagination)
Here I show how to analyze the controller and its performance in a closed loop:
system = TransferFunctionModel[(0.5/((0.2 s + 1) (2 s + 1))), s];
pid = pid = PIDTune[system, Automatic, "PIDData"];
cloop = pid["ReferenceOutput"];
or = OutputResponse[cloop, UnitStep[t], {t, 0, 4}];
p = Plot[%, {t, 0, 4}, PlotRange -> All, Frame -> True,
FrameLabel -> {"t", "y"}, LabelStyle -> Directive[15],
PlotStyle -> Blue]
Using a PID controller instead reduces the bump a little bit:
pid = pid = PIDTune[system, "PID", "PIDData"];
On Woflram blog in '11 Andrew Moylan wrote two very exciting and amusing posts on stabilising an inverted pendulum (segeway) using Control Systems and with decent animations. (http://blog.wolfram.com/2011/01/19/stabilized-inverted-pendulum/)
Hope that this was informative for you. I know that this is not at all visual modeling, but the principles are the same.
Using Modelica for System Dynamics
The way to go for doing System Dynamics (i.e. continuous time, equation based simulations describing the changes of a system's states by flows—essentially reducing a system of higher order ODEs to a system of first-order ODE) within the Wolfram universe is to turn to System Modeler which is built upon Modelica—a simulation language for cyber-physical systems—as Malte has mentioned in his answer.
Downsides of the System Dynamics library
Unfortunately, some of the "downsides" mentioned do indeed apply to the before mentioned System Dynamics library, which is purely build using information or signal flows as I have explained in this tallk(→ minutes 06:28 to 10:00) at the Wolfram Technology Conference 2020. This forfeits a lot of Modelica's powerful features. To give an example, modeling a mass outflow from a stock as an information input, as it is done in that library, means that we cannot leave that connector unconnected in case there is no outflow from the stock. So we will need a special class for a stock having no outflow which is rather cumbersome—a reason why the library is rather unheard of within the system dynamics community.
A new Modelica library for System Dynamics
A lot of the flexibility of Modelica is tied to the use of acausal connectors for physical connections (e.g. the mass flows in System Dyanmics). There is now a new, free library available in the System Modeler Libaray Store: Business Simulation Library (BSL). It makes use of acausal connectors in implementing System Dynamics and offers a lot of the convenience known from dedicated SD tools.
The example of a process of social diffusion given in the OP (e.g. the bass diffusion model of new product adoption) is included as an example in the library, which models the closely related process of epidemic spread in a SIR model:
As you can see, the process of diffusion is modeled as a compact component Diffusion
(e.g. becoming_infected). You can see how it is implemented in the documentation.