% Domain activation and deactivation % % This model demonstrates how to activate and deactivate domains during % an analysis using the LiveLink for MATLAB. The problem described here % consists in heating of an object from alternating regions. % Use CTRL+SHIFT+ENTER keys to run the script in sequence. %% % Load the model containing the heat transfer simulation. model = mphload('domain_activation_llmatlab'); % Set the list the domain index to use alternatively. domInd = [2,3,5,4]; % Create a shortcut to the heat transfer physics interface. ht = model.physics('ht'); %% % Start the loop set for 8 iterations. for i = 1:8 %% % Define the variable k as the modulus of the division of the % iteration number by 8. k = mod(i,4); % Prevent k to be null if k == 0 k = 4; end % Set the domain selection for the heat transfer physics interface, and % initial condition feature node. ht.selection.set([1 domInd(k)]); ht.feature('init2').selection.set(domInd(k)); %% % Solve the model. model.study('std1').run; %% % At the 1st iteration, change model settings. if i==1 % Create a point graph at points (0;0;L/10), (L/2;L/2;L/10) and % (L;L;L/10). cpt1 = model.result.dataset.create('cpt1', 'CutPoint3D'); cpt1.set('pointx', '0 L/2 L'); cpt1.set('pointy', '0 L/2 L'); cpt1.set('pointz', 'L/10'); pg1 = model.result.create('pg1', 'PlotGroup1D'); pg1.set('data', 'cpt1'); ptgr1 = pg1.feature.create('ptgr1', 'PointGraph'); ptgr1.set('legend', 'on'); % Create a 3D surface plot of the temperature. pg2 = model.result.create('pg2', 'PlotGroup3D'); surf1 = pg2.feature.create('surf1', 'Surface'); surf1.set('rangecoloractive', 'on'); surf1.set('rangecolormax', '336'); surf1.set('rangecolormin', '293.15'); % Set the initial temperature at domain 1 using the temperature % expression. ht.feature('init1').set('T', 1, 'T'); % Set the initial condition expression using the solution contains % in sol1. v1 = model.sol('sol1').feature('v1'); v1.set('initsol', 'sol1'); end %% % Display the first plot group in a MATLAB figure. figure(1) mphplot(model,'pg1','rangenum',1) hold on % Display the 3D surface plot on a multiple figure window. figure(2) subplot(4,2,i) pg2.setIndex('looplevel', '25', 0); mphplot(model,'pg2'); %% % Update initial time for the next iteration. time = mphglobal(model,'t','solnum','end'); model.param.set('t0',time); %% % End of the iteration. disp(sprintf('End of iteration No.%d',i)); end