Skip to content

Commit

Permalink
Merge 5ef1b67 into d359470
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelduchesne committed Aug 6, 2019
2 parents d359470 + 5ef1b67 commit b60fd35
Show file tree
Hide file tree
Showing 78 changed files with 21,689 additions and 10,570 deletions.
17 changes: 6 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ env: ARCHETYPAL_INTEGRATION=True ENERGYPLUS_VERSION=8.9.0 ENERGYPLUS_SHA=40101ea
addons:
apt:
packages:
wine
- wine
- libgfortran3

before_install:
# install EnergyPlus
Expand All @@ -28,8 +29,9 @@ before_install:
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then
sudo chmod +x $ENERGYPLUS_DOWNLOAD_FILENAME.$EXT;
echo "y\r" | sudo ./$ENERGYPLUS_DOWNLOAD_FILENAME.$EXT;
sudo tar -C /usr/local/EnergyPlus-$ENERGYPLUS_INSTALL_VERSION/PreProcess/IDFVersionUpdater -xvf 8230;
sudo chmod -R a+rX /usr/local/EnergyPlus-$ENERGYPLUS_INSTALL_VERSION/PreProcess/IDFVersionUpdater/*; fi
sudo tar zxvf 8230 -C /usr/local/EnergyPlus-$ENERGYPLUS_INSTALL_VERSION/PreProcess/IDFVersionUpdater;
sudo chmod -R a+rwx /usr/local/EnergyPlus-$ENERGYPLUS_INSTALL_VERSION/PreProcess/IDFVersionUpdater;
sudo chmod -R a+rwx /usr/local/EnergyPlus-$ENERGYPLUS_INSTALL_VERSION/ExampleFiles; fi
- if [ "$TRAVIS_OS_NAME" == "windows" ]; then
sudo chmod +x $ENERGYPLUS_DOWNLOAD_FILENAME.$EXT;
echo "y\r" | sudo ./$ENERGYPLUS_DOWNLOAD_FILENAME.$EXT; fi
Expand All @@ -42,14 +44,7 @@ before_install:
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --set always_yes yes --set show_channel_urls true
- conda update -n base conda
- conda config --prepend channels conda-forge
- conda create -n archetypal python=$TRAVIS_PYTHON_VERSION
- conda env update -n archetypal -f environment.yml --prune
- conda install -n archetypal --file requirements-dev.txt
- source activate archetypal
- conda info --all
- pip install .[dev]

install:
- python setup.py install
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# package_data is a low-down, dirty lie. It is only used when building binary packages (python setup.py bdist ...) but
# not when building source packages (python setup.py sdist ...)

include archetypal/templates/*
include archetypal/ressources/*
include requirements.txt
include requirements-dev.txt
17 changes: 13 additions & 4 deletions archetypal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@
################################################################################

# Version of the package
__version__ = '1.2.6'
__version__ = "1.2.6"
# Latest version of EnergyPlus compatible with archetypal
ep_version = '8-9-0'
ep_version = "8-9-0"

# warn if a newer version of archetypal is available
from outdated import warn_if_outdated
warn_if_outdated('archetypal', __version__)

warn_if_outdated("archetypal", __version__)

from .utils import *
from .simple_glazing import *
from .idfclass import *
from .energyseries import EnergySeries
from .energydataframe import EnergyDataFrame
from .reportdata import ReportData
from .tabulardata import TabularData
from .schedule import Schedule
from .dataportal import *
from .plot import *
from .trnsys import *
from .cli import *
from .template import *
from .core import *
from .building import *
from .umi_template import *
from .cli import *
102 changes: 102 additions & 0 deletions archetypal/building.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
################################################################################
# Module: building.py
# Description: Functions related to building
# License: MIT, see full license in LICENSE.txt
# Web: https://github.com/samuelduchesne/archetypal
################################################################################

import numpy as np
import pandas
import pyomo.core as pyomo
import pyomo.environ
from pyomo.opt import SolverFactory
from .energyseries import EnergySeries


def create_fake_profile(
x=None,
y1={},
y2={},
normalize=False,
profile_type="undefined",
sorted=False,
ascending=False,
units="J",
):
"""Utility that generates a generic EnergySeries isntance
Args:
x (np.ndarray): is a linspace. Default is np.linspace(0, 8759, 8760)
y1 (dict): {'A':1, 'f':1/8760, 'phy':1, 's':0.5}
y2 (dict): {'A':1, 'f':1/24, 'phy':1, 's':0.5}
ascending (bool): if True, sorts in ascending order. Implies 'sorted'
is also True
profile_type (str): name to give the series. eg. 'heating load' or
'cooling load'
sorted (bool): id True, series will be sorted.
Returns:
EnergySeries: the EnergySeries
"""
if x is None:
x = np.linspace(0, 8759, 8760)
A1 = y1.get("A", 1)
f = y1.get("f", 1 / 8760)
w = 2 * np.pi * f
phy = y1.get("phy", 1)
s = y1.get("s", 0.5)
y1 = A1 * np.sin(w * x + phy) + s

A = y2.get("A", A1)
f = y2.get("f", 1 / 24)
w = 2 * np.pi * f
phy = y2.get("phy", 1)
s = y2.get("s", 0.5)
y2 = A * np.sin(w * x + phy) + s

y = y1 + y2
return EnergySeries(
y,
index=x,
frequency="1H",
units=units,
profile_type=profile_type,
normalize=normalize,
is_sorted=sorted,
ascending=ascending,
)


def discretize(profile, bins=5):
m = pyomo.ConcreteModel()

m.bins = pyomo.Set(initialize=range(bins))
m.timesteps = pyomo.Set(initialize=range(8760))
m.profile = profile.copy()
m.duration = pyomo.Var(m.bins, within=pyomo.NonNegativeIntegers)
m.amplitude = pyomo.Var(m.bins, within=pyomo.NonNegativeReals)

m.total_duration = pyomo.Constraint(
m.bins,
doc="All duration must be " "smaller or " "equal to 8760",
rule=total_duration_rule,
)

m.obj = pyomo.Objective(
sense=pyomo.minimize, doc="Minimize the sum of squared errors", rule=obj_rule
)
optim = SolverFactory("gurobi")

result = optim.solve(m, tee=True, load_solutions=False)

m.solutions.load_from(result)

return m


def total_duration_rule(m):
return sum(m.duration[i] for i in m.bins) == 8760


def obj_rule(m):
return sum(m.duration * m.amplitude)
Loading

0 comments on commit b60fd35

Please sign in to comment.