Skip to content

Commit

Permalink
create classes for PySAM wind technology and financial models
Browse files Browse the repository at this point in the history
  • Loading branch information
bayc committed Aug 30, 2023
1 parent deb073a commit 92ba6d7
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
26 changes: 26 additions & 0 deletions hopp/simulation/technologies/wind/pysam_financial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# tools to add floris to the hybrid simulation class
from attrs import define, field

import PySAM.Singleowner as Singleowner

from hopp.simulation.base import BaseClass
from hopp.type_dec import resource_file_converter
from hopp.utilities.utilities import load_yaml


@define
class PySAMFinancial(BaseClass):
config_dict: dict = field(converter=dict)

financial_model: Singleowner = field(init=False)

def __attrs_post_init__(self):
input_file_path = resource_file_converter(self.config_dict["financial_input_file"])
filetype = input_file_path.suffix.strip(".")
if filetype.lower() in ("yml", "yaml"):
input_dict = load_yaml(input_file_path)
else:
raise ValueError("Supported import filetype is YAML")

self.financial_model = Singleowner.new()
self.financial_model.assign(input_dict)
65 changes: 65 additions & 0 deletions hopp/simulation/technologies/wind/pysam_wind.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from attrs import define, field

import PySAM.Windpower as Windpower

from hopp.simulation.base import BaseClass
from hopp.simulation.technologies.sites import SiteInfo
from hopp.type_dec import resource_file_converter
from hopp.utilities.utilities import load_yaml


@define
class PySAMWind(BaseClass):
config_dict: dict = field(converter=dict)
site: SiteInfo = field()
timestep: tuple = field(default=(), converter=tuple)

system_model: Windpower = field(init=False)

def __attrs_post_init__(self):
input_file_path = resource_file_converter(self.config_dict["simulation_input_file"])
filetype = input_file_path.suffix.strip(".")
if filetype.lower() in ("yml", "yaml"):
input_dict = load_yaml(input_file_path)
else:
raise ValueError("Supported import filetype is YAML")

self.system_model = Windpower.new()
self.system_model.assign(input_dict)

self.wind_turbine_rotor_diameter = input_dict['Turbine']['wind_turbine_rotor_diameter']
self.wind_farm_xCoordinates = input_dict['Farm']['wind_farm_xCoordinates']
self.wind_farm_yCoordinates = input_dict['Farm']['wind_farm_yCoordinates']
self.nTurbs = len(self.wind_farm_xCoordinates)
self.system_model.value("wind_resource_data", self.site.wind_resource.data)

# turbine power curve (array of kW power outputs)
self.wind_turbine_powercurve_powerout = [1] * self.nTurbs

def value(self, name: str, set_value=None):
"""
if set_value = None, then retrieve value; otherwise overwrite variable's value
"""
if set_value:
self.__setattr__(name, set_value)
else:
return self.__getattribute__(name)

def execute(self, project_life):
self.system_model.execute(project_life)

@property
def annual_energy(self):
return self.system_model.value("annual_energy")

@annual_energy.setter
def annual_energy(self, d):
self.system_model.value("annual_energy", d)

@property
def gen(self):
return self.system_model.value("gen")

@gen.setter
def gen(self, d):
self.system_model.value("gen", d)

0 comments on commit 92ba6d7

Please sign in to comment.