CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   Setting cell variable values in a fluid zone using UDF (http://www.cfd-online.com/Forums/fluent-udf/120824-setting-cell-variable-values-fluid-zone-using-udf.html)

eromon84 July 15, 2013 14:29

Setting cell variable values in a fluid zone using UDF
 
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.

blackmask July 15, 2013 20:00

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.

eromon84 July 15, 2013 23:25

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.

blackmask July 16, 2013 01:22

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?

eromon84 July 16, 2013 08:35

no...I did not know that! :D

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)

JouleBrayton October 15, 2013 05:16

HI! Finally how did you solve this problem? Thanks!!


All times are GMT -4. The time now is 09:52.