Skip to content

Commit

Permalink
Added the possibilty to plot logfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAnderegg committed Jul 1, 2021
1 parent 5a85f93 commit dbcf446
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ This package provides some convenience functions for [ADflow](https://github.com
1. Easily calculate a Polar sweep with ADflow.
2. Automatically create the **output** folder for ADflow.
3. Automatically restart ADflow if there is a solution available.
2. Plot realtime ADflow state variables in the terminal.
4. Plot realtime ADflow state variables in the terminal.
5. Plot ADflow state variables from a logfile


# Usage
Expand Down Expand Up @@ -41,9 +42,9 @@ solverOptions = {
au = ADFLOW_UTIL(aeroOptions, solverOptions, options)
au.run()
```
The dict **aeroOptions** holds all the variables that normally **baseclasses.AeroProblem** would. If one variable is a list, this is considered the sweep variable. All variables except **coefPol, cosCoefFourier, sinCoefFourier, momentAxis, solverOptions, evalFuncs** can be sweeped.
The dict **aeroOptions** holds all the variables that normally **baseclasses.AeroProblem** would. If one variable is a list, this is considered the sweep variable. All variables except **coefPol, cosCoefFourier, sinCoefFourier, momentAxis, solverOptions, evalFuncs** can be sweeped.

The dict **options** holds some ADFLOW_UTIL specific options. More about them can be found
The dict **options** holds some ADFLOW_UTIL specific options. More about them can be found
[here](https://github.com/DavidAnderegg/adflow_util/blob/master/adflow_util/adflow_util.py#L52).

This script will generate a file called *n0012_sweep.out* with this content:
Expand All @@ -59,7 +60,7 @@ evalFuncs cl, cd, cmz
RESULTS
RESULTS
alpha cd cl cmz totalRes iterTot
------- ---------- ---------- ---------- ---------- ---------
1 0.01011288 0.11602992 0.00066774 0.00085824 633
Expand All @@ -73,9 +74,9 @@ It is also possible to have multiple sweep variables. But all must have the same


## adflow_plot
If this package was installed using pip, the command **adflow_plot** should be available in your terminal. To use it, simply type **adflow_plot -i yourADflowScript.py**. As this utility reads the stdout stream, it should work with all scripts as long as the ADflow option **printIterations** is **True**.
If this package was installed using pip, the command **adflow_plot** should be available in your terminal. To use it, simply type **adflow_plot -i yourADflowScript.py**. As this utility reads the stdout stream, it should work with all scripts as long as the ADflow option **printIterations** is **True**.

If you want to parallelize your ADflow calculation, simply add **-np number_of_cores** oder **-H list_of_nodes**. As a default, **mpirun** is used to start mpi. If you have a different installation of mpi, you can change it with **-mpi some_different_mpi_command**. Type **adflow_plot -h** to get a list of all available start options.
If you want to parallelize your ADflow calculation, simply add **-np number_of_cores** oder **-H list_of_nodes**. As a default, **mpirun** is used to start mpi. If you have a different installation of mpi, you can change it with **-mpi some_different_mpi_command**. Type **adflow_plot -h** to get a list of all available start options.


The output looks something like this:
Expand All @@ -88,6 +89,10 @@ To close it, type **q** or **quit**.

Type **h** or **help** to get a list of all commands. type **h a_command** oder **help a_command** to get additional information about this specific command.

### Plot a logfile
If the inputfile does not end with **.py** it is assumed to be a logfile. The file is read continously with
the linux-command **tail -f**. This makes it possible to plot the variables allmost in realtime while
the script is executed on a cluster for example.


# Installation
Expand All @@ -105,4 +110,4 @@ If you find any bugs and/or you have ideas that I could add, file an issue on gi
# Acknowledgements
This package uses a modified version of **plotext**. The raw package is available at https://github.com/piccolomo/plotext.

The Naca0012 Grid in the example folder is from https://github.com/mdolab/MACH-Aero.
The Naca0012 Grid in the example folder is from https://github.com/mdolab/MACH-Aero.
35 changes: 29 additions & 6 deletions adflow_util/adflow_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ class ADFlowPlot():
"""

def __init__(self):
# self.screen = None
self.commandBuffer = CommandBuffer()
self.screenBuffer = ScreenBuffer()
self.adData = ADflowData()
Expand Down Expand Up @@ -256,7 +255,7 @@ def cleanup(self):
curses.endwin()

def main_loop(self):
self.adData.start_adflow()
self.adData.start()
while not self._exit:
t0 = time.time()

Expand All @@ -269,7 +268,7 @@ def main_loop(self):
self.screenBuffer.scr_cols = cols
self.screenBuffer.scr_rows = rows
self.screenBuffer.message = self.message
self.screenBuffer.command = self.commandBuffer
self.screenBuffer.command_active = self.commandBuffer.get_active()
self.screenBuffer.adflow_stdout_len = len(self.adData.stdout_lines)
if len(self.adData.adflow_vars) > 0:
self.screenBuffer.adflow_iter_len = len(self.adData.adflow_vars['Iter'])
Expand Down Expand Up @@ -351,10 +350,7 @@ def print_labels(self, cols, rows):
labels = []
max_len_label = 0
for var, color in self._plot_vars.items():
# label = [color]
# label = (color, '')
if self._plot_log:
# label.append('• log({})'.format(var))
txt = '• log({})'.format(var)
else:
txt = '• {}'.format(var)
Expand Down Expand Up @@ -924,6 +920,33 @@ def reset_vars(self):
self.adflow_vars_raw = OrderedDict()
self.hist_iteration += 1

def start(self):
"""
This Kickstarts the whole process
if the inputfile is a py-file, it gets executed, otherwise it is treated like a log-file
"""

_, file_extension = os.path.splitext(self.args.inputfile)
if file_extension == '.py':
self.start_adflow()
return

self.start_logfile()

def start_logfile(self):
self.adflow_process = subprocess.Popen(
['tail', '-f', '-n', '+1', self.args.inputfile],
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
bufsize=1, close_fds=ON_POSIX)

# Pipe thread
self.adflow_thread = threading.Thread(
target=enqueue_output, args=(self.adflow_process.stdout, self.adflow_queue))
self.adflow_thread.daemon = True # thread dies with the program
self.adflow_thread.start()

def start_adflow(self):
# run adflow script
command = self.create_adflow_run_command()
Expand Down

0 comments on commit dbcf446

Please sign in to comment.