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 gth802s  
#1 Posted : 20 December 2023 05:55:54(UTC)
gth802s


Rank: Member

Groups: Registered
Joined: 21/11/2023(UTC)
Posts: 24
United States

Was thanked: 2 time(s) in 2 post(s)
Hi all, I am putting together a quick worksheet to calculate factor of safety against soil liquefaction triggering. As I have been going step-by-step and defining the various variables, I noticed that all the calculations take place more or less instantaneously, whereas the last variable I defined (N1_60cs) seems to take a relatively long time to calculate (approximately 12 seconds on my machine). The worksheet I have so far is attached.

Any thoughts as to what is causing this? Thanks in advance!

Seismic Site Class & Liquefaction Potential.sm (125kb) downloaded 7 time(s).

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

Offline Davide Carpi  
#2 Posted : 20 December 2023 06:50:59(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
Hi,

select all > optimization > numeric

AND EITHER

z:z

z def z.png

OR

z:+line(...)

z plus.png


This is because z:line() is a procedure (something like a function, but for variables); it doesn't evaluates in place on definition, hence is completely calculated from scratch every time you need z, z[j], etc....
Using a + between the definition operator and the line() function, you don't have anymore a procedure; using z:z, it evaluates once from that point onwards.


Seismic Site Class & Liquefaction Potential_num.sm (125kb) downloaded 7 time(s).

Edited by user 20 December 2023 07:23:06(UTC)  | Reason: clarification

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Offline gth802s  
#3 Posted : 20 December 2023 07:01:15(UTC)
gth802s


Rank: Member

Groups: Registered
Joined: 21/11/2023(UTC)
Posts: 24
United States

Was thanked: 2 time(s) in 2 post(s)
Perfect, that works!

Much appreciated as always!
Offline Davide Carpi  
#4 Posted : 20 December 2023 07:23:18(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
You're welcome!
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Offline Jean Giraud  
#5 Posted : 20 December 2023 07:30:22(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)
Your last for/loop, as given, takes 32 s
isolate the three components
a:=eval(a) , b:=eval(Cool ...
timing drops 4 s
Offline Razonar  
#6 Posted : 20 December 2023 08:07:23(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)
Hi. This is another option, without numeric optimizations. You don't need to use line in your calculations. As Davide says, that makes the calculations faster to SMath.

Seismic Site Class & Liquefaction Potential.sm (123kb) downloaded 7 time(s).


Bes regards.
Alvaro.
Offline gth802s  
#7 Posted : 20 December 2023 09:15:47(UTC)
gth802s


Rank: Member

Groups: Registered
Joined: 21/11/2023(UTC)
Posts: 24
United States

Was thanked: 2 time(s) in 2 post(s)
Thank you, Alvaro! I like having the lines because it makes it clearer as to which parameter I am defining. I just didn't realize it was slowing it down so much (although putting + in front of the lines makes the problem go away - sort of a win-win!).

Thanks again.

Originally Posted by: Razonar Go to Quoted Post
Hi. This is another option, without numeric optimizations. You don't need to use line in your calculations. As Davide says, that makes the calculations faster to SMath.

Seismic Site Class & Liquefaction Potential.sm (123kb) downloaded 7 time(s).


Bes regards.
Alvaro.


Offline overlord  
#8 Posted : 20 December 2023 09:16:36(UTC)
overlord


Rank: Advanced Member

Groups: Registered
Joined: 23/07/2013(UTC)
Posts: 1,128
Turkey

Was thanked: 509 time(s) in 339 post(s)
Originally Posted by: Razonar Go to Quoted Post
Hi. This is another option, without numeric optimizations. You don't need to use line in your calculations.

Another issue is, all calculation can be done under one for() loop.
If data matrices is much longer and not 10, this would benefit too.
However, the way it is written look much nicer and cleaner.
Offline Razonar  
#9 Posted : 20 December 2023 18:07:29(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: gth802s Go to Quoted Post
I like having the lines because it makes it clearer as to which parameter I am defining.


Hi. You can eliminate all the for loops using the SMath index vectorization, which work more or less like the same concept in matlab, with cases() for having some visual separation

Clipboard01.png

Seismic Site Class & Liquefaction Potential v2.sm (120kb) downloaded 4 time(s).

Best regards.
Alvaro.
Users browsing this topic
Guest
Similar Topics
Very slow calculation time (Questions)
by Lucas_MSA 17/11/2021 17:52:00(UTC)
Very slow calculation (Questions)
by hrwang 29/04/2021 12:13:23(UTC)
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.