A Formal Approach for Modeling and Simulation

Yves A. Papegay

INRIA/COPRIN

Motivation

A Communication in the Wolfram Blog

PhD in 1991 on “Symbolic Tools for Dynamics Modeling".

Modeling is a symbolic activity

Modeling is descriptive

({{Symbol, Description, Unit}, {l, Length at rest, m}, {k, stiffness, N.(m^(-1))}, {b, damping, N.(m^(-1)).s}, {m, Mass, kg}, {x, Position, m}, {v, Speed, m.(s^(-1))}, {F, Force, N}})({{g= 9.81}, {F=P +(Subscript[F, spring]) +(Subscript[F, damp])}, {P=m g}, {(Subscript[F, spring])=-k (x-l)}, {(Subscript[F, damp])=-b v}, {F=m.γ}, {v=(dx/dt)}, {γ=(dv/dt)}})

Modeling is descriptive

Implementation requirement : managing a “context”

What are the variables involved in the model ?

What are the equations involved in the model ?

"Pendulum1"

variableList["Pendulum"]
equationList["Pendulum"]

"Pendulum2"

CurrentValue[nbo,{TaggingRules,listVariables}]
CurrentValue[nbo,{TaggingRules,listEquations}]

Modeling is based on variables

Implementation requirement : accessing extended symbols

(Subscript[x, y])=5

?(Subscript[x, y])

y=0

(Subscript[x, y])

Clear[(Subscript[x, y]),(Subscript[x, 0])]

Modeling is based on objects

Implementation requirement : mimicking object-oriented programming

Model["Pendulum",listVars->{Variable[l,Unit->m],Variable[k, N.(m^(-1))],...},listEqs->{Equation[Variable[g, Unit->N.(m^(-1))]==9.81,Type->Constant] ...}]

model

ViewModel[model]

Modeling is based on programs

Modeling led to simulation

Conclusion

Code

BeginModel[s_String]:=(CurrentModel=s; variableList[s]={}; equationList[s]={};)
EndModel[]:=(CurrentModel=None;)
DeclareVariable[s_]:=AppendTo[variableList[CurrentModel],s]
DeclareEquation[s_]:=AppendTo[equationList[CurrentModel],s]

ViewModel[Model[s_String,r__Rule]]:=OpenerView[{Row[{Style["Model",Bold],s},"   "],Column[Map[ViewModel,{r}]]}]
ViewModel[Rule[id_,l_]]:= OpenerView[{Style[id,Italic],Column[Map[ViewModel,l]]}]
ViewModel[Variable[id_]]:=Row[{Style["Variable",Bold],id},"   "]
ViewModel[Equation[expr_]]:=Row[{Style["Equation", Bold],expr/.Variable[any_]:>any},"   "]

model=With[{vars={l,k,b,m,x,v,F,g,(Subscript[F, spring]),(Subscript[F, damp]),γ}},Model["Pendulum",listVars->Map[Variable,vars],listEqs->Map[Equation[#[[1]]==#[[2]]]&,{g->9.81`,F->P+(Subscript[F, damp])+(Subscript[F, spring]),P->g m,(Subscript[F, spring])->-k (-l+x),(Subscript[F, damp])->-b v,F->m.γ,v->(d/dt)[x],γ->(d/dt)[v]}]/.Map[#->Variable[#]&,vars]]];