Message Boards Message Boards

TableCurrent with WSMLink

I am trying to use the TableCurrent block in SystemModeler with WSMLink.  The idea is to define a current profine in Mathematica and then use it to trigger the simulation in SystemModeler.  Has anyone done this successfully?  I cannot assign the table of values inside Mathematica.

POSTED BY: Francois du Plessis
3 years ago

The table is a parameter in the TableCurrent block. You can set parameters by using
WSMSimulate["mymodel", {tstart,tend}, WSMParameterValues-> {"tableCurrent.table[1,1"->1,...}]
The drawback here is that you need to allocate the correct size of the table in the model before calling WSMSimulate. WSMParameterValues can only set values that already exist, i.e. it doesn't automatically expand the table matrix.

Thus, a better alternative would be to use the SignalCurrent component. Like this:
 model Model1
   Modelica.Electrical.Analog.Basic.Ground ground;
   Modelica.Electrical.Analog.Basic.Resistor resistor;
   Modelica.Electrical.Analog.Sources.SignalCurrent signalCurrent;
   Modelica.Blocks.Interfaces.RealInput u;
  connect(resistor.n,ground.p) ;
end Model1;
Then you can use WSMInputFunctions to control the input signal from WSMSimulate, like this:
WSMSimulate["Model1", {0, 10}, WSMInputFunctions -> {"u" -> Sin}]
Here, Sin can be replaced with an arbitrary Mathematica function.

I hope this helps.
POSTED BY: Peter Aronsson
3 years ago
Thanks for the response.  I only saw it today.  I still have no success.  I changed the component to SignalCurrent, but keep getting the message:

WSMSimulate::invu: The inputs {u} were not recognized.

Irrespective of the function I provide to the input.  Ideally I would like to use it as 

sim = WSMSimulate["Battery.BatteryDischarge_FdP", {0, 1775},
  WSMInputFunctions -> {"u" -> current}]

Where current is a vector containing measured current data that I want to use to stimulate the simulation.

POSTED BY: Francois du Plessis
3 years ago
WSMInputFunctions takes rules where the targets are functions. If you have measured current data you can create a function with e.g. the Interpolation function in Mathematica.
Also, make sure that you name the input u in your model, the error message indicates that it is not found.
POSTED BY: Peter Aronsson
3 years ago

Group Abstract Group Abstract