## 2 Materials and Methods
### System Components
#### 2.4.3 Biogas Generator (BG)  
A BG converts methane-rich gas from organic materials like agricultural waste, animal manure, or sewage into electricity. This process relies on the anaerobic digestion of biomass to generate biogas, combusted in an engine or turbine. The biomass conversion efficiency and operational parameters (e.g., methane yield, carbon-to-nitrogen ratio, hydraulic retention time) are based on established methodologies described extensively in previous research [19; 20; 46]. By harnessing waste products as fuel, BG helps reduce greenhouse gas emissions and provides a renewable energy source for both on-grid and off-grid applications. The electric power output \(P_{out}\) of a BG can be approximated by Equation (7). \[P_{out}=\eta_{gen}\times\dot{m}_{fuel}\times LHV_{Biogas} \tag{7}\]  
where \(\eta_{gen}\) is the electrical efficiency of the generator, \(\dot{m}_{fuel}\) is the mass flow rate of biogas (kg/h), and \(LHV_{Biogas}\) is the lower heating value of the biogas (kJ/kg). Equation (7) states that the generator's electric output is the product of the biogas energy input (flow rate \(\times\) heating value) times the generator's electrical efficiency. Like DG or natural gas genesis, HOMER often uses a simplified two-parameter fuel curve to account for variations in generator efficiency at partial load, as shown in Equation (8). \[\dot{V}_{fuel}(P_{out})=A\times P_{rated}+B\times P_{out} \tag{8}\]  
where \(\dot{V}_{fuel}(P_{out})\) is the volumetric flow of biogas at the current output (m\({}^{3}\)/h), \(P_{rated}\) is the rated (maximum) generator power (kW), \(P_{out}\) is the actual electrical output (kW), \(A\) is the intercept coefficient or the no-load fuel consumption coefficient (m\({}^{3}\)/kW.h), and \(B\) is the slope or incremental fuel consumption coefficient (m\({}^{3}\)/kW.h). In this model, \(A\times P_{rated}\) represents the baseline fuel consumption when the generator runs but produces little or no power (idle losses). In contrast, \(B\times P_{out}\) captures the additional fuel needed as output increases. Once HOMER calculates the required electrical output \(P_{out}\) at each time step, it determines the fuel flow \(V_{fuel}\) using the two-parameter model. Then, it converts volumetric flow to mass flow (if needed) using biogas density. Finally, it checks consistency with the energy equation to ensure \(P_{out}\leq\eta_{gen}\times\dot{m}_{fuel}\times LHV_{Biogas}\). Using these formulas and iterative simulations, HOMER helps users optimize BG size and operation schedule within an overall energy system. The BG used in this analysis is a generic genset with a reference capacity of 200 kW [19], designed to enhance system reliability and sustainability. It operates with a minimum load ratio of 40% and has a lifetime of 20,000 h, ensuring long-term durability. Fuel consumption follows a linear curve, with an intercept coefficient of 0.1 kg/h per kW rated capacity and a slope of 2.0 kg/h per kW output. The BG's efficiency is minimal at lower loads (near-zero output) because the engine must overcome internal losses and baseline fuel consumption. As the generator's electrical output rises, efficiency increases steadily, reflecting more effective fuel utilization under heavier loads. Near its rated capacity (around 200 kW), the generator reaches its peak efficiency--about 30-35%. This curve reflects the typical behavior of many engines, which achieve their highest efficiency when operating near their rated load. Emission levels are minimal, with 2 g of carbon monoxide and 1.25 g of nitrogen oxides per kg of fuel. At the same time, no unburned hydrocarbons or particulate matter are produced, highlighting its environmentally friendly operation. The generator operates on an optimized schedule. When solar irradiation is unavailable from 6 p.m. to 6 a.m., the generator must operate at its nominal capacity to meet criticalenergy demands.