Вы находитесь на странице: 1из 16

UNIVERSITY OF CALIFORNIA, DAVIS

Transient 2d Heat Transfer with Convective Boundary Conditions using the Finite Element Method
The development of a MATLAB code
Matthew Klein 3/20/2013

This paper will discuss the development of a MATLAB based code that uses the Finite Element Method to solve a 2d transient heat conduction problem with convective boundary conditions. It was specifically developed to meet the course requirements of MAE 239 as well as act as a tool for Dr. Parks Green Transportation Lab in conducting battery pack thermal management studies.

INTRODUCTION
Electrochemical devices have characteristics that are greatly temperature dependent. This includes both the instantaneous electrical performance as well as the long term lifetime performance. For lithium ion batteries generally low temperature cycling and high temperature storage accelerate degradation. Thus the lithium ion battery packs in electric vehicles require thermal management systems in order to control the power capability, lifetime, and of greatest importance to maintain safe operation. The thermal properties of the batteries and heat transfer system must be thoroughly analyzed in order to optimize the design and control strategies used to maintain the proper temperature of the battery at all times. A commonly shared convention in this field is to control the battery such that the largest temperature difference within the battery pack is 2 C. This value is selected based on the temperature sensitivity of the performance of lithium batteries and is likely to be highly conservative, therefore leaving much room for optimization. Pouch cells are a popular choice for many reasons and are typically stacked and compressed into modules. This only leaves the edges open for cooling and will then create temperature gradients along the face of the cell. If one were to understand how that affects performance the cell dimensions and control strategies and heat transfer system could be optimized for the best instantaneous vehicle power and long term life. Thus it is the goal of my research to shed new light on understanding the performance effects of an electric vehicles battery based on how the heat is removed from the cells (i.e. cell temperature gradient to performance relationship) and how that also couples into the long term performance. As a start to that end a 2d transient FEM model will be developed here to aid in system characterization.

BACKGROUND AND OBJECTIVES


Figure 1,Figure 2Figure 3 show different views of the particular battery module under investigation. In Figure 1 the chill plate that is used to transfer heat to/from the module is shown in an exploded view. Of primary interest with the design of the chill plate is its capability to transfer heat with an even temperature distribution across its surface in order to achieve a balanced temperature distribution within the electrochemical cells (to maintain balanced electrical performance). The goal here will be to learn how to create a thermal FE model to quantify the heat transfer capabilities of the cells based on temperature gradient limitations. In the end a model containing the coupled electrochemical-thermal effects within the cell and the coupled thermalfluid effects between the module and the chill plate will be needed, but as a project of this magnitude is infeasible for a quarter long term project it was decided to focus on the temperature

distribution in two dimensions within a cell as an introductory learning example of the development of a FEM code.

Figure 1 - Exploded view of the battery module chill plate

Figure 2 - Assembled battery module in CAD

Figure 3 - Exploded view of the full battery module

Typically a FEM package will contain three main sections: 1) Pre-proccesor, 2) Solver, and 3) Postprocessor. In a class setting most attention is paid on section 2, the solving of the FEM equations, e.g. solving the Differential Equation in a discretized domain using shape functions of varying orders and applying Galerkins approach to the Method of Weighted Residuals. However, as important as this is obviously, a good code is really nothing without proper attention being paid to sections 1 and 3 as well. And before actually developing ones own code it is difficult to fully understand how much attention does need to be paid there. In all actuality those are likely to be the largest areas of focus for a company developing a package for industry. Think of it this way, it is the job of a company creating a commercial package to disconnect the user as much as possible from the gritty details and allow for them as intuitively as possible to solve their problem. Thus large amounts of work must be done behind the scenes to take their part, create an advanced mesh, create the global equations for that mesh, solve the system and then present those results in a clear and understandable fashion. Certainly no easy task and thus the reason why companies like ANSYS, COMSOL, etc., are able to charge so much for their products. Here a relatively simple example is undertaken to begin to get a flavor of what it takes to create a FEM package from scratch. Thus, the final objective here will be to create a code in MATLAB that can solve for the temperature distribution in a 2d, time dependent heat conduction problem that has convective boundary conditions. The capability to control the internal heat generation and the convection coefficient as a function of time will be added as well to study the temperature gradients

