<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
 <channel>
  <atom:link href="http://www.comsol.asia/community/forums/general/rss/thread/3664.rss" rel="self" type="application/rss+xml"/>
  <title>COMSOL Forums: How can I combine several subregions while &quot;keeping the mesh&quot;?</title>
  <link>http://www.comsol.asia/community/forums/general/thread/3664/</link>
  <description>Most recent forum messages</description>
  <pubDate>Mon, 15 Mar 2010 08:35:21 +0000</pubDate>
  <image>
   <title>COMSOL Forums: How can I combine several subregions while &quot;keeping the mesh&quot;?</title>
   <url>http://www.comsol.asia/shared/images/logos/comsol_logo.gif</url>
   <link>http://www.comsol.asia/community/forums/general/thread/3664/</link>
  </image>
  <item>
   <title>Re: How can I combine several subregions while &quot;keeping the mesh&quot;?</title>
   <link>http://www.comsol.asia/community/forums/general/thread/3664/#p9997</link>
   <description>Hi&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
Well why do you really want to remove the interiour boundaries, just leave them, no ?&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
As the mesh is related to your geometry there is no easy way around, from my knowledge you can only export the mesh as is and import it again, but then you loose the ability to easily play with it&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
But OK you have given us some interesting commands and scripts there, thanks for that !&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
Good luck&lt;br /&gt;&#13;
Ivar</description>
   <pubDate>Mon, 15 Mar 2010 08:35:21 +0000</pubDate>
   <guid isPermaLink="false">3664.1268642121.9997</guid>
  </item>
  <item>
   <title>Solution</title>
   <link>http://www.comsol.asia/community/forums/general/thread/3664/#p9991</link>
   <description>Hi, I solved my &amp;quot;funny indexing puzzle&amp;quot; :)&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
The functions below might not work for all geometry and might be slow.&lt;br /&gt;&#13;
However, they do the job for me and you may modify the functions for your own needs.&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
- Save the attached functions and add them to your matlab path (Matlab menu: File=&amp;gt;Set Path...)&lt;br /&gt;&#13;
- Export your fem structure to the Matlab workspace as &amp;quot;fem&amp;quot;.&lt;br /&gt;&#13;
- Run following command: &lt;br /&gt;&#13;
  fem=remove_internal_boundaries(fem)&lt;br /&gt;&#13;
