%build the geometrical modelclear;fs.randSeed(2);%build random modelB=obj_Box;%build a box objectB.name='BoxMicroParticle';B.GPUstatus='auto';B.ballR=2e-5;B.isClump=0;B.distriRate=0.2;B.sampleW=5e-3;B.sampleL=0;B.sampleH=5e-3;%B.BexpandRate=4;%B.PexpandRate=4;B.type='topPlaten';%B.type='TriaxialCompression';B.setType();B.buildInitialModel();%B.show();B.setUIoutput();d=B.d;%d.breakGroup('sample');d.breakGroup('lefPlaten');d.mo.setGPU('auto');%--------------end initial model------------B.gravitySediment();B.compactSample(1);%input is compaction time%------------return and save result--------------d.status.dispEnergy();%display the energy of the modeld.clearData(1);%clear dependent datad.recordCalHour('BoxMicroParticle1Finish');save(['TempModel/'B.name'1.mat'],'B','d');save(['TempModel/'B.name'1R'num2str(B.ballR)'-distri'num2str(B.distriRate)'aNum'num2str(d.aNum)'.mat']);d.calculateData();d.show('aR');
%---------------1. load dataclearload('TempModel/BoxMicroParticle1.mat');B.setUIoutput();%set output of messaged=B.d;d.calculateData();d.mo.setGPU('off');d.getModel();%get xyz from d.mo%---------------2. get the gray rank matrixfileName='slope\micro particle.PNG';%the file to source=imread(fileName);%read imagesource=double(source);%change to double dataimH=size(source,1);imW=size(source,2);%the height and width of the imageRGB=(source(:,:,1)*256+source(:,:,2))*256+source(:,:,3);%changed to RGB valuesRGB=flipud(RGB);%flip data along vertical direction[uColor,iA,iC]=unique(RGB);%find unique colorGray=mean(source,3);%get gray levelGray=flipud(Gray);%flip data along vertical directionuGray=Gray(iA);%unique gray level[v,grayI]=sort(uGray);%sort the groupId according to gray levelGrayRank=reshape(grayI(iC),size(Gray));%gray rank matrix%---------------3. get the groupId of clump by imagesampleId=d.GROUP.sample;%the sample group will be usedsampleX=d.mo.aX(sampleId);sampleZ=d.mo.aZ(sampleId);sampleR=d.mo.aR(sampleId);x1=min(sampleX-sampleR);%get the four limits of the modelx2=max(sampleX+sampleR);z1=min(sampleZ-sampleR);z2=max(sampleZ+sampleR);sFilter=false(d.mNum,1);sFilter(d.GROUP.sample)=true;%filter of elementsdX=(x2-x1)/imW;dZ=(z2-z1)/imH;imageXI=ceil((sampleX-x1)/dX);%get the location of element in imageimageZI=ceil((sampleZ-z1)/dZ);startId=min([d.GROUP.groupId;-10])-1;%clump starts from -11 or lowest groupId-1GrayGId=-GrayRank+1+startId;%change gray rank to groupIdimageIndex=(imageXI-1)*imH+imageZI;%element index in imageimageGId=GrayGId(imageIndex);%element groupId in image%---------------4. set the clump by groupIdd.GROUP.groupId(sFilter)=imageGId;%assing groupId to the groupd.setClump();%set clump for groupId<=-11delFilter=d.GROUP.groupId==startId;%groupId of pores is startIdd.delElement(find(delFilter));%delete poresfiguresubplot(1,2,1);imshow(fileName);subplot(1,2,2);d.showData('groupId');colorbaroff;%---------------5. save the datad.mo.setGPU('off');d.clearData(1);d.recordCalHour('BoxModel2Finish');save(['TempModel/'B.name'2.mat'],'B','d');save(['TempModel/'B.name'2R'num2str(B.ballR)'-distri'num2str(B.distriRate)'aNum'num2str(d.aNum)'.mat']);d.calculateData();