MATLAB Answers

PDE Toolbox - Convection in Diffusion Equation

33 views (last 30 days)
I'm trying to add a convection term to solve a diffusion PDE using the PDE Toolbox. I'm defining the PDE as:
specifyCoefficients(model,'Face',2,'m',0,'d',1,'c',Da,'a',0,'f',@fcoeff);
and have the following at the end of my code:
function f = fcoeff(location,state)
y = location.y./h;
x = location.x./L;
v = va;
f = -(v.*state.ux.*state.time + v.*state.uy.*state.time);
end
However, whenever I try to run the code I get the following error:
Error using pde.CoefficientAssignment/checkCoefFcnHdlArgCounts (line 499)
Function specifying a coefficient must accept two
input arguments and return one output argument.
Error in pde.CoefficientAssignment/checkFcnHdlArgCounts (line 272)
self.checkCoefFcnHdlArgCounts(self.f, systemsize, ndims);
Error in pde.CoefficientAssignment (line 104)
obj.checkFcnHdlArgCounts(systemsize, numdims);
Error in pde.PDEModel/specifyCoefficients (line 143)
coef = pde.CoefficientAssignment(self.EquationCoefficients,argsToPass{:});
Error in Dry_Air (line 49)
specifyCoefficients(model,'Face',2,'m',0,'d',1,'c',Da,'a',0,'f',@fcoeff);
I don't understand the error because as I see it I am ipnuting two arguments and am returning one output. Whenever I take away the function for 'f' on the RHS of the PDE my code works perfectly. Any help would be much appreciated!

  0 Comments

Sign in to comment.

Accepted Answer

Ravi Kumar
Ravi Kumar on 21 Jan 2020
It looks like your function errored without returning one onput. Most likely the error could have been due to 'va' being out of scope for the function fcoeff.
Regards,
Ravi

  3 Comments

Andrew Ferguson
Andrew Ferguson on 21 Jan 2020
Even if I change the function to
function f = fcoeff(location,state)
y = location.y./h;
x = location.x./L;
va = 0.5; % m/s
v = va;
f = -(v.*state.ux.*state.time + v.*state.uy.*state.time);
end
I still get the same error. Any other thoughts?
Ravi Kumar
Ravi Kumar on 21 Jan 2020
I think you are still missing some variable in the funciton, like 'h' and 'L'. You can also insert a breakpoint on the first line of the funciton and see where you get the error.
Regards,
Ravi

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Products


Release

R2019b