[MBDyn-users] Standard way to have a dynamically updated set of formulas

Pierangelo Masarati pierangelo.masarati at polimi.it
Mon Sep 17 15:09:23 CEST 2018


On 09/17/2018 12:26 PM, Richard Crozier wrote:
> Dear List,
>
> I would like to have some values calculated in my model which are 
> evaluated at run time based on the model state. I would like to 
> calculate a series of expressions whose input are the outputs of other 
> expressions.
What you can do, in the string drive, is to format the string like this:

"( expr1 ; expr2 ; ... ; exprN )"

The outcome will be the result of the last expression.  Then you can do 
something like this:

       force:
           f_rod01,
           absolute internal,
           n_base01,    # node 1
           null,        # node 1 arm
           n_body01,    # node 2
           null,        # node 2 arm
           component,    # three components as separate drives
         string, "( vardist = model::distance(n_base01,n_body01) ; 
varxdist = model::xdistance(n_base01,n_body01) ; Fx = 
2.0*varxdist/vardist )",
         string, "( varydist = model::ydistance(n_base01,n_body01) ; Fy 
= 2.0*varydist/vardist )",
         string, "( varzdist = model::zdistance(n_base01,n_body01) ; Fz 
= 2.0*varzdist/vardist )";

You can be even more synthetic, if you wish.  Of course, you need to 
declare variables in advance.

Sincerely, p.

>
> I'm aware of the string driver where I can do things like:
>
> string,
> "2.0*model::xdistance(n_base01,n_body01)/model::distance(n_base01,n_body01)", 
>
>
> but what if I want to calculate a value in another formula and then 
> use this value in the string expression?
>
> Basically, can I calculate a series of expressions, i.e. do something 
> like:
>
> vardist = model::distance(n_base01,n_body01)
>
> varxdist = model::xdistance(n_base01,n_body01)
> varydist = model::ydistance(n_base01,n_body01)
> varzdist = model::zdistance(n_base01,n_body01)
>
> Fx = 2.0*varxdist/vardist
>
> Fy = 2.0*varydist/vardist
>
> Fz = 2.0*varzdist/vardist
>
>
>       force:
>           f_rod01,
>           absolute internal,
>           n_base01,    # node 1
>           null,        # node 1 arm
>           n_body01,    # node 2
>           null,        # node 2 arm
>           component,    # three components as separate drives
>         string, "Fx",
>         string, "Fy",
>         string, "Fz";
>
> If so what is the syntax? I realise I could probably have a series of 
> drivers, using 'drive drive' that could do this, but is there a 
> clearer way like above where one can simply set out a series of 
> formulas to be evaluates which take as input previously evaluated 
> variables? Somehting like the plugin variables?
>
> Thanks!
>
> Richard
>

-- 
Pierangelo Masarati
Professor
Dipartimento di Scienze e Tecnologie Aerospaziali
Politecnico di Milano



More information about the MBDyn-users mailing list