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 Lucas_MSA  
#1 Posted : 17 November 2021 17:52:00(UTC)
Lucas_MSA

Rank: Newbie

Groups: Registered
Joined: 17/11/2021(UTC)
Posts: 2
Brazil
Location: Rio de Janeiro

Was thanked: 1 time(s) in 1 post(s)
Hello everyone!

I'm writting a program for oblique flexo-compression and flexo-tension in reinforced concrete sections that generates the interaction diagram, but the calculation is very very slow.

I tried everything to spped things up a little, some modifications worked to some extent but the overall calculation time is yet completely impractical. I will try to explain a little how the alghorithm works and will annex the worksheet for those would dedicate their precious time trying to help me, to whom a thank very much in advance.

The program basically works finding the roots for f(ɑ;x.0) where ɑ is the incliantion of the neutral axis and x.0 is its depth relative to the uppermost point of the section, as in the image below.

FLEXAO OBLIQUA.PNG

Since it is a two variable function problem, what I do is that I use a loop to generate values of ɑ between 0 and 2π and then solve the function for each ɑ value to find its respective x.0 and then use the values of ɑ and x.0, using the secant method that I wrote myself because the interval where x.0 (the root) is not known and I need to make the interval larger in the case that the root is'nt in the first guess, to find the resisting moments of the section in the x and y axis and plot them to generate the interaction diagram.

As I said before I tried everything, changed the optimization to numeric, I put the whole program under a single line(), eliminated as much loops as I could, eval()"ed" the s**t out of everything, but it stiil takes more than 5 minutes to calculate using only 63 values of ɑ and I'm going to need much more than that for more complex sections. Plus, I will need to add more iterative routines for calculating the steel area for section with dual simmetry and things tend to get much worse.

So, I attached the worksheet and hope that someone will be able and willing to help me. Thanks in advance!

FLEXO TRACAO E FLEXO COMPRESSAO OBLIQUAS CORRIGIDO 0.33 AFTER ERROR EVAL.sm (269kb) downloaded 20 time(s).
thanks 1 user thanked Lucas_MSA for this useful post.
on 18/11/2021(UTC)

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

Offline Razonar  
#2 Posted : 17 November 2021 20:04:59(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,356
Uruguay

Was thanked: 815 time(s) in 516 post(s)
It is difficult to know when to use eval and when not, as sometimes it actually slows down the program. However, where you may always have to use it is with stack, augment, max and min. The code has a couple of those functions without eval, including a fairly hidden one where you put eval (max) -min, change that to eval (max-min).

Another detail to correct would be not to call f (x) so many times, because to extract f (x) [k] it actually evaluates all the lines of f (x).

There could be other calls to f (x) that could be stored in intermediate variables to extract its components.

In the main loop of the solver, try to evaluate f only once, in this case for xmid, instead of for x1 and x2, exchanging the values ​​of f1 and f2 when necessary.

Finally he takes the calculation of the flexures out of the loop.

Maybe an independent function for only the first component of f can speed up the process even more, but I don't know how linked the 6 variables of f are.

At the moment the fastest and most efficient purely numerical algorithm available in SMath for nonlinear systems of equations is al_nleqsolve. You can check it here.

This version is around 30 sec for the 63 steps.

FLEXO TRACAO E FLEXO COMPRESSAO OBLIQUAS CORRIGIDO 0.33 AFTER ERROR EVAL.sm (277kb) downloaded 8 time(s).

Best regards.
Alvaro.

Edited by user 17 November 2021 20:06:32(UTC)  | Reason: Not specified

Offline Razonar  
#3 Posted : 17 November 2021 20:50:45(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,356
Uruguay

Was thanked: 815 time(s) in 516 post(s)
Ten secondonds, more or less, with a variation of the newton raphson method from here.

FLEXO TRACAO E FLEXO COMPRESSAO OBLIQUAS CORRIGIDO 0.33 AFTER ERROR EVAL V2.sm (274kb) downloaded 36 time(s).

Best regards.
Alvaro.
thanks 1 user thanked Razonar for this useful post.
on 18/11/2021(UTC)
Offline Lucas_MSA  
#4 Posted : 17 November 2021 23:26:31(UTC)
Lucas_MSA

