Skip to content

Commit

Permalink
Merge pull request #40 from SutubraResearch/NewConstraints
Browse files Browse the repository at this point in the history
Add New Constraints
  • Loading branch information
SutubraResearch authored Aug 18, 2023
2 parents 3215b05 + db753c7 commit 7382330
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 27 deletions.
52 changes: 50 additions & 2 deletions data_files/temoa_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ CREATE TABLE "Output_CapacityByPeriodAndTech" (
);
CREATE TABLE "MyopicBaseyear" (
"year" real
"notes" text
"notes" text
);
CREATE TABLE "MinGenGroupWeight" (
"regions" text,
Expand Down Expand Up @@ -326,6 +326,17 @@ CREATE TABLE "MinCapacity" (
FOREIGN KEY("tech") REFERENCES "technologies"("tech"),
FOREIGN KEY("periods") REFERENCES "time_periods"("t_periods")
);
CREATE TABLE "MinNewCapacity" (
"regions" text,
"periods" integer,
"tech" text,
"mincap" real,
"mincap_units" text,
"mincap_notes" text,
PRIMARY KEY("regions","periods","tech"),
FOREIGN KEY("periods") REFERENCES "time_periods"("t_periods"),
FOREIGN KEY("tech") REFERENCES "technologies"("tech")
);
CREATE TABLE "MinActivity" (
"regions" text,
"periods" integer,
Expand All @@ -348,6 +359,17 @@ CREATE TABLE "MaxCapacity" (
FOREIGN KEY("periods") REFERENCES "time_periods"("t_periods"),
FOREIGN KEY("tech") REFERENCES "technologies"("tech")
);
CREATE TABLE "MaxNewCapacity" (
"regions" text,
"periods" integer,
"tech" text,
"maxcap" real,
"maxcap_units" text,
"maxcap_notes" text,
PRIMARY KEY("regions","periods","tech"),
FOREIGN KEY("periods") REFERENCES "time_periods"("t_periods"),
FOREIGN KEY("tech") REFERENCES "technologies"("tech")
);
CREATE TABLE "MaxActivity" (
"regions" text,
"periods" integer,
Expand All @@ -359,6 +381,32 @@ CREATE TABLE "MaxActivity" (
FOREIGN KEY("periods") REFERENCES "time_periods"("t_periods"),
FOREIGN KEY("tech") REFERENCES "technologies"("tech")
);
CREATE TABLE IF NOT EXISTS "MinAnnualCapacityFactor" (
"regions" text,
"periods" integer,
"tech" text,
"output_comm" text,
"min_acf" real CHECK("min_acf" >= 0 AND "min_acf" <= 1),
"source" text,
"min_acf_notes" text,
PRIMARY KEY("regions","periods","tech"),
FOREIGN KEY("periods") REFERENCES "time_periods"("t_periods"),
FOREIGN KEY("tech") REFERENCES "technologies"("tech"),
FOREIGN KEY("output_comm") REFERENCES "commodities"("comm_name")
);
CREATE TABLE IF NOT EXISTS "MaxAnnualCapacityFactor" (
"regions" text,
"periods" integer,
"tech" text,
"output_comm" text,
"max_acf" real CHECK("max_acf" >= 0 AND "max_acf" <= 1),
"source" text,
"max_acf_notes" text,
PRIMARY KEY("regions","periods","tech"),
FOREIGN KEY("periods") REFERENCES "time_periods"("t_periods"),
FOREIGN KEY("tech") REFERENCES "technologies"("tech"),
FOREIGN KEY("output_comm") REFERENCES "commodities"("comm_name")
);
CREATE TABLE "LifetimeTech" (
"regions" text,
"tech" text,
Expand Down Expand Up @@ -582,7 +630,7 @@ CREATE TABLE "MaxResource" (
CREATE TABLE "LinkedTechs" (
"primary_region" text,
"primary_tech" text,
"emis_comm" text,
"emis_comm" text,
"linked_tech" text,
"tech_linked_notes" text,
FOREIGN KEY("primary_tech") REFERENCES "technologies"("tech"),
Expand Down
6 changes: 5 additions & 1 deletion temoa_model/temoa_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,12 @@ def query_table (t_properties, f):
['param','TechInputSplitAverage', '', '', 4],
['param','MinCapacity', '', '', 3],
['param','MaxCapacity', '', '', 3],
['param','MinNewCapacity', '', '', 3],
['param','MaxNewCapacity', '', '', 3],
['param','MaxActivity', '', '', 3],
['param','MinActivity', '', '', 3],
['param','MinAnnualCapacityFactor', '', '', 4],
['param','MaxAnnualCapacityFactor', '', '', 4],
['param','MaxResource', '', '', 2],
['param','GrowthRateMax', '', '', 2],
['param','GrowthRateSeed', '', '', 2],
Expand Down Expand Up @@ -507,4 +511,4 @@ def build(self,**kwargs):
f.close()
sys.stdout = sys.__stdout__
if counter > 0:
sys.stderr.write("\n{} .db DD file(s) converted\n".format(counter))
sys.stderr.write("\n{} .db DD file(s) converted\n".format(counter))
60 changes: 46 additions & 14 deletions temoa_model/temoa_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

"""
Tools for Energy Model Optimization and Analysis (Temoa):
Tools for Energy Model Optimization and Analysis (Temoa):
An open source framework for energy systems optimization modeling
Copyright (C) 2015, NC State University
Expand All @@ -16,8 +16,8 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
A complete copy of the GNU General Public License v2 (GPLv2) is available
in LICENSE.txt. Users uncompressing this from an archive may not have
A complete copy of the GNU General Public License v2 (GPLv2) is available
in LICENSE.txt. Users uncompressing this from an archive may not have
received this license file. If not, see <http://www.gnu.org/licenses/>.
"""

Expand All @@ -37,12 +37,12 @@ def temoa_create_model(name="Temoa"):
M = TemoaModel(name)

# ---------------------------------------------------------------
# Define sets.
# Define sets.
# Sets are collections of items used to index parameters and variables
# ---------------------------------------------------------------

# Define time periods
M.time_exist = Set(ordered=True)
M.time_exist = Set(ordered=True)
M.time_future = Set(ordered=True)
M.time_optimize = Set(ordered=True, initialize=init_set_time_optimize)
# Define time period vintages to track capacity installation
Expand All @@ -58,7 +58,7 @@ def temoa_create_model(name="Temoa"):

# Define regions
M.regions = Set()
# RegionalIndices is the set of all the possible combinations of interregional
# RegionalIndices is the set of all the possible combinations of interregional
# exhanges plus original region indices. If tech_exchange is empty, RegionalIndices =regions.
M.RegionalIndices = Set(initialize=CreateRegionalIndices)

Expand Down Expand Up @@ -126,12 +126,12 @@ def temoa_create_model(name="Temoa"):

M.Demand = Param(M.regions, M.time_optimize, M.commodity_demand)
M.initialize_Demands = BuildAction(rule=CreateDemands)

M.ResourceBound = Param(M.regions, M.time_optimize, M.commodity_physical)

# Define technology performance parameters
M.CapacityToActivity = Param(M.RegionalIndices, M.tech_all, default=1)

M.ExistingCapacity = Param(M.RegionalIndices, M.tech_all, M.vintage_exist)

M.Efficiency = Param(
Expand Down Expand Up @@ -194,12 +194,12 @@ def temoa_create_model(name="Temoa"):
M.Loan_rtv = Set(dimen=3, initialize=lambda M: M.CostInvest.keys())
M.LoanAnnualize = Param(M.Loan_rtv, initialize=ParamLoanAnnualize_rule)


M.ModelProcessLife_rptv = Set(dimen=4, initialize=ModelProcessLifeIndices)
M.ModelProcessLife = Param(
M.ModelProcessLife_rptv, initialize=ParamModelProcessLife_rule
)

M.ProcessLifeFrac_rptv = Set(dimen=4, initialize=ModelProcessLifeIndices)
M.ProcessLifeFrac = Param(
M.ProcessLifeFrac_rptv, initialize=ParamProcessLifeFraction_rule
Expand All @@ -209,11 +209,15 @@ def temoa_create_model(name="Temoa"):
M.RegionalGlobalIndices = Set(initialize=RegionalGlobalInitializedIndices)
M.MinCapacity = Param(M.RegionalIndices, M.time_optimize, M.tech_all)
M.MaxCapacity = Param(M.RegionalIndices, M.time_optimize, M.tech_all)
M.MinNewCapacity = Param(M.RegionalIndices, M.time_optimize, M.tech_all)
M.MaxNewCapacity = Param(M.RegionalIndices, M.time_optimize, M.tech_all)
M.MaxResource = Param(M.RegionalIndices, M.tech_all)
M.MinCapacitySum = Param(M.time_optimize) # for techs in tech_capacity
M.MaxCapacitySum = Param(M.time_optimize) # for techs in tech_capacity
M.MaxActivity = Param(M.RegionalGlobalIndices, M.time_optimize, M.tech_all)
M.MinActivity = Param(M.RegionalGlobalIndices, M.time_optimize, M.tech_all)
M.MinAnnualCapacityFactor = Param(M.RegionalGlobalIndices, M.time_optimize, M.tech_all, M.commodity_carrier)
M.MaxAnnualCapacityFactor = Param(M.RegionalGlobalIndices, M.time_optimize, M.tech_all, M.commodity_carrier)
M.GrowthRateMax = Param(M.RegionalIndices, M.tech_all)
M.GrowthRateSeed = Param(M.RegionalIndices, M.tech_all)
M.EmissionLimit = Param(M.RegionalGlobalIndices, M.time_optimize, M.commodity_emissions)
Expand Down Expand Up @@ -336,7 +340,7 @@ def temoa_create_model(name="Temoa"):
)
M.CommodityBalanceAnnualConstraint = Constraint(
M.CommodityBalanceAnnualConstraint_rpc, rule=CommodityBalanceAnnual_Constraint
)
)

M.ResourceConstraint_rpr = Set(
dimen=3, initialize=lambda M: M.ResourceBound.sparse_iterkeys()
Expand Down Expand Up @@ -461,6 +465,13 @@ def temoa_create_model(name="Temoa"):
M.MaxCapacityConstraint_rpt, rule=MaxCapacity_Constraint
)

M.MaxNewCapacityConstraint_rpt = Set(
dimen=3, initialize=lambda M: M.MaxNewCapacity.sparse_iterkeys()
)
M.MaxNewCapacityConstraint = Constraint(
M.MaxNewCapacityConstraint_rpt, rule=MaxNewCapacity_Constraint
)

M.MaxResourceConstraint_rt = Set(
dimen=2, initialize=lambda M: M.MaxResource.sparse_iterkeys()
)
Expand All @@ -482,13 +493,34 @@ def temoa_create_model(name="Temoa"):
M.MinCapacityConstraint_rpt, rule=MinCapacity_Constraint
)

M.MinNewCapacityConstraint_rpt = Set(
dimen=3, initialize=lambda M: M.MinNewCapacity.sparse_iterkeys()
)
M.MinNewCapacityConstraint = Constraint(
M.MinNewCapacityConstraint_rpt, rule=MinNewCapacity_Constraint
)

M.MinCapacitySetConstraint_rp = Set(
dimen=2, initialize=lambda M: M.MinCapacitySum.sparse_iterkeys()
)
M.MinCapacitySetConstraint = Constraint(
M.MinCapacitySetConstraint_rp, rule=MinCapacitySet_Constraint
)

M.MinAnnualCapacityFactorConstraint_rpto = Set(
dimen=4, initialize=lambda M: M.MinAnnualCapacityFactor.sparse_iterkeys()
)
M.MinAnnualCapacityFactorConstraint = Constraint(
M.MinAnnualCapacityFactorConstraint_rpto, rule=MinAnnualCapacityFactor_Constraint
)

M.MaxAnnualCapacityFactorConstraint_rpto = Set(
dimen=4, initialize=lambda M: M.MaxAnnualCapacityFactor.sparse_iterkeys()
)
M.MaxAnnualCapacityFactorConstraint = Constraint(
M.MaxAnnualCapacityFactorConstraint_rpto, rule=MaxAnnualCapacityFactor_Constraint
)

M.TechInputSplitConstraint_rpsditv = Set(
dimen=7, initialize=TechInputSplitConstraintIndices
)
Expand All @@ -502,14 +534,14 @@ def temoa_create_model(name="Temoa"):
M.TechInputSplitAnnualConstraint = Constraint(
M.TechInputSplitAnnualConstraint_rpitv, rule=TechInputSplitAnnual_Constraint
)

M.TechInputSplitAverageConstraint_rpitv = Set(
dimen=5, initialize=TechInputSplitAverageConstraintIndices
)
M.TechInputSplitAverageConstraint = Constraint(
M.TechInputSplitAverageConstraint_rpitv, rule=TechInputSplitAverage_Constraint
)

M.TechOutputSplitConstraint_rpsdtvo = Set(
dimen=7, initialize=TechOutputSplitConstraintIndices
)
Expand Down Expand Up @@ -556,4 +588,4 @@ def runModel():
command line as follows: $ python temoa_model/temoa_model.py path/to/dat/file"""

dummy = "" # If calling from command line, send empty string
model = runModel()
model = runModel()
Loading

0 comments on commit 7382330

Please sign in to comment.