as a function of the control strategy being used. Additionally, this paper will be written in a way that walks the reader through the development process, in an albeit streamlined version of the story. The intent here is for it to possibly serve as a learning tool for future generations of students working on a similar project.

METHODS
SYSTEM GENERATION CODE
PRE-PROCESSING
The resulting code that was developed to meet this projects objective has two main parts. The first m-file has an initial section which is dedicated to the insertion of material parameters as well as the number of elements that are to be used for the rectangular mesh. Following that the convective boundary coefficients and temperatures are defined. After all inputs are defined the elemental matrices are computed. First the x,y coordinates for all of the nodes are determined. This is done by the function called elementCoords and is shown below:
function [n_coords] = elementCoords(n_ele_x,n_ele_y,dx,dy) n_coords = zeros((n_ele_x+1)*(n_ele_y+1),2); for j = 1:(n_ele_y+1) for i = 1:(n_ele_x+1) n_coords(i+(j-1)*(n_ele_x+1),1) = dx*(i-1); n_coords(i+(j-1)*(n_ele_x+1),2) = dy*(j-1); end end

The key to that function is the determination of the index based on the nodal numbering scheme. Next the nodal numbers that apply to each element are located. This is commonly referred to as the element connectivity. This utilizes the function findElemNodes, which is displayed below:
function [elem_nodes] = findElemNodes(n_ele_x,n_ele_y) elem_nodes = zeros(n_ele_x*n_ele_y,4); for j = 1:n_ele_y for i = 1:n_ele_x k=i+(j-1)*n_ele_x; elem_nodes(k,1) = k+(j-1); elem_nodes(k,2) = (k+1)+(j-1); elem_nodes(k,3) = (k+(n_ele_x+2))+(j-1); elem_nodes(k,4) = (k+(n_ele_x+1))+(j-1); end end

After this, based on the entered number of x- and y-elements a function determines which elements fall into one of three categories: 1) Core elements, 2) Corner elements and 3) Boundary elements. For the boundary elements those are refined further into which are bottom, right, top and left. The

elements are separated as such to allow for proper boundary condition application. Hence the core elements have no external B.C. being applied, the corners take in two different B.C.s and the boundaries take in a single B.C. on one of its sides based on whether that is located on the bottom, right, etc. The function findElems follows:
function [core_elems,corner_elems,bott_elems,top_elems,right_elems,left_elems] = findElems(n_ele_x,n_ele_y) % Core elements num_core_elems = (n_ele_x-2)*(n_ele_y-2); core_elems = zeros(num_core_elems,1); for j = 1:(n_ele_y-2) for i = 1:(n_ele_x-2) k=i+(j-1)*(n_ele_x-2); core_elems(k) = (n_ele_x+2) + (i-1) + (j-1)*n_ele_x; end end % Corner elements %num_corner_elems = 4; % fixed at four as this is a simple rectangular mesh and thus must have four corners corner_elems(1) = 1; % bottom left corner corner_elems(2) = n_ele_x; % bottom right corner corner_elems(3) = n_ele_x*n_ele_y; % top right corner corner_elems(4) = n_ele_x*n_ele_y - (n_ele_x-1); % top left corner % Bottom elements num_bott_elems = (n_ele_x - 2); bott_elems = zeros(num_bott_elems,1); for i = 1:num_bott_elems bott_elems(i) = 1+i; end % Top elements num_top_elems = (n_ele_x - 2); top_elems = zeros(num_top_elems,1); for i = 1:num_top_elems top_elems(i) = (n_ele_x*n_ele_y - (n_ele_x-2))+(i-1); end % Right elements num_right_elems = (n_ele_y - 2); right_elems = zeros(num_right_elems,1); for i = 1:num_right_elems right_elems(i) = 2*n_ele_x + (i-1)*n_ele_x; end % Left elements num_left_elems = (n_ele_y - 2); left_elems = zeros(num_left_elems,1); for i = 1:num_left_elems left_elems(i) = n_ele_x+1 + (i-1)*n_ele_x; end %--------------------------------------------------------------------------

All of this preliminary work described above essentially develops the mesh and prepares which elements will get which boundary conditions as well as who is connected to who.

ELEMENT EQUATION FORMULATION


