Use of "region" and "state" in PDE models with variable coefficients.

23 次查看(过去 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.

采纳的回答

Ravi Kumar
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 个评论
Allen
Allen 2020-1-6
Ravi,
Thanks very much for working on this. A few things:
  1. Last line of code should be kOut(state.u<crackT) = Nu*kOut(state.u<crackT);
  2. For some reason if Nu is not defined in kFunc, then the "2 input arguments" error happens.
  3. There are some interesting interactions between Nu and crackT that cause the convergence error. I am experimenting with that and playing with tolerances. Sometimes it does not fail but just sits on the solve step for a long time.
  4. I still do not understand the "2 input arguments" error, but at least things seem to be working! Thanks again. I hope this thread helps others dealing with these undocumented but useful parts of Matlab.
Allen
MandarinLu
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 个)

类别

Help CenterFile Exchange 中查找有关 Geometry and Mesh 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by