Ansys Products

Ansys Products

Discuss installation & licensing of our Ansys Teaching and Research products

UDF: Segmentation fault when using F_AREA

TAGGED: 

    • Maria Sanchez Farran
      Subscriber

      Hello,
      I need to calculate the area of all faces within a given domain. This was my approach:

      1. I looked into the ANSYS UDF MANUAL and I found a code that outputs the location of the centroids of the cells (page 225). 
      2. I adapted this code for outputting the area of each face within a domain but I receive a Segmentation fault. 
      3. I debugged the code and the issue occurs when the code runs into the F_AREA(A,f,t) macro.
      4. FYI - I am not running in parallel.

       The problematic code is shown below. I would appreciate if you give me any advice on this.

    • Rob
      Forum Moderator

      I don't think you've defined A correctly, https://ansyshelp.ansys.com/account/Secured?returnurl=/Views/Secured/corp/v241/en/flu_udf/flu_udf_ModelSpecificDEFINE.html%23flu_udf_sec_ex_beam_direction 

    • Maria Sanchez Farran
      Subscriber

      Hi Rob,

      Thank you for replying - do I first need to register for me to access your answer?

    • Rob
      Forum Moderator

      No, click on Help in Fluent, and paste the link into the browser that opens. The solvers have a token/cookie/biscuit that bypasses the security check. 

    • Maria Sanchez Farran
      Subscriber

      Hi Rob,

      Thank you for your answer. I was able to read the link you provided in Fluent. 

      Regarding the definition of A, I realized the following:

      • the UDF example you provided defines A as: real A[3]
      • my UDF defines it as: real NV_VEC(A)

      I am not sure if this is the issue (would it make a difference?).

      If that is indeed the issue, I replaced the definition to "real A[3]" but I again receive the segmentation fault error.

      Thank you!

       

    • Rob
      Forum Moderator

      Looking here  https://ansyshelp.ansys.com/account/Secured?returnurl=/Views/Secured/corp/v241/en/flu_udf/flu_udf_DPMDEFINE.html  the example uses real A[ND_ND] and F_AREA[A,f,t]  

      In your code, the face loop calls F_AREA[A,f,t]  but doesn't look to do anything with it other than print. 

      We're not able to offer debugging advice, and you're already on the right track by using comments to find the problem. F_AREA is used in several of the examples, search F_AREA and see what else you find. 

    • Maria Sanchez Farran
      Subscriber

      Thank you for your comments, Rob. 

      Regarding the face loop, it is true that F_AREA[A,f,t] in the code doesn't do anything. It just prints because I can't get over the segmentation fault issue. I have looked through the examples using F_AREA and checked for syntax errors, and also looked at previous posts in the forum. 

      I understand that you cannot provide debugging advice. However, I followed your suggestion and I am now using the UDF that appears in the manual "Global Summation of Pressure on a Face Zone and its Area Average Computation". I am testing it in a parallel simulation, and I am having again the same issue.

      Here are the highlights:

      • I did not modify the code, except changing the surface_thread_id for the one that is relevant to my simulation.
      • I get segmentation fault when including the F_AREA and the PRINCIPAL_FACE_P conditional inside the face loop. The code runs ok if I just place a message withing the face loop. I show below three alternatives of the face loop that I have tried so far.
      • The problem is not with F_AREA only but if I modify the code for F_CENTROID it will give me the same problem.
      • The problem is beyond F_AREA and I wonder what is wrong with the face loop.
      1.face loop WITH segmentation fault (original loop from the code)
      begin_f_loop(face,thread)
      if (PRINCIPAL_FACE_P(face,thread))
      {
      F_AREA(area,face,thread);
      total_area += NV_MAG(area);
      total_force += NV_MAG(area)*F_P(face,thread);
      }
      end_f_loop(face,thread)
       
      2. Removed the conditional and the code still gives segmentation fault.
      begin_f_loop(face,thread)
          F_AREA(area,face,thread);
          total_area += NV_MAG(area);
          total_force += NV_MAG(area)*F_P(face,thread); 
      end_f_loop(face,thread)

      3. Code runs OK with a message inside the loop.

      begin_f_loop(face,thread)

      Message("I am inside the loop\n");

      end_f_loop(face,thread)
       
       
       
    • Rob
      Forum Moderator

      The other difference being the "area" definition. How is that defined?

    • Maria Sanchez Farran
      Subscriber

      Hi Rob,

      Than you for helping me out.

      1. I was trying to get information on the interior faces but I realized that the zone-id I was using in the code did not allow me to do that. I was using a zone-id that belongs to the "Cell Zone Conditions". From what I understand now, these zones only store cell information as opposed to information on interior faces. Is this correct?
      2. If I instead use the respective zone id that is listed in the "Boundary Conditions/Internals", I can get information on the interior faces and there is no segmentation fault. The code runs.
      3. I want to determine the flux that goes into each cell of a porous media. Would it be possible to loop over cells and then over the faces of each cell? The reason why I ask this is because the zone-id for cells is separate than for faces so I am not sure how to approach this task.
    • Rob
      Forum Moderator

      Interior faces should also have an ID, click on the surface in the GUI and in the Boundary Conditions Task Page you should see an ID. F_AREA is for facet data (surface) and C_stuff is for volumes. 

      For flux into a porous zone I'd look at the bounding surface (interior) rather than the cells. You can loop over cells and then facets on a cell to find a boundary but that can be very inefficient as that loop may be called every iteration/timestep depending on the code. 

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