Finally, with the completion of the above it is now time to assemble the global system of equations to prepare it for time-stepping. The equation below describes the general differential equation being solved here and is used in the application of MWR via Galerkins approach. This is the general D.E. for transient two-dimensional heat conduction with internal heat generation Q. ( ) ( )

The equations are derived for a 4-noded rectangular element using linear shape functions. Here a function was developed using MATLABs built in symbolic function solver to do the error prone work of integrating the set of equations developed through the use of the MWR. An example of the code is below:
% This code is currently written to symbolically create the matrices % derived using Galerkin's method on the MWR function for a 2-d square % element heat transfer problem. The boundaries are currently set with % convection and one of the edges has dramatically larger convection due to % the chill plate. function [C,Ktot,Rtot] = SymbolicEqns_LinearShape(dx,dy,h,Tamb,rho,cp) % clc;close;clear; % rho = 2250; % cp = 980; % h=[5 0 0 0]; % Tamb = [298 0 0 0]; % dx = .1; %m % dy = .1; %m xc = dx/2; yc = dy/2; y1 = 0; x1 = 0; y2 = dy; x2 = dx; % rho = 2200; %kg/m^3, average density of the lithium battery % cp = 980; %J/(kg-K), average specific heat of the lithium battery kx = 25; %W/(m-K), thermal conductivity of the Li-batt in the x-direction ky = 25; %W/(m-K), thermal conductivity of the Li-batt in the y-direction h1 h2 h3 h4 Te1 Te2 Te3 Te4 = = = = = = = = h(1); h(2); h(3); h(4); %W/(m^2-K), %W/(m^2-K), %W/(m^2-K), %W/(m^2-K), heat heat heat heat transfer transfer transfer transfer coefficient coefficient coefficient coefficient at at at at the the the the bottom edge of the cell right edge of the cell top edge of the cell left edge of the cell

Tamb(1); Tamb(2); Tamb(3); Tamb(4);

% Shape functions syms x y psi = 2*(x-xc)/dx; eta = 2*(y-yc)/dy; N1 = .25*(1-psi)*(1-eta); N2 = .25*(1+psi)*(1-eta); N3 = .25*(1+psi)*(1+eta);

