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/)
-   -   Opening a file and if statement before a DPM UDF (https://www.cfd-online.com/Forums/fluent-udf/140255-opening-file-if-statement-before-dpm-udf.html)

anthony05 August 11, 2014 23:16

Opening a file and if statement before a DPM UDF
 
I am currently using a UDF for DEFINE_DPM_PROPERTY and it involves an If statement, reading a file, and then modifying a particle property.

So the very simplified file looks like,

DEFINE_DPM_PROPERTY
>if 1 condition
>open file A
else
>open file B

>modify particle property

This works but is extremely slow due to the way the file opens. Is there anyway I can open the file before the UDF loops over every particle?

This was not a problem when I was using DEFINE_PROPERTY since the loop over every cell was contained within a for loop and the file could be opened before this. However if I put the file opening part before DEFINE_DPM_PROPERTY line I get 2 compiler errors since 'If' statements cannot be used outside of a function and my file opening needs an address operator (&) which also seems to not work outside of a function.

The compiler errors I receive are:
error C2143: syntax error : missing ')' before '&'
error C2143: syntax error : missing '{' before '&'
error C2059: syntax error : '&'
error C2059: syntax error : ')'
error C2059: syntax error : 'if'

Thanks in advance to anyone that can help :D

pakk August 12, 2014 01:48

Simplified:

DEFINE_ON_DEMAND
>open file A
>save data in variable C
>open file B
>save data in variable D

DEFINE_DPM_PROPERTY
>if 1 condition
>read variable C
else
>read variable D

>modify particle property

anthony05 August 12, 2014 09:29

I should have said before that the file is being read by proprietary software. Once the file is read, the same program needs to use that data which it stores internally to evaluate the conditions in the Fluent simulation such as temperature, pressure and species concentrations. So it isn't possible for me to save the data to a variable. Once the end of a function is reached, the program closes and the data is lost.

pakk August 12, 2014 11:04

Just to be sure if I understand it, does the following describe the workflow (excluding the if-statement)?

- Fluent has flow data in memory.
- PropSoftware reads flow data directly from Fluent's memory.
- PropSoftware writes dpm data to file.
- Fluent reads dpm data from file.
- Fluent calculates next time step.
- Go back to beginning.

Do you think the following pseudo-code would work in your situation?

DEFINE_DPM_PROPERTY
>if (first particle in current time step):
> read files A and B, store in variables C and D
>endif
>if 1 condition
> read variable C
>else
> read variable D
>endif
>modify particle property

anthony05 August 14, 2014 00:39

Hi pakk,

Thanks for your help, it appears it does work with something close to your first solution. With your help and help from Ansys, I was able to make it work with DEFINE_EXECUTE_ON_LOADING for the first function. The program doesn't close in between functions as I first thought.


All times are GMT -4. The time now is 11:39.