Rank: Newbie

Groups: Registered
Joined: 17/11/2021(UTC)
Posts: 2
Brazil
Location: Rio de Janeiro

Was thanked: 1 time(s) in 1 post(s)
Thank you so very much Alvaro!

I will go over point by point and if you allow me I have a couple of questions.

It is difficult to know when to use eval and when not, as sometimes it actually slows down the program. However, where you may always have to use it is with stack, augment, max and min. The code has a couple of those functions without eval, including a fairly hidden one where you put eval (max) -min, change that to eval (max-min).

I wiil certanly do that. I have two versios of the code using eval() the first with leees eval() and a secondo with more. As I was kind of desperate to solve the issue I inseted eval in every little thing in the second, but the calculation actually became slower so I annexed here the first one.

Another detail to correct would be not to call f (x) so many times, because to extract f (x) [k] it actually evaluates all the lines of f (x).


There could be other calls to f (x) that could be stored in intermediate variables to extract its components.

The problem is that a need to call the function in every step of the loop in order to find the root and I wasn't able to find a way around that. The for autside of the main function was a while that a changed in order to spped up the calculations, adicionally there were two whiles but I combined them in just one in order to do the same.

In the main loop of the solver, try to evaluate f only once, in this case for xmid, instead of for x1 and x2, exchanging the values ​​of f1 and f2 when necessary.

I didn't get this one, because I need to calculate f(x) in the interval in order to find the root. I think that the best way is to change the Algorythm for finding the roots like you did and finding a way around of expanding the interval for the case that the root isn't between the first guesses of x1 and x1.

Finally he takes the calculation of the flexures out of the loop.

Done!

Maybe an independent function for only the first component of f can speed up the process even more, but I don't know how linked the 6 variables of f are.

If you look in the upper parte of the spreadsheet you will see that every part of the code was once separated, but I joined everything since from x2x' y2y' forward everything became a function of ɑ and x.0 and since they were separate behind the line() they kept calling each other and that would slow the calculation a lot, and it was slow before I implemented the algorithm to find the roots. So I kind o had to join everything to improve the calculation time.

I had this same program written in Mathcad 15 when I was in college, but I'm rewriting it in Smath bacause it is free to use and offer so much possibility now. In Mathcad I was able to "transform" a two variable function by evaluating it through a second function that gives value to one of the variables. Like we have f(ɑ;x) would became g(x) assigning values to ɑ, in the case of this program in particular I used a vector of ɑ values and vectorized f(ɑ;x), but I wasn't able to do the same on Smath. If this were possible it would eliminate the external loop and improve the calculation time even further.

I'm sorry for flooding you with issues and once again thank you so very much for your help.
Offline Razonar  
#5 Posted : 18 November 2021 08:07:58(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,356
Uruguay

Was thanked: 815 time(s) in 516 post(s)
Originally Posted by: Lucas_MSA Go to Quoted Post

There could be other calls to f (x) that could be stored in intermediate variables to extract its components.

The problem is that a need to call the function in every step of the loop in order to find the root and I wasn't able to find a way around that. The for autside of the main function was a while that a changed in order to spped up the calculations, adicionally there were two whiles but I combined them in just one in order to do the same.


I'm talking about avoid multiple calls to "the function" when you can store its value into an intermediate result. You can see that in the fmid, f1, f2 in your root procedure.

Originally Posted by: Lucas_MSA Go to Quoted Post

I didn't get this one, because I need to calculate f(x) in the interval in order to find the root. I think that the best way is to change the Algorythm for finding the roots like you did and finding a way around of expanding the interval for the case that the root isn't between the first guesses of x1 and x1.


After you get an interval with sign change, you need to call only once the function for bisection and two for newton raphson (minimun, with a rough derivativa).

Finally, you can try to implement NR or al_nleqsolve for the system f(x,alpha) for solve both at same time, but given that f is very extense, I have not idea if that could be faster / accurate enough than discretizing alpha and then solve for x.

Best regards.
Alvaro.
Users browsing this topic
Guest
Similar Topics
Sometimes VERY slow calculation time in program loops (Questions)
by themzlab 15/02/2017 17:52:49(UTC)
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.