


{"id":168917,"date":"2022-04-26T23:26:26","date_gmt":"2022-04-26T23:26:26","guid":{"rendered":"\/forum\/forums\/topic\/wall-distance-calculation\/"},"modified":"2022-05-05T07:02:48","modified_gmt":"2022-05-05T07:02:48","slug":"wall-distance-calculation","status":"closed","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/wall-distance-calculation\/","title":{"rendered":"Wall distance calculation"},"content":{"rendered":"<div class=\"Item-Body\">\n<div class=\"Message userContent\">\n<p>Hello guys I found a problem in a UDF. I have to calculate the distance of the particle respect to the wall. I did a loop to find the minimum distance. My questions are:<\/p>\n<p>1) how can I know in which face of the thread i found the minimum distance<\/p>\n<p>2) how can I create a normal vector in that point in such ba why to project the vector &quot;vec&quot; in that direction<\/p>\n<p><\/p>\n<\/p>\n<p>This is my UDF, thanks in advance<\/p>\n<p><\/p>\n<\/p>\n<p>\/* UDF adding an external body force to the particles *\/<\/p>\n<p>#include &quot;udf.h&quot;<\/p>\n<p>#include &quot;dpm.h&quot;<\/p>\n<p>#include &quot;dpm_mem.h&quot;<\/p>\n<p>#include &quot;surf.h&quot;<\/p>\n<p><\/p>\n<\/p>\n<p>DEFINE_DPM_BODY_FORCE(particle_body_force, p, i)<\/p>\n<p>{<\/p>\n<p><\/p>\n<\/p>\n<p>&nbsp;&nbsp;\/* declaration of variables *\/<\/p>\n<p>&nbsp;&nbsp;double w, Dh, Ufx, Ufy, Ufz, Gx, rho, a, F_L, c_height, c_length,<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;c_volume, side, H, W, f_height_total, Renx, Reny, Renz, crDh, mu, aUfx, aUfy, aUfz, C1, C2, C3, C4, C_Ly, C_Lz, z, y, distancewall, cosine;<\/p>\n<p><\/p>\n<\/p>\n<p>&nbsp;&nbsp;real xw[ND_ND];<\/p>\n<p>&nbsp;&nbsp;real vec[ND_ND];<\/p>\n<p>&nbsp;&nbsp;Domain* d;<\/p>\n<p>&nbsp;&nbsp;cell_t c;<\/p>\n<p>&nbsp;&nbsp;Thread* t;<\/p>\n<p>&nbsp;&nbsp;face_t f; \/\/f is the face index that is inside the face thread t(our wall). You will extract the face area vector from f index&nbsp;<\/p>\n<p>&nbsp;&nbsp;d = Get_Domain(1);<\/p>\n<p>&nbsp;&nbsp;c = P_CELL(p); \/\/cell in witch the particle is currently in&nbsp;<\/p>\n<p>&nbsp;&nbsp;t = Lookup_Thread(d, 9); \/\/9 is the ID number of the upper wall. t is the thread index(pointer) of the wall boundary surface 9<\/p>\n<p><\/p>\n<\/p>\n<p>&nbsp;&nbsp;distancewall = 100; \/\/i&#039;m setting a generic initial value<\/p>\n<p>&nbsp;&nbsp;begin_f_loop(f, t)<\/p>\n<p>&nbsp;&nbsp;{<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;F_CENTROID(xw, f, t);&nbsp;\/\/center of each face&nbsp;<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;NV_VV(vec, =, xw, -, P_POS(p)); \/\/vector connecting the particle to the face center that is placed at the wall. The NV_VV do the operation between 2 vectors :(vec=xw-P_POS(p))<\/p>\n<p><\/p>\n<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\/\/now you want to calculate the minimum distance between particle and wall, and so you want to find the minimum of the vector vec doing the loop over all the boundary face<\/p>\n<p><\/p>\n<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;if (distancewall &gt;= NV_MAG(vec))<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;{<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;distancewall = NV_MAG(vec);<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;end_f_loop(f, t)<\/p>\n","protected":false},"template":"","class_list":["post-168917","topic","type-topic","status-closed","hentry"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_btv_view_count":["1849"],"_bbp_likes_count":["0"],"_bbp_subscription":["254277"],"_bbp_topic_status":["unanswered"],"_bbp_status":["publish"],"_bbp_topic_id":["168917"],"_bbp_forum_id":["27792"],"_bbp_engagement":["199","22555","254277"],"_bbp_voice_count":["3"],"_bbp_reply_count":["16"],"_bbp_last_reply_id":["213175"],"_bbp_last_active_id":["213175"],"_bbp_last_active_time":["2022-05-05 07:02:48"]},"test":"angelantoniosquiccia97gmail-com"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/168917","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\/168917\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=168917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}