Skip to main content
1-Visitor
June 5, 2013
Question

Making API Getvalue call faster

  • June 5, 2013
  • 1 reply
  • 3094 views

I'm a regular user of Mathcad for more than 15 years, and I'm really pushing hard to get more engineers to use it instead of Excel. Recently I started to work on a fluid solving software that allows you to expand its component library using Excel add-ins. I managed to convince the developers to create a similar interface for Mathcad using the API. This works, but it slows down the flow solver tremendously.

Does anybody perhaps know why it is so slow, or how to speed things up?

The developers found that the "GetValue" call does not always succeed, so they had to keep calling "Recalculate" until "GetValue" suceeds. This will definitely slow down the process. Also, my suspicion is that a lot of the processing time is to update the visual display of the Mathcad woksheet. Any way one can "switch off" the graphics but still keep the Mathcad object alive?

I'll really appreciate any comments. I would hate to traslate all the Mathcad work into Excel just to get a faster solver...

1 reply

1-Visitor
June 5, 2013

You have to show an example. No one knows how you use the API. Here are a few examples, they can help you:

Re: how to save graphs using VB code.?

If you write: MathcadApplication.Visible = False

Mathcad will not be visible.

wfuls-21-VisitorAuthor
1-Visitor
June 5, 2013

Since I'm not the developer of the flow software, I won't be able to show the exact code, but I can try to explain the way I understand they implemented it. They use .NET for the programming. The image below shows the interface:

MC+component.png

MC+in+Fnx.JPG

The flow software has various components like pipes, pumps, valves etc which one links together and solve for the flow conditions. The MC link they developed enables one to describe the physical characteristics of the custom component in MC. The solver will call the MC worksheet using SetValue (or SetComplex) for each of the inputs defined (like mass flow or inlet pressure). Then it calls Recalculate, and then GetValue (or GetComplex) for the output variables that would then describe the flow characteristics of the compent (like outlet pressure or temperature).

This all works fine, but the turn-around time from setting the inputs to getting the outputs is almost 50 times longer than an equivalent implementation using Excel. This becomes a real issue when doing a transient analysis in 10ms time steps.

The developers have managed to make MC invisible, but that did not help much. It seems the API call "waits" for something before returning the values, or the recalculate call still does a lot of background processing, even though the worksheet itself only contains a trivial summation of the unputs.

I was hoping somone else my have tried something similar and figured out a way to speed up the turn-around time. We have tried the normal and embedded API, and it seems the embedded one is faster.

Hope this makes more sense.

19-Tanzanite
June 5, 2013

Do I misunderstand, or are you calling the MC worksheet from within a solver in Excel, in a way that means the MC worksheet has to be called for every iteration of the solver? That would be really slow, because every iteration you have the overhead of the Windoze API.

Regardless of whether you have put the API calls in a solver loop, you could try putting all the values you need to set in a vector, and calling SetValue only once, rather than many times.