


{"id":275780,"date":"2023-03-21T22:34:33","date_gmt":"2023-03-21T22:34:33","guid":{"rendered":"\/forum\/forums\/topic\/fluent-udf-passing-information-to-a-face-loop-within-a-cell-loop\/"},"modified":"2023-03-21T23:06:03","modified_gmt":"2023-03-21T23:06:03","slug":"fluent-udf-passing-information-to-a-face-loop-within-a-cell-loop","status":"closed","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/fluent-udf-passing-information-to-a-face-loop-within-a-cell-loop\/","title":{"rendered":"Fluent UDF: Passing information to a face loop within a cell loop"},"content":{"rendered":"<p>I have a relatively simple UDF that does the following:<br \/>1. Loops over all the cell threads.<br \/>&nbsp; &nbsp;2. Loops over all cells of each cell thread.<br \/>&nbsp; &nbsp; &nbsp;3. Calculates centroid of each cell.<br \/>&nbsp; &nbsp; &nbsp;4. Loops over all face threads.<br \/>&nbsp; &nbsp; &nbsp; &nbsp; 5. Loops over all faces of each face thread.<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;6. Calculate centroid of each face.<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;7. Assign a UDM value to the cell if a condition between the cell and face centroids is met.<\/p>\n<p>The UDF looks something like below, where I have used an example condition which compares the z-coordinate difference between the cell and face centroids. There would be other conditions which stop the loop and move on to the next cell if the UDM value of that cell is 1, but I&#8217;ve omitted these lines for clarity.&nbsp;<\/p>\n<pre class=\"alt2\" dir=\"ltr\">#if !RP_HOST\n\nDomain *domain;\nThread *tc, *tf;\nface_t f;\ncell_t c;\n\ndomain = Get_Domain(ROOT_DOMAIN_ID);\n\nreal xc[ND_ND];\nreal xf[ND_ND];\n\n<strong>thread_loop_c(tc,domain)<\/strong>\n{\n    <strong>begin_c_loop(c,tc)<\/strong>\n    {\n        C_CENTROID(xc,c,tc);\n\t<strong>thread_loop_f(tf,domain)<\/strong>\n        {\n\t    <strong>begin_f_loop(f,tf)<\/strong>\n\t    {\n                F_CENTROID(xf,f,tf);\n                if (fabs(xc[2] - xf[2]) &lt; 0.1)\n                    C_UDMI(c,tc,0) = 1;\n            }\n            <strong>end_f_loop(f,tf)<\/strong>\n        }\n    }\n    <strong>end_c_loop(c,tc)<\/strong>\n}\n\n#endif<strong><br><\/strong><\/pre>\n<p>The code works in serial, but I could not get it to work in parallel. The issue is that the face loop may be done on a different compute node to the node of the cell loop, so that the face loop compute node does not have information calculated in the outside cell loop.<\/p>\n<p><span><strong>How can I pass the cell centroid information from the cell loop into the face loop (and each face thread loop) so that the above code works in parallel?<\/strong><\/span><\/p>\n<p>I&#8217;ve considered intializing and creating a 3D array which contains the centroid of all the faces of each face thread, and then looping over the cells, but this does not seem very efficient as most of the array would need to be filled with null values since the number of faces on each thread would be different. I&#8217;ve also considered using a pointer, but I don&#8217;t know how to feed information about the pointer into the face thread loop.<\/p>\n","protected":false},"template":"","class_list":["post-275780","topic","type-topic","status-closed","hentry","topic-tag-udf"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_bbp_subscription":["279402","22555"],"_bbp_author_ip":["23.223.149.174"]," _bbp_last_reply_id":["0"]," _bbp_likes_count":["0"],"_btv_view_count":["2497"],"_edit_lock":["1679981404:211250"],"_bbp_topic_status":["unanswered"],"_bbp_status":["publish"],"_bbp_topic_id":["275780"],"_bbp_forum_id":["27792"],"_bbp_engagement":["22555","279402"],"_bbp_voice_count":["2"],"_bbp_reply_count":["11"],"_bbp_last_reply_id":["276751"],"_bbp_last_active_id":["276751"],"_bbp_last_active_time":["2023-03-28 06:19:24"]},"test":"kenneth-funglciconsultants-com-au"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/275780","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics"}],"about":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/275780\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=275780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}