


{"id":396704,"date":"2024-12-08T21:22:47","date_gmt":"2024-12-08T21:22:47","guid":{"rendered":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/density-udf-for-a-mixture\/"},"modified":"2024-12-08T21:22:47","modified_gmt":"2024-12-08T21:22:47","slug":"density-udf-for-a-mixture","status":"publish","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/density-udf-for-a-mixture\/","title":{"rendered":"Density UDF for a mixture"},"content":{"rendered":"<p>&lt;p&gt;I wrote a UDF to specify density as a function of&nbsp; temperature for a multi-species, multiphase model. This is the error I get.&lt;br&gt;&lt;br&gt;&lt;\/p&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;&nbsp; step&nbsp; flow-time&nbsp; &nbsp; &nbsp;p-inlet&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;&nbsp; &nbsp; &nbsp;0&nbsp; 0.0000e+00 -1.0553e-14&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Updating solution at time level N&#8230;&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;&nbsp;done.&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;&nbsp; iter&nbsp; continuity&nbsp; x-velocity&nbsp; y-velocity&nbsp; z-velocity&nbsp; &nbsp; &nbsp; energy&nbsp; ch44-p&nbsp; ch3oh-pha&nbsp; n2-phase-a&nbsp; co2-phase-&nbsp; vf-phase-a&nbsp; &nbsp; &nbsp;time\/iter&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; Stabilizing pressure coupled to enhance linear solver robustness.&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; Stabilizing pressure coupled using GMRES to enhance linear solver robustness.&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Experiencing convergence difficulties &#8211; temporarily relaxing and trying again&#8230;&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Experiencing convergence difficulties &#8211; temporarily relaxing and trying again&#8230;&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Experiencing convergence difficulties &#8211; temporarily relaxing and trying again&#8230;&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Experiencing convergence difficulties &#8211; temporarily relaxing and trying again&#8230;&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; Stabilizing pressure coupled to enhance linear solver robustness.&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; Stabilizing pressure coupled using GMRES to enhance linear solver robustness.&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Experiencing convergence difficulties &#8211; temporarily relaxing and trying again&#8230;&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: pressure coupled temperature limited to 3.273150e+03 in 387997 cells on zone 1231 in domain 1&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Stabilizing vof-1 to enhance linear solver robustness.&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; Stabilizing vof-1 using GMRES to enhance linear solver robustness.&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: vof-1&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: pressure coupled&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: vof-1&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: pressure coupled&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: vof-1&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: pressure coupled&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: vof-1&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: pressure coupled&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: vof-1&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: pressure coupled&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: vof-1&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: pressure coupled&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: vof-1&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: pressure coupled&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: vof-1&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: pressure coupled&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: vof-1&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: pressure coupled&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: vof-1&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: pressure coupled&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: vof-1&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: pressure coupled&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Divergence detected in AMG solver: vof-1&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Error at host: floating point exception&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Error: floating point exception&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Error Object: ()&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Error at Node 5: floating point exception&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Error at Node 4: floating point exception&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Error at Node 6: floating point exception&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Error at Node 3: floating point exception&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Error at Node 10: floating point exception&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Error at Node 7: floating point exception&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Error at Node 0: floating point exception&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Error at Node 9: floating point exception&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Error at Node 8: floating point exception&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Error at Node 1: floating point exception&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Error at Node 11: floating point exception&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Error at Node 2: floating point exception&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #236fa1;&#8221;&gt;Error: floating point exception&lt;\/span&gt;&lt;\/div&gt;&lt;p&gt;Would someone be able to review my UDF (below) and tell me if there is an obvious mistake.&lt;br&gt;&lt;br&gt;&lt;\/p&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;#include &#8220;udf.h&#8221;&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;\/* Define the UDF to specify temperature-dependent density *\/&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;DEFINE_PROPERTY(temperature_dependent_density, cell, thread)&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;{&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; real T;&nbsp; \/* Temperature *\/&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; real density;&nbsp; \/* Density *\/&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; real vol_frac;&nbsp; \/* Volume fraction of phase A *\/&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; \/* Loop over all cells in the thread *\/&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; begin_c_loop(cell, thread)&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; {&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; \/* Get the volume fraction of phase A in the cell *\/&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; vol_frac = C_VOF(cell, thread);&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; \/* Check if the volume fraction of phase A is greater than 50% *\/&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; if (vol_frac &gt; 0.5)&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; {&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/* Get the temperature of the cell *\/&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; T = C_T(cell, thread);&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/* Calculate the density based on the given relationship *\/&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; density = 1.4811 &#8211; 0.0007 * T;&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/* Set the density for the cell *\/&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; C_R(cell, thread) = density;&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; &nbsp; &nbsp; }&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; }&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; end_c_loop(cell, thread)&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;&nbsp; &nbsp; return density;&lt;\/span&gt;&lt;\/div&gt;&lt;div&gt;&lt;span style=&#8221;color: #169179;&#8221;&gt;}&lt;\/span&gt;&lt;\/div&gt;<\/p>\n","protected":false},"template":"","class_list":["post-396704","topic","type-topic","status-publish","hentry","topic-tag-fluent","topic-tag-udferror"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_bbp_forum_id":["27792"],"_bbp_topic_id":["396704"],"_bbp_subscription":["437146","199"],"_bbp_author_ip":["47.188.202.145"],"_bbp_last_reply_id":["396929"],"_bbp_last_active_id":["396929"],"_bbp_last_active_time":["2024-12-10 11:39:59"],"_bbp_reply_count":["3"],"_bbp_reply_count_hidden":["0"],"_bbp_voice_count":["2"],"_bbp_engagement":["437146","199"],"_btv_view_count":["490"],"_bbp_topic_status":["unanswered"]},"test":"sjohnbenchmark-space-com"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/396704","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\/396704\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=396704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}