Implementing Neumann and Dirichlet boundary conditions on a disk

3 views (last 30 days)
Dear matlab community,
I try to solve the Helmholtz equation on a disk with a small part of the boundary where I have Neumann boundary conditions and Dirichlet boundary conditions elsewhere.
The Neumann boundary conditions (which I simulated with inhomogeneous Dirichlet boundary conditions u = 1) should be valid for all x with - R*cos(pi/2 - theta0) < x < R*cos(pi/2 - theta0).
The following code I created does however fully igonore the Neumann boundary conditions and just gives me the solution for the Dirichlet boundary condition on the full circle
model = createpde;
R = 1;
disk = [1, 0, 0, R]';
gm = decsg(disk);
geometryFromEdges(model, gm);
theta0 = pi/4;
BCFunc = @(location,state) -heaviside(location.x - R*cos(pi/2 - theta0)) + heaviside(location.x + R*cos(pi/2 - theta0));
b1 = applyBoundaryCondition(model, 'dirichlet', Edge=(1:4), u = BCFunc);
specifyCoefficients(model,m=0,d=1,c=1,a=0,f=0);
r = [0,10];
generateMesh(model,Hmax=0.05);
results = solvepdeeig(model,r);
l = sqrt(results.Eigenvalues)
u = results.Eigenvectors;
figure
pdeplot(model,XYData=u(:,1),Contour="on",Colormap="default");
xlim([-1,1])
ylim([-1,1])
As a workaround I tried to model the disk as a polygon such that the boundary conditions can be implemented without BCFunc by solely calling the edges. But when I applied it for a polygon with more than 10 corners matlab started to label the whole edge of the polygon as one connected edge again.
Does anyone have an idea why matlab is ignoring the Neumann part of the boundary conditions and/or is there a workaroung to this problem?

Accepted Answer

Drishti
Drishti on 6 Mar 2025
Hi Jannik,
I understand you are trying to implement both the Neumann boundary conditions and the Dirichlet boundary conditions while solving the Helmholtz equation on a disk.
One workaround you can follow is first applying the the Dirichlet boundary conditions on the entire boundary and then applying the Neumann boundary on the specific edge.
You can refer to the code snippet below to understand the same:
% Apply Dirichlet boundary condition to the entire boundary initially
applyBoundaryCondition(model, 'dirichlet', 'Edge', (1:4), 'u', 0);
% Assume edge 2 is the correct edge for Neumann conditions as an example
neumann_edge = 2;
% Apply Neumann condition to the specific edge
applyBoundaryCondition(model, 'neumann', 'Edge', neumann_edge, 'g', 1, 'q', 0);
For more information, refer to the MATLAB Documentation of 'applyBoundaryCondition' function provided below:
I hope this helps!
  2 Comments
Jannik
Jannik on 10 Mar 2025
Dear Drishti,
I implemented your suggested workaround and it worked! Thank you so much for your help.
Best,
Jannik
Star Strider
Star Strider on 10 Mar 2025
@Jannik — It is important to Accept (and preferably also vote for) an answer that solves your problem. This notifies others that the solution worked, and gives reputation points to the person who provided the answer.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!