Skip to content

Commit

Permalink
fix linearfile for linearization()
Browse files Browse the repository at this point in the history
  • Loading branch information
arun3688 committed Aug 10, 2021
1 parent 8a6cf80 commit b02cd1f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/OMJulia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1044,12 +1044,19 @@ function linearize(omc)
# println(linearexpr)
sendExpression(omc, linearexpr)
omc.resultfile = replace(joinpath(omc.tempdir, join([omc.modelname,"_res.mat"])), r"[/\\]+" => "/")
omc.linearmodelname = join(["linear_",omc.modelname])
omc.linearmodelname = "linearized_model"
omc.linearfile = joinpath(omc.tempdir, join([omc.linearmodelname,".mo"]))

# support older openmodelica versions before OpenModelica v1.16.2 where linearize() generates "linear_modelname.mo" file
if(!isfile(omc.linearfile))
omc.linearmodelname = join(["linear_", omc.modelname])
omc.linearfile = joinpath(omc.tempdir, join([omc.linearmodelname, ".mo"]))
end

if (isfile(omc.linearfile))
loadmsg = sendExpression(omc, "loadFile(\"" * omc.linearfile * "\")")
if (!loadmsg)
return sendExpression(omc, "getErrorString()")
return println(sendExpression(omc, "getErrorString()"))
end
cNames = sendExpression(omc, "getClassNames()")
buildmodelexpr = join(["buildModel(",cNames[1],")"])
Expand All @@ -1068,11 +1075,11 @@ function linearize(omc)
linearMatrix = getLinearMatrix(omc)
return linearMatrix
else
return sendExpression(omc, "getErrorString()")
return println("Building linearized Model failed: ", sendExpression(omc, "getErrorString()"))
end
else
errormsg = sendExpression(omc, "getErrorString()")
println(errormsg)
return println("Linearization failed: ","\"" , omc.linearfile,"\"" ," not found \n", errormsg)
end
end

Expand Down

0 comments on commit b02cd1f

Please sign in to comment.