Fluids

Fluids

Finding an specific cell in the domain

    • m.shafiee1374
      Subscriber

      Hello,

      I want to find a cell in my domain that contains a specific point. The method I'm using is like this:

      thread_loop_c (c_thread,dom)

      {

      begin_c_loop(cell,c_thread)

      {

      //checking whether the point is inside the cell or not

      //getting the cell id

      }

      }

      Then I want to use this cell identifier in a DEFINE_ADJUST macro to read the velocity of that cell and use it in my calculations.

      However, since DEFINE_ADJUST is a macro that is executed at every iteration of the Ansys Fluent solver, I don't want to include the above code in the DEFINE_ADJUST. Instead, I want to use it in another source code inside a DEFINE_EXECUTE_ON_LOADING macro and then use the cell id in the main source code that contains the DEFINE_ADJUST .

      SO the questions are:

      Am I able to do this at all?

      And how can I pass the cell id from one source code to another one?


      Thanks. ☺️

    • DrAmine
      Ansys Employee
      There are some undocumented function to do that. But there are some other ways which are pure C. You check for every cell centroid its distance to one point if it below tolerance you mark the cell and return its cell id. Is not something I can go deep into it or share on this open platform.
    • m.shafiee1374
      Subscriber
      Thanks for your response I know that you can measure the distance of cell centroid and the point and I've already used this method. But my question was about how to pass the cell id from a DEFINE_EXECUTE_ON_LOADING macro to a DEFINE_EXECUTE_ON_LOADING macro?
    • m.shafiee1374
      Subscriber
      Hello,
      So an update to my problem: I managed to solve it by defining a cell and thread pointer as external global variable in a header file.
      then I was able to pass these pointers to other source codes (or macros) by including the mentioned header file.
    • DrAmine
      Ansys Employee
      External variable or marking A cell Memory with True / 1 and the other with False/0.
    • m.shafiee1374
      Subscriber
      Hi again Recently I wrote a udf for this purpose to find the cell id of the nearest cell to the hub location of a wind turbine. The code is compiled successfully with no errors whatsoever :

      But after loading the library into Fluent 19, a long list of errors are shown and then the fluent process crashes for some reason ­ƒñªÔÇìÔÖé´©Å
      I couldn't find any reason behind these errors, since the code looks correct and errors are kind of vague.
      How can I fix this?
    • DrAmine
      Ansys Employee
      Avoid the defitions on line 2 and 3 and do that inside the define macro. Also worth using globsl C_ID in parallel to get the unique ID of the cell.

      Also line 34 is not required.
      Also your UDF is not parallelized.
    • m.shafiee1374
      Subscriber
      The reason I defined thread and cell id above the define macro (line2&3) is that I want them to be global variables so that later I can use them in another source file by using the extern command .
      I tried compiling and loading this code using serial mode, and got similar error messages. I didn't know about udf parallelization but I will try and learn it once I'm about to run it in parallel.
Viewing 7 reply threads
  • You must be logged in to reply to this topic.