CFD - Incompressible Flows Mohamed El Amine GORINE November 2022 Abstract In this case study, we were asked to get familiar with the steps and algorithm given to us for the steady heat problem of a cylinder shape geometry with Dirichlet masks, generated using FreeFEM++ then solved by applying Finite Element method using GNU Octave. In the second part, we were asked to adapt the algorithm provided to account for the unsteadiness of the problem while keeping the same geometry and to compare the results obtained. 1 Introduction In mathematics and physics, the heat equation is a certain partial differential equation. Solutions of the heat equation are sometimes known as caloric functions. The theory of the heat equation was first developed by Joseph Fourier in 1822 for the purpose of modeling how a quantity such as heat diffuses through a given region. [2] We are addressing the problem of the steady and unsteady heat transfer around a fixed cylinder. The cylinder is placed in a square domain and we assume that temperature T ( #» x , t) follows the steady and unsteady heat equations. We note Ω the total volume of the fluid and S = S1 ∪ S2 the surface containing this volume. We assume that temperature follows only Dirichlet boundary conditions and denote by Ta and Tb the temperatures imposed: [1] T ( #» x ∈ S1 , t) = Ta and T ( #» x ∈ S2 , t) = Tb (1) To solve this problem, a template is provided which simulates the corresponding steady heat problem (i.e. with no time variation but the same geometry and set of boundary conditions). The aim is to adapt this template to the simulation of an unsteady heat problem. Heat transfer is the transfer of thermal energy from a hot body to another cold body. This thermal energy transfer can occur in steady state or transient conditions. At steady state, the temperature in the system does not change with time. Conversely, in transient conditions, the temperature in the system changes over time. A transient is a precursor to a steady state. At steady state, the system does not exist from the beginning. After heat transfer is initiated, some time must elapse before the system reaches steady state. The system is in a temporary state during this transition period. Of course, the system cannot live permanently in a transient state. The temperature of the system will eventually reach the temperature of the heat source and when this 1 happens the system will reach steady state. Even if the amount of heat transferred to the system increases, eventually the system reaches a critical temperature and the energy transferred to it starts causing phase changes in the system instead of raising the temperature. 1.1 Steady heat problem We start first with the steady heat problem and assume that the temperature T ( #» x ) follows the steady heat equation, namely: −∇ · (κ∇T ) = s (2) Where the coefficient κ denotes the thermal diffusivity and s a source term. By applying the weak formulation we find: (3) κK T = M s Where M and K are the mass and stiffness matrices respectively who are extracted using FreeFEM++ and loaded to Octave code to use. We assign : A = κK and C = M s Introducing Dirichlet masks for the resolution and decomposing the temperature vector as : T = T ′ + T D and reformulating it to get: A T ′ = C − A T D = C′ (4) Where T ′ and T D are the unknown and known (Dirichlet masks) values of T respectively. We note also T red the vector containing the nonzero coefficients of T ′ therefore Ared and C ′red the corresponding matrices. At last, the unknowns are computed by solving: Ared T red = C ′red 1.2 (5) Unsteady heat problem We move to the unsteady heat problem and assume that the temperature T ( #» x ) follows the unsteady heat equation, namely: ∂T − ∇ · (κ∇T ) = s ∂t (6) Where the coefficient κ denotes the thermal diffusivity and s a source term. We introduce a time step ∆t and time tn = n∆t. We denote by T (n) the temperature at time tn . We discretize the equation of unsteady heat transfer in time and we get: T (n+1) − T (n) = α [∇ · (κ∇T (n+1) + s(n+1) ] + (1 − α) [∇ · (κ∇T (n) + s(n) ] ∆t with α taking different values according to time integration method: • Euler explicit: α = 0 • Euler implicit: α = 1 2 (7) • Crank-Nicolson: α = 1/2 We assume that temperature follows the same Finite Element decomposition as in the steady heat problem. So we get the following dicretized equation : 1 1 (n+1) = (8) M + ακK T M − (1 − α)κK T (n) + M αs(n+1) + (1 − α)s(n) ∆t ∆t 1 1 M + ακK and B (n) = ∆t M − (1 − α)κK T (n) +M αs(n+1) + (1 − α)s(n) We assign A = ∆t Introducing Dirichlet masks for the resolution and decomposing the temperature vector as : T = T ′ + T D and reformulating it to get: A T ′(n+1) = B (n) − A T D = B ′(n) (9) Following the same steps for the steady case, we get: (n+1) Ared T red 2 ′(n) = B red (10) Assignment For the first part, we will try to generate the mesh and matrices of stiffness, mass and also the boundary conditions with FreeFEM++, then implementing them in the resolution script using Octave. After that, the algorithm will be divided to small parts to be described. Testing and describing the influence of the space resolution and the source term s. In the second part, we will try to adapt the provided algorithm to account for the unsteadiness of the problem and comparing the solution 2.1 Part 1 Downloading the template code sources and place them in the working repository. Figure 1: working repository Generating the geometry and Finite Element matrices with FreeFEM++. 3 Figure 2: FreeFEM code source lines 1 to 27 Figure 3: FreeFEM code source lines 28 to 55 Figure 4: FreeFEM code source lines 56 to 76 4 After that, the geometry will pop-up and the different data will be generated in the same repository. Figure 5: Geometry of the domain disretized Figure 6: Data generated Solving the steady heat problem using Octave with the aid of the script solution steady heat.m By applying the following parameters : grid refinement factor RF=2 , without source term s=0 We get the results: 5 Figure 7: Results of steady case Description of different scripts: readarray.m function x=readarray(filenm) f=fopen(filenm); x=fscanf(f,'%g'); fclose(f); n=x(1); x=x(2:end); this function access and reads data of an array filenm which contains the geometry of the domain readmat.m function A=readmat(filenm) f=fopen(filenm); text=textscan(f,'%s','delimiter','\n'); fclose(f); text=text{1}; text=text(3:end); nm=sscanf(text{1},'%g'); n=nm(1); m=nm(2); ifsym=nm(4); nval=nm(3); A=zeros(nval,3); % for ii=1:nval 6 A(ii,:)=sscanf(text{ii+1},'%g'); end A(:,1)=A(:,1)+1; A(:,2)=A(:,2)+1; A=sparse(A(:,1),A(:,2),A(:,3),n,m); if(ifsym) A=A+(triu(A,1))'; end this function access and reads data of a matrix filenm, mainly Finite Element matrices, stiffness and mass. visu 2D.m function fig=visu_2D(x,y,mesh_info,buffer,... EdgeColor_setting,visibility); rank=mesh_info(:,1)+1; for ii=1:length(rank) vertex1(rank(ii))=mesh_info(ii,2)+1; vertex2(rank(ii))=mesh_info(ii,3)+1; vertex3(rank(ii))=mesh_info(ii,4)+1; end fig=figure('Visible',visibility); hold on; for ii=1:length(rank) xplot(1:3,ii)=[x(vertex1(ii)) x(vertex2(ii)) x(vertex3(ii))]; yplot(1:3,ii)=[y(vertex1(ii)) y(vertex2(ii)) y(vertex3(ii))]; buff_plot(1:3,ii)=[buffer(vertex1(ii)) buffer(vertex2(ii)) ... buffer(vertex3(ii))]; end patch(xplot,yplot,'cdata',buff_plot,'EdgeColor',EdgeColor_setting); % axis equal; axis tight; colorbar %% % % ££e^{\pi i} + 1 = 0££ % % for x = 1:10 % % for x = 1:10 % % for x = 1:10 % % for x = 1:10 % % for x = 1:10 % 7 % for x = 1:10 % % for x = 1:10 % disp(x) % end % % disp(x) % end % % disp(x) % end % % disp(x) % end % % disp(x) % end % % disp(x) % end % % disp(x) % end % % xlabel x; ylabel y; This function visualizes the temperature field found after resolution of the problem. solution steady heat.m clear all; close all; %addpath ../COMMON/; addpath ../COMMON_BOUSSINGAULT/; clear all deletes all variables and free memory, close all closes all figures if exist. addpath adds named directories to the function search path. % Visual aspects set(0,'defaultAxesFontSize',20); set(0,'defaultAxesLineWidth',2); this part handles the visual aspects and sets different property values for the graphics that comes after. % Physical parameters kappa=0.005; amplitude_s=0.0; % 0.0 Thole=5; Tborder=2; Tcolormap=[2 5]; 8 this part presents the physical parameters used in calculations ; thermal diffusivity kappa, the source term amplitude amplitude s, Temperature at the hole Thole, Temperature at the borders Tborder, and color mapping range Tcolormap % Read the informations from the geometry x=readarray('x.dat'); y=readarray('y.dat'); mesh_info=load('meshinfo.dat'); this part reads and loads geometry data generated with FreeFEM++ using the function readarray and load will load all variables within the file meshinfo.dat. % Read matrices from the Finite Element Formulation % Read mass matrix M=readmat('M.dat'); [n,m]=size(M); %pcolor(M); K=readmat('K.dat'); this part reads the mass and stiffness matrices using the function readmat, and gets the matrix dimensions using size. % Get the position of the Dirichlet masks BC_Dir_hole=readarray('BCdir5.dat'); ii_Dir_hole=find(abs(BC_Dir_hole)>0); BC_Dir_borders=readarray('BCdir1234.dat'); ii_Dir_borders=find(abs(BC_Dir_borders)>0); BC_Dir=readarray('BCdir.dat'); ii_int=find(BC_Dir==0); this part reads the Dirichlet boundary conditions data using the function readarray and determines positions (indices) of the non-zero elements with the exception of ii int which deals with interior of the domain BCdir.dat, hence excluding the boundaries. % Build corresponding matrices A=kappa*K; Ared=A(ii_int,ii_int); s=amplitude_s*ones(n,1); in this phase we build the corresponding matrices needed to resolve the problem ; the reduced coefficient matrix Ared from A and the source term vector s. % SOLVE Td=zeros(n,1); Td(ii_Dir_hole)=Thole; Td(ii_Dir_borders)=Tborder; % C=M*s-A*Td; Cred=C(ii_int); Tred=Ared\Cred; % T=Td; T(ii_int)=Tred; % 9 before solving the system, temperature boundary values Td are introduced to reduce the system. %FIG=visu_2D(x,y,mesh_info,T,'black','on'); %FIG=visu_2D(x,y,mesh_info,T,'none','off'); FIG=visu_2D(x,y,mesh_info,T,'none','on'); caxis(Tcolormap); % savename=['steady_solution']; print(FIG,'-r200','-djpg',savename); the last part concerns the visualisation of results obtained also called the ”heat map” of the problem using the function visu 2D with coordinates x, y, mesh data mesh info, and temperature field T as arguments while saving the figure in the repository as the script and named steady solution. Influence of the space resolution: changing the mesh refinement factor will evidently change the accuracy of the resolution ; dense mesh increases the accuracy of results by having more nodes but in result more computation time and inversely for coarser mesh. using the function cputime() we get: RF Total cpu time in seconds 2 2.015625 3 3.453125 4 4.609375 5 6.187500 Table 1: Run time for steady heat case without source term for different refinement factors Figure 8: mesh geometry for RF=2 10 Figure 9: mesh geometry for RF=3 Figure 10: mesh geometry for RF=4 Figure 11: mesh geometry for RF=5 11 Influence of the source term s: Source term measures the physical effect of an external heat source. It has units of heat flux , i.e. change in temperature per unit time), thus it gives the instantaneous temperature change due to an external heat source. considering no source term makes the differential equation homogeneous unlike introducing other values to it. taking into consideration RF=2 for simplification purposes Figure 12: Heat map without source term s=0 Figure 13: Heat map with source term s=0.05 12 Figure 14: Heat map with source term s=0.1 Figure 15: Heat map with source term s=-0.05 Figure 16: Heat map with source term s=-0.1 13 Figure 17: Heat map with source term s=-0.15 we notice by varying the source term, the obtained results change accordingly ; higher positive values of s means more propagation of heat towards the borders with fewer heat loss (damping) along the way, equilibrium is reached at higher values of temperature hence temperature at the hole, and vice versa for negative values of source term. 2.2 Part 2 In this part, we will try to adapt the steady case solution algorithm to account for the unsteadiness of the problem while keeping the same geometry and set of boundary conditions. First step would be adding the specification of time step ∆t, for our case we choose ∆t = 0.001. the number of iterations will vary along the results obtained to reach equilibrium and solution converges with an absolute error tolerance of in our case 10−3 with respect to the steady solution. the coefficient of time integration method α will take three different values needed to discritize the equation and to know which method converges faster for this problem a loop while over time is introduced to compute the temperature field at different time iterations. For simplification purposes, we assume the source term s is invariant over time which means s(n+1) = s(n) . In the following we will try to solve the problem with refinement factor RF = 2 and for time integration coefficient α we will try to compare the corresponding temperature field result for each value. The solution script is provided with the attachments folder. Results will be as next: 14 alpha run time in seconds number of iterations 0 155.015625 66209 0.5 160.609375 66213 1 157.625000 66216 Table 2: run time and number of iterations for different α values We notice no big difference between time integration schemes and run time speed to reach results. An animation .gif file for the heat map of the results is provided with the attachments. 3 Conclusion To summarize, no such system initially exists under stationary conditions. After heat transfer begins, the system must pass for a period of time to reach a steady state. such phenomena is called unsteadiness. The temperature of the system will eventually reach the temperature of the heat source, and once this happens, the system reached equilibrium. The first part was dedicated to steady state case. The influence of mesh refinement factor RF and how it affects the accuracy and reliability of the study. The influence of source term s and how it affects the stability of the system and its equilibrium phase. The second part dealt with the unsteadiness problem by adapting the provided steady case algorithm to reach desired temperature field results while passing by iterations and trying multiple time integration methods for the goal to converge to steady case results. References [1] Chouippe. CFD - incompressible flows - steady and unsteady heat problem. Assignement sheet. Oct. 11, 2022. [2] Wikipedia contributors. Heat equation. Nov. 4, 2022. url: https://en.wikipedia. org/wiki/Heat_equation. 15