CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Parse error in UDF code (https://www.cfd-online.com/Forums/fluent/126287-parse-error-udf-code.html)

stuart230588 November 13, 2013 06:31

Parse error in UDF code
 
Hi,

I am very new to c coding. I am trying to define temperature dependent material properties and have come across a parse error in my code, getting the error:

UDF.c: line 2: parse error

My code at this stage is:

#include “udf.h”
DEFINE_PROPERTY(argon_density, cell, thread)
{
float temp, rho;
temp = C_T(cell, thread);

So it's in the define property line.

Probably simple but can someone point out what I've done wrong and how to correct it?

Thanks,
Stuart

pakk November 14, 2013 07:51

I compiled this without parse error:
Code:


#include"udf.h"
DEFINE_PROPERTY(argon_density, cell, thread)
{
float temp, rho;
temp = C_T(cell, thread);
return temp;
}

Are you sure your code is exactly as you wrote above?

flotus1 November 14, 2013 08:07

Depending on where you copied the code from, the text may contain "invisible" characters that lead to errors during compilation.
Copying the code again for example from this forum post can indeed lead to a better result.

stuart230588 November 14, 2013 08:40

2 Attachment(s)
Thanks for your replies.

However, I am still getting the same parse code error.

I have attached a screenshot and the UDF code that I am trying to interpret. If you could help out that would be much appreciated.

Thanks,
Stuart

pakk November 14, 2013 09:29

I got the same result when I interpreted your code.

I was able to fix it by changing the format from UNICODE to ASCII, and using linux-style Line-endings. I don't know which of those solved the problem.

If you don't know how to do this yourself, I can not give you a clear advice on how to do it, but in that case I hope google can help you or somebody else on this forum.

stuart230588 November 14, 2013 10:03

Thanks for your response Pakk,

How did you convert from UNICODE to ASCII? I found websites online that convert the format but because of my lack of programming knowledge I'm not sure if what it changes it to is correct. Either way it still wouldn't interpret.

How did you convert the line endings to Linux? Is this something that can be done without any Linux programming knowledge or a Linux OS?

Also, could you send the file that you managed to interpret so I can try and figure it out?

Cheers,
Stuart

stuart230588 November 20, 2013 07:17

Does anyone know how to fix this?

pakk November 20, 2013 07:20

What I think could help:
-Open the file in Textpad
-Select 'Save as'
-File format: UNIX
-Encoding: ANSI
-Save the file

stuart230588 November 20, 2013 08:14

This is driving me demented!

When I change the file format from .c to .unix Fluent does not recognise this as a source file. When I change UDF source files to All files in the search box and select the new .unix file I get the same parse code error.

You mentioned linux-style line endings - how do I go about doing that?

Thanks

pakk November 20, 2013 08:20

I never said you should change the extension from .c to .unix...
I gave you an explanation at 13:20 today on how to use Textpad to change your file to unix-style endings.

(In my vocabulary, "unix-style endings" and "linux-style endings" are the same thing. I know that one of them is a wrong term.)

stuart230588 November 20, 2013 08:30

1 Attachment(s)
Ok, I think I must be missing something as I don't have the option to select UNIX file format and ANSI encoding...

What have I done wrong this time?

Sorry to be a pest

pakk November 20, 2013 08:44

You used Notepad, I used Textpad. Notepad does not have this option, Textpad does. ;)

(And Notepad does have the ANSI encoding option, I can see it in your screenshot. But it looks like you already selected that one.)

stuart230588 November 20, 2013 09:18

Thanks for your help Pakk

Downloaded Textpad but still having the parse error after following your steps above.

So frustrating!

pakk November 20, 2013 09:48

Are you 100% sure that you tried my UDF that I posted on November 14, 2013, 13:51, and that this gave the same error for you?

stuart230588 November 20, 2013 10:23

I am using the code that I uploaded on 14th November at 14.40.

The error has changed to "invalid expression type for if: float"

referring to the line "rho = 0.098;"

pakk November 20, 2013 10:40

I think you initially received an error message because you used the wrong quotes in your first line.
Code:

#include “udf.h” //your version
#include "udf.h"//correct version

The error message that you see now, is because you use a single minus sign where you should use two. So:
Code:

if (temp = 293. )
should be
Code:

if (temp == 293. )
This also happens at other places in your code.

In fact, this line can be removed, which will make your code easier:
Code:

if (temp == 293. )
rho = 1.623;
elseif (temp > 293. && temp < 500. )
rho = 1.623 + ((0.999 - 1.623) / 207. ) * (temp - 293. );

is the same as
Code:

if ((temp >= 293.) && (temp < 500.))
rho = 1.623 + ((0.999 - 1.623) / 207. ) * (temp - 293. );

I also added extra brackets in the if-statement for clarity.
Finally, note that in the current code, if the temperature is below 293K your argon will have a low density (0.098), which is not physical. If you are sure that the temperature will not drop below 293K, it is not a problem, but it could be safer to start with a line "if (temp<293.) ...".

stuart230588 November 21, 2013 03:45

Thanks very much for the help Pakk.

The UDFs appear to be interpreting now although I haven't run a simulation yet.


All times are GMT -4. The time now is 07:59.