# Looking for help changing linked class objects in parallel

1 view (last 30 days)
Marc Laub on 12 Jun 2020
Hey guys,
I'am looking for help with following problem.
In my code I have defindes vertices, edges and polygons as class handle objects and each of them are linked to each other.
So the vertices knows its position and knows to which are its neighbour vertices and to which edges it belongs and which are its adjacend polygons. Same for the polygons which knows what its limiting vertices and edges are and ame for edges how know to whcih polygos its adjacend and of which vertices it consist of.
Now i need to refine my mesh by adding more vertices on the edges. So i add a new vertex on one edge and I have to relinked to previous neighbour vertices to the new vertex and cut the link to each other, i have to create new linkages to the polygons and same for polygon i need new linkages to its new limiting vertex and new edge.
Since thats pretty time consuming , especially whne i need to do it multiple times in a row, I wanted to do in parrallel since I expect a huge benefit from that.
It tried it with a parfor but it didnt work and i got the error not enough input arguments and I guess the error is that while for example look at the vertices a,b,c and the edges AB and BC, that while I am adding a vertex to AB, like AD, DB , I am changing the properties of B, more precisely the linkes of B to its edges and vertices and that the problem that I run into problems when another worker wants to calculate the edge BC at the same time.
Does anybody has an idea how to do a workaround? I thought about somehow saving the new links that can be applied later but i have no idea of how to do that.
In the code below you can see the loop that is splittig the edges and the split fuction which is a hndle class of the edges itsself.
for j=1:6
new_edges=Edge.empty(length(edge),0);
new_vertex = Vertex.empty(length(edge),0);
disp('refining edges')
for i =1:length(edge) %% here I want a parfor
[new_edges(i),new_vertex(i)]=split_edge(edge(i));
end
edge=[edge,new_edges];
vertex=[vertex,new_vertex];
end
classdef Edge < handle
properties
end
methods
function ed=Edge(v)
end
end
end
end
function [new_edge,v]=split_edge(ed)
new_vert_pos=(P1(:) + P2(:)).'/2;
% generate new vertex
v = Vertex(new_vert_pos);
% re assign old edge vertices to new vertex
v1.neighbour_vertex(find(ismember(v1.neighbour_vertex,v2)))=v;
v2.neighbour_vertex(find(ismember(v2.neighbour_vertex,v1)))=v;
% assign new vertex to old edge vertices
v.neighbour_vertex(1)=v1;
v.neighbour_vertex(2)=v2;
% assign adjacend polygon to new vertex
end
% insert new vertex to both adjacend polygons
if id(1)==1 && id(1)+1~=id(2)
else
end
end
break
end
end
% renerate new edge
new_edge=Edge([v1,v]);
else
new_edge=Edge([v2,v]);
end
% re assign one egde
end
end
end
Maybe somebody can help my with this.
Best regards

R2019b

### Community Treasure Hunt

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

Start Hunting!