


{"id":369456,"date":"2024-06-01T03:27:37","date_gmt":"2024-06-01T03:27:37","guid":{"rendered":"\/forum\/forums\/topic\/storing-and-plotting-values-in-udm\/"},"modified":"2024-06-01T03:27:37","modified_gmt":"2024-06-01T03:27:37","slug":"storing-and-plotting-values-in-udm","status":"closed","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/storing-and-plotting-values-in-udm\/","title":{"rendered":"Storing and plotting values in UDM"},"content":{"rendered":"<p>I basically want to store the value of r, for each face, and plot it vs axial position. When I try this, its just a constant line at 0. I turned on a udm location and node memery location but is there anything else I have to do?<\/p>\n<div>#include &#8220;udf.h&#8221;<\/div>\n<div>#include &lt;math.h&gt;<\/div>\n<div>&nbsp;<\/div>\n<div>#define rho 950 \/\/ kg\/m^3<\/div>\n<div>#define Hg 2033631 \/\/ J\/Kg<\/div>\n<div>#define Hf -310000 \/\/ J\/Kg<\/div>\n<div>#define T_ref 298 \/\/ K<\/div>\n<div>#define A1 0.01104 \/\/ m\/s<\/div>\n<div>#define A2 3.9648 \/\/ m\/s<\/div>\n<div>#define Cp 1500 \/\/ J\/(Kg*K)<\/div>\n<div>#define E1 20557.188 \/\/ J\/mol<\/div>\n<div>#define E2 55893.78 \/\/ J\/mol<\/div>\n<div>#define R_u 8.314 \/\/ J\/(mol*K)<\/div>\n<div>#define alpha 0.3<\/div>\n<div>&nbsp;<\/div>\n<div>DEFINE_PROFILE(surface_temperature_profile, t, position)<\/div>\n<div>{<\/div>\n<div>&nbsp; &nbsp; face_t f;<\/div>\n<div>&nbsp; &nbsp; real Ts, heat_flux, heat, a_face, Hv, r, Ts_old, Ts_new, error, Ts_new_prime, Area[ND_ND];<\/div>\n<div>&nbsp; &nbsp; real radial_position;<\/div>\n<div>&nbsp; &nbsp; real centroid[ND_ND];<\/div>\n<div>&nbsp; &nbsp; int iter;<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp; &nbsp; begin_f_loop(f, t)<\/div>\n<div>&nbsp; &nbsp; {<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; Ts = F_T(f, t);&nbsp; \/\/ Current temperature at the face<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; heat = BOUNDARY_HEAT_FLUX(f, t);&nbsp; \/\/ Heat transfer at face f in watts<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; F_AREA(Area, f, t);&nbsp; \/\/ Get the area vector of the face<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; a_face = NV_MAG(Area);&nbsp; \/\/ Magnitude of the face area<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ Calculate the radial position of the face centroid<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; F_CENTROID(centroid, f, t);<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; radial_position = centroid[1]; \/\/ Assuming the radial position is the y-coordinate in 2D axisymmetric<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ Heat flux for the circumferential area<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; heat_flux = (heat*2*M_PI*radial_position) \/ a_face; \/\/ Heat flux in W\/m^2<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;Heat flux on face %d: %g W\/m^2\\n&#8221;, f, heat_flux);<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; Ts_old = Ts;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; iter = 0;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; error = 1;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; while (error &gt; 1e-6 &amp;&amp; iter &lt; 100)<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; {<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Hv = Hg &#8211; Hf + Cp * (Ts &#8211; T_ref);&nbsp; \/\/ Calculation heat of formation<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r = (fabs(heat_flux)) \/ (Hv * rho);&nbsp; \/\/ Regression rate<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (Ts_old &gt; 722)<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ts_new = E1 \/ (R_u * (log(A1) &#8211; log(r)));&nbsp; \/\/ New surface temperature for high temperature<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ts_new = E2 \/ (R_u * (log(A2) &#8211; log(r)));&nbsp; \/\/ New surface temperature for low temperature<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error = fabs(Ts_new &#8211; Ts_old);&nbsp; \/\/ Error calculation<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ts_old = Ts_new;&nbsp; \/\/ Update Ts_old for next iteration<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iter++;&nbsp; \/\/ Increment iteration count<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; }<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; Ts_new_prime = Ts + (alpha * (Ts_new &#8211; Ts));&nbsp;<\/div>\n<div>r = (fabs(heat_flux)) \/ (Hv * rho);<\/div>\n<div>\/\/ Store r in UDM<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; F_UDMI(f, t, 0) = r;&nbsp; \/\/ Assuming the UDM index is 0<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;New Temp %d: %g K\\n&#8221;, f, Ts_new_prime);<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;r_dot %d: %g mm\/s\\n&#8221;, f, r*1000);<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; F_PROFILE(f, t, position) = Ts_new_prime;&nbsp; \/\/ Update the face temperature profile<\/div>\n<div>&nbsp; &nbsp; }<\/div>\n<div>&nbsp; &nbsp; end_f_loop(f, t)<\/div>\n<div>}<\/div>\n","protected":false},"template":"","class_list":["post-369456","topic","type-topic","status-closed","hentry"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_bbp_subscription":["343144","199"],"_bbp_author_ip":["23.216.133.166"]," _bbp_last_reply_id":["0"]," _bbp_likes_count":["0"],"_btv_view_count":["554"],"_bbp_topic_status":["unanswered"],"_bbp_topic_id":["369456"],"_bbp_forum_id":["27792"],"_bbp_engagement":["199","343144"],"_bbp_voice_count":["2"],"_bbp_reply_count":["1"],"_bbp_last_reply_id":["369563"],"_bbp_last_active_id":["369563"],"_bbp_last_active_time":["2024-06-03 11:10:43"]},"test":"zwernjaydengmail-com"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/369456","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\/369456\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=369456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}