How to solve semi discretized PDE matrices with a time derivative in PDE tool box using ODE solvers that includes Dirichlet BC

3 views (last 30 days)
I am solving the basic Heat equation using two methods. One is completely using PDE tool box and the other method is using FE matrices which are spacially discretized by PDE tool box and having one time derivative and I am using ODE solver to solve this system of equations.
% applyBoundaryCondition ( heatmodel ,'neumann','edge',1:4 ,'g' ,-20,'q' ,3);
applyBoundaryCondition ( heatmodel,'dirichlet','edge',1:4,'u',0);
When I apply neumann boundary condition, I was getting the same results in both the cases but when i use dirichlet BC i was getting different results in both cases. I am not able to figure out why i am not getting same results with dirichlet BC. Can someone help me in this regard. Thanks in advance.
Please find the attachment of both MATLAB files. It has both the cases.
Here I am showing my ODE case but for pde tool box case, you can find it in my attachments to this mail.
clear,clc,close all;
global FEM_M FEM_K FEM_A FEM_Q FEM_G FEM_F;
model = createpde(1);
%% Geometry
R1 = [3;4;-1;1;1;-1;-1;-1;1;1];
g = decsg(R1);
heatmodel_geom = geometryFromEdges(model,g);
%% Mesh
msh = generateMesh(model,'GeometricOrder','linear');
[P,E,T] = meshToPet( msh );
%% Specify Coefficients
specifyCoefficients(model,'m',0,'d',1,'c',1,'a',0,'f',1);
%% Please switch to dirichlet instead of neumann and check the results in both cases
% applyBoundaryCondition(model,'dirichlet','Edge',1:4,'u',0);
applyBoundaryCondition ( model,'neumann','Edge',1:4 ,'g' ,-2,'q' ,3);
%% assemble the 6 finite elements matrices
model_FEM_matrices = assembleFEMatrices(model);
FEM_M = model_FEM_matrices.M;
FEM_K = model_FEM_matrices.K;
FEM_A = model_FEM_matrices.A;
FEM_Q = model_FEM_matrices.Q;
FEM_G = model_FEM_matrices.G;
FEM_F = model_FEM_matrices.F;
%% Time for Simulation
ntime = 20;
startTime = 0;
endTime = 0.1;
tlist = linspace(startTime,endTime,ntime);
odesolve_tol = 1e-6;
%% This evaluates Initial Condition
u0 = IC_general(P(1,:), P(2,:));
options = odeset('Mass',FEM_M ,'AbsTol',odesolve_tol ,'RelTol',odesolve_tol ,'Stats','on');
disp('ode45');
[TOUT , YOUT] = ode45(@odefun_semidiscretize_pde,tlist,u0',options );
%% plot
pdeplot(model ,'XYData',YOUT(end ,:),'ZData',YOUT(end ,:),'Contour','on','ColorMap','jet');
function f = IC_general(x,y)
nr = length(x);
f = zeros(1, nr);
f(1 ,:) = 1;
end
function Yout = odefun_semidiscretize_pde(t,Y)
global FEM_M FEM_K FEM_A FEM_Q FEM_G FEM_F
Yout = -(FEM_K*Y+ FEM_A*Y+ FEM_Q*Y)+ FEM_G + FEM_F ;
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!