Skip to content
Snippets Groups Projects
Commit 874dcbfd authored by Ashwin Vishnu's avatar Ashwin Vishnu
Browse files

Reorganize and extend fluidsim, add abstract, new fig 1 etc (not over yet)

parent 34e27542
No related branches found
No related tags found
No related merge requests found
......@@ -23,8 +23,8 @@
@article{fluidsim,
author = "Ashwin Vishnu Mohanan and Cyrille Bonamy and Pierre Augier",
year = "2018",
title = "FluidSim: modular, object-oriented Python package for CFD
simulations",
title = "FluidSim: modular, object-oriented Python package for
high-performance CFD simulations",
journal = "J. Open Research Software",
volume = "?",
pages = "?"
......
digraph {
graph [bgcolor=white fontcolor=black fontsize=14 label="" layout=circo overlap=prism overlap_scaling=3.5 pack=True rankdir=BT]
node [color=black fillcolor=steelblue fontcolor=white fontname=monospace shape=hexagon style=filled]
edge [arrowhead=open color=black fontcolor=white fontname=Courier fontsize=12 style=solid]
sim
{
graph [bgcolor=white fontcolor=black fontsize=14 label="" overlap=prism pack=True rankdir=BT]
node [color=black fillcolor=black fontcolor=white fontname="DejaVu Sans" shape=rect style="rounded, filled"]
edge [arrowhead=open color=black fontcolor=white fontname=Courier fontsize=12 style=solid]
info_solver
params
info
oper
output
state
time_stepping
init_fields
preprocess
sim -> info_solver
sim -> params
sim -> info
sim -> oper
sim -> output
sim -> state
sim -> time_stepping
sim -> init_fields
sim -> preprocess
}
{
graph [bgcolor=white fontcolor=black fontsize=14 label="" overlap=prism pack=True rankdir=BT]
node [color=black fillcolor=black fontcolor=white fontname="DejaVu Sans" shape=rect style="rounded, filled"]
edge [arrowhead=open color=black fontcolor=white fontname=Courier fontsize=12 style=solid]
sim
params
oper
print_stdout
phys_fields
spectra
increments
spatial_means
spect_energy_budg
output -> sim
output -> params
output -> oper
output -> print_stdout
output -> phys_fields
output -> spectra
output -> increments
output -> spatial_means
output -> spect_energy_budg
}
{
graph [bgcolor=white fontcolor=black fontsize=14 label="" overlap=prism pack=True rankdir=BT]
node [color=black fillcolor=beige fontcolor=black fontname="DejaVu Sans" shape=rect style="rounded,filled"]
edge [arrowhead=open color=black fontcolor=white fontname=Courier fontsize=12 style=dashed]
operdealiasing [label=dealiasing]
operfft_as_arg [label=fft_as_arg]
operifft_as_arg [label=ifft_as_arg]
operrandom_arrayK [label=random_arrayK]
operrotfft_from_vecfft [label=rotfft_from_vecfft]
oper -> operdealiasing
oper -> operfft_as_arg
oper -> operifft_as_arg
oper -> operrandom_arrayK
oper -> operrotfft_from_vecfft
statecompute [label=compute]
statestatefft_from_statephys [label=statefft_from_statephys]
statestatephys_from_statefft [label=statephys_from_statefft]
state -> statecompute
state -> statestatefft_from_statephys
state -> statestatephys_from_statefft
time_steppingstart [label=start]
time_stepping -> time_steppingstart
tendencies_nonlinsim [label=tendencies_nonlin]
sim -> tendencies_nonlinsim
animatephys_fields [label=animate]
plotphys_fields [label=plot]
phys_fields -> animatephys_fields
phys_fields -> plotphys_fields
animatespectra [label=animate]
computespectra [label=compute]
plot1dspectra [label=plot1d]
plot2dspectra [label=plot2d]
spectra -> animatespectra
spectra -> computespectra
spectra -> plot1dspectra
spectra -> plot2dspectra
computeincrements [label=compute]
plotincrements [label=plot]
increments -> computeincrements
increments -> plotincrements
plotspatial_means [label=plot]
spatial_means -> plotspatial_means
computespect_energy_budg [label=compute]
plotspect_energy_budg [label=plot]
spect_energy_budg -> computespect_energy_budg
spect_energy_budg -> plotspect_energy_budg
}
}
fluidsim/Pyfig/fig_simul_obj.png

175 KiB

import functools
import os
import graphviz as gv
from imageio import imread
import matplotlib.pyplot as plt
class Digraph(object):
GraphClass = gv.Digraph
def __init__(self, path_file=None, label=''):
self.path_file = path_file
if path_file is None:
self.graph = self.GraphClass()
self.render = self.graph.render
else:
filename, ext = os.path.splitext(path_file)
ext = ext.split('.')[-1]
self.graph = self.GraphClass(format=ext)
self.render = functools.partial(self.graph.render, filename=filename)
# Function aliases
self.add_node = self.graph.node
self.add_edge = self.graph.edge
self.styles = {
'graph': {
'label': label,
'fontsize': '14',
'fontcolor': 'black',
'bgcolor': 'white',
'rankdir': 'BT',
'overlap': 'prism',
'pack': 'True',
},
'nodes': {
'fontname': 'DejaVu Sans',
'shape': 'rect',
'fontcolor': 'white',
'color': 'black',
'style': 'rounded, filled',
'fillcolor': 'white',
},
'edges': {
'style': 'solid',
'color': 'black',
'arrowhead': 'open',
'fontname': 'Courier',
'fontsize': '12',
'fontcolor': 'white',
}
}
def __repr__(self):
return self.graph.source
def add_nodes(self, nodes):
graph = self.graph
for n in nodes:
if isinstance(n, tuple):
graph.node(n[0], **n[1])
else:
graph.node(n)
def add_edges(self, edges):
graph = self.graph
for e in edges:
if isinstance(e[0], tuple):
graph.edge(*e[0], **e[1])
else:
graph.edge(*e)
def add_graph(self, other):
if isinstance(other, self.__class__):
self.graph.subgraph(other.graph)
elif isinstance(other, gv.Digraph):
self.graph.subgraph(other)
def apply_styles(self, styles=None):
if styles is None:
styles = self.styles
graph = self.graph
graph.graph_attr.update(
('graph' in styles and styles['graph']) or {}
)
graph.node_attr.update(
('nodes' in styles and styles['nodes']) or {}
)
graph.edge_attr.update(
('edges' in styles and styles['edges']) or {}
)
return graph
def show(self):
try:
img = imread(self.path_file)
except:
img = plt.imread(self.path_file)
plt.imshow(img)
plt.show()
class Graph(Digraph):
GraphClass = gv.Graph
#!/usr/bin/env python
import types
import shutil
from fluidsim.solvers.ns2d.solver import Simul
from easygraph import Digraph
from base import curdir
g = Digraph(curdir + '/../Pyfig/fig_simul_obj.png')
g_sim = Digraph() # all objects attached to sim.
g_out = Digraph() # sim.output.
g_doc = Digraph() # first line of __doc__
g_met = Digraph() # methods
def filter_object_dict(obj):
return dict(
[(key, attr) for key, attr in obj.__dict__.items()
if not isinstance(attr, (types.MethodType, str, bool))])
def match(method_name):
exact_match = [
'fft_as_arg', 'ifft_as_arg', 'tendencies_nonlin', 'compute', 'plot',
'dealiasing', 'random_arrayK', 'rotfft_from_vecfft', 'animate',
'statephys_from_statefft', 'statefft_from_statephys', 'plot1d',
'plot2d', 'start'
]
partially_match = [
]
if method_name in exact_match:
return method_name
elif any((name in method_name for name in partially_match)):
return method_name
else:
return None
def filter_method_dict(obj):
return dict(
[(key, getattr(obj, key)) for key in dir(obj)
if isinstance(getattr(obj, key), (types.FunctionType, types.MethodType, types.BuiltinMethodType)) and
match(key) is not None])
params = Simul.create_default_params()
with Simul(params) as sim:
sim_dict = filter_object_dict(sim)
output_dict = filter_object_dict(sim.output)
sim_methods = {}
output_methods = {}
for key, attr in sim_dict.items():
sim_methods[key] = filter_method_dict(attr)
for key, attr in output_dict.items():
output_methods[key] = filter_method_dict(attr)
# Avoid duplicates
del output_methods['oper']
# print(sim.info)
shutil.rmtree(sim.output.path_run)
g.add_node('sim')
g.styles['graph']['layout'] = 'circo'
g.styles['graph']['overlap'] = 'prism'
g.styles['graph']['overlap_scaling'] = '3.5'
g.styles['nodes']['fontname'] = 'monospace'
g.styles['nodes']['fillcolor'] = 'steelblue'
g.styles['nodes']['shape'] = 'hexagon'
g.styles['nodes']['style'] = 'filled'
g.apply_styles()
g_sim.add_nodes(sim_dict.keys())
g_sim.styles['nodes']['fillcolor'] = 'black'
g_sim.apply_styles()
g_sim.add_edges([('sim', key) for key in sim_dict])
g_out.add_nodes(output_dict.keys())
g_out.styles['nodes']['fillcolor'] = 'black'
g_out.apply_styles()
g_out.add_edges([('output', key) for key in output_dict])
g_doc.add_nodes(
[('doc' + key, {'label': str(attr.__doc__).splitlines()[0]})
for key, attr in sim_dict.items()])
g_doc.styles['nodes']['fillcolor'] = 'gray'
g_doc.styles['nodes']['fontcolor'] = 'black'
g_doc.styles['edges']['style'] = 'dashed'
g_doc.apply_styles()
g_doc.add_edges([(key, 'doc' + key) for key in sim_dict])
for node, node_methods in sim_methods.items():
g_met.add_nodes([(node + key, {'label': key}) for key in node_methods])
g_met.add_edges([(node, node + key) for key in node_methods])
for node, node_methods in output_methods.items():
g_met.add_nodes([(key + node, {'label': key}) for key in node_methods])
g_met.add_edges([(node, key + node) for key in node_methods])
g_met.styles['nodes']['fontcolor'] = 'black'
g_met.styles['nodes']['shape'] = 'rect'
g_met.styles['nodes']['style'] = 'bold'
g_met.styles['nodes']['fillcolor'] = 'beige'
g_met.styles['nodes']['style'] = 'rounded,filled'
# g_met.styles['nodes']['style'] = 'radial'
g_met.styles['edges']['style'] = 'dashed'
g_met.apply_styles()
g.add_graph(g_sim)
g.add_graph(g_out)
g.add_graph(g_met)
# g.add_graph(g_doc)
print(g)
g.render()
g.show()
This diff is collapsed.
......@@ -79,6 +79,8 @@
\usepackage{fancyref}
\usepackage{minted}
\usepackage{booktabs}
\usepackage{outlines}
\usepackage{natbib}
\usepackage{har2nat}
......@@ -109,4 +111,4 @@
\newcommand{\pack}[1]{\codeinline{#1}}
\endinput
\ No newline at end of file
\endinput
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment