I was in a similar situation as you InquisitiveOne; I'm an Electrical/Systems Engineer who has undertaken design of an HCCI engine and has had to learn all this material just as you have.
Let me start my answering your question, "The ultimate reason behind my trying to figure this out is, engines make more horsepower with richer than stoichiometric conditions. For instance, gasoline makes peak torque/power at a ratio close to 12.5:1, when stoichiometrically all the oxygen is gone at 14.7:1. Why is that?"
I like addressing this point from the perspective of HCCI in which a pre-mixed fuel/air mixture is compressed to ignition. In this approach, it's easy to imagine that each molecule of fuel is surrounded by air sufficient to combust that molecule and the mixture compressed to yield the heat necessary to initiate the reaction. In this ideal state, the optimum air/fuel ratio would be stoichiometric. The air/fuel mixture is not, however, perfectly mixed; it has local rich and lean regions. The variance in mixture homogeneity is accommodated according to objective. If the objective is maximum power, then excess fuel is provided to ensure all the air is consumed. If the objective is maximum fuel efficiency, excess air is provided to ensure all fuel is consumed.
Moving on to calculations...
The calculation of atmospheric (ambient) conditions is described at
https://www.grc.nasa.gov/WWW/K-12/airplane/atmosmet.html
The fundamental calculations for Pressure (Pa), Volume (m3), and Temperature (K) are the isentropic functions given at
https://en.wikipedia.org/wiki/Isentropic_process#Table_of_isentropic_relations_for_an_ideal_gas
The critical specific heat ratio (y) varies with temperature and mixture composition. The paper "https://www.researchgate.net/publication/222535464_Temperature_and_air-fuel_ratio_dependent_specific_heat_ratio_functions_for_lean_burned_and_unburned_mixture" provides a pretty good summary of the variance in y depending on temperature and mixture composition. Below is a snapshot of the key section giving the equation for y when the mixture is unburned (yu) and burned (yb) where T is temperature (K) and λ is the air-fuel ratio. Note the equaton for pure air is available on-line.
Given all the above, you can create an Excel spreadsheet that starts with atmospheric conditions in the intake volume from which you can calculate mass via PV=mRT where P is in Pa, V is in m3, m (mass) is in kg, R is 286.98 and T is in K. Next, make a table of V values between initial and compression V noting that compression V/initial V is the compression ratio. If you wish, the compression V can also be calculated from a target pressure or temperature with good reason (more later).
A critical equation for calculating energy and work is Q=mCvΔT where Q is Joules, m is mass in kg, Cv is 286.98/(y-1) and ΔT is the change in temperature from one step to the next. This equation can be applied to each step in the table described in the prior paragraph to determine how much energy was added to the closed volume through compression. Conversely, it shows the amount of work done on the gas during compression. Since we're going to focus on work, we want negative values during compression, so subtract the higher temperature from the lower temperature when determining ΔT.
The Q=mCvΔT equation is also used to determine heat added by fuel during combustion. In this case, m (mass) is the kg of fuel added and Q is Joules-per-kg of the fuel according to it's Lower Heating Value (LHV) (43.4 MJ/kg for gasoline). From this, ΔT can be calculated then added to the temperature at the end of compression to find the temperature after combustion. See later notes on accuracy.
Once the combustion temperature is known, the isentropic relations and y can be used to calculate the associated rise in pressure. Using the now known Volume, Pressure, and Temperature, you can build a second table similar to the first that expands the gas. The work done during this phase is also calculated with the Q=mCvΔT equation but with positive (work output) results.
Once both tables are complete, you can calculate Work in Joules by summing the work columns from the Compression and Expansion tables. Using RPM and knowledge of your cycle (i.e. 4 vs 2 stroke), you can convert the sum to Joules per minute (J/min). Finally, you can convert J/min to HP using an on-line calculator.
Now about accuracy...
A key error source not described is friction. It can be estimated using the figure below that I compiled from two key sources, Ricardo and Heywood. The figures are for a 6 cylinder engine. To use this data, you'll have to calculate HP the way professionals do using IMEP, FMEP, and BMEP: IMEP (bar) = Work (J)/Displacement (m3), FMEP (bar) from the figure below, and BMEP (bar) = IMEP-BMEP. Once you have BMEP, the calculations at
http://www.epi-eng.com/piston_engine_technology/bmep_performance_yardstick.htm and a few unit conversions can be used to calculate HP and Torque (lb-ft).
The largest single error source in the model as described is heat loss which accounts for a very large part of efficiency losses. It can be approximated by assuming the cooling system holds the cylinder at around 400K (to prevent breakdown of the lubricating oil) then working through the equation at
https://www.engineeringtoolbox.com/convective-heat-transfer-d_430.html using one of the heat transfer coefficients given on page 147 - 149 of the document at
http://www.ni.com/pdf/manuals/NICASUM.pdf (the model being described here is so course, it really doesn't matter which one is selected). The larger issue in calculating heat loss (and another key loss, pumping loss) is the fact that it assumes knowledge of engine geometry (areas, piston speeds, etc.) which requires some pretty intense work to develop.
There is some small work done during exhaust and intake. These processes are not performed on a closed volume, so the calculation of work is different than that given (left as an exercise). Assuming properly sized valves that don't produce excess pumping loss, the primary reason for incorporating the intake and exhaust cycles is to capture their impact on heat transfer; in the prior discussion, for example, conditions at the start of compression were assumed to be ambient (typically 288K at sea level) but it's clear that contact with the 400K typical wall during intake will in fact warm the charge and affect the start condition of compression.
The method I described for calculating temperature after combustion is very coarse because it assumes all the heat of the fuel was released instantaneously. Only HCCI comes close to releasing the fuel heat so quickly (illustrated in the video below); Spark engines depend on comparatively slow flame propagation and diesel engines depend on the time required for spray injection and the kinetics of air and fuel mixing in that spray (to make matters worse, the use of crankshafts means the volume is changing during heat release, so the slower spark and diesel systems aren't actually operating using fixed volume combustion, and this impacts all the calculations). The heat release rate of the selected combustion technique combined with the ignition delay associated with octane factors heavily into timing as previously noted.
Some practical considerations...
In the Otto cycle, the peak compression temperature of the air/fuel mixture must be limited such that the bulk of heat release occurs after Top Dead Center. The timing of combustion is affected by ignition delay which is affected by octane in turn. Furthermore, the mechanical efficiency of the linear to rotary conversion system (typically a crankshaft) has some bearing on the timing of heat release. It's all quite complex.
In all cycles, peak combustion pressure must be held below around 220 bar or the lubricating oil in the cylinder and rings will auto-ignite. This phenomenon is a hot topic in design of modern turbo charged engines and, in this realm, it's called Low Speed Pre-Ignition (LSPI). You will find that this 220 bar limit sets the upper temperature limit of combustion. As a result, you will find that greater compression leaves less ΔT for generation by fuel, and this reduces power.
All modern engines use catalytic converters, and they require a minimum exhaust temperature around 533K. Ignoring heat loss, compression and expansion in an Otto cycle engine are inversely correlated, so at least 533K of heat must be added by fuel to meet this requirement.
I hope all this helps!
Rod