Skip to content

Commit

Permalink
Merge pull request #11 from onodip/colors
Browse files Browse the repository at this point in the history
Color update
  • Loading branch information
ewu63 authored Nov 30, 2019
2 parents cb13428 + ce29f94 commit 735a5bd
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 189 deletions.
47 changes: 21 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pyXDSM

A python library for generating publication quality PDF XDSM diagrams.
This library is a thin wrapper that uses the TIKZ library and LaTeX to build the PDFs.
This library is a thin wrapper that uses the TikZ library and LaTeX to build the PDFs.

# Installation
Clone this repo or download the zip and unzip it.
Expand All @@ -27,50 +27,45 @@ If you would like a citation for XDSM, here is the bibtex for that paper:
}


## TIKZ and LaTeX?
## TikZ and LaTeX?
You need to install these libraries for pyXDSM to work. See the [install guide](https://www.latex-project.org/get/) for your platform

## How do I use it?
Here is a simple example. There are some other more advanced things you can do as well. Check out the [examples folder](https://github.com/mdolab/pyXDSM/blob/master/examples)
```python
from pyxdsm.XDSM import XDSM

#
opt = 'Optimization'
solver = 'MDA'
comp = 'Analysis'
group = 'Metamodel'
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.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', r'y_1, y_2')
x.connect('solver', 'F', 'y_1, y_2')
x.connect('D2', 'solver', r'\mathcal{R}(y_2)')
x.connect('solver', 'G', r'y_1, y_2')

x.connect('solver', 'G', 'y_1, y_2')

x.connect('F', 'opt', r'f')
x.connect('G', 'opt', r'g')
x.connect('F', 'opt', 'f')
x.connect('G', 'opt', '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.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')
```
![XDSM of MDF](https://github.com/mdolab/pyXDSM/blob/master/images_for_readme/mdf.png)
Expand Down
Binary file added examples/kitchen_sink.pdf
Binary file not shown.
57 changes: 34 additions & 23 deletions examples/kitchen_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,68 @@

# styling names for the boxes
opt = 'Optimization'
subopt = 'SubOptimization'
solver = 'MDA'
ecomp = 'Analysis'
icomp = 'ImplicitAnalysis'
group = 'Metamodel'
doe = 'DOE'
ifunc = 'ImplicitFunction'
func = 'Function'
group = 'Group'
igroup = 'ImplicitGroup'
metamodel = 'Metamodel'

x = XDSM()

x.add_system('opt', opt, r'\text{Optimizer}')
x.add_system('D1', ecomp, r'D_1')
x.add_system('DOE', doe, r'\text{DOE}')
x.add_system('MDA', solver, r'\text{Newton}')
x.add_system('D1', func, 'D_1')

# can fade out blocks to allow for emphasis on sub-sections of XDSM
x.add_system('D2', icomp, r'D_2', faded=True)
x.add_system('D2', ifunc, 'D_2', faded=True)

# can fade out blocks to allow for emphasis on sub-sections of XDSM
x.add_system('D3', icomp, r'D_3')
x.add_system('D3', ifunc, 'D_3')
x.add_system('subopt', subopt, 'SubOpt')
x.add_system('G1', group, 'G_1')
x.add_system('G2', igroup, 'G_2')
x.add_system('MM', metamodel, 'MM')

# if you give the label as a list or tuple, it splits it onto multiple lines
x.add_system('F', func, (r'F', r'\text{Functional}'))
x.add_system('F', func, ('F', r'\text{Functional}'))

# stacked can be used to represent multiple instances that can be run in parallel
x.add_system('G', func, r'G', stack=True)

x.add_process(['opt', 'D1', 'D2', 'F', 'G', 'opt'], arrow=True)
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.connect('opt', 'D1', r'x, z, y_2')
x.connect('opt', 'D2', r'z, y_1')
x.connect('opt', 'D3', r'z, y_1')
x.connect('opt', 'F', r'x, z')
x.connect('opt', 'F', r'y_1, y_2')
x.connect('opt', 'D1', 'x, z, y_2')
x.connect('opt', 'D2', 'z, y_1')
x.connect('opt', 'D3', 'z, y_1')
x.connect('opt', 'subopt', 'z, y_1')
x.connect('subopt', 'G1', 'z_2')
x.connect('subopt', 'G2', 'z_2')
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', 'G', r'y_1, y_2', stack=True)
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', r'f')
x.connect('G', 'opt', r'g', stack=True)
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', r'P_1')
x.add_input('D2', r'P_2')
x.add_input('D1', 'P_1')
x.add_input('D2', '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.add_output('H', r'h^*', side='right')

x.write('kitchen_sink', cleanup=False)
10 changes: 5 additions & 5 deletions examples/mat_eqn.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
# 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(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)
Expand All @@ -46,11 +46,11 @@
################################
lin_system.jacobian()
lin_system.spacer()
lin_system.vector(base_color='red', highlight=[0,0,2,2,2,0,0,0,0,0,0,0])
lin_system.vector(base_color='red', highlight=[0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0])
lin_system.spacer()
lin_system.vector(base_color='red', highlight=[0,0,0,0,0,2,2,2,0,0,0,0])
lin_system.vector(base_color='red', highlight=[0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0])
lin_system.spacer()
lin_system.vector(base_color='red', highlight=[0,0,0,0,0,0,0,0,2,2,2,2])
lin_system.vector(base_color='red', highlight=[0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2])
lin_system.spacer()
lin_system.operator('=')
lin_system.vector(base_color='green', highlight=[1,1,2,1,1,1,1,1,1,1,1,1])
Expand Down
Binary file modified examples/mat_eqn_example.pdf
Binary file not shown.
Binary file modified examples/mdf.pdf
Binary file not shown.
43 changes: 19 additions & 24 deletions examples/mdf.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
from pyxdsm.XDSM import XDSM

#
opt = 'Optimization'
solver = 'MDA'
comp = 'Analysis'
group = 'Metamodel'
func = 'Function'

# 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', 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.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', r'y_1, y_2')
x.connect('solver', 'F', 'y_1, y_2')
x.connect('D2', 'solver', r'\mathcal{R}(y_2)')
x.connect('solver', 'G', r'y_1, y_2')

x.connect('solver', 'G', 'y_1, y_2')

x.connect('F', 'opt', r'f')
x.connect('G', 'opt', r'g')
x.connect('F', 'opt', 'f')
x.connect('G', 'opt', '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.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')
Binary file modified images_for_readme/kitchen_sink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images_for_readme/mdf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 735a5bd

Please sign in to comment.