Use of "region" and "state" in PDE models with variable coefficients.
13 views (last 30 days)
Show older comments
"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 Comments
Accepted Answer
Ravi Kumar
on 3 Jan 2020
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 Comments
MandarinLu
on 27 Oct 2020
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
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!