%step1: packing the elementsclear;fs.randSeed(1);%random model seed, 1,2,3...B=obj_Box;%declare a box objectB.name='PorePermeability';%--------------initial model------------B.GPUstatus='auto';%program will test the CPU and GPU speed, and choose the quicker oneB.ballR=0.0005;B.isShear=0;B.isClump=0;%if isClump=1, particles are composed of several ballsB.distriRate=0.2;%define distribution of ball radius, B.sampleW=0.0309*2;%width, length, height, average radiusB.sampleL=0;%when L is zero, it is a 2-dimensional modelB.sampleH=0.05;B.boundaryRrate=0.999999;B.BexpandRate=2;%boundary is 4-ball wider than B.PexpandRate=1;B.isSample=1;B.type='TriaxialCompression';B.setType();B.buildInitialModel();%B.show();d=B.d;%d.breakGroup('sample');d.breakGroup('lefPlaten');%you may change the size distribution of elements here, e.g. d.mo.aR=d.aR*0.95;d.showB=1;%--------------end initial model------------d.mo.setGPU('off');%----------remove overlap platen elementsdelId=[d.GROUP.topPlaten(end-1:end);d.GROUP.botPlaten(end-1:end)];d.delElement(delId);d.mo.zeroBalance();%----------end remove overlap platen elementsd.mo.isShear=0;%---------- gravity sedimentationB.gravitySediment(1);%you may use B.gravitySediment(10); to increase sedimentation time (10)%B.compactSample(2);%input is compaction time%------------return and save result--------------d.status.dispEnergy();%display the energy of the modeld.show('-aR');d.mo.bFilter(:)=1;d.mo.zeroBalance();d.Rrate=1;d.mo.setGPU('off');d.clearData(1);%clear dependent datad.recordCalHour('Step1Finish');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('-Id');
%set the material of the modelclearload('TempModel/PorePermeability1.mat');B.setUIoutput();%set output of messaged=B.d;d.calculateData();d.mo.setGPU('off');d.getModel();%get xyz from d.mo%----------set material of modelmatTxt=load('Mats\RockHydro.txt');Mats{1,1}=material('RockHydro',matTxt,B.ballR);Mats{1,1}.Id=1;d.Mats=Mats;%----------end set material of model%---------assign material to layers and balance the modelB.setPlatenFixId();d.setGroupMat('sample','RockHydro');d.groupMat2Model({'sample'});d.balanceBondedModel0();d.mo.bFilter(:)=false;d.balance('Standard',1);%---------end assign material to layers and balance the model1. %---------save the datad.mo.setGPU('off');d.clearData(1);d.recordCalHour('Step2Finish');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();
%test the permeability of sample%in this example, there are two material with different permeabilityclearfs.randSeed(2);load('TempModel/PorePermeability2.mat');sampleH=0.04;%height of sample is 4 cmdH=1;%water head is 1m%---------define permeabilitykRate=0.5;%change the kRate to change permeabilityk=2e-10*kRate;%permeability factorlowKRate=0.1;%percentage of low permeability elementstotalBalance=100000;%increase the value when highK:lowK increase%---------end define permeability%-----------initializing the modelB.setUIoutput();d=B.d;d.calculateData();d.mo.setGPU('off');d.getModel();%get xyz from d.mod.showB=2;d.deleteConnection('boundary');d.Rrate=1;d.resetStatus();d.getModel();d.mo.isCrack=1;%-----------end initializing the model%------------remove top and bottom elements of samplesampleHcenter=mean(d.mo.aZ(d.GROUP.sample));topModelFilter=d.mo.aZ>sampleHcenter+sampleH/2;botModelFilter=d.mo.aZ<sampleHcenter-sampleH/2;delId=find(topModelFilter|botModelFilter);maxS=max(d.GROUP.sample);delId=delId(delId<=maxS);d.delElement(delId);%------------end remove top and bottom elements of sample%------------initilizing pore systemp=pore(d);p.pathLimitRate=0.3;%path diameter<pathLimitRate*ballR will be connectionp.isCouple=1;%fluid-solid couplingp.setInitialPores();p.setPlaten('fix');%fix the coordinates of platensp.aWaterdR=d.mo.aR*0.025;%defind the water diameterp.setWaterdR();sLength=length(d.GROUP.sample);lowKId=randperm(sLength,round(sLength*lowKRate));p.aWaterdR(lowKId)=p.aWaterdR(lowKId)*0.1;p.setWaterdR();d.mo.SET.aWaterdR=p.aWaterdR;%d.show('SETaWaterdR');%return%-----------------end set cracks in the model%--------------setting of the simulationp.dT=p.d.mo.dT/kRate;fName=['data/step/'B.namenum2str(B.ballR)'-lowKRate'num2str(lowKRate)'loopNum'];topBallId=ceil(mean(d.GROUP.topPlaten));botBallId=ceil(mean(d.GROUP.botPlaten));pressureHigh=p.pPressure(2)+1e3*9.8*dH;pressureLow=p.pPressure(2);topPoreId=p.getBallConnectedPore(topBallId);botPoreId=p.getBallConnectedPore(botBallId);p.pPressure(topPoreId)=pressureHigh;p.pPressure(botPoreId)=pressureLow;p.setPressure();%set pore pressure of seawaterp.isCouple=0;%no fluid flow coupling%--------------end setting of the simulationsave([fName'0.mat']);%return;%-----------apply high pressurecDiameterFlow=p.cDiameter+p.cDiameterAdd;%calculate the diameter ofcDiameterFlow(cDiameterFlow<0)=0;p.cKFlow=cDiameterFlow*k./p.cPathLength;%default K of throat is determined by diameter and path lengthpIndex=p.getPIndex();topPIndex=pIndex(topPoreId,:);botPIndex=pIndex(botPoreId,:);balanceRates=[];%-------------balancing the pore pressurefori=1:totalBalancep.pPressure(topPoreId)=pressureHigh;p.pPressure(botPoreId)=pressureLow;p.setPressure();%set pore pressure of seawaterp.balance();%rate defines the balance timetoppMass=p.poreFlowMass{topPIndex(1)};botpMass=p.poreFlowMass{botPIndex(1)};ifmod(i,1000)==0fs.disp(['Calculating 'num2str(i/1000)'/'num2str(totalBalance/1000)]);balanceRate=-sum(botpMass,2)/sum(toppMass,2);balanceRates=[balanceRates;balanceRate];fs.disp(['Balance rate is 'num2str(balanceRate*100)' percent']);endend%-------------end balancing the pore pressurefs.disp('Balance of pore pressure is finished');fs.disp('Start the permeability test');stableT=p.totalT;massI=0;totalCircle=20;stepNum=500;topPoreMass=zeros(totalCircle*stepNum,1);botPoreMass=zeros(totalCircle*stepNum,1);fori=1:totalCircleforj=1:stepNump.pPressure(topPoreId)=pressureHigh;p.pPressure(botPoreId)=pressureLow;p.setPressure();%set pore pressure of seawaterp.balance();%rate defines the balance timemassI=massI+1;toppMass=p.poreFlowMass{topPIndex(1)};botpMass=p.poreFlowMass{botPIndex(1)};topPoreMass(massI)=sum(toppMass,2);botPoreMass(massI)=sum(botpMass,2);endfs.disp(['Calculating 'num2str(i)'/'num2str(totalCircle)]);%save([fName num2str(i) '.mat']);endtopMassAll=sum(topPoreMass);botMassAll=sum(botPoreMass);flowT=p.totalT-stableT;%k = Q*L /( A*△h)%---------calculate the hydraulic conductivity KQ=botMassAll/1e3/flowT;L=sampleH;A=B.sampleW*p.pThickness;K=Q*L/(A*dH);fs.disp(['Permeability coefficient of the sample is 'num2str(K)]);%---------end calculate the hydraulic conductivity Kp.show('pPressure');p.showData('poreFlowMass');save([fName'0.mat']);%return;