How to Apply Multiple BC Types (Dirichlet, Robin, Neumann) on a Single 3D Face?

6 views (last 30 days)
Hello MATLAB Community,
I am trying to solve a 3D transient heat transfer problem on a simple cuboid using the PDE Toolbox.
My main challenge is applying three different types of boundary conditions to different regions of a single face.
Problem Description:
The geometry is a simple 3D block. The boundary conditions are:
  • Back Face (x=0): Constant temperature (Dirichlet condition).
  • All 4 Side Faces (in Y and Z): Adiabatic (zero flux / Neumann).
  • Front Face (x=L): This face needs a composite boundary condition, as shown in this diagram:
  • A central rectangular region with a constant temperature (Dirichlet).
  • Regions above and below the central patch with convection (Robin).
  • Regions to the left and right of the central patch which are adiabatic (Neumann).
What is the correct programmatic method to define these different types of boundary conditions on sub-regions of a single face, especially in a version of MATLAB that does not seem to support the more recent, flexible function handle syntaxes?
  2 Comments
Torsten
Torsten on 11 Jul 2025
I have no experience with the preprocessor of the PDE Toolbox. Usually this is done at the geometry level: either the front face of the cuboid is splitted into nine parts or the cuboid itself is created as the union of nine separate cuboids reflecting the front zones where you want to prescribe different boundary conditions.
Pedro
Pedro on 11 Jul 2025
It's very simple what I want to do, but I can't figure out how to do it at all. My latest research indicates that you can't just separate a face into several regions

Sign in to comment.

Accepted Answer

Torsten
Torsten on 12 Jul 2025
Moved: Torsten on 12 Jul 2025
gd = [3 4 -0.5 0.5 0.5 -0.5 -0.5 -0.5 0.5 0.5;
3 4 0.5 1.5 1.5 0.5 -0.5 -0.5 0.5 0.5;
3 4 -1.5 -0.5 -0.5 -1.5 -0.5 -0.5 0.5 0.5;
3 4 -0.5 0.5 0.5 -0.5 0.5 0.5 2 2;
3 4 0.5 1.5 1.5 0.5 0.5 0.5 2 2;
3 4 -1.5 -0.5 -0.5 -1.5 0.5 0.5 2 2;
3 4 -0.5 0.5 0.5 -0.5 -0.5 -0.5 -2 -2;
3 4 -0.5 -1.5 -1.5 -0.5 -0.5 -0.5 -2 -2;
3 4 0.5 1.5 1.5 0.5 -0.5 -0.5 -2 -2]';
dl = decsg(gd);
gm = geometryFromEdges(dl);
gm = extrude(gm,0.5);
gm = mergeCells(gm,[1 2]);
gm = mergeCells(gm,[1 2]);
gm = mergeCells(gm,[1 2]);
gm = mergeCells(gm,[1 2]);
gm = mergeCells(gm,[1 2]);
gm = mergeCells(gm,[1 2]);
gm = mergeCells(gm,[1 2]);
gm = mergeCells(gm,[1 2]);
%Create the model and add the geometry
model = createpde;
model.Geometry = gm;
generateMesh(model,Hmax=0.05);
figure(1)
pdemesh(model)
specifyCoefficients(model,m=0,d=0,c=1,a=0,f=0);
applyBoundaryCondition(model,"dirichlet", ...
"Face",11,"u",400);
applyBoundaryCondition(model,"dirichlet", ...
"Face",[14 17],"u",0);
R=solvepde(model);
figure(2)
pdeplot3D(R.Mesh, ...
ColorMapData=R.NodalSolution)
[X,Y,Z] = meshgrid(-1.5:0.05:1.5,-2:0.05:2,0:0.05:0.5);
V = interpolateSolution(R,X,Y,Z);
V = reshape(V,size(X));
%Take slice at z = zmax/2
figure(3)
Vs = slice(X,Y,Z,V,[],[],0.25);
max(Vs.CData(:))
ans = 311.4004
shading interp
colorbar
  3 Comments
Pedro
Pedro on 12 Jul 2025
Adding
I tested it in matlab online and that's exactly what I wanted. The mergeCells function removes the inner faces but keeps the outer faces, allowing you to apply different boundary conditions. Very simple, just as I imagined it would be to solve this problem.
Thanks again
Torsten
Torsten on 12 Jul 2025
Edited: Torsten on 12 Jul 2025
Your answer clearly solves my question, although I can't use it because of my version of matlab.
I see. "mergeCells" was introduced in R2023b - thus too recent for your MATLAB, I guess. Maybe you can read in the geometry as an stl-file or find a different solution. There should be a simpler way than what I did above. Good luck !

Sign in to comment.

More Answers (1)

Torsten
Torsten on 11 Jul 2025
Edited: Torsten on 11 Jul 2025
Here is one way to create the geometry such that you can set different boundary conditions on different faces at the top.
If you consider the top as the front face, you can set e.g. Face 11 for Dirichlet, Faces 14 and 17 for Robin and Faces 16, 10, 13, 18, 12 and 15 for Neumann.
Maybe there is a simpler solution.
gd = [3 4 -0.5 0.5 0.5 -0.5 -0.5 -0.5 0.5 0.5;
3 4 0.5 1.5 1.5 0.5 -0.5 -0.5 0.5 0.5;
3 4 -1.5 -0.5 -0.5 -1.5 -0.5 -0.5 0.5 0.5;
3 4 -0.5 0.5 0.5 -0.5 0.5 0.5 2 2;
3 4 0.5 1.5 1.5 0.5 0.5 0.5 2 2;
3 4 -1.5 -0.5 -0.5 -1.5 0.5 0.5 2 2;
3 4 -0.5 0.5 0.5 -0.5 -0.5 -0.5 -2 -2;
3 4 -0.5 -1.5 -1.5 -0.5 -0.5 -0.5 -2 -2;
3 4 0.5 1.5 1.5 0.5 -0.5 -0.5 -2 -2]';
dl = decsg(gd);
gm = geometryFromEdges(dl);
gm = extrude(gm,0.5);
%Create the model and add the geometry
model = createpde;
model.Geometry = gm;
generateMesh(model);
pdegplot(model,"FaceAlpha",0.3)
hold on
pdemesh(model)
pdegplot(gm,"FaceLabels","on")
  3 Comments
Torsten
Torsten on 12 Jul 2025
Edited: Torsten on 12 Jul 2025
"mergeCells" will delete the inner faces between blocks. If you apply this feature several times, you will be left with only one cell, but the outer face structure to set the boundary conditions on the top will remain.
Pedro
Pedro on 12 Jul 2025
Thank you
I misunderstood when I was reading this library then.
Unfortunately my college doesn't give me access to the version of matlab that has this function

Sign in to comment.

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!