CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   CFX (https://www.cfd-online.com/Forums/cfx/)
-   -   How to write an expression with an if condition statment? (https://www.cfd-online.com/Forums/cfx/167120-how-write-expression-if-condition-statment.html)

visitor February 23, 2016 22:49

How to write an expression with an if condition statment?
 
Can anyone help on this please?

Basically a thermostat which reads temperature at a coordinate; 0,0,0.7 this is in meters, and than control a heater. Heater is in the sub-domain at; Sources>Equation Sources>Energy>Source 7e6 W/m3

basically get temp at 0,0,0.7,
if temp <= 300 K then 7e6
else 0

Thanks in advance

honcho62 February 24, 2016 02:13

You can find this stuff in the tutorials. You make a new expression and then write:

if(condition, result when true, result when false)

so for yours that'd be something like this, though I'm not sure about the Temperature@Point stuff:

if(Temperature@Point <= 300 [K], 7e6 [W m^-3], 0)

visitor February 24, 2016 03:23

Thank you for your reply

Will try this out as soon as i get back in compu lab.

Might enter another expression for Point with a definition of e.g. 0,0,0.7

ghorrocks February 24, 2016 05:09

If your simulation is transient then this approach will work. It should cause the heater to turn on and off over time.

If your simulation is steady state this will never converge, so it is not a suitable approach.

visitor March 14, 2016 05:24

Didn't get a chance to try this myself, but a friend of mine tried it and got the following errors;

The following unrecognized names were referenced; Temperature, point.


point was defined under a separate expressions with coordinates;
0,0,0.7

Thanks

-Maxim- March 14, 2016 05:31

I think you can't use an expression to create that point. I would try to insert a 'Source Point' in Pre with those coordinates and use that as location

visitor March 15, 2016 06:52

Well, the Point issue is resolve be assigning the Source Point with a name Point, with coordinates. But, the error message remains with Temperature; CEL error
"The following unrecognized name was referenced: Temperature.

hamidciv March 15, 2016 11:19

I think you should use the probe function like below:

if(probe(T)@location<=300[K],7e6,0)

hope it helps

-Maxim- March 16, 2016 02:06

Quote:

Originally Posted by visitor (Post 589791)
Well, the Point issue is resolve be assigning the Source Point with a name Point, with coordinates. But, the error message remains with Temperature; CEL error
"The following unrecognized name was referenced: Temperature.

How about you post the expression and we help you to find the error?
I mean the error message you get is pretty clear...

visitor March 22, 2016 22:42

Hello everyone,

The following were tried, no errors were seen, also nothing happened regarding changes in water temperature.

Following expression was entered to plot temperature at the coordinate Point
(Probe(Temperature)@Point), using Monitor at Solver Output.


This expression is the thermostat, this should switch heater on.
if(Probe(Temperature)@Point <= 350[K],7e6[W m^-3],0[W m^-3])

Point was a Source Point with coordinates, renamed as Point.

Thanks

ghorrocks March 23, 2016 16:34

Have you checked what the temperature is at your point? If the temperature is >350K anyway it would not activate the heater.

Goenitz February 10, 2020 07:23

Quote:

Originally Posted by ghorrocks (Post 591370)
Have you checked what the temperature is at your point? If the temperature is >350K anyway it would not activate the heater.

how to apply if statement for an expression to function at certain lengths
for instance Rate1=A* e^(-Eact/R/T) [mol kg^-1 s^-1]
so to active this expression from 5mm-15mm I use this:

Cond if= if(0.005<=x<=.015, Rate=Rate1,0)

P.S: Rate1 has no variable 'x' in its expression and has different units.

Following question is:

I want to use Rate for calculation of fluxes. So defining new expression (Cond if) is good or should I use this:
Rate=if(0.005<=x<=.015, Rate=A* e^(-Eact/R/T),0)
Or
Rate=if(0.005<=x<=.015, A* e^(-Eact/R/T) ,0)

Goenitz February 10, 2020 08:12

To overcome my problem I use this
Actually, The rate expression is like this

Rate=A* e^(-Eact/R/T)*washcoat [mol m^-2 s^-1]

where washcoat is 0.32 [g m^-2]

So I left the Rate as it is but changed the washcoat expression
washcoat=if(0.005[m]<x,0.32,0) [g m^-2]

However it doesn't allow to create expression like this:

washcoat=if(0.005[m]<x<0.015[m],0.32,0) [g m^-2]

which I really want

Goenitz February 10, 2020 08:22

I think it is solved
I used this expression
if (0.005[m]<=x&&x<=.015[m], 0.40 ,0) [g m^-2]


All times are GMT -4. The time now is 17:21.