|
[Sponsors] |
Setting cell variable values in a fluid zone using UDF |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
July 15, 2013, 15:29 |
Setting cell variable values in a fluid zone using UDF
|
#1 |
New Member
Join Date: Apr 2013
Posts: 20
Rep Power: 13 |
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 09:55. |
|
July 15, 2013, 21:00 |
|
#2 |
Senior Member
|
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. |
|
July 16, 2013, 00:25 |
|
#3 |
New Member
Join Date: Apr 2013
Posts: 20
Rep Power: 13 |
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. |
|
July 16, 2013, 02:22 |
|
#4 |
Senior Member
|
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; |
|
July 16, 2013, 09:35 |
|
#5 |
New Member
Join Date: Apr 2013
Posts: 20
Rep Power: 13 |
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) |
|
October 15, 2013, 06:16 |
|
#6 |
New Member
Flavio G.
Join Date: Sep 2013
Posts: 4
Rep Power: 13 |
HI! Finally how did you solve this problem? Thanks!!
|
|
March 28, 2021, 12:59 |
|
#7 |
Senior Member
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0 |
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. |
|
|
|
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 11:52 |
UDF for cell zone condition | rachana | Fluent UDF and Scheme Programming | 0 | January 23, 2013 16:43 |
Pressure and Temperature UDF for Cell Zone | elixer2104 | FLUENT | 0 | February 24, 2011 12:54 |
error in COMSOL:'ERROR:6164 Duplicate Variable' | bhushas | COMSOL | 1 | May 30, 2008 05:35 |
Terrible Mistake In Fluid Dynamics History | Abhi | Main CFD Forum | 12 | July 8, 2002 10:11 |