diff --git a/src/CashFlows.py b/src/CashFlows.py index 098e7179b..b6c5755b5 100644 --- a/src/CashFlows.py +++ b/src/CashFlows.py @@ -1101,11 +1101,19 @@ def calculateCashflow(self, variables, lifetimeCashflows, lifetime, verbosity): ## FIXME what if I have set the values already? # get variable values, if needed need = {'alpha': self._alpha, 'driver': self._driver} + # load alpha, driver from variables if need be need = self.loadFromVariables(need, variables, lifetimeCashflows, lifetime) # for Capex, use m * alpha * (D/D')^X alpha = need['alpha'] driver = need['driver'] + # check if not-zero alpha > 1 + maskAlpha = np.where(alpha != 0.0, )[0] + if len(maskAlpha) > 1: + if len(np.where(driver != 0.0, )[0]) == 1: + val = driver[np.where(driver != 0.0, )] + driver[maskAlpha] = val + reference = self.getParam('reference') if reference is None: reference = 1.0 @@ -1342,7 +1350,7 @@ def extendParameters(self, toExtend, t): # how we treat the driver depends on if this is the amortizer or the depreciator if self._is_credit: if not mathUtils.isAString(driver): - toExtend['driver'] = np.ones(t) * driver[0] * -1.0 + toExtend['driver'] = np.ones(t) * np.sum(driver[np.where(driver != 0.0)]) * -1.0 toExtend['driver'][0] = 0.0 for name, value in toExtend.items(): if name.lower() in ['driver']: diff --git a/tests/CashFlow_test_NPV_delayed_construction.xml b/tests/CashFlow_test_NPV_delayed_construction.xml new file mode 100644 index 000000000..e80f583f9 --- /dev/null +++ b/tests/CashFlow_test_NPV_delayed_construction.xml @@ -0,0 +1,77 @@ + + + CashFlow_test_delayed_contruction_time + A. Alfonsi + 2023-10-10 + + This test tests the possibility to allow for CAPEX construction times spanning on multiple years (not only in the first one). + + + Models.ExternalModel.TEAL + + Addressed issue #17 + + + + + . + MCrun,printTOfile + + + + BOP_capacity, BOP_TOT_revenueEL, IP_capacity, IP_TOT_revenueBY, Multiplier + NPV + + + + + GRO_CashFlow_in, GRO_CashFlow_out + + + + + + + + 1 + + 300.0E6 + 350.0E6 + 51.0E6 + 31.5E6 + 1.0 + + + + + + GRO_CashFlow_in + OutputPlaceHolder + + + GRO_CashFlow_in + GRO_CashFlow_out + + + + + + SET_CashFlow_in + Cash_Flow + test_MC + SET_CashFlow_out + + + SET_CashFlow_out + dumpNPVDelay + + + + + + csv + SET_CashFlow_out + input,output + + + diff --git a/tests/Cash_Flow_input_NPV_delayed_construction.xml b/tests/Cash_Flow_input_NPV_delayed_construction.xml new file mode 100644 index 000000000..d03a79b5f --- /dev/null +++ b/tests/Cash_Flow_input_NPV_delayed_construction.xml @@ -0,0 +1,56 @@ + + + 0.05 + 0.392 + 0.04 + + BOP|CA + BOP|RE + IP|CA + IP|RE + + + + + 15 + + + + + BOP_capacity + -4510000000 -4510000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1100000000 + 0.64 + 5. 9.50 8.55 7.70 6.93 6.23 5.90 5.90 5.91 5.90 5.91 5.90 5.91 5.90 5.91 + + + + + + BOP_TOT_revenueEL + 1.0 + + + + + + 15 + + + + + -153000000 + IP_capacity + 231000000 + 1.0 + + + + + + IP_TOT_revenueBY + 1.0 + + + + diff --git a/tests/gold/dumpNPVDelay.csv b/tests/gold/dumpNPVDelay.csv new file mode 100644 index 000000000..2cc33b7df --- /dev/null +++ b/tests/gold/dumpNPVDelay.csv @@ -0,0 +1,2 @@ +BOP_capacity,BOP_TOT_revenueEL,IP_capacity,IP_TOT_revenueBY,Multiplier,NPV +300000000.0,350000000.0,51000000.0,31500000.0,1.0,-638217255.28 diff --git a/tests/tests b/tests/tests index c97470450..55f55e3a5 100644 --- a/tests/tests +++ b/tests/tests @@ -115,4 +115,12 @@ rel_err = 0.001 [../] + [./CashFlow_test_delayed_contruction_time] + type = 'RavenFramework' + input = 'CashFlow_test_NPV_delayed_construction.xml' + UnorderedCsv = 'dumpNPVDelay.csv' + max_time = 500 + rel_err = 0.001 + [../] + []