Thursday 12 October 2023

Saithe Fish UDF (ANSYS Fluent)

     This post is about Fish Simulation in ANSYS Fluent using a User Defined Function (UDF). The UDF is mentioned below. The flow conditions are taken from [1]. This goes with the videos shown in Fig. 1-2. The CAD files for t=0 are available here (for UDF 01).

Fig. 1, Animation of motion achieved through the UDF 01.

 
 Fig. 2, Animation of motion achieved through the UDF 02 (Validated).

     The results of present simulations are compared with [1]. The results are in excellent agreement as the Cl, max from [1] is at 1.57 while the maximum Cl, max from present simulation is at 1.6. The drag coefficient [1], Cd, max in [1] is at 0.164; while from the present simulations I got, 0.151. The Cd, avg comes out to be 0.072 [1] form the present simulations. I got a value of 0.064 from he present simulation. These would gradually become more accurate with mesh refinement, which I will certainly do if I send some ideas I have for peer review.

UDF 01:

#include "udf.h"
#include "unsteady.h"
#include "dynamesh_tools.h"
#include "math.h"


DEFINE_GRID_MOTION(dynamic,domain,dt,time,dtime)
{
 Thread *tf = DT_THREAD(dt);
 face_t f;
 Node *v;
 int n;
 double x, y, y_ref_previous, y_ref;
 SET_DEFORMING_THREAD_FLAG(THREAD_T0(tf));  
 begin_f_loop(f,tf) {
  f_node_loop(f,tf,n) {
   v = F_NODE(f,tf,n);
   if (NODE_POS_NEED_UPDATE(v)) {
    NODE_POS_UPDATED(v);
    x = NODE_X(v);
    real amplitude = 0.02 + 0.01*x + 0.1*x*x;
    y_ref_previous = amplitude * cos(2*M_PI*x + 2*M_PI*0.8*(PREVIOUS_TIME));
    y_ref = amplitude * cos(2*M_PI*x + 2*M_PI*0.8*(CURRENT_TIME));
     
if (NODE_Y(v) > y_ref_previous){
     NODE_Y(v) = y_ref+fabs(NODE_Y(v)-y_ref_previous);
    }
    else 
     if (NODE_Y(v) < y_ref_previous){
      NODE_Y(v) = y_ref-fabs(NODE_Y(v)-y_ref_previous);
     }
     else {
      NODE_Y(v) = y_ref;
     }
    }
   }
  }
 }
 end_f_loop(f,tf);

UDF 02 (Validated):

#include "udf.h"

DEFINE_GRID_MOTION(dynamic,domain,dt,time,dtime)
{
 Thread *tf = DT_THREAD(dt);
 face_t f;
 Node *v;
 int n;
 double x, y_ref_previous, y_ref, amplitude, fr;
 SET_DEFORMING_THREAD_FLAG(THREAD_T0(tf));  
 begin_f_loop(f,tf) {
  f_node_loop(f,tf,n) {
   v = F_NODE(f,tf,n);
   if (NODE_POS_NEED_UPDATE(v)) {
    NODE_POS_UPDATED(v);
    x = fabs(NODE_X(v));
    amplitude = 0.02 - 0.0825 * x + 0.1625 * x * x;
    fr = 2;
    y_ref_previous = amplitude * cos(2 * M_PI * x - 2 * M_PI * fr * (PREVIOUS_TIME));
    y_ref = amplitude * cos(2 * M_PI * x - 2 * M_PI * fr * (CURRENT_TIME));
     
if (NODE_Y(v) > y_ref_previous){
     NODE_Y(v) = y_ref + fabs(NODE_Y(v) - y_ref_previous);
    }
    else 
     if (NODE_Y(v) < y_ref_previous){
      NODE_Y(v) = y_ref - fabs(NODE_Y(v) - y_ref_previous);
     }
     else {
      NODE_Y(v) = y_ref;
     }
    }
   }
  }
 }
 end_f_loop(f,tf);

If you want to hire me as you next shining PhD/Master student or collaborate in research, please reach out! Thank you for reading!

References

[1] Gen-Jin Dong, Xi-Yun Lu; Characteristics of flow over traveling wavy foils in a side-by-side arrangement. Physics of Fluids 1 May 2007; 19 (5): 057107. https://doi.org/10.1063/1.2736083