Sei sulla pagina 1di 38

Turin, July 9th 2012

Master degree in Mechanical Engineering Numerical Modelling Academic year 2011-2012

Report on MATLAB laboratory

Finite elements analysis of a panel heating system

Professors: Prof. Claudio Canuto Prof. Paolo Bardella

Students: Gabriele Persichilli (188681) Navid Amanat Shahin Tabandeh (181504) (181655)

Index

1. Introduction.....4 2. Problem description.....5 3. Model description....8 4. Numerical method..10 5. Numerical analysis.................11


5.1 5.2 5.3 5.4 5.5 5.6 Domain representation................14 Boundary conditions....................15 Stiffness matrix............................20 Steady state solution....................24 Mass Matrix.....................................26 Transient analysis........................27

6. Conclusions................30 7. Appendix........................31
7.1 7.2 7.3 7.4 Script...............................................31 AssemblaDiffCalore ...............................................33 AssemblaMatriceMassaCalore (Heat Mass Matrix).......................35 GUI..................................................36

1.

Introduction

This report presents the analysis of a panel heating system with numerical methods. Panel heating systems are a form of central heating systems which achieves indoor climate control for thermal comfort by means of controlled-temperature panels on the floor, walls, or ceiling; the temperature control is maintained by circulating water, air, or electric current through a circuit embedded in the panel. In particular, the studied system was previously designed by our group during the course of Advanced Engineering Thermodynamics.

Figure 1: typical section of a radiant panel. In this case, like in our case, the panel is embedded in the floor, under which the tubes (red) transport hot water.

In order to analyze the steady state behaviour and the time transient of the system the software MATLAB has been used to create the geometry of the model, to implement the numerical simulation and to obtain a graphical result. This tool was studied during the laboratory part of the course of Numerical Modelling. Moreover a Graphical User Interface (GUI) has been used in order to allow the user to choose some basic parameters of the model. This part has been freely introduced by us, thanks to our personal knowledge.

2.

Problem description

In this chapter the studied system will be analyzed more in detail, in order to provide a background knowledge of the problem. In our case, the panel heating system is used to guarantee thermal comfort to a house placed in Turin (more precisely in Torino Caselle) during the winter season, thus considering the worst condition; the house is composed by seven rooms and it has an autonomous heating system composed by panels embedded in the floor.

Figure 2: 3D model and plant of the studied house.

The heating system is composed by the panels, a boiler and a pump for the water recirculation; in particular, the panels are composed by equally spaced pipes of steel. The design started with data gathering about the outside thermal conditions and the inside thermal conditions that must be satisfied; then geometry definition of the house, thermal load and consequent design of the panels. Once the temperature of the flowing water had been calculated for each room, the boiler and the pump were designed.

Some basic data follows:


CASELLE TORINESE Altitude [m] Climatic Area Surface [m2] value 277 E 117 description

TEMPERATURES ta [C] to [C] tg [C]

20,0 inside air temperature -4,6 outside air temperature 9,8 ground temperature

This report focuses on the fundamental part of this system, which are the panels. Hence we need some basic information about the panel dimensions, thermal property and the temperature of the water for each room. Since the main goal of this report is to present the simulation and not the design of the heating system, all the calculations and the details wont be reported here, but only the final results which are important for the simulation itself:
PANEL ru [m2*K/W] M [m] Do [m] Di [m]

0,30 panel total resistivity 0,20 on-center space between tubes 0,014 tube external diameter 0,012 tube internal diameter

Room 1 2 3 4 5 6 7#1 7#2 TOT

tw [C] 33,4 31,0 32,0 32,2 32,3 32,1 31,0 31,0

Q [W] 266 999 929 523 1079 426 1266 1266 6752

tin [C] 34

tout [C] 32,8 28,5 30,2 30,6 30,7 30,3 28,5 28,5

m [kg/s] 0,053 0,043 0,058 0,037 0,078 0,027 0,055 0,055 0,407

Where: Q is the heat load tw is the mean water temperature tin is the inlet water temperature tout is the exit water temperature m is the water mass flow rate
Room 7 was divided in two parts for technical reasons. 6

At the end, the tubes layout was sketched:

