-
-
March 20, 2024 at 6:05 am
vikram chahal
SubscriberGood morning sir/mam,
i am doing coupled simulation of vehicle and fluid tank thtough UDF using ansys fluent. UDF is succesfully compliled but at the time of running simulation it showing bad termination of FFF fluent and automatically shut down. below is my UDF.
#include "udf.h"DEFINE_ADJUST(coupled_simulation, d){real simulation_time = RP_Get_Real("flow-time");real dt = 0.0001; // Time step sizereal end_time = 15; // End time of simulationDomain *domain = Get_Domain(2); // Assuming the fluid domain has ID 2if (!domain){Message("Error: Unable to obtain domain.\n");return;}// Define vehicle parametersreal m_truck = 5450.0; // Mass of the truck (kg)real I_truck = 5000.0; // Moment of inertia of the truck (kg*m^2)real k1 = 2.86e10; // Front spring stiffness (N/m)real k2 = 3.870e5; // Rear spring stiffness (N/m)real l1 = 0.2; // Distance of front axle from CG (m)real l2 = 0.8; // Distance of rear axle from CG (m)real F_braking = 1000.0; // Braking force (N)// Define fluid parameters for water phasereal fluid_density_water = 1000.0; // Density of water (kg/m^3)// Define fluid parameters for air phasereal fluid_density_air = 1.2; // Density of air (kg/m^3)// Initial conditions for vehicle motionreal x = 1.0; // Initial vertical displacementreal theta = 1.0; // Initial angular displacementreal x_dot = 0.0; // Initial vertical velocityreal theta_dot = 0.0; // Initial angular velocityreal x_ddot = 0.0; //vehicle accelerationreal fluid_force_x_water = 0.0, fluid_force_x_air = 0.0;real fluid_force_y_water = 0.0, fluid_force_y_air = 0.0;real fluid_force_z_water = 0.0, fluid_force_z_air = 0.0;real fluid_moment_x_water = 0.0, fluid_moment_x_air = 0.0;real fluid_moment_y_water = 0.0, fluid_moment_y_air = 0.0;real fluid_moment_z_water = 0.0, fluid_moment_z_air = 0.0;Thread *t;face_t f;cell_t c;// Main simulation loopwhile (simulation_time < end_time){// Step 1: Calculate vehicle response to braking forcereal x_ddot = (-k1 * (x - l1 * theta) - k2 * (x + l2 * theta) + F_braking) / m_truck;real theta_ddot = (-k1 * l1 * (x - l1 * theta) + k2 * l2 * (x + l2 * theta)) / I_truck;// Step 2: Apply vehicle response to fluid domain as a body force in the source termreal vehicle_force_y = -m_truck * x_ddot;real vehicle_moment_z = -k1 * l1 * (x - l1 * theta) + k2 * l2 * (x + l2 * theta);// Loop over fluid cellst = Lookup_Thread(domain, 2); // Assuming FLUID_THREAD_ID is the ID of the fluid threadthread_loop_c(t, d){begin_c_loop(c, t){// Apply the body force components based on vehicle response// For simplicity, assuming all the force acts in the y-directionC_UDMI(c, t, 0) = 0.0; // Body force in x-directionC_UDMI(c, t, 1) = vehicle_force_y; // Body force in y-directionC_UDMI(c, t, 2) = 0.0; // Body force in z-direction// Apply the moment components based on vehicle response// Here, we'll assume all the moments act around the z-axisC_UDMI(c, t, 3) = 0.0; // Moment about x-axisC_UDMI(c, t, 4) = 0.0; // Moment about y-axisC_UDMI(c, t, 5) = vehicle_moment_z; // Moment about z-axis}end_c_loop(c, t);}// Step 3: Calculate fluid forces and moments for water and air phases// Loop over fluid cellst = Lookup_Thread(domain, 2); // Assuming FLUID_THREAD_ID is the ID of the fluid threadthread_loop_c(t, d){begin_c_loop(c, t){real A[ND_ND], F[ND_ND], F_area[ND_ND]; // Add F_area vector to store face areareal p = C_P(c, t); // Pressure of the cell (initialise pressure value in Fluent= mg/ base area)C_CENTROID(A, c, t); // Centroid of the cellfor (int i = 0; i < ND_ND; i++){F[i] = 0.0; // Initialize force vector}// Loop over faces of the cell using C_FACE macrofor (int f = 0; f < C_NFACES(c, t); f++){face_t face = C_FACE(c, t, f);F_AREA(F_area, face, t); // Face area vector// Calculate face forcefor (int j = 0; j < ND_ND; j++){F[j] += p * F_area[j]; // Use F_area instead of calling F_AREA macro multiple times}}// Accumulate forces and moments for water phasefluid_force_x_water += F[0];fluid_force_y_water += F[1];fluid_force_z_water += F[2];fluid_moment_x_water += (A[1] * F[2] - A[2] * F[1]);fluid_moment_y_water += (A[2] * F[0] - A[0] * F[2]);fluid_moment_z_water += (A[0] * F[1] - A[1] * F[0]);// Accumulate forces and moments for air phasefluid_force_x_air += F[0];fluid_force_y_air += F[1];fluid_force_z_air += F[2];fluid_moment_x_air += (A[1] * F[2] - A[2] * F[1]);fluid_moment_y_air += (A[2] * F[0] - A[0] * F[2]);fluid_moment_z_air += (A[0] * F[1] - A[1] * F[0]);}end_c_loop(c, t);}// Step 4: Update vehicle response based on fluid forces and moments as excitation force on vehicle equationsreal fluid_force_x = fluid_force_x_water + fluid_force_x_air;real fluid_force_y = fluid_force_y_water + fluid_force_y_air;real fluid_force_z = fluid_force_z_water + fluid_force_z_air;real fluid_moment_x = fluid_moment_x_water + fluid_moment_x_air;real fluid_moment_y = fluid_moment_y_water + fluid_moment_y_air;real fluid_moment_z = fluid_moment_z_water + fluid_moment_z_air;x_dot += fluid_force_x / m_truck * dt;theta_dot += fluid_moment_z / I_truck * dt;x += x_dot * dt;theta += theta_dot * dt;// Increment simulation timesimulation_time += dt;// Step 5: Output results if neededprintf("Time: %.2f, x: %.4f, theta: %.4f\n", simulation_time, x, theta);} -
March 26, 2024 at 2:05 pm
SRP
Ansys EmployeeHi,
Before continue, add extra debugging output statements to your UDF to pinpoint the specific location of the fault. You may display intermediate variables, verify loop iterations, and confirm that each step of the computation is completed appropriately. Avoid needless memory allocations and deallocations within loops, as they might lead to memory leaks or segmentation problems.
-
March 27, 2024 at 4:16 am
vikram chahal
SubscriberHOW CAN I DO THIS WITHOUT USING MEMORY ALLOCATION? could you please suggest any alternative for that// Apply the body force components based on vehicle response// For simplicity, assuming all the force acts in the y-directionC_UDMI(c, t, 0) = 0.0; // Body force in x-directionC_UDMI(c, t, 1) = vehicle_force_y; // Body force in y-directionC_UDMI(c, t, 2) = 0.0; // Body force in z-direction// Apply the moment components based on vehicle response// Here, we'll assume all the moments act around the z-axisC_UDMI(c, t, 3) = 0.0; // Moment about x-axisC_UDMI(c, t, 4) = 0.0; // Moment about y-axisC_UDMI(c, t, 5) = vehicle_moment_z; // Moment about z-axis}end_c_loop(c, t); -
March 27, 2024 at 8:39 am
SRP
Ansys EmployeeHi,
I recommend that you first execute the code section by section to troubleshoot the issue, as I suggested in my previous response, so that we can determine whether there is an error. I hope this helps.
-
- The topic ‘coupled simulation of vehicle and fluid tank’ is closed to new replies.
-
5934
-
1906
-
1420
-
1306
-
1021
© 2026 Copyright ANSYS, Inc. All rights reserved.