Use of "region" and "state" in PDE models with variable coefficients.
17 次查看(过去 30 天)
显示 更早的评论
"state" and "region" sometimes show up in questions about solving PDEs with variable coefficients, but these things are basically undocumented. I am trying to model a 3-region heat-transfer system in which the thermal conductivity of one layer is a function of temperature (see https://www.mathworks.com/matlabcentral/answers/498820-how-to-write-anonymous-function-for-variable-coefficients-in-heat-transfer-problem). What I wrote in the other post does not give an error but also does not assign the proper value to the layer in question.
If anyone has a grasp of how to use state and region to assign variable properties in PDEs, as in the earlier post, please reply.
0 个评论
采纳的回答
Ravi Kumar
2020-1-3
Hi Allen,
Solver passes two input arguments to the function that you define, "region" and "state" are just place holder names. You can call them anything you want. Just be aware that the first argument, region, contains spatial data which you can use to compute k and second contains solution data to serve you the same purpose.
Now to your specific question on kFunc I think you are using the logical expression state.u<cractT to modify K. The input data, that solver sends to your function, state.u contains solution at several points withiin Face 3. Depending on your initial condition you start out with state.u<cractT yielding logical vector (logical zeros and ones). I am guessing this is not what you want. Also, it is hard to say if the solution actually crosses 900 to change the thermal conductivity. If the condition is never false, then you will always get k +k*(Nu-1) as thermal conductivity. I would suggest writing a full function, instead of anonymous function as:
function kOut = kFunc(region,state)
if any(isnan(state.u))
kOut = nan(size(state.u));
return;
end
kOut = k;
if any(state.u < crackT)
kOut = k+k*(Nu-1)*ones(size(state.u));
end
end
Then specify, this kFunc's handle on to faces 3 as:
thermalProperties(thermalModel,'Face',3,'ThermalConductivity',@kFunc,'MassDensity',2500,'SpecificHeat',1000);
Regards,
Ravi
7 个评论
MandarinLu
2020-10-27
A tip: use global function at the beginning for defining the global parameter, so that you can call it in many function handles by just writing global again. For example:
global a
a=10;
%
% here is main code
%
function b=Func(location,state)
global a
b=a*100;
end
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!