CFD Online Discussion Forums

CFD Online Discussion Forums (
-   FLUENT (
-   -   defining UDS scalar (

sivakumar February 12, 2002 16:36

defining UDS scalar
hi all,

can anyone please tell me if there is some other way(other than using enum) by which i can define the user defined scalar. i want to know this because if i define them as enumerated variables their range is that of integer values and hence my calculations are going crazy. any help will be greatly appreciated. thank you, sivakumar

Greg Perkins February 12, 2002 20:42

Re: defining UDS scalar

Just use an integer to point to the index of the uds. Ie uds 0 is stored in C_UDSI(cell,thread,0). The kth one is stored in C_UDSI(cell,thread,k) where k is an integer.

The actual value of C_UDSI will be a real - not an integer!!!!!


ps in the udf manual they use an enum definition to define the index - this is a programmers choice, but the actual indexes are just integers. In some of my code I use simple calcs on the index to determine the right location, ie C_UDSI(cell,thread,UDS_BASE_IDX+i) where UDS_BASE_IDX and i are integers etc.

Greg Perkins February 12, 2002 20:52

Re: defining UDS scalar
By the way what I like to do in my code is abstract the Fluent variables one additional level. So for a uds for volume fraction say, I would define

#define UDS_VOF 0 #define UDS_TEMP 1

#define CELL_UDS_VOF(c,t) C_UDSI(c,t,UDS_VOF) #define CELL_UDS_TEMP(c,t) C_UDSI(c,t,UDS_TEMP)

the good bit about this is that you can change the location of the uds (each run-time) and not change your code at all. This is in fact the way Fluent define their variables - just look in the mem.h etc header files.

Most of the time, I actually would declare


and then initialise these variables in a DEFINE_INIT and/or DEFINE_ADJUST etc piece of code.

Similarly one can redfine CELL_FLUID_U(c,t) as C_U(c,t). etc... Now its possible to redefine your fluid velocity by changing the macro definition and not your code etc. This doesn't slow down your code either, since the pre-processor does the substitutions before compilation.

Now for the examples I've mentioned this doesn't really make a huge difference, but for complex code its the only way to do it. In one of my models I solve over 10 uds's and have over 50 udm's - and they get defined dynamically by a secondary input file that is read by my code - a sort of case file for my models.


Matthew Brannock March 12, 2002 08:42

Re: defining UDS scalar
Hi Greg,

Quite a good idea with respect to making the code easier to read. But what do you mean by saying that it can make things easier by being able to "change the location of the uds (each run-time) and not change your code at all"? By "location" I assume you mean the index number your scalar is assigned to. I understand that it would make it easier to swap around the index numbers between scalars, but why would you want to do this? The only case that I can think of is if you reduce the number of scalars by taking out index numbers that are mid-range. Also, how can you change the "location" at each run-time, wouldn't you have to recompile the UDF first? They might be silly questions but the reason I ask is that I want to take full advantage of this method.



Greg Perkins March 12, 2002 21:53

Re: defining UDS scalar
Hi Matthew,

well, what I've done is to extend Fluent to handle a secondary phases with species, etc etc. In this case I read a text file which defines the phases and species in the model - in a sense it is like a secondary case file. Then using this file I allocate uds's to solve various eqns by using an index. Thus in the code I have something like,

#define CELL_PHASE_SP(c,t,p,i) C_UDSI(c,t,Index[p][i])

thus the actual location of the ith species of the pth phase can change from run to run, and there's no need to recompile the udfs. My case, is ratehr extreme, since I'm adding substantial capabilities that extend Fluent quite a lot. One day I expect they will have some of these features - say in Fluent 6.5! But in some cases, I use hybrid models/methods which are required for my problem and won't be in any standard CFD code.

Really, the only use for this is to make your code more modular, more readable and thus easier to maintain.

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