What’s new in Calcpad 5.8 and later?

In the last several months, Calcpad was subjected to continuous improvement, driven by the efforts of its developers and the help of the community. In this post, we will make a short review of the most important changes.

1. Modules

If you have a simple and short worksheet, it is definitely easier to keep it all in a single file. But imagine that you have to build an entire library for design of timber structures. And each worksheet should start with identical content for selection of materials and cross sections. Then, it would be better to put this part in a separate module and reference it from all other worksheets. Now, you can do this in Calcpad, using the following code:

#include filename.cpd

If the file is in the same folder, you can enter only the filename, otherwise you must specify the full path. This is better than copying one and the same text in all worksheets. You can also select which part of the module is local and global by inserting the respective keywords: “#local“, “#global“. Local parts will not be included into the external module.

2. String variables and macros

This is a good way to further organize your code and avoid repetitions at a module level. You can assign a piece of code to a string variable. Then, you can insert it wherever you like, by simply writing the name instead of the whole text.

The difference between variables and macros is that macros have parameters, and variables don’t. On the other hand, both can be inline of multiline. All names must and with the “$” symbol and can include letters, numbers and underscore “_”. You can use the following syntax:

Inline string variable:

#def variable_name$ = content

Multiline string variable:

#def variable_name$
'content line 1
'content line 2
'...
#end def

Inline macro:

#def macro_name$(param1$; param2$; ...) = content

Multiline macro:

#def macro_name$(param1$; param2$; ...)
'content line 1
'content line 2
'...
#end def

This is a really powerful feature that can save a lot of work. It allows you to expand the Calcpad functionality with features that never existed before. For example, you can create Html “shortcodes” for faster and better formatting:

#def b$(x$) = <strong>x$</strong>
#def i$(x$) = <em>x$</em>
#def sup$(x$) = <sup>x$</sup>
#def sub$(x$) = <sub>x$</sub>
#def err$(x$) = <span class="err">x$</span>
'Usage:
'<p>b$(Check): i$(f)sub$(yk) = err$(2) kN/cmsup$(2)</p>

Result:
Check: fyk = 2 kN/cm2

Another interesting example is the following general design check routine:

#def check$(x$; x_max$)
    #if x$ ≤ x_max$
        'The check is satisfied:'x$'≤'x_max$'✓
    #else
        '<p class="err">The check is not satisfied:'x$'&gt;'x_max$'✖</span></p>
    #end if
#end def

Usage:

σ = 280MPa','σ_lim = 250MPa
check$(σ; σ_lim)
τ = 120MPa','τ_lim = 0.58*σ_lim
check$(τ; τ_lim)

Result:
σ = 280 MPa , σ lim = 250 MPa
The check is not satisfied: σ = 280 MPa > σlim = 250 MPa
τ = 120 MPa , τ  lim = 0.58·σ lim = 0.58·250 MPa = 145 MPa
The check is satisfied: τ = 120 MPaτ lim = 145 MPa

Modules, string variables and macros are parsed at preprocessor stage. Calcpad scans the code and rewrites the names with the actual contents. As a result, it generates “unwrapped” source code. If you check the respective checkbox you will see it in the output window, instead of the calculation results. It will also show automatically if any error occurs in preprocessing.

3. Angle units

In the latest versions, native angle units are available for use:
°, deg – degrees;
– minutes = degrees/60; 
– seconds = minutes/60;
rad  – radians = π / 180 degrees;
grad  – grades = 10 / 9 degrees;
rev – revolutions = 360 degrees.

You can convert between angle units and combine them with others to create composite ones like “rad/s” and “rev/min“. Angle units are accepted by all trigonometric functions. They override all other settings, made in the Calpad UI or by using “#deg“, “#rad” and “#grad” keywords in the code. Inverse trigonometric functions can optionally return the results with units, if you define the variable: “ReturnAngleUnits = 1“.

4. C/C++ style operators

Some relational operators in Calcpad use mathematical notation symbols like , , , , which are not available on computer keyboards. Although Calcpad provides buttons for insertion, this is still slower than typing. That is why, we introduced an alternative C/C++ like syntax that uses only keyboard symbols as follows:

OperatorSymbolAlt syntax
equal==
unequal!=
less or equal<=
greater or equal>=

