Fluids

Fluids

How to calculate area of particular surface through UDF?

    • Excited
      Subscriber

      Background

      Hello, everyone:

       I want to calculate the area of top surface(ID=10) which is shown in Figure 1, but I encountered some problem and I cannot figure it out.

       For UDF code, I searched previous examples on the internet, but I cannot fully understand the meaning of some syntax.

      Problem

      (1) UDF problem. I know I should find the target surface and then use the macro called F_AREA and NV_MAG to obtain area, but I don’t know how to realize it?

      (2) Understanding of macro problem. The loop macro in UDF code, ‘thread_loop_f’ and ‘begin_f_loop-end_f_loop’, I know the function of these two macros, for example, to my understanding, ‘thread_loop_f(thread, domain) is to loop over thread which contains faces in domain(am I right?), but I do not know why they are here?

      (3) After built and loaded UDF file successfully, once I clicked the ‘execute on demand’, error pops out, which is shown in Figure 2, why this happened?

      Any help will be appreciated, thank you, I need your help.

      Regards,

      Excited



    • Karthik R
      Administrator
      Hello You seem to be using one of the newer releases on Ansys Fluent. You should be able to use the Fluent expressions for this (instead of a UDF). Please look through the following link to see if this helps.
      https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v211/en/flu_ug/flu_ug_expression_syntax.html
      Also, did your UDF compile right? Where there any error messages?
      Karthik
    • Excited
      Subscriber
      Hello, kremella, thanks for your reply:
      1.I cannot log in that forum since I do not have account, so, I am unable to get the help;
      2. For UDF code, there maybe exist some errors in ÔÇ£the thread_loopÔÇØ, actually, I think it is wrong here, but I cannot find a way to select the target wall to apply the calculation macro, can you give me a hint about that? Thx!
      Regards Excited

    • Karthik R
      Administrator
      Hello Please try and follow these instructions and see if you are able to access the link I shared earlier.
      Please see if you can circumvent the UDF approach here using Fluent Expressions.
      Karthik
    • Excited
      Subscriber
      Thanks for your kind relpy, although my problem has been resolved. My UDF code is as follows:
      #include "udf.h"
      DEFINE_ON_DEMAND(Face_area)
      {
      face_t face;
      Thread* thread;
      Domain* domain;
      domain = Get_Domain(1);
      int zone_id = 10;
      thread = Lookup_Thread(domain, zone_id);
      real NV_VEC(va); /* for storing area vector */
      real Area = 0;
      begin_f_loop(face, thread)
      {
      F_AREA(va, face, thread); /* Obtain the area vector */
      Area += NV_MAG(va); /* Obtain area magnitude */
      }
      end_f_loop(face, thread)
      #if RP_NODE
      Area = PRF_GRSUM1(Area);
      #endif
      node_to_host_real_1(Area);
      #if RP_HOST
      Message("Area of top surface is %f\n", Area);
      #endif
      }
      Regards Excited
Viewing 4 reply threads
  • You must be logged in to reply to this topic.