def test_options(self): filename = 'xdsm_test_options' spec_dir = filename + '_specs' # Change `use_sfmath` to False to use computer modern x = XDSM(use_sfmath=False) x.add_system('opt', 'Optimization', r'\text{Optimizer}') x.add_system('solver', 'MDA', r'\text{Newton}') x.add_system('D1', 'Function', 'D_1', text_width=2.0) x.add_system('D2', 'Function', 'D_2', stack=False) x.add_system('F', 'Function', 'F', faded=True) x.add_system('G', 'Function', 'G', spec_name="G_spec") x.connect('opt', 'D1', 'x, z') x.connect('opt', 'D2', 'z') x.connect('opt', 'F', 'x, z') x.connect('solver', 'D1', 'y_2') x.connect('solver', 'D2', 'y_1') x.connect('D1', 'solver', r'\mathcal{R}(y_1)') x.connect('solver', 'F', 'y_1, y_2') x.connect('D2', 'solver', r'\mathcal{R}(y_2)') x.connect('solver', 'G', 'y_1, y_2') 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('G', 'g^*') x.write(filename) x.write_sys_specs(spec_dir) # Test if files where created self.assertTrue(os.path.isfile(filename + '.tikz')) self.assertTrue(os.path.isfile(filename + '.tex')) self.assertTrue(os.path.isdir(spec_dir)) self.assertTrue(os.path.isfile(os.path.join(spec_dir, 'F.json'))) self.assertTrue(os.path.isfile(os.path.join(spec_dir, 'G_spec.json')))
def test_options(self): filename = "xdsm_test_options" spec_dir = filename + "_specs" # Change `use_sfmath` to False to use computer modern x = XDSM(use_sfmath=False) x.add_system("opt", OPT, r"\text{Optimizer}") x.add_system("solver", SOLVER, r"\text{Newton}") x.add_system("D1", FUNC, "D_1", label_width=2) x.add_system("D2", FUNC, "D_2", stack=False) x.add_system("F", FUNC, "F", faded=True) x.add_system("G", FUNC, "G", spec_name="G_spec") x.connect("opt", "D1", "x, z") x.connect("opt", "D2", "z") x.connect("opt", "F", "x, z") x.connect("solver", "D1", "y_2") x.connect("solver", "D2", "y_1") x.connect("D1", "solver", r"\mathcal{R}(y_1)") x.connect("solver", "F", "y_1, y_2") x.connect("D2", "solver", r"\mathcal{R}(y_2)") x.connect("solver", "G", "y_1, y_2") 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("G", "g^*") x.write(filename) x.write_sys_specs(spec_dir) # Test if files where created self.assertTrue(os.path.isfile(filename + ".tikz")) self.assertTrue(os.path.isfile(filename + ".tex")) self.assertTrue(os.path.isdir(spec_dir)) self.assertTrue(os.path.isfile(os.path.join(spec_dir, "F.json"))) self.assertTrue(os.path.isfile(os.path.join(spec_dir, "G_spec.json")))
FUNC = "Function" GROUP = "Group" IGROUP = "ImplicitGroup" METAMODEL = "Metamodel" x.add_system("opt", OPT, r"\text{Optimizer}") x.add_system("solver", SOLVER, r"\text{Newton}") x.add_system("D1", FUNC, "D_1") x.add_system("D2", FUNC, "D_2") x.add_system("F", FUNC, "F") x.add_system("G", FUNC, "G") x.connect("opt", "D1", "x, z") x.connect("opt", "D2", "z") x.connect("opt", "F", "x, z") x.connect("solver", "D1", "y_2") x.connect("solver", "D2", "y_1") x.connect("D1", "solver", r"\mathcal{R}(y_1)") x.connect("solver", "F", "y_1, y_2") x.connect("D2", "solver", r"\mathcal{R}(y_2)") x.connect("solver", "G", "y_1, y_2") 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.write("mdf")
#x.connect('A', 'opt', r'') #x.connect('L', 'opt', r'\mathcal{R}(L)') #x.connect('S', 'opt', r'\mathcal{R}(S)') #x.connect('P', 'opt', r'\mathcal{R}(P)') x.connect('O', 'opt', r'f_{0}') x.connect('I', 'opt', r'c_{0}') x.connect('C', 'opt', r'c_{c}') x.add_input( 'opt', r'S_{e}^{0},b_{e}^{0},\lambda_{e}^{0},\Lambda_{LE}^{0},CST_{root}^{0},CST_{tip}^{0},\phi_{t}^{0},loc_{engines}^{0},\hat{MTOW}^{0},\hat{W_{f}}^{0},\hat{loading}^{0},\hat{L/D}{^0}' ) x.add_output( 'opt', r'S_{e}^{*},b_{e}^{*},\lambda_{e}^{*},\Lambda_{LE}^{*},CST_{root}^{*},CST_{tip}^{*},\phi_{t}^{*},loc_{engines}^{*},\hat{MTOW}^{*},\hat{W_{f}}^{*},\hat{loading}^{*},\hat{L/D}^{*}', side='left') x.add_output('A', r'L/D^{*}', side='left') x.add_output('L', r'loading^{*}', side='left') x.add_output('S', r'MTOW^{*}', side='left') x.add_output('P', r'W_{f}^{*}', side='left') #x.add_output('F', r'f^*', side='left') #x.add_output('G', r'g^*', side='left') x.add_process(['opt', 'A', 'C', 'opt']) x.add_process(['opt', 'L', 'C', 'opt']) x.add_process(['opt', 'S', 'C', 'opt']) x.add_process(['opt', 'S', 'I', 'opt']) x.add_process(['opt', 'P', 'C', 'opt']) x.add_process(['opt', 'P', 'I', 'opt']) x.add_process(['opt', 'P', 'O', 'opt'])
#x.add_input("OBJ", "x,z_2") x.connect("opt", "D1", "x,z_1,z_2") x.connect("opt", "D2", "z_1,z_2") x.connect("opt", "OBJ", "x,z_2") x.connect("solver", "D1", "y_2") x.connect("solver", "D2", "y_1") x.connect("solver", "OBJ", "y_1,y_2") x.connect("solver", "G1", "y_1") x.connect("solver", "G2", "y_2") #x.connect("D1", "D2", "y_1") #x.connect("D1", "OBJ", "y_1") #x.connect("D1", "G1", "y_1") #x.connect("D2", "OBJ", "y_2") #x.connect("D2", "G2", "y_2") x.connect("D1", "solver", "y_1") x.connect("D2", "solver", "y_2") #x.connect("D2", "D1", "y_2") x.connect("OBJ", "opt", "f") x.connect("G1", "opt", "g_1") x.connect("G2", "opt", "g_2") x.add_output("opt", "x^*,z_1^*,z_2^*", side="right") x.add_output("D1", "y_1^*", side="right") x.add_output("D2", "y_2^*", side="right") x.add_output("OBJ", "f^*", side="right") x.add_output("G1", "g_1^*", side="right") x.add_output("G2", "g_2^*", side="right") x.write("xdsm_sellar")
# opt = 'Optimization' solver = 'MDA' comp = 'Analysis' group = 'Metamodel' func = 'Function' x = XDSM() x.add_system('EOM', comp, r'EOM') x.add_system('nav', comp, r'nav') x.add_system('threat', func, r'threat') # x.connect('opt', 'EOM', r'x, z') # x.connect('opt', 'nav', r'z') # x.connect('opt', 'F', r'x, z') # x.connect('solver', 'EOM', r'y_2') # x.connect('solver', 'nav', r'y_1') x.connect('nav', 'threat', r'r_{ship}') # x.connect('solver', 'F', r'y_1, y_2') # x.connect('solver', 'G', r'y_1, y_2') x.add_input('EOM', r'v, \phi') x.add_input('nav', r'x, y') x.add_input('threat', r'time') # x.add_output('opt', r'x^*, z^*', side='left') x.add_output('EOM', r'\dot{x}, \dot{y}', side='right') x.add_output('threat', r'range_{sub}', side='right') x.write('donner_sub_ode_xdsm')
x.add_system("opt", OPT, [r"\text{Optimizer}"]) x.add_system("solver", SOLVER, [r"\text{MDA}"]) x.add_system("D1", IFUNC, ["Aerodynamic", "F=CA_fv^2"]) x.add_system("D2", IFUNC, ["Structural", "k\\theta=\\frac{1}{2}\\rho C_D"]) x.add_system("G", FUNC, ["Constraint1", "g=F-F_{max}"]) x.add_system("H", FUNC, ["Constraint2", "h=lw-A"]) x.add_system("OBJ", FUNC, ["Objective", "f=(\\theta-{\\hat \\theta})^2"]) x.add_input("opt", "l^{(0)},w^{(0)}") x.connect("opt", "D1", "l,w") x.connect("opt", "D2", "l") x.connect("opt", "H", "l,w") x.connect("solver", "G", "F") x.connect("solver", "OBJ", "\\theta") x.connect("D1", "solver", "F") x.connect("D2", "solver", "\\theta") x.connect("OBJ", "opt", "f") x.connect("G", "opt", "g") x.connect("H", "opt", "h") x.add_output("opt", "l^*,w^*", side="left") x.add_output("D1", "F^*", side="left") x.add_output("D2", "\\theta^*", side="left") x.add_output("G", "g^*", side="left") x.add_output("H", "h^*", side="left") x.add_output("OBJ", "f^*", side="left") x.write("xdsm_airflow_sensor_mdf")
def test_tikz_content(self): # Check if TiKZ file was created. # Compare the content of the sample below and the newly created TiKZ file. sample_txt = r""" %%% Preamble Requirements %%% % \usepackage{geometry} % \usepackage{amsfonts} % \usepackage{amsmath} % \usepackage{amssymb} % \usepackage{tikz} % Optional packages such as sfmath set through python interface % \usepackage{sfmath} % \usetikzlibrary{arrows,chains,positioning,scopes,shapes.geometric,shapes.misc,shadows} %%% End Preamble Requirements %%% \input{"path/to/diagram_styles"} \begin{tikzpicture} \matrix[MatrixSetup]{ %Row 0 \node [DataIO] (left_output_opt) {$x^*, z^*$};& \node [Optimization] (opt) {$\text{Optimizer}$};& & \node [DataInter] (opt-D1) {$x, z$};& \node [DataInter] (opt-D2) {$z$};& \node [DataInter] (opt-F) {$x, z$};& \\ %Row 1 & & \node [MDA] (solver) {$\text{Newton}$};& \node [DataInter] (solver-D1) {$y_2$};& \node [DataInter] (solver-D2) {$y_1$};& \node [DataInter] (solver-F) {$y_1, y_2$};& \node [DataInter] (solver-G) {$y_1, y_2$};\\ %Row 2 \node [DataIO] (left_output_D1) {$y_1^*$};& & \node [DataInter] (D1-solver) {$\mathcal{R}(y_1)$};& \node [Function] (D1) {$D_1$};& & & \\ %Row 3 \node [DataIO] (left_output_D2) {$y_2^*$};& & \node [DataInter] (D2-solver) {$\mathcal{R}(y_2)$};& & \node [Function] (D2) {$D_2$};& & \\ %Row 4 \node [DataIO] (left_output_F) {$f^*$};& \node [DataInter] (F-opt) {$f$};& & & & \node [Function] (F) {$F$};& \\ %Row 5 \node [DataIO] (left_output_G) {$g^*$};& \node [DataInter] (G-opt) {$g$};& & & & & \node [Function] (G) {$G$};\\ %Row 6 & & & & & & \\ }; % XDSM process chains \begin{pgfonlayer}{data} \path % Horizontal edges (opt) edge [DataLine] (opt-D1) (opt) edge [DataLine] (opt-D2) (opt) edge [DataLine] (opt-F) (solver) edge [DataLine] (solver-D1) (solver) edge [DataLine] (solver-D2) (D1) edge [DataLine] (D1-solver) (solver) edge [DataLine] (solver-F) (D2) edge [DataLine] (D2-solver) (solver) edge [DataLine] (solver-G) (F) edge [DataLine] (F-opt) (G) edge [DataLine] (G-opt) (opt) edge [DataLine] (left_output_opt) (D1) edge [DataLine] (left_output_D1) (D2) edge [DataLine] (left_output_D2) (F) edge [DataLine] (left_output_F) (G) edge [DataLine] (left_output_G) % Vertical edges (opt-D1) edge [DataLine] (D1) (opt-D2) edge [DataLine] (D2) (opt-F) edge [DataLine] (F) (solver-D1) edge [DataLine] (D1) (solver-D2) edge [DataLine] (D2) (D1-solver) edge [DataLine] (solver) (solver-F) edge [DataLine] (F) (D2-solver) edge [DataLine] (solver) (solver-G) edge [DataLine] (G) (F-opt) edge [DataLine] (opt) (G-opt) edge [DataLine] (opt); \end{pgfonlayer} \end{tikzpicture}""" filename = "xdsm_test_tikz" x = XDSM(use_sfmath=True) x.add_system("opt", OPT, r"\text{Optimizer}") x.add_system("solver", SOLVER, r"\text{Newton}") x.add_system("D1", FUNC, "D_1") x.add_system("D2", FUNC, "D_2") x.add_system("F", FUNC, "F") x.add_system("G", FUNC, "G") x.connect("opt", "D1", "x, z") x.connect("opt", "D2", "z") x.connect("opt", "F", "x, z") x.connect("solver", "D1", "y_2") x.connect("solver", "D2", "y_1") x.connect("D1", "solver", r"\mathcal{R}(y_1)") x.connect("solver", "F", "y_1, y_2") x.connect("D2", "solver", r"\mathcal{R}(y_2)") x.connect("solver", "G", "y_1, y_2") 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.write(filename) # Check if file was created tikz_file = filename + ".tikz" self.assertTrue(os.path.isfile(tikz_file)) sample_lines = sample_txt.split("\n") sample_lines = filter_lines(sample_lines) with open(tikz_file, "r") as f: new_lines = filter_lines(f.readlines()) sample_no_match = [] # Sample text new_no_match = [] # New text for new_line, sample_line in zip(new_lines, sample_lines): if new_line.startswith(r"\input{"): continue if new_line != sample_line: # else everything is okay # This can be because of the different ordering of lines or because of an error. sample_no_match.append(new_line) new_no_match.append(sample_line) # Sort both sets of suspicious lines sample_no_match.sort() new_no_match.sort() for sample_line, new_line in zip(sample_no_match, new_no_match): # Now the lines should match, if only the ordering was different self.assertEqual(new_line, sample_line) # To be sure, check the length, otherwise a missing last line could get unnoticed because of using zip self.assertEqual(len(new_lines), len(sample_lines))
def test_tikz_content(self): # Check if TiKZ file was created. # Compare the content of the sample below and the newly created TiKZ file. tikz_txt = r""" %%% Preamble Requirements %%% % \usepackage{geometry} % \usepackage{amsfonts} % \usepackage{amsmath} % \usepackage{amssymb} % \usepackage{tikz} % Optional packages such as sfmath set through python interface % \usepackage{sfmath} % \usetikzlibrary{arrows,chains,positioning,scopes,shapes.geometric,shapes.misc,shadows} %%% End Preamble Requirements %%% \input{"D:/Documents/GitHub/mypyXDSM/pyXDSM/pyxdsm/diagram_styles"} \begin{tikzpicture} \matrix[MatrixSetup]{ %Row 0 \node [DataIO] (left_output_opt) {$x^*, z^*$};& \node [Optimization] (opt) {$\text{Optimizer}$};& & \node [DataInter] (opt-D1) {$x, z$};& \node [DataInter] (opt-D2) {$z$};& \node [DataInter] (opt-F) {$x, z$};& \\ %Row 1 & & \node [MDA] (solver) {$\text{Newton}$};& \node [DataInter] (solver-D1) {$y_2$};& \node [DataInter] (solver-D2) {$y_1$};& \node [DataInter] (solver-F) {$y_1, y_2$};& \node [DataInter] (solver-G) {$y_1, y_2$};\\ %Row 2 \node [DataIO] (left_output_D1) {$y_1^*$};& & \node [DataInter] (D1-solver) {$\mathcal{R}(y_1)$};& \node [Function] (D1) {$D_1$};& & & \\ %Row 3 \node [DataIO] (left_output_D2) {$y_2^*$};& & \node [DataInter] (D2-solver) {$\mathcal{R}(y_2)$};& & \node [Function] (D2) {$D_2$};& & \\ %Row 4 \node [DataIO] (left_output_F) {$f^*$};& \node [DataInter] (F-opt) {$f$};& & & & \node [Function] (F) {$F$};& \\ %Row 5 \node [DataIO] (left_output_G) {$g^*$};& \node [DataInter] (G-opt) {$g$};& & & & & \node [Function] (G) {$G$};\\ %Row 6 & & & & & & \\ }; % XDSM process chains \begin{pgfonlayer}{data} \path % Horizontal edges (opt) edge [DataLine] (opt-D1) (opt) edge [DataLine] (opt-D2) (opt) edge [DataLine] (opt-F) (solver) edge [DataLine] (solver-D1) (solver) edge [DataLine] (solver-D2) (D1) edge [DataLine] (D1-solver) (solver) edge [DataLine] (solver-F) (D2) edge [DataLine] (D2-solver) (solver) edge [DataLine] (solver-G) (F) edge [DataLine] (F-opt) (G) edge [DataLine] (G-opt) (opt) edge [DataLine] (left_output_opt) (D1) edge [DataLine] (left_output_D1) (D2) edge [DataLine] (left_output_D2) (F) edge [DataLine] (left_output_F) (G) edge [DataLine] (left_output_G) % Vertical edges (opt-D1) edge [DataLine] (D1) (opt-D2) edge [DataLine] (D2) (opt-F) edge [DataLine] (F) (solver-D1) edge [DataLine] (D1) (solver-D2) edge [DataLine] (D2) (D1-solver) edge [DataLine] (solver) (solver-F) edge [DataLine] (F) (D2-solver) edge [DataLine] (solver) (solver-G) edge [DataLine] (G) (F-opt) edge [DataLine] (opt) (G-opt) edge [DataLine] (opt); \end{pgfonlayer} \end{tikzpicture}""" def filter_lines(lns): # Empty lines are excluded. # Leading and trailing whitespaces are removed # Comments are removed. return [ ln.strip() for ln in lns if ln.strip() and not ln.strip().startswith('%') ] filename = 'xdsm_test_tikz' x = XDSM(use_sfmath=True) x.add_system('opt', 'Optimization', r'\text{Optimizer}') x.add_system('solver', 'MDA', r'\text{Newton}') x.add_system('D1', 'Function', 'D_1') x.add_system('D2', 'Function', 'D_2') x.add_system('F', 'Function', 'F') x.add_system('G', 'Function', 'G') x.connect('opt', 'D1', 'x, z') x.connect('opt', 'D2', 'z') x.connect('opt', 'F', 'x, z') x.connect('solver', 'D1', 'y_2') x.connect('solver', 'D2', 'y_1') x.connect('D1', 'solver', r'\mathcal{R}(y_1)') x.connect('solver', 'F', 'y_1, y_2') x.connect('D2', 'solver', r'\mathcal{R}(y_2)') x.connect('solver', 'G', 'y_1, y_2') 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.write(filename) # Check if file was created tikz_file = filename + '.tikz' self.assertTrue(os.path.isfile(tikz_file)) tikz_lines = tikz_txt.split('\n') tikz_lines = filter_lines(tikz_lines) with open(tikz_file, "r") as f: lines = filter_lines(f.readlines()) sample_no_match = [] # Sample text new_no_match = [] # New text for line1, line2 in zip(lines, tikz_lines): if line1 != line2: # else everything is okay # This can be because of the different ordering of lines or because of an error. sample_no_match.append(line1) new_no_match.append(line2) # Sort both sets of suspicious lines sample_no_match.sort() new_no_match.sort() for line1, line2 in zip(sample_no_match, new_no_match): # Now the lines should match, if only the ordering was different self.assertEqual(line1, line2) # To be sure, check the length, otherwise a missing last line could get unnoticed because of using zip self.assertEqual(len(lines), len(tikz_lines))
x.add_system("solver", SOLVER, [r"\text{MDA}"]) x.add_system("D1", FUNC, ["Discipline1", "y_{21}=x_1+x_2"]) x.add_system("D2", FUNC, ["Discipline2", "y_{12}=x_1/2+x_2"]) x.add_system("OBJ", FUNC, ["Objective", "f=x_1^2+x_2^2+x_3^2"]) x.add_system("G1", FUNC, ["Constraint1", "g_1=y_{12}^t/2+3x_1/4+1"]) x.add_system("G2", FUNC, ["Constraint2", "g_2=-y_{21}^t-x_1+x_3"]) x.add_input("opt", "x_1^{(0)},x_2^{(0)},x_3^{(0)}") x.connect("opt", "D1", "x_1,x_2") x.connect("opt", "D2", "x_1,x_2") x.connect("opt", "OBJ", "x_1,x_2,x_3") x.connect("opt", "G1", "x_1") x.connect("opt", "G2", "x_1,x_3") x.connect("solver", "G1", "y_{12}^t") x.connect("solver", "G2", "y_{21}^t") x.connect("D1", "solver", "y_{21}") x.connect("D2", "solver", "y_{12}") x.connect("OBJ", "opt", "f") x.connect("G1", "opt", "g_1") x.connect("G2", "opt", "g_2") x.add_output("opt", "x_1^*,x_2^*,x_3^*", side="left") x.add_output("D1", "y_{21}^*", side="left") x.add_output("D2", "y_{12}^*", side="left") x.add_output("OBJ", "f^*", side="left") x.add_output("G1", "g_1^*", side="left") x.add_output("G2", "g_2^*", side="left") x.write("xdsm_analytical_mdf")
x.add_system('heat_pipe', func, ['Heat pipe']) x.add_system('Struct', func, ['Struct']) # Optimizer x.connect('Optimizer', 'pack_design', ['energy_{required}', 'eta_{batt}', 'I_{batt}']) # Pack Size x.add_input('pack_design', [ 'L_{pack}', 'W_{pack}', 'L_{cell}', 'W_{cell}', 'H_{cell}', 'mass_{cell}', 'voltage_{low,cell}', 'voltage_{nom,cell}', 'dischargeRate_{cell}', 'Q_{max}', 'V_{batt}' ]) x.connect('pack_design', 'PCM', ['n_{cpk}', 'n_{kps}']) x.connect('pack_design', 'Struct', 'mass_{cell}') x.add_output('pack_design', ['n_{series}', 'n_{parallel}'], side='right') # PCM x.connect('PCM', 'pack_design', 't_{PCM}') x.connect('PCM', 'Struct', 'mass_{PCM}') # HP x.add_input('heat_pipe', ['d_{init}', 'rho_{HP}', 'L_{pack}']) x.connect('heat_pipe', 'Struct', 'mass_{HP}') x.connect('heat_pipe', 'pack_design', 't_{HP}') # Struct x.connect('Struct', 'pack_design', 't_{wall}') x.add_output('Struct', ['mass_{battery}'], side='right') x.write('Design_XDSM')
x.add_system('e_solver', solver, ['Solver'], spec_name=False) x.add_system('e_comp', func, ['Zappy']) x.add_system('battery', func, ['Battery']) x.add_system('TMS', func, ['TMS']) # Connect Dymos outputs to subsystems x.connect('DYMOS', 'battery', ['SOC', 'V_{thev}','Q_{fire}','PCM_{sat}']) # Connect Solver states to subsystems x.connect('e_solver', 'e_comp', '') x.connect('e_solver', 'battery', '') # Connect Zappy outputs to subsystems x.connect('e_comp', 'battery', 'I_{batt}') x.add_output('e_comp', 'Q_{lines}', side='right') # output to thermal phase # x.add_output('e_comp', r'C_{max}', side='right') # Connect Battery outputs to subsystems x.add_input('battery', ['n_{series}','n_{parallel}','Q_{max}']) x.connect('battery', 'DYMOS', ['dXdt:SOC', 'dXdt:V_{thev}','dXdt:PCM_{sat}']) x.connect('battery', 'e_comp', 'V_{batt,actual}') x.connect('battery', 'e_solver', '') x.connect('battery', 'TMS', ['T_{cold}']) x.add_output('battery', ['T_{batt}'], side='right') x.add_input('TMS', ['A_{cold}']) x.connect('TMS','battery',['Q_{rej}']) # # Connect Thermal outputs to subsystems
# opt = 'Optimization' solver = 'MDA' group = 'Group' func = 'Function' x = XDSM() x.add_system('d1', func, [r'Discipline 1', 'y_1 = z_1^2 + z_2 + x_1 - 0.2y_2']) x.add_system('d2', func, [r'Discipline 2', 'y_2 = \sqrt{y_1} + z_1 + z_2']) x.add_system('f', func, [r'Objective', 'f = x^2 + z_1 + y_1 + e^{-y_2}']) x.add_system('g1', func, [r'Constraint 1', 'g1 = 3.16-y_1 ']) x.add_system('g2', func, [r'Constraint 2', 'g_2 = y_2 - 24.0']) x.connect('d1', 'd2', r'y_1') x.connect('d1', 'f', r'y_1') x.connect('d1', 'g1', r'y_1') x.connect('d2', 'd1', r'y_2') x.connect('d2', 'f', r'y_2') x.connect('d2', 'g2', r'y_2') x.add_input('d1', r'x, z_1, z_2') x.add_input('d2', r'z_1, z_2') x.add_input('f', r'x, z_1') x.add_output('f', r'f', side='right') x.add_output('g1', r'g_1', side='right') x.add_output('g2', r'g_2', side='right') x.write('sellar_xdsm')
from pyxdsm.XDSM import XDSM x = XDSM() # Define styles OPT = "Optimization" SUBOPT = "SubOptimization" SOLVER = "MDA" DOE = "DOE" IFUNC = "ImplicitFunction" FUNC = "Function" GROUP = "Group" IGROUP = "ImplicitGroup" METAMODEL = "Metamodel" DataIO = "DataIO" DataInter = "DataInter" x.add_system("opt", OPT, [r"\text{Optimizer}"]) x.add_system("D1", FUNC, ["Discipline1", "f(x,y)=(x-3)^2+xy+(y+4)^2-3"]) x.add_input("opt", "x^{(0)},y^{(0)}") x.connect("opt", "D1", "x,y") x.connect("D1", "opt", "f") x.add_output("opt", "x^*,y^*", side="left") x.add_output("D1", "f^*", side="left") x.write("xdsm_single_disp")
# Change `use_sfmath` to False to use computer modern x = XDSM(use_sfmath=True) x.add_system("opt", OPT, r"\text{Optimizer}") x.add_system("solver", SOLVER, r"\text{Newton}") x.add_system("D1", FUNC, "D_1") x.add_system("D2", FUNC, "D_2") x.add_system("F", FUNC, "F") x.add_system("G", FUNC, "G") x.connect("opt", "D1", "x, z") x.connect("opt", "D2", "z") x.connect("opt", "F", "x, z") x.connect("solver", "D1", "y_2") x.connect("solver", "D2", "y_1") x.connect("D1", "solver", r"\mathcal{R}(y_1)") x.connect("solver", "F", "y_1, y_2") x.connect("D2", "solver", r"\mathcal{R}(y_2)") x.connect("solver", "G", "y_1, y_2") 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.write("mdf")
from pyxdsm.XDSM import XDSM # Part-1 : Generate XDSM class object x = XDSM() # Part-2 : Define shape styles used in XDSM DataIO = 'DataIO' comp2 = 'ImplicitFunction' group = 'Metamodel' func = 'Function' OPT = "Optimization" # Part-3 : create system x.add_system('opt', OPT, r'\text{Optimizer}') x.add_system('D1', func, (r'Discipline1', r'y_1 = y_2^2')) x.add_system('D2', comp2, (r'Discipline2', r'exp(-y_1y_2)-xy_2 = 0 ')) x.add_system('F', func, (r'\text{Model Output}', r'f= y_1^2 - y_2 +3')) # Part-4 : Connect systems with variables x.connect('opt', 'D2', 'x') x.connect('D1', 'D2', r'y_1') x.connect('D1', 'F', r'y_1') x.connect('D2', 'F', r'y_2') x.connect('D2', 'D1', r'y_2') x.connect('F', 'opt', r'f') x.add_output('opt', 'x^*', side='left') # Part-5 : write Sellar.tex, Sellar.tikz, Sellar.pdf files x.write('Sellar')
x.add_system('wing_ambient', ecomp, [r'\text{Wing}', r'\text{Ambient}']) x.add_system('aero_comp', icomp, [ r'\text{Wing Aerodynamics/}', r'\text{Structures}', r'\text{(OpenAeroStruct)}' ]) x.add_system('aircraft_mass', ecomp, [r'\text{Aircraft Mass}']) # AKA prebalance x.add_system('balance', icomp, [r'\text{Balance}']) x.add_input('prop_comp', r'\bar{X}_{propeller}') x.add_input('e_comp', r'\bar{X}_{electrical}') x.add_input('engine_comp', r'\bar{X}_{turboshaft}') x.add_input('aero_comp', r'\bar{X}_{wing}') x.add_input('aircraft_mass', [r'\bar{X}_{aircraft}', r'm_{fuel}']) x.add_output('e_comp', r'\bar{Y}_{electrical}', side='right') x.add_output('engine_comp', r'\bar{Y}_{turboshaft}', side='right') x.add_output('aero_comp', [r'\bar{Y}_{wing}'], side='right') x.add_output('aircraft_mass', [r'm_{total}'], side='right') x.connect('eng_ambient', 'prop_comp', [r'FC']) x.connect('eng_ambient', 'engine_comp', [r'FC']) x.connect('thrust_comp', 'prop_comp', [r'T']) x.connect('prop_comp', 'e_comp', [r'P_{propeller}']) x.connect('e_comp', 'engine_comp', [r'P_{generator}']) x.connect('prop_comp', 'aircraft_mass', [r'm_{propeller}']) x.connect('e_comp', 'aircraft_mass', [r'm_{electrical}']) x.connect('engine_comp', 'aircraft_mass', [r'm_{turboshaft}']) x.connect('wing_ambient', 'aero_comp', [r'FC']) x.connect('aero_comp', 'aircraft_mass', [r'm_{wing}'])
IFUNC = "ImplicitFunction" FUNC = "Function" GROUP = "Group" IGROUP = "ImplicitGroup" METAMODEL = "Metamodel" DataIO = "DataIO" DataInter = "DataInter" x.add_system("D1", FUNC, ["Discipline1", "y_1=z_1^2+z_2+x_1-0.2y_2"]) x.add_system("D2", FUNC, ["Discipline2", "y_2=sqrt(y_1)+z_1+z_2"]) x.add_system("OBJ", FUNC, ["Objective", "f=x^2+z_2+y_1+exp(-y_2)"]) x.add_system("G1", FUNC, ["Constraint1", "g_1=3.16-y_1"]) x.add_system("G2", FUNC, ["Constraint2", "g_2=y_2-24"]) x.add_input("D1", "x,z_1,z_2") x.add_input("D2", "z_1,z_2") x.add_input("OBJ", "x,z_2") x.connect("D1", "D2", "y_1") x.connect("D1", "OBJ", "y_1") x.connect("D1", "G1", "y_1") x.connect("D2", "OBJ", "y_2") x.connect("D2", "G2", "y_2") x.connect("D2", "D1", "y_2") x.add_output("OBJ", "f", side="right") x.add_output("G1", "g_1", side="right") x.add_output("G2", "g_2", side="right") x.write("xdsm_sellar")
# x.connect('battery', 'pack',['mass_{cell}','A_{cell}','t_{cell}']) # x.connect('battery', 'transient',['mass_{cell}','A_{cell}']) # PCM x.add_input('PCM',['rho_{foam}','rho_{pcm}','n_{cpk}','n_{kps}']) x.connect('PCM', 'pack',['mass_{pcm}']) x.connect('PCM','transient',['mass_{pcm}']) # HP x.add_input('heat_pipe', ['geometry (round/flat)']) x.connect('heat_pipe', 'pack','mass_{HP}') x.connect('heat_pipe','transient',['L_{hp}']) # Pack Size # x.add_input('pack', ['L_{pack}', 'W_{pack}','L_{cell}', 'W_{cell}', 'H_{cell}', # 'mass_{cell}','voltage_{low,cell}','voltage_{nom,cell}','dischargeRate_{cell}','Q_{max}','V_{batt}']) x.add_input('pack', ['num_{cells}','mass_{cell}']) x.connect('pack','Optimizer',['mass_{pack}','vol_{pack}']) x.connect('pack','transient',['num_{cells}']) x.add_output('pack', ['n_{series}','n_{parallel}'], side='right') # Dymos x.add_input('transient',['geometry (round/flat)']) x.connect('transient','Optimizer','T_{neighbor}') x.write('Design_XDSM') x.write_sys_specs('Design_specs')
x.add_system('G', func, r'$G$', stack=True) x.add_process(['opt', 'D1', 'D2', 'F', 'G', 'opt'], arrow=True) x.connect('opt', 'D1', r'$x, z, y_2$') x.connect('opt', 'D2', r'$z, y_1$') x.connect('opt', 'F', r'$x, z$') x.connect('opt', 'F', r'$y_1, y_2$') # you can also stack variables x.connect('opt', 'G', r'$y_1, y_2$', stack=True) x.connect('D1', 'opt', r'$\mathcal{R}(y_1)$') x.connect('D2', 'opt', r'$\mathcal{R}(y_2)$') x.connect('F', 'opt', r'$f$') x.connect('G', 'opt', r'$g$', stack=True) # can specify inputs to represent external information coming into the XDSM x.add_input('D1', r'$P_1$') x.add_input('D2', r'$P_2$') # 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('G', r'$g^*$', side='right') x.write('idf', cleanup=False)
x.connect("opt", "G2", "z") x.connect("opt", "F", "x, z") x.connect("opt", "F", "y_1, y_2") # you can also stack variables x.connect("opt", "H", "y_1, y_2", stack=True) x.connect("D1", "opt", r"\mathcal{R}(y_1)") x.connect("D2", "opt", r"\mathcal{R}(y_2)") x.connect("F", "opt", "f") x.connect("H", "opt", "h", stack=True) # can specify inputs to represent external information coming into the XDSM x.add_input("D1", "P_1") x.add_input("D2", "P_2") 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_process(["output_opt", "opt", "left_output_opt"]) x.write("kitchen_sink", cleanup=False) x.write_sys_specs("sink_specs")
func = 'Function' x = XDSM() x.add_system('opt', opt, r'\text{Optimizer}') x.add_system('solver', solver, r'\text{Newton}') x.add_system('D1', comp, r'D_1') x.add_system('D2', comp, r'D_2') x.add_system('F', func, r'F') x.add_system('G', func, r'G') x.connect('opt', 'D1', r'x, z') x.connect('opt', 'D2', r'z') x.connect('opt', 'F', r'x, z') x.connect('solver', 'D1', r'y_2') x.connect('solver', 'D2', r'y_1') x.connect('D1', 'solver', r'\mathcal{R}(y_1)') x.connect('solver', 'F', r'y_1, y_2') x.connect('D2', 'solver', r'\mathcal{R}(y_2)') x.connect('solver', 'G', r'y_1, y_2') x.connect('F', 'opt', r'f') x.connect('G', 'opt', r'g') x.add_output('opt', r'x^*, z^*', side='left') 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='left') x.add_output('G', r'g^*', side='left') x.write('mdf')
comp = 'Analysis' group = 'Metamodel' func = 'Function' x = XDSM() x.add_system('d1', comp, r'\TwolineComponent{10em}{Discipline 1}{$y_1 = z_1^2 + z_2 + x_1 - 0.2y_2$}') x.add_system('d2', comp, r'\TwolineComponent{8em}{Discipline 2}{$y_2 = \sqrt{y_1} + z_1 + z_2$}') x.add_system('f', func, r'\TwolineComponent{10em}{Objective}{$f = x^2 + z_1 + y_1 + e^{-y_2}$}') x.add_system('g1', func, r'\TwolineComponent{7em}{Constraint 1}{$g1 = 3.16-y_1 $}') x.add_system('g2', func, r'\TwolineComponent{7em}{Constraint 2}{$g_2 = y_2 - 24.0$}') x.connect('d1', 'd2', r'$y_1$') x.connect('d1', 'f', r'$y_1$') x.connect('d1', 'g1', r'$y_1$') x.connect('d2', 'd1', r'$y_2$') x.connect('d2', 'f', r'$y_2$') x.connect('d2', 'g2', r'$y_2$') x.add_input('d1', r'$x, z_1, z_2$') x.add_input('d2', r'$z_1, z_2$') x.add_input('f', r'$x, z_1$') x.add_output('f', r'$f$', side='right') x.add_output('g1', r'$g_1$', side='right') x.add_output('g2', r'$g_2$', side='right') x.write('sellar_xdsm')
# x.connect('prop_comp', 'cool_comp', r'V_{prop}') x.connect('prop_comp', 'e_comp', r'P_{prop}, N') x.connect('solver', 'aero_comp', r'\alpha') # , V_{\infty} x.connect('solver', 'flight_dynamics', r'\alpha') x.connect('aero_comp', 'flight_dynamics', r'L_{wing}') x.connect('aero_comp', 'EOM_comp', r'D_{wing}') x.connect('flight_dynamics', 'balance', r'\alpha_{LHS}, \alpha_{RHS}') x.connect('balance', 'solver', r'\mathcal{R} \alpha') x.connect('engine_comp', 'DYMOS', r'w_{fuel}^*') # x.connect('e_comp', 'cool_comp', r'Q_{heat 1,2,3...}') x.connect('e_comp', 'engine_comp', r'P_{shaft}, N') # x.connect('cool_comp', 'DYMOS', r'T_{fins}^*') # x.connect('cool_comp', 'drag_comp', 'D_{cool}') # x.connect('drag_comp', 'EOM_comp', r'D_{tot}') x.connect('EOM_comp', 'DYMOS', r'h^*, r^*') x.add_output('DYMOS', r'r,h', side='right') x.add_output('prop_comp', r'P_{prop,max}', side='right') x.add_output('engine_comp', r'T_4', side='right') # x.add_output('cool_comp', r'T_{fins}', side='right') x.write('Mission_XDSM')
x.connect("subopt", "MM", "z_2") x.connect("opt", "G2", "z") x.connect("opt", "F", "x, z") x.connect("opt", "F", "y_1, y_2") # you can also stack variables x.connect("opt", "H", "y_1, y_2", stack=True) x.connect("D1", "opt", r"\mathcal{R}(y_1)") x.connect("D2", "opt", r"\mathcal{R}(y_2)") x.connect("F", "opt", "f") x.connect("H", "opt", "h", stack=True) # can specify inputs to represent external information coming into the XDSM x.add_input("D1", "P_1") x.add_input("D2", "P_2") 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_process(["output_opt", "opt", "left_output_opt"]) x.write("kitchen_sink", cleanup=False) x.write_sys_specs("sink_specs")
x.connect('opt', 'solver', r'T^{t,(0)}') x.connect('opt', 'Qext', r'\Phi, \Psi, \Omega, \alpha') x.connect('opt', 'Power', r'P_{out}') x.connect('opt', 'Temp', r'\epsilon, k') x.connect('opt', 'Fun', r'P_{out}') x.connect('solver', 'Qext', 'T^t') x.connect('solver', 'Power', 'T^t') x.connect('Qext', 'Power', r'Q_{sun}') x.connect('Qext', 'Temp', r'Q_{sun}, Q_{planet}, Q_{alb}') x.connect('Qext', 'Temp', r'Q_{sun}, Q_{planet}, Q_{alb}') x.connect('Power', 'Temp', r'Q_{dis}') x.connect('Power', 'Fun', r'Q_{dis}, P_{el}') x.connect('Temp', 'solver', r'\mathcal{R}(T)') x.connect('Temp', 'Fun', 'T') x.connect('Fun', 'opt', 'f,c') #x.connect('G', 'opt', 'g') x.add_input('opt', r'x_0', stack=True) x.add_output('opt', 'x^*', side='left') x.add_output('Temp', 'T^*', side='left') x.add_output('Qext', r'Q_{sun}^*', side='left', stack=True) x.add_output('Fun', 'f^*, c^*', side='left') x.add_output('Power', r'Q_{dis}^*', side='left') x.add_process(['opt', 'solver', 'Qext', 'Power', 'Temp', 'solver'], arrow=True) x.add_process(['solver', 'Fun', 'opt'], arrow=True) x.write('mdf')
x.add_system('heat_pipe', func, ['Heat pipe'], spec_name=False) # Dymos #x.connect('dymos','Optimizer','T_{neighbor}') x.connect('dymos', 'heat_pipe', 'T_{wall}', stack=True) x.connect('dymos', 'PCM', 'T_{pcm}', stack=True) x.connect('dymos', 'battery', 'T_{cell}', stack=True) # Battery x.add_input('battery', ['rho/cp_{cell}', 'q_{in,cell}']) x.connect('battery', 'PCM', ['q_{in,pcm}'], stack=True) x.connect('battery', 'dymos', 'dT_{cells}/dt', stack=True) # x.add_output('battery', ['n_{series}','n_{parallel}'], side='right') # PCM x.add_input( 'PCM', ['t_{pad}, A_{pad}', 'porosity', 'rho/LH/K/cp_{foam/pcm}', 'T_{hi/lo}']) x.connect('PCM', 'dymos', 'dT_{pcm}/dt', stack=True) x.connect('PCM', 'heat_pipe', 'q_{in,hp}', stack=True) x.connect('PCM', 'battery', 'q_{out,pcm}', stack=True) x.add_output('PCM', ['PS'], side='right', stack=True) # HP x.add_input('heat_pipe', ['geometry (round/flat)', 'num_{cells}']) x.connect('heat_pipe', 'PCM', 'q_{out,hp}', stack=True) x.connect('heat_pipe', 'dymos', 'dT_{wall}/dt', stack=True) x.write('Transient_XDSM') x.write_sys_specs('Transient_specs')