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

Opening a file and if statement before a DPM UDF

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By pakk

Reply
 
LinkBack Thread Tools Display Modes
Old   August 11, 2014, 23:16
Question Opening a file and if statement before a DPM UDF
  #1
New Member
 
Anthony
Join Date: Jul 2013
Posts: 15
Rep Power: 4
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, 01:48
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 684
Rep Power: 9
pakk is on a distinguished road
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, 09:29
Default
  #3
New Member
 
Anthony
Join Date: Jul 2013
Posts: 15
Rep Power: 4
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, 11:04
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 684
Rep Power: 9
pakk is on a distinguished road
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, 00:39
Default
  #5
New Member
 
Anthony
Join Date: Jul 2013
Posts: 15
Rep Power: 4
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

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On



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