function T=export_parameters(paths,p,fit) % Complete input/coefficients register. Computed trajectories remain in run CSVs. rows=cell(0,7); for q=p.registry add(['BASE.' q.symbol],num2str(q.value,17),q.unit,q.identity,q.source_id,q.locator,q.equations_used); end H=readtable(fullfile(paths.inputs,'he-parameters.csv'),'TextType','string','Encoding','UTF-8'); for i=find(startsWith(H.parameter_id,'HE-T2'))' add(char(H.parameter_id(i)),char(H.original_value(i)),char(H.unit(i)),'original_published_scenario','R23-L17',char(H.locator(i)),'originalHeEqs1-15'); end usedHe=["HE-X-01","HE-X-02","HE-X-03","HE-X-06","HE-X-07","HE-X-09","HE-X-12","HE-X-13","HE-X-14","HE-X-15","HE-X-16","HE-X-18","HE-X-19","HE-X-20","HE-X-22"]; for i=find(ismember(H.parameter_id,usedHe))' add(char(H.parameter_id(i)),char(H.original_value(i)),char(H.unit(i)),'original_published_function_literal_not_new_fit','R23-L17',char(H.locator(i)),'originalHeEqs10-15; rawliteratureunitsretained'); end for i=1:numel(fit.fc) f=fit.fc(i);for k={'a','b','c','envelope_intercept_shift','envelope_a','envelope_b'} key=k{1};unit='W/kg';if strcmp(key,'c'),unit='W';end add(['FIT.FC.' f.family '.' key],num2str(f.(key),17),unit,'MATLAB_nonlinfit_or_minimum_envelope_shift','R2-CAND-1.0.0',strjoin(f.sample_ids,','),'HeEq10currentdata'); end end for i=1:numel(fit.tank) f=fit.tank(i);for k={'a','b','envelope_a','envelope_b','energy_intercept_Wh','energy_slope_Wh_per_kg'} key=k{1};unit='kgH2';if any(strcmp(key,{'b','envelope_b'})),unit='kgH2/kgEmpty';end if contains(key,'intercept_Wh'),unit='Wh';elseif contains(key,'Wh_per_kg'),unit='Wh/kgEmpty';end add(['FIT.TANK.' f.family '.' key],num2str(f.(key),17),unit,'grouped_MATLAB_OLS_or_envelope','R2-CAND-1.0.0',strjoin(f.sample_ids,','),'HeEq11-12currentdata'); end end d=jsondecode(fileread(fullfile(paths.inputs,'r2-integration.json'))); as=d.engineering_assumptions;if ~iscell(as),as=num2cell(as);end for ai=1:numel(as) a=as{ai}; if isfield(a,'value'),add(a.parameter_id,num2str(a.value,17),a.unit,a.identity,d.version,'currentdesign-input.json engineering_assumptions; earlier unchanged values inherited','completeBOM/power');end end B=readtable(fullfile(paths.inputs,'r2-bom.csv'),'TextType','string','VariableNamingRule','preserve','Encoding','UTF-8'); for i=1:height(B) for field={'budget_unit_mass_kg','budget_mass_lower_kg','budget_mass_upper_kg','power_W_budget'} k=field{1};v=B.(k)(i);if isnumeric(v),textval=num2str(v,17);missing=~isfinite(v);else,textval=char(v);missing=ismissing(v)||strlength(v)==0;end if ~missing,unit='kg each';if contains(k,'power'),unit='W';end add(['BOM.' char(B.bom_id(i)) '.' k],textval,unit,char(B.budget_identity(i)),char(B.source_id(i)),char(B.model_or_engineering_spec(i)),char(B.activation_rule(i))); end end if ~ismissing(B.budget_mass_expression_si(i))&&strlength(B.budget_mass_expression_si(i))>0 add(['BOM.' char(B.bom_id(i)) '.mass_expression'],char(B.budget_mass_expression_si(i)),'kg each','declared_geometry/source_material_mass',char(B.source_id(i)),char(B.model_or_engineering_spec(i)),'quantity times expression; no unknown to zero'); end end branches=d.design_branches;if ~iscell(branches),branches=num2cell(branches);end for i=1:numel(branches),flatten(branches{i}.core_budget_overrides,['OVERRIDE.' branches{i}.design_branch_id],d.version,'currentBOMbranchoverrides; unchanged prior values inherited');end settings=dir(fullfile(paths.inputs,'*-mission-settings.json')); for i=1:numel(settings),v=jsondecode(fileread(fullfile(settings(i).folder,settings(i).name)));flatten(v,['MISSION.' v.design_id],['SIM-R3-001;' d.version],'explicitmission/EMSassumption; designSHA in settings');end for name={'Hydrogen','ParaHydrogen'} v=jsondecode(fileread(fullfile(paths.inputs,['eos-' name{1} '.json'])));e=v.EOS; for key={'alpha0','alphar','gas_constant','molar_mass','Ttriple','T_max','p_max'} flatten(e.(key{1}),['EOS.' name{1} '.' key{1}],'Leachman2009;CoolProp_pinned_SHA','Tables3-7;200itemindependentaudit'); end red=struct('T',e.STATES.reducing.T,'rhomolar',e.STATES.reducing.rhomolar,'p',e.STATES.reducing.p); flatten(red,['EOS.' name{1} '.reducing'],'Leachman2009','Table7;usedreducingconstants'); for key={'rhoL','rhoV'},flatten(v.ANCILLARIES.(key{1}),['EOS.' name{1} '.sat_initial_guess.' key{1}],'CoolProp_pinned_SHA','initialguessonly;EOSp/gequilibriumrefined');end end S=jsondecode(fileread(fullfile(paths.report,'storage-summary.json'))); for i=1:numel(S.cases),flatten(S.cases(i).vessel,['CRYO.' S.cases(i).route '.' S.cases(i).constraint_case],'L05;SIM-R3-001','research_vesselparameters/modeloutputs');end explicit={ 'CRYO.Vbay',.020,'m3';'CRYO.VinnerCap',S.common_max_inner_volume_m3,'m3';'CRYO.Vthreshold',S.threshold_map.V_inner_m3,'m3'; ... 'CRYO.external_interface_volume_budget',.002,'m3';'CG.body_outer_diameter',.200,'m';'CG.body_length',.536,'m'; ... 'CRYO.recovery_cap',50,'W';'CRYO.recovery_fraction',.05,'1'; ... 'CRYO.heater_limit',25,'W';'CRYO.heater_efficiency',.95,'1';'CRYO.extra_controller_load',5,'W'; ... 'L05.etaFC',.5197,'1';'L05.LHV',119.96e6,'J/kg';'L05.rho0',66.3,'kg/m3';'L05.P0',225400,'Pa'; ... 'L05.Pfeed',200000,'Pa';'L05.Qflux',9.15,'W/m2';'L05.inner_diameter',.2673,'m'; ... 'L05.baseline_V',.020,'m3';'L05.Case1_V',.0153,'m3';'L05.Case2_V',.019,'m3'; ... 'L05.baseline_Pmax',280000,'Pa';'L05.Case1_Pmax',3200000,'Pa';'L05.Case2_Pmax',5000000,'Pa'; ... 'L05.baseline_power',292,'W';'L05.Case2_power',315.6,'W'}; for i=1:size(explicit,1),add(explicit{i,1},num2str(explicit{i,2},17),explicit{i,3},'literature_or_explicit_research_scenario','L05;SIM-R3-001','l05_reconstruction/storage_analysis source comments','thermalcoupling');end T=cell2table(rows,'VariableNames',{'parameter_id','value_or_expression','unit','identity','source_id','source_locator_or_boundary','equations_or_use'}); assert(numel(unique(T.parameter_id))==height(T),'Every engineering parameter scope needs a unique ID.'); writetable(T,fullfile(paths.model,'all-engineering-parameters.csv'),'Encoding','UTF-8'); algorithm=struct('seed',23001,'CI_alpha',.05,'CI_scope','pointwise','NLS_multistarts',27,'mass_scan_points',1000,'speed_scan_points',101, ... 'joint_mass_points',180,'joint_speed_starts',25,'fit_band_points',180,'fminbnd_TolX',1e-8,'fminsearch_TolX',1e-8, ... 'NLS_TolX',1e-10,'NLS_TolFun',1e-12,'saturation_table_T_points',500,'saturation_equilibrium_tolerance',1e-11, ... 'temperature_root_TolX_K',1e-8,'vent_mass_bisection_iterations',28,'L05_dt_s',60,'task_dt_s',1,'convergence_dt_s',[2 1 .5 .25], ... 'cryo_dt_s',2,'cryo_gross_search_dt_s',4,'cryo_search_iterations',12,'realization','MATLABR2025a,nativebasefunctions,noPythonmath'); r23.write_json(fullfile(paths.model,'algorithm-settings.json'),algorithm); function add(id,val,unit,identity,source,locator,use) rows(end+1,:)={id,val,unit,identity,source,locator,use}; end function flatten(v,path,source,locator) if isnumeric(v) for j=1:numel(v),unit=guess_unit(path);add(sprintf('%s[%d]',path,j),num2str(v(j),17),unit,'published_constant/derived_coefficient_or_explicit_budget',source,locator,'seefullpathandmodelsource');end elseif iscell(v) for j=1:numel(v),flatten(v{j},sprintf('%s{%d}',path,j),source,locator);end elseif isstruct(v) for j=1:numel(v) scope=path;if numel(v)>1,scope=sprintf('%s{%d}',path,j);end fields=fieldnames(v(j));for kk=1:numel(fields),flatten(v(j).(fields{kk}),[scope '.' fields{kk}],source,locator);end end end end end function unit=guess_unit(path) % Unit resolution uses the leaf field only: parent mass_limited is not a unit. parts=strsplit(path,'.');leaf=regexprep(parts{end},'\[\d+\]$',''); unit='1 (reduced coefficient; see symbol path)'; if endsWith(leaf,'_kg'),unit='kg';end if endsWith(path,'_W')||endsWith(path,'cap_W'),unit='W';end if endsWith(path,'_Pa')||endsWith(path,'p_max')||endsWith(path,'.p'),unit='Pa';end if endsWith(path,'_m3'),unit='m3';end if endsWith(path,'_m'),unit='m';end if endsWith(leaf,'_mm'),unit='mm';end if endsWith(leaf,'_bar'),unit='bar';end if endsWith(leaf,'_L'),unit='L';end if endsWith(path,'_s'),unit='s';end if endsWith(leaf,'_m_s'),unit='m/s';end if endsWith(path,'_Wh'),unit='Wh';end if endsWith(path,'_V'),unit='V';end if endsWith(path,'_A')||endsWith(path,'_Ah'),unit='A or Ah as named';end if endsWith(path,'_A'),unit='A';end if endsWith(path,'_Ah'),unit='Ah';end if endsWith(path,'_W_s'),unit='W/s';end if endsWith(path,'_J_kg'),unit='J/kg';end if endsWith(path,'_ohm'),unit='ohm';end if endsWith(path,'_kg_m3'),unit='kg/m3';end if endsWith(leaf,'_m2'),unit='m2';end if endsWith(leaf,'_kg_m2'),unit='kg/m2';end if endsWith(path,'molar_mass'),unit='kg/mol';end if endsWith(path,'gas_constant'),unit='J/(mol K)';end if any(strcmp(leaf,{'v','T','Tcrit','T_r','Ttriple','T_max','Tmin','Tmax'}))||endsWith(leaf,'_K'),unit='K';end if endsWith(path,'rhomolar')||contains(path,'.rhoL.reducing_value')||contains(path,'.rhoV.reducing_value'),unit='mol/m3';end if strcmp(leaf,'max_abserror_percentage'),unit='%';end if any(strcmp(leaf,{'weld_efficiency','heater_efficiency','recovery_fraction'})),unit='1';end end