Author Topic: Can I monitor the location of min/max values during the simulation in Fluent  (Read 6474 times)

Offline pico

  • Newbie
  • *
  • Posts: 19
  • Reputation: +0/-0
  • Searching for solution
    • View Profile
Advertisement
I want to monitor the location of min/max values, lets say pressure over the duration of a simulation with Ansys Fluent. Can anyone please help?

Thank you.

Offline william

  • Full Member
  • ***
  • Posts: 159
  • Reputation: +15/-0
  • Know it, share it.
    • View Profile
You can use a UDF for this purpose, here is a sample code. You can modify it to suite your requirements for any variable you like to monitor:

Code: [Select]
#include "udf.h"
static real global_max_pressure;
static real global_coordinates_max_pressure[ND_ND];
static int global_print_output = 1;
DEFINE_ON_DEMAND(get_max_pressure)
{
 Domain *d = Get_Domain(1);
 Thread *t;
 cell_t c;
 real max_pressure = -REAL_MAX;
 real max_pressure_node;
 real iwork[ND_ND], coordinates_max_pressure[ND_ND];

#if !RP_HOST
 /* Calculate the maximum pressure */
 thread_loop_c(t, d)
 {
 if (FLUID_THREAD_P(t)) {
 begin_c_loop_int(c, t)
 {
 if (C_P(c,t) > max_pressure) {
 max_pressure = C_P(c,t);
 C_CENTROID(coordinates_max_pressure, c, t);
 }
 }
 end_c_loop_int(c, t)
 }
 }
 max_pressure_node = max_pressure;

 /* Global reduction */
 max_pressure = PRF_GRHIGH1(max_pressure);

/* Verify on each compute node, consider numerical round-off errors */
 if (max_pressure_node < max_pressure-max_pressure*1e-16) {
 NV_S(coordinates_max_pressure,=,-REAL_MAX);
 }
 PRF_GRHIGH(coordinates_max_pressure,ND_ND,iwork);

 /* Output */
 global_max_pressure = max_pressure;
 NV_V(global_coordinates_max_pressure,=,coordinates_max_pressure);

 if (global_print_output) {
#if RP_2D
 Message0("Max pressure %e at %e | %e\n", max_pressure,
coordinates_max_pressure[0], coordinates_max_pressure[1]);
#else

Message0("Max pressure %e at %e | %e | %e\n", max_pressure,
coordinates_max_pressure[0], coordinates_max_pressure[1],
coordinates_max_pressure[2]);
#endif
 }
#endif
}
DEFINE_ON_DEMAND(activate_console_output)
{
 global_print_output = 1;
}
DEFINE_ON_DEMAND(deactivate_console_output)
{
 global_print_output = 0;
}
DEFINE_EXECUTE_AT_END(run_max_pressure)
{
 get_max_pressure();
 node_to_host_real_1(global_max_pressure);
 node_to_host_real(global_coordinates_max_pressure, ND_ND);
}
DEFINE_REPORT_DEFINITION_FN(max_pressure_location_x)
{
 return global_coordinates_max_pressure[0];
}
DEFINE_REPORT_DEFINITION_FN(max_pressure_location_y)
{
 return global_coordinates_max_pressure[1];
}

DEFINE_REPORT_DEFINITION_FN(max_pressure_location_z)
{
#if RP_2D
 return 0.0;
#else
 return global_coordinates_max_pressure[2];
#endif
}