Loading
/custom-emojis/emojis/contour-map.png
Templates
📚
Articles & Resources
📖
Guides & Support
🌵
CalcTree
Quality control in engineering calculations using Units's banner
📐

Quality control in engineering calculations using Units



💡

This article is about units of measurement, not to be confused with unit tests in software engineering practice!

In engineering practice, we work with measurements representing real-world quantities like distance, time, and force. To quantify these measurements, we assign units to a value. This article aims to compare two approaches to engineering calculations involving units of measurement and explain why one approach is superior.

Definition: A unit of measurement, or unit of measure, is a definite magnitude of a quantity defined and adopted by convention or by law that is used as a standard for measurement of the same kind of quantity. Any other quantity of that kind can be expressed as a multiple of the unit of measurement.

⚖️



The first approach: handling units outside calculations


Let's calculate the distance travelled by a car at 100 km/hr in 37 minutes:





If we use a hand calculator, we must remember that hand calculators only accept numbers and do not understand units. Therefore, we should extract numbers from the quantities when inputting them into the calculator (for example, 100 x 37). After obtaining the calculator's result, we must interpret the unit separately. For instance, if the result is 100 x 37 = 3700, we will need to convert it into a relevant unit of distance.

Spreadsheets are another common calculation tool that requires explicit unit guidelines for inputs and outputs. Authors must provide guidance about the expected input units and intended output units inside a spreadsheet.

The hand calculator example will require a unit conversion applied to the result to be useful. However, as the calculations become more complex and involves multiple steps, handling the units separately from the numbers becomes a cumbersome task prone to errors. In a lot of engineering cases, units might also be factored as part of the equation too, i.e. changing

to

, which can also add to the complexity of the calculation.


A better approach: Unit-aware calculations


If a calculation tool can work with quantities, there will be no need for additional care about units when using the tool. For example, most sophisticated technical computing software like MathCAD, Maple, or CalcTree can perform calculations on quantities, that is, values and their corresponding unit.
With a unit-aware calculation tool, in our example of travelling distance, we can create a calculation that takes a speed measurement in any speed unit and a duration measurement in any time unit and then multiplies them to obtain a distance measurement. The result's unit is derived automatically.


Quality control with units

Unit-aware calculation tools can identify operations that don't make sense, for example, adding one meter to one second:




With such ability, unit-aware tools can assist in two distinct ways with quality control of engineering calculations: 1) ensuring that the units of the inputs are as intended, and 2) dimensional analysis compliance.

Ensuring that the units of the inputs are right
As a simple example, if you set up a calculation to add one meter to a given input distance in a unit-aware tool, you can be confident that:
  1. If a mismatching quantity of, for example, time, is used as input, the calculation tool won't accept it because it doesn't make sense to add one meter to a time quantity and
  2. You can use any length unit you want for the input, as long as it is a measurement of length, without worrying about affecting the calculation.

Dimensional analysis compliance

Definition: In engineering and science, dimensional analysis is the analysis of the relationships between different physical quantities by identifying their base quantities (such as length, mass, time, and electric current) and units of measurement (such as meters and grams) and tracking these dimensions as calculations or comparisons are performed.

📐


With unit-aware calculation tools, every operation must adhere to dimensional analysis requirements. For instance, if a variable is omitted from an expression, leading to a change in the term's unit in the equation, the dimensional compatibility of terms will be violated. The tool will be able to detect this issue.

In engineering calculations, units can be likened to data types in software engineering. Just as in typed programming languages, where you can't assign a string value to a variable of integer type, in unit-aware calculations, you can't use a mismatching quantity in an expression that expects a specific quantity type.


CalcTree Units v2.0

Previously, units were treated as formatting for numbers, and the calculations were not unit-aware. We have released a significant update for the CalcTree application that enables unit-aware calculation across math expressions and Python scripts.

We were among the first to witness the unit quality control in action. We had a calculation template for calculating the neutral axis of a reinforced concrete beam. After updating the Python, we immediately encountered this error in the Python code:

We detected a mismatch in one of the expressions inside the Python script. We immediately located the corresponding line and fixed it!

You can learn more about how you can use Units of measurement in your Python scripts in CalcTree here: Units in Python


👀 See it in action
Here, we calculate the energy needed to displace an object by a distance

while applying a force of

. You can try adjusting the Displacement and Force values using different units:



F
:10 kN



d
:3 m



energy
:30 kJ


You can use any unit for force (F) and any unit for displacement (D):

if you use an incompatible unit, you will receive a unit mismatch error:





CalcTree

CalcTree, the app you're reading this one is a calculation management platform. You can sign-up and build hosted, shareable web apps (complete with an API and a web publishing module) with tools like Python and Spreadsheets. Learn more here!