Figure 3: Panel layout. The temperature decrease of the flowing water can be clearly visualized.

3.

Model description

In order to study the problem numerically, a proper model is required. We chose to model a generic room by considering the cross section of a part of the panel containing two adjacent tubes, one with hot water (red) and the other with cold water (blue), flowing in opposite directions.

Figure 4: 2D-model. The panel (grey), the hot tube (red), the cold tube (blue) and the covering tiles (brown).

One important consideration is that, in our case, the heat is exchanged by conduction, convection and radiation, hence an appropriate formulation of the problem must be implemented in order to avoid drastic errors, which will lead to completely wrong conclusions. This aspect will be treated more in detail in section 5.2.1.

Another important point is to choose the proper boundary conditions, in order to solve the boundary value problem related to the system, that is a differential equation together with a set of additional constraints (the boundary conditions) imposed at the extremes of the domain; the type and the definition of the boundary conditions depend on the nature of the system:

Dirichlet boundary condition This kind of constraint forces the unknown function, in our case the temperature, to have a given value on a given boundary domain; the condition is said to be homogeneous whenever the assigned values is zero. In practical terms we can impose the temperature on a given boundary:
, = (, )

We imposed Dirichlet boundary conditions at the inner diameter of the tubes, setting the temperatures equal to the ones chosen by the user. Neumann boundary condition This kind of constraint forces the derivative of unknown function to have a given value on a given boundary domain. In practical terms we can impose a certain the heat flux on a given boundary: , Where: is the heat flux 2 is the thermal conductivity We imposed Neumann boundary conditions on the two side boundaries equal to zero and on the lower boundary equal to water cooling heat flux to the ground which is fixed to zero one time and the calculated value by classical method another time. Robin boundary condition It is a sort of combination of Neumann and Dirichlet boundary conditions. It could be written as : , [ (, )] = = = (, ) = = =

Where is the temperature of the fluid flowing far away from the solid is the convective heat transfer coefficient 2

It is the weakest boundary, because neither the boundary flux nor the boundary temperature are known, it is only prescribing a functional dependence between them. We imposed Robin boundary conditions on the upper boundary, setting equal to the room temperature and the convective heat transfer coefficient of the panel composed of convection and linearized radiation.
9

4.

Numerical Method

To solve our model we used Finite Element Method (FEM), which is a numerical procedure that can be applied to obtain the solution of a variety of engineering problems, such as problems of static, transient, linear and nonlinear stress analysis, heat transfer and electromagnetism. It was developed from the need to solve a series of practical problems for which it is not possible to obtain an exact solution; this limit can be attributed both to the complex nature of governing differential equations and the difficulties that arise in dealing with boundary conditions. To overcome this limitation the approximate numerical solution is used, which, unlike the analytical solutions that shows the exact behavior of each point of the system, offers solutions that approximate the exact ones only at discrete points, called nodes. The first step of any numerical procedure is the discretization, a process which divides the system of interest in a large number of elements and nodes. Then a system of algebraic equations with integral formulation is created and it is assumed to represent an approximated continuous function to represent the solution of each element. The complete solution is then generated by assembling the individual solutions, assuming continuity in the bonds between the elements. In our case the engineering problem deals with heat transfer and we study the steady state condition and the transient. The finite element chosen for the discretization is a 2D element, in particular a triangle, since we are considering a generic point in the room, hence the axial direction of the tube is irrelevant for our purpose.

10

5.

Numerical Analysis

In this section we will get deeper in the core of the simulation, analyzing it step by step. First of all we have to define some general quantities, such as conductivity , density and heat capacity :
Sh(1)=set(Sh(1),'Conductivity',1); Sh(2)=set(Sh(2),'Conductivity',1.6); Sh(1)=set(Sh(1),'DensityByHeatCapacity',1506*0.84); Sh(2)=set(Sh(2),'DensityByHeatCapacity',1506*0.84);

An important advantage is that modeling a generic room allows the user to choose which room must be simulated by simply changing the values of the inlet and exit temperature of that room, thanks to the Graphical User Interface.

Figure 5: Graphical User Interface. The user have just to introduce the values of the temperature and click Solve

11

The GUI is sensitive to numbers, hence if then input is not properly defined, the GUI will give an error as feedback:

Figure 6: Feedback error from the GUI.

For initializing, GUI needs to know what the shape is so we define the its geometry:
function guigui_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject; guidata(hObject, handles); s(1)=Rect([0,0],[.4,.06]); s(2)=rect([0,.03+.00125],[.4,.0025]); s(1)=s(1)-(circle([-.114,0],[.014,.014])+circle([.114,0],[.014,0.014])); s(1)=set(s(1),'Conductivity',237); s(1)=set(s(1),'DensityByHeatCapacity',2700*896.9); s(2)=set(s(2),'Conductivity',237); s(2)=set(s(2),'DensityByHeatCapacity',2700*896.9); Draw(s)

12

The GUI structure is based on two text box and one push button. The code used for one text box, as an example, is shown below:
function density_Callback(hObject, eventdata, handles) density = str2double(get(hObject, 'String')); if isnan(density) set(hObject, 'String', 0); errordlg('Input must be a number','Error'); end

And then we can set this callback for push button:


tref1 = handles.metricdata.density; tref2 = handles.metricdata.volume;

13

5.1

Domain representation

At this point the real simulation code can be implemented. The first step is to define the domain geometry by setting one rectangle as tile layer and one as cement; we omit the two circles representing the pipes (already defined for the GUI) :

Sh(1)=Rect([0,0],[.4,.06])-(circle([-.1,0],[.014,.014])+circle([.1,0], [.014,0.014])); Sh(2)=rect([0,.03+.00125],[.4,.0025]); Sh(1)=set(Sh(1),'Conductivity',1); Sh(2)=set(Sh(2),'Conductivity',1.6); Sh(1)=set(Sh(1),'DensityByHeatCapacity',1506*0.84); Sh(2)=set(Sh(2),'DensityByHeatCapacity',1506*0.84); draw(Sh,'edge')

And we add Boundary conditions:


BC=Boundary(SH); BC(1).Polygons(1).Edge(1)=Neumann(0); BC(1).Polygons(1).Edge([2,4])=Periodic(@(x,y) [-x,y]); BC(2).Polygons(1).Edge([1,3])=Periodic(@(x,y) [-x,y]); BC(1).Polygons(1).Edge(3)=Continuity(); BC(2).Polygons(1).Edge(3)=Continuity(); BC(2).Polygons(1).Edge(2)=Robin(12,-240);%Robin(alfa, alfa*Tinf) BC(1).Polygons(3).Edge(1:16)=Dirichlet(tref1);%left pipe temp BC(1).Polygons(2).Edge(1:16)=Dirichlet(tref2);%right pipe temp

The next step is mesh creation; we use mesh factor equal to 1.4 in order to guarantee a good mesh quality, without having too long simulation time.
Me=Mesh(SH,BC,1.4); figure; Draw(Me,'quality');

Figure 7: Mesh quality.

14

5.2

Boundary conditions

As already explained we have two periodic boundary conditions on the left and on the right side and perfect insulation on the bottom, while on the top we need to model convection and radiation together; in order to do this, we can use Taylor expansion for Boltzmann radiation equation and also use the ASHRAE equation for convection coefficients. However, by following the rigorous method provided below, we set an equivalent convection coefficient equal to 12. Typically, we model the tube by means of a one-dimensional approach, and assume negligible the effects of coupling among pipes. To be exact, we neglect the effects of the heat transfer in a tube due to adjacent tubes. Here the following figure shows the system of infinitesimal dimension W*X that we choose to analyze:

Figure 8: Infinitesimal pipe element. upper component represents the cement coating and the covering tiles

15

Technically, there will be heat transferred from the hot pipe to both the panel and the ground, as we can see in detail in the following figure:

Figure 9: energy fluxes of the infinitesimal model

The equation: q = + 4 4 stands for the heat transferred from the pipe to the house due to convection and radiation. The equation: q = ( ) represents the heat loss from the pipe to the ground. And = + +1 2

is the linear mean temperature of the water. In this section, we use the linear method rather than the logarithmic method (more rigorous for heat transfer) because the results from both methods are definitely equal (the error is lower than 1%) and the linear method is much simpler. From Figure 9, we can get the next formula due to energy conservation: G = + 4 4 + ( ) where T = +1
16