The alternative symbols are replaced with the original ones while typing.

5. Calcs suppression with #noc

Previously, there were only two visibility control keywords regarding equations:
#equ – displays the equation and the result;
#val – displays only the final result without the equation.

Recently, we added one more option:
#noc – displays only the equation, without the result;

It not only hides the results, but also suppresses the calculations. This allows you to use Calcpad as a simple equation editor for faster typing of formulas. Unlike MathML and LaTeX, which use special syntax, Calcpad formats raw, simple text equations. At the end, you can export the entire content to MS Word or Libre Office with MathType/Math formatted equations.

6. Integration with Tanh-Sinh quadrature

Double exponential quadrature (Takahasi & Mori, 1974) is one of the most efficient numerical integration algorithms. In our tests, it demonstrated outstanding performance, compared to other popular methods: Integration-test-results.pdf. It is also adaptive and very accurate. The only problem is that the function must be continuous and smooth. However, due to its efficiency, we decided to include it as a second method, using the “$Integrate” command.

The original algorithm has been improved further by Michashki & Mosig (2016) and Van Engelen (2022). In Calcpad, we made additional enhancements by precomputing and caching the abscissas and weights.

In all cases, you can continue using the old “$Area” command, which is more general purpose. It is powered by the famous adaptive Gauss-Lobatto-Kronrod quadrature by Gander & Gautschi (2000).

7. Improved formatting

Sums, products and integrals are now formatted with the respective large symbol and limits on bottom and top. That gives the reports more professional feel and look. For example:

S = $Sum{(-1)^k/(2*k + 1) @ k = 0 : 1000}
C(n; k) = $Product{(i + n - k)/i @ i = 1 : k}
I = $Integral{x/(e^x - 1) @ x = 0.001 : 10}

are formatted as follows:

8. Input fields defaults

In the previous versions, default values for input fields were specified by clicking the respective question marks in the code. When you saved the file, they were appended consequently at the end. This made uncomfortable using external editors like Notepad++ for writing Calcpad code. After introducing modules and macros, it was almost impossible to match the values with the corresponding input fields.

That is why, we changed the approach and made the default values to be added immediately after the question marks. You must enclose them with curly brackets, like: “a = ? {2}“. You can also override the values inside modules and macros by specifying the values as in the following example:

#include abc.cpd #{4; 5; 6}
d = a + b + c

If abc.cpd has the following contents:

a = ? {1}
b = ? {2}
c = ? {3}

The result will be:
a = 4
b = 5
c = 6
d = a + b + c = 4 + 5 + 6 = 15

9. Custom rounding

You can also override the global rounding settings for certain parts of your code, by using the “#round n” keyword. Replace n with the number of digits after the decimal point (from 0 to 15).

10. Pausing and step by step execution

If you have long calculations, you can pause the solution by pressing the “Pause/Break” key or “Ctrl + Alt + P” from the keyboard. Then, you can resume it with “F5“. Also, you can define breakpoints in your code by using the “#pause” and “#input” keywords. They correspond to two types of breakpoints:
#pause – stops the solution at the current line and displays the avalable results;
#input – stops at themcurrent line and renders an input form.

On the next #input, it will calculate and show the results before the current one and render the next input form. Sometimes, engineers need to see some intermediate results before entering more data. For example, when you design a RC beam, you calculate the required main reinforcement from bending ULS. After that, you select some actual reinforcement and use it further for SLS checks like deflections, crack widths, etc.

11. Performance and optimization

In the last few versions, we made important optimizations to improve Calcpad performance, as follows:

  • UI responsiveness – it is not lagging anymore on large files;
  • text processing and parsing – string splitting is replaced by the more effective memory spans wherever possible;
  • function caching – now it works faster, but consumes much less memory;
  • compiling – “constant folding” was introduced for faster execution;
  • units – units arithmetic performance was enhanced by 20% – 30%.

You can learn more about the new features from the Calcpad documentation:

calcpad-readme.pdf

Published by Calcpad

Hi, my name is Ned. I am a structural engineer with over 20 years of experience in the design of nuclear and industrial facilities, factories, residential and public buildings. I am a fan of engineering, mathematics and computer programming. I spend a lot of time for developing of useful tools that help structural design.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: