% MICROCRE teaching simulation: Synthetic indentation cycle % NOT EXECUTED IN MATLAB/Octave in the authoring environment. % Python/SciPy counterpart has been run; see validation-report.json. % Standalone MATLAB R2016b+ script (local functions); no extra toolbox required. % Edit p below, run this file, inspect outputs and assumptions before use. % Formula: P_load=k(h/1000)²;P_unload=P_max[(h−h_f)/(h_max−h_f)]ᵐ;W=∫P dh % Assumption: 准静态、单调加载/卸载,两段各401点。1 mN·nm=1 pJ。 % Assumption: 限制(1−残余比例)/(m+1)≤1/3以避免所设幂律产生负耗散。 % Limitation: 没有接触面积标定、黏塑性、裂纹或温度效应;不能反演真实硬度/模量。 % Limitation: 卸载幂律用于演示数据处理思路,不代表经过验证的本构模型。 % Source: https://web.mit.edu/cortiz/www/3.052/3.052CourseReader/45_OliverPharr1992Nanoindentation.pdf % This is not product performance, calibration, or compliance evidence. clear; close all; clc; p.peak_load = 10; % 峰值载荷 [mN] p.loading_k = 20; % 加载系数 k [mN/µm²] p.residual_fraction = 0.7; % 残余深度比例 [1] p.unload_exponent = 1.5; % 卸载指数 m [1] assert(isfinite(p.peak_load) && p.peak_load>=0.001 && p.peak_load<=1000, 'Invalid peak_load'); assert(isfinite(p.loading_k) && p.loading_k>=0.001 && p.loading_k<=1000000.0, 'Invalid loading_k'); assert(isfinite(p.residual_fraction) && p.residual_fraction>=0.05 && p.residual_fraction<=0.95, 'Invalid residual_fraction'); assert(isfinite(p.unload_exponent) && p.unload_exponent>=1 && p.unload_exponent<=3, 'Invalid unload_exponent'); hmax=1000*sqrt(p.peak_load/p.loading_k); hf=p.residual_fraction*hmax; m=p.unload_exponent; assert((1-p.residual_fraction)/(m+1)<=1/3,'Negative synthetic dissipation; revise inputs.'); u=linspace(0,1,401); hl=hmax*u; pl=p.peak_load*u.^2; hu=hf+(hmax-hf)*fliplr(u); pu=p.peak_load*fliplr(u).^m; lines=[s('Loading',hl,pl,'nm','mN'),s('Unloading',hu,pu,'nm','mN')]; win=trapz(hl,pl); wout=-trapz(hu,pu); out=struct('peak_depth',hmax,'residual_depth',hf,'unloading_stiffness',m*p.peak_load/(hmax-hf),'work_in',win,'work_recovered',wout,'work_dissipated',win-wout); outdir=fullfile(pwd,'indentation-cycle_results'); if ~exist(outdir,'dir'),mkdir(outdir);end fid=fopen(fullfile(outdir,'indentation-cycle.csv'),'w'); assert(fid>=0,'Cannot open CSV'); fprintf(fid,'series,x,y,x_unit,y_unit\n'); for j=1:numel(lines) for k=1:numel(lines(j).x) fprintf(fid,'"%s",%.17g,%.17g,"%s","%s"\n',lines(j).name,lines(j).x(k),lines(j).y(k),lines(j).xu,lines(j).yu); end end fclose(fid); fig=figure('Color','w');hold on; for j=1:numel(lines) if lines(j).plot,plot(lines(j).x,lines(j).y,'LineWidth',1.5,'DisplayName',lines(j).name);end end grid on;legend('show','Location','best');xlabel(lines(1).xu);ylabel(lines(1).yu); title('Synthetic indentation cycle','Interpreter','none'); print(fig,fullfile(outdir,'indentation-cycle.png'),'-dpng','-r160'); fid=fopen(fullfile(outdir,'indentation-cycle-summary.json'),'w');fprintf(fid,'%s',jsonencode(struct('inputs',p,'outputs',out,'notice','Teaching model; not product validation.')));fclose(fid); disp(out); function a=s(name,x,y,xu,yu) a=struct('name',name,'x',x,'y',y,'xu',xu,'yu',yu,'plot',true); end function q=qlinear(values,p) v=sort(values); pos=p*(numel(v)-1); k=floor(pos)+1; f=pos-floor(pos); if k==numel(v),q=v(k);else,q=v(k)*(1-f)+v(k+1)*f;end end