WX = the exposed surface for convection and radiation, and also for conduction with ground [m2] UG = transmission coefficient of conduction with the ground [W/m2 K] Until now, it is necessary to mention that the sample coils selected are under Room 4. Then, the heat loss from pipe to the ground can be regarded as the component of transmission heat loss through the floor of Room 4. Therefore, we can have an equation to calculate UG. =
4

where tw is the mean water temperature of Room 4, not the one of the selected pipe sample. As we have calculated in the desing process, the value of tw is 32.2 [C]. Afterwards, we recall the equations for radiation and convection used in our panel heating system: = 5 108 [ + 273
4

+ 273 4 ]

= 2.13( )1.31

And combining: Q = + 4 4 We can get: = 2.13


0.31

= 4( 3 + 3 )

To solve the temperature distribution part, we use an iterative coding, with the following scheme: Guess Tp Solve eq.1 Get TK+1 Refresh Tp by =

+ +1 2

+ +

+ +

17

Consequently, here are the graphs we simulate with water cooling condition (the x-axis represents the length of pipe, the blue line is the exact solution and the red line is the linear approximation in all the following graphs):

Figure 10: Temperature distribution

We can see that behavior of water temperature is almost linear and we can accept linear approximation for future projects. Following plot shows the temperature distribution of panel which is proportional to heat radiation and convection.

Figure 11: Temperature of the panel

18

Next tow graphs show the effect of temperature reduction of water on convection and radiation coefficients:

Figure 12: convective heat transfer coefficient hc

Figure 13: radiation heat transfer coefficient hr

19

The MATLAB code for accomplishing this goal follows:


w=0.2; x=1/100; l=28.18; gcp=238.6; up=21.14; tg=9.8+273; ta=20+273; aust=19+273; ug=0; tk=34+273; %inlet temp inlettemp=tk-273 t=[]; tp00=[]; t(1)=tk; tp=273+34; steps=l/x; flag=0; for i=1:steps hc=2.13*(tp-ta)^0.31; hr=20*10^-8*(tp^3+aust^3); flag=0; for k=1:50 c1=-gcp/(w*x); c2=-gcp/(w*x); %a=hc+(5*10^-8)*tp^3+up; a=(hc*ta+hr*aust)/(up+hc+hr); c3=hc*(tp-ta)+5*10^-8*(tp^4-aust^4)+ug*(ta-tg); tk1=(c2/c1)*tk+c3/c1; tmean=(tk+tk1)/2; tp0=(up*tmean+hc*ta+hr*aust)/(up+hc+hr); hc=2.13*(tp0-ta)^0.31; hr=20*10^-8*(tp0^3+aust^3); % a=(-hc*ta-hr*aust)/(up-hc-hr); % b=up/(up-hc-hr); tp-tp0; if abs(tp0-tp)<.001 1; t(i+1)=tk1; tk=tk1; flag=1; k0(i)=k; break else end

20

tp=tp0; tp00(k,i)=tp; end tp-tp0; q0(i)=w*x*(hc*(tp-ta)+5*10^-8*(tp^4-aust^4)+ug*(tmean-tg)); if flag==0 'No convergence' beep beep break else k0(i)=k; hc0(i)=hc; hr0(i)=hr; tp000(i)=tp-273; end end outlettemp=tk1-273 meanWaterTemperature=mean(t-273) meanOFhc= mean(hc0) meanOFhr=mean(hr0) meanOFtp=mean(tp000) totalheat=sum(q0) plot(t-273) beep

21

5.3

Stiffness matrix

Lets get some relevant conditions from mesh properties:


Tr=Me.Triangles; NI=Me.UnknownNodes; C=Me.Coordinates; L=Me.Edges; Ne=Me.EdgesNeumann; N_Tr = size(Tr,1); N_int = max(NI); D = spalloc(N_int,N_int,10*N_int); b = zeros(N_int,1);

