CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Opening a file and if statement before a DPM UDF

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By pakk

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 12, 2014, 00:16
Question Opening a file and if statement before a DPM UDF
  #1
New Member
 
Anthony
Join Date: Jul 2013
Posts: 15
Rep Power: 13
anthony05 is on a distinguished road
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
anthony05 is offline   Reply With Quote

Old   August 12, 2014, 02:48
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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 likes this.
pakk is offline   Reply With Quote

Old   August 12, 2014, 10:29
Default
  #3
New Member
 
Anthony
Join Date: Jul 2013
Posts: 15
Rep Power: 13
anthony05 is on a distinguished road
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.
anthony05 is offline   Reply With Quote

Old   August 12, 2014, 12:04
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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
pakk is offline   Reply With Quote

Old   August 14, 2014, 01:39
Default
  #5
New Member
 
Anthony
Join Date: Jul 2013
Posts: 15
Rep Power: 13
anthony05 is on a distinguished road
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.
anthony05 is offline   Reply With Quote

Reply

Tags
dpm, fluent, udf


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 13:38.