- Import the new fem structure &amp;quot;fem&amp;quot; back to the Comsol interface.&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
Good luck!&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
********************************&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
function resultfem=remove_internal_boundaries(fem)&lt;br /&gt;&#13;
%this function removes internal boundaries from a fem strukture and keeps the mesh&lt;br /&gt;&#13;
%fem=remove_internal_boundaries(fem)&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 %delete interior boundaries of geometry--------------------------------------------------------------------------------&lt;br /&gt;&#13;
 new_geometry=geomdel(fem.geom);&lt;br /&gt;&#13;
 %geomplot(new_geometry);&lt;br /&gt;&#13;
  &lt;br /&gt;&#13;
 %read mesh information from fem----------------------------------------------------------------------------------------&lt;br /&gt;&#13;
 el=get(fem.mesh,'el');&lt;br /&gt;&#13;
 p=get(fem.mesh,'p');&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 %write triangle element information to new el structure----------------------------------------------------------------&lt;br /&gt;&#13;
 for i=1:length(el)&lt;br /&gt;&#13;
 	if isequal(el{i}.type,'tri')&lt;br /&gt;&#13;
   tri_elem=el{i}.elem;&lt;br /&gt;&#13;
		end&lt;br /&gt;&#13;
	end&lt;br /&gt;&#13;
 el_structure{1}=struct('type','tri','elem',tri_elem);&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 %create new mesh ------------------------------------------------------------------------------------------------------&lt;br /&gt;&#13;
 fem.mesh=femmesh(p,el_structure);&lt;br /&gt;&#13;
 fem.mesh=meshenrich(fem); &lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 %the new mesh has to be modified to fit the already existing geometry==================================================&lt;br /&gt;&#13;
 %read new mesh information from fem------------------------------------------------------------------------------------&lt;br /&gt;&#13;
 clear el; clear p;&lt;br /&gt;&#13;
 el=get(fem.mesh,'el');&lt;br /&gt;&#13;
 p=get(fem.mesh,'p');&lt;br /&gt;&#13;
 tri=el{1};&lt;br /&gt;&#13;
 vtx=el{2};&lt;br /&gt;&#13;
 edg=el{3}&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 %correct vtx information-----------------------------------------------------------------------------------------------&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 %get elem vector&lt;br /&gt;&#13;
 elem=vtx.elem;&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 %get according coordinates&lt;br /&gt;&#13;
 elem_coord=p(:,elem)';&lt;br /&gt;&#13;
 [n m] = size(elem_coord);&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 %get according dom numbers&lt;br /&gt;&#13;
 for k = 1:n&lt;br /&gt;&#13;
		vtx.dom(k)=get_point(new_geometry, elem_coord(k,1),elem_coord(k,2));&lt;br /&gt;&#13;
 end&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 %correct edg information-----------------------------------------------------------------------------------------------&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 %get elem vector&lt;br /&gt;&#13;
 elem=edg.elem;&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 %get according coordinates&lt;br /&gt;&#13;
 elem_coord_1=p(:,elem(1,:))';&lt;br /&gt;&#13;
 elem_coord_2=p(:,elem(2,:))';&lt;br /&gt;&#13;
 [n m] = size(elem_coord_1);&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 for k = 1:n&lt;br /&gt;&#13;
		%get according dom numbers&lt;br /&gt;&#13;
		x1=elem_coord_1(k,1);&lt;br /&gt;&#13;
		y1=elem_coord_1(k,2);&lt;br /&gt;&#13;
		xy1=[x1 y1];&lt;br /&gt;&#13;
		x2=elem_coord_2(k,1);&lt;br /&gt;&#13;
		y2=elem_coord_2(k,2);&lt;br /&gt;&#13;
		xy2=[x2 y2];&lt;br /&gt;&#13;
		edg.dom(k)=get_edg_boundary(new_geometry, xy1, xy2);&lt;br /&gt;&#13;
		&lt;br /&gt;&#13;
		%calculate up-down subdomains  &lt;br /&gt;&#13;
			%calculate test point that lies left of boundary&lt;br /&gt;&#13;
			epsi=3*eps;&lt;br /&gt;&#13;
			if ~(abs(x2-x1)&amp;lt;epsi)&lt;br /&gt;&#13;
				test_point_x=x1+(x2-x1)/2;&lt;br /&gt;&#13;
				if x2-x1 &amp;gt; 0&lt;br /&gt;&#13;
					test_point_y=y1+(y2-y1)/2+epsi;&lt;br /&gt;&#13;
				else&lt;br /&gt;&#13;
					test_point_y=y1+(y2-y1)/2-epsi;&lt;br /&gt;&#13;
				end&lt;br /&gt;&#13;
			elseif ~(abs(y2-y1)&amp;lt;epsi)&lt;br /&gt;&#13;
				test_point_y=y1+(y2-y1)/2;&lt;br /&gt;&#13;
				if y2-y1 &amp;gt; 0&lt;br /&gt;&#13;
					test_point_x=x1+(x2-x1)/2-epsi;&lt;br /&gt;&#13;
				else&lt;br /&gt;&#13;
					test_point_x=x1+(x2-x1)/2+epsi;&lt;br /&gt;&#13;
				end&lt;br /&gt;&#13;
			else&lt;br /&gt;&#13;
				msgbox('Error in mesh correction.');&lt;br /&gt;&#13;
			end&lt;br /&gt;&#13;
			%test if test point lies inside the subdomain polygon and set ud numbers&lt;br /&gt;&#13;
				%create convex polygon &lt;br /&gt;&#13;
				poly_ind=convhull(p(1,:),p(2,:));&lt;br /&gt;&#13;
				poly_p_x=p(1,poly_ind);&lt;br /&gt;&#13;
				poly_p_y=p(2,poly_ind);&lt;br /&gt;&#13;
			&lt;br /&gt;&#13;
				%test and set ud number&lt;br /&gt;&#13;
				edg.ud(1,k)=inpolygon(test_point_x,test_point_y,poly_p_x,poly_p_y);&lt;br /&gt;&#13;
				edg.ud(2,k)=~edg.ud(1,k);			&lt;br /&gt;&#13;
		&lt;br /&gt;&#13;
		%transform param values from absolute distances to relative distances	&lt;br /&gt;&#13;
			%get length of boundary&lt;br /&gt;&#13;
			XY1=flgeomed(new_geometry,edg.dom(k),0);&lt;br /&gt;&#13;
			XY2=flgeomed(new_geometry,edg.dom(k),1);&lt;br /&gt;&#13;
			bound_length=sqrt((XY2(2)-XY1(2))^2+(XY2(1)-XY1(1))^2);&lt;br /&gt;&#13;
			%set param values&lt;br /&gt;&#13;
			edg.param(:,k)=edg.param(:,k)/bound_length; &lt;br /&gt;&#13;
						&lt;br /&gt;&#13;
		%check orientation and flip, if edg orientation is not equal boundary orientation&lt;br /&gt;&#13;
		if ~and(isequal(XY2(1)-XY1(1)&amp;gt;epsi,x2-x1&amp;gt;epsi),isequal(XY2(2)-XY1(2)&amp;gt;epsi,y2-y1&amp;gt;epsi))&lt;br /&gt;&#13;
			%flip elem&lt;br /&gt;&#13;
			saveelem=edg.elem(1,k);&lt;br /&gt;&#13;
			edg.elem(1,k)=edg.elem(2,k);&lt;br /&gt;&#13;
			edg.elem(2,k)=saveelem;&lt;br /&gt;&#13;
			%flip ud&lt;br /&gt;&#13;
			saveud=edg.ud(1,k);&lt;br /&gt;&#13;
			edg.ud(1,k)=edg.ud(2,k);&lt;br /&gt;&#13;
			edg.ud(2,k)=saveud;&lt;br /&gt;&#13;
			%calculate new param&lt;br /&gt;&#13;
			edg.param(1,k)=1-edg.param(1,k);&lt;br /&gt;&#13;
			edg.param(2,k)=1-edg.param(2,k);		&lt;br /&gt;&#13;
		end &lt;br /&gt;&#13;
		&lt;br /&gt;&#13;
 end&lt;br /&gt;&#13;
		&lt;br /&gt;&#13;
 %assign corrected mesh information-------------------------------------------------------------------------------------&lt;br /&gt;&#13;
 el{1}=tri;&lt;br /&gt;&#13;
 el{2}=edg;&lt;br /&gt;&#13;
 el{3}=vtx;&lt;br /&gt;&#13;
 fem.mesh=femmesh(p,el);&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 %assign new geometry---------------------------------------------------------------------------------------------------&lt;br /&gt;&#13;
 fem.geom=new_geometry;&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 resultfem=fem;&lt;br /&gt;&#13;
