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

조회 수: 23 (최근 30일)
Allen
Allen 2020년 1월 3일
댓글: MandarinLu 2020년 10월 27일
"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