Clear Filters
Clear Filters

Want to use barbellgraph.mat as a mesh

6 views (last 30 days)
There is a .mat file used as an example for a parition graph. I would like to use it as a 2D mesh to solve PDEs on. I cannot find a way to use it in a model. Could anyone guide me?
  1 Comment
Walter Roberson
Walter Roberson on 19 Feb 2024
I am far from sure... but I think you might just be able to start by building a triangulation from the Graph, and then passing the triangulation to fegeometry and pass the resulting geometry to femodel

Sign in to comment.

Accepted Answer

Malay Agarwal
Malay Agarwal on 19 Feb 2024
Edited: Malay Agarwal on 20 Feb 2024
Hi Michelle,
I understand that you want to use the data in “barbellgraph.mat” file, used in the example “Partition Graph with Laplacian Matrix”, as a 2D mesh to solve PDEs on.
Please try the following code:
% Load the MAT file
load barbellgraph.mat
% Create a graph using A
G = graph(A, "omitselfloops");
% Extract the endpoints of each edge as two separate variables
x = G.Edges.EndNodes(:, 1);
y = G.Edges.EndNodes(:, 2);
% Create a triangulation
tri = delaunayTriangulation(x, y);
% Create a geometry using the triangulation
geom = fegeometry(tri);
% Create a model using the geometry
% Note: Change AnalysisType according to use case
model = femodel("AnalysisType","structuralStatic","Geometry", geom);
The code above:
  • Loads the “.mat” file and creates a graph “G” using the variable “A”.
  • Extracts the endpoints for each edge in the graph as two separate variables “x” and “y”. For example, if the graph has edges (a, b) and (c, d), “x” is “[a c]” and “y” is “[b d]”.
  • Creates a Delaunay triangulation “tri” using the endpoints of the edges of the graph.
  • Uses the triangulation to create a geometry “geom”.
  • Creates a model “model” using the geometry, which can now be used to solve PDEs. Please note that you might have to change “AnalysisType” in the call to “femodel” depending on your use case.
The triangulation and the geometry can be plotted as a sanity check using the following code:
triplot(tri);
pdegplot(geom, FaceAlpha=0.3);
The resultant mesh looks as follows:
pdemesh(model);
You can refer to the following resources for more details:
Hope this helps!
  5 Comments
Malay Agarwal
Malay Agarwal on 23 Feb 2024
Edited: Malay Agarwal on 23 Feb 2024
Hi Michelle,
The reason why the number of nodes decreases is due to the call to "generateMesh" with the "GeomtericOrder" name-value argument. The name-value arguments of "generateMesh" are used to modify the mesh generation, as specified in the documentation: https://www.mathworks.com/help/pde/ug/pde.pdemodel.generatemesh.html?s_tid=doc_ta#bupct6k-3:~:text=example-,___,%2CName%2CValue),-modifies%20the%20mesh.
If the model is plotted after these lines:
% Stores the P and T variables
load pt.mat
model = createpde;
geometryFromMesh(model,P',T');
specifyCoefficients(model,"m",0,"d",1,"c",1,"a",0,"f",0);
applyBoundaryCondition(model,'dirichlet','Edge',[1,2,3,4],'u',0);
It has the expected mesh:
pdeplot(model);
I don't think the "generateMesh" call is required here since the model's geometry was created using variables "P" and "T", and the expected mesh is already part of the model. You should be able to solve PDEs after the call to "applyBoundaryCondition".
This can also be confirmed by looking at the "Mesh" property of "model" before and after calling "generateMesh":
  • Before the call to "generateMesh":
model.Mesh
ans =
FEMesh with properties: Nodes: [2×2713 double] Elements: [3×5152 double] MaxElementSize: 0.0746 MinElementSize: 0.0074 MeshGradation: [] GeometricOrder: 'linear'
  • After the call to "generateMesh":
generateMesh(model, "GeometricOrder", "linear");
model.Mesh
ans =
FEMesh with properties: Nodes: [2×158 double] Elements: [3×246 double] MaxElementSize: 0.1265 MinElementSize: 0.0632 MeshGradation: 1.5000 GeometricOrder: 'linear'
Hope this helps!
Michelle
Michelle on 23 Feb 2024
Hi Malay,
You are correct, removing that line has my code working exactly as expected! Thank you so much for the help.

Sign in to comment.

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!