Simple calculations in numeric input fields

Hi,

it’s really cool that PrePoMax can calculate the value in currently used units when a different unit is provided in numeric input fields. For example, here you input the pressure magnitude of 0.07 bar and it’s automatically converted to 0.007 MPa: PrePoMax & CalculiX - Hydrostatic pressure - YouTube

Would it be possible to support also simple mathematical operations - addition, subtraction, multiplication, division and maybe others (like square roots)? This could be very useful. For example, one could input the hydrostatic pressure directly as ρ * g * H without having to calculate it externally and copy or rewrite the value.

3 Likes

Yes, that would be great, if it’s possible.

It’s the little things like these that makes interfacing with the software a lot quicker; the general user experience effortless and so much more enjoyable.

I think this is doable. But I will have to separate the values in equations from units which is not possible now. And then it will work only for numbers without a unit or with one unit at the end like “1000 * 9.81 * 0.5 Pa” and not for numbers with units like “1000 kg/m^3 * 9.81 m/s^2 * 0.5 m”.

Sure, I think that it will be perfectly sufficient if it works for one unit at the end so that it’s possible to do the calculations first and then convert the units if needed.

Just a few thoughts:

  1. According to my experience, “semi-unitless” calculations is the main source of mistakes in analytical calculations. That is the main reason why such programs as Mathcad or its very good free clone SMath Studio are used for engineering calculations instead of Excel (a.k.a. Exhell). It is too easy to use an improper multiplier in such expressions as "1000 * 9.81 * 0.5 Pa”. My students make such mistakes almost permanently:-(. It is not that difficult to open the Wolfram Alpha web page, paste “1000 kg/m^3 * 9.81 m/s^2 * 0.5 m” text string and obtain the correct result with the proper units. IMHO PPM should not be a substitution of all existing numerical analysis programs.
  2. @FEAnalyst request as well as many other similar requests about PPM customization can be granted by embedding an interpreter of any simple scripting language, like Lua or, preferably, not so simple Python into the PPM. Embedded scripting is the best way for any program to allow a user to add a new feature.

It’s not about eliminating the need for Wolfram Alpha or other math software like that. Pretty much all CAD programs (including FreeCAD) and many CAE programs (like Abaqus) support such simple mathematical operations in numeric input fields for convenience. You are right that a user could confuse units and it’s an important factor to take into account but likely most operations would be on two numbers, e.g. dividing a load value by 2 to account for symmetry. Also, this would be fully optional and you could recommend your students to do the calculations outside of PrePoMax if they are not so skilled in unit handling. A warning could be even added to the documentation.

I agree that scripting would be useful but mainly for other purposes, like automation.

If you do the calculation with a calculator or inside PrePoMax numeric field, you will get the same result (if you use correct or wrong units). So I think that adding this support will not worsen the situation but it can be handy in some situations. After you confirm the equation, it will be evaluated and shown with the unit of the numeric field. But it would be better to support equations with units. How to do that is another problem.

That is another topic that I like but I am not really sure how to do it in a simple matter. Adding Python would be the preferred choice from my side.

1 Like

I am afraid you are not right. First, the results of ‘1000 * 9,81 = 981’ and ‘1000 mm * 9,81 m/s^2 = 9,81 (m/s)^2’ are different if the program can convert units. Second and more important, using units usually allows to avoid primitive mistakes like ‘1000 mm + 9,81 m/s^2’. In this case calculation without units give you mathematically correct (1000 + 9,81=1009,81), but physically senseless result.

The main idea behind my message was quite simple. You are the only developer of the PPM just now. Your free time is limited. There are too many things that can be implemented in the PPM. All feature requests simply must have different priority for you. Otherwise you will spend your all valuable time on implementation of non-critical features (internal calculator is one of such features). At the same time The Big Problems (like PPM version incompatibility) will remain unsolved.

  1. I do know about evaluation of expressions in the numeric input fields of major CAD programs. However, if you analyze changes in mass-market FEA programs like SOLIDWORKS Simulation during several last years, you will see that purely unitless calculations are gradually substituted by more safe calculations with units.
  2. From programming point of view, embedding of a simple calculator into any program is the same as implementing a simple interpreter of numerical expressions in a text form. The easiest way to do so is to embed an existing scripting language into your program. There are a lot of scripting languages for different needs. Some of them are ultra lightweight and used mainly for such simple calculations. Programming is mainly using existing solutions, not reinventing a wheel.

