Fluids

Fluids

Advanced Fluent UDF Questions

    • lslxao
      Subscriber

      Hello!


      I would like to create a chemical reactor network (CRN) model from the data generated from a preexisting solution for a steady-state, single-phase simulation in Fluent.


      Using exported field variables, I have segmented the only zone containing the fluid cells of interest into discrete subvolumes. Each one of these subvolumes is distinguishable by the array of cell IDs of the constituent cells.


      My goal is to calculate the mass flow between each subvolume. I will need to loop through of each fluid cell, check for its subvolume ID, then loop again for all faces belonging to each cell and check if the neighboring face belongs to another subvolume; if so, the program should calculate the mass flux/flow rate between the two subvolumes through the current face. The tally of the individual flow rates should then give the total mass flow rate from one subvolume to another.


      I have the cell ID values from the export file, as well as the zone ID of the only zone of fluid cells through the TUI.


      I believe that the only way to access adjacent face pair data is through the connectivity macros implemented with a UDF. If so, I will need to import the list of cell IDs belonging to each zone using Scheme macros. My questions are:


      0) Am I even looping through this in the correct way?


      1)  The examples of Scheme macros in the UDF manual only read in a single number. Is it possible to read in an integer array of variable length (the list of IDs of cell belonging to a subvolume)?


      2) Is it possible to export a data array from the UDF say a or real[subvolume_size] real[subvolume_size][subvolume_size]? This will be especially helpful for debugging individual outputs such as current cell ID, neighbor cell ID, mass flux at C0/C1 & etc.


      Attached is what I have so far. I will also comment it down below. The things that I don’t know how to implement are commented in ALL CAPS.


       

    • lslxao
      Subscriber

      #include "udf.h"


      #include "mem.h"


       


      DEFINE_ON_DEMAND(my_init_func,d)


      {


      int domain_id = 1; // Defualt fluid domain for single-phase simulation


      int zone_ID = 4; // Zone containing all fluid cells


       


      // READ IN SUBVOLUME CELL LIST


       


      Domain *d = Get_Domain(domain_id); // Assign domain pointer


      Thread *tz, *tf, *t0, *t1; // Declare cell threads


      cell_t c, c0, c1; // Declare cell index variables


      face_t f; // Declare face index variables


      real NV_VEC(psi), NV_VEC(A); // Declare real variables


      real dens, m0 = 0.0;


       


      int i; // Initialize face index variable


      tz = Lookup_Thread(domain,zone_ID);


      begin_c_loop(c, tz) // Loop over all cells within zone


      {


      i = 0; // Reset face index counter


      c_face_loop(c,tz,i) // Loop over all faces of current cell


      {


      f = C_FACE(c,tz,i); // Get current face index


      tf = C_FACE_THREAD(c,tz,i); // Get current face thread


      c0 = F_C0(f,t); // Index of current cell; should be equivalent to c


       


      // FIND SUBVOLUME ID OF CURRENT CELL


      // FIND SUBVOLUME ID OF NEIGHBORING CELL


      // IF CELLS ARE OF DIFFERENT SUBVOLUMES


       


      t0 = F_C0_THREAD(f,t); // Thread of current cell


      F_AREA(A, f, tf); // Get area vector of face


      if (BOUNDARY_FACE_THREAD_P(t)) // If external face i.e. face is at domain boundary


      {


      if (NNULLP(THREAD_STORAGE(t,SV_DENSITY)))


      dens = F_R(f,t); // Set dens to face value if available


      else


      dens = C_R(c0,t0); // Else, set dens to cell value


      NV_DS(psi, =, F_U(f,t), F_V(f,t), F_W(f,t), *, dens); // psi is the mass flux, rho*V


      m_dot = NV_DOT(psi, A); // Mass flow through Face


      }


      else // If internal face


      {


      c1 = F_C1(f,t); // Get cell on other side of face


      t1 = F_C1_THREAD(f,t);


      if  IS_EXTERNAL(c1,c0)// If c1 is in another subvolume


      NV_DS(psi, = C_U(c1,t1),C_V(c1,t1),C_W(c1,t1),*,C_R(c1,t1)); 


      // Or that of c0 depending on which one is current


      m_dot = NV_DOT(psi, A)/2.0; /* Average flux through face */


      }


      }


      }


       


      end_c_loop(c, tz)


      }

    • Rob
      Ansys Employee

      If you know the interior (surface) ID would you be better off looping over those rather than over the cells? Remember to account for flow in both directions otherwise you may get silly results in a recirculation zone. 


      We can't comment & don't debug code on here, but it looks like you've read the manual (keep doing that!). Beyond that we can offer training if you contact us via the University. 

    • lslxao
      Subscriber

      Hello!


      Thank you for your reply. Unfortunately, I do not know the surface IDs of my subvolumes since these subvolumes were determined from user-defined segmentation methods that were done in another program.


      I am sorry if it seems that I am asking for coding advice. I merely wanted to know if what I am proposing is even possible with the current capabilities of Fluent UDFs.


      If my current method is too complicated, I will at the very least need to loop over all faces in the domain w/o checking for their subvolume IDs.


      In that case, can the software produce an output array with these variables that I need for the integration for all faces in the zone?


      Column 1: current cell ID


      Column 2: external/internal face


      Column 2: neighbor cell ID (if internal)


      Column 3-5: local cell center/face velocity components


      Column 6: local cell center/face density


      Column 7-9: face area components


      For a zone of n faces, the result is then a ~2n x 9 matrix, which I will then pass to an external program to obtain the data I need.


      Edit: I just looked over the manual again and this appears to be possible using the capabilities of C in compiled UDFs. I will need to look into this further. However, I would love to receive UDF training if that were possible. How may I initiate that?

    • DrAmine
      Ansys Employee

      Check https://www.ansys.com/en-gb/services/training-center

Viewing 4 reply threads
  • You must be logged in to reply to this topic.