Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline fedeghi  
#1 Posted : 19 June 2018 00:09:19(UTC)
fedeghi


Rank: Advanced Member

Groups: Registered
Joined: 14/09/2013(UTC)
Posts: 90
Italy

Was thanked: 24 time(s) in 16 post(s)
Hi there, I'm not sure if this is the right section of the forum, hopefully yes.
Don't know if there is some area in the forum where newbies like me post newbie-like questions, and then some Yoda out there shows the path... that would be the case of this post :P

Starting from the beginning: just to practice a little bit with programming in SMath (I'm NOT an expert at all), I wanted to set up a small calculation file to determine temperature profiles into big pipelines equipped with internal refractory linings and external insulation layers.
It's both a programming exercise for me, and (in case I succeed) a handy tool for office work..
So, I started preparing the attached file.

PROVA CONDUZIONE TERMICA_bkp.sm (63kb) downloaded 38 time(s).

Basic elements of the file are:
* There are four layers of internal refractory (1 to 4)
* Layer 5 is steel
* Layers 6 and 7 are external insulation
* In case a layer is missing, its thickness is set to zero.
* A database o materials is defined, and conductivity is interpolated between known data (supplied by lining fabricators).

The logic behind is:
1) Input general data
2) Select materials and thicknesses
3) Program loops from a trial linear temperature profile, updating conductivities at each loop, since conductivity is a function of temperature itself... that's the reason for looping.
4) Equivalent thermal resistance is calculated
5) Total heat flux is calculated
6) Trial temperature profile is updated backwards...

... or at least, that was my initial goal
:'(

I found out that the "while" iterations will take A LOT of memory, even if in my mind this problem seems not so demanding in terms of resources.
This is the reason why the "while" loop is temporarily controlled by a maximum number of iterations.
I wanted to add a numerical residual check, in order to break the "while" when residuals where small enough, but I had to begin debugging, so at the moment i'm using the variable "counterlimit" to stop the loop.
It came out that, with counterlimit set to 3 (or below, but in that case results are not yet good enough..), Smath runs the calculation in 20 sec... If counter is set to 4 or above, it runs for minutes (and I always stop it manually).

This said..... why such increase in execution time? Does anybody understand where am I missing something and why is this calculation so demanding, only if counterlimit is increased?
What bothers me the most, is that calculation time does not increase proportionally with the "while" counter number, even if the dataset is not increase in dimension while iterations proceed...
If somebody is willing to dig a little bit into this file, I will be glad to learn something from some expert user!

Thank you
Ciao!


ps: I can see that the conductivity calculation, as I implemented it, is kind of messy (a matrix of materials made up of vectors, used to interpolate conductivity for each material at each loop).... but honestly speaking I couldn't find a better way to fit conductivity equations into (remarkable!) Davide Carpi Comboboxlist plugin.
I will try to store equations as a string, recall it from the database and cook it back again as a formula with "num2string"... Never tried this approach, but it's worth a test or two.

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Jean Giraud  
#2 Posted : 19 June 2018 03:42:24(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Honestly, I'm lost in there. The project is so messy, it lacks sound preparation.
Your Rint 0 generates "division by zero" easy to imagine that Rint may not be
exactly 0 ... 10^-12 is very close to 0.
On the other hand, the while loop must be "Numeric" NOT Optimiz
Also, part of the while loop does not like Units.
My Smath version 6179
Would be wise to work unitless.

Will be back ... Jean

PROVA CONDUZIONE TERMICA_bkp.sm (230kb) downloaded 24 time(s).

Offline ola_nicolas  
#3 Posted : 19 June 2018 11:38:23(UTC)
ola_nicolas


Rank: Advanced Member

Groups: Registered
Joined: 21/11/2017(UTC)
Posts: 112
Romania
Location: Olt county

Was thanked: 1 time(s) in 1 post(s)
Originally Posted by: fedeghi Go to Quoted Post
... If somebody is willing to dig a little bit into this file...


Benvenuto.

I also try Jean Giraud's opinion that I was lost in a jungle, although the project does not seem to be a big one. I think you should first make a logic scheme and then structure the project accordingly. Otherwise, all the best.
Offline fedeghi  
#4 Posted : 19 June 2018 12:53:39(UTC)
fedeghi


Rank: Advanced Member

Groups: Registered
Joined: 14/09/2013(UTC)
Posts: 90
Italy

Was thanked: 24 time(s) in 16 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
Your Rint 0 generates "division by zero" easy to imagine that Rint may not be exactly 0 ... 10^-12 is very close to 0.

