- Thermal Model: https://www.mathworks.com/help/pde/ug/pde.thermalmodel.html
- Internal Heat Source function: https://www.mathworks.com/help/pde/ug/pde.thermalmodel.internalheatsource.html#:~:text=heatSourceValue%20%E2%80%94%20Heat%20source%20value
- Passing function handles to function: https://www.mathworks.com/help/matlab/matlab_prog/pass-a-function-to-another-function.html#:~:text=Also%2C%20you%20can%20pass%20a%20handle%20to%20an%20anonymous%20function%20to%20function%20functions.
Define internalHeatSource in thermal transient axisymmetric model?
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I am trying to simulate an exothermal reaction that takes place in a cylindrical reactor. The reactant is fed from the center of the reactor passing through a filter and spreading in the system. In the geometry, R2 stands for the filter boundary, R3 is for the tank one.
The internal heat source is generated from face 2 and spreads along the radial coordinate changing during time with temperature.
For this reason, I tried to write a for loop but it gives me an error message: "Error using isempty. Too many input arguments". In addition, it does not recognize the region variable but it should be into Matlab toolbox by default, isn't it?
Here is the code:
modelT = createpde('thermal','transient-axisymmetric');
%Geometry
R2 = [3, 4 [ 0 5 5 0 0 0 5 5 ]/1000]';
R3 = [3, 4 [0 25.4 25.4 0 0 0 5 5]/1000]';
gdm = [R2 R3];
ns = char('R2','R3');
g = decsg (gdm, 'R2 + R3',ns');
geometryFromEdges(modelT,g)
figure
pdegplot(modelT,'EdgeLabels','on','FaceLabels','on');
%Material Properties
thermalProperties(modelT, 'ThermalConductivity',k_M,...
'MassDensity', rho_MH,...
'SpecificHeat', Cp_MH);
%Boundary and initial conditions
thermalBC(modelT,'Edge',1,'HeatFlux',0);
thermalBC(modelT,'Edge',2,...
'ConvectionCoefficient',1975,...
'AmbientTemperature',292);
thermalBC(modelT,'Edge',[3,4,5,6],'HeatFlux',0);
thermalBC(modelT,'Edge',7,'HeatFlux',0);
thermalIC(modelT,T0);
%Mesh
mesh = generateMesh(modelT)
pdemesh(modelT);
node_matrix = mesh.Nodes;
A = linspace(1,653,100);
B = ceil(A);
first_row_matrix = mesh.Nodes(1,B);
second_row_matrix = mesh.Nodes(2,B);
Matrix_nodes = [first_row_matrix;second_row_matrix];
sz = size(Matrix_nodes);
for i = 2:100
results(i) = solve(modelT, linspace(0,(i-1).*0.5,100));
T(i) = results(i).Temperature(i);
Ti(i) = results(i).SolutionTimes(i);
qfunc = @(region,state) heatgeneration(1, size(region.x,1)).*region.x;
internalHeatSource(modelT,qfunc(region,state),'Face',2);
for u = Matrix_nodes(1,:)
iu(i,u) = (T(u,i-1));
end
m(i) = Ca.*exp(-Ea./(R.*Tu(i)))*log(P_gas0./Peq_vector).*(rho_sat-rhos_vector);
QReaction(i) = (-m(i).*DH_abs)./(rhocpe);
Qsens(i) = (-m(i).*Tu(i))./(rhocpe)*(Cp_g-Cp_MH);
Tu(i) = Tu(i-1) +QReaction(i) + Qsens(i)*0.1;
end
t_span, Peq_vector,wt_vector, rhos_vector are all 1x100 vectors and all the variables not declared explicitly are constants.
Any suggestions or explanations of things I'm missing about Matlab's thermal models would be appreciated.
0 个评论
回答(1 个)
sai charan sampara
2023-10-19
Hello Francesca,
I understand that you are trying to simulate an exothermal reaction in MATLAB.
You are getting an error that “region” is not a recognised variable. This is because “region” is not predefined. It is not part of any toolbox and hence MATLAB sees it as a variable and expects an initiation/declaration. Same error will be thrown for “state” variable also. Both these variables are used in defining an anonymous function handle and hence will be just placeholder variables for the function inputs. Hence when calling “qfunc()” with these variables in “internalHeatSource” function will give an error.
The second input of the function call “internalHeatSource” expects a function handle or a value. In your case if you want to input the function handle then “qfunc” should be directly given as an input instead of “qfunc(region,state)”. This might be the error because MATLAB is treating it as a value and hence is looking for some values for “region” and “state” variables. It can be corrected as below:
internalHeatSource(modelT,qfunc,'Face',2);
Regarding the other error, since “isempty” is not being called directly it is being called as part of another function. Breakpoints can be used to debug and find out where it is being called. “isempty” only accepts one input which is an array and returns a logical 1 or 0 based on whether the array is empty or not. Look for the place where this is getting violated. Fixing the above function call might also fix this error.
You can refer to the below documentation to learn more :
Hope this helps.
Thanks,
Charan.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!