CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   after adding if...else,the macro message cannot work (https://www.cfd-online.com/Forums/fluent-udf/144240-after-adding-if-else-macro-message-cannot-work.html)

shuangshuang_liu November 10, 2014 22:38

after adding if...else,the macro message cannot work
 
programs are as follow:
#include "udf.h"
#include "mem.h"
#include "metric.h"
int kount=0;

DEFINE_INIT(my_init,domain)
{
cell_t c;
Thread *t;
C_UDMI(c,t,0)=0;
}
DEFINE_ADJUST(demo_calc,domain)
{
kount++;
Message("\nkount=%d\n",kount);
}
DEFINE_ADJUST(best_point_temp,domain)
{
cell_t c;
Thread *t;
real xc[ND_ND];
// real temp;
/* loop over all cell threads in the domain*/
thread_loop_c(t,domain)
{
/* loop over all cells*/

begin_c_loop(c,t)
{
if((sqrt(ND_SUM(pow(xc[0]-.07,2.),pow(xc[1]-.07,2.),0.)))<.001)
{
C_UDMI(c,t,0)=C_T(c,t);
temp=C_UDMI(c,t,0);
Message("\ntemp=%1f\n",temp);
}
else
{
return;
}
}
end_c_loop(c,t)


}
}

if i get rid of if...else, i can get the values of temp,but i have no idea what's going on with if...else.
please give me a hand!

mvee November 11, 2014 00:00

Hi Liu

Please check your if condition. It may be wrong. To check it, put one message inside if and else. If every time else message is printing then modify if condition properly.
Also check the syntex of if condition...
Best wishes
mvee

pakk November 11, 2014 04:38

What are we supposed to do here?

You show a code, but don't say what is does. But you say that if you remove the if-else (remove what exactly?), you can get values of temp ("get" in which way?).

What is really your question? Do you want an explanation of what the if-else statement does?

(The strange part in the code seems to be the else-part: once a cell is found that is more than 0.001 m away from your point (0.07,0.07), the loop ends and all other cells are ignored. I don't know if that is wrong, because maybe that is exactly what you want your code to do.)

upeksa November 11, 2014 07:13

I think that the problem could be your "return". if the "if" statement is false, the code will real a "return" and will exit you DEFINE_ADJUST function.
Check if your "if" statement is true in somewhere in your case anyway.

shuangshuang_liu November 12, 2014 00:14

u r right, i should tell the code clearly
 
Quote:

Originally Posted by pakk (Post 518484)
What are we supposed to do here?

You show a code, but don't say what is does. But you say that if you remove the if-else (remove what exactly?), you can get values of temp ("get" in which way?).

What is really your question? Do you want an explanation of what the if-else statement does?

(The strange part in the code seems to be the else-part: once a cell is found that is more than 0.001 m away from your point (0.07,0.07), the loop ends and all other cells are ignored. I don't know if that is wrong, because maybe that is exactly what you want your code to do.)

u r right, i should tell the code clearly

shubham jain August 4, 2016 10:26

Hello. I also a problem (different though than mentioned in this post earlier). I am struggling with the syntax for if else conditions. I am saving this as .cse format and then running within CFD-POST.

! open (ID, '>', 'write01.txt');
! $n=10;
if ($n==1) {
! print ID "if command executed\n";
}
else {
! print ID "else command executed\n";
}
! close ID;


Although I want to create polylines using a contour, but in order to find the error, I have shorten it out to this and even this doesnot work with following error.

ERROR
CCL parser failed with message:
invalid parameter name "if (10": contains invalid character '('

This is very very annoying as I am stuck due to this minor thing. If someone could assist me, that would be of great help. Thanks a lot


All times are GMT -4. The time now is 14:20.