Thermal conductivity problem

Thermal conductivity problem - Half practice, half practical problem... but definitely not working, help appreciated :P - Messages

#1 Posted: 6/18/2018 6:09:19 PM
fedeghi

fedeghi

25 likes in 112 posts.

Group: User

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 (62 KiB) downloaded 60 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.
#2 Posted: 6/18/2018 9:42:24 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

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 (229 KiB) downloaded 41 time(s).

#3 Posted: 6/19/2018 5:38:23 AM
Nicolae Olaru

Nicolae Olaru

1 likes in 115 posts.

Group: User

Wrote

... 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.
#4 Posted: 6/19/2018 6:53:39 AM
fedeghi

fedeghi

25 likes in 112 posts.

Group: User

Wrote

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.

Wrote

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.
#5 Posted: 6/19/2018 9:16:09 AM
Arie

Arie

93 likes in 285 posts.

Group: User

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 (65 KiB) downloaded 32 time(s).
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#6 Posted: 6/19/2018 9:54:48 AM
Arie

Arie

93 likes in 285 posts.

Group: User

Wrote


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
#7 Posted: 6/19/2018 8:45:12 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

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 (94 KiB) downloaded 36 time(s).

#8 Posted: 6/19/2018 9:17:04 PM
CBG

CBG

77 likes in 312 posts.

Group: User

A small modification

PROVA_CONDUZIONE.png

PROVA CONDUZIONE TERMICA_bkp_CBG.sm (224 KiB) downloaded 39 time(s).


Best Regards

Carlos
#9 Posted: 6/20/2018 10:39:03 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

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 (344 KiB) downloaded 38 time(s).
#10 Posted: 6/20/2018 11:29:01 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

Few more things at the end.



Document.PNG
#11 Posted: 6/20/2018 12:13:05 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

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
#12 Posted: 6/20/2018 12:40:29 PM
CBG

CBG

77 likes in 312 posts.

Group: User

Hello Jean

I think there is an error in the internal radios.


PROVA_JEAN.png



Best Regards

Carlos
#13 Posted: 6/20/2018 4:04:24 PM
fedeghi

fedeghi

25 likes in 112 posts.

Group: User

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
#14 Posted: 6/20/2018 4:50:05 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

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 (390 KiB) downloaded 34 time(s).
#15 Posted: 6/20/2018 5:48:44 PM
fedeghi

fedeghi

25 likes in 112 posts.

Group: User

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:
Wrote

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.
Wrote

... 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.
Wrote

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.
Wrote

Wrote

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...
Wrote

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

#16 Posted: 6/20/2018 10:03:18 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

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 (61 KiB) downloaded 43 time(s). ... stuff about eval(,)

Project PROVA CONDUZIONE TERMICA_bkp_CBG [Jean].sm (391 KiB) downloaded 40 time(s). ... refreshed
#17 Posted: 6/20/2018 11:16:50 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

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

#18 Posted: 6/21/2018 1:18:42 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

... 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 (402 KiB) downloaded 54 time(s).
  • New Posts New Posts
  • No New Posts No New Posts