New: setup.py for setuptools

New: credentials and some description
Move: all modules was merged to one global module
Fix: useless test
This commit is contained in:
L-Nafaryus 2021-08-10 15:41:12 +05:00
parent efe229ada8
commit b707a76278
39 changed files with 126 additions and 133 deletions

9
anisotropy.py Normal file
View File

@ -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())

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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)
)

View File

@ -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)

View File

@ -0,0 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

View File

View File

@ -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"

View File

@ -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()

View File

@ -1,8 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from salomepl import (
geometry,
mesh,
utils
)

44
setup.py Normal file
View File

@ -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()

View File

@ -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()