Now a basic step for solving our system is implemented, which is the creation of the stiffness matrix. The calculation can be done for inner nodes initially:
for e=1:N_Tr Dx(1) = C(Tr(e,3),1) - C(Tr(e,2),1); Dx(2) = C(Tr(e,1),1) - C(Tr(e,3),1); Dx(3) = C(Tr(e,2),1) - C(Tr(e,1),1); Dy(1) = C(Tr(e,3),2) - C(Tr(e,2),2); Dy(2) = C(Tr(e,1),2) - C(Tr(e,3),2); Dy(3) = C(Tr(e,2),2) - C(Tr(e,1),2); mu= get(Me,e,'Conductivity'); Area=Me.Aree(e); for i=1:3 ii = NI(Tr(e,i)); if( ii > 0) for j=1:3 jj = NI(Tr(e,j)); d=mu*(Dy(i)*Dy(j)+Dx(i)*Dx(j))/(4.0*Area) ; if( jj > 0) D(ii,jj) = D(ii,jj) + d; else val=Me.DirichletNodes(-jj,2); b(ii) = b(ii) - d*val ; end end end end end for k=1:length(Ne) Nodo1=L(Ne(k),1); Nodo2=L(Ne(k),2); dist=C(Nodo1,:)-C(Nodo2,:); g=Ne(k,2); if NI(Nodo1)>0 b(NI(Nodo1))=b(NI(Nodo1))+g/2*norm(dist); end if NI(Nodo2)>0 b(NI(Nodo2))=b(NI(Nodo2))+g/2*norm(dist); end end

22

At this point, we can add Robin nodes to stiffness matrix:


for k=1:length(Ro) Nodo1=L(Ro(k,1),1); Nodo2=L(Ro(k,1),2); dist=norm(C(Nodo1,:)-C(Nodo2,:)); ii1=NI(Nodo1); ii2=NI(Nodo2); h=Ro(k,2); g=Ro(k,3); if ii1>0 && ii2<0 %ii1 incognito, ii2 noto b(ii1)=b(ii1)+g/2*dist; D(ii1,ii1)=D(ii1,ii1)+h*dist/3; elseif ii1<0 && ii2>0 %ii1 noto, ii2 incognito b(ii2)=b(ii2)+g/2*norm(dist); D(ii2,ii2)=D(ii2,ii2)+h*dist/3; else %allora sono entrambi di Neumann b(ii1)=b(ii1)+g/2*norm(dist); b(ii2)=b(ii2)+g/2*norm(dist); D(ii1,ii1)=D(ii1,ii1)+h*dist/3; D(ii2,ii2)=D(ii2,ii2)+h*dist/3; D(ii1,ii2)=D(ii1,ii2)+h*dist/6; D(ii2,ii1)=D(ii2,ii1)+h*dist/6; end end

23

5.4

Steady state solution

We have to solve heat equation by means of stiffness matrix and mass matrix with the use of AssemblaDiffHeatRobin function which is the edit version of AssemblaDiffHeat and we solve the problem by \ command and finally we have to add DirichletNodes temperature and draw the figure:
[D,b] = AssemblaDiffHeatRobin(Me); u=D\b; uu=zeros(size(Me.Coordinates,1),1); uu(Me.UnknownNodes>0)=u; uu(Me.UnknownNodes<0)=Me.DirichletNodes(:,2); figure; Draw(Me,uu,'Hidemesh'); colorbar;

This is the result for 22 C and 22.2 C for each pipe temperature:

24

And also we can see the condition for 22 degrees for both pipes as following:

25

5.5

Mass Matrix

We have to recall some properties from mesh:


Tr=Me.Triangles; NI=Me.UnknownNodes; N_int = max(NI);

And then we can implement the mass matrix:


for e=1:size(Tr,1) rhocv=get(Me,e,'DensityByHeatCapacity'); Area=Me.Aree(e); for i=1:3 ii = NI(Tr(e,i)); if( ii > 0) for j=1:3 jj = NI(Tr(e,j)); if( jj > 0) if(jj==ii) M(ii,ii)=M(ii,ii)+1/6*Area*rhocv; else M(ii,jj)=M(ii,jj)+1/12*Area*rhocv; end end end end end end

26

5.6

Transient analysis

For the transient analysis we used implicit Euler method as presented below: First of all we have to call AssemblaMassMatrixHeat matrix:
M=AssemblaMassMatrixHeat(Me);