end&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
************************************&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
function index = get_point(geometry,x,y,tol)&lt;br /&gt;&#13;
%This function finds the index of a point at given coordinates with tolerance tol&lt;br /&gt;&#13;
%index = get_point(geometry,x,y,tol)&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 %set default tolerance=================================================================================================&lt;br /&gt;&#13;
 if nargin &amp;lt; 4 &lt;br /&gt;&#13;
    tol = eps;&lt;br /&gt;&#13;
 end&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 % plot geometry =======================================================================================================&lt;br /&gt;&#13;
 %geomplot(geometry,'pointlabels','on','edgelabels','on');&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 %get number of objects=================================================================================================&lt;br /&gt;&#13;
 gd = geominfo(geometry,'out',{'gd'});&lt;br /&gt;&#13;
 no = geominfo(geometry,'out',{'no'},'od',0:gd);&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 %get vertex coordinates================================================================================================&lt;br /&gt;&#13;
 xy=flgeomvtx(geometry);&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 %get indice that lie in the region of interest=========================================================================&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 % getting elements with x-coordinate &amp;gt; x-tol &lt;br /&gt;&#13;
 element_x_g = find(xy(1,:) &amp;gt;=  x - tol);&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 % getting elements with x-coordinate &amp;lt; x+tol &lt;br /&gt;&#13;
 element_x_s = find(xy(1,:) &amp;lt;=  x + tol);&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 % creating a matrix for the elements greater x&lt;br /&gt;&#13;
 coordinate_matrix_x_g = zeros(1,no(1));&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 % creating a matrix for the elements smaller x&lt;br /&gt;&#13;
 coordinate_matrix_x_s = zeros(1,no(1));&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 % filling the matrix with a one when element fullfills the condition &amp;gt; x&lt;br /&gt;&#13;
 coordinate_matrix_x_g(element_x_g) = 1;&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 % filling the matrix with a one when element fullfills the condition &amp;lt; x&lt;br /&gt;&#13;
 coordinate_matrix_x_s(element_x_s) = 1;&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 % Merge the x-coordinate_s and x-coordinate_g matrix&lt;br /&gt;&#13;
 coordinate_matrix_x = coordinate_matrix_x_g &amp;amp; coordinate_matrix_x_s;&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 % getting elements with y-coordinate &amp;gt; y-tol &lt;br /&gt;&#13;
 element_y_g = find(xy(2,:) &amp;gt;=  y - tol);&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 % getting elements with y-coordinate &amp;lt; y + tol &lt;br /&gt;&#13;
 element_y_s = find(xy(2,:) &amp;lt;=  y + tol);&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 % creating a matrix for the elements greater y&lt;br /&gt;&#13;
 coordinate_matrix_y_g = zeros(1,no(1));&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 % creating a matrix for the elements smaller y&lt;br /&gt;&#13;
 coordinate_matrix_y_s = zeros(1,no(1));&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 % filling the matrix with an one when element fullfills the condition &amp;gt; y&lt;br /&gt;&#13;
 coordinate_matrix_y_g(element_y_g) = 1;&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 % filling the matrix with an one when element fullfills the condition &amp;lt; y&lt;br /&gt;&#13;
 coordinate_matrix_y_s(element_y_s) = 1;&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 % Merge the y-coordinate_s and y-coordinate_g matrix&lt;br /&gt;&#13;
 coordinate_matrix_y = coordinate_matrix_y_g &amp;amp; coordinate_matrix_y_s;&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 %% Calculating the Object which fullfills all the conditions x y &lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 %get indice &lt;br /&gt;&#13;
 index = find(coordinate_matrix_x &amp;amp; coordinate_matrix_y == 1);&lt;br /&gt;&#13;
 if length(index) &amp;gt; 1&lt;br /&gt;&#13;
  msgbox(['More than one point found in region around x = ' num2str(x,3) ', y = ' num2str(y,3) ],'Error','error');&lt;br /&gt;&#13;
 end&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 if length(index) &amp;lt; 1&lt;br /&gt;&#13;
  msgbox(['No point found in region around x = ' num2str(x,3) ', y = ' num2str(y,3) ],'Error','error');&lt;br /&gt;&#13;
 end&lt;br /&gt;&#13;
  &lt;br /&gt;&#13;
