MATLAB Answers

# PDE toolbox and non-constant coefficients

39 views (last 30 days)
Flo brd on 4 Oct 2018
Commented: Flo brd on 20 Nov 2018
Hi Matlab experts.
I am playing with the C coefficient, and would like to set it as a state dependent coefficient. While I am more and more understanding the nature of function handle as stated in the matlab help for the c coefficient ( Here ), I am a left with few questions:
- I am solving only 1 equation ( model = createpde(1) ). if the c coefficient is constant the program works well. As long as I try to make it state.u dependent, it either doesn't work, or gives me Warning about integration tolerances. I am therefore unsure about the structure of state . The help says that the state.u field represents the current value of the solution u, and that starts to confuse me a bit. As I am trying to solve for pressure diffusion, I would have assume that state.u was a value of pressure in whichever unit I am using, but I am slowly starting to doubt it.
- again in the help, the cmatrix vector is built depending on the N variable. As my N=1, I would have assumed that I needed to fill in cmatrix(1,:) with my calculations around state.u. I guess here again I am wrong, and I don't really get what to do anymore in order to ouput the right vector format.
I join pieces of my code. The idea is to use state.u (assuming to is a pressure) to recalculate the permeability of my 2D field.
function cmatrix = DiffusivityV4(location,state,ki, depth,density, T)
N = 1;
nr = length(location.x);
confiningStress = density*9.81*depth*1e-6;
Cp = 0.000000001;
T = T+273.15;
A=2.414*10^-5;
B=247.8;
C=140;
u = A*10^(B/(T-C));
gamma = (0.012+0.013)/2;
cmatrix = zeros(N,nr);
try
cmatrix(1,:) = (ki-(0.04343*gamma*(confiningStress-state.u(1,:))))/(u*Cp);
if isnan(cmatrix)
cmatrix(N,nr)=0;
end
catch
cmatrix(N,nr)=0;
end
end
This function is called this way:
Dcore= @(location, state) DiffusivityV4(location,state,1e-17,4000, 2700, 200);
specifyCoefficients(model,'m',0,'d',d,'c',Dcore,'a',a,'f',f, 'face',1);
Please let me know if you need any other information about my code. I am really new to function handle and the PDE toolbox, so sorry by advance if I did misunderstand the way it works.
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Ravi Kumar on 4 Oct 2018
Hello Flo,
Your understanding of the function_handle and c-coefficient are correct. The state.u is the value of the solution at the current iteration. Please note when your c-coefficient is a function of state.u, that means you are solving a nonlinear problem. Solver will take multiple steps iteratively to move towards solution, state.u is the one such intermediate approximation in the solution iterations.
You have provided some information in this post and also in separate <https://www.mathworks.com/matlabcentral/answers/421773-pde-toolbox-undefined-function-mtimes-for-input-arguments-of-type-function_handle post >. However, it is not complete setup which can be used to reproduce the issue you are facing.
I have a suggestion based on the information I gathered from your posts, remove the following from your DiffusivityV4 function:
if isnan(cmatrix)
cmatrix(N,nr)=0;
end
Solver passes state.u as NaN to determine if the function is nonlinear. This might fix your problem. If not please update this post with a complete reproduction code.
##### 1 CommentShowHide None
Flo brd on 20 Nov 2018
Thank you for your help. So I tried everything you said and I think my issue was linked to the maths behind my equation rather than a misunderstanding of the PDE toolbox.
It compiles now :)
Flo

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!