N4 = .25*(1-psi)*(1+eta); % derviatives of the shape functions to be used for temperature gradient % interpolation dN1_dx = diff(N1,x);dN2_dx = diff(N2,x);dN3_dx = diff(N3,x);dN4_dx = diff(N4,x); dN1_dy = diff(N1,y);dN2_dy = diff(N2,y);dN3_dy = diff(N3,y);dN4_dy = diff(N4,y); % Create matrices of the shape functions and the derivatives N_row = [N1 N2 N3 N4]; N_mat = N_row'*N_row; B_mat = [dN1_dx dN2_dx dN3_dx dN4_dx; dN1_dy dN2_dy dN3_dy dN4_dy]; BT_B = B_mat'*B_mat; %% Perform integration in order to get element matrices C and K % Get [C] matrix C1 = int(N_mat,x,x1,x2); C = rho*cp*int(C1,y,y1,y2); % Get [Kcond] matrix D = [kx 0;0 ky]; BT_Bcond = B_mat'*D*B_mat; Kc = int(int(BT_Bcond,x,x1,x2),y,y1,y2); % Get the [Kconv] matrices; there's one for each boundary (four for the square element) Kh1 = h1*int(subs(N_mat,y,y1),x,x1,x2); Kh2 = h2*int(subs(N_mat,x,x2),y,y1,y2); Kh3 = h3*int(subs(N_mat,y,y2),x,x1,x2); Kh4 = h4*int(subs(N_mat,x,x1),y,y1,y2); Ktot = Kc + (Kh1 + Kh2 + Kh3 + Kh4); %% Finally the right side vectors are to be derived % Internal heat generation Q = 0; R_Q1 = int(N_row',x,x1,x2); R_Q = int(R_Q1,y,y1,y2); R_Q = Q*R_Q; % Convective resistance term R_h1 = h1*Te1*int(subs(N_row',y,y1),x,x1,x2); R_h2 = h2*Te2*int(subs(N_row',x,x2),y,y1,y2); R_h3 = h3*Te3*int(subs(N_row',y,y2),x,x1,x2); R_h4 = h4*Te4*int(subs(N_row',x,x1),y,y1,y2); Rtot = R_Q + (R_h1 + R_h2 + R_h3 + R_h4);

The general form of the resulting equation from the MWR is as follows:

This simplifies to:

where,

This is the general equation for three-dimensions and includes constant temperature, heat fluxes and radiative heat loads, however in this case the additional loads mentioned here are done away with as well as the third z-dimension. Thus as can be seen in the above code (function:
SymbolicEqns_LinearShape) first some parameter initialization is performed, then the linear

shape functions are created and then differentiated with respect to each spatial dimension. The N vector and NTN matrix is generated as well as the B and BTB matrices. Finally, once these matrices are constructed from the shape functions and there partial spatial derivatives the C, K and R matrices and vector may be computed through integration. Again for the integration the MATLAB symbolic function is applied.

SYSTEM EQUATION ASSEMBLY


The three outputs from the symbolic element solver are sent to the assemble function which performs the scattering of the elemental values to the respective locations in the globally sized matrix based on the nodal values for each element. That code is shown below for the core elements:
function [Kcores1,Ccores1,Rcores1] = assemble(Ktot_core,Ctot_core,Rtot_core,core_elems,dof,elem_nodes,Kcores1,Ccores1,Rcore s1) for i = 1:length(core_elems) nodes = elem_nodes(core_elems(i),:); name = ['K_' num2str(i)]; Kcores.(name) = zeros(dof,dof); Kcores.(name)(nodes(1),nodes(1)) = Ktot_core(1,1); Kcores.(name)(nodes(1),nodes(2)) = Ktot_core(1,2); Kcores.(name)(nodes(1),nodes(3)) = Ktot_core(1,3); Kcores.(name)(nodes(1),nodes(4)) = Ktot_core(1,4); Kcores.(name)(nodes(2),nodes(1)) = Ktot_core(2,1); Kcores.(name)(nodes(2),nodes(2)) = Ktot_core(2,2); Kcores.(name)(nodes(2),nodes(3)) = Ktot_core(2,3); Kcores.(name)(nodes(2),nodes(4)) = Ktot_core(2,4); Kcores.(name)(nodes(3),nodes(1)) = Ktot_core(3,1); Kcores.(name)(nodes(3),nodes(2)) = Ktot_core(3,2); Kcores.(name)(nodes(3),nodes(3)) = Ktot_core(3,3); Kcores.(name)(nodes(3),nodes(4)) = Ktot_core(3,4); Kcores.(name)(nodes(4),nodes(1)) = Ktot_core(4,1); Kcores.(name)(nodes(4),nodes(2)) = Ktot_core(4,2); Kcores.(name)(nodes(4),nodes(3)) = Ktot_core(4,3); Kcores.(name)(nodes(4),nodes(4)) = Ktot_core(4,4); Kcores1 = Kcores.(name) + Kcores1; Ccores.(name) = zeros(dof,dof); Ccores.(name)(nodes(1),nodes(1)) Ccores.(name)(nodes(1),nodes(2)) Ccores.(name)(nodes(1),nodes(3)) Ccores.(name)(nodes(1),nodes(4)) Ccores.(name)(nodes(2),nodes(1)) Ccores.(name)(nodes(2),nodes(2)) Ccores.(name)(nodes(2),nodes(3)) Ccores.(name)(nodes(2),nodes(4)) Ccores.(name)(nodes(3),nodes(1))

= = = = = = = = =

Ctot_core(1,1); Ctot_core(1,2); Ctot_core(1,3); Ctot_core(1,4); Ctot_core(2,1); Ctot_core(2,2); Ctot_core(2,3); Ctot_core(2,4); Ctot_core(3,1);

Ccores.(name)(nodes(3),nodes(2)) Ccores.(name)(nodes(3),nodes(3)) Ccores.(name)(nodes(3),nodes(4)) Ccores.(name)(nodes(4),nodes(1)) Ccores.(name)(nodes(4),nodes(2)) Ccores.(name)(nodes(4),nodes(3)) Ccores.(name)(nodes(4),nodes(4))

= = = = = = =

Ctot_core(3,2); Ctot_core(3,3); Ctot_core(3,4); Ctot_core(4,1); Ctot_core(4,2); Ctot_core(4,3); Ctot_core(4,4);

Ccores1 = Ccores.(name) + Ccores1; Rcores.(name) = zeros(dof,1); Rcores.(name)(nodes(1)) = Rtot_core(1); Rcores.(name)(nodes(2)) = Rtot_core(2); Rcores.(name)(nodes(3)) = Rtot_core(3); Rcores.(name)(nodes(4)) = Rtot_core(4); Rcores1 = Rcores.(name) + Rcores1; end

In that function it loops through based on the number of the type of elements it is working on. Shown for example is for the core elements and hence it uses the number of core elements. It is computing the globally sized matrix for each element and then simply adding that to the previously calculated matrix to assemble the full system. This is then performed for all of the different sets of elements. Finally, after the global matrix is generated for each set of elements those are all summed together to create the truly full system of equations. This finally finishes the system generation code and this information is then saved to be loaded by the time-stepping code and then finally the data must be visualized in some useful manner.

SOLVING: TIME-STEPPING SCHEME


Here a simple Euler forward time stepping scheme was employed. Below is the basic Euler equation as well as it shown in a simplified form to compute the new temperatures:

[ ]

( [ ]

[ ]

[ ]) [ ]) ]