I see that Rint=0 his coming from a modification in the calculation of the internal radius of the first layer of lining; it was Rint[1 in my file, resulting in a non-zero radius.
I see Rint[2 in yours, so first element of the vector is set to zero while second element stores the radius.

Originally Posted by: Jean Giraud Go to Quoted Post
On the other hand, the while loop must be "Numeric" NOT Optimiz
Also, part of the while loop does not like Units.
....
Would be wise to work unitless.

Is there a way to understand during debugging if and why the units are creating the problem?


In any case, I understand that the file itself is still too much of a messy draft, I need to find some time to organize it better (and with some comments/explanation too), and in case post an updated draft.
Offline alyles  
#5 Posted : 19 June 2018 15:16:09(UTC)
alyles


Rank: Advanced Member

Groups: Registered
Joined: 23/03/2016(UTC)
Posts: 276
United States

Was thanked: 91 time(s) in 57 post(s)
I didn't really get a chance to go through the math at all, but I did optimize run time of the current implementation. I used the eval() function in the lamda_t function definition. Took evaluation from 20 seconds to 0.25 seconds on my machine.

Untitled.png
PROVA CONDUZIONE TERMICA_bkp_alyles.sm (66kb) downloaded 17 time(s).
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
Offline alyles  
#6 Posted : 19 June 2018 15:54:48(UTC)
alyles


Rank: Advanced Member

Groups: Registered
Joined: 23/03/2016(UTC)
Posts: 276
United States

Was thanked: 91 time(s) in 57 post(s)
Originally Posted by: fedeghi Go to Quoted Post

Is there a way to understand during debugging if and why the units are creating the problem?



I know Jean has an aversion to using the built-in unit system within SMath, but I use it frequently without issue. I've not noticed a decrease in performance when using units vs. defining programs to be unitless. I personally think the use of units in calculation is extremely useful in quickly validating general arithmetic and results. Working with units can sometimes be a pain in the sense that when generating equations/programs you may often run into issues where units don't match (and calculations cannot complete) or end results don't make sense. Again, I find this useful in understanding all the different components of the equations/programs I generate.
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
Offline Jean Giraud  
#7 Posted : 20 June 2018 02:45:12(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: fedeghi Go to Quoted Post
Is there a way to understand during debugging if and why the units are creating the problem?

Work 1rst modular like in the attached.
Most confusing are different but equivalent maths that output different unit system.
What other simple maths will output another/same unit system or "Units don't match".

Units_Units.PNG
Units_Rejected.PNG

PROVA CONDUZIONE TERMICA_bkp [0].sm (95kb) downloaded 18 time(s).

Offline CBG  
#8 Posted : 20 June 2018 03:17:04(UTC)
CBG


Rank: Advanced Member

Groups: Registered
Joined: 14/10/2015(UTC)
Posts: 308

Was thanked: 77 time(s) in 58 post(s)
A small modification

PROVA_CONDUZIONE.png

PROVA CONDUZIONE TERMICA_bkp_CBG.sm (225kb) downloaded 21 time(s).


Best Regards

Carlos
Offline Jean Giraud  
#9 Posted : 20 June 2018 16:39:03(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: CBG Go to Quoted Post
A small modification


Thanks Carlos for doctoring this project.

1. Refreshed a bit
2. Few more things at the end.
3. "L" is confusing as not explained ... considered "unary"
4. Two pests [in green] wrt to units.
5. The last 4 "clear" removed from program [avoid red]

Wait and see for Originator to comment/complement

Jean

PROVA CONDUZIONE TERMICA_bkp_CBG [Jean].sm (345kb) downloaded 20 time(s).
Offline Jean Giraud  
#10 Posted : 20 June 2018 17:29:01(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
Few more things at the end.


Document.PNG
Offline Jean Giraud  
#11 Posted : 20 June 2018 18:13:05(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
Few more things at the end.


... maybe the last brick in the wall, if so desired:
I'm only slightly pregnant of understanding the discontinuity
@ [770] ... infinitesimal film is not discontinuous.
Easy to fillet, Hermite tool box will do.

Fillet.PNG
Offline CBG  
#12 Posted : 20 June 2018 18:40:29(UTC)
CBG


Rank: Advanced Member

Groups: Registered
Joined: 14/10/2015(UTC)
Posts: 308

Was thanked: 77 time(s) in 58 post(s)
Hello Jean

I think there is an error in the internal radios.


PROVA_JEAN.png



Best Regards

Carlos
Offline fedeghi  
#13 Posted : 20 June 2018 22:04:24(UTC)
fedeghi


Rank: Advanced Member

Groups: Registered
Joined: 14/09/2013(UTC)
Posts: 90
Italy

Was thanked: 24 time(s) in 16 post(s)
Hi everybody, thanks for all the efforts and support.

I will review all the contributions one by one, I just had the chance right now to go through the posts now quickly..

The use of eval() is somehow new to me, I will look at it's implications, since I understand that it has improved a lot the execution time.
Yesterday morning I spent some minutes again testing my file and became suspicious at how I implemented lambda.
It looks like I was accessing to that database matrix a lot of time.
Now I see that a great improvement has come from this eval() function...

Will go through the details and keep you posted.

Thanks again for the support
Offline Jean Giraud  
#14 Posted : 20 June 2018 22:50:05(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: CBG Go to Quoted Post
Hello Jean

I think there is an error in the internal radios.


Thanks Carlos: my mistake from copy/paste, delete 'm'
Forgot the unit system bug that does not output 0m, 1m.
That bug was reported long time ago, may have corrected in 6671.
Added: Hermite sub-space fillet.

Jean

Project PROVA CONDUZIONE TERMICA_bkp_CBG [Jean].sm (391kb) downloaded 17 time(s).
Offline fedeghi  
#15 Posted : 20 June 2018 23:48:44(UTC)
fedeghi


Rank: Advanced Member

Groups: Registered
Joined: 14/09/2013(UTC)
Posts: 90
Italy

Was thanked: 24 time(s) in 16 post(s)
Ok, I took my time to study all the files you posted and read all the replies again and again.
I'm happy to see that the "while" was messy, not commented properly, etc etc... but it could work (with some help)!
And also the lambda function and the way I defined the database...

First of all, going to your contributions, now I see what Jean meant with one of the first replies:
Originally Posted by: Jean Giraud Go to Quoted Post
On the other hand, the while loop must be "Numeric" NOT Optimiz

I needed to right click and set the while to Numerical optimization?
Cattura.PNG

Setting my original file this way, makes the loop work quickly (shame on me, I wasn't even aware of such setting...)

Also Alyses hint has helped me to understand that the symbolic evaluation was the problem, and that some different setting should be implemented.
Originally Posted by: alyles Go to Quoted Post
... I did optimize run time of the current implementation. I used the eval() function in the lamda_t function definition...

Iinfact, the following files by other users did not use the eval() function, so I was kind of lost, until I found that right click setting...
So, in the end, if my understanding is correct, eval() and right-click numeric optimization setting are equivalent, isn't it?

Now, going to Carlos contribution, thanks, I see that you found the way to make all the "if" and "while" loops scalable, meaning that I can add / subtract layers of lining.
The length of arrays, the number of loops will now automatically adapt... that was one of my goals, except that I got stuck in the execution time problem, so stayed simple with seven fixed layers of materials. Thank you.
Originally Posted by: CBG Go to Quoted Post
A small modification
And by the way, I see that your file uses a plugin with a lot of functions I did not know (that cases() function, for sure I will be using it a lot in the future....)


Jean, what command are you using to generate this kind of matrix? What is the sintax, I mean,to define Q(w) or T.ext (°c) and obtain results without Units? Looks like it is a Custom Function again.
Originally Posted by: Jean Giraud Go to Quoted Post
Originally Posted by: Jean Giraud Go to Quoted Post
Few more things at the end.

Document.PNG


Thanks guys, I definitely learnt something (to say the least) from this thread.

Federico



Ps: by the way, totally on the same page here, but I see Jean's point in running unitless with his example he provided too...
Originally Posted by: alyles Go to Quoted Post
I personally think the use of units in calculation is extremely useful in quickly validating general arithmetic and results. Working with units can sometimes be a pain in the sense that when generating equations/programs you may often run into issues where units don't match (and calculations cannot complete) or end results don't make sense
Offline Jean Giraud  
#16 Posted : 21 June 2018 04:03:18(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: fedeghi Go to Quoted Post
ean, what command are you using to generate this kind of matrix? What is the sintax, I mean,to define Q(w) or T.ext (°c) and obtain results without Units? Looks like it is a Custom Function again.


That, mon ami, is too simple doing ... like this:
1. from the matrix palette, insert a 2 rows by 5 cols
2. in 2nd row, paste results from above results,
backspace on units Rint ... bacspace on all 'm'
3. in 1rst row, type trial(Alt+248C) => trial(°C)
4. λ(,) ... kg*m/s^3*K from result above

This type of matrix project collection is natural, fast
and fully accessible by more maths from other demands.
It has nothing to do with the plugin "Table region"

About your other question: optimiz mode, eval there is no clear 1/1 answer.
In some advanced maths, the RHS , i.e: the function must be set in eval(,) mode.

Observe: Genfit Rational Type J_6
1. Minimize(XY,f,φ,β) .... some eval(,) within overall numeric
2. φ(x,β,f,n) ... strictly symbolic
3. eval(Φ^-1)*d ... eval(,) within numeric

The λ(,) is 1/1 similar to the LMTD [Log Mean Temperature Difference]
otherwise related to diameters ratio. I found no maths from suppliers.

Cheers Frederico ... Jean

Genfit Rational Type J_6.sm (62kb) downloaded 21 time(s). ... stuff about eval(,)

Project PROVA CONDUZIONE TERMICA_bkp_CBG [Jean].sm (392kb) downloaded 22 time(s). ... refreshed
Offline Jean Giraud  
#17 Posted : 21 June 2018 05:16:50(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: fedeghi Go to Quoted Post
So, in the end, if my understanding is correct, eval() and right-click numeric optimization setting are equivalent, isn't it?

Not so simple !
In the just attached Hermite Polyline, open the first collapsed area.
Observe eval(,) in the subspace module, this is a case of local definition.

Jean

Offline Jean Giraud  
#18 Posted : 21 June 2018 19:18:42(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
... Data Table added. No problem to construct and display.
Couldn't reduce the height of the two first rows ... Ah !

TableFrederico.PNG

Project PROVA CONDUZIONE TERMICA_bkp_CBG [Jean].sm (403kb) downloaded 35 time(s).
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.