How can I move one element from one meshed domain to another in the frame of the Partial Differential Equation Toolbox?

1 回表示 (過去 30 日間)
Given a meshed domain partitioned in multiple meshed subdomain, it is sought for a workflow that allows one element to be transferred from one meshed subdomain to another one.
How can I move one element from one meshed domain to another in the frame of the  Partial Differential Equation Toolbox?

採用された回答

MathWorks Support Team
MathWorks Support Team 2021 年 2 月 26 日
In order to transfer one element from a meshed subdomain to another, function 'geometryFromMesh' can be leveraged, see the following documentation page,
Accordingly, the workflow involves a common conforming mesh that is being partitioned in the various meshed subdomains. Then workflow is described below:
1.) Assumed is that the domain is subdivided into two subdomains for the sake of demonstration. However, the workflow is not restricted into two subdomains, but the workflow can be enhanced to involve more than two subdomains.
In this case assumed is that the problem is to be solved using the structural solver. Accordingly, the complete domain 'analysisModel' along with the corresponding two subdomains 'analysisModel1' and 'analysisModel2' are created, see the following code snippet:
%% Create three models, one for mesh with two subdomain, and two analysis models that have different distribution of elements
analysisModel = createpde('structural','static-solid');
analysisModel1 = createpde('structural','static-solid');
analysisModel2 = createpde('structural','static-solid');
2.) Then, the underlying geometry that consists of two subdomains/cells is assigned to domain 'analysisModel'. Each of these cells will be subsequently used to identify elements between the different parts, see the following code snippet:
%% Assign the underlying geometries
 
% create the geometry for the whole model
analysisModel.Geometry = multicuboid(0.01,0.01,[0.05,0.05],'Zoffset',[0,0.05]);
generateMesh(analysisModel,'Hmax',0.3); % 0.003
msh = analysisModel.Mesh;
 
% plot the whole geometry
pdegplot(analysisModel,'FaceLabels','on','FaceAlpha',0.5);
hold on;
pdemesh(analysisModel);
hold off;
title('The complete meshed geometry')
 
3.) Note that the domain 'analysisModel' has now been meshed using function 'pdemesh'. As a next step, one can identify elements from each subdomain using the identifiers 1 and 2, see the following code snippet:
%% Find the nodes and elements in each subregion
 
% Find the nodes
m1Nodes = findNodes(msh, 'region', 'Cell', 1);
m2Nodes = findNodes(msh, 'region', 'Cell', 2);
 
% Find the elements
m1Elems = findElements(msh, 'region', 'Cell', 1);
m2Elems = findElements(msh, 'region', 'Cell', 2);
Please note that the 'analysisModel.Geometry' model consists of 2 cells that can be used to differentiate between the two different subdomains.
4.) The next step is to create a so-called mapping vector, which contains the ID of the domain/cell to which each element in the common mesh belongs to, see the following code snippet:
%% Create a mapping vector with initial element distribution
 
% create the mapping vector
elem2SudomainMap = ones(1, size(msh.Elements,2));
elem2SudomainMap(m2Elems) = 2;
 
% get the individual domains from the whole model using the initial element
% distribution
geometryFromMesh(analysisModel1, msh.Nodes, msh.Elements, elem2SudomainMap);
geometryFromMesh(analysisModel2, msh.Nodes, msh.Elements, elem2SudomainMap);
 
% find the elements in the meshed domain 1
am1Elems = findElements(analysisModel1.Mesh, 'region', 'Cell', 1);
 
% plot the the meshed domain 1
figure
pdemesh(analysisModel1.Mesh.Nodes,analysisModel1.Mesh.Elements(:, am1Elems))
title('Initial mesh in domain 1')
 
Note that the vector 'elem2SudomainMap' after executing the latter commands has the following content:
elem2SudomainMap =
  Columns 1 through 9
  1     1     1     1     1     1     1     1     1
  Columns 10 through 18
1     1     1     2     2     2     2     2     2
  Columns 19 through 24
  2     2     2     2     2     2
Note that the first 12 components have the ID 1, whereas the 12 last components have the ID 2. That means, that the first 12 elements of the common domain 'analysisModel' belong to subdomain 1, whereas the last 12 elements of the common domain 'analysisModel' belong to subdomain 2.
5.) To move an element from one mesh to another, you need to simply modify the latter mapping vector and then recreate the mesh using the function 'geometryFromMesh'. This workflow is demonstrated below:
%% Move element 18 that is initially located in domain 2 into domain 1
fprintf('Element 18 is intially in domain: %d\n\n', elem2SudomainMap(18));
elem2SudomainMap(18) = 1;
fprintf('Setting element 18 to domain: %d\n\n', elem2SudomainMap(18));
 
% Update the analysismodel1 to include element 18 in Cell 1
analysisModel1.Geometry = [];
geometryFromMesh(analysisModel1, msh.Nodes, msh.Elements, elem2SudomainMap);
am1Elems = findElements(analysisModel1.Mesh, 'region', 'Cell', 1);
 
% plot the meshed domain 1 along with the element 18
figure
pdemesh(analysisModel1.Mesh.Nodes, analysisModel1.Mesh.Elements(:, am1Elems));
title('Updated mesh in Cell 1')
 
% Update the analysismodel2 to exclude element 18 in Cell 2
analysisModel2.Geometry = [];
geometryFromMesh(analysisModel2, msh.Nodes, msh.Elements, elem2SudomainMap);
am1Elems = findElements(analysisModel2.Mesh,'region','Cell',2);
 
% plot the meshed domain 2 without the element 18
figure
pdemesh(analysisModel2.Mesh.Nodes, analysisModel2.Mesh.Elements(:, am1Elems));
title('Updated mesh in Cell 2')
as you can see, the component 18 of the mapping vector 'elem2SudomainMap' is modified from 2 to 1. This means that element 18 in the common mesh is assigned from domain 2 to domain 1. Then, function 'geometryFromMesh' is called in both subdomains 'analysisModel1' and 'analysisModel2' in order to update the meshes. I added also some plotting functions, that demonstrate the resulting meshes and where you can observe that indeed the element 18 from the common mesh is moved from domain 2 to domain 1, see the following figure:

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeometry and Mesh についてさらに検索

タグ

タグが未入力です。

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by