[([ ]

Where C, K, and fn are equivalent to the C, K, and R computed for the system, respectively. This equation is iterated on for as long as one would like to perform a simulation. For thermal systems selection of the time step size is rather important. If the step size is too large the data will be complete garbage. Here the following equation was used to compute the necessary step size based on the systems physical parameters.

It was found here that the actual time step needed to be much smaller for the system to run.

clc;close;clear; load('GlobalSys_6by6_030713.mat'); n_ele_x = 6; n_ele_y = 6; dof = (n_ele_x+1)*(n_ele_y+1); %% Numerical Integration of system % Initial uniform domain temperature TinC = 45; Tinit = 273.1+TinC; % Parameters used to create the time vector start_time = 0; k = 25; rho = 2169; cp = 980; alpha = k/rho/cp; L = .1; lamM = 12*alpha/L^2; dt_crit = 2/lamM; dt = 1/100*dt_crit; end_minutes = 30; end_time = 60*end_minutes; time = start_time:dt:end_time; % Initialize a temperature matrix for the four node linear % element Tl = zeros(dof,length(time)); Tl(:,1) = Tinit*ones(length(dof),1); % Create Euler time stepping system using the linear shape % element Fg = dt*Rg; Gg = Cg - dt*Kg; % Linear shape function system time stepping %for i=2:length(time) RT = 25; room_temp = 273.1+RT; i=2; while mean(Tl(:,i-1))>room_temp && i<length(time) Tl(:,i) = Cg\(Fg+Gg*Tl(:,i-1)); i=i+1; end clear Fg Gg Cg Rg Kg load('GlobalSys_Settling_6by6_030713.mat'); end_minutes_s = 3; end_time_s = 60*end_minutes_s; time_s = start_time:dt:end_time_s; % Initialize a temperature matrix for the four node linear % element Tls = zeros(dof,length(time_s)); Tls(:,1) = Tl(:,i-1); % Create Euler time stepping system using the linear shape % element Fgs = dt*Rg; Ggs = Cg - dt*Kg; % Linear shape function system time stepping for k=2:length(time_s) Tls(:,k) = Cg\(Fgs+Ggs*Tls(:,k-1)); end

rectangular

function

rectangular

function

The code shown above is the portion that performs the times-stepping. For this particular simulation a while loop was run until a certain mean temperature was met. This was followed by inserting the last temperature values as the initial conditions to a second for loop to complete the simulation. That was run for a fixed amount of time.

POST-PROCESSING
Here the post processing that was completed consisted of creating animations since this data was a transient set. For that the WriteVideo function of MATLAB was used. The following code is an example of how to create a simulation:
xmin = 0;xmax = L;ymin = 295; ymax = 320; name2 = 'Cool_6by6_midTemps_Comparison.avi'; vid = VideoWriter(name2); vid.Quality = 100; vid.FrameRate = 15; open(vid); n=3; for j=1:10:length(Ttot(1,:)) figure(3) h=plot(x,Ttot(22:28,j),'-*',xbg,Tmc(:,j),'-.'); set(h,'LineWidth', n); set(gca,'FontSize',14); axis([xmin xmax ymin ymax]);xlabel('Cell Width, [m]');ylabel('Temperature, [K]'); title(['Cool-down from ' num2str(TinC) ' ^oC to ' num2str(RT) ' ^oC, Total Time = ' num2str(((i-1)*dt/60)+end_minutes_s) ' minutes']); legend('FEM','Bond Graph'); writeVideo(vid, getframe(gcf)); end close(vid); winopen(name2);

First a set of limits is set for the plotting axes followed by a name that the video file will take. Then the video file is started using the VideoWriter function and the quality and frame rate are set. The vid is opened and finally the for-loop that will step through the time data is begun. It steps through the length of time and the stepping amount is changed depending on how long one wants the generated animation to be. Then, within the loop the typical plotting is peformed as well as any modifications one may want to make to the figure. Finally, the writeVideo/getframe command is used to tell each figure to become a frame of the video. This then loops through the length of the time vector and then closes the vid file. Winopen may be used as an option to tell Windows to open the *.avi file post loop completion. Additionally, a heat map may be generated nicely using the pcolor plotting function in MATLAB. The code used here looks like so:

name1 = 'test1_15minCool_6by6.avi'; vid = VideoWriter(name1); vid.Quality = 100; vid.FrameRate = 15; open(vid); % Create an animation and set the color axes to stay fixed based on the % scaling in the initial pcolor plot created below T = [Tinit, 277, 275;Tinit,278,276;Tinit,277,274]; pcolor(T); shading interp; colorbar; caxis manual; set(gca,'nextplot','replacechildren'); % run the loop to plot the temp map through time and get the movie frames x = n_coords(:,1); y = n_coords(:,2); for i = 1:(10/dt*dt):length(time) for j = 1:(n_ele_y+1) for k = 1:(n_ele_x+1) T(j,k) = Tl(((dof-n_ele_x)+(k-1)-((j-1)*(n_ele_x+1))),i); end end pcolor(T);shading interp;colorbar; writeVideo(vid, getframe(gcf)); end close(vid); winopen(name1);

The nested for-loops are used to take the vector of nodal temperatures and generate a matrix in the shape of the physical object, in this case a 2d grid.

RESULTS
Show in the two figures below are screen-shot examples of the data generated by this code. Figure 4 shows the temperature profile along the center line of the 2d grid in the x-direction. Additionally, shown in this same figure the data from a section of a 3d lumped thermal model of the same battery module that was generated using the Bond Graph modeling technique is shown for comparison. A side motivation for generating this code was to use it to validate the BG model that had been developed in our lab earlier in the year. It turns out that the results are quite similar and this is due to the proper number of lumps being used and the relatively slow heat transfer rates. Figure 5 shows a screen-shot of the heat map animation that was generated to visualize the temperature distribution over the entire domain.

Figure 4 - A screen-shot of the animation that was generated using the first example of the animation code.

Figure 5 - A screen-shot of the animation shown in the second example code for creating animations.

CONCLUSIONS
Much learning was done in the creation of this code. It proved very useful as an educational tool in understanding how one may actually use this thing called the Finite Element Method to solve a differential equation. That was really the core objective here, but as stated in the background section it was also to make a tool that was useful to the battery thermal management research being conducted in my lab. A 2d transient heat conduction problem with convection boundary conditions can be solved using this code and this allows for the start of its application to the labs research. Moving forward, taking what was learned here as a stepping point, developing the expanded capability of solving a coupled electrochemical-thermal problem as well as the coupled thermal-fluid problem of the actual battery system will provide the greatest benefit to the labs research. This work here certainly provided that initial momentum.

REFERENCES
Nikishkov, Gennadly. (2010). Programming Finite Elements in JavaTM. London: Springer-Verlag. The main equations shown above were used from Chapter 2. Chessa, J. 2002. Programming the Finite Element Method with MATLAB. Website: http://www.math.mcmaster.ca/~bprotas/MATH745b/matlab_fem.pdf This source was useful to understand someone elses process for developing a similar code. Cailletaud, G. Finite Element: Matrix Formulation. PowerPoint. Unkown date of publication. First viewed 25 February 2013. http://mms2.ensmp.fr/msi_paris/deformation/transparents/e_ElemFormulation.pdf. This served useful in wrapping my head around the matrix formulation for one element into the global size.

Вам также может понравиться