How to impose a variable temperature distribution for one edge of a rectangular plate while keeping the temperatures of other three edges same and constant?

Hi all,
I was trying to plot heat flux lines for a heat transfer problem. The problem specifies a 0.3m by 0.1m rectangular plate. Its right, left and bottom edges are kept at 273.15K and the top edge has a temperature distribution:
with thermal conductivity, k=2.5 W/mK. I've tried the following to solve this problem:
load('gd');
load('ns');
load('sf');
g=decsg(gd,sf,ns);
thermalmodel = createpde('thermal');
geometryFromEdges(thermalmodel,g);
pdegplot(thermalmodel,'EdgeLabels','on')
xlim([0 .3])
ylim([0 .15])
axis equal
dx=.0001;
x=0:dx:.3;
thermalProperties(thermalmodel,'ThermalConductivity',2.5,'Face',1);
thermalBC(thermalmodel,'Edge',1,'Temperature',273.15);
thermalBC(thermalmodel,'Edge',2,'Temperature',273.15);
thermalBC(thermalmodel,'Edge',4,'Temperature',273.15);
thermalBC(thermalmodel,'Edge',3,'Temperature',30.*sin(pi.*x/.3));
generateMesh(thermalmodel);
results = solve(thermalmodel)
I'm getting the following error: Error using pde.ThermalBC/set.Temperature (line 136)
Temperature for all specified edges or faces must be a scalar value or a single function handle. Could someone suggest how I can impose the variable temperature distribution?

 Accepted Answer

Hi Anik,
Define a function to model variation of temperature and use it in BC specification:
tFunc = @(region,state) 30.*sin(pi.*region.x/3)
thermalBC(thermalmodel,'Edge',3,'Temperature',@tFunc);
Regards,
Ravi

6 Comments

Hi Ravi,
Thanks for your suggestion! do I need to define the region and state to use the 'tFunc'? cause I've included the two lines of code you kindly provided here and getting the following error:
Error: File: prob1.m Line: 20 Column: 48
"tFunc" was previously used as a variable, conflicting with its use here as the name of a function or command.
See "How MATLAB Recognizes Command Syntax" in the MATLAB documentation for details.
load('gd');
load('ns');
load('sf');
g=decsg(gd,sf,ns);
thermalmodel = createpde('thermal');
geometryFromEdges(thermalmodel,g);
pdegplot(thermalmodel,'EdgeLabels','on')
xlim([0 .3])
ylim([0 .15])
axis equal
dx=.0001;
x=0:dx:.3;
thermalProperties(thermalmodel,'ThermalConductivity',2.5,'Face',1);
thermalBC(thermalmodel,'Edge',1,'Temperature',273.15);
thermalBC(thermalmodel,'Edge',2,'Temperature',273.15);
thermalBC(thermalmodel,'Edge',4,'Temperature',273.15);
tFunc = @(region,state) 30.*sin(pi.*region.x/3)
thermalBC(thermalmodel,'Edge',3,'Temperature',@tFunc);
generateMesh(thermalmodel);
results = solve(thermalmodel)
I made a mistake in my original post, you don't need "@" in front of tFunc as it is already a function handle. Use:
tFunc = @(region,state) 30.*sin(pi.*region.x/3)
thermalBC(thermalmodel,'Edge',3,'Temperature',tFunc);
Any suggestions regarding plotting the isotherms for this problem?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!