From 6f72dd20d56404a298ff5a2cb0df32aa2e206e8e Mon Sep 17 00:00:00 2001 From: Alexey Mulyukin Date: Thu, 21 Sep 2017 16:45:09 +0300 Subject: [PATCH] Implement supporting the RAMP function from xmile specification. --- pysd/py_backend/functions.py | 15 +++++++++------ pysd/py_backend/xmile/SMILE2Py.py | 3 +-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pysd/py_backend/functions.py b/pysd/py_backend/functions.py index 8c6930dd..8ca97014 100644 --- a/pysd/py_backend/functions.py +++ b/pysd/py_backend/functions.py @@ -744,9 +744,9 @@ def _integrate(self, time_steps, capture_elements, return_timestamps): return outputs -def ramp(slope, start, finish): +def ramp(slope, start, finish=0): """ - Implements vensim's RAMP function + Implements vensim's and xmile's RAMP function Parameters ---------- @@ -755,7 +755,7 @@ def ramp(slope, start, finish): start: float Time at which the ramp begins finish: float - Time at which the ramo ends + Optional. Time at which the ramp ends Returns ------- @@ -770,10 +770,13 @@ def ramp(slope, start, finish): t = time() if t < start: return 0 - elif t > finish: - return slope * (finish - start) else: - return slope * (t - start) + if finish <= 0: + return slope * (t - start) + elif t > finish: + return slope * (finish - start) + else: + return slope * (t - start) def step(value, tstep): diff --git a/pysd/py_backend/xmile/SMILE2Py.py b/pysd/py_backend/xmile/SMILE2Py.py index 465c8f8d..8be5061f 100644 --- a/pysd/py_backend/xmile/SMILE2Py.py +++ b/pysd/py_backend/xmile/SMILE2Py.py @@ -79,8 +79,7 @@ "pulse": "functions.pulse_magnitude", "step": "functions.step", - - # "ramp" !TODO! + "ramp" "functions.ramp", # === # 3.5.5 Time Functions