We know that our pipes temperature change as following so we use the relevant code:

f=@(t)min(10+8*t/60,25);%starts from 10 to 25 the final time is 650 s thus: Tend=650; We set our time interval dt=0.4; we need to set some parameters in advanced to run Implicit Euler method MIE=M+D*dt; bdt=b*dt/22; Ddt=D*dt; uu=zeros(size(Me.Coordinates,1),1); %Implicit Euler for k=1:Tend/dt t=(k-1)*dt; Tk=f(t); u=MIE\(M*u+bdt*Tk); uu(Me.UnknownNodes>0)=u; uu(Me.UnknownNodes<0)=Tk ; hold off; Draw(Me,uu,'hidemesh'); colorbar; zlim('auto');_ Allow subsequent plots to use the same color limits caxis manual; % allow subsequent plots to use the same color limits caxis([-10 30]); view([0,90]); title(['t=',num2str(t) 's']); drawnow(); end

27

Some frames of the animation of the transient solution follow:

28

29

6.

Conclusions

The most important result coming from stationary solution is that we verify that the distance between two pipes must be properly selected because the temperature of surface must not go beyond 22C, which is important from a design point of view, to guarantee thermal comfort. Moreover, the temperature gradient on surface is only 0.5 C which means that inhabitants dont feel very high temperature difference on the ground. The most important phenomena here is water cooling effect due to energy flux into the ground (heat loss equal to 13 W), which we neglected at the beginning; in the following graphs this effect is shown:

Min=21.2222

Min=21.2061

However, this cause a small temperature difference, it will be very important in all coil length long. For what concerns the calculation time for different mesh sizes, for t = 650 s with = 0.4 s and mesh quality number equal to 0.01 is 4 minutes and 28 seconds. On the other hand if we set mesh quality equal to 1 we find out that the new calculation time is equal to 4 minutes and 10 seconds with the same hardware and software situation, but the mesh creation time is respectively 1,294 s and 1,372 s. In addition we used implicit Euler method because it is unconditionally stable and project converges by any t and x selection but it is first order accurate. If we need more accuracy we can use Crank Nicolson but it is quite slower than IE. Another solution can be EE but we have to use very small time intervals thus it will be very slower than others therefore the best solution for this required accuracy is IE.

30

7.

Appendix

7.1 Script
clear all clc Sh(1)=Rect([0,0],[.4,.06])-(circle([.1,0],[.014,.014])+circle([.1,0],[.014,0.014])); Sh(2)=rect([0,.03+.00125],[.4,.0025]); Sh(1)=set(Sh(1),'Conductivity',1); Sh(2)=set(Sh(2),'Conductivity',1.6); Sh(1)=set(Sh(1),'DensityByHeatCapacity',1506*0.84); Sh(2)=set(Sh(2),'DensityByHeatCapacity',1506*0.84); draw(Sh,'edge') tref1 = 22; tref2 = 22; Bc=Boundary(Sh); Bc(1).Polygons(1).Edge(3)=Continuity(); Bc(2).Polygons(1).Edge(4)=Continuity(); Bc(1).Polygons(1).Edge(1)=Neumann(0); Bc(1).Polygons(1).Edge(2)=Neumann(0); Bc(1).Polygons(1).Edge(4)=Neumann(0); Bc(2).Polygons(1).Edge(1)=Neumann(0); Bc(2).Polygons(1).Edge(3)=Neumann(0); Bc(2).Polygons(1).Edge(2)=Robin(5,-100);%Robin(alfa, alfa*Tinf) Bc(1).Polygons(3).Edge(:)=Dirichlet(tref1);%left pipe temp Bc(1).Polygons(2).Edge(:)=Dirichlet(tref2);%right pipe temp Draw(Sh,Bc,'edge'); Me=Mesh(Sh,Bc,.01); draw(ME,Me.Quality); [D,b] = AssemblaDiffHeatRobin(Me); u=D\b; uu=zeros(size(Me.Coordinates,1),1); uu(Me.UnknownNodes>0)=u; uu(Me.UnknownNodes<0)=Me.DirichletNodes(:,2); figure; Draw(Me,uu,'Hidemesh'); colorbar; M=AssemblaMassMatrixHeat(Me); f=@(t)min(10+8*t/60,25);%starts from 10 to 25 Tend=650; dt=0.4; MIE=M+D*dt; bdt=b*dt/22; Ddt=D*dt; uu=zeros(size(Me.Coordinates,1),1); %Implicit Euler for k=1:Tend/dt t=(k-1)*dt; Tk=f(t); u=MIE\(M*u+bdt*Tk); uu(Me.UnknownNodes>0)=u; uu(Me.UnknownNodes<0)=Tk ; hold off; Draw(Me,uu,'hidemesh'); colorbar; zlim('auto');_ caxis manual; % allow subsequent plots to use the same color limits caxis([-10 30]);

