Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

Writing UDF data to a file in parallel

    • brandon.hager.63
      Subscriber

      Hello, 

      I am writing a UDF as DEFINE_SOURCE that will perform some calculations within a singular cell zone. I want to write the result of those calculations in a text file. Currently, I can write the data using the following code. However, I run into issues where I get duplicates of many values. Additionally, some of those duplicates contain values that aren't sensible. I have confirmed that these are duplicate values by having the UDF write the cell coordinates and unique cell ID numbers. Because the DEFINE_SOURCE macro loops over all of the cells in a cell zone I expect that the amount of data written is equal to the total number of cells. This is often not the case as I usually have more data than cells. I think my issue is that my current code is not parallelized for writing the data.

      I have found the Ansys documentation on how to write files in parallel here: https://www.afs.enea.it/project/neptunius/docs/fluent/html/udf/node231.htm

      I have tried to implement it within the source term by removing the DEFINE_ON_DEMAND, but I either receive a segmentation fault error or the simulation will hang on the iteration that the data is supposed to be written on. Currently, I am only testing by writing each cell's temperature instead of all of the data I require. I've included the new code below.

      I'm not sure what is causing the segmentation fault or the hanging behavior. Any help would be greatly appreciated.

      Thanks.

    • Luca B.
      Forum Moderator

      Hi, in the Ansys Fluent Documentation you can find very good indication how to best write an UDF in parallel.

      When you run an UDF in parallel and you want to print ( or write to file ) a data, you have to be be sure to loop only on nodes and skip the host. There are some "Neighborhood" cells that you want to skip in the count. ( see chapter 7.2) 

      I have seen you are trying to use this raccomandation in your UDF.  It is quite hard to debug your code to understand what generate the segmentation fault. 

      I suggest you to create a simpler case, to test how writing in parallel works and then to increse the complexity to identify the critical lines that generate the error.

      You can first print the results on screen and then save to file. 

      You wrote you are not using DEFINE_ON_DEMAND macro. What type of macro are you using? 

      Hope my suggestions help you.

      Luca

Viewing 1 reply thread
  • The topic ‘Writing UDF data to a file in parallel’ is closed to new replies.