|
[Sponsors] |
November 20, 2023, 11:47 |
CFX if and statement
|
#1 |
New Member
Join Date: Apr 2022
Posts: 26
Rep Power: 4 |
Hi I am trying to write a nested IF statement as an expression in CFX.
Particularly I am getting errors as I would like to include the && (AND) portion - sorry I have already read the reference guide section on expressions This is the equation that I would wish to include, thank you. Thank you. T_vc = 0.34[s] T_vr = 0.15[s] T = 1[s] |
|
November 20, 2023, 17:45 |
|
#2 |
Super Moderator
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 17,872
Rep Power: 144 |
if(t<=T_vc,[Top function],if(t<=T_vc+T_vr,[Middle function],if(y<=T,0[units?],[undefined!])))
Easy.
__________________
Note: I do not answer CFD questions by PM. CFD questions should be posted on the forum. |
|
November 20, 2023, 20:41 |
|
#3 |
New Member
Join Date: Apr 2022
Posts: 26
Rep Power: 4 |
Thank you! This was a massive help and I am really very grateful.
if(t<=tvc,0.5 - 0.5*cos(pi*t/tvc),if(t<=tvc+tvr,0.5 + 0.5*cos(pi*(t-tvc)/tvr),if(t<=te,0[ ] ,0))) I realised that this needs to be periodic e.g. 5s, could I ask how would a mod function be initialised? |
|
November 20, 2023, 20:56 |
|
#4 |
Super Moderator
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 17,872
Rep Power: 144 |
t_cycle = mod(t,5[s]))
Then change the equation to check t_cycle rather than t. Also note your last nested if() statement is not required, both cases evaluate to 0 so you might as well remove it.
__________________
Note: I do not answer CFD questions by PM. CFD questions should be posted on the forum. |
|
November 21, 2023, 05:38 |
|
#5 |
New Member
Join Date: Apr 2022
Posts: 26
Rep Power: 4 |
Thank you, sorry a last question I hope!
I tried using the above and also this simple example for another post Cycletime = mod(t,11[s]) HeaterPower = if(Cycletime<1[s],100[W],0[W]) When I go to the variable in expressions either Cycletime and HeaterPower and plot for t > 1s e.g. 4s would I see the period function repeated in the plot? I don't seem to obtain that. |
|
November 21, 2023, 06:13 |
|
#6 |
Super Moderator
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 17,872
Rep Power: 144 |
Please post what you do obtain then. Make sure you have enough resolution in the plot to resolve the transients - 0.1[s] resolution would be suitable.
__________________
Note: I do not answer CFD questions by PM. CFD questions should be posted on the forum. |
|
November 21, 2023, 06:38 |
|
#7 |
New Member
Join Date: Apr 2022
Posts: 26
Rep Power: 4 |
Actually I managed to find out what was going on, you were right and had to zoom out to see it was repeating every 5 seconds instead, so I needed to set the time period to 1sec!
mod(t,1[s]) This works a treat and was really a massive help, so sincerely my thanks |
|
|
|