31

view([0,90]); title(['t=',num2str(t) 's']); drawnow(); end

32

7.2 AssemblaDiffCalore
function [D,b] = AssemblaDiffCalore(Me) Tr=Me.Triangles; NI=Me.UnknownNodes; C=Me.Coordinates; L=Me.Edges; Ne=Me.EdgesNeumann; N_Tr = size(Tr,1); N_int = max(NI); D = spalloc(N_int,N_int,10*N_int); b = zeros(N_int,1); for e=1:N_Tr Dx(1) = C(Tr(e,3),1) - C(Tr(e,2),1); Dx(2) = C(Tr(e,1),1) - C(Tr(e,3),1); Dx(3) = C(Tr(e,2),1) - C(Tr(e,1),1); Dy(1) = C(Tr(e,3),2) - C(Tr(e,2),2); Dy(2) = C(Tr(e,1),2) - C(Tr(e,3),2); Dy(3) = C(Tr(e,2),2) - C(Tr(e,1),2); mu= get(Me,e,'Conductivity'); Area=Me.Aree(e); for i=1:3 ii = NI(Tr(e,i)); if( ii > 0) for j=1:3 jj = NI(Tr(e,j)); d=mu*(Dy(i)*Dy(j)+Dx(i)*Dx(j))/(4.0*Area) ; if( jj > 0) D(ii,jj) = D(ii,jj) + d; else val=Me.DirichletNodes(-jj,2); b(ii) = b(ii) - d*val ; end end end end end for k=1:length(Ne) Nodo1=L(Ne(k),1); Nodo2=L(Ne(k),2); dist=C(Nodo1,:)-C(Nodo2,:); g=Ne(k,2); if NI(Nodo1)>0 b(NI(Nodo1))=b(NI(Nodo1))+g/2*norm(dist); end if NI(Nodo2)>0 b(NI(Nodo2))=b(NI(Nodo2))+g/2*norm(dist); end end Ro=Me.EdgesRobin; for k=1:length(Ro) Nodo1=L(Ro(k,1),1); Nodo2=L(Ro(k,1),2); dist=norm(C(Nodo1,:)-C(Nodo2,:)); ii1=NI(Nodo1); ii2=NI(Nodo2);

33

h=Ro(k,2); g=Ro(k,3); if ii1>0 && ii2<0 %ii1 incognito, ii2 noto b(ii1)=b(ii1)+g/2*dist; D(ii1,ii1)=D(ii1,ii1)+h*dist/3; elseif ii1<0 && ii2>0 %ii1 noto, ii2 incognito b(ii2)=b(ii2)+g/2*norm(dist); D(ii2,ii2)=D(ii2,ii2)+h*dist/3; else %allora sono entrambi di Neumann b(ii1)=b(ii1)+g/2*norm(dist); b(ii2)=b(ii2)+g/2*norm(dist); D(ii1,ii1)=D(ii1,ii1)+h*dist/3; D(ii2,ii2)=D(ii2,ii2)+h*dist/3; D(ii1,ii2)=D(ii1,ii2)+h*dist/6; D(ii2,ii1)=D(ii2,ii1)+h*dist/6; end end

34

7.3 AssemblaMatriceMassaCalore (Heat Mass Matrix)


