Class SimulationState
State management object for storage and retrieval of substance data, stream values, and associated parameterizations.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSimulationState(OverridingConverterStateGetter stateGetter, UnitConverter unitConverter) Create a new SimulationState instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaccumulateRecharge(UseKey useKey, EngineNumber population, EngineNumber intensity) Accumulate recharge parameters.voidclearLastSpecifiedValue(UseKey useKey, String stream) Clear the last specified value in the parameterization for the given use key.voidensureSubstance(UseKey useKey) Ensure a substance exists for a key, creating it if needed.getAppliedRechargeAmount(UseKey useKey) Get the applied recharge amount for cumulative calculations.getAppliedRetirementAmount(UseKey useKey) Get the applied retirement amount for cumulative calculations.intGet the current year for this simulation state.getDistribution(UseKey useKey) Get a sales stream distribution for the given substance/application.getDistribution(UseKey useKey, boolean includeExports) Get a sales stream distribution for the given substance/application.getEnergyIntensity(UseKey useKey) Get the energy intensity for a key.getGhgIntensity(UseKey useKey) Get the greenhouse gas intensity for a key.booleangetHasReplacementThisStep(UseKey useKey) Get the replacement mode for retire commands this step.getInductionRate(UseKey useKey) Get the induction rate percentage for recycling for a key.getInductionRate(UseKey useKey, RecoverOperation.RecoveryStage stage) Get the induction rate percentage for recycling for a key with a specific stage.getInductionStream(UseKey useKey, RecoverOperation.RecoveryStage stage) Get the induction stream value for a specific recovery stage.getInductionStream(UseKey useKey, RecoverOperation.RecoveryStage stage, boolean priorYear) Get the induction stream value for a specific recovery stage.getInitialCharge(UseKey useKey, String substream) Get the initial charge for a key.getLastSpecifiedValue(UseKey useKey, String streamName) Get the last specified value for a stream.getRechargeBasePopulation(UseKey useKey) Get the recharge base population for cumulative calculations.getRechargeIntensity(UseKey useKey) Get the recharge intensity for a key.getRechargePopulation(UseKey useKey) Get the recharge population percentage for a key.getRecoveryRate(UseKey useKey) Get the recovery rate percentage for a key.getRecoveryRate(UseKey useKey, RecoverOperation.RecoveryStage stage) Get the recovery rate percentage for a key with a specific stage.Get all registered substance-application pairs.booleangetRetireCalculatedThisStep(UseKey useKey) Get whether retire has been calculated this step.getRetirementBasePopulation(UseKey useKey) Get the retirement base population for cumulative calculations.getRetirementRate(UseKey useKey) Get the retirement rate percentage for a key.Get the value of a specific stream using key.Get the value of a specific stream using key from this or prior year.getTotalInductionStream(UseKey useKey) Get total induction across all stages.getTotalInductionStream(UseKey useKey, boolean priorYear) Get total induction across all stages.getYieldRate(UseKey useKey) Get the yield rate percentage for recycling for a key.getYieldRate(UseKey useKey, RecoverOperation.RecoveryStage stage) Get the yield rate percentage for recycling for a key with a specific stage.booleanhasLastSpecifiedValue(UseKey useKey, String streamName) Check if a stream has a last specified value.booleanhasStreamBeenEnabled(UseKey useKey, String streamName) Check if a stream has ever been enabled (set to non-zero value).booleanhasStreamsEnabled(UseKey useKey) Check if any sales streams have been enabled for the given substance/application.booleanhasSubstance(UseKey useKey) Check if a substance exists for a key.voidIncrement the year, updating populations and resetting internal params.booleanisKnownStream(UseKey useKey, String name) Check if a stream exists for a key.booleanisRecyclingCalculatedThisStep(UseKey useKey) Get whether recycling has been calculated this step.booleanisSalesIntentFreshlySet(UseKey useKey) Check if sales intent has been freshly set for the given scope.voidmarkStreamAsEnabled(UseKey useKey, String streamName) Mark a stream as having been enabled (set to non-zero value).voidresetSalesIntentFlag(UseKey useKey) Reset the sales intent flag for the given scope.voidsetAppliedRechargeAmount(UseKey useKey, EngineNumber value) Set the applied recharge amount for cumulative calculations.voidsetAppliedRetirementAmount(UseKey useKey, EngineNumber value) Set the applied retirement amount for cumulative calculations.voidsetCurrentYear(int year) Set the current year for this simulation state.voidsetEnergyIntensity(UseKey useKey, EngineNumber newValue) Set the energy intensity for a key.voidsetGhgIntensity(UseKey useKey, EngineNumber newValue) Set the greenhouse gas intensity for a key.voidsetHasReplacementThisStep(UseKey useKey, boolean value) Set the replacement mode for retire commands this step.voidsetInductionRate(UseKey useKey, EngineNumber newValue) Set the induction rate percentage for recycling for a key.voidsetInductionRate(UseKey useKey, EngineNumber newValue, RecoverOperation.RecoveryStage stage) Set the induction rate percentage for recycling for a key with a specific stage.voidsetInitialCharge(UseKey useKey, String substream, EngineNumber newValue) Set the initial charge for a key's stream.voidsetLastSpecifiedValue(UseKey useKey, String streamName, EngineNumber value) Tracks the last specified value for sales-related streams.voidsetRechargeBasePopulation(UseKey useKey, EngineNumber value) Set the recharge base population for cumulative calculations.voidsetRechargeIntensity(UseKey useKey, EngineNumber newValue) Set the recharge intensity for a key.voidsetRechargePopulation(UseKey useKey, EngineNumber newValue) Set the recharge population percentage for a key.voidsetRecoveryRate(UseKey useKey, EngineNumber newValue) Set the recovery rate percentage for a key.voidsetRecoveryRate(UseKey useKey, EngineNumber newValue, RecoverOperation.RecoveryStage stage) Set the recovery rate percentage for a key with a specific stage.voidsetRecyclingCalculatedThisStep(UseKey useKey, boolean calculated) Set whether recycling has been calculated this step.voidsetRetireCalculatedThisStep(UseKey useKey, boolean calculated) Set whether retire has been calculated this step.voidsetRetirementBasePopulation(UseKey useKey, EngineNumber value) Set the retirement base population for cumulative calculations.voidsetRetirementRate(UseKey useKey, EngineNumber newValue) Set the retirement rate percentage for a key.voidsetYieldRate(UseKey useKey, EngineNumber newValue) Set the yield rate percentage for recycling for a key.voidsetYieldRate(UseKey useKey, EngineNumber newValue, RecoverOperation.RecoveryStage stage) Set the yield rate percentage for recycling for a key with a specific stage.voidupdate(SimulationStateUpdate stateUpdate) Set a stream using pre-computed stream data.
-
Field Details
-
ZERO_VOLUME
-
-
Constructor Details
-
SimulationState
Create a new SimulationState instance.- Parameters:
stateGetter- Structure to retrieve state informationunitConverter- Converter for handling unit transformations
-
-
Method Details
-
getRegisteredSubstances
Get all registered substance-application pairs.- Returns:
- Array of substance identifiers
-
hasSubstance
Check if a substance exists for a key.- Parameters:
useKey- The key containing application and substance- Returns:
- true if the substance exists for the key
-
ensureSubstance
Ensure a substance exists for a key, creating it if needed.- Parameters:
useKey- The key containing application and substance
-
update
Set a stream using pre-computed stream data.This method replaces setStream, setOutcomeStream, and setSalesStream with a unified interface that accepts pre-computed stream values. The SimulationStateUpdate object encapsulates all necessary parameters including distribution logic and recycling behavior.
This method provides clear architectural separation between calculation instructions (StreamUpdate) and pre-computed results (SimulationStateUpdate).
- Parameters:
stateUpdate- Pre-computed stream data with all parameters
-
getStream
Get the value of a specific stream using key. Uses current year.- Parameters:
useKey- The key containing application and substancename- The stream name- Returns:
- The stream value
-
getStream
Get the value of a specific stream using key from this or prior year.- Parameters:
useKey- The key containing application and substancename- The stream namepriorYear- If true, returns prior year value if available, returns current year if no prior year exists.- Returns:
- The stream value
-
isKnownStream
Check if a stream exists for a key.- Parameters:
useKey- The key containing application and substancename- The stream name- Returns:
- true if the stream exists
-
getInductionStream
Get the induction stream value for a specific recovery stage. Uses current year.- Parameters:
useKey- The key containing application and substancestage- The recovery stage (EOL or RECHARGE)- Returns:
- The induction stream value in kg
-
getInductionStream
public EngineNumber getInductionStream(UseKey useKey, RecoverOperation.RecoveryStage stage, boolean priorYear) Get the induction stream value for a specific recovery stage.- Parameters:
useKey- The key containing application and substancestage- The recovery stage (EOL or RECHARGE)priorYear- If true, returns prior year value if available, returns current year if no prior year exists.- Returns:
- The induction stream value in kg
-
getTotalInductionStream
Get total induction across all stages. Uses current year.- Parameters:
useKey- The key containing application and substance- Returns:
- Total induction in kg
-
getTotalInductionStream
Get total induction across all stages.- Parameters:
useKey- The key containing application and substancepriorYear- If true, returns prior year value if available, returns current year if no prior year exists.- Returns:
- Total induction in kg
-
getDistribution
Get a sales stream distribution for the given substance/application.This method centralizes the logic for creating sales distributions by getting the current domestic and import values, determining their enabled status, and building an appropriate distribution using the builder pattern. Exports are excluded for backward compatibility.
- Parameters:
useKey- The key containing application and substance- Returns:
- A SalesStreamDistribution with appropriate percentages
-
getDistribution
Get a sales stream distribution for the given substance/application.This method centralizes the logic for creating sales distributions by getting the current domestic, import, and optionally export values, determining their enabled status, and building an appropriate distribution using the builder pattern.
- Parameters:
useKey- The key containing application and substanceincludeExports- Whether to include exports in the distribution calculation- Returns:
- A SalesStreamDistribution with appropriate percentages
-
hasStreamsEnabled
Check if any sales streams have been enabled for the given substance/application.- Parameters:
useKey- The key containing application and substance- Returns:
- True if any of domestic, import, or export streams are enabled
-
getCurrentYear
public int getCurrentYear()Get the current year for this simulation state.- Returns:
- The current year
-
setCurrentYear
public void setCurrentYear(int year) Set the current year for this simulation state.- Parameters:
year- The current year
-
incrementYear
public void incrementYear()Increment the year, updating populations and resetting internal params. -
setGhgIntensity
Set the greenhouse gas intensity for a key.- Parameters:
useKey- The key containing application and substancenewValue- The new GHG intensity value
-
setEnergyIntensity
Set the energy intensity for a key.- Parameters:
useKey- The key containing application and substancenewValue- The new energy intensity value
-
getGhgIntensity
Get the greenhouse gas intensity for a key.- Parameters:
useKey- The key containing application and substance- Returns:
- The GHG intensity value
-
getEnergyIntensity
Get the energy intensity for a key.- Parameters:
useKey- The key containing application and substance- Returns:
- The energy intensity value
-
setInitialCharge
Set the initial charge for a key's stream.- Parameters:
useKey- The key containing application and substancesubstream- The stream identifier ('domestic' or 'import')newValue- The new initial charge value
-
getInitialCharge
Get the initial charge for a key.- Parameters:
useKey- The key containing application and substancesubstream- The substream name- Returns:
- The initial charge value
-
setRechargePopulation
Set the recharge population percentage for a key.- Parameters:
useKey- The key containing application and substancenewValue- The new recharge population value
-
getRechargePopulation
Get the recharge population percentage for a key.- Parameters:
useKey- The key containing application and substance- Returns:
- The current recharge population value
-
setRechargeIntensity
Set the recharge intensity for a key.- Parameters:
useKey- The key containing application and substancenewValue- The new recharge intensity value
-
getRechargeIntensity
Get the recharge intensity for a key.- Parameters:
useKey- The key containing application and substance- Returns:
- The current recharge intensity value
-
accumulateRecharge
Accumulate recharge parameters. Sets when not previously set, accumulates otherwise.Multiple calls accumulate rates (addition) and intensities (weighted-average). Rates add linearly and intensities use weighted-average with absolute value weights to handle negative adjustments correctly.
- Parameters:
useKey- The key containing application and substancepopulation- The recharge population rate to addintensity- The recharge intensity for this rate
-
getRechargeBasePopulation
Get the recharge base population for cumulative calculations.- Parameters:
useKey- The key containing application and substance- Returns:
- The base population, or null if not yet captured this year
-
setRechargeBasePopulation
Set the recharge base population for cumulative calculations.- Parameters:
useKey- The key containing application and substancevalue- The base population value
-
getAppliedRechargeAmount
Get the applied recharge amount for cumulative calculations.- Parameters:
useKey- The key containing application and substance- Returns:
- The total amount already recharged this year in kg
-
setAppliedRechargeAmount
Set the applied recharge amount for cumulative calculations.- Parameters:
useKey- The key containing application and substancevalue- The total amount recharged this year in kg
-
isRecyclingCalculatedThisStep
Get whether recycling has been calculated this step.- Parameters:
useKey- The key containing application and substance- Returns:
- true if recycling was calculated, false otherwise
-
setRecyclingCalculatedThisStep
Set whether recycling has been calculated this step.- Parameters:
useKey- The key containing application and substancecalculated- true if recycling was calculated, false otherwise
-
setRecoveryRate
Set the recovery rate percentage for a key.If a recovery rate is already set, this method implements additive recycling:- Recovery rates are added together.
- Both rates are converted to percentage units before addition.
- The combined rate is stored as a percentage.
- Parameters:
useKey- The key containing application and substancenewValue- The new recovery rate value
-
setRecoveryRate
public void setRecoveryRate(UseKey useKey, EngineNumber newValue, RecoverOperation.RecoveryStage stage) Set the recovery rate percentage for a key with a specific stage.Implements additive behavior for multiple recovery commands on the same stage:- When a recovery rate is already set for this stage, the new rate is added to the existing one.
- The first recovery rate for a timestep is set directly without addition.
- Parameters:
useKey- The key containing application and substancenewValue- The new recovery rate valuestage- The recovery stage (EOL or RECHARGE)
-
getRecoveryRate
Get the recovery rate percentage for a key.- Parameters:
useKey- The key containing application and substance- Returns:
- The current recovery rate value
-
getRecoveryRate
Get the recovery rate percentage for a key with a specific stage.- Parameters:
useKey- The key containing application and substancestage- The recovery stage (EOL or RECHARGE)- Returns:
- The current recovery rate value
-
setYieldRate
Set the yield rate percentage for recycling for a key.Convenience method that sets the yield rate for the RECHARGE recovery stage. Delegates to
setYieldRate(UseKey, EngineNumber, RecoveryStage)with RecoveryStage.RECHARGE.- Parameters:
useKey- The key containing application and substancenewValue- The new yield rate value- See Also:
-
setYieldRate
public void setYieldRate(UseKey useKey, EngineNumber newValue, RecoverOperation.RecoveryStage stage) Set the yield rate percentage for recycling for a key with a specific stage.When an existing yield rate is set for this stage, combines them using a weighted average approach that uses equal weighting, which is a reasonable approximation for efficiency rates.
- Parameters:
useKey- The key containing application and substancenewValue- The new yield rate valuestage- The recovery stage (EOL or RECHARGE)
-
getYieldRate
Get the yield rate percentage for recycling for a key.- Parameters:
useKey- The key containing application and substance- Returns:
- The current yield rate value
-
getYieldRate
Get the yield rate percentage for recycling for a key with a specific stage.- Parameters:
useKey- The key containing application and substancestage- The recovery stage (EOL or RECHARGE)- Returns:
- The current yield rate value
-
setInductionRate
Set the induction rate percentage for recycling for a key.- Parameters:
useKey- The key containing application and substancenewValue- The new induction rate value
-
setInductionRate
public void setInductionRate(UseKey useKey, EngineNumber newValue, RecoverOperation.RecoveryStage stage) Set the induction rate percentage for recycling for a key with a specific stage.- Parameters:
useKey- The key containing application and substancenewValue- The new induction rate valuestage- The recovery stage (EOL or RECHARGE)
-
getInductionRate
Get the induction rate percentage for recycling for a key.- Parameters:
useKey- The key containing application and substance- Returns:
- The current induction rate value
-
getInductionRate
Get the induction rate percentage for recycling for a key with a specific stage.- Parameters:
useKey- The key containing application and substancestage- The recovery stage (EOL or RECHARGE)- Returns:
- The current induction rate value
-
setRetirementRate
Set the retirement rate percentage for a key.- Parameters:
useKey- The key containing application and substancenewValue- The new retirement rate value
-
getRetirementRate
Get the retirement rate percentage for a key.- Parameters:
useKey- The key containing application and substance- Returns:
- The current retirement rate value
-
getRetirementBasePopulation
Get the retirement base population for cumulative calculations.- Parameters:
useKey- The key containing application and substance- Returns:
- The base population, or null if not yet captured
-
setRetirementBasePopulation
Set the retirement base population for cumulative calculations.- Parameters:
useKey- The key containing application and substancevalue- The base population value
-
getAppliedRetirementAmount
Get the applied retirement amount for cumulative calculations.- Parameters:
useKey- The key containing application and substance- Returns:
- The total amount already retired this year
-
setAppliedRetirementAmount
Set the applied retirement amount for cumulative calculations.- Parameters:
useKey- The key containing application and substancevalue- The total amount retired this year
-
getHasReplacementThisStep
Get the replacement mode for retire commands this step.- Parameters:
useKey- The key containing application and substance- Returns:
- null if no retire yet, true if with replacement, false if without replacement
-
setHasReplacementThisStep
Set the replacement mode for retire commands this step.- Parameters:
useKey- The key containing application and substancevalue- true for with replacement, false for without replacement
-
getRetireCalculatedThisStep
Get whether retire has been calculated this step.- Parameters:
useKey- The key containing application and substance- Returns:
- true if retire was calculated, false otherwise
-
setRetireCalculatedThisStep
Set whether retire has been calculated this step.- Parameters:
useKey- The key containing application and substancecalculated- true if retire was calculated, false otherwise
-
setLastSpecifiedValue
Tracks the last specified value for sales-related streams.This method preserves user intent across carry-over years by storing the units and values that were explicitly specified by the user. This is essential for maintaining correct behavior when sales values carry over to subsequent years, particularly for unit-based specifications where recharge calculations need to be applied consistently.
- Parameters:
useKey- The key containing application and substancestreamName- The name of the stream (e.g., "sales", "domestic", "import")value- The value being specified with its units
-
getLastSpecifiedValue
Get the last specified value for a stream.- Parameters:
useKey- The key containing application and substancestreamName- The name of the stream- Returns:
- The last specified value with units, or null if not set
-
hasLastSpecifiedValue
Check if a stream has a last specified value.- Parameters:
useKey- The key containing application and substancestreamName- The name of the stream- Returns:
- true if the stream has a last specified value, false otherwise
-
isSalesIntentFreshlySet
Check if sales intent has been freshly set for the given scope.- Parameters:
useKey- The key containing application and substance- Returns:
- true if sales intent was freshly set, false otherwise
-
resetSalesIntentFlag
Reset the sales intent flag for the given scope.- Parameters:
useKey- The key containing application and substance
-
hasStreamBeenEnabled
Check if a stream has ever been enabled (set to non-zero value).- Parameters:
useKey- The key containing application and substancestreamName- The name of the stream to check- Returns:
- true if the stream has been enabled, false otherwise
-
markStreamAsEnabled
Mark a stream as having been enabled (set to non-zero value).- Parameters:
useKey- The key containing application and substancestreamName- The name of the stream to mark as enabled
-
clearLastSpecifiedValue
Clear the last specified value in the parameterization for the given use key.The last specified value tracks the user specified target for a stream such that commands changing those values respect user directives like maintaining units-based tracking with implicit recharge. This method clears that directive so that, for example, a set command can override a prior given value. This, for example, allows the user to switch from units-based to volume-based tracking.
- Parameters:
useKey- The substance / application pair in which to clear last specified value.stream- The name of the stream like "sales" or "import" in which to clear.
-