function out = model % % levelset_wang.m % % Model exported on Jan 16 2019, 23:33 by COMSOL 5.4.0.246. DomainWidth=2; DomainHight=1; ENPC=40; ENPR=80; nelx = ENPR; nely = ENPC; FEAInterval=1; PlotInterval=1; % Step 1: Data initialization EW = DomainWidth / ENPR; % The width of each finite element. EH = DomainHight / ENPC; % The hight of each finite element. M = [ ENPC + 1 , ENPR + 1 ]; [ x ,y ] = meshgrid( EW * [ -0.5 : ENPR + 0.5 ] , EH * [ -0.5 : ENPC + 0.5 ]); [ FENd.x, FENd.y, FirstNdPCol ] = MakeNodes(ENPR,ENPC,EW,EH); Ele.NdID = MakeElements( ENPR, ENPC, FirstNdPCol ); LSgrid.x = x(:); LSgrid.y = y(:); % The coordinates of each Level Set grid for i = 1 : length(Ele.NdID(:,1)) Ele.LSgridID(i) = find((LSgrid.x - FENd.x(Ele.NdID(i,1)) - EW/2).^2 +... (LSgrid.y - FENd.y(Ele.NdID(i,1)) - EH/2).^2 <= 100*eps); end; cx = DomainWidth / 200 * [ 33.33 100 166.67 0 66.67 133.33 200 33.33 100 166.67 0 66.67 133.33 200 33.33 100 166.67]; cy = DomainHight / 100 * [ 0 0 0 25 25 25 25 50 50 50 75 75 75 75 100 100 100]; % % for i = 1 : length( cx ) tmpPhi( :, i ) = - sqrt ( ( LSgrid . x - cx ( i ) ) .^2 + ( LSgrid . y - cy ( i ) ) .^2 ) + DomainHight/8; end; LSgrid.Phi = -(max(tmpPhi.')).'; LSgrid.Phi((LSgrid.x - min(LSgrid.x)) .* (LSgrid.x - max(LSgrid.x)) .* (LSgrid.y - max(LSgrid.y)) .* (LSgrid.y - min(LSgrid.y)) <= 100*eps) = -1e-6; FENd.Phi = griddata( LSgrid.x, LSgrid.y, LSgrid.Phi, FENd.x, FENd.y, 'cubic'); % Generate phi phi3 = [FENd.x, FENd.y, FENd.Phi]'; % phi3 = FENd.Phi'; import com.comsol.model.* import com.comsol.model.util.* model = ModelUtil.create('Model'); model.modelPath('C:\Users\sayinde\Desktop\wang_comsol_matlab'); model.label('levelset_wang.mph'); model.comments(['Levelset opt\n\n']); model.param.set('volfrac', '0.5'); model.param.set('ht', '1.0'); model.param.set('alpha', '0.3'); model.param.set('d', '0.01'); model.param.set('dx', '2/3'); model.param.set('dy', '1/2'); model.param.set('x0', 'dx/2'); model.param.set('y0', 'dy/2'); model.param.set('r', '1/8'); model.param.set('gamma', '0.1'); model.param.set('sigma', '5'); model.param.set('beta', '1'); model.param.set('kappa', '0.00125'); model.param.set('x00', 'x0'); model.param.set('x01', '1'); model.param.set('x02', '2-x0'); model.param.set('y00', '0'); model.param.set('y01', '0'); model.param.set('y02', '0'); model.param.set('x10', '0'); model.param.set('x11', '2*x0'); model.param.set('x12', '4*x0'); model.param.set('x13', '2'); model.param.set('y10', '0.25'); model.param.set('y11', '0.25'); model.param.set('y12', '0.25'); model.param.set('y13', '0.25'); model.param.set('x20', 'x0'); model.param.set('x21', '1'); model.param.set('x22', '2-x0'); model.param.set('y20', '0.5'); model.param.set('y21', '0.5'); model.param.set('y22', '0.5'); model.param.set('x30', '0'); model.param.set('x31', '2*x0'); model.param.set('x32', '4*x0'); model.param.set('x33', '2'); model.param.set('y30', '0.75'); model.param.set('y31', '0.75'); model.param.set('y32', '0.75'); model.param.set('y33', '0.75'); model.param.set('x40', 'x0'); model.param.set('x41', '1'); model.param.set('x42', '2-x0'); model.param.set('y40', '1'); model.param.set('y41', '1'); model.param.set('y42', '1'); model.param.set('rho_void', '1e-3'); model.param.set('rho_mat', '1'); model.param.set('delta', '0.05'); model.component.create('mod1', false); model.component('mod1').geom.create('geom1', 2); model.component('mod1').defineLocalCoord(false); model.result.table.create('evl2', 'Table'); model.result.table.create('tbl1', 'Table'); model.component('mod1').mesh.create('mesh1'); model.component('mod1').geom('geom1').repairTolType('relative'); model.component('mod1').geom('geom1').create('R1', 'Rectangle'); model.component('mod1').geom('geom1').feature('R1').set('pos', '0.0,0.0'); model.component('mod1').geom('geom1').feature('R1').set('size', [2 1]); model.component('mod1').geom('geom1').create('pt1', 'Point'); model.component('mod1').geom('geom1').feature('pt1').set('p', [2 0.5]); model.component('mod1').geom('geom1').create('pt2', 'Point'); model.component('mod1').geom('geom1').feature('pt2').set('p', [0 0.5]); model.component('mod1').geom('geom1').feature('fin').set('repairtoltype', 'relative'); model.component('mod1').geom('geom1').run; model.variable.create('var1'); model.variable('var1').set('rho', '(rho_mat*(mod1.phi>=delta)+rho_void*(mod1.phi<-delta)+(0.75 * (rho_mat - rho_void ) * ( (mod1.phi / delta) - (mod1.phi / delta)^3 / 3.0 ) + 0.5 * ( rho_mat + rho_void ))*(-delta<=mod1.phi&&mod1.phi