


{"id":354743,"date":"2024-03-01T08:46:53","date_gmt":"2024-03-01T08:46:53","guid":{"rendered":"\/forum\/forums\/topic\/coupled-simulation-of-vehicle-and-fluid-tank\/"},"modified":"2024-03-01T08:46:53","modified_gmt":"2024-03-01T08:46:53","slug":"coupled-simulation-of-vehicle-and-fluid-tank","status":"closed","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/coupled-simulation-of-vehicle-and-fluid-tank\/","title":{"rendered":"coupled simulation of vehicle and fluid tank"},"content":{"rendered":"<div>\n<div>i am doing coupled simulation of vehicle and fluid tank. In which i am trying to interact the vehicle bouncing and pitching motion to fluid tank and vice versa in fluent using udf. but during the interpretion of UDF i am getting parse error. can you suggest where changes are required. below is the udf:<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp;<\/div>\n<div>#include &#8220;udf.h&#8221;<\/div>\n<div>#include &#8220;thread.h&#8221; \/\/ Include the thread header file<\/div>\n<div>DEFINE_EXECUTE_AT_END(coupled_simulation)<\/div>\n<div>{<\/div>\n<div>&nbsp; &nbsp; real simulation_time = 0.0;<\/div>\n<div>&nbsp; &nbsp; real dt = 0.5; \/\/ Time step size<\/div>\n<div>&nbsp; &nbsp; real end_time = 4.0; \/\/ End time of simulation<\/div>\n<p><\/p>\n<div>&nbsp; &nbsp; &nbsp;Define vehicle parameters<\/div>\n<div>&nbsp; &nbsp; real m_truck = 2000.0; \/\/ Mass of the truck (kg)<\/div>\n<div>&nbsp; &nbsp; real I_truck = 5000.0; \/\/ Moment of inertia of the truck (kg*m^2)<\/div>\n<div>&nbsp; &nbsp; real k1 = 2.86e10; \/\/ Front spring stiffness (N\/m)<\/div>\n<div>&nbsp; &nbsp; real k2 = 3.870e5; \/\/ Rear spring stiffness (N\/m)<\/div>\n<div>&nbsp; &nbsp; real l1 = 0.2; \/\/ Distance of front axle from CG (m)<\/div>\n<div>&nbsp; &nbsp; real l2 = 0.8; \/\/ Distance of rear axle from CG (m)<\/div>\n<div>&nbsp; &nbsp; real F_braking = -10000.0; \/\/ Braking force (N)<\/div>\n<p><\/p>\n<div>&nbsp; &nbsp; \/\/ Define fluid parameters<\/div>\n<div>&nbsp; &nbsp; real fluid_density = 1000.0; \/\/ Density of the fluid (kg\/m^3)<\/div>\n<div>&nbsp; &nbsp; real fluid_velocity_x = 0.0; \/\/ Initial fluid velocity in x-direction (m\/s)<\/div>\n<div>&nbsp; &nbsp; real fluid_velocity_y = 0.0; \/\/ Initial fluid velocity in y-direction (m\/s)<\/div>\n<div>&nbsp; &nbsp; real fluid_velocity_z = 0.0; \/\/ Initial fluid velocity in z-direction (m\/s)<\/div>\n<p><\/p>\n<div>&nbsp; &nbsp; \/\/ Initial conditions for vehicle motion<\/div>\n<div>&nbsp; &nbsp; real x = 0.0; \/\/ Initial vertical displacement<\/div>\n<div>&nbsp; &nbsp; real theta = 0.0; \/\/ Initial angular displacement<\/div>\n<div>&nbsp; &nbsp; real x_dot = 0.0; \/\/ Initial vertical velocity<\/div>\n<div>&nbsp; &nbsp; real theta_dot = 0.0; \/\/ Initial angular velocity<\/div>\n<p><\/p>\n<div>&nbsp; &nbsp; \/\/ Main simulation loop<\/div>\n<div>&nbsp; &nbsp; while (simulation_time &lt; end_time)<\/div>\n<div>&nbsp; &nbsp; {<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ Step 1: Calculate vehicle response to braking force<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; real x_ddot = (-k1 * (x &#8211; l1 * theta) &#8211; k2 * (x + l2 * theta) + F_braking) \/ m_truck;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; real theta_ddot = (-k1 * l1 * (x &#8211; l1 * theta) + k2 * l2 * (x + l2 * theta)) \/ I_truck;<\/div>\n<p><\/p>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; x_dot += x_ddot * dt;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; theta_dot += theta_ddot * dt;<\/div>\n<p><\/p>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; x += x_dot * dt;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; theta += theta_dot * dt;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; real simulation_time = CURRENT_TIME + dt;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ Step 2: Apply vehicle response to fluid tank and compute fluid forces and moments<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; real fluid_force_x = 10.0;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; real fluid_force_y = 0.0;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; real fluid_force_z = 0.0;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; real fluid_moment_x = 0.0;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; real fluid_moment_y = 5.0;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; real fluid_moment_z = 0.0;<\/div>\n<p><\/p>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; Thread *t;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; face_t f;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; cell_t c;<\/div>\n<p><\/p>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; \/* Loop over all cells *\/<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; begin_c_loop(c, t)<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; {<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/* Loop over all faces of the cell *\/<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; real A[ND_ND], F[ND_ND];<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; real p = C_P(c, t); \/\/ Pressure of the cell<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; C_CENTROID(A, c, t); \/\/ Centroid of the cell<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int i;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; ND_ND; i++)<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; F[i] = 0.0; \/\/ Initialize force vector<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/div>\n<p><\/p>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/* Loop over all faces of the cell *\/<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; THREAD_NFACES(t); i++)<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f = C_FACE(c, t, i);<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; F_AREA(A, f, t); \/\/ Face area vector<\/div>\n<p><\/p>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/* Calculate face force *\/<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int j;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (j = 0; j &lt; ND_ND; j++)<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; F[j] += p * F_AREA(A, f, t)[j]; \/\/ Pressure force on face<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/div>\n<p><\/p>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/* Accumulate forces and moments *\/<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fluid_force_x += F[0];<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fluid_force_y += F[1];<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fluid_force_z += F[2];<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fluid_moment_x += (A[1] * F[2] &#8211; A[2] * F[1]);<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fluid_moment_y += (A[2] * F[0] &#8211; A[0] * F[2]);<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fluid_moment_z += (A[0] * F[1] &#8211; A[1] * F[0]);<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; }<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; end_c_loop(c, t)<\/div>\n<p><\/p>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ Step 3: Update vehicle motion based on fluid forces and moments<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; Excitation force = fluid force<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; x_dot += fluid_force_x \/ m_truck * dt;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; theta_dot += fluid_moment_y \/ I_truck * dt;<\/div>\n<p><\/p>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; x += x_dot * dt;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; theta += theta_dot * dt;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; simulation_time +=dt;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ Step 5: Output results if needed<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ printf(&#8220;Time: %.2f, x: %.4f, theta: %.4f\\n&#8221;, simulation_time, x, theta);<\/div>\n<p><\/p>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ Step 6: Check termination condition<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; if (simulation_time &gt;= end_time)<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<\/div>\n<div>&nbsp; &nbsp; }<\/div>\n<div>}<\/div>\n<\/div>\n","protected":false},"template":"","class_list":["post-354743","topic","type-topic","status-closed","hentry"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_bbp_subscription":["336538","199"],"_bbp_author_ip":["23.218.248.146"]," _bbp_last_reply_id":["0"]," _bbp_likes_count":["0"],"_btv_view_count":["246"],"_bbp_topic_status":["unanswered"],"_bbp_topic_id":["354743"],"_bbp_forum_id":["27792"],"_bbp_engagement":["199","336538"],"_bbp_voice_count":["2"],"_bbp_reply_count":["16"],"_bbp_last_reply_id":["360660"],"_bbp_last_active_id":["360660"],"_bbp_last_active_time":["2024-04-05 10:53:25"]},"test":"vikramkumar-m22me1002mbcet-ac-in"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/354743","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\/354743\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=354743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}