diff --git a/anisotropy/core/runner.py b/anisotropy/core/runner.py index 69e5840..bf1b317 100644 --- a/anisotropy/core/runner.py +++ b/anisotropy/core/runner.py @@ -132,8 +132,13 @@ class UltimateRunner(object): params["label"], params["direction"], params["alpha"] )) filename = "shape.step" + shapepath = path.join(self.casepath(), filename) timer = Timer() + if path.exists(shapepath) and shapeParams.shapeStatus == "done" and not self.config["overwrite"]: + logger.info("Shape exists. Skipping ...") + return + shape = { "simple": Simple, "bodyCentered": BodyCentered, @@ -189,8 +194,13 @@ class UltimateRunner(object): params["label"], params["direction"], params["alpha"] )) filename = "mesh.mesh" + meshpath = path.join(self.casepath(), filename) timer = Timer() + if path.exists(meshpath) and meshParams.meshStatus == "done" and not self.config["overwrite"]: + logger.info("Mesh exists. Skipping ...") + return + if not self.shape: shapefile = "shape.step" filepath = path.join(self.casepath(), shapefile) diff --git a/anisotropy/gui/settings.py b/anisotropy/gui/settings.py index da3c968..c61f420 100644 --- a/anisotropy/gui/settings.py +++ b/anisotropy/gui/settings.py @@ -24,12 +24,20 @@ layout = html.Div([ is_open = False, style = message ), - + dbc.Alert( + id = "general-status", + duration = 10000, + dismissable = True, + is_open = False, + style = message + ), # General html.H2("General"), html.Hr(), - html.P("Path: {}".format(os.environ.get("ANISOTROPY_CWD", ""))), - dbc.Button("Save", id = "submit", style = minWidth), + html.P("Path"), + dcc.Input(id = "cwd", style = { "min-width": "500px" }), + html.Br(), + dbc.Button("Save general", id = "general-save", style = minWidth), # Options html.H2("Options"), @@ -42,6 +50,7 @@ layout = html.Div([ options = [ { "label": k, "value": k } for k in ["all", "shape", "mesh", "flow", "postProcess"] ], style = minWidth ), + dbc.Button("Save", id = "submit", style = minWidth), # Cases html.H2("Cases"), @@ -54,6 +63,29 @@ layout = html.Div([ # Callbacks ## @app.callback( + Output("general-status", "children"), + Output("general-status", "is_open"), + Output("general-status", "color"), + [ Input("general-save", "n_clicks") ], + [ + State("cwd", "value"), + ], + prevent_initial_call = True +) +def generalSave(clicks, cwd): + if not os.path.abspath(cwd): + return "Cwd path must be absolute", True, "danger" + + if cwd[-1] == "/": + cwd = cwd[ :-1] + + os.environ["ANISOTROPY_CWD"] = cwd + + return "General settings saved", True, "success" + + +@app.callback( + Output("cwd", "value"), Output("nprocs", "value"), Output("stage", "value"), Output("cases", "value"), @@ -69,7 +101,7 @@ def settingsLoad(pathname): if os.path.exists(filepath): config.load(filepath) - return config["nprocs"], config["stage"], toml.dumps(config.content) + return os.environ["ANISOTROPY_CWD"], config["nprocs"], config["stage"], toml.dumps(config.content) @app.callback( diff --git a/anisotropy/gui/visualization.py b/anisotropy/gui/visualization.py index 75264ce..e3e3a49 100644 --- a/anisotropy/gui/visualization.py +++ b/anisotropy/gui/visualization.py @@ -71,6 +71,22 @@ class MeshRepresentation(object): return representation +def databaseColumns(): + from anisotropy.database import Database + import re + + db = Database() + idcol = re.compile(r"\s*_id") + columns = [] + + for table in db.tables: + for column in table._meta.columns.keys(): + if not idcol.search(column): + columns.append(column) + + return columns + + ### # Layout ## @@ -151,7 +167,7 @@ plotcontrols = html.Div([ html.P("Data"), dcc.Dropdown( id = "plot-data", - options = [ { "label": v, "value": v } for v in [ "porosity",] ], + options = [ { "label": v, "value": v } for v in databaseColumns() ], value = "porosity", ), html.Br(), @@ -233,9 +249,15 @@ def plotDraw(clicks, execution, structure, direction, data): else: break + if direction == "all": + select = (models.Shape.alpha, column, models.Shape.direction) + + else: + select = (models.Shape.alpha, column) + query = ( models.Shape - .select(models.Shape.alpha, column) + .select(*select) .join(models.Execution, JOIN.LEFT_OUTER) .switch(models.Shape) .join(models.Mesh, JOIN.LEFT_OUTER) @@ -243,15 +265,20 @@ def plotDraw(clicks, execution, structure, direction, data): .where( models.Shape.exec_id == execution, models.Shape.label == structure, - models.Shape.direction == json.loads(direction), ) ) - print(query.sql()) + + if not direction == "all": + query = qeury.where(models.Shape.direction == json.loads(direction)) with db: if query.exists(): table = [] for row in query.dicts(): + for k in row.keys(): + if type(row[k]) == list: + row[k] = str(row[k]) + table.append(row) else: @@ -273,6 +300,12 @@ def plotDraw(clicks, execution, structure, direction, data): fig = px.line( DataFrame(table), x = "alpha", y = data, title = structure, markers = True ) + + if direction == "all": + fig = px.line( + DataFrame(table), x = "alpha", y = data, title = structure, markers = True, color = "direction" + ) + fig.layout.template = "custom_dark" fig.update_xaxes(showline=True, linewidth=1, linecolor='#4f687d', mirror=True) fig.update_yaxes(showline=True, linewidth=1, linecolor='#4f687d', mirror=True)