CFD Online Discussion Forums

CFD Online Discussion Forums (
-   FLUENT (
-   -   Terminate Fluent when body reaches a temperature (

magicalmarshmallow November 18, 2013 15:53

Terminate Fluent when body reaches a temperature

I'm really new to using Fluent and I need to run a multiphysics heat transfer simulation. Basically I am cooling an aluminium block by passing water through channels on the surface.

The initial temperature of the block is 500K and the water temperature is 300K. The way I am setting the temperature of the block is using the patch setting after initialisation. Is the the best?

The main question though is how do I tell fluent to stop solving when the temperature of the block is at or below 350K? I haven't been able to work this out.

If someone could help it would be excellent


macfly November 20, 2013 18:44

You can do that with a DEFINE_EXECUTE_AT_END udf. The udf would calculate the average temperature in the domain at each timestep, and then an if condition would follow in the udf to stop Fluent if some average T is reached.

magicalmarshmallow November 21, 2013 17:55

Is it possible to do this from the GUI? I am guessing not.

So far I have managed to cobble this lot together


#include "udf.h"
/* Obtain the mean temperature of the domain ID12
 volume_t c;
 Domain *d;
 Thread *t;
 d = Get_Domain(12);

I've no idea if this makes any sense at all. I assume it gets something more to end it that just this, but I haven't a clue

Finally, if I am sending this to a linux HPC using PBS, so my question then becomes; am I wasting my time? From what I have read, your UDF script is local and not included in the case file. Is this true?

macfly November 21, 2013 19:11

Maybe an if condition in Calculation Activities\Execute Commands... Look here to see an example of how to implement an if condition:

By the way, that's the kind of stuff that is soooo easy to figure out in Comsol and will take hours to work out in the prehistoric Fluent interface.

magicalmarshmallow November 21, 2013 20:21

Sorry to be a hassle here, but I really have no clue as to what I am doing. I read the thread you recommended, but I still haven't a clue if I am on the right track (or any track) in terms editing and writing these functions to suit my purpose. I have no idea how to get the Execute command 'if' condition to link to the UDF which calculates the average temperature, not what should be included in the UDF. Moreover, I haven't a clue about writing the UDF.

I could simplify the problem to a the average temperature on a surface. Does this make the UDF any easier to write?


Originally Posted by macfly (Post 463014)
By the way, that's the kind of stuff that is soooo easy to figure out in Comsol and will take hours to work out in the prehistoric Fluent interface.

Yeh I know, I wanted to use COMSOL, but unfortunately we don't have a licence for COMSOL in my faculty :(. We also don't have it on the HPC either

macfly November 22, 2013 14:50

1 Attachment(s)
Ok here is how:
1. define a scheme variable in Fluent TUI: (rp-var-define 't_vol_avg 0 'real #f)

2. interpret the following udf which will calculate volume-weighted temperature and assign the result to the scheme variable:

#include "udf.h"

Domain *d; /* declare domain pointer since it is not passed as an argument to the DEFINE macro */
real t_vol_avg_1 = 0.;
real t_vol_avg_2 = 0.;
real t_cell = 0.;
real volume = 0.;
real volume_tot = 0.;
Thread *t;
cell_t c;
d = Get_Domain(1); /* Get the domain using ANSYS FLUENT utility */

thread_loop_c(t,d) /* Loop over all cell threads in the domain */
        /* Compute volume-averaged temperature by looping over all cells */
                volume = C_VOLUME(c,t); /* get cell volume */
                t_cell = C_T(c,t); /* get cell temperature */
                volume_tot += volume; /* sum of volumes */
                t_vol_avg_1 += t_cell*volume; /* sum of volume-weighted temperatures */
        t_vol_avg_2 = t_vol_avg_1/volume_tot; /* volume-weighted temperature */
        RP_Set_Real("t_vol_avg",t_vol_avg_2); /* update value of scheme variable */
    printf("\n Volume-weighted T = %g K \n",t_vol_avg_2); /* print volume-weighted temperature in TUI */

3. Hook the udf: Define\User-Defined\Function Hooks...\Execute at End...

4. The value of the scheme variable can be retrieved in Fluent with: (rpgetvar 't_vol_avg)
Therefore we can implement an interrupting condition in Execute Commands, see attached picture.

Try with a simple 2D square transient conduction model. Initial T of solid at 500 K and all boundaries at 300 K.

magicalmarshmallow November 25, 2013 05:13

Thanks a million for this. I haven't had a chance to try it just yet. Hopefully sometime today :)


All times are GMT -4. The time now is 17:46.