refine mesh in PDEModel

Hello, I'm trying to solve a laplace equation using PDEModel. I created the mesh object like this:
model=createpde;
msh=generateMesh(model,'Hmax',l/20);
But it looks like it is not good enough (there are no nodes in the bulk). Is there a way to refine the mesh in the PDEModel?
I also tried to refine it like this:
[p,e,t] = meshToPet(msh);
[p,e,t] = refinemesh(dl,p,e,t);
But I dont know how to convert the [p,e,t]-mesh into FEMesh and insert it to the PDEModel object. Is there an opposite function to the meshToPet maybe?
I attached to pictures of the mesh using "generateMesh" command and mesh using "refinemesh" command and

 Accepted Answer

Alan Weiss
Alan Weiss on 27 Aug 2015

0 votes

You cannot refine a mesh using a PDEModel. You have to import the geometry (I assume that you did that before trying to create a mesh) and then call generateMesh using an appropriate value of Hmax. If you need more nodes, just call generateMesh again using a smaller value of Hmax.
Alan Weiss
MATLAB mathematical toolbox documentation

9 Comments

d
d on 30 Aug 2015
Even if I'm using a smaller Hmax I get nodes only at the edges.
Perhaps you can show us how you created your geometry and imported it into the PDE model.
It is possible that, in the meantime, you can use a legacy syntax for boundary conditions and PDE coefficients in 2-D function form. They aren't as nice or easy to use as the PDE Model way, but maybe you can get things to work.
I am assuming here, based on your picture, that you have 2-D geometry. If you have 3-D geometry, then I do not understand your picture.
Alan Weiss
MATLAB mathematical toolbox documentation
I'll try to look into it.
The geometry was created like this:
pdemod=createpde;
w=1e-5;
l=0.1;
gd=[3 4 0 w w 0 0 0 l l]';
ns=char('I');
ns=ns';
sf=('I');
[dl,bt] = decsg(gd,sf,ns);
geometryFromEdges(pdemod,dl);
generateMesh(pdemod,'hmax',l/20); %mesh
For small values of 'w' there are no nodes Inside the rectangle just at the edges
Thank you for giving the geometry construction details. I finally understand what is going on.
Your geometry has an aspect ratio (length of long side of rectangle to short side) of 1e4. That is a very large aspect ratio. In order to get triangles that are not too narrow, but still have nodes in the interior of the geometry, the Hmax option needs to be set to about 5e-6. That is too small for the default 2-D mesher. Fortunately, you can use the new mesher version:
generateMesh(pdemod,'Hmax',5e-6,'MesherVersion','R2013a'); %mesh
This gives you a lot of triangles. But if you look at them (be sure to set axis equal) you see that they are nice, not too narrow. That is the best you can do with your nearly-singular geometry.
Alan Weiss
MATLAB mathematical toolbox documentation
When implementing this mesh I get:
Warning: Approximately 2400000 triangles will be generated.
and it looks like it will take a very long time to solve it.
I think I found a way to do it. After looking at the links you sent I realised how to create functions for the boundaries in the PDE-App, then I exported the boundary matrix. The problem was that I wrote:
g=myfun
instead of
g=myfun(y) % - meaning I didn't send the variable to the function.
I created the mesh and solved the PDE using:
[p,e,t]=initmesh(g);
[p1,e1,t1] = refinemesh(g,p,e,t) % 5 times so I will have more nodes inside the rectangle.
u = assempde(b,p,e,t,c,a,f) % solve the PDE
I think it looks OK now Thank you very much for the help and patience.
P.S-
I'll be happy to hear further insights if you have some
OK as a workaround, but why can't we do this using PDEModel? I want to do something similar, and don't really mind what shape my triangles are - it's never been a problem before. I tried to re-import my refined p,e,t values back into the PDEModel, but apparently they're read-only.
You might not mind what shape your triangles are, but the solver then has to deal with nearly-singular equations, ones with very high condition. That is why PDEModel won't make poorly formed triangles.
Alan Weiss
MATLAB mathematical toolbox documentation
Hello, I am thinking about this problem these days, I am dealing with plane stress problems and studying stresses of the edges of a hole in an plate. I understand that it's better to use 'assempde' to get the solves, because I want more nodes in edges of the hole (I need to refine mesh). But this way, I can only get solutions 'u' which means x-displacements in plane stress problems, while by using PDEmodel I can get 'result.NodalSolution' and 'result.XGradients','result.YGradients' which contains displacements and deformations. And the more important thing is in 'result.NodalSolution' I get a matrix (n-by-2,where n is quantity of all nodes) which means the x- and y-displacements. But 'u = assempde' give me only a vector which means x-displacement. Shortly speaking, I want to refine mesh to get more nodes in the edges of hole and at the same time I need to get a n-by-2 matrix at the output of my program. But I can't figure out how to get them both. Hoping that you can give me some advice and I will really appreciate that.
Hello Shixiang,
I am facing the same problem as you. Were you able to refine mesh using PDEModel or evaluating the gradient of the solution using [p e t ] mesh? Thank you in advance

Sign in to comment.

More Answers (2)

There is now a port of refinemesh() available for PDEModel. Like refinemesh(), it works for 2D linear triangular geometries only.
The new PDEModel compatible function is refinePDEMmesh().
This is how you would run your problem:
model=createpde;
msh=generateMesh(model,'Hmax',l/20);
model = refinePDEMmesh(model);
Lukasz
Lukasz on 25 Apr 2025

0 votes

Hello, I am a beginner and I need help.
I am creating geometry in the PDE Toolbox - example below.
How can I refine the mesh at the edges in a selected corner of the square, or along the edge on a chosen segment?
I do not want to refine the mesh in the whole area.

Asked:

d
d
on 25 Aug 2015

Answered:

on 25 Apr 2025

Community Treasure Hunt

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

Start Hunting!