from pyxdsm.matrix_eqn import MatrixEquation ################################ # define the system ################################ lin_system = MatrixEquation() lin_system.add_variable(1, size=1, text="a") lin_system.add_variable(2, size=1, text="b") lin_system.add_variable(3, size=1, text="c") lin_system.add_variable(4, size=2) lin_system.add_variable(5, size=2) lin_system.add_variable(6, size=1, text="d") lin_system.add_variable(7, size=2) lin_system.add_variable(8, size=2) lin_system.add_variable(9, size=1, text="e") lin_system.add_variable(10, size=2) lin_system.add_variable(11, size=2) # variable identifiers can be any hashable object lin_system.add_variable("f", size=1, text="f") lin_system.connect(1, [4, 5, 7, 8, 10, 11]) lin_system.connect(2, [4, 5, 7, 8, 10, 11]) lin_system.connect(3, 4) lin_system.connect(4, 5)
from pyxdsm.matrix_eqn import MatrixEquation ################################ # define the system ################################ lin_system = MatrixEquation() lin_system.add_variable(1, size=1, text="a") lin_system.add_variable(2, size=1, text="b") lin_system.add_variable(3, size=1, text="c") lin_system.add_variable( 4, size=2, ) lin_system.add_variable( 5, size=2, ) lin_system.add_variable(6, size=1, text="d") lin_system.add_variable( 7, size=2, ) lin_system.add_variable( 8, size=2, )
sys.jacobian(transpose=True) sys.spacer() sys.vector(base_color='red', highlight=[2,2,2,2,2]) sys.spacer() sys.operator('=') sys.vector(base_color='green', highlight=[2,1,1,1,1]) sys.write('uncoupled_rev') ############################################ # Coupled Uncoupled System ############################################ sys = MatrixEquation() sys.add_variable(1, size=1) sys.add_variable(2, size=1) sys.add_variable(3, size=2) sys.add_variable(4, size=2) sys.add_variable(5, size=1) sys.connect(1, [2,3,4,5]) sys.connect(2, [5]) sys.connect(3, [2,4,5]) sys.connect(4, [2,5]) sys.connect(5, [2,3,4]) sys.jacobian() sys.spacer() sys.vector(base_color='red', highlight=[2,2,2,2,2])
def build_sys(): sys = MatrixEquation() sys.add_variable(1, size=1) sys.add_variable(2, size=1) sys.add_variable(3, size=2) sys.add_variable(4, size=2) sys.add_variable(5, size=1) sys.connect(1, [2,3,4,5]) sys.connect(2, [3,4,5]) sys.connect(3, [4,5]) sys.connect(4, [5]) return sys
def par_system(): sys = MatrixEquation() sys.add_variable(1, size=2, text=r"\textbf{x}") sys.add_variable(2, size=2, text=r"\textbf{y}") sys.add_variable(3, size=4, text=r"\textbf{s1}", color=IMPLICIT_COLOR) sys.add_variable(3.5, size=1, text=r"\textbf{z1}") sys.add_variable(4, size=4, text=r"\textbf{s2}", color=IMPLICIT_COLOR) sys.add_variable(4.5, size=1, text=r"\textbf{z2}") sys.connect(1, 2) sys.connect(2, [3, 4], color="blue") sys.connect(3, 3.5, color=IMPLICIT_COLOR) sys.connect(4, 4.5, color=IMPLICIT_COLOR) return sys
par = par_system() par.jacobian(transpose=True) par.spacer() par.vector(base_color='red', highlight=[2, 2, 2, 2, 0, 0]) par.vector(base_color='red', highlight=[2, 2, 0, 0, 2, 2]) par.operator('=') par.vector(base_color='red', highlight=[1, 1, 1, 2, 0, 0]) par.vector(base_color='red', highlight=[1, 1, 0, 0, 1, 2]) par.write('parallel_adj_combined') ############################################################# # 2 Color Version ############################################################# sys = MatrixEquation() sys.add_variable(1, size=2, text="x") sys.add_variable(2, size=2, text="y") sys.add_variable(3, size=4, text="s1", color=IMPLICIT_COLOR) sys.add_variable(3.5, size=1, text="a1") sys.add_variable(3.6, size=1, text="b1") sys.add_variable(4, size=4, text="s2", color=IMPLICIT_COLOR) sys.add_variable(4.5, size=1, text="a2") sys.add_variable(4.6, size=1, text="b2") sys.connect(1, 2) sys.connect(2, [3, 4], color="blue") sys.connect(3, [3.5, 3.6], color=IMPLICIT_COLOR) sys.connect(4, [4.5, 4.6], color=IMPLICIT_COLOR)
def simul_system(): simul = MatrixEquation() simul.add_variable(1, size=1, text="a") simul.add_variable(2, size=1, text="b") simul.add_variable(3, size=1, text="c") simul.add_variable( 4, size=2, ) simul.add_variable( 5, size=2, ) simul.add_variable('gc', size=1, text=r"$g_c$") simul.add_variable(6, size=1, text="d") simul.add_variable( 7, size=2, ) simul.add_variable( 8, size=2, ) simul.add_variable('gd', size=1, text=r"$g_d$") simul.add_variable(9, size=1, text="e") simul.add_variable( 10, size=2, ) simul.add_variable( 11, size=2, ) simul.add_variable('ge', size=1, text=r"$g_e$") simul.add_variable(12, size=1, text="f") simul.connect(1, [4, 5, 7, 8, 10, 11, 12, 'gc', 'gd', 'ge']) simul.connect(2, [4, 5, 7, 8, 10, 11, 12, 'gc', 'gd', 'ge']) simul.connect(3, 4) simul.connect(4, 5) simul.connect(5, 4) simul.connect(3, 'gc') simul.connect(4, 'gc') simul.connect(5, 'gc') simul.connect(6, 7) simul.connect(7, 8) simul.connect(8, 7) simul.connect(6, 'gd') simul.connect(7, 'gd') simul.connect(8, 'gd') simul.connect(9, 10) simul.connect(10, 11) simul.connect(11, 10) simul.connect(9, 'ge') simul.connect(10, 'ge') simul.connect(11, 'ge') simul.connect(11, 12) return simul
def par_system(): sys = MatrixEquation() sys.add_variable(1, size=2, text=r"\textbf{x}") sys.add_variable(2, size=2, text=r"\textbf{y}") sys.add_variable(3, size=4, text=r"\textbf{s1}", color=IMPLICIT_COLOR) sys.add_variable(3.5, size=1, text=r"\textbf{z1}") sys.add_variable(4, size=4, text=r"\textbf{s2}", color=IMPLICIT_COLOR) sys.add_variable(4.5, size=1, text=r"\textbf{z2}") sys.connect(1, 2) sys.connect(2, [3,4], color="blue") sys.connect(3, 3.5, color=IMPLICIT_COLOR) sys.connect(4, 4.5, color=IMPLICIT_COLOR) return sys
par.jacobian(transpose=True) par.spacer() par.vector(base_color='red', highlight=[2, 2, 2, 2, 0, 0]) par.vector(base_color='red', highlight=[2, 2, 0, 0, 2, 2]) par.operator('=') par.vector(base_color='red', highlight=[1, 1, 1, 2, 0, 0]) par.vector(base_color='red', highlight=[1, 1, 0, 0, 1, 2]) par.write('parallel_adj_combined') ############################################################# # 2 Color Version ############################################################# sys = MatrixEquation() sys.add_variable(1, size=2, text="x") sys.add_variable(2, size=2, text="y") sys.add_variable(3, size=4, text="s1", color=IMPLICIT_COLOR) sys.add_variable(3.5, size=1, text="a1") sys.add_variable(3.6, size=1, text="b1") sys.add_variable(4, size=4, text="s2", color=IMPLICIT_COLOR) sys.add_variable(4.5, size=1, text="a2") sys.add_variable(4.6, size=1, text="b2") sys.connect(1, 2) sys.connect(2, [3,4], color="blue") sys.connect(3, [3.5, 3.6], color=IMPLICIT_COLOR) sys.connect(4, [4.5, 4.6], color=IMPLICIT_COLOR)