cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Making API Getvalue call faster

wfuls-2
1-Newbie

Making API Getvalue call faster

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...

7 REPLIES 7

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.

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.

RichardJ
19-Tanzanite
(To:wfuls-2)

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.

Wim Fuls wrote:

The developers found that the "GetValue" call does not always succeed, so they had to keep calling "Recalculate" until "GetValue" suceeds.

Try to turn off the automatic calculation in the document and save it.

Richard Jackson wrote:

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.

I think they can't do that. SetValue() not working with matrices as I know. You can't pass a set of values ​​at the same time.

What interface do they use? Mathcad.IMathcadApplication2 ? In any case, Mathcad is not designed for fast computations. It ideology - is the mathematical form of the document. Computing speed decreases because of rendering support. If the result and the computation time is more important to you then use what is appropriate for that anymore.

I think they can't do that. SetValue() not working with matrices as I know.

Sure it does.

I've been doing it wrong. Yes, it works, thank you.

Thanks Viacheslav and Richard for your responses. It seems I'll have to be content with the speed if I wish to integrate MathCAD into the solver. I think I'll do that until speed really becomes an issue, and only then re-code the calculations in someting else.

Hopefully one day Prime will get to the same level as MC15, and if they still plan to include the option to compile a MC worksheet, then that could be faster. However, at the rate Prime is developing right now, I doubt that will happen in this decade.

Side-note: I'm REALLY disappointed with PTC's Prime. I don't understand why I need to pay maintenance on something that is about 7 years old in terms of development (MC15), just because the newer version is seriosly inferior. I'm getting more and more inclined to switch to Maple...

Top Tags