function out=simulate_mission(c,prop,p,work_s,dt) dur=[c.startup_s,c.spinup_s,c.takeoff_s,c.climb_s,c.transit_each_s,work_s,c.transit_each_s,c.reserve_hover_s,c.descent_s,c.landing_s]; names={'startup','spinup','takeoff','climb','outbound','work','return','reserve_hover','descent','landing'}; ends=cumsum(dur);edges=[0,ends]; H=c.H0_kg;SOC=c.SOC0;fc=0;time=0;Ebus=0;Efc=0;Edis=0;Echarge=0;Eloss=0;Eself=0;Hfc=0;Hvent=0; hasStorage=isfield(c,'storage');thermalOK=true;heatRecTotal=0;heaterTotal=0; if hasStorage ts=r23.thermo_state(c.storage.T0_K,H/c.storage.V_m3,c.storage.fluid); tank=struct('m',H,'U',H*ts.u_J_kg,'U0',H*ts.u_J_kg,'s',ts,'Qin_J',0,'out_enthalpy_J',0,'balance_J',0); end motorTimer=0;battTimer=0;N=ceil(sum(dur)/dt)+15;rows=nan(N,28);n=0;reason='completed';powerOK=true;socOK=true;fuelOK=true;mapOK=true; q=p;q.aux_power=0; for seg=1:10 if dur(seg)<=0,continue;end while time0&&any(seg==[5 6 7])&&SOC4*c.continuous_motor_each_W+1e-8); battTimer=(battTimer+step)*(Pd>c.battery_current_check_V*c.battery_cont_current_A+1e-8); if Pprop>4*c.peak_motor_each_W+1e-8||motorTimer>c.motor_peak_duration_s+1e-6||Pd>c.battery_current_check_V*c.battery_peak_current_A+1e-8||battTimer>c.battery_peak_duration_s+1e-6 powerOK=false; end if SOCnextc.SOCmax+1e-8,socOK=false;end if Hnext1,reason='hard_energy_state_limit';break;end end if ~mapOK||H<=0||SOC<0||SOC>1,break;end end rows=rows(1:n,:); columns={'time_s','aircraft_mass_kg','H2_kg','SOC','bus_load_W','FC_bus_W','battery_bus_signed_W','propulsion_DC_W','charger_input_W', ... 'segment','airspeed_m_s','climb_m_s','rpm','CT','advance_ratio','tip_speed_m_s','load_energy_Wh','FC_energy_Wh','battery_storage_used_Wh','battery_path_loss_Wh','motor_over_cont_s','battery_over_cont_s'}; columns=[columns,{'tank_T_K','tank_P_Pa','tank_U_J','vent_extra_kg_s','heat_recovery_W','heater_battery_W'}]; series=array2table(rows,'VariableNames',columns); completed=abs(time-sum(dur))<1e-6&&mapOK; if ~powerOK,reason='power_or_continuous_duration_constraint';end if ~socOK,reason='SOC_constraint';end if ~fuelOK,reason='H2_reserve_constraint';end if ~thermalOK,reason='storage_pressure_or_heat_supply_constraint';end if completed&&powerOK&&socOK&&fuelOK&&thermalOK,reason='completed_with_reserves';end out=struct('design_id',c.design_id,'work_s',work_s,'dt_s',dt,'completed_profile',completed, ... 'feasible',completed&&powerOK&&socOK&&fuelOK&&thermalOK,'reason',reason,'power_constraints_pass',powerOK,'SOC_constraints_pass',socOK,'H2_reserve_pass',fuelOK,'thermal_supply_pass',thermalOK, ... 'total_profile_s',time,'flight_s',max(time-c.startup_s-c.spinup_s,0),'H2_final_kg',H,'H2_FC_used_kg',Hfc,'H2_vented_kg',Hvent, ... 'SOC_final',SOC,'SOC_min',min([c.SOC0;series.SOC;SOC]),'SOC_max',max([c.SOC0;series.SOC;SOC]), ... 'FC_energy_Wh',Efc/3600,'load_energy_Wh',Ebus/3600,'battery_storage_delta_Wh',(Echarge-Edis)/3600, ... 'battery_loss_Wh',Eloss/3600,'battery_side_electronics_and_heater_Wh',Eself/3600,'energy_balance_residual_J',Efc+Edis-Echarge-Ebus-Eloss-Eself, ... 'H2_balance_residual_kg',c.H0_kg-H-Hfc-Hvent, ... 'SOC_energy_balance_residual_Wh',(SOC-c.SOC0)*c.battery_energy_Wh-(Echarge-Edis)/3600, ... 'final_mass_kg',c.M0_kg-(c.H0_kg-H)*(1-9*c.water_retained_fraction),'segment_names',{names},'series',series, ... 'maximum_motor_each_W',max(series.propulsion_DC_W)/4,'maximum_FC_W',max(series.FC_bus_W), ... 'maximum_battery_discharge_W',max(series.battery_bus_signed_W),'minimum_battery_signed_W',min(series.battery_bus_signed_W)); out.heat_recovery_Wh=heatRecTotal/3600;out.electric_tank_heater_Wh=heaterTotal/3600; out.tank_energy_balance_J=NaN;if hasStorage,out.tank_energy_balance_J=tank.balance_J;end end