in this cases, may IronPython can make this task less complicated.

In this case you are right. What I wanted to say was that if you compute an equation 1000 * 9,81 using the calculator or inside the PrePoMax’s numeric text box that supports only the expected final unit, the result will be the same. If the user makes a mistake with units, he will make it no matter where he evaluates the equation. The solution would definitely be a unit-aware equation solver as already mentioned.

Yes, it is true, this is not a critical issue and it is also true that my time is limited. But I think a big and important idea of PrePoMax is to be user-friendly. Such features, which users are used from other software, make it user-friendly.

And some features are easier (faster) to implement than others, so I move them up on the priority list :slight_smile:

They have. But I work on PrePoMax mostly as a hobby (aside from some projects that we have). So sometimes I add features that I find interesting, I find challenging or I find nice to have/add.

3 Likes

Just one more suggestion. Some FEA programs always substitute an expression in the input field by the result of calculations. It means, that the user-defined expression like ‘2000 * sin(60)/(pi * 25^2)’ is automatically substituted by 0,8821. Such substitution makes impossible to check the initial formula, so be so kind to keep calculation formula unchanged.

Yes, it’s a very common approach. Abaqus and FreeCAD also use it. It makes sense, especially for short and simple operations (like the aforementioned division by 2) but of course it would be great if PrePoMax could preserve the formulas in input fields. Then displaying the results of calculation could be problematic but maybe there is a relatively simple way to achieve that.

I must say that I also hate it when I enter an equation in the numeric field, and then the equation is evaluated and changed into a value. But the reason is that leaving the equation without a value does not help. So somehow, the equation and the result should be shown to the user. The question is how such UI should look.

Maybe PrePoMax could replace the formula with its result after evaluating but display the formula when a user hovers the mouse cursor over the formula. Or the opposite - display the result when hovering over the formula. Assuming that it’s not too problematic to add a widget that will appear next to the cursor when it’s placed on the input field and then disappear when the cursor is moved away from it.

If both the equation and its result should be shown in the input field itself, the = sign could be displayed between the formula and the result. A user could modify only the formula and the result would be updated accordingly. Of course, this sign would appear only with formulas, not when the value is specified directly.

My intention always is to make Matej’s life a bit less tough :grinning:. In practice, 90% if not 100% formulas are used for load definition. In such a case, the final force/pressure/etc. value is always shown in the graphics window near the load vectors. This value is also always used in the INP-file. Thus, there is no problem for a user to see the result of calculation formula. Due to this reason it would be good enough to stay with the simplest solution, at least for beta-testing stage.

Thank you, Ihor. I appreciate it. I was wondering if some other software has this capability already integrated.

I have made simple tests. I could easily integrate the following support for equations. In each numeric field, an equation without units could be entered. Upon evaluation of the equation, the equation would be replaced by a value, and the equation would be lost.

For the units, I can do the following. Since I know which unit is the default unit of the numeric field, I can remove the default unit from the equation before evaluating. This results in some useful examples, like:

  • 12 MPa / 2 = 6 MPa
  • 12 MPa + 2 MPa = 14 MPa

And some strange examples where units make no sense like:

  • 12 MPa / 2 MPa = 6 MPa
  • 12 / 2 MPa = 6 MPa

So the question is, should the equations support such units (probably not :slight_smile: )?

I think that it would be safest to make the equations operate without any units and apply the unit only to the result of the evaluated equation. So that a user can enter e.g. 12/2 or 12+2 and then MPa is added to the result. Of course, the big disadvantage (already discussed here) is that it will be up to the user to ensure proper inputs. But it might be the only safe solution for now.

it seems right, only multiplication or division factor (unitless) is enough. this may similar to partial factor of material and load multiplication factor in European steel codes, another country or regulations may familiar also.

example given,

  • 12 MPa / 2 = 6 MPa
  • 12 MPa * 2 = 24 MPa

recorded these factor values could be useful to reminding and keep the track at last changes.