/// <summary> /// Computes the energy balance for the given organelles in biome /// </summary> public static EnergyBalanceInfo ComputeEnergyBalance(IEnumerable <OrganelleDefinition> organelles, BiomeConditions biome, MembraneType membrane) { var result = new EnergyBalanceInfo(); float processATPProduction = 0.0f; float processATPConsumption = 0.0f; float movementATPConsumption = 0.0f; int hexCount = 0; var enumerated = organelles.ToList(); // Compute all process efficiencies once var efficiencies = ComputeOrganelleProcessEfficiencies(enumerated, biome); foreach (var organelle in enumerated) { foreach (var efficiencyInfo in efficiencies) { foreach (var processData in efficiencyInfo.Value.Processes) { // Find process inputs and outputs that use/produce ATP // and that are performed by this organelle // and add to totals if (!organelle.Processes.ContainsKey(processData.Process.InternalName)) { continue; } if (processData.OtherInputs.ContainsKey(ATP)) { var amount = processData.OtherInputs[ATP].Amount; processATPConsumption += amount; result.AddConsumption(organelle.Name, amount); } if (processData.Outputs.ContainsKey(ATP)) { var amount = processData.Outputs[ATP].Amount; processATPProduction += amount; result.AddProduction(organelle.Name, amount); } } } // Take special cell components that take energy into account if (organelle.HasComponentFactory <MovementComponentFactory>()) { var amount = Constants.FLAGELLA_ENERGY_COST; movementATPConsumption += amount; result.Flagella += amount; result.AddConsumption(organelle.Name, amount); } // Store hex count hexCount += organelle.HexCount; } // Add movement consumption together result.BaseMovement = Constants.BASE_MOVEMENT_ATP_COST * hexCount; var totalMovementConsumption = movementATPConsumption + result.BaseMovement; // Add osmoregulation result.Osmoregulation = Constants.ATP_COST_FOR_OSMOREGULATION * hexCount * membrane.OsmoregulationFactor; result.AddConsumption("osmoregulation", result.Osmoregulation); // Compute totals result.TotalProduction = processATPProduction; result.TotalConsumptionStationary = processATPConsumption + result.Osmoregulation; result.TotalConsumption = result.TotalConsumptionStationary + totalMovementConsumption; result.FinalBalance = result.TotalProduction - result.TotalConsumption; result.FinalBalanceStationary = result.TotalProduction - result.TotalConsumptionStationary; return(result); }
/// <summary> /// Computes the energy balance for the given organelles in biome /// </summary> public static EnergyBalanceInfo ComputeEnergyBalance(IEnumerable <OrganelleDefinition> organelles, BiomeConditions biome, MembraneType membrane) { var result = new EnergyBalanceInfo(); float processATPProduction = 0.0f; float processATPConsumption = 0.0f; float movementATPConsumption = 0.0f; int hexCount = 0; var enumerated = organelles.ToList(); foreach (var organelle in enumerated) { foreach (var process in organelle.RunnableProcesses) { var processData = CalculateProcessMaximumSpeed(process, biome); if (processData.WritableInputs.ContainsKey(ATP)) { var amount = processData.WritableInputs[ATP]; processATPConsumption += amount; result.AddConsumption(organelle.InternalName, amount); } if (processData.WritableOutputs.ContainsKey(ATP)) { var amount = processData.WritableOutputs[ATP]; processATPProduction += amount; result.AddProduction(organelle.InternalName, amount); } } // Take special cell components that take energy into account if (organelle.HasComponentFactory <MovementComponentFactory>()) { var amount = Constants.FLAGELLA_ENERGY_COST; movementATPConsumption += amount; result.Flagella += amount; result.AddConsumption(organelle.InternalName, amount); } // Store hex count hexCount += organelle.HexCount; } // Add movement consumption together result.BaseMovement = Constants.BASE_MOVEMENT_ATP_COST * hexCount; result.AddConsumption("baseMovement", result.BaseMovement); var totalMovementConsumption = movementATPConsumption + result.BaseMovement; // Add osmoregulation result.Osmoregulation = Constants.ATP_COST_FOR_OSMOREGULATION * hexCount * membrane.OsmoregulationFactor; result.AddConsumption("osmoregulation", result.Osmoregulation); // Compute totals result.TotalProduction = processATPProduction; result.TotalConsumptionStationary = processATPConsumption + result.Osmoregulation; result.TotalConsumption = result.TotalConsumptionStationary + totalMovementConsumption; result.FinalBalance = result.TotalProduction - result.TotalConsumption; result.FinalBalanceStationary = result.TotalProduction - result.TotalConsumptionStationary; return(result); }
/// <summary> /// Computes the energy balance for the given organelles in biome /// </summary> public static EnergyBalanceInfo ComputeEnergyBalance( IEnumerable <OrganelleDefinition> organelles, Biome biome, MembraneType membrane) { var result = new EnergyBalanceInfo(); float totalATPProduction = 0.0f; float processATPConsumption = 0.0f; float movementATPConsumption = 0.0f; int hexCount = 0; var atp = SimulationParameters.Instance.GetCompound("atp"); foreach (var organelle in organelles) { foreach (var efficiencyInfo in ComputeOrganelleProcessEfficiencies(organelles, biome)) { foreach (var processData in efficiencyInfo.Value.Processes) { // Find process inputs and outputs that use/produce ATP and add to // totals if (processData.OtherInputs.ContainsKey(atp.InternalName)) { var amount = processData.OtherInputs[atp.InternalName].Amount; processATPConsumption += amount; result.AddConsumption(organelle.Name, amount); } if (processData.Outputs.ContainsKey(atp.InternalName)) { var amount = processData.Outputs[atp.InternalName].Amount; totalATPProduction += amount; result.AddProduction(organelle.Name, amount); } } } // Take special cell components that take energy into account if (organelle.HasComponentFactory <MovementComponentFactory>()) { var amount = Constants.FLAGELLA_ENERGY_COST; movementATPConsumption += amount; result.AddConsumption(organelle.Name, amount); } // Store hex count hexCount += organelle.HexCount; } // Add movement consumption together result.BaseMovement = Constants.BASE_MOVEMENT_ATP_COST * hexCount; var totalMovementConsumption = movementATPConsumption + result.BaseMovement; // Add osmoregulation result.Osmoregulation = Constants.ATP_COST_FOR_OSMOREGULATION * hexCount * membrane.OsmoregulationFactor; result.AddConsumption("osmoregulation", result.Osmoregulation); // Compute totals var totalATPConsumption = processATPConsumption + totalMovementConsumption + result.Osmoregulation; var totalBalanceStationary = totalATPProduction - totalATPConsumption; var totalBalance = totalBalanceStationary - totalMovementConsumption; // Finish building the result object result.TotalProduction = totalATPProduction; result.TotalConsumption = totalATPConsumption; result.FinalBalance = totalBalance; result.FinalBalanceStationary = totalBalanceStationary; return(result); }