@@ -1276,7 +1276,7 @@ function analyzeStructurally(equations, params, unknowns_indices, deriv, unknown
12761276 equation_code = nothing
12771277 end
12781278
1279- if newStateSelection || useKinsol && false # # Disable simulation for 0.7
1279+ if newStateSelection || useKinsol # && false ## Disable simulation for 0.7
12801280 generateCode (newStateSelection, useKinsol, params, realStates, unknownsNames, deriv, equations, componentsIG, assignIG, Avar, Bequ, VSizes, ESizes, invAssign, sortedEquations, equation_code, unknowns)
12811281
12821282 return nothing , nothing , nothing , nothing , nothing , nothing , nothing , nothing , nothing , nothing , nothing , nothing , nothing , nothing , nothing
@@ -1511,7 +1511,7 @@ function generateCode(newStateSelection, useKinsol, params, realStates, unknowns
15111511 func *= " # Set parameters\n "
15121512
15131513 for (p, v) in params
1514- pName = replace (string (p), " ." , " _" )
1514+ pName = replace (string (p), " ." => " _" )
15151515 func *= " " * pName * " = " * string (v) * " \n "
15161516 if logFDAE
15171517 func *= " " * " @show $pName " * " \n "
@@ -1523,7 +1523,7 @@ function generateCode(newStateSelection, useKinsol, params, realStates, unknowns
15231523 vNames = makeList (unknownsNames, 1 : length (assignIG), Avar)
15241524
15251525 for i in 1 : length (sortedEquations. Vx)
1526- xName = replace (string (vNames[sortedEquations. Vx[i]]), " ." , " _" )
1526+ xName = replace (string (vNames[sortedEquations. Vx[i]]), " ." => " _" )
15271527 func *= " $(xName) = _x[$i ]\n "
15281528 if logFDAE
15291529 func *= " " * " @show $xName " * " \n "
@@ -1532,7 +1532,7 @@ function generateCode(newStateSelection, useKinsol, params, realStates, unknowns
15321532
15331533 for i in 1 : length (sortedEquations. Vderx)
15341534 if sortedEquations. Vderx[i] > 0
1535- der_xName = replace (string (vNames[sortedEquations. Vderx[i]]), " ." , " _" )
1535+ der_xName = replace (string (vNames[sortedEquations. Vderx[i]]), " ." => " _" )
15361536 func *= " $(der_xName) = _der_x[$i ]\n "
15371537 if logFDAE
15381538 func *= " " * " @show $der_xName " * " \n "
@@ -1549,8 +1549,8 @@ function generateCode(newStateSelection, useKinsol, params, realStates, unknowns
15491549 # func *= " " * "println(\"next\")" * "\n"
15501550 for (solution, solved) in equation_code
15511551 pp = prettyPrint (solution)
1552- pp = replace (string (pp), " der(" , " (der_" )
1553- pp = replace (string (pp), " der_der_" , " der2_" )
1552+ pp = replace (string (pp), " der(" => " (der_" )
1553+ pp = replace (string (pp), " der_der_" => " der2_" )
15541554 if logFDAE
15551555 func *= " " * " println(\" $pp \" )" * " \n "
15561556 end
@@ -1564,10 +1564,12 @@ function generateCode(newStateSelection, useKinsol, params, realStates, unknowns
15641564 loglnModia ()
15651565 end
15661566
1567+ func *= " time = t0\n "
1568+
15671569 func *= " # Copy state vector and derivative vector to each state and derivative\n "
15681570 for i in 1 : length (realStates)
1569- xName = replace (string (realStates[i]), " ." , " _" )
1570- xName = replace (xName, " this_" , " " )
1571+ xName = replace (string (realStates[i]), " ." => " _" )
1572+ xName = replace (xName, " this_" => " " )
15711573 derName = " der_" * xName
15721574 func *= " $(xName) = _x[$i ]\n "
15731575 func *= " $(derName) = _der_x[$i ]\n "
@@ -1660,8 +1662,8 @@ function generateCode(newStateSelection, useKinsol, params, realStates, unknowns
16601662 @show orgIndexVar
16611663 end
16621664 vName = variables[orgIndexVar[varIndex]] ### [1]
1663- vName = replace(string(vName), ".", "_")
1664- vName = replace(vName, "this_", "")
1665+ vName = replace(string(vName), "." => "_")
1666+ vName = replace(vName, "this_" => "")
16651667 if derOrderVar[varIndex] == 1 ### Fix for higher order needed
16661668 vName = "der_"*vName
16671669 elseif derOrderVar[varIndex] == 2 ### Fix for higher order needed
@@ -1671,7 +1673,7 @@ function generateCode(newStateSelection, useKinsol, params, realStates, unknowns
16711673 if varIndex > 0
16721674
16731675 vName = vNames[varIndex]
1674- vName = replace (string (vName), " ." , " _" )
1676+ vName = replace (string (vName), " ." => " _" )
16751677
16761678 if VSizes[varIndex] == ()
16771679 vIndex += 1
@@ -1718,8 +1720,8 @@ function generateCode(newStateSelection, useKinsol, params, realStates, unknowns
17181720 # e = :(_res[$globalResidualIndex] = $(e.args[1]) - $(e.args[2]))
17191721 end
17201722 pp = prettyPrint (e)
1721- pp = replace (string (pp), " der(" , " (der_" )
1722- pp = replace (string (pp), " der_der_" , " der2_" )
1723+ pp = replace (string (pp), " der(" => " (der_" )
1724+ pp = replace (string (pp), " der_der_" => " der2_" )
17231725
17241726 if logFDAE
17251727 if length (c) > 1
@@ -1751,8 +1753,8 @@ function generateCode(newStateSelection, useKinsol, params, realStates, unknowns
17511753 #=
17521754 (orgIndexVar, derOrderVar) = invertDer(Avar)
17531755 vName = variables[orgIndexVar[varIndex]] ### [1]
1754- vName = replace(string(vName), ".", "_")
1755- vName = replace(vName, "this_", "")
1756+ vName = replace(string(vName), "." => "_")
1757+ vName = replace(vName, "this_" => "")
17561758 if derOrderVar[varIndex] == 1 ### Fix for higher order needed
17571759 vName = "der_"*vName
17581760 elseif derOrderVar[varIndex] == 2 ### Fix for higher order needed
@@ -1762,7 +1764,7 @@ function generateCode(newStateSelection, useKinsol, params, realStates, unknowns
17621764 if varIndex > 0
17631765
17641766 vName = vNames[varIndex]
1765- vName = replace (string (vName), " ." , " _" )
1767+ vName = replace (string (vName), " ." => " _" )
17661768
17671769 if VSizes[varIndex] == ()
17681770 vIndex += 1
@@ -1789,8 +1791,8 @@ function generateCode(newStateSelection, useKinsol, params, realStates, unknowns
17891791 func *= " # Create residual vector for derivatives\n "
17901792
17911793 for i in 1 : length (realStates)
1792- xName = replace (string (realStates[i]), " ." , " _" )
1793- xName = replace (xName, " this_" , " " )
1794+ xName = replace (string (realStates[i]), " ." => " _" )
1795+ xName = replace (xName, " this_" => " " )
17941796 derName = " der_" * xName
17951797 globalResidualIndex += 1
17961798 func *= " " * " _res[$globalResidualIndex ] = _der_x[$i ] - $derName " * " \n "
@@ -1812,7 +1814,7 @@ function generateCode(newStateSelection, useKinsol, params, realStates, unknowns
18121814 loglnModia (func)
18131815
18141816 # Allow editing of FDAE
1815- if false
1817+ if true
18161818 open (" FDAE.jl" , " w" ) do f
18171819 write (f, func)
18181820 end
@@ -1824,7 +1826,7 @@ function generateCode(newStateSelection, useKinsol, params, realStates, unknowns
18241826 end
18251827 end
18261828
1827- FUNC = parse (func)
1829+ FUNC = Meta . parse (func)
18281830 fdae = eval (FUNC)
18291831
18301832 if newStateSelection
@@ -1870,7 +1872,8 @@ function generateCode(newStateSelection, useKinsol, params, realStates, unknowns
18701872
18711873 if length (x0) > 0
18721874 println (" \n Simulate" )
1873- t = linspace (0.0 , 50 , 1000 )
1875+ # t = linspace(0.0, 50, 1000)
1876+ t = range (0.0 , stop= 50.0 , length= 1000 )
18741877 result = ModiaMath. ModiaToModiaMath. simulate (m, t; log= false , tolRel= 1E-5 )
18751878
18761879#= Temporarily removed due to problem with PyPlot
0 commit comments