From 8f038439ba6af26449a45f5fc3a7ed3c04c0078e Mon Sep 17 00:00:00 2001 From: L-Nafaryus Date: Thu, 5 Aug 2021 00:56:24 +0500 Subject: [PATCH] Mod: db issues + genmesh --- anisotropy/core.py | 25 ++++++++++++------ anisotropy/genmesh.py | 17 +++++++----- salomepl/mesh.py | 60 +++++++------------------------------------ simple | 34 ------------------------ 4 files changed, 37 insertions(+), 99 deletions(-) delete mode 100644 simple diff --git a/anisotropy/core.py b/anisotropy/core.py index 236b700..0a58f46 100644 --- a/anisotropy/core.py +++ b/anisotropy/core.py @@ -216,7 +216,7 @@ class Anisotropy(object): )) - def getParams(structure: str, direction: list, theta: float): + def getParams(self, structure: str, direction: list, theta: float): for entry in self.params: if entry["name"] == structure and \ entry["geometry"]["direction"] == direction and \ @@ -256,7 +256,7 @@ class Anisotropy(object): Structure.update(**raw) .where( Structure.name == req["name"], - Structure.direction == req["direction"], + Structure.direction == str(req["direction"]), Structure.theta == req["theta"] ) ) @@ -289,6 +289,9 @@ class Anisotropy(object): return tabID def _updateSubMesh(self, srcs: list, queryMain, meshID) -> None: + if not srcs: + return + for src in srcs: raw = deepcopy(src) @@ -306,13 +309,16 @@ class Anisotropy(object): query = ( SubMesh.update(**raw) .where( - SubMesh.mesh_id == req["mesh_id"] + SubMesh.mesh_id == req["mesh_id"], SubMesh.name == src["name"] ) ) query.execute() def _updateMeshResult(self, src: dict, queryMain, meshID) -> None: + if not src: + return + raw = deepcopy(src) with self.db.atomic(): @@ -348,20 +354,21 @@ class Anisotropy(object): ) ) - # TODO: empty entries structureID = self._updateStructure(entry, query) meshID = self._updateMesh(entry["mesh"], query, structureID) self._updateSubMesh(entry.get("submesh", []), query, meshID) self._updateMeshResult(entry.get("meshresults", {}), query, meshID) - + # TODO: loadDB (one model), loadsDB (all models) @timer def updateFromDB(self): squery = Structure.select().order_by(Structure.id) mquery = Mesh.select().order_by(Mesh.structure_id) + smquery = SubMesh.select() + mrquery = MeshResult.select().order_dy(MeshResult.mesh_id) self.params = [] - for s, m in zip(squery.dicts(), mquery.dicts()): + for s, m, mr in zip(squery.dicts(), mquery.dicts(), mrquery.dicts()): name = s.pop("name") path = s.pop("path") @@ -369,7 +376,9 @@ class Anisotropy(object): name = name, path = path, geometry = s, - mesh = m + mesh = m, + submesh = [ d for d in smquery.dicts() if d["mesh_id"] == m["mesh_id"] ], + meshresults = mr )) self.params = sorted(self.params, key = lambda entry: f"{ entry['name'] } { entry['geometry']['direction'] } { entry['geometry']['theta'] }") @@ -379,7 +388,7 @@ class Anisotropy(object): scriptpath = os.path.join(self.env["ROOT"], "anisotropy/genmesh.py") port = 2900 - return salomepl.utils.runSalome(port, scriptpath, env["ROOT"], name, direction, theta) + return salomepl.utils.runSalome(port, scriptpath, self.env["ROOT"], name, direction, theta) def computeFlow(self): pass diff --git a/anisotropy/genmesh.py b/anisotropy/genmesh.py index ce0a384..5cd5e72 100644 --- a/anisotropy/genmesh.py +++ b/anisotropy/genmesh.py @@ -36,9 +36,9 @@ def genmesh(root, name, direction, theta): from anisotropy import ( Anisotropy, logger, - simple, - bodyCentered, - faceCentered + Simple, + BodyCentered, + FaceCentered ) import salomepl @@ -47,6 +47,7 @@ def genmesh(root, name, direction, theta): # Model ## model = Anisotropy() + model.setupDB() model.updateFromDB() p = model.getParams(name, direction, theta) @@ -70,8 +71,12 @@ def genmesh(root, name, direction, theta): # Shape ## geompy = salomepl.geometry.getGeom() - structure = locals().get(p["name"]) - shape, groups = structure(**p["geometry"]) + structure = dict( + simple = Simple, + bodyCentered = BodyCentered, + faceCentered = FaceCentered + )[p["name"]] + shape, groups = structure(**p["geometry"]).build() [length, surfaceArea, volume] = geompy.BasicProperties(shape, theTolerance = 1e-06) @@ -98,7 +103,7 @@ def genmesh(root, name, direction, theta): faces = [] for group in groups: - if group.GetName() in mconfig["facesToIgnore"]: + if group.GetName() in mp["facesToIgnore"]: faces.append(group) diff --git a/salomepl/mesh.py b/salomepl/mesh.py index 8459bf5..10abc32 100644 --- a/salomepl/mesh.py +++ b/salomepl/mesh.py @@ -21,59 +21,10 @@ class Fineness(enum.Enum): VeryFine = 4 Custom = 5 -class ExtrusionMethod(object): - pass - #SURF_OFFSET_SMOOTH = smeshBuilder.SURF_OFFSET_SMOOTH - #FACE_OFFSET = smeshBuilder.FACE_OFFSET - #NODE_OFFSET = smeshBuilder.NODE_OFFSET def getSmesh(): return smesh -def defaultParameters(**configParameters): - maxSize = 0.5 - minSize = 0.05 - - fineness = Fineness.Custom.value - growthRate = 0.7 - nbSegPerEdge = 0.3 - nbSegPerRadius = 1 - - chordalErrorEnabled = True - chordalError = 0.25 - - secondOrder = False - optimize = True - quadAllowed = False - useSurfaceCurvature = True - fuseEdges = True - checkChartBoundary = False - - viscousLayers = False - thickness = 0.005 - numberOfLayers = 1 - stretchFactor = 1 - isFacesToIgnore = True - facesToIgnore = ["inlet", "outlet"] - faces = [] - extrusionMethod = ExtrusionMethod.SURF_OFFSET_SMOOTH - - p = locals() - del p["configParameters"] - - if configParameters: - for k, v in p.items(): - if configParameters.get(k) is not None: - p[k] = configParameters[k] - - # Overwrite special values - if k == "fineness": - p["fineness"] = Fineness.__dict__[p["fineness"]].value - - if k == "extrusionMethod": - p["extrusionMethod"] = ExtrusionMethod.__dict__[p["extrusionMethod"]] - - return p def updateParams(old, new: dict): old.SetMaxSize(new.get("maxSize", old.GetMaxSize())) @@ -112,13 +63,20 @@ class Mesh(object): self.params = updateParams(self.params, kwargs) + def _extrusionMethod(self, key: str): + return dict( + SURF_OFFSET_SMOOTH = smeshBuilder.SURF_OFFSET_SMOOTH, + FACE_OFFSET = smeshBuilder.FACE_OFFSET, + NODE_OFFSET = smeshBuilder.NODE_OFFSET, + ).get(key, smeshBuilder.SURF_OFFSET_SMOOTH) + def ViscousLayers(self, thickness = 1, numberOfLayers = 1, stretchFactor = 0, faces = [], isFacesToIgnore = True, - extrMethod = None,#ExtrusionMethod.SURF_OFFSET_SMOOTH, + extrMethod = "SURF_OFFSET_SMOOTH", **kwargs ): @@ -128,7 +86,7 @@ class Mesh(object): stretchFactor, faces, isFacesToIgnore, - extrMethod + self._extrusionMethod(extrMethod) ) def Triangle(self, subshape, **kwargs): diff --git a/simple b/simple deleted file mode 100644 index ed976e7..0000000 --- a/simple +++ /dev/null @@ -1,34 +0,0 @@ -runSalome running on localhost -Check if port can be used: 2900 - KO: port is busy -Searching for a free port for naming service: 2810 - OK -Searching Naming Service + found in 0.1 seconds -Searching /Registry in Naming Service + found in 0.5 seconds -Searching /Kernel/ModulCatalog in Naming Service + found in 0.5 seconds -RunStudy -Searching /Study in Naming Service + found in 0.5 seconds -Searching /Containers/elnafo/FactoryServer in Naming Service ++[1, -0, -0] -0.01 - found in 1.0 seconds -Start SALOME, elapsed time : 2.7 seconds -th. 139821375270848 - Trace /volatile/salome/jenkins/workspace/Salome_master_CO7_MPI/SALOME-9.7.0-MPI-CO7/SOURCES/KERNEL/src/ModuleCatalog/SALOME_ModuleCatalog_Server.cxx [98] : Module Catalog Server: Naming Service was found -Warning, no type found for resource "localhost", using default value "single_machine" -Traceback (most recent call last): - File "/home/nafaryus/.vault/projects/anisotropy/anisotropy/genmesh.py", line 155, in - genmesh() - File "/home/nafaryus/.vault/programs/SALOME/SALOME-9.7.0-MPI/BINARIES-CO7/Python/lib/python3.6/site-packages/click/core.py", line 722, in __call__ - return self.main(*args, **kwargs) - File "/home/nafaryus/.vault/programs/SALOME/SALOME-9.7.0-MPI/BINARIES-CO7/Python/lib/python3.6/site-packages/click/core.py", line 697, in main - rv = self.invoke(ctx) - File "/home/nafaryus/.vault/programs/SALOME/SALOME-9.7.0-MPI/BINARIES-CO7/Python/lib/python3.6/site-packages/click/core.py", line 895, in invoke - return ctx.invoke(self.callback, **ctx.params) - File "/home/nafaryus/.vault/programs/SALOME/SALOME-9.7.0-MPI/BINARIES-CO7/Python/lib/python3.6/site-packages/click/core.py", line 535, in invoke - return callback(*args, **kwargs) - File "/home/nafaryus/.vault/projects/anisotropy/anisotropy/genmesh.py", line 25, in genmesh - direction = list(map(lambda num: float(num), direction[1:-1].split(","))) - File "/home/nafaryus/.vault/projects/anisotropy/anisotropy/genmesh.py", line 25, in - direction = list(map(lambda num: float(num), direction[1:-1].split(","))) -ValueError: could not convert string to float: -ERROR:salomeContext:SystemExit 1 in method _runAppli. -th. 140195594066816 - Trace /volatile/salome/jenkins/workspace/Salome_master_CO7_MPI/SALOME-9.7.0-MPI-CO7/SOURCES/KERNEL/src/NamingService/SALOME_NamingService.cxx [1192] : Destroy_Name(): CORBA::SystemException: unable to contact the naming service