-
-
March 20, 2024 at 6:05 amvikram chahalSubscriber
Good 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 size  real end_time = 15; // End time of simulation  Domain *domain = Get_Domain(2); // Assuming the fluid domain has ID 2  if (!domain)  {    Message("Error: Unable to obtain domain.\n");    return;  }  // Define vehicle parameters  real 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 phase  real fluid_density_water = 1000.0; // Density of water (kg/m^3)  // Define fluid parameters for air phase  real fluid_density_air = 1.2; // Density of air (kg/m^3)  // Initial conditions for vehicle motion  real x = 1.0; // Initial vertical displacement  real theta = 1.0; // Initial angular displacement  real x_dot = 0.0; // Initial vertical velocity  real theta_dot = 0.0; // Initial angular velocity  real x_ddot = 0.0; //vehicle acceleration  real 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 loop  while (simulation_time < end_time)  {    // Step 1: Calculate vehicle response to braking force    real 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 term  real vehicle_force_y = -m_truck * x_ddot;  real vehicle_moment_z = -k1 * l1 * (x - l1 * theta) + k2 * l2 * (x + l2 * theta);  // Loop over fluid cells  t = Lookup_Thread(domain, 2); // Assuming FLUID_THREAD_ID is the ID of the fluid thread  thread_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-direction      C_UDMI(c, t, 0) = 0.0; // Body force in x-direction      C_UDMI(c, t, 1) = vehicle_force_y; // Body force in y-direction      C_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-axis      C_UDMI(c, t, 3) = 0.0; // Moment about x-axis      C_UDMI(c, t, 4) = 0.0; // Moment about y-axis      C_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 cells  t = Lookup_Thread(domain, 2); // Assuming FLUID_THREAD_ID is the ID of the fluid thread  thread_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 area      real 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 cell      for (int i = 0; i < ND_ND; i++)      {        F[i] = 0.0; // Initialize force vector      }      // Loop over faces of the cell using C_FACE macro      for (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 force        for (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 phase      fluid_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 phase      fluid_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 equations  real 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 time    simulation_time += dt;     // Step 5: Output results if needed      printf("Time: %.2f, x: %.4f, theta: %.4f\n", simulation_time, x, theta);      }  -
March 26, 2024 at 2:05 pmSRPAnsys Employee
Hi,
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 amvikram chahalSubscriberHOW 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-direction      C_UDMI(c, t, 0) = 0.0; // Body force in x-direction      C_UDMI(c, t, 1) = vehicle_force_y; // Body force in y-direction      C_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-axis      C_UDMI(c, t, 3) = 0.0; // Moment about x-axis      C_UDMI(c, t, 4) = 0.0; // Moment about y-axis      C_UDMI(c, t, 5) = vehicle_moment_z; // Moment about z-axis    }    end_c_loop(c, t); -
March 27, 2024 at 8:39 amSRPAnsys Employee
Hi,
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.
- Non-Intersected faces found for matching interface periodic-walls
- Unburnt Hydrocarbons contour in ANSYS FORTE for sector mesh
- Help: About the expression of turbulent viscosity in Realizable k-e model
- Script error Code: 800a000d
- Cyclone (Stairmand) simulation using RSM
- Fluent fails with Intel MPI protocol on 2 nodes
- error udf
- Diesel with Ammonia/Hydrogen blend combustion
- Mass Conservation Issue in Methane Pyrolysis Shock Tube Simulation
- Script Error
-
1241
-
543
-
523
-
225
-
209
© 2024 Copyright ANSYS, Inc. All rights reserved.