We have an exciting announcement about badges coming in May 2025. Until then, we will temporarily stop issuing new badges for course completions and certifications. However, all completions will be recorded and fulfilled after May 2025.
Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

Considering the average temperature in a UDF

TAGGED: 

    • eng_m_m.abd89
      Subscriber

      Hello, this is my UDF for heat source; it worked well, but now I want to consider the average temperature instead of the cell temperature. My domain is three bodies [the battery, battery wall, and fluid around them]. I want to consider only the average temperature of the battery. Any help with performing this?

      /*my_battery_heat_source_trial.c*/
      #include "udf.h"
      #include "stdio.h"
      #include "math.h"
      #include "mem.h"
      #include "time.h"

      // Inputs
      #define V_bat 0.0000165 // Battery volume (m^3)
      #define H_chem 11740 // Total heat release of chemical reaction (J)
      #define H_sc 17560 // Total heat release of short circuit (J)
      #define rho 2600 // Density of battery (kg/m^3)
      #define Cp 1720 // Specific heat capacity (J/kg.K)
      #define A 0.92 // Pre-exponential factor (unitless)
      #define b 28.5 // Reaction rate constant (unitless)
      #define T_ref 533.15 // Normalized temperature coefficient (K)
      #define T_chem 413.15 // Start temperature of chemical reactions (K)
      #define T_tr 533.15 // Triggering temperature of thermal runaway (K)
      #define C_chem_max 12
      #define C_elec_max 12


      // UDF to define heat generation source term
      DEFINE_SOURCE(my_battery_heat_source_trial,c,t,ds, eqn)
      {
      // Declaring Local variable for chemical and electrical energy concentration
      real C_chem = 1.0;
      real C_chem_old = 1.0;
      real C_elec = 1.0;
      real C_elec_old = 1.0;
      real dC_chem_dt = 0.0;
      real dC_elec_dt = 0.0;
      real q_chem;
      real q_elec;
      real qv;
      real T = C_T(c,t); // Get the temperature from the cell
      real dt = CURRENT_TIMESTEP; // Get the simulation time step
      // Function to compute the rate of change of C_chem (dC_chem/dt)
      if (T>T_chem && T<=T_tr && C_chem>=0 && C_chem<=1)
      dC_chem_dt =(Cp / H_chem) * A * rho * V_bat * pow((T / T_ref), b);
      else if (T>T_tr && C_chem>=0 && C_chem<=1)
      dC_chem_dt = C_chem_max;
      else
      dC_chem_dt = 0.0;
      // Update the chemical energy concentration
      C_chem = C_chem_old - (dC_chem_dt * dt);
      // Function to compute volumetric chemical heat generation rate (q_chem)
      q_chem = (1.0/V_bat) * H_chem * dC_chem_dt;
      // Function to compute short-circuit reaction rate (dC_elec/dt)
      if (T>T_tr && C_chem>=0 && C_chem<=1)
      dC_elec_dt = C_elec_max;
      else
      dC_elec_dt = 0.0;
      // Update the electrical energy concentration
      C_elec = C_elec_old - (dC_elec_dt * dt);
      // Function to compute volumetric electric heat generation rate (q_elec)
      q_elec = (1.0/V_bat) * H_sc * dC_elec_dt;
      // Compute heat generation rates
      qv = q_chem + q_elec; // Total heat generation rate (W/m³)
      ds[eqn]=0;
      return qv; // Return total heat source term for Fluent
      }

    • Rob
      Forum Moderator

      You'll need to loop over the cell zone cells and remember to account for NODE/HOST issues. 

    • eng_m_m.abd89
      Subscriber

      Any advice on where/how to start writing it, as I am new to the UDF and don't know how to make the loop over the battery cells? 

    • Rob
      Forum Moderator

      Look for examples using begin_c_loop and end_c_loop for some ideas. 

Viewing 3 reply threads
  • You must be logged in to reply to this topic.