Closed qlangfitt closed 3 years ago
Here's the code I propose that seemed to fix it (all I did is replace F69 with F77 and E69 with E77):
'%%%%%%%%%%%%
'Set gas exports to zero, if applicable If ActiveField.Range("J104").Value = -1 Then 'When fraction of gas reinjection is set to -1 the gas reinjection fraction in the Active Field Working Sheet calculations is set to 0 (OPGEE default) ActiveField.Range("J104").Value = 0 Dim ImportAtZeroReinj As Boolean
' Check if gas must be exported even if no reinjection If EnergyConsumption.Range("F77") > 0 Then ImportAtZeroReinj = True Results.Range("G65").Offset(0, i).Value = ActiveField.Range("J104").Value Results.Range("G65").Offset(0, i) = ActiveField.Range("J104").Value Results.Range("G65").Offset(0, i).Interior.Color = RGB(234, 171, 0) Else ImportAtZeroReinj = False End If
If ImportAtZeroReinj = False Then
Do While EnergyConsumption.Range("E77") > 0
ActiveField.Range("J104").Value = ActiveField.Range("J104").Value + 0.005
Loop Results.Range("G65").Offset(0, i).Value = ActiveField.Range("J104").Value Results.Range("G65").Offset(0, i) = ActiveField.Range("J104").Value Results.Range("G65").Offset(0, i).Interior.Color = RGB(234, 171, 0) 'Changed
End If
End If
Time16 = Timer
'%%%%%%%%%%%%%%%%%%%%%%%
Implemented quinn's fix. I think the problem is arising if someone changes the energy consumption summary sheet then the code does not update. VBA does not auto-update when the sheets change. Argh!!!!
@arbrandt looks like you implemented my code exactly, but the energy summary sheet had changed further after my issue report. Need to fix again. Also, for future reference, the column letters seem very unlikely to change, but the row numbers should be the row of Table 3 listing the exports and imports of natural gas.
Also, this step is a significant amount of the total run time for fields that end up needing 100% or close to that NG reinjection (on my computer ~20 seconds out of a total field run time of ~24 seconds). The current increment is 0.5%. Could we double that increment to 1% to cut our run time in half? Seems like 1% is sensitive enough and probably the run time wasn't a factor in OPGEE 2.0.
Fixed. Row is now 85, so E77 becomes E85, and F77 becomes F75. Hopefully energy summary sheet stable now so no more fixes. Also did 1% increment change. The issue with a larger change is that you can overshoot and result in strange mass balance issues or (perhaps) imports. The latter is not an issue really because the amount will be small. Causing mass balance errors won't be good.
The switch to restrict exports when the fraction of natural gas reinjection is -1 is broken in OPGEE 3.0.
I think I have pieced together what it is supposed to do and my best understanding is:
The issue is when the macro checks if gas is being exported when NG reinjection fraction = 0 (step 2), the cell it points to is wrong (it points to E69, but should checking E85) . The same problem occurs in the Do While loop (step 3). This all starts at line 543 of the bulk assessment macro with the code as below.
'Set gas exports to zero, if applicable If ActiveField.Range("J104").Value = -1 Then 'When fraction of gas reinjection is set to -1 the gas reinjection fraction in the Active Field Working Sheet calculations is set to 0 (OPGEE default) ActiveField.Range("J104").Value = 0 Dim ImportAtZeroReinj As Boolean
' Check if gas must be exported even if no reinjection If EnergyConsumption.Range("F69") > 0 Then ImportAtZeroReinj = True Results.Range("G65").Offset(0, i).Value = ActiveField.Range("J104").Value Results.Range("G65").Offset(0, i) = ActiveField.Range("J104").Value Results.Range("G65").Offset(0, i).Interior.Color = RGB(234, 171, 0) Else ImportAtZeroReinj = False End If
If ImportAtZeroReinj = False Then
Do While EnergyConsumption.Range("E69") > 0
ActiveField.Range("J104").Value = ActiveField.Range("J104").Value + 0.005
Loop Results.Range("G65").Offset(0, i).Value = ActiveField.Range("J104").Value Results.Range("G65").Offset(0, i) = ActiveField.Range("J104").Value Results.Range("G65").Offset(0, i).Interior.Color = RGB(234, 171, 0) 'Changed
End If
End If
-