Class SingleThreadEngine
- All Implemented Interfaces:
Engine
At this time the only implementation of Engine which does not guarantee thread safety within a single scenario. However, note that Engine only evaluates one scenario at a time so Kigali Sim still achieves concurency by having multiple Engines and evaluating scenarios or Monte Carlo trials in parallel.
-
Constructor Summary
ConstructorsConstructorDescriptionSingleThreadEngine(int startYear, int endYear) Create a new SingleThreadEngine instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidcap(String stream, EngineNumber amount, YearMatcher yearMatcher, String displaceTarget, DisplacementType displacementType) Cap a stream at a maximum value.voidchangeStream(String stream, EngineNumber amount, YearMatcher yearMatcher) Change a stream value by a delta amount with default scope.voidchangeStream(String stream, EngineNumber amount, YearMatcher yearMatcher, UseKey useKey) Change a stream value by a delta amount.voiddefineVariable(String name) Create a user-defined variable in the current scope.voidenable(String name, Optional<YearMatcher> yearMatcher) Enable a stream without setting its value.voidequals(EngineNumber amount, YearMatcher yearMatcher) Set GHG equivalency (GWP - Global Warming Potential) for the current application and substance.voidexecuteStreamUpdate(StreamUpdate update) Execute a stream update operation using a StreamUpdate object.voidfloor(String stream, EngineNumber amount, YearMatcher yearMatcher, String displaceTarget, DisplacementType displacementType) Set a minimum floor value for a stream.intGet the ending year of the simulation.Retrieve the energy intensity for the current application and substance.getEqualsEnergyIntensityFor(UseKey useKey) Retrieve the energy intensity for the given UseKey.Retrieve the tCO2e intensity (GWP - Global Warming Potential) for the current application and substance.getEqualsGhgIntensityFor(UseKey useKey) Retrieve the tCO2e intensity (GWP - Global Warming Potential) for the given UseKey.getGhgIntensity(UseKey useKey) Get the GHG intensity (GWP - Global Warming Potential) associated with a substance.getInitialCharge(String stream) Get the initial charge value for a given stream.booleanDetermine if the engine has reached its final year.booleanGets whether recalc optimizations are enabled.getRawInitialChargeFor(UseKey useKey, String stream) Get the initial charge for a specific application and substance.Get the recharge intensity for the current application and substance.Get the recharge volume for the current application and substance.Get the results for all registered substances.Get the retirement rate for the current application and substance.Get the scenario name.getScope()Get the engine's current scope.intGet the starting year of the simulation.Get the state getter for converter operations.Get the stream value with default scope and no conversion.Get the stream value for a given application and substance key.getStreamFor(UseKey key, String stream) Get the stream value without any conversion.Get the simulation state for this engine.intGet the trial number.Get the unit converter for this engine.getVariable(String name) Get the value of a user-defined variable in the current scope.intgetYear()Get the year that the engine is currently simulating.voidIncrement the engine to simulate the next year.voidrecharge(EngineNumber volume, EngineNumber intensity, YearMatcher yearMatcher) Set recharge parameters for the current application and substance.voidrecycle(EngineNumber recoveryWithUnits, EngineNumber yieldWithUnits, YearMatcher yearMatcher, RecoverOperation.RecoveryStage stage) Set recycling parameters for the current application and substance.voidreplace(EngineNumber amountRaw, String stream, String destinationSubstance, YearMatcher yearMatcher) Replace an amount from one substance with another.voidReset the induction rate to default behavior for recycling operations.voidretire(EngineNumber amount, YearMatcher yearMatcher) Set retirement rate for the current application and substance.voidsetApplication(String newApplication) Set the application for the engine current scope.voidsetInductionRate(EngineNumber inductionRate, RecoverOperation.RecoveryStage stage) Set the induction rate for recycling operations.voidsetInitialCharge(EngineNumber value, String stream, YearMatcher yearMatcher) Set the initial charge for a stream.voidsetScenarioName(String scenarioName) Set the scenario name.voidSet the stanza for the engine current scope.voidsetStream(String name, EngineNumber value, Optional<YearMatcher> yearMatcher) Set a stream for explicit user operations (applies user-level processing like SetExecutor).voidsetSubstance(String newSubstance) Set the substance for the engine current scope with default validation behavior.voidsetSubstance(String newSubstance, boolean checkValid) Set the substance for the engine current scope.voidsetTrialNumber(int trialNumber) Set the trial number.voidsetVariable(String name, EngineNumber value) Set the value of a variable in the current scope.
-
Constructor Details
-
SingleThreadEngine
public SingleThreadEngine(int startYear, int endYear) Create a new SingleThreadEngine instance.- Parameters:
startYear- The starting year of the simulationendYear- The ending year of the simulation
-
-
Method Details
-
getStartYear
public int getStartYear()Description copied from interface:EngineGet the starting year of the simulation.Get the starting year of the simulation as defined in the simulation stanza or similar. Actual execution will start at this value and increment one timestep (year) at a time until end year such that commands outside this range will not run.
- Specified by:
getStartYearin interfaceEngine- Returns:
- The start year like 2025.
-
getEndYear
public int getEndYear()Description copied from interface:EngineGet the ending year of the simulation.Get the starting year of the simulation as defined in the simulation stanza or similar. Actual execution will end at this value, incrementing one timestep (year) at a time until end year such that commands outside this range will not run.
- Specified by:
getEndYearin interfaceEngine- Returns:
- The end year like 2050.
-
getScenarioName
Get the scenario name.- Specified by:
getScenarioNamein interfaceEngine- Returns:
- The name of the scenario being run
-
setScenarioName
Set the scenario name.- Specified by:
setScenarioNamein interfaceEngine- Parameters:
scenarioName- The name of the scenario being run
-
getTrialNumber
public int getTrialNumber()Get the trial number.- Specified by:
getTrialNumberin interfaceEngine- Returns:
- The trial number of the current run
-
setTrialNumber
public void setTrialNumber(int trialNumber) Set the trial number.- Specified by:
setTrialNumberin interfaceEngine- Parameters:
trialNumber- The trial number of the current run
-
setStanza
Description copied from interface:EngineSet the stanza for the engine current scope.Specify the stanza in which the engine is currently running and which can be used to describe the current variable scope. Note that this may be used in some error reporting and should match the input script or similar.
-
setApplication
Description copied from interface:EngineSet the application for the engine current scope.Specify the name of the application which is currently being evaluated as indicated in the input script or similar. Note that this may be used in some error reporting and should match the user specified name.
- Specified by:
setApplicationin interfaceEngine- Parameters:
newApplication- The new application name like commercial refrigeration.
-
setSubstance
Description copied from interface:EngineSet the substance for the engine current scope.Specify the substance that is currently being evaluated by the engine where a substance may appear in multiple applications. Note that this is used in some error reporting and should match the user specified name.
- Specified by:
setSubstancein interfaceEngine- Parameters:
newSubstance- The new substance name like HFC-134a.checkValid- True if an error should be thrown if the app/substance is not previously registered or false if it should be registered if not found. Defaults to false.
-
setSubstance
Description copied from interface:EngineSet the substance for the engine current scope with default validation behavior.Specify the substance that is currently being evaluated by the engine where a substance may appear in multiple applications. Note that this is used in some error reporting and should match the user specified name.
- Specified by:
setSubstancein interfaceEngine- Parameters:
newSubstance- The new substance name like HFC-134a.
-
getScope
Description copied from interface:EngineGet the engine's current scope.Get information about the current "location" in which the Engine is performing calculations. This specifically refers to the set of variables in scope where scope may indicate, for example, which application the Engine is evaluating in order to determine the correct initial charge to use.
-
getStateGetter
Description copied from interface:EngineGet the state getter for converter operations.QubecTalk numbers have both a numeric value and a type such as kilograms. Many values require conversion to alternative units like metric tonnes and some of those conversions such as from number of units of equipment to tCO2e require information about equipment like charge levels. This retrieves an instance which supports querying of information needed to perform conversions specific to equipment, substance, or stream.
- Specified by:
getStateGetterin interfaceEngine- Returns:
- ConverterStateGetter The state getter which can be used for state-dependent conversions.
-
getUnitConverter
Description copied from interface:EngineGet the unit converter for this engine.QubecTalk numbers have both a numeric value and a type such as kilograms. Many values require conversion to alternative units like metric tonnes. This retrieves an object which can be used with this Engine for those conversions.
- Specified by:
getUnitConverterin interfaceEngine- Returns:
- UnitConverter Facade which can perform unit conversions for operations with this Engine.
-
getStreamKeeper
Description copied from interface:EngineGet the simulation state for this engine.- Specified by:
getStreamKeeperin interfaceEngine- Returns:
- SimulationState Accounting object which describes the current state of this siulation across all applications and substances.
-
incrementYear
public void incrementYear()Description copied from interface:EngineIncrement the engine to simulate the next year.- Specified by:
incrementYearin interfaceEngine
-
getYear
public int getYear()Description copied from interface:EngineGet the year that the engine is currently simulating. -
getIsDone
public boolean getIsDone()Description copied from interface:EngineDetermine if the engine has reached its final year.The simulation goes through one timestep (year) at a time from start year to end year and is considered finished when reaching end year. This evaluates if that terminal state has been reached.
-
executeStreamUpdate
Description copied from interface:EngineExecute a stream update operation using a StreamUpdate object.- Specified by:
executeStreamUpdatein interfaceEngine- Parameters:
update- The StreamUpdate describing how to update a stream and which contains all parameters for the operation.
-
setStream
Description copied from interface:EngineSet a stream for explicit user operations (applies user-level processing like SetExecutor). -
enable
Description copied from interface:EngineEnable a stream without setting its value.This method marks a stream as enabled, allowing it to be included in distribution calculations for operations like recharge, retire, and recover without having to set an actual value to the stream.
-
getStream
Description copied from interface:EngineGet the stream value for a given application and substance key.Get the current value of a stream where a stream is a type of stock in the stock and flow model such as sales or equipment.
- Specified by:
getStreamin interfaceEngine- Parameters:
name- The name of the stream to retrieve like sales.useKey- The key containing application and substance information.conversion- The conversion specification for units (like mt), or empty for no conversion.- Returns:
- The value of the stream, possibly converted like to kg.
-
getStream
Description copied from interface:EngineGet the stream value with default scope and no conversion.Get the current value of a stream where a stream is a type of stock in the stock and flow model such as sales or equipment. This gets the value of the stream automatically converted to kilograms in the current Engine scope.
-
getStreamFor
Description copied from interface:EngineGet the stream value without any conversion.Get the current value of a stream where a stream is a type of stock in the stock and flow model such as sales or equipment.
- Specified by:
getStreamForin interfaceEngine- Parameters:
key- The application and substance name for which the stream should be returned.stream- The name of the stream to get like recycle.- Returns:
- The value of the given combination without conversion (as last saved).
-
defineVariable
Description copied from interface:EngineCreate a user-defined variable in the current scope.- Specified by:
defineVariablein interfaceEngine- Parameters:
name- The name of the variable to define
-
getVariable
Description copied from interface:EngineGet the value of a user-defined variable in the current scope.- Specified by:
getVariablein interfaceEngine- Parameters:
name- The name of the variable to retrieve- Returns:
- The value of the variable, or special values for 'yearsElapsed' and 'yearAbsolute' in years.
-
setVariable
Description copied from interface:EngineSet the value of a variable in the current scope.- Specified by:
setVariablein interfaceEngine- Parameters:
name- The name of the variable to setvalue- The value to assign to the variable
-
getInitialCharge
Description copied from interface:EngineGet the initial charge value for a given stream.Get the current initial charge in the current state for a given stream, typically a sales stream like sales, import, export, domestic. This is looked up in the current scope.
- Specified by:
getInitialChargein interfaceEngine- Parameters:
stream- The stream identifier to get the initial charge for like sales.- Returns:
- The initial charge value for the stream like in kg / unit.
-
getRawInitialChargeFor
Description copied from interface:EngineGet the initial charge for a specific application and substance.Get the current initial charge in the current state for a given stream, typically a sales stream like sales, import, export, domestic.
- Specified by:
getRawInitialChargeForin interfaceEngine- Parameters:
useKey- Application and substance for which initial charge is requestedstream- The stream in which the initial charge is requested and must be realized- Returns:
- The initial charge for the stream in the given application and substance like in kg / unit.
-
setInitialCharge
Description copied from interface:EngineSet the initial charge for a stream.Set the initial charge to use for a stream in the current scope. This is typically a sales stream like sales, import, export, domestic. This operation will only be applied if the year matcher passes, otherwise a no-op.
- Specified by:
setInitialChargein interfaceEngine- Parameters:
value- The initial charge value to set like 5 kg / unit.stream- The stream identifier to set the initial charge for like sales.yearMatcher- Matcher to determine if the change applies to current year. If not matching the current year, will be a no-op.
-
getRechargeVolume
Description copied from interface:EngineGet the recharge volume for the current application and substance.Get the servicing volume (across all recharge commands) within the current scope in the units last saved.
- Specified by:
getRechargeVolumein interfaceEngine- Returns:
- The recharge volume value like percent.
-
getRechargeIntensity
Description copied from interface:EngineGet the recharge intensity for the current application and substance.Get the servicing intensity (across all recharge commands) within the current scope in the units last saved.
- Specified by:
getRechargeIntensityin interfaceEngine- Returns:
- The recharge intensity value in kg per unit.
-
recharge
Description copied from interface:EngineSet recharge parameters for the current application and substance.Recharge represents the substance needed to service existing equipment due to leakage, maintenance, or repair. This method configures both the percentage of equipment requiring recharge (volume) and the amount of substance needed per unit (intensity).
Note that, when users specify sales in equipment units (e.g., "800 units"), they indicate how many new equipment units should be sold. This recharge method must calculate substance needed for exiting equipment and add it on top. For example, if a user specifies "set import to 800 units during year 2025" and provides no specification for 2026, the carry over mechanism will automatically continue 800 new units in 2026, while recalculating and adding the appropriate recharge volume based on the growing equipment population.
-
retire
Description copied from interface:EngineSet retirement rate for the current application and substance.Set the retirement (also called) scrap rate within the current scope. This is the hazard rate rate to use for retirement and can be specified in any units but are typically given in percentages (probability). Note that these may also be the result of a stateful formula like for users which have an age-dependent hazard for their survival analysis.
-
getRetirementRate
Description copied from interface:EngineGet the retirement rate for the current application and substance.Get the current hazard rate for equipment retirment (also called scrap in some communities).
- Specified by:
getRetirementRatein interfaceEngine- Returns:
- The retirement rate value like as percentage.
-
recycle
public void recycle(EngineNumber recoveryWithUnits, EngineNumber yieldWithUnits, YearMatcher yearMatcher, RecoverOperation.RecoveryStage stage) Description copied from interface:EngineSet recycling parameters for the current application and substance.Recycling allows for recovery of some amount of substance to be reused, potentially in place of virgin material. However, this is controlled through an induction (induced demand) parameter. Note that some may use recycling with 0% yield to model destruction in which substance is prevented from emitting but is not salvaged for reuse.
- Specified by:
recyclein interfaceEngine- Parameters:
recoveryWithUnits- The recovery rate, typically in percentage or probability.yieldWithUnits- The yield rate indicating how much recovered is actually reused.yearMatcher- Matcher to determine if the change applies to current year and, if not matching the current year, turns this into a no-op.stage- The recovery stage (EOL for end of life or RECHARGE for servicing) at which the substance is captured.
-
setInductionRate
Description copied from interface:EngineSet the induction rate for recycling operations.This parameter allows for modeling induced demand, an economic effect in which increased supply (in our case through recycling / secondary production) actually causes demand to also increase such that one kg of secondary material does not fully reduce or offset one kg of virgin production.
Induction rate determines how recycled material affects virgin production:- 100% induction (default): Recycled material does not displace virgin material, adding to total supply (induced demand behavior)
- 0% induction: Recycled material fully displaces virgin material, maintaining steady population (displacement behavior)
- Partial induction: Mixed behavior with proportional effects
- Specified by:
setInductionRatein interfaceEngine- Parameters:
inductionRate- The induction rate as an EngineNumber with percentage units, or null for default behavior (100% induced demand).stage- The recovery stage (EOL or RECHARGE) for which to set the induction rate.
-
resetInductionRate
Description copied from interface:EngineReset the induction rate to default behavior for recycling operations.This method sets the induction rate to 100%, which represents default induced demand behavior where recycled material adds to total supply rather than displacing virgin material. This is the recommended setting when users are uncertain about induction effects.
Induction rate determines how recycled material affects virgin production:- 100% induction (default): Recycled material does not displace virgin material, adding to total supply (induced demand behavior)
- 0% induction: Recycled material fully displaces virgin material, maintaining steady population (displacement behavior)
- Partial induction: Mixed behavior with proportional effects
- Specified by:
resetInductionRatein interfaceEngine- Parameters:
stage- The recovery stage (EOL or RECHARGE) to reset the induction rate for
-
equals
Description copied from interface:EngineSet GHG equivalency (GWP - Global Warming Potential) for the current application and substance.Set GHG equivalency (GWP - Global Warming Potential) for the current application and substance as defined by the current scope. Will only execute if the year matcher matches the current year. Otherwise, this is a no-op.
Note that this is intended only for direct emissions though useres may calculate indirect or secondary emissions through energy mix outside of Kigali Sim.
-
getGhgIntensity
Description copied from interface:EngineGet the GHG intensity (GWP - Global Warming Potential) associated with a substance.Set GHG equivalency (GWP - Global Warming Potential) for the specified application and substance (regradless of current scope). Will only execute if the year matcher matches the current year. Otherwise, this is a no-op.
Note that this is intended only for direct emissions though useres may calculate indirect or secondary emissions through energy mix outside of Kigali Sim.
- Specified by:
getGhgIntensityin interfaceEngine- Parameters:
useKey- The UseKey containing application and substance information- Returns:
- The GHG intensity value associated with the given combination in tCO2e per kg.
-
getEqualsGhgIntensity
Description copied from interface:EngineRetrieve the tCO2e intensity (GWP - Global Warming Potential) for the current application and substance.Retrieve the primary GHG intensity (GWP) for the current application and substance where this value is not expected to cover secondary or indirect emissions. That said, users may calculate those additional emissions through energy mix data from outside Kigali Sim.
- Specified by:
getEqualsGhgIntensityin interfaceEngine- Returns:
- The GHG intensity value with volume normalized GHG in tCO2e per kg.
-
getEqualsGhgIntensityFor
Description copied from interface:EngineRetrieve the tCO2e intensity (GWP - Global Warming Potential) for the given UseKey.Retrieve the primary GHG intensity (GWP) for the given application and substance where this value is not expected to cover secondary or indirect emissions. That said, users may calculate those additional emissions through energy mix data from outside Kigali Sim.
- Specified by:
getEqualsGhgIntensityForin interfaceEngine- Parameters:
useKey- The UseKey containing application and substance information- Returns:
- The GHG intensity value with volume normalized GHG in tCO2e per kg.
-
getEqualsEnergyIntensity
Description copied from interface:EngineRetrieve the energy intensity for the current application and substance.- Specified by:
getEqualsEnergyIntensityin interfaceEngine- Returns:
- The energy intensity value, typically in kwh / unit (yearly).
-
getEqualsEnergyIntensityFor
Description copied from interface:EngineRetrieve the energy intensity for the given UseKey.- Specified by:
getEqualsEnergyIntensityForin interfaceEngine- Parameters:
useKey- The UseKey containing application and substance information for the application and substance pair for which energy intensity is to be returned.- Returns:
- The energy intensity value, typically in kwh / unit (yearly).
-
changeStream
Description copied from interface:EngineChange a stream value by a delta amount with default scope.- Specified by:
changeStreamin interfaceEngine- Parameters:
stream- The stream identifier to modifyamount- The amount to change the stream byyearMatcher- Matcher to determine if the change applies to current year
-
changeStream
public void changeStream(String stream, EngineNumber amount, YearMatcher yearMatcher, UseKey useKey) Description copied from interface:EngineChange a stream value by a delta amount.- Specified by:
changeStreamin interfaceEngine- Parameters:
stream- The stream identifier to modifyamount- The amount to change the stream byyearMatcher- Matcher to determine if the change applies to current yearuseKey- The key containing application and substance information
-
cap
public void cap(String stream, EngineNumber amount, YearMatcher yearMatcher, String displaceTarget, DisplacementType displacementType) Description copied from interface:EngineCap a stream at a maximum value.- Specified by:
capin interfaceEngine- Parameters:
stream- The stream identifier to capamount- The maximum value to cap atyearMatcher- Matcher to determine if the change applies to current yeardisplaceTarget- Optional target for displaced amountdisplacementType- The type of displacement (EQUIVALENT, BY_VOLUME, or BY_UNITS)
-
floor
public void floor(String stream, EngineNumber amount, YearMatcher yearMatcher, String displaceTarget, DisplacementType displacementType) Description copied from interface:EngineSet a minimum floor value for a stream.- Specified by:
floorin interfaceEngine- Parameters:
stream- The stream identifier to set floor foramount- The minimum value to set as flooryearMatcher- Matcher to determine if the change applies to current yeardisplaceTarget- Optional target for displaced amountdisplacementType- The type of displacement (EQUIVALENT, BY_VOLUME, or BY_UNITS)
-
replace
public void replace(EngineNumber amountRaw, String stream, String destinationSubstance, YearMatcher yearMatcher) Description copied from interface:EngineReplace an amount from one substance with another. -
getResults
Description copied from interface:EngineGet the results for all registered substances.- Specified by:
getResultsin interfaceEngine- Returns:
- List of results for each registered substance
-
getOptimizeRecalcs
public boolean getOptimizeRecalcs()Description copied from interface:EngineGets whether recalc optimizations are enabled.When true, certain redundant recalculation steps are skipped for performance. When false, all recalc operations are performed for maximum accuracy verification.
- Specified by:
getOptimizeRecalcsin interfaceEngine- Returns:
- true if optimizations are enabled, false otherwise
-