Best way to iteratively solve PDE

6 views (last 30 days)
Rafi Hessami
Rafi Hessami on 26 Jul 2019
Answered: Chen on 10 Oct 2022
Hello,
I am trying to iteratively solve Poisson's equation where f has a dependence on u. Currently, I have solvepde(model) in a for loop with f defined by the function below. As I understand it, matlab should automatically pass the most recent solution to u as state.u to f, but that is not the case, as it is only fed u=0. Is there a more correct way to go about this?
I know it runs correctly the first time, as the output is good, but every output for all a values are exactly identical, so the f being fed in mus also be idneitical, which should not be the case if u is changing. I strongly suspect the problem is that the state isn't being given to fcoeffunction the way I expect.
The for loop:
for a = 1:10
% Solves PDE
result = solvepde(model);
u = result.NodalSolution;
state.u = u;
end
The function:
function f = fcoeffunction(location,state)
N = 1; % Number of equations
nr = length(location.x); % Number of columns
f = zeros(N,nr); % Allocate f
% Defines gamma
m = 9.109*10^-31;
%omega = 2*10^6; % Check if this holds in alt unit formulation
B = 5;
q = 1.6*10^-19;
c = 3*10^8;
bigomega = abs(q*B/(m*c));
omega = 2e9/c;
n0 = 2.3*10^17; % FIX, CHOSEN FROM MATHEMATICA
gamma = 2*m*omega*(bigomega-omega)/(4*pi*n0*q^2)-1;
gamma=1e-5; % DELETE JUST FOR TESTING
% Now the particular functional form of f
f(1,:) = exp(state.u(1,:))-1-gamma;
end

Answers (1)

Chen
Chen on 10 Oct 2022
Hi, this problem also happens to me, I also need to solve the pde iteratively and need to specify the function f. My solution work likes these, maybe you can gain idea from it. Thanks.
  1. Need to make the parameters global.
  2. This solution can adapt to your problem, but you might need to change the u0 in the loop.
  3. Wish you luck.
function f = fcoeffunction1(location,state)
global msh;
global u0;
global alpha;
nr = length(location.x); % Number of columns
f = zeros(1,nr);
xx=location.x;
yy=location.y;
cc=findNodes(msh,"nearest",[xx;yy]);
f(1,:)=alpha*u0(cc);
end

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!