public double AddDamagesUp(Damages Damages, int yearsToAggregate, Timestep emissionPeriod) { double i_totalDamage = 0.0; for (int year = emissionPeriod.Value; year < Math.Min(LegacyConstants.NYear, emissionPeriod.Value + yearsToAggregate); year++) { for (int region = 0; region < LegacyConstants.NoReg; region++) { for (int sector = 0; sector < LegacyConstants.NoSector; sector++) { i_totalDamage += Damages[year, region, (Sector)sector] * this[year, region]; } } } return(i_totalDamage); }
public static Damages CalculateMarginalDamage(Damages Damages1, Damages Damages2, double normalization) { Damages i_marginalDamages = new Damages(); for (int year = 0; year < LegacyConstants.NYear + 1; year++) { for (int region = 0; region < LegacyConstants.NoReg; region++) { for (int sector = 0; sector < LegacyConstants.NoSector; sector++) { i_marginalDamages._damages[year, region, sector] = (Damages2._damages[year, region, sector] - Damages1._damages[year, region, sector]) / normalization; } } } return(i_marginalDamages); }
public double[] DoOneRun(int RunId, WeightingCombination[] i_weightingCombinations, ParameterValues parameters) { ModelOutput i_output2; Damages i_marginalDamages; double i_aggregatedDamage; ModelOutput i_output1; // Create Output object for run 1, set addmp to 0 so that // the extra greenhouse gases are not emitted and then run // the model i_output1 = new ModelOutput(); var f1 = FundModel.GetModel(); f1["ImpactWaterResources"].Variables["water"].StoreOutput = true; f1["ImpactForests"].Variables["forests"].StoreOutput = true; f1["ImpactHeating"].Variables["heating"].StoreOutput = true; f1["ImpactCooling"].Variables["cooling"].StoreOutput = true; f1["ImpactAgriculture"].Variables["agcost"].StoreOutput = true; f1["ImpactSeaLevelRise"].Variables["drycost"].StoreOutput = true; f1["ImpactSeaLevelRise"].Variables["protcost"].StoreOutput = true; f1["ImpactSeaLevelRise"].Variables["entercost"].StoreOutput = true; f1["ImpactTropicalStorms"].Variables["hurrdam"].StoreOutput = true; f1["ImpactExtratropicalStorms"].Variables["extratropicalstormsdam"].StoreOutput = true; f1["ImpactBioDiversity"].Variables["species"].StoreOutput = true; f1["ImpactDeathMorbidity"].Variables["deadcost"].StoreOutput = true; f1["ImpactDeathMorbidity"].Variables["morbcost"].StoreOutput = true; f1["ImpactSeaLevelRise"].Variables["wetcost"].StoreOutput = true; f1["ImpactSeaLevelRise"].Variables["leavecost"].StoreOutput = true; f1["SocioEconomic"].Variables["income"].StoreOutput = true; f1["Population"].Variables["population"].StoreOutput = true; if (AdditionalInitCode != null) { AdditionalInitCode(f1); } var result1 = f1.Run(parameters); i_output1.Load(result1); // Create Output object for run 2, set addmp to 1 so that // the extra greenhouse gases for the marginal run are // emitted and then run the model i_output2 = new ModelOutput(); var f2 = FundModel.GetModel(); f2["ImpactWaterResources"].Variables["water"].StoreOutput = true; f2["ImpactForests"].Variables["forests"].StoreOutput = true; f2["ImpactHeating"].Variables["heating"].StoreOutput = true; f2["ImpactCooling"].Variables["cooling"].StoreOutput = true; f2["ImpactAgriculture"].Variables["agcost"].StoreOutput = true; f2["ImpactSeaLevelRise"].Variables["drycost"].StoreOutput = true; f2["ImpactSeaLevelRise"].Variables["protcost"].StoreOutput = true; f2["ImpactSeaLevelRise"].Variables["entercost"].StoreOutput = true; f2["ImpactTropicalStorms"].Variables["hurrdam"].StoreOutput = true; f2["ImpactExtratropicalStorms"].Variables["extratropicalstormsdam"].StoreOutput = true; f2["ImpactBioDiversity"].Variables["species"].StoreOutput = true; f2["ImpactDeathMorbidity"].Variables["deadcost"].StoreOutput = true; f2["ImpactDeathMorbidity"].Variables["morbcost"].StoreOutput = true; f2["ImpactSeaLevelRise"].Variables["wetcost"].StoreOutput = true; f2["ImpactSeaLevelRise"].Variables["leavecost"].StoreOutput = true; f2["SocioEconomic"].Variables["income"].StoreOutput = true; f2["Population"].Variables["population"].StoreOutput = true; if (AdditionalInitCode != null) { AdditionalInitCode(f2); } f2.AddComponent("marginalemission", typeof(Fund.Components.MarginalEmissionComponent), "emissions"); f2["marginalemission"].Parameters["emissionperiod"].SetValue(_emissionyear); switch (_gas) { case MarginalGas.C: f2["marginalemission"].Parameters["emission"].Bind("emissions", "mco2"); f2["climateco2cycle"].Parameters["mco2"].Bind("marginalemission", "modemission"); break; case MarginalGas.CH4: f2["marginalemission"].Parameters["emission"].Bind("emissions", "globch4"); f2["climatech4cycle"].Parameters["globch4"].Bind("marginalemission", "modemission"); break; case MarginalGas.N2O: f2["marginalemission"].Parameters["emission"].Bind("emissions", "globn2o"); f2["climaten2ocycle"].Parameters["globn2o"].Bind("marginalemission", "modemission"); break; case MarginalGas.SF6: f2["marginalemission"].Parameters["emission"].Bind("emissions", "globsf6"); f2["climatesf6cycle"].Parameters["globsf6"].Bind("marginalemission", "modemission"); break; default: throw new NotImplementedException(); } var result2 = f2.Run(parameters); i_output2.Load(result2); Fund28LegacyWeightingCombinations.GetWeightingCombinationsFromName(this.WeightingCombination, out i_weightingCombinations, _emissionyear); // Take out growth effect effect of run 2 by transforming // the damage from run 2 into % of GDP of run 2, and then // multiplying that with GDP of run 1 for (int year = 1; year < LegacyConstants.NYear; year++) { for (int region = 0; region < LegacyConstants.NoReg; region++) { for (int sector = 0; sector < LegacyConstants.NoSector; sector++) { i_output2.Damages[year, region, (Sector)sector] = (i_output2.Damages[year, region, (Sector)sector] / i_output2.Incomes[year, region]) * i_output1.Incomes[year, region]; } } } // Calculate the marginal damage between run 1 and 2 for each // year/region/sector i_marginalDamages = Damages.CalculateMarginalDamage(i_output1.Damages, i_output2.Damages); double[] i_weightedAggregatedDamages = new double[i_weightingCombinations.Length]; for (int i = 0; i < i_weightingCombinations.Length; i++) { i_weightingCombinations[i].CalculateWeights(i_output1); i_aggregatedDamage = i_weightingCombinations[i].AddDamagesUp(i_marginalDamages, YearsToAggregate, _emissionyear); i_weightedAggregatedDamages[i] = i_aggregatedDamage; WriteAggregateDamage(RunId, i, i_aggregatedDamage, i_weightingCombinations); // Console.Write(i_weightingCombinations[i].Name + ": "); // Console.WriteLine(Convert.ToString(i_aggregatedDamage)); } if (m_YearRegionSectorWeightingSchemeCsv != null) { foreach (var i_Damage in i_marginalDamages) { if ((i_Damage.Year >= _emissionyear.Value) && (i_Damage.Year < _emissionyear.Value + this.YearsToAggregate)) { for (int k = 0; k < i_weightingCombinations.Length; k++) { WriteMarginalDamage(RunId, i_Damage, k, i_weightingCombinations[k][i_Damage.Year, i_Damage.Region], i_weightingCombinations); } } } } return(i_weightedAggregatedDamages); }
public double Start() { int yearsToRun = Math.Min(1049, EmissionYear.Value + YearsToAggregate); var f1 = FundModel.GetModel(storeFullVariablesByDefault: false, years: yearsToRun); f1["impactwaterresources"].Variables["water"].StoreOutput = true; f1["ImpactForests"].Variables["forests"].StoreOutput = true; f1["ImpactHeating"].Variables["heating"].StoreOutput = true; f1["ImpactCooling"].Variables["cooling"].StoreOutput = true; f1["ImpactAgriculture"].Variables["agcost"].StoreOutput = true; f1["ImpactSeaLevelRise"].Variables["drycost"].StoreOutput = true; f1["ImpactSeaLevelRise"].Variables["protcost"].StoreOutput = true; f1["ImpactSeaLevelRise"].Variables["entercost"].StoreOutput = true; f1["ImpactTropicalStorms"].Variables["hurrdam"].StoreOutput = true; f1["ImpactExtratropicalStorms"].Variables["extratropicalstormsdam"].StoreOutput = true; f1["ImpactBioDiversity"].Variables["species"].StoreOutput = true; f1["ImpactDeathMorbidity"].Variables["deadcost"].StoreOutput = true; f1["ImpactDeathMorbidity"].Variables["morbcost"].StoreOutput = true; f1["ImpactSeaLevelRise"].Variables["wetcost"].StoreOutput = true; f1["ImpactSeaLevelRise"].Variables["leavecost"].StoreOutput = true; f1["socioeconomic"].Variables["income"].StoreOutput = true; f1["Population"].Variables["population"].StoreOutput = true; if (AdditionalInitMethod != null) { AdditionalInitMethod(f1); } var result1 = f1.Run(Parameters); var i_output1 = new ModelOutput(); i_output1.Load(result1, years: yearsToRun); var f2 = FundModel.GetModel(storeFullVariablesByDefault: false, years: yearsToRun); f2["impactwaterresources"].Variables["water"].StoreOutput = true; f2["ImpactForests"].Variables["forests"].StoreOutput = true; f2["ImpactHeating"].Variables["heating"].StoreOutput = true; f2["ImpactCooling"].Variables["cooling"].StoreOutput = true; f2["ImpactAgriculture"].Variables["agcost"].StoreOutput = true; f2["ImpactSeaLevelRise"].Variables["drycost"].StoreOutput = true; f2["ImpactSeaLevelRise"].Variables["protcost"].StoreOutput = true; f2["ImpactSeaLevelRise"].Variables["entercost"].StoreOutput = true; f2["ImpactTropicalStorms"].Variables["hurrdam"].StoreOutput = true; f2["ImpactExtratropicalStorms"].Variables["extratropicalstormsdam"].StoreOutput = true; f2["ImpactBioDiversity"].Variables["species"].StoreOutput = true; f2["ImpactDeathMorbidity"].Variables["deadcost"].StoreOutput = true; f2["ImpactDeathMorbidity"].Variables["morbcost"].StoreOutput = true; f2["ImpactSeaLevelRise"].Variables["wetcost"].StoreOutput = true; f2["ImpactSeaLevelRise"].Variables["leavecost"].StoreOutput = true; f2["socioeconomic"].Variables["income"].StoreOutput = true; f2["Population"].Variables["population"].StoreOutput = true; if (AdditionalInitMethod != null) { AdditionalInitMethod(f2); } f2.AddComponent("marginalemission", typeof(Fund.Components.MarginalEmissionComponent), "emissions"); f2["marginalemission"].Parameters["emissionperiod"].SetValue(EmissionYear); switch (Gas) { case MarginalGas.C: f2["marginalemission"].Parameters["emission"].Bind("emissions", "mco2"); f2["climateco2cycle"].Parameters["mco2"].Bind("marginalemission", "modemission"); break; case MarginalGas.CH4: f2["marginalemission"].Parameters["emission"].Bind("emissions", "globch4"); f2["climatech4cycle"].Parameters["globch4"].Bind("marginalemission", "modemission"); break; case MarginalGas.N2O: f2["marginalemission"].Parameters["emission"].Bind("emissions", "globn2o"); f2["climaten2ocycle"].Parameters["globn2o"].Bind("marginalemission", "modemission"); break; case MarginalGas.SF6: f2["marginalemission"].Parameters["emission"].Bind("emissions", "globsf6"); f2["climatesf6cycle"].Parameters["globsf6"].Bind("marginalemission", "modemission"); break; default: throw new NotImplementedException(); } var result2 = f2.Run(Parameters); var i_output2 = new ModelOutput(); i_output2.Load(result2, years: yearsToRun); // Take out growth effect effect of run 2 by transforming // the damage from run 2 into % of GDP of run 2, and then // multiplying that with GDP of run 1 for (int year = 1; year < LegacyConstants.NYear; year++) { for (int region = 0; region < LegacyConstants.NoReg; region++) { for (int sector = 0; sector < LegacyConstants.NoSector; sector++) { i_output2.Damages[year, region, (Sector)sector] = (i_output2.Damages[year, region, (Sector)sector] / i_output2.Incomes[year, region]) * i_output1.Incomes[year, region]; } } } // Calculate the marginal damage between run 1 and 2 for each // year/region/sector var i_marginalDamages = Damages.CalculateMarginalDamage(i_output1.Damages, i_output2.Damages); var weightingcom = new WeightingCombination(); if (UseEquityWeights) { weightingcom.Add(new ConstantDiscountrate(Prtp, EmissionYear.Value)); weightingcom.Add(new EquityWeighting(EmissionYear.Value, -1, Eta)); } else { weightingcom.Add(new RamseyRegionalDiscounting(Prtp, Eta, EmissionYear.Value)); } weightingcom.CalculateWeights(i_output1); var i_aggregatedDamage = weightingcom.AddDamagesUp(i_marginalDamages, YearsToAggregate, EmissionYear); return(i_aggregatedDamage); }