From b707a7627870042a838bae6a9a3f7ad6a8ed8db1 Mon Sep 17 00:00:00 2001 From: L-Nafaryus Date: Tue, 10 Aug 2021 15:41:12 +0500 Subject: [PATCH] New: setup.py for setuptools New: credentials and some description Move: all modules was merged to one global module Fix: useless test --- anisotropy.py | 9 +++ anisotropy/__init__.py | 18 ++--- anisotropy/{ => config}/default.toml | 6 +- .../core}/__init__.py | 0 anisotropy/{__main__.py => core/cli.py} | 6 +- anisotropy/{core.py => core/main.py} | 81 ++++++++----------- anisotropy/{ => core}/models.py | 17 ++-- anisotropy/{ => core}/utils.py | 0 {openfoam => anisotropy/openfoam}/__init__.py | 0 .../openfoam}/application.py | 0 .../openfoam}/meshConversion.py | 0 .../openfoam}/meshManipulation.py | 0 .../openfoam}/miscellaneous.py | 0 .../openfoam}/parallelProcessing.py | 0 {openfoam => anisotropy/openfoam}/solvers.py | 0 .../openfoam}/template/0/U | 0 .../openfoam}/template/0/p | 0 .../template/constant/transportProperties | 0 .../template/constant/turbulenceProperties | 0 .../openfoam}/template/system/collapseDict | 0 .../openfoam}/template/system/controlDict | 0 .../openfoam}/template/system/createPatchDict | 0 .../template/system/decomposeParDict | 0 .../openfoam}/template/system/fvSchemes | 0 .../openfoam}/template/system/fvSolution | 0 {openfoam => anisotropy/openfoam}/utils.py | 0 anisotropy/salomepl/__init__.py | 4 + {salomepl => anisotropy/salomepl}/geometry.py | 0 {salomepl => anisotropy/salomepl}/mesh.py | 0 {salomepl => anisotropy/salomepl}/utils.py | 0 anisotropy/samples/__init__.py | 0 anisotropy/{ => samples}/bodyCentered.py | 0 anisotropy/{ => samples}/faceCentered.py | 0 anisotropy/{ => samples}/simple.py | 0 postProcessing/showFailed | 24 ------ postProcessing/utils.py | 28 ------- salomepl/__init__.py | 8 -- setup.py | 44 ++++++++++ tests/test_anisotropy.py | 14 ++-- 39 files changed, 126 insertions(+), 133 deletions(-) create mode 100644 anisotropy.py rename anisotropy/{ => config}/default.toml (99%) rename {postProcessing => anisotropy/core}/__init__.py (100%) rename anisotropy/{__main__.py => core/cli.py} (92%) rename anisotropy/{core.py => core/main.py} (96%) rename anisotropy/{ => core}/models.py (91%) rename anisotropy/{ => core}/utils.py (100%) rename {openfoam => anisotropy/openfoam}/__init__.py (100%) rename {openfoam => anisotropy/openfoam}/application.py (100%) rename {openfoam => anisotropy/openfoam}/meshConversion.py (100%) rename {openfoam => anisotropy/openfoam}/meshManipulation.py (100%) rename {openfoam => anisotropy/openfoam}/miscellaneous.py (100%) rename {openfoam => anisotropy/openfoam}/parallelProcessing.py (100%) rename {openfoam => anisotropy/openfoam}/solvers.py (100%) rename {openfoam => anisotropy/openfoam}/template/0/U (100%) rename {openfoam => anisotropy/openfoam}/template/0/p (100%) rename {openfoam => anisotropy/openfoam}/template/constant/transportProperties (100%) rename {openfoam => anisotropy/openfoam}/template/constant/turbulenceProperties (100%) rename {openfoam => anisotropy/openfoam}/template/system/collapseDict (100%) rename {openfoam => anisotropy/openfoam}/template/system/controlDict (100%) rename {openfoam => anisotropy/openfoam}/template/system/createPatchDict (100%) rename {openfoam => anisotropy/openfoam}/template/system/decomposeParDict (100%) rename {openfoam => anisotropy/openfoam}/template/system/fvSchemes (100%) rename {openfoam => anisotropy/openfoam}/template/system/fvSolution (100%) rename {openfoam => anisotropy/openfoam}/utils.py (100%) create mode 100644 anisotropy/salomepl/__init__.py rename {salomepl => anisotropy/salomepl}/geometry.py (100%) rename {salomepl => anisotropy/salomepl}/mesh.py (100%) rename {salomepl => anisotropy/salomepl}/utils.py (100%) create mode 100644 anisotropy/samples/__init__.py rename anisotropy/{ => samples}/bodyCentered.py (100%) rename anisotropy/{ => samples}/faceCentered.py (100%) rename anisotropy/{ => samples}/simple.py (100%) delete mode 100755 postProcessing/showFailed delete mode 100644 postProcessing/utils.py delete mode 100644 salomepl/__init__.py create mode 100644 setup.py diff --git a/anisotropy.py b/anisotropy.py new file mode 100644 index 0000000..67b6823 --- /dev/null +++ b/anisotropy.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# This file is part of anisotropy. +# License: GNU GPL version 3, see the file "LICENSE" for details. + +import sys +import anisotropy + +sys.exit(anisotropy.main()) diff --git a/anisotropy/__init__.py b/anisotropy/__init__.py index 2552e5e..ceaa1f1 100644 --- a/anisotropy/__init__.py +++ b/anisotropy/__init__.py @@ -1,13 +1,13 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- -"""asd""" -from anisotropy.core import ( - Anisotropy, - logger -) +# This file is part of anisotropy. +# License: GNU GPL version 3, see the file "LICENSE" for details. -from anisotropy.simple import Simple -from anisotropy.bodyCentered import BodyCentered -from anisotropy.faceCentered import FaceCentered +"""anisotropy +""" +__license__ = "GPL3" +__version__ = "1.1.0" +__author__ = __maintainer = "George Kusayko" +__email__ = "gkusayko@gmail.com" +from anisotropy.core.main import main diff --git a/anisotropy/default.toml b/anisotropy/config/default.toml similarity index 99% rename from anisotropy/default.toml rename to anisotropy/config/default.toml index ba54327..3d8f4eb 100644 --- a/anisotropy/default.toml +++ b/anisotropy/config/default.toml @@ -74,7 +74,7 @@ faceCentered = true fuseEdges = true checkChartBoundary = false - [flow] + [structures.flow] scale = [ 1e-5, 1e-5, 1e-5 ] constant.nu = 1e-6 @@ -159,7 +159,7 @@ faceCentered = true fuseEdges = true checkChartBoundary = false - [flow] + [structures.flow] scale = [ 1e-5, 1e-5, 1e-5 ] constant.nu = 1e-6 @@ -244,7 +244,7 @@ faceCentered = true fuseEdges = true checkChartBoundary = false - [flow] + [structures.flow] scale = [ 1e-5, 1e-5, 1e-5 ] constant.nu = 1e-6 diff --git a/postProcessing/__init__.py b/anisotropy/core/__init__.py similarity index 100% rename from postProcessing/__init__.py rename to anisotropy/core/__init__.py diff --git a/anisotropy/__main__.py b/anisotropy/core/cli.py similarity index 92% rename from anisotropy/__main__.py rename to anisotropy/core/cli.py index db9e169..61210bb 100644 --- a/anisotropy/__main__.py +++ b/anisotropy/core/cli.py @@ -5,7 +5,7 @@ def version(): msg = "Missed package anisotropy" try: - from anisotropy import Anisotropy + from anisotropy.core.main import Anisotropy msg = Anisotropy.version() except ImportError: @@ -22,7 +22,7 @@ def anisotropy(): @click.option("-s", "--stage", "stage", type = click.Choice(["all", "mesh", "flow"]), default = "all") @click.option("-p", "--param", "params", metavar = "key=value", multiple = True) def compute(stage, params): - from anisotropy import Anisotropy + from anisotropy.core.main import Anisotropy model = Anisotropy() model.setupDB() @@ -69,7 +69,7 @@ def _compute_mesh(root, name, direction, theta): os.path.join(root, "env/lib/python3.9/site-packages") ]) - from anisotropy import Anisotropy + from anisotropy.core.main import Anisotropy ### model = Anisotropy() diff --git a/anisotropy/core.py b/anisotropy/core/main.py similarity index 96% rename from anisotropy/core.py rename to anisotropy/core/main.py index 573752d..48eeaba 100644 --- a/anisotropy/core.py +++ b/anisotropy/core/main.py @@ -4,43 +4,11 @@ from datetime import timedelta, datetime import shutil import logging -__version__ = "1.1" -### -# Shell args -## -#configPath = "conf/config.toml" -#mode = "safe" - -#for n, arg in enumerate(sys.argv): -# if arg == "-c" or arg == "--config": -# configPath = sys.args[n + 1] - -# if arg == "-s" or arg == "--safe": -# mode = "safe" - -# elif arg == "-a" or arg == "--all": -# mode = "all" - -### -# Load configuration and tools -## -#CONFIG = os.path.join(ROOT, configPath) -#config = struct(toml.load(CONFIG)) - -#LOG = os.path.join(ROOT, "logs") -#if not os.path.exists(LOG): -# os.makedirs(LOG) - -#BUILD = os.path.join(ROOT, "build") -#if not os.path.exists(BUILD): -# os.makedirs(BUILD) - -################################################################################## -import os import toml from copy import deepcopy -from anisotropy.models import db, JOIN, Structure, Mesh, SubMesh, MeshResult -from anisotropy.utils import struct, deepupdate + +from anisotropy.core.models import db, Structure, Mesh, SubMesh, MeshResult +from anisotropy.core.utils import struct, deepupdate ### @@ -50,7 +18,7 @@ env = { "ROOT": os.path.abspath(".") } env.update(dict( BUILD = os.path.join(env["ROOT"], "build"), LOG = os.path.join(env["ROOT"], "logs"), - DEFAULT_CONFIG = os.path.join(env["ROOT"], "anisotropy/default.toml"), + DEFAULT_CONFIG = os.path.join(env["ROOT"], "anisotropy/config/default.toml"), CONFIG = os.path.join(env["ROOT"], "conf/config.toml") )) env["db_path"] = env["BUILD"] @@ -101,10 +69,10 @@ class CustomFormatter(logging.Formatter): return formatter.format(record) logger = logging.getLogger(logger_env.get("name", "anisotropy")) -logger.setLevel(logging.DEBUG) +logger.setLevel(logging.INFO) sh = logging.StreamHandler() -sh.setLevel(logging.DEBUG) +sh.setLevel(logging.INFO) sh.setFormatter(CustomFormatter()) fh = logging.FileHandler(os.path.join(env["LOG"], logger_env.get("name", "anisotropy"))) @@ -127,12 +95,17 @@ def timer(func): return inner -import salomepl -import openfoam +from anisotropy import salomepl +from anisotropy import openfoam from math import sqrt +from peewee import JOIN class Anisotropy(object): + """Ultimate class that organize whole working process""" + def __init__(self): + """Constructor method""" + self.env = env self.db = None self.params = [] @@ -140,6 +113,11 @@ class Anisotropy(object): @staticmethod def version(): + """Returns versions of all used main programs + + :return: Versions joined by next line symbol + :rtype: str + """ versions = { "anisotropy": __version__, "Python": sys.version.split(" ")[0], @@ -157,7 +135,13 @@ class Anisotropy(object): return "\n".join([ f"{ k }: { v }" for k, v in versions.items() ]) - def loadFromScratch(self): + def loadFromScratch(self) -> list: + """Loads parameters from configuration file and expands special values + + :return: List of dicts with parameters + :rtype: list + """ + if not os.path.exists(self.env["DEFAULT_CONFIG"]): logger.error("Missed default configuration file") return @@ -201,13 +185,11 @@ class Anisotropy(object): paramsAll.append(entryNew) return paramsAll - self.setupDB() - - for entry in paramsAll: - self.updateDB(entry) def evalParams(self): + """Evals specific geometry(structure) parameters""" + structure = self.params.get("structure") if not structure: @@ -261,7 +243,12 @@ class Anisotropy(object): fillets = fillets ) - def getCasePath(self): + def getCasePath(self) -> str: + """Constructs case path from main control parameters + + :return: Absolute path to case + :rtype: str + """ structure = self.params.get("structure") if not structure: @@ -629,7 +616,7 @@ class Anisotropy(object): for d in foamCase: shutil.copytree( - os.path.join(ROOT, "openfoam/template", d), + os.path.join(ROOT, "anisotropy/openfoam/template", d), os.path.join(case, d) ) diff --git a/anisotropy/models.py b/anisotropy/core/models.py similarity index 91% rename from anisotropy/models.py rename to anisotropy/core/models.py index d23db07..ed3a588 100644 --- a/anisotropy/models.py +++ b/anisotropy/core/models.py @@ -1,4 +1,11 @@ -from peewee import * +from peewee import ( + SqliteDatabase, + Model, Field, + AutoField, ForeignKeyField, + TextField, FloatField, + IntegerField, BooleanField, + TimeField +) class ListField(Field): field_type = "list" @@ -30,7 +37,7 @@ class BaseModel(Model): class Structure(BaseModel): - structure_id = PrimaryKeyField() + structure_id = AutoField() type = TextField() direction = ListField() @@ -46,7 +53,7 @@ class Structure(BaseModel): class Mesh(BaseModel): - mesh_id = PrimaryKeyField() + mesh_id = AutoField() structure_id = ForeignKeyField(Structure, backref = "meshes") maxSize = FloatField(null = True) @@ -78,7 +85,7 @@ class Mesh(BaseModel): class SubMesh(BaseModel): - submesh_id = PrimaryKeyField() + submesh_id = AutoField() mesh_id = ForeignKeyField(Mesh, backref = "submeshes") name = TextField() @@ -102,7 +109,7 @@ class SubMesh(BaseModel): class MeshResult(BaseModel): - meshresult_id = PrimaryKeyField() + meshresult_id = AutoField() mesh_id = ForeignKeyField(Mesh, backref = "meshresults") surfaceArea = FloatField(null = True) diff --git a/anisotropy/utils.py b/anisotropy/core/utils.py similarity index 100% rename from anisotropy/utils.py rename to anisotropy/core/utils.py diff --git a/openfoam/__init__.py b/anisotropy/openfoam/__init__.py similarity index 100% rename from openfoam/__init__.py rename to anisotropy/openfoam/__init__.py diff --git a/openfoam/application.py b/anisotropy/openfoam/application.py similarity index 100% rename from openfoam/application.py rename to anisotropy/openfoam/application.py diff --git a/openfoam/meshConversion.py b/anisotropy/openfoam/meshConversion.py similarity index 100% rename from openfoam/meshConversion.py rename to anisotropy/openfoam/meshConversion.py diff --git a/openfoam/meshManipulation.py b/anisotropy/openfoam/meshManipulation.py similarity index 100% rename from openfoam/meshManipulation.py rename to anisotropy/openfoam/meshManipulation.py diff --git a/openfoam/miscellaneous.py b/anisotropy/openfoam/miscellaneous.py similarity index 100% rename from openfoam/miscellaneous.py rename to anisotropy/openfoam/miscellaneous.py diff --git a/openfoam/parallelProcessing.py b/anisotropy/openfoam/parallelProcessing.py similarity index 100% rename from openfoam/parallelProcessing.py rename to anisotropy/openfoam/parallelProcessing.py diff --git a/openfoam/solvers.py b/anisotropy/openfoam/solvers.py similarity index 100% rename from openfoam/solvers.py rename to anisotropy/openfoam/solvers.py diff --git a/openfoam/template/0/U b/anisotropy/openfoam/template/0/U similarity index 100% rename from openfoam/template/0/U rename to anisotropy/openfoam/template/0/U diff --git a/openfoam/template/0/p b/anisotropy/openfoam/template/0/p similarity index 100% rename from openfoam/template/0/p rename to anisotropy/openfoam/template/0/p diff --git a/openfoam/template/constant/transportProperties b/anisotropy/openfoam/template/constant/transportProperties similarity index 100% rename from openfoam/template/constant/transportProperties rename to anisotropy/openfoam/template/constant/transportProperties diff --git a/openfoam/template/constant/turbulenceProperties b/anisotropy/openfoam/template/constant/turbulenceProperties similarity index 100% rename from openfoam/template/constant/turbulenceProperties rename to anisotropy/openfoam/template/constant/turbulenceProperties diff --git a/openfoam/template/system/collapseDict b/anisotropy/openfoam/template/system/collapseDict similarity index 100% rename from openfoam/template/system/collapseDict rename to anisotropy/openfoam/template/system/collapseDict diff --git a/openfoam/template/system/controlDict b/anisotropy/openfoam/template/system/controlDict similarity index 100% rename from openfoam/template/system/controlDict rename to anisotropy/openfoam/template/system/controlDict diff --git a/openfoam/template/system/createPatchDict b/anisotropy/openfoam/template/system/createPatchDict similarity index 100% rename from openfoam/template/system/createPatchDict rename to anisotropy/openfoam/template/system/createPatchDict diff --git a/openfoam/template/system/decomposeParDict b/anisotropy/openfoam/template/system/decomposeParDict similarity index 100% rename from openfoam/template/system/decomposeParDict rename to anisotropy/openfoam/template/system/decomposeParDict diff --git a/openfoam/template/system/fvSchemes b/anisotropy/openfoam/template/system/fvSchemes similarity index 100% rename from openfoam/template/system/fvSchemes rename to anisotropy/openfoam/template/system/fvSchemes diff --git a/openfoam/template/system/fvSolution b/anisotropy/openfoam/template/system/fvSolution similarity index 100% rename from openfoam/template/system/fvSolution rename to anisotropy/openfoam/template/system/fvSolution diff --git a/openfoam/utils.py b/anisotropy/openfoam/utils.py similarity index 100% rename from openfoam/utils.py rename to anisotropy/openfoam/utils.py diff --git a/anisotropy/salomepl/__init__.py b/anisotropy/salomepl/__init__.py new file mode 100644 index 0000000..586a5fd --- /dev/null +++ b/anisotropy/salomepl/__init__.py @@ -0,0 +1,4 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + diff --git a/salomepl/geometry.py b/anisotropy/salomepl/geometry.py similarity index 100% rename from salomepl/geometry.py rename to anisotropy/salomepl/geometry.py diff --git a/salomepl/mesh.py b/anisotropy/salomepl/mesh.py similarity index 100% rename from salomepl/mesh.py rename to anisotropy/salomepl/mesh.py diff --git a/salomepl/utils.py b/anisotropy/salomepl/utils.py similarity index 100% rename from salomepl/utils.py rename to anisotropy/salomepl/utils.py diff --git a/anisotropy/samples/__init__.py b/anisotropy/samples/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/anisotropy/bodyCentered.py b/anisotropy/samples/bodyCentered.py similarity index 100% rename from anisotropy/bodyCentered.py rename to anisotropy/samples/bodyCentered.py diff --git a/anisotropy/faceCentered.py b/anisotropy/samples/faceCentered.py similarity index 100% rename from anisotropy/faceCentered.py rename to anisotropy/samples/faceCentered.py diff --git a/anisotropy/simple.py b/anisotropy/samples/simple.py similarity index 100% rename from anisotropy/simple.py rename to anisotropy/samples/simple.py diff --git a/postProcessing/showFailed b/postProcessing/showFailed deleted file mode 100755 index ce9808a..0000000 --- a/postProcessing/showFailed +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.." -cd ${DIR} - -source $OPENFOAM - -getcase() -{ - for _case in $( find $1 -type f -name $2 ); do - if [ "$( cat $_case | grep "$3" )" ]; then - echo $_case - fi - done -} - -echo -e "\nFailed mesh:" -getcase "$DIR/build" "task.toml" "mesh = false" - -echo -e "\nFailed flow:" -getcase "$DIR/build" "task.toml" "flow = false" - -endTime="$( foamDictionary "${DIR}/openfoam/template/system/controlDict" -entry endTime -value )" -echo -e "\nComputation exceed 'endTime = $endTime':" -getcase "$DIR/build" "simpleFoam.log" "Time = $endTime" diff --git a/postProcessing/utils.py b/postProcessing/utils.py deleted file mode 100644 index 8edb71b..0000000 --- a/postProcessing/utils.py +++ /dev/null @@ -1,28 +0,0 @@ -from paraview.simple import * - -def plotMagnitude(): - - rv = CreateRenderView() - rv.ViewSize = [1920, 1080] - rv.CameraPosition = [1e-05, 2e-05, 1e-05] - rv.CameraFocalPoint = [1e-05, 2e-05, 1e-05] - - - layout1 = CreateLayout(name='Layout #1') - layout1.AssignView(0, rv) - - SetActiveView(rv) - - foam = OpenFOAMReader(FileName = "simple.foam") - foam.CaseType = "Decomposed Case" - foam.MeshRegions = ["internalMesh"] - foam.CellArrays = ["U", "p"] - - SetActiveSource(foam) - display = Show(foam, rv, "UnstructuredGridRepresentation") - r = Render() - - SaveScreenshot("test.png", r) - -if __name__ == "__main__": - plotMagnitude() diff --git a/salomepl/__init__.py b/salomepl/__init__.py deleted file mode 100644 index 38040e8..0000000 --- a/salomepl/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -from salomepl import ( - geometry, - mesh, - utils -) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..1fe538b --- /dev/null +++ b/setup.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# This file is part of anisotropy. +# License: GNU GPL version 3, see the file "LICENSE" for details. + +from setuptools import setup + +import anisotropy + +def main(): + setup( + name = "anisotropy", + description = "Anisotropy", + long_description = anisotropy.__doc__, + version = anisotropy.__version__, + author = anisotropy.__author__, + author_email = anisotropy.__email__, + license = anisotropy.__license__, + url = "https://github.com/L-Nafaryus/anisotropy", + keywords = "anisotropy console", + classifiers = [ + "Environment :: Console", + "Operating System :: POSIX", + "Operating System :: Unix", + "Programming Language :: Python :: 3.9" + ], + package_data = { + "anisotropy": [ + "config/default.toml" + ] + }, + packages = ( + "anisotropy", + "anisotropy.config", + "anisotropy.core", + "anisotropy.openfoam", + "anisotropy.salomepl", + "anisotropy.samples" + ) + ) + + +if __name__ == "__main__": + main() diff --git a/tests/test_anisotropy.py b/tests/test_anisotropy.py index 76928cd..c49d175 100644 --- a/tests/test_anisotropy.py +++ b/tests/test_anisotropy.py @@ -5,8 +5,8 @@ unittest.TestLoader.sortTestMethodsUsing = None class TestAnisotropy(unittest.TestCase): def setUp(self): - import anisotropy - self.model = anisotropy.Anisotropy() + from anisotropy.core.main import Anisotropy + self.model = Anisotropy() def test_01_create_db(self): self.model.setupDB() @@ -14,11 +14,15 @@ class TestAnisotropy(unittest.TestCase): self.assertTrue(os.path.exists(path)) - def test_02_load_scratch(self): + def test_02_load_from_scratch(self): passed = True try: - self.model.loadScratch() + paramsAll = self.model.loadFromScratch() + self.model.setupDB() + + for entry in paramsAll: + self.model.updateDB(entry) except Exception as e: passed = False @@ -31,8 +35,6 @@ class TestAnisotropy(unittest.TestCase): self.assertEqual(self.model.params["structure"]["type"], "simple") - def test_04_updateDB(self): - self.model.updateDB() if __name__ == "__main__": unittest.main()