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

Setting cell variable values in a fluid zone using UDF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 15, 2013, 14:29
Default Setting cell variable values in a fluid zone using UDF
  #1
New Member
 
Join Date: Apr 2013
Posts: 20
Rep Power: 13
eromon84 is on a distinguished road
Hello,

I am fairly new to ansys and very new to the whole concept of UDF's. I have some C++ programming knowledge ( fairly basic ) and currently learning C now aswell.

I am trying to create a UDF to exports cell data with a small fluid zone and I think i figured out the commands I need for those

begin_loop_c(c,t){

value = C_T(c,t)

// write value out to file

}
end_loop_c(c,t)


however I am also trying to get a corresponding UDF for reading in particular variables from a file and assigning the value to a cell.

I am using this per iteration and I am not using the DEFINE_PROFILE macro to hook to the gui for various reasons and as such C_PROFILE(c,t,i) will not work for me in this situation.

I since I am not using DEFINE_Profile I have no way of understanding how I can set the value of a particular variable within a cell, for example.

begin_loop_c(c,t)
{

// read in value, store in var

// temperature in cell c is now equal to var

// repeat loop for next cell and read in another line
}

end_loop_c(c,t)

If anyone knows the command to allow me to write to a particular variable within a cell please let me know, thank you.

Last edited by eromon84; July 16, 2013 at 08:55.
eromon84 is offline   Reply With Quote

Old   July 15, 2013, 20:00
Default
  #2
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 21
blackmask will become famous soon enough
The order of cells in "begin_loop_c" can not be guaranteed which means you wont be able to assign the value for the temperature if there is only one variable in your input file. The input should looks like
x1 y1 z1 t1
x2 y2 z2 t2
...
Then you can loop over all the cells in a particular thread, find the nearest coordinates from the input file, and assign the corresponding temperature for this cell.
blackmask is offline   Reply With Quote

Old   July 15, 2013, 23:25
Default
  #3
New Member
 
Join Date: Apr 2013
Posts: 20
Rep Power: 13
eromon84 is on a distinguished road
Hi blackmask,

Appreciate the advice, however my question is what the command is to write a particular variable to a particular cell?

C_T(c,t) will return a value for the temperature variable within a particular cell, but I do not know the command to set / write the particular variable into a cell's data.

I want to hook this to an adjust UDF so that it is called at start of every iteration aswell.
eromon84 is offline   Reply With Quote

Old   July 16, 2013, 01:22
Default
  #4
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 21
blackmask will become famous soon enough
The expansion of C_T(c,t) macro results in an l-value, so that if you want to specify values for some particular cells you could used
Code:
C_T(c, t) = 200;
I must have misunderstood you meaning because you have already knew that in your fist post. Could you explain what you real problem is in more detail?
blackmask is offline   Reply With Quote

Old   July 16, 2013, 08:35
Default
  #5
New Member
 
Join Date: Apr 2013
Posts: 20
Rep Power: 13
eromon84 is on a distinguished road
no...I did not know that!

reading the UDF manual it seemed that those variable macro's could only be used like this

real var

var = C_T(c,t) ( or C_P(c,t) etc )

And another post around here had stated that you can not use it to set a value within a cell, only to return a value from within a cell.

Because of this, i thought that C_T(c,t) returned an actual number (i.e a constant) and did not consider that it was an expression that could be an lvalue.

Does this mean I can use those C_T(c,t) macro's for both setting and getting of variables? that would be fantastic!

The only thing left to do if that is the case is to store the centroid of each cell as you suggested, since the loops do not go through a specific order.

EDIT: looking at my first post, i actually made a typing error, I had meant to state the following within that first loop.

value = C_T(c,t)
eromon84 is offline   Reply With Quote

Old   October 15, 2013, 05:16
Post
  #6
New Member
 
Flavio G.
Join Date: Sep 2013
Posts: 4
Rep Power: 12
JouleBrayton is on a distinguished road
HI! Finally how did you solve this problem? Thanks!!
JouleBrayton is offline   Reply With Quote

Old   March 28, 2021, 11:59
Default
  #7
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Hello Blackmask.

I know this is an old posting, but it's interesting.

Q: how do I get "C_T(c,t)" to loop over cells and obtain energy in joules, and CO2 mol value in a cell?

Example;
1. Loop in a domain.
2. Get energy value in a cell. Or in the fluid domain, if easier.
3. Get CO2 mol value in the same cell. Or in the fluid domain, if easier.
4. Do a calculation for energy and CO2.
5. Put the newly calculated energy and CO2 value back into the cell.
6. Move to the next cell, and keep updating.

Thanks.
visitor is offline   Reply With Quote

Reply


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Commercial meshers] fluentMeshToFoam multidomain mesh conversion problem Attesz OpenFOAM Meshing & Mesh Conversion 12 May 2, 2013 10:52
UDF for cell zone condition rachana Fluent UDF and Scheme Programming 0 January 23, 2013 15:43
Pressure and Temperature UDF for Cell Zone elixer2104 FLUENT 0 February 24, 2011 11:54
error in COMSOL:'ERROR:6164 Duplicate Variable' bhushas COMSOL 1 May 30, 2008 04:35
Terrible Mistake In Fluid Dynamics History Abhi Main CFD Forum 12 July 8, 2002 09:11


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