From 3f8d79896530d1b295c0c9569ed0e33ab6de3306 Mon Sep 17 00:00:00 2001 From: L-Nafaryus Date: Tue, 24 Aug 2021 17:30:42 +0500 Subject: [PATCH] Mod: cli + fix some mistakes --- anisotropy/__init__.py | 3 +- anisotropy/core/cli.py | 110 ++++-- anisotropy/core/database.py | 11 +- anisotropy/core/main.py | 2 +- anisotropy/core/models.py | 1 - anisotropy/samples/simple.py | 6 +- docs/source/static/deps.svg | 418 +++++++++++++++++++++ docs/source/static/er-diagram.svg | 587 ++++++++++++++++++++++++++++++ notes/images.rst | 11 + requirements.txt | 2 + 10 files changed, 1113 insertions(+), 38 deletions(-) create mode 100644 docs/source/static/deps.svg create mode 100644 docs/source/static/er-diagram.svg create mode 100644 notes/images.rst diff --git a/anisotropy/__init__.py b/anisotropy/__init__.py index fb77c9e..cfb6c87 100644 --- a/anisotropy/__init__.py +++ b/anisotropy/__init__.py @@ -21,7 +21,8 @@ env = dict( env.update( BUILD = os.path.join(env["ROOT"], "build"), LOG = os.path.join(env["ROOT"], "logs"), - CONFIG = os.path.join(env["ROOT"], "anisotropy/config/default.toml") + CONFIG = os.path.join(env["ROOT"], "anisotropy/config/default.toml"), + DOCS = os.path.join(env["ROOT"], "docs") ) env.update( logger_name = "anisotropy", diff --git a/anisotropy/core/cli.py b/anisotropy/core/cli.py index 87a8757..3c01109 100644 --- a/anisotropy/core/cli.py +++ b/anisotropy/core/cli.py @@ -4,6 +4,7 @@ import click import ast +import os class LiteralOption(click.Option): def type_cast_value(self, ctx, value): @@ -75,7 +76,7 @@ def anisotropy(): help = "Current computation stage" ) @click.option( - "-P", "--parallel", "parallel", + "-N", "--nprocs", "nprocs", type = click.INT, default = 1, help = "Count of parallel processes" @@ -87,16 +88,16 @@ def anisotropy(): cls = KeyValueOption, help = "Overwrite existing parameter (except control variables)" ) -def compute(stage, parallel, params): +def compute(stage, nprocs, params): from anisotropy.core.main import Anisotropy, logger - from anisotropy.core.utils import timer + from anisotropy.core.utils import timer, parallel args = dict() for param in params: args.update(param) - + ### model = Anisotropy() model.db.setup() @@ -106,37 +107,65 @@ def compute(stage, parallel, params): for entry in paramsAll: model.db.update(entry) - type, direction, theta = args["type"], args["direction"], args["theta"] + ### + def computeCase(stage, type, direction, theta): + case = Anisotropy() + case.load(type, direction, theta) + case.evalParams() + case.update() + + if stage == "all" or stage == "mesh": + (out, err, returncode), elapsed = timer(case.computeMesh)() + + click.echo(out) + click.echo(err) + + case.load(type, direction, theta) + + if case.params.get("meshresult"): + case.params["meshresult"]["calculationTime"] = elapsed + case.update() + + if returncode: + logger.error("Mesh computation failed. Skipping flow computation ...") + return + + if stage == "all" or stage == "flow": + (out, err, returncode), elapsed = timer(case.computeFlow)() + + click.echo(out) + click.echo(err) + + case.load(type, direction, theta) + + if case.params.get("flowresult"): + case.params["flowresult"]["calculationTime"] = elapsed + case.update() + + if returncode: + logger.error("Flow computation failed.") + return + + + ### + params = model.db.loadGeneral( + args.get("type"), + args.get("direction"), + args.get("theta") + ) + queueargs = [] - - model.load(type, direction, theta) - # TODO: merge cli params with db params here - model.evalParams() - model.update() + for p in params: + s = p["structure"] - # TODO: single compute / queue - - if stage == "all" or stage == "mesh": - ((out, err, code), elapsed) = timer(model.computeMesh)() + queueargs.append((stage, s["type"], s["direction"], s["theta"])) - if out: click.echo(out) - if err: click.echo(err) + if nprocs == 1: + for pos, qarg in enumerate(queueargs): + computeCase(*qarg) - if model.params.get("meshresult"): - model.load(type, direction, theta) - model.params["meshresult"]["calculationTime"] = elapsed - model.update() - - if stage == "all" or stage == "flow": - ((out, err, code), elapsed) = timer(model.computeFlow)() - - if out: click.echo(out) - if err: click.echo(err) - - if model.params.get("flowresult"): - model.load(type, direction, theta) - model.params["flowresult"]["calculationTime"] = elapsed - model.update() + else: + parallel(nprocs, queueargs, computeCase) @anisotropy.command( @@ -175,6 +204,25 @@ def computemesh(root, type, direction, theta): model.genmesh() +@anisotropy.command( + help = """Build documentation + + TARGET is the builder to use (default: html) + """ +) +@click.argument( + "target", + default = "html" +) +def docs(target): + from sphinx.cmd.make_mode import run_make_mode + from anisotropy import env + + sourcepath = os.path.join(env["DOCS"], "source") + buildpath = os.path.join(env["DOCS"], "build") + + run_make_mode([target, sourcepath, buildpath]) + ### # CLI entry ## diff --git a/anisotropy/core/database.py b/anisotropy/core/database.py index 86c2265..f06616a 100644 --- a/anisotropy/core/database.py +++ b/anisotropy/core/database.py @@ -107,7 +107,7 @@ class Database(object): return params - def loadGeneral(self) -> list: + def loadGeneral(self, type: str = None, direction: list = None, theta: float = None) -> list: query = ( Structure .select() @@ -115,6 +115,15 @@ class Database(object): ) response = [] + if type: + query = query.where(Structure.type == type) + + if direction: + query = query.where(Structure.direction == str(direction)) + + if theta: + query = query.where(Structure.theta == theta) + for entry in query.dicts(): response.append({ "structure": entry }) diff --git a/anisotropy/core/main.py b/anisotropy/core/main.py index f21a0df..078e6bd 100644 --- a/anisotropy/core/main.py +++ b/anisotropy/core/main.py @@ -356,7 +356,7 @@ class Anisotropy(object): )) else: - logger.error(errors) + logger.error(err) p["meshresult"].update( status = "Failed", diff --git a/anisotropy/core/models.py b/anisotropy/core/models.py index b07dd5c..6c2c631 100644 --- a/anisotropy/core/models.py +++ b/anisotropy/core/models.py @@ -18,7 +18,6 @@ db = SqliteDatabase( field_types = { "list": "text" } ) - class BaseModel(Model): class Meta: database = db diff --git a/anisotropy/samples/simple.py b/anisotropy/samples/simple.py index 4779301..d29bcc3 100644 --- a/anisotropy/samples/simple.py +++ b/anisotropy/samples/simple.py @@ -97,13 +97,13 @@ class Simple(object): point = [] xl, yw, zh = -self.L - self.L / 6, -self.L - self.L / 6, -self.L / 6 - point.append((L + xl, self.L + yw, self.L + zh)) + point.append((self.L + xl, self.L + yw, self.L + zh)) point.append((5 * self.L / 3 + xl, 2 * self.L / 3 + yw, 2 * self.L / 3 + zh)) point.append((2 * self.L + xl, self.L + yw, 0 + zh)) point.append((5 * self.L / 3 + xl, 5 * self.L / 3 + yw, -self.L / 3 + zh)) - point.append((L + xl, 2 * self.L + yw, 0 + zh)) + point.append((self.L + xl, 2 * self.L + yw, 0 + zh)) point.append((2 * self.L / 3 + xl, 5 * self.L / 3 + yw, 2 * self.L / 3 + zh)) - point.append((L + xl, self.L + yw, self.L + zh)) + point.append((self.L + xl, self.L + yw, self.L + zh)) scale = 100 oo = geompy.MakeVertex(0, 0, 0) diff --git a/docs/source/static/deps.svg b/docs/source/static/deps.svg new file mode 100644 index 0000000..f45bc01 --- /dev/null +++ b/docs/source/static/deps.svg @@ -0,0 +1,418 @@ + + + + + + +G + + + +anisotropy_core_cli + +anisotropy. +core. +cli + + + +anisotropy_core_database + +anisotropy. +core. +database + + + +anisotropy_core_main + +anisotropy. +core. +main + + + +anisotropy_core_database->anisotropy_core_main + + + + + +anisotropy_core_main->anisotropy_core_cli + + + + + +anisotropy_core_models + +anisotropy. +core. +models + + + +anisotropy_core_models->anisotropy_core_database + + + + + +anisotropy_core_utils + +anisotropy. +core. +utils + + + +anisotropy_core_utils->anisotropy_core_cli + + + + + + +anisotropy_core_utils->anisotropy_core_database + + + + + +anisotropy_core_utils->anisotropy_core_main + + + + + + +anisotropy_openfoam + +anisotropy. +openfoam + + + +anisotropy_openfoam->anisotropy_core_main + + + + + +anisotropy_openfoam_application + +anisotropy. +openfoam. +application + + + +anisotropy_openfoam_meshConversion + +anisotropy. +openfoam. +meshConversion + + + +anisotropy_openfoam_application->anisotropy_openfoam_meshConversion + + + + + +anisotropy_openfoam_meshManipulation + +anisotropy. +openfoam. +meshManipulation + + + +anisotropy_openfoam_application->anisotropy_openfoam_meshManipulation + + + + + +anisotropy_openfoam_miscellaneous + +anisotropy. +openfoam. +miscellaneous + + + +anisotropy_openfoam_application->anisotropy_openfoam_miscellaneous + + + + + +anisotropy_openfoam_parallelProcessing + +anisotropy. +openfoam. +parallelProcessing + + + +anisotropy_openfoam_application->anisotropy_openfoam_parallelProcessing + + + + + +anisotropy_openfoam_solvers + +anisotropy. +openfoam. +solvers + + + +anisotropy_openfoam_application->anisotropy_openfoam_solvers + + + + + +anisotropy_openfoam_meshConversion->anisotropy_openfoam + + + + + +anisotropy_openfoam_meshManipulation->anisotropy_openfoam + + + + + +anisotropy_openfoam_miscellaneous->anisotropy_openfoam + + + + + +anisotropy_openfoam_parallelProcessing->anisotropy_openfoam + + + + + +anisotropy_openfoam_solvers->anisotropy_openfoam + + + + + +anisotropy_openfoam_utils + +anisotropy. +openfoam. +utils + + + +anisotropy_openfoam_utils->anisotropy_openfoam + + + + + +anisotropy_salomepl + +anisotropy. +salomepl + + + +anisotropy_salomepl->anisotropy_core_main + + + + + + + +anisotropy_samples_bodyCentered + +anisotropy. +samples. +bodyCentered + + + +anisotropy_salomepl->anisotropy_samples_bodyCentered + + + + + +anisotropy_samples_faceCentered + +anisotropy. +samples. +faceCentered + + + +anisotropy_salomepl->anisotropy_samples_faceCentered + + + + + +anisotropy_samples_simple + +anisotropy. +samples. +simple + + + +anisotropy_salomepl->anisotropy_samples_simple + + + + + +anisotropy_salomepl_geometry + +anisotropy. +salomepl. +geometry + + + +anisotropy_salomepl_geometry->anisotropy_core_main + + + + + +anisotropy_salomepl_geometry->anisotropy_samples_bodyCentered + + + + + + +anisotropy_salomepl_geometry->anisotropy_samples_faceCentered + + + + + +anisotropy_salomepl_geometry->anisotropy_samples_simple + + + + + +anisotropy_salomepl_mesh + +anisotropy. +salomepl. +mesh + + + +anisotropy_salomepl_mesh->anisotropy_core_main + + + + +anisotropy_salomepl_utils + +anisotropy. +salomepl. +utils + + + +anisotropy_salomepl_utils->anisotropy_core_main + + + + +anisotropy_samples + +anisotropy. +samples + + + +anisotropy_samples->anisotropy_core_main + + + + +anisotropy_samples_bodyCentered->anisotropy_samples + + + + + +anisotropy_samples_faceCentered->anisotropy_samples + + + + + +anisotropy_samples_simple->anisotropy_samples + + + + + +click + +click + + + +click->anisotropy_core_cli + + + + + +peewee + +peewee + + + +peewee->anisotropy_core_models + + + + + +sphinx + +sphinx + + + +sphinx->anisotropy_core_cli + + + + +toml + +toml + + + +toml->anisotropy_core_main + + + + diff --git a/docs/source/static/er-diagram.svg b/docs/source/static/er-diagram.svg new file mode 100644 index 0000000..3c0a830 --- /dev/null +++ b/docs/source/static/er-diagram.svg @@ -0,0 +1,587 @@ + + + + + + +erd + + + +BaseModel + + +             +            BaseModel             +             +id +             +             +AutoField +             + + + +Flow + + +             +            Flow             +             +flow_id +             +             +AutoField +             +             +structure_id +             +             +ForeignKeyField +             +             +scale +             +             +ListField +             +             +pressure +             +             +JSONField +             +             +velocity +             +             +JSONField +             +             +transportProperties +             +             +JSONField +             + + + +Structure + + +             +            Structure             +             +structure_id +             +             +AutoField +             +             +type +             +             +TextField +             +             +direction +             +             +ListField +             +             +theta +             +             +FloatField +             +             +r0 +             +             +FloatField +             +             +L +             +             +FloatField +             +             +radius +             +             +FloatField +             +             +filletsEnabled +             +             +BooleanField +             +             +fillets +             +             +FloatField +             + + + +Flow:structure_id->Structure:structure_id + + + + + +FlowApproximation + + +             +            FlowApproximation             +             +flow_approximation_id +             +             +AutoField +             +             +flow_id +             +             +ForeignKeyField +             +             +pressure +             +             +JSONField +             +             +velocity +             +             +JSONField +             +             +transportProperties +             +             +JSONField +             + + + +FlowApproximation:flow_id->Flow:flow_id + + + + + +FlowResult + + +             +            FlowResult             +             +flowresult_id +             +             +AutoField +             +             +flow_id +             +             +ForeignKeyField +             +             +flowRate +             +             +FloatField +             +             +status +             +             +TextField +             +             +calculationTime +             +             +TimeField +             + + + +FlowResult:flow_id->Flow:flow_id + + + + + +Mesh + + +             +            Mesh             +             +mesh_id +             +             +AutoField +             +             +structure_id +             +             +ForeignKeyField +             +             +maxSize +             +             +FloatField +             +             +minSize +             +             +FloatField +             +             +fineness +             +             +IntegerField +             +             +growthRate +             +             +FloatField +             +             +nbSegPerEdge +             +             +FloatField +             +             +nbSegPerRadius +             +             +FloatField +             +             +chordalErrorEnabled +             +             +BooleanField +             +             +chordalError +             +             +FloatField +             +             +secondOrder +             +             +BooleanField +             +             +optimize +             +             +BooleanField +             +             +quadAllowed +             +             +BooleanField +             +             +useSurfaceCurvature +             +             +BooleanField +             +             +fuseEdges +             +             +BooleanField +             +             +checkChartBoundary +             +             +BooleanField +             +             +viscousLayers +             +             +BooleanField +             +             +thickness +             +             +FloatField +             +             +numberOfLayers +             +             +IntegerField +             +             +stretchFactor +             +             +FloatField +             +             +isFacesToIgnore +             +             +BooleanField +             +             +facesToIgnore +             +             +ListField +             +             +extrusionMethod +             +             +TextField +             + + + +Mesh:structure_id->Structure:structure_id + + + + + +MeshResult + + +             +            MeshResult             +             +meshresult_id +             +             +AutoField +             +             +mesh_id +             +             +ForeignKeyField +             +             +surfaceArea +             +             +FloatField +             +             +volume +             +             +FloatField +             +             +elements +             +             +IntegerField +             +             +edges +             +             +IntegerField +             +             +faces +             +             +IntegerField +             +             +volumes +             +             +IntegerField +             +             +tetrahedrons +             +             +IntegerField +             +             +prisms +             +             +IntegerField +             +             +pyramids +             +             +IntegerField +             +             +status +             +             +TextField +             +             +calculationTime +             +             +TimeField +             + + + +MeshResult:mesh_id->Mesh:mesh_id + + + + + +SubMesh + + +             +            SubMesh             +             +submesh_id +             +             +AutoField +             +             +mesh_id +             +             +ForeignKeyField +             +             +name +             +             +TextField +             +             +maxSize +             +             +FloatField +             +             +minSize +             +             +FloatField +             +             +fineness +             +             +IntegerField +             +             +growthRate +             +             +FloatField +             +             +nbSegPerEdge +             +             +FloatField +             +             +nbSegPerRadius +             +             +FloatField +             +             +chordalErrorEnabled +             +             +BooleanField +             +             +chordalError +             +             +FloatField +             +             +secondOrder +             +             +BooleanField +             +             +optimize +             +             +BooleanField +             +             +quadAllowed +             +             +BooleanField +             +             +useSurfaceCurvature +             +             +BooleanField +             +             +fuseEdges +             +             +BooleanField +             +             +checkChartBoundary +             +             +BooleanField +             + + + +SubMesh:mesh_id->Mesh:mesh_id + + + + + diff --git a/notes/images.rst b/notes/images.rst new file mode 100644 index 0000000..1530d21 --- /dev/null +++ b/notes/images.rst @@ -0,0 +1,11 @@ +Usefull command for making images +================================= + +.. code-block:: python + + from peewee_erd import draw + draw(["anisotropy/core/models.py"], "docs/source/static/er-diagram.svg", "#333333", "#eeeeee", 12, False, False) + +.. code-block:: bash + + pydeps anisotropy --max-bacon 2 --cluster -o docs/source/static/deps.svg --noshow diff --git a/requirements.txt b/requirements.txt index f66f4fd..f5b783a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,5 @@ pandas Sphinx sphinx-rtd-theme Click +peewee-erd +pydeps