How to create a table with xyz coordinates and ElectricPotential for STL file

4 vues (au cours des 30 derniers jours)
mathijs lemmens
mathijs lemmens le 1 Mar 2023
I made an design for a stator in solidworks which I converted to an STL file. I plotted electropotential that runs through the stator with a colormap using the partial differential toolbox. When I solve the model I get the structure R which contains electropotential, electric field, electric fluxdensity and Mesh data. the table that contains the electropotentials doesn't have xyz coördinate that belongs to each coördinate of the object. Want to make a table that shows the electronpotential for each coördinate but I don't know how.
model = createpde("electromagnetic","electrostatic");
gmBushing = importGeometry("Assigment_Niels - Stator.STL")
% pdegplot(gmBushing)
gmAir = multicuboid(85,25,60)
gmAir.translate([35,0.0001,0.-5]);
gmModel = addCell(gmAir,gmBushing);
model.Geometry = gmModel
model.VacuumPermittivity = 8.8541878128E-12;
electromagneticProperties(model,"Cell",1,"RelativePermittivity",1500);
electromagneticProperties(model,"Cell",2,"RelativePermittivity",1500);
electromagneticProperties(model,"Cell",3,"RelativePermittivity",1);
electromagneticBC(model,"Face",17,"Voltage",1.51);
electromagneticBC(model,"Face",11,"Voltage",0.379);
electromagneticBC(model,"Face",2,"Voltage",0);
msh=generateMesh(model);
R = solve(model)
elemsBushing = findElements(model.Mesh,"Region","Cell",[2 3]);
figure
pdemesh(model.Mesh.Nodes, ...
model.Mesh.Elements(:,elemsBushing), ...
...
"NodeLabels","on","mesh","on","EdgeColor","black","ColorMapData",R.ElectricPotential);
% Extract the nodal coordinates and ElectricPotential values
nodes = model.Mesh.Nodes(:);
ElectricPotential = R.ElectricPotential(:);
% Combine the nodal coordinates and ElectricPotential values into a table
table_data = [nodes, ElectricPotential];
% Create a table with appropriate column names
table_name = array2table(table_data, 'VariableNames', {'x', 'y', 'z', 'ElectricPotential'});

Réponses (1)

Shubham
Shubham le 7 Avr 2023
Hi mathijs,
To obtain the electropotential for each coordinate of the stator, you need to associate the nodal coordinates of the mesh with the corresponding electropotential values.
First, you can obtain the nodal coordinates from the mesh using model.Mesh.Nodes, which returns an Nx3 matrix where N is the number of nodes and the columns correspond to the x, y, and z coordinates of each node.
Then, you can extract the electropotential values from R.ElectricPotential, which is an Nx1 vector that contains the electropotential values at each node.
Next, you can combine these two arrays into a single matrix using the horzcat function to horizontally concatenate them.
Finally, you can create a table from the combined matrix using the array2table function with the appropriate column names, like this:
nodes = model.Mesh.Nodes;
ElectricPotential = R.ElectricPotential;
table_data = horzcat(nodes, ElectricPotential);
table_name = array2table(table_data, 'VariableNames', {'x', 'y', 'z', 'ElectricPotential'});
This will create a table called table_name with four columns: x, y, z, and ElectricPotential. Each row of the table corresponds to a node in the mesh, and the values in the ElectricPotential column correspond to the electropotential value at each node.

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by