end &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
****************************************&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 function index = get_edg_boundary(geometry,p1,p2,tol)&lt;br /&gt;&#13;
%this function finds the boundary index of a edge element between the&lt;br /&gt;&#13;
%points p1 = [x1 y1] and p2 =[x2 y2]&lt;br /&gt;&#13;
%index = get_edg_boundary(geometry,p1,p2)&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 %set default tolerance=================================================================================================&lt;br /&gt;&#13;
 if nargin &amp;lt; 4 &lt;br /&gt;&#13;
    tol = eps;&lt;br /&gt;&#13;
 end&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 % plot geometry =======================================================================================================&lt;br /&gt;&#13;
 %geomplot(geometry,'pointlabels','on','edgelabels','on');&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 %get number of objects=================================================================================================&lt;br /&gt;&#13;
  gd = geominfo(geometry,'out',{'gd'});&lt;br /&gt;&#13;
 no = geominfo(geometry,'out',{'no'},'od',0:gd);&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 %get coordinates of edges==============================================================================================&lt;br /&gt;&#13;
 X1=0;&lt;br /&gt;&#13;
 Y1=0;&lt;br /&gt;&#13;
 X2=0;&lt;br /&gt;&#13;
 Y2=0;&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 for k = 1:no&lt;br /&gt;&#13;
  xy=flgeomed(geometry,k,0);&lt;br /&gt;&#13;
  X1(k)=xy(1);&lt;br /&gt;&#13;
  Y1(k)=xy(2);&lt;br /&gt;&#13;
  xy2=flgeomed(geometry,k,1);&lt;br /&gt;&#13;
  X2(k)=xy2(1);&lt;br /&gt;&#13;
  Y2(k)=xy2(2);  &lt;br /&gt;&#13;
 end&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 %%calculate all boundary elements that may include the edg element in x-direction&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
  % getting elements with X1 &amp;lt;= x1, X1 &amp;lt;= x2 &lt;br /&gt;&#13;
  element_x_s1 = find(X1 &amp;lt;=  p1(1)+tol);&lt;br /&gt;&#13;
  element_x_s2 = find(X1 &amp;lt;=  p2(1)+tol);&lt;br /&gt;&#13;
  &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
  % getting elements with X2 &amp;gt;= x1, X2 &amp;gt;=x2 &lt;br /&gt;&#13;
  element_x_g1 = find(X2 &amp;gt;=  p1(1)-tol);&lt;br /&gt;&#13;
  element_x_g2 = find(X2 &amp;gt;=  p2(1)-tol);&lt;br /&gt;&#13;
  &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
		% creating matrix for start_x smaller x_vals&lt;br /&gt;&#13;
  coordinate_matrix_x_s1 = zeros(1,no(1));&lt;br /&gt;&#13;
  coordinate_matrix_x_s2 = zeros(1,no(1));&lt;br /&gt;&#13;
		&lt;br /&gt;&#13;
  % creating matrix for end_x greater x_vals&lt;br /&gt;&#13;
  coordinate_matrix_x_g1 = zeros(1,no(1));&lt;br /&gt;&#13;
  coordinate_matrix_x_g2 = zeros(1,no(1));&lt;br /&gt;&#13;
		&lt;br /&gt;&#13;
		% filling matrix with a one when element fullfills the smaller condition&lt;br /&gt;&#13;
  coordinate_matrix_x_s1(element_x_s1) = 1;&lt;br /&gt;&#13;
  coordinate_matrix_x_s2(element_x_s2) = 1;&lt;br /&gt;&#13;
  coordinate_matrix_x_s = coordinate_matrix_x_s1 &amp;amp; coordinate_matrix_x_s2;&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
  % filling matrix with a one when element fullfills the greater condition&lt;br /&gt;&#13;
  coordinate_matrix_x_g1(element_x_g1) = 1;&lt;br /&gt;&#13;
  coordinate_matrix_x_g2(element_x_g2) = 1;&lt;br /&gt;&#13;
  coordinate_matrix_x_g = coordinate_matrix_x_g1 &amp;amp; coordinate_matrix_x_g2;&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
  % Merge the x-coordinate_s and x-coordinate_g matrix  &lt;br /&gt;&#13;
  coordinate_matrix_x = coordinate_matrix_x_g &amp;amp; coordinate_matrix_x_s;&lt;br /&gt;&#13;
  &lt;br /&gt;&#13;
 %% calculate all boundary elements that may include the edg element in y-direction&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
  % getting elements with Y1 &amp;lt;= y1, Y1 &amp;lt;= y2 &lt;br /&gt;&#13;
  element_y_s1 = find(Y1 &amp;lt;=  p1(2)+tol);&lt;br /&gt;&#13;
  element_y_s2 = find(Y1 &amp;lt;=  p2(2)+tol);&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
  % getting elements with Y2 &amp;gt;= x1, Y2 &amp;gt;=x2&lt;br /&gt;&#13;
  element_y_g1 = find(Y2 &amp;gt;=  p1(2)-tol);&lt;br /&gt;&#13;
  element_y_g2 = find(Y2 &amp;gt;=  p2(2)-tol);&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
  % creating matrix for start_y smaller y_vals&lt;br /&gt;&#13;
  coordinate_matrix_y_s1 = zeros(1,no(1));&lt;br /&gt;&#13;
  coordinate_matrix_y_s2 = zeros(1,no(1));&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
  % creating matrix for end_x greater x_vals&lt;br /&gt;&#13;
  coordinate_matrix_y_g1 = zeros(1,no(1));&lt;br /&gt;&#13;
  coordinate_matrix_y_g2 = zeros(1,no(1));&lt;br /&gt;&#13;
		&lt;br /&gt;&#13;
		% filling matrix with a one when element fullfills the smaller condition&lt;br /&gt;&#13;
  coordinate_matrix_y_s1(element_y_s1) = 1;&lt;br /&gt;&#13;
  coordinate_matrix_y_s2(element_y_s2) = 1;&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
  % filling matrix with a one when element fullfills the greater condition&lt;br /&gt;&#13;
  coordinate_matrix_y_g1(element_y_g1) = 1;&lt;br /&gt;&#13;
  coordinate_matrix_y_g2(element_y_g2) = 1;&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
  % Merge the x-coordinate_s and x-coordinate_g matrix&lt;br /&gt;&#13;
  coordinate_matrix_y_g = coordinate_matrix_y_g1 &amp;amp; coordinate_matrix_y_g2;&lt;br /&gt;&#13;
  coordinate_matrix_y_s = coordinate_matrix_y_s1 &amp;amp; coordinate_matrix_y_s2;&lt;br /&gt;&#13;
  &lt;br /&gt;&#13;
  coordinate_matrix_y = coordinate_matrix_y_g &amp;amp; coordinate_matrix_y_s; &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 %% Calculating the Object which fullfills all the conditions&lt;br /&gt;&#13;
 &lt;br /&gt;&#13;
 % Addition of both matrices to get the element which is the searchobject&lt;br /&gt;&#13;
 index = find(coordinate_matrix_x &amp;amp; coordinate_matrix_y == 1);&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 if length(index) &amp;gt; 1&lt;br /&gt;&#13;
  msgbox(['Error: More than one possible boundary found.' sprintf('\n') ...&lt;br /&gt;&#13;
           'for the edg element between p1 = (' num2str(p1(1),3) ', ' num2str(p1(2),3) ') and' sprintf('\n') ...&lt;br /&gt;&#13;
	   '        p2 = (' num2str(p2(1),3) ', ' num2str(p2(2),3) ') !'],'Error','error');&lt;br /&gt;&#13;
 end &lt;br /&gt;&#13;
 if length(index) &amp;lt; 1&lt;br /&gt;&#13;
  msgbox(['Error: No boundary found for the edg element' sprintf('\n') ...&lt;br /&gt;&#13;
           'between p1 = (' num2str(p1(1),3) ', ' num2str(p1(2),3) ') and' sprintf('\n') ...&lt;br /&gt;&#13;
	   '        p2 = (' num2str(p2(1),3) ', ' num2str(p2(2),3) ') !'],'Error','error');&lt;br /&gt;&#13;
 end &lt;br /&gt;&#13;
