Skip to content

Commit

Permalink
defined constants for LEFT and RIGHT (#42)
Browse files Browse the repository at this point in the history
Co-authored-by: Neil Wu <[email protected]>
  • Loading branch information
JustinSGray and ewu63 authored Jan 5, 2022
1 parent 6c63115 commit 259f56a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 24 deletions.
32 changes: 24 additions & 8 deletions examples/kitchen_sink.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
from pyxdsm.XDSM import XDSM, OPT, SUBOPT, SOLVER, DOE, IFUNC, FUNC, GROUP, IGROUP, METAMODEL
from pyxdsm.XDSM import (
XDSM,
OPT,
SUBOPT,
SOLVER,
DOE,
IFUNC,
FUNC,
GROUP,
IGROUP,
METAMODEL,
LEFT,
RIGHT,
)

x = XDSM()

Expand All @@ -22,7 +35,10 @@
# stacked can be used to represent multiple instances that can be run in parallel
x.add_system("H", FUNC, "H", stack=True)

x.add_process(["opt", "DOE", "MDA", "D1", "D2", "subopt", "G1", "G2", "MM", "F", "H", "opt"], arrow=True)
x.add_process(
["opt", "DOE", "MDA", "D1", "D2", "subopt", "G1", "G2", "MM", "F", "H", "opt"],
arrow=True,
)

x.connect("opt", "D1", ["x", "z", "y_2"], label_width=2)
x.connect("opt", "D2", ["z", "y_1"])
Expand Down Expand Up @@ -50,12 +66,12 @@
x.add_input("opt", r"x_0", stack=True)

# can put outputs on the left or right sides
x.add_output("opt", r"x^*, z^*", side="right")
x.add_output("D1", r"y_1^*", side="left")
x.add_output("D2", r"y_2^*", side="left")
x.add_output("F", r"f^*", side="right")
x.add_output("H", r"h^*", side="right")
x.add_output("opt", r"y^*", side="left")
x.add_output("opt", r"x^*, z^*", side=RIGHT)
x.add_output("D1", r"y_1^*", side=LEFT)
x.add_output("D2", r"y_2^*", side=LEFT)
x.add_output("F", r"f^*", side=RIGHT)
x.add_output("H", r"h^*", side=RIGHT)
x.add_output("opt", r"y^*", side=LEFT)

x.add_process(["output_opt", "opt", "left_output_opt"])

Expand Down
12 changes: 6 additions & 6 deletions examples/mdf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyxdsm.XDSM import XDSM, OPT, SOLVER, FUNC
from pyxdsm.XDSM import XDSM, OPT, SOLVER, FUNC, LEFT

# Change `use_sfmath` to False to use computer modern
x = XDSM(use_sfmath=True)
Expand All @@ -23,9 +23,9 @@
x.connect("F", "opt", "f")
x.connect("G", "opt", "g")

x.add_output("opt", "x^*, z^*", side="left")
x.add_output("D1", "y_1^*", side="left")
x.add_output("D2", "y_2^*", side="left")
x.add_output("F", "f^*", side="left")
x.add_output("G", "g^*", side="left")
x.add_output("opt", "x^*, z^*", side=LEFT)
x.add_output("D1", "y_1^*", side=LEFT)
x.add_output("D2", "y_2^*", side=LEFT)
x.add_output("F", "f^*", side=LEFT)
x.add_output("G", "g^*", side=LEFT)
x.write("mdf")
28 changes: 24 additions & 4 deletions pyxdsm/XDSM.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
GROUP = "Group"
IGROUP = "ImplicitGroup"
METAMODEL = "Metamodel"
LEFT = "left"
RIGHT = "right"

tikzpicture_template = r"""
%%% Preamble Requirements %%%
Expand Down Expand Up @@ -126,7 +128,16 @@ def __init__(self, use_sfmath=True):

self.use_sfmath = use_sfmath

def add_system(self, node_name, style, label, stack=False, faded=False, label_width=None, spec_name=None):
def add_system(
self,
node_name,
style,
label,
stack=False,
faded=False,
label_width=None,
spec_name=None,
):
"""
Add a "system" block, which will be placed on the diagonal of the XDSM diagram.
Expand Down Expand Up @@ -237,9 +248,18 @@ def add_output(self, name, label, label_width=None, style="DataIO", stack=False,
elif side == "right":
self.right_outs[name] = Output("right_output_" + name, label, label_width, style, stack, side)
else:
raise ValueError("The option 'side' must be given as either 'left' or 'right!'")

def connect(self, src, target, label, label_width=None, style="DataInter", stack=False, faded=False):
raise ValueError("The option 'side' must be given as either 'left' or 'right'!")

def connect(
self,
src,
target,
label,
label_width=None,
style="DataInter",
stack=False,
faded=False,
):
"""
Connects two components with a data line, and adds a label to indicate
the data being transferred.
Expand Down
2 changes: 1 addition & 1 deletion pyxdsm/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.2.0"
__version__ = "2.2.1"
10 changes: 5 additions & 5 deletions tests/test_xdsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shutil
import tempfile
import subprocess
from pyxdsm.XDSM import XDSM, OPT, FUNC, SOLVER
from pyxdsm.XDSM import XDSM, OPT, FUNC, SOLVER, LEFT, RIGHT
from numpy.distutils.exec_command import find_executable

basedir = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -92,10 +92,10 @@ def test_options(self):
x.connect("F", "opt", "f")
x.connect("G", "opt", "g")

x.add_output("opt", "x^*, z^*", side="right")
x.add_output("D1", "y_1^*", side="left", stack=True)
x.add_output("D2", "y_2^*", side="left")
x.add_output("F", "f^*", side="left")
x.add_output("opt", "x^*, z^*", side=RIGHT)
x.add_output("D1", "y_1^*", side=LEFT, stack=True)
x.add_output("D2", "y_2^*", side=LEFT)
x.add_output("F", "f^*", side=LEFT)
x.add_output("G", "g^*")
x.write(filename)
x.write_sys_specs(spec_dir)
Expand Down

0 comments on commit 259f56a

Please sign in to comment.