Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.
Extracting and Sorting Entity Numbers based on their Coordinates
Posted 2017年10月26日 GMT-4 03:25 Geometry Version 5.2a 1 Reply
Please login with a confirmed email address before reporting spam
Hi,
I'm working on a model in Comsol+MATLAB and when trying to automate my process I came across a problem that I haven't been able to solve.
I create a semi-circle using a polygon geometry with the following command:
model.geom('geom1').create('pol1', 'Polygon');
model.geom('geom1').feature('pol1').set('x', 'r*sin({range(0,dtheta,pi)})') ;
model.geom('geom1').feature('pol1').set('y', 'r*cos({range(0,dtheta,pi)})');
model.geom('geom1').run;
Later on my model I need to find the coordinates of those points that I created and sort them out so that they go from 0 to pi. For this I use the following:
% Indices of membrane points and edges from theta = 0 to theta = pi
mempoints_raw = intersect(mphgetadj(model,'geom1','point','domain',intdomain),mphgetadj(model,'geom1','point','domain',extdomain));
memedges_raw = intersect(mphgetadj(model,'geom1','boundary','domain',intdomain),mphgetadj(model,'geom1','boundary','domain',extdomain));
if mod(length(mempoints_raw),2) == 0
mempoints = [mempoints_raw(2:2:end) mempoints_raw(end-1:-2:1)];
memedges = [memedges_raw(2:2:end-1) memedges_raw(end:-2:1)];
else
mempoints = [mempoints_raw(2:2:end-1) mempoints_raw(end:-2:1)];
memedges = [memedges_raw(2:2:end) memedges_raw(end-1:-2:1)];
end
end
mempoints_coords = mphgetcoords(model,'geom1','point',mempoints);
Now, this was working fine because I had symetric points, but now I need a finner discretization in only one of those segments (let's say that only between pi-dtheta and pi I add more points) and the code that I was using to sort my points and segments from 0 to pi doesn't hold anymore (because of the way Comsol defines the entity numbers).
So, my question is: Is there a simple way to extract the indeces of the points, find their coordinates and sort them (the indeces) based on those coordinates?
I thought of extracting the coordinates of my raw points, sort those coordinates in descending order for the y axis (using the sort command from MATLAB), then fix both my x axis and my number entities based on the indeces found with the sort function. So, basically doing:
mempoints_raw = intersect(mphgetadj(model,'geom1','point','domain',intdomain),... mphgetadj(model,'geom1','point','domain',extdomain));
mempoints_coords = mphgetcoords(model,'geom1','point',mempoints);
x = mempoints_coords(1,:);
y = mempoints_coords(2,:);
[y_sorted, index] = sort(y,' descend');
x_sorted = x(index);
mempoints_sorted = mempoints(index);
But I was hoping there would be a more elegant way of doing this.
Thanks for your help.
Clarissa