Want to use barbellgraph.mat as a mesh

조회 수: 4 (최근 30일)
Michelle
Michelle 2024년 2월 7일
댓글: Michelle 2024년 2월 23일
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
Walter Roberson
Walter Roberson 2024년 2월 19일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Malay Agarwal
Malay Agarwal 2024년 2월 19일
편집: Malay Agarwal 2024년 2월 20일
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
Malay Agarwal
Malay Agarwal 2024년 2월 23일
편집: Malay Agarwal 2024년 2월 23일
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 2024년 2월 23일
Hi Malay,
You are correct, removing that line has my code working exactly as expected! Thank you so much for the help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Geometry and Mesh에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by