4 Ways to Decrease Calculation Time for PTC Mathcad Gateway

In the minds of the general public, driving a car seldom extends beyond the basic principles of operation: use a key to start the car, know where the gas and brake pedals are, Park-Revers-Neutral-Drive, go the speed limit (maybe), fill up the tank when gas is low. To most, driving a car is simply a matter of utilization, but to those who know the inner workings of vehicles, driving a car is about optimization. Over and above simple operation, proper maintenance and care and configuration is necessary to produce the best results. It’s no longer a matter of getting from point A to point B, but of doing so in a way that minimizes fuel consumption and maximizes the life of the vehicle and its parts. Even being diligent in the basics can make a big difference in fuel economy: keeping tires at the correct pressure, changing the air filter, replacing old spark plugs.

In similar fashion, while PTC Mathcad Gateway may seem like magic to the end user, with her only concern being inputting values and getting results returned, there are many moving parts “under the hood” that can be optimized to make this process more efficient. The core of PTC Mathcad Gateway is in the name: PTC Mathcad. Every time an end user submits inputs on the client browser, the server is opening the specified worksheet in PTC Mathcad, calculating with the new inputs, and then closing the worksheet. Knowing this is critical. If a worksheet takes a long time to calculate on its own, you can expect it to take a long time to get results back to the client browser. Of course, this is inevitable; PTC Mathcad and PTC Mathcad Gateway users will often have complex worksheets that require some hefty computing power and time. But in most cases, worksheets can be streamlined and optimized such that their calculation time is minimized. The following are some tips to help that process:

1. Less is more. Oftentimes, PTC Mathcad users will try to fit as much as possible into one worksheet, having one worksheet that performs analyses on many different parts or systems. While this makes sense in some cases, it can lead to “heavy” worksheets. When it comes to PTC Mathcad Gateway, it is best, where possible, to break calculations into coherent and self-contained chunks that are smaller than the combined whole. Of course, this may not be possible, but if you find yourself trying to use a “Swiss Army Knife” worksheet, with many tools built into one behemoth worksheet, consider a “divide and conquer” strategy instead.


2. Replace rather than rebuild. If you are using programming structures within your worksheet to manipulate or build matrices, it is important to initialize the matrix at the beginning rather than build it element-by-element in a loop. Take the following trivial function as an example:


Because A does not yet exist, for every pass through the “for” loop, A is being rebuilt with a slightly larger memory allocation. This takes time. However, if we initialize A at its full size and fill it with zeros before entering the loop, A is not being rebuilt; rather, the zeros are being replaced one-by-one. This is less time-intensive.



When the matrices are small, the time savings are negligible, but with very big matrices, the difference can be drastic.


3. Function over form. One of the best things about PTC Mathcad is how it allows engineers to document their calculations, with plots seamlessly incorporated into the calculations, allowing for easy and elegant visualization of results. The sweet spot of both form and function, documentation and calculation. But PTC Mathcad Gateway is different. Those plots are no longer being seen by the end user, and they only add to the computation that has to be done by the server when PTC Mathcad Gateway calls that worksheet. So rather than having the worksheet populated by plots that won’t get seen, include your plots in the PTC Mathcad Gateway results instead. This concept can be extended to anything in the worksheet that will not be seen in the client browser. Evaluating calculations (especially matrices!) in the worksheet that are not passed as Outputs from the worksheet to PTC Mathcad Gateway only adds time without adding benefit. The savings here are not enormous, but in certain situations, it can add up.

4. No silver bullets. Hopefully these best practices will help shave time off of your PTC Mathcad Gateway calculations, but it is important to remember that these tips are not one-size-fits-all, nor is one change likely to exponentially reduce the calculation time. Most lengthy calculations can be streamlined, but the best way to do that will vary depending on how the calculations are set up. The better you know the mechanics of how your car works, the better you will be at optimizing its performance. In similar fashion, having a better understanding of how PTC Mathcad works will enable you to optimize the performance of PTC Mathcad Gateway. That’s a not-so-subtle way of suggesting that you should look into training options for PTC Mathcad.