function M = AssemblaMatriceMassaCalore(Me) %function M = AssemblaMatriceMassa(Me) %Calcola la matrice di massa %Input: %Me :struttura generata dal programma che crea il grigliato % %Output: %M :matrice di massa Tr=Me.Triangles; NI=Me.UnknownNodes; N_int = max(NI); M = spalloc(N_int,N_int,10*N_int); for e=1:size(Tr,1) rhocv=get(Me,e,'DensityByHeatCapacity'); Area=Me.Aree(e); for i=1:3 ii = NI(Tr(e,i)); if( ii > 0) for j=1:3 jj = NI(Tr(e,j)); if( jj > 0)

if(jj==ii) M(ii,ii)=M(ii,ii)+1/6*Area*rhocv; else M(ii,jj)=M(ii,jj)+1/12*Area*rhocv; end end end end end end

35

7.4 GUI
function varargout = guigui(varargin) gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @guigui_OpeningFcn, ... 'gui_OutputFcn', @guigui_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end function guigui_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject; guidata(hObject, handles); s(1)=Rect([0,0],[.4,.06]); s(2)=rect([0,.03+.00125],[.4,.0025]); s(1)=s(1)-(circle([-.114,0],[.014,.014])+circle([.114,0],[.014,0.014])); s(1)=set(s(1),'Conductivity',237); s(1)=set(s(1),'DensityByHeatCapacity',2700*896.9); s(2)=set(s(2),'Conductivity',237); s(2)=set(s(2),'DensityByHeatCapacity',2700*896.9); Draw(s) function varargout = guigui_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output; function density_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function density_Callback(hObject, eventdata, handles) density = str2double(get(hObject, 'String')); if isnan(density) set(hObject, 'String', 0); errordlg('Input must be a number','Error'); end

handles.metricdata.density = density; guidata(hObject,handles) function volume_CreateFcn(hObject, eventdata, handles)

36

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function volume_Callback(hObject, eventdata, handles) volume = str2double(get(hObject, 'String')); if isnan(volume) set(hObject, 'String', 0); errordlg('Input must be a number','Error'); end

handles.metricdata.volume = volume; guidata(hObject,handles) function calculate_Callback(hObject, eventdata, handles) SH(1)=Rect([0,0],[.4,.06])-(circle([.114,0],[.014,.014])+circle([.114,0],[.014,0.014])); SH(2)=rect([0,.03+.00125],[.4,.0025]); SH(1)=set(SH(1),'Conductivity',60.87); SH(1)=set(SH(1),'DensityByHeatCapacity',27*89); SH(2)=set(SH(2),'Conductivity',168); SH(2)=set(SH(2),'DensityByHeatCapacity',27*89); tref1 = handles.metricdata.density; tref2 = handles.metricdata.volume; BC=Boundary(SH); BC(1).Polygons(1).Edge(1)=Neumann(0); BC(1).Polygons(1).Edge([2,4])=Periodic(@(x,y) [-x,y]); BC(2).Polygons(1).Edge([1,3])=Periodic(@(x,y) [-x,y]); BC(1).Polygons(1).Edge(3)=Continuity(); BC(2).Polygons(1).Edge(3)=Continuity(); BC(2).Polygons(1).Edge(2)=Robin(12,-240);%Robin(alfa, alfa*Tinf) BC(1).Polygons(3).Edge(1:16)=Dirichlet(tref1);%left pipe temp BC(1).Polygons(2).Edge(1:16)=Dirichlet(tref2);%right pipe temp Me=Mesh(SH,BC,1.4); figure; Draw(Me,'quality'); %draw(Me); [D,b] = AssemblaDiffHeatRobin(Me); u=D\b; uu=zeros(size(Me.Coordinates,1),1); uu(Me.UnknownNodes>0)=u; uu(Me.UnknownNodes<0)=Me.DirichletNodes(:,2); figure; Draw(Me,uu,'Hidemesh'); colorbar; function reset_Callback(hObject, eventdata, handles)

initialize_gui(gcbf, handles, true);

function initialize_gui(fig_handle, handles, isreset) % If the metricdata field is present and the reset flag is false, it means % we are we are just re-initializing a GUI by calling it from the cmd line

37

% while it is up. So, bail out as we dont want to reset the data. if isfield(handles, 'metricdata') && ~isreset return; end handles.metricdata.density = 22; handles.metricdata.volume = 23; % Update handles structure guidata(handles.figure1, handles);

38

Potrebbero piacerti anche