end</description>
   <pubDate>Mon, 15 Mar 2010 08:15:50 +0000</pubDate>
   <guid isPermaLink="false">3664.1268640950.9991</guid>
  </item>
  <item>
   <title>Re: How can I combine several subregions while &quot;keeping the mesh&quot;?</title>
   <link>http://www.comsol.asia/community/forums/general/thread/3664/#p9799</link>
   <description>Not only the order of the boundary elements is different.&lt;br /&gt;&#13;
The param field of the mesh after meshenrich contains absolute values while&lt;br /&gt;&#13;
the param field of the original mesh contains relative values.&lt;br /&gt;&#13;
</description>
   <pubDate>Fri, 12 Mar 2010 08:45:50 +0000</pubDate>
   <guid isPermaLink="false">3664.1268383550.9799</guid>
  </item>
  <item>
   <title>Re: How can I combine several subregions while &quot;keeping the mesh&quot;?</title>
   <link>http://www.comsol.asia/community/forums/general/thread/3664/#p9652</link>
   <description>Thank you. Some empathy is also nice to get :)&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
I digged a little bit in the mesh object. If I export a single subdomain,&lt;br /&gt;&#13;
extract triangle coordinates, build a new mesh... the import also doesn't work.&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
The problem seems to be that meshenrich uses a differend indexing order&lt;br /&gt;&#13;
for the boundary edges. &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
If i apply &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
el=get(fem.mesh,'el'); &lt;br /&gt;&#13;
el{1}&lt;br /&gt;&#13;
el{2}&lt;br /&gt;&#13;
el{3}&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
to the two meshes (first one after export, second one build from &lt;br /&gt;&#13;
extracted information) i get different results:&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
Case 1:------------------------------------------------------------------&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
type: 'vtx'&lt;br /&gt;&#13;
    elem: [1 8 12 20]&lt;br /&gt;&#13;
     dom: [1 3 2 4]&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
type: 'edg'&lt;br /&gt;&#13;
     elem: [2x12 double]&lt;br /&gt;&#13;
      dom: [2 2 1 1 2 1 4 3 4 3 3 4]&lt;br /&gt;&#13;
       ud: [2x12 double]&lt;br /&gt;&#13;
    param: [2x12 double]&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
 type: 'tri'&lt;br /&gt;&#13;
    elem: [3x26 double]&lt;br /&gt;&#13;
     dom: [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
Case 2:-----------------------------------------------------------------&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
type: 'vtx'&lt;br /&gt;&#13;
    elem: [1 8 12 20]&lt;br /&gt;&#13;
     dom: [1 2 3 4]&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
type: 'edg'&lt;br /&gt;&#13;
     elem: [2x12 double]&lt;br /&gt;&#13;
      dom: [2 4 2 2 4 4 3 1 3 1 3 1]&lt;br /&gt;&#13;
       ud: [2x12 double]&lt;br /&gt;&#13;
    param: [2x12 double]&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
type: 'tri'&lt;br /&gt;&#13;
    elem: [3x26 double]&lt;br /&gt;&#13;
     dom: [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
--------------------------------------------------------------------------&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
=&amp;gt; The &amp;quot;dom&amp;quot; numbers are mixed up.&lt;br /&gt;&#13;
(The order of the el-fields is also different, but this should not matter.&lt;br /&gt;&#13;
Above I wrote the el-fields in the same order for easy comparison.)&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
I do not like the Comsol-Indexing system!!! *grrrrr* &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
It already took me a lot of time in the past.&lt;br /&gt;&#13;
I wrote something to find out the index of a point or boundary at&lt;br /&gt;&#13;
specified coordinates and now I can use my own indexing for &lt;br /&gt;&#13;
complex geometries. &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
Maybe something similiar will work for this issue. &lt;br /&gt;&#13;
Or maybe I will not work with Comsol any more ;).&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
</description>
   <pubDate>Wed, 10 Mar 2010 15:37:07 +0000</pubDate>
   <guid isPermaLink="false">3664.1268235427.9652</guid>
  </item>
  <item>
   <title>Re: How can I combine several subregions while &quot;keeping the mesh&quot;?</title>
   <link>http://www.comsol.asia/community/forums/general/thread/3664/#p9649</link>
   <description>Hi Stefan,&lt;br /&gt;&#13;
I understand your problem and your needs, but at the moment I have no tip. &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
I am sorry. Please keep me updated if you find a good solution to your issue.&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
Regards&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
Pasquale</description>
   <pubDate>Wed, 10 Mar 2010 15:05:40 +0000</pubDate>
   <guid isPermaLink="false">3664.1268233540.9649</guid>
  </item>
  <item>
   <title>Re: How can I combine several subregions while &quot;keeping the mesh&quot;?</title>
   <link>http://www.comsol.asia/community/forums/general/thread/3664/#p9637</link>
   <description>Hi,&lt;br /&gt;&#13;
I want to generate a mesh with variable mesh element size for semiconductor simulations. &lt;br /&gt;&#13;
My current approach is:&lt;br /&gt;&#13;
- Define a &amp;quot;mesh-size expression&amp;quot; mesh_size(x,y) in the scalar expressions.&lt;br /&gt;&#13;
- Copy the fem structure &amp;quot;fem&amp;quot; to a dummy fem structure &amp;quot;dummy_fem&amp;quot; &lt;br /&gt;&#13;
- Initialize the fem structure and calculate contour lines of the expression mesh_size(x,y).&lt;br /&gt;&#13;
- Take the contour lines as subdomain boundaries.&lt;br /&gt;&#13;
- Mesh the subdomains with different mesh sizes, according to the &amp;quot;countour-height&amp;quot;.&lt;br /&gt;&#13;
- Remove the internal boundaries.&lt;br /&gt;&#13;
- Transfer the new mesh of &amp;quot;dummy_fem&amp;quot; to &amp;quot;fem&amp;quot;, including all boundary conditions ect. &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
If i do not remove the boundaries i would have to specify the physics for a lot of regions&lt;br /&gt;&#13;
where the physics is the same. &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
Another approach was to start with a coarse triangle mesh and refine&lt;br /&gt;&#13;
the triangles if triangle-size is smaller than mesh_size(x,y). This&lt;br /&gt;&#13;
takes too much time and the mesh is too fine at some locations. &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
Is there a way to import a mesh without meshenrich?&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
If I find another way to get my wanted mesh point coordinates (and use the delaunay triangulation &lt;br /&gt;&#13;
function...) I would get the same problem with the mesh import. &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
So the main question is: &amp;quot;How to import a mesh for a already existing geometry?&amp;quot; </description>
   <pubDate>Wed, 10 Mar 2010 10:09:00 +0000</pubDate>
   <guid isPermaLink="false">3664.1268215740.9637</guid>
  </item>
  <item>
   <title>Re: How can I combine several subregions while &quot;keeping the mesh&quot;?</title>
   <link>http://www.comsol.asia/community/forums/general/thread/3664/#p9634</link>
   <description>Hi Stefan again,&lt;br /&gt;&#13;
the &amp;quot;meshenrich&amp;quot; function creates also a new geometry decomposition based just only on mesh data. This geometry may be different from the original one (that one you created after removing internal boundaries). The approach I suggested you can be useful but you need to redefine all domain and boundary conditions. &lt;br /&gt;&#13;
Please tell me why you need to delete interior boundaries from your application? Is there some specific reason? &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
Pasquale&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
</description>
   <pubDate>Wed, 10 Mar 2010 09:40:01 +0000</pubDate>
   <guid isPermaLink="false">3664.1268214001.9634</guid>
  </item>
  <item>
   <title>Re: How can I combine several subregions while &quot;keeping the mesh&quot;?</title>
   <link>http://www.comsol.asia/community/forums/general/thread/3664/#p9631</link>
   <description>Hi Pasquale,&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
thank you for your answer! I got on the same path and below is some stuff i tried. &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
It is possible to extract the triangle information and create a new mesh without internal&lt;br /&gt;&#13;
sobdomain boundaries. So far so good. &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
It is also possible to create a new geometry from this new mesh and import it together&lt;br /&gt;&#13;
with the new mesh back to the Comsol interface.&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
But if I try to fit the new mesh to my own geometry (old geometry after removing&lt;br /&gt;&#13;
internal boundaries) I get following error:&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&amp;quot;Geometry object and mesh object are not compatible.&amp;quot;&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
I saw some small differences (in the order of 1e-20) in the coordinates of the edge&lt;br /&gt;&#13;
points of my new mesh and the edge point coordinatets of the geometry. Could&lt;br /&gt;&#13;
that be the reason? I tried to rescale the mesh coordinates, but the scaled mesh did not fit, too.  &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
Any idea how I have to further modify the mesh or the existing geometry?&lt;br /&gt;&#13;
(I do not want to reset my application modes.)&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
-------------------------------------------------------------------------&lt;br /&gt;&#13;
%- read mesh data from fem structure&lt;br /&gt;&#13;
ele=get(fem.mesh,'el');&lt;br /&gt;&#13;
p=get(fem.mesh,'p');&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%-get triangles...&lt;br /&gt;&#13;
tria=ele{3}.elem;&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%- create new structure...&lt;br /&gt;&#13;
elestr{1}=struct('type','tri','elem',tria);&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%- create new mesh object...&lt;br /&gt;&#13;
fem.mesh=femmesh(p,elestr);&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%- update comsol data&lt;br /&gt;&#13;
fem.mesh=meshenrich(fem);&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%generate geometry from mesh (import would work with this new geometry)&lt;br /&gt;&#13;
%fem=mesh2geom(fem);&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%delete interior boundaries of geometry (import does not work with resulting geometry)&lt;br /&gt;&#13;
fem.geom=geomdel(fem.geom);&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%meshplot(fem,'Boundmode','off');&lt;br /&gt;&#13;
%geomplot(fem)&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%!!!!!! Import of 'fem' results in the error &amp;quot;Geometry object and mesh object are not compatible.&amp;quot; !!!!!!!!&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
-----------------------------------------------------------------------------&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
some further code snippets:&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%get mesh point coordinates from file&lt;br /&gt;&#13;
%d=importdata('mesh.mphtxt',' ',22);&lt;br /&gt;&#13;
%xy=d.data(1:end-1,:);  %remove last line with NaN&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%get mesh point coordinates from fem structure&lt;br /&gt;&#13;
xy=get(fem.mesh,'p')';&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%remove scaling errors&lt;br /&gt;&#13;
%xw =3e-4;     %specify width of geometry&lt;br /&gt;&#13;
%yw =1.5e-4;  %specify height of geometry&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%max(xy(:,1))-xw %errors before scaling&lt;br /&gt;&#13;
%min(xy(:,2))+yw %&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%xy(:,1)=xy(:,1)*xw/max(xy(:,1));&lt;br /&gt;&#13;
%xy(:,2)=xy(:,2)*(-yw)/min(xy(:,2));&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%max(xy(:,1))-xw %errors after scaling = 0&lt;br /&gt;&#13;
%min(xy(:,2))+yw %&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%generate delaunay triangle mesh from mesh point coordinates&lt;br /&gt;&#13;
tri = DelaunayTri(xy(:,1),xy(:,2));&lt;br /&gt;&#13;
vertices=tri.Triangulation;&lt;br /&gt;&#13;
coord=tri.X;&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%transform the matlab mesh to a comsol mesh structure fem.mesh&lt;br /&gt;&#13;
el = cell(1,0);&lt;br /&gt;&#13;
el{1} = struct('type','tri','elem',vertices');&lt;br /&gt;&#13;
fem.mesh = femmesh(coord',el);&lt;br /&gt;&#13;
fem.mesh = meshenrich(fem);&lt;br /&gt;&#13;
%meshplot(fem,'Boundmode','off');&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%!!!!!! Import results in the same error &amp;quot;Geometry object and mesh object are not compatible.&amp;quot; !!!!!!!&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
</description>
   <pubDate>Wed, 10 Mar 2010 09:11:36 +0000</pubDate>
   <guid isPermaLink="false">3664.1268212296.9631</guid>
  </item>
  <item>
   <title>Re: How can I combine several subregions while &quot;keeping the mesh&quot;?</title>
   <link>http://www.comsol.asia/community/forums/general/thread/3664/#p9629</link>
   <description>Hi Stefan,&lt;br /&gt;&#13;
I guess that there is no way to solve your question by using comsol gui tools. I thing that you should try via Matlab.&lt;br /&gt;&#13;
Try the procedure below:&lt;br /&gt;&#13;
1. create the live-link with matlab&lt;br /&gt;&#13;
2. export fem data as matlab structure (your variable is saved in the workspace as &amp;quot;fem&amp;quot; by default)&lt;br /&gt;&#13;
3. run the following matlab script:&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%%%%%%%%%%%%%%&lt;br /&gt;&#13;
%- get element data...&lt;br /&gt;&#13;
ele=get(fem.mesh,'el');&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%-get triangles...&lt;br /&gt;&#13;
tria=ele{3}.elem;&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%- create new structure...&lt;br /&gt;&#13;
elestr{1}=struct('type','tri','elem',tria);&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%- create new mesh object...&lt;br /&gt;&#13;
mobj=femmesh(node,elestr);&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
%- update comsol data&lt;br /&gt;&#13;
mobj=meshenrich(mobj);&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
femNew.mesh=mobj;&lt;br /&gt;&#13;
%%%%%%%%%%%%%&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
4. now &amp;quot;femNew&amp;quot; is the updated comsol structure having only mesh data information (as you are looking for)&lt;br /&gt;&#13;
5. import &amp;quot;femNew&amp;quot; in comsol and run your application mode.&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
I hope this can help you.&lt;br /&gt;&#13;
Please let me know if this works well!&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
Good luck&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
Pasquale&lt;br /&gt;&#13;
</description>
   <pubDate>Wed, 10 Mar 2010 08:31:26 +0000</pubDate>
   <guid isPermaLink="false">3664.1268209886.9629</guid>
  </item>
  <item>
   <title>How can I combine several subregions while &quot;keeping the mesh&quot;?</title>
   <link>http://www.comsol.asia/community/forums/general/thread/3664/#p9526</link>
   <description>I have three subregions and mesh the subregions with different mesh size&lt;br /&gt;&#13;
(see attached figure).&lt;br /&gt;&#13;
After meshing i want to &amp;quot;remove&amp;quot; the internal boundaries&lt;br /&gt;&#13;
and keep the variable sized mesh.&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
At the end there should be only one subregion but the mesh should &lt;br /&gt;&#13;
stay &amp;quot;the same&amp;quot; as before. &lt;br /&gt;&#13;
&lt;br /&gt;&#13;
How can I convert the internal boundaries to triangle edges&lt;br /&gt;&#13;
of a &amp;quot;combined mesh&amp;quot;?&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
</description>
   <pubDate>Mon, 08 Mar 2010 14:40:04 +0000</pubDate>
   <guid isPermaLink="false">3664.1268059204.9526</guid>
  </item>
 </channel>
</rss>
