New: move files
This commit is contained in:
parent
08de009cc4
commit
d4dacd2e07
56
TODO.md
56
TODO.md
@ -1,56 +0,0 @@
|
|||||||
## Usefull utils
|
|
||||||
- createPatch
|
|
||||||
- polyDualMesh
|
|
||||||
- fvSolution: cellLimited
|
|
||||||
- collapseDict: collapseEdges
|
|
||||||
- renumberMesh
|
|
||||||
- processorField
|
|
||||||
|
|
||||||
## Errors
|
|
||||||
- salome:
|
|
||||||
|
|
||||||
th. 139990926538304 -
|
|
||||||
Trace /volatile/salome/jenkins/workspace/Salome_master_CO7/SALOME-9.6.0-CO7/SOURCES/SMESH/src/SMESH/SMESH_subMesh.cxx [2005] :
|
|
||||||
NETGEN_2D3D failed on sub-shape #1 with error COMPERR_BAD_INPUT_MESH
|
|
||||||
"NgException at Volume meshing: Stop meshing since surface mesh not consistent Some edges multiple times in surface mesh"
|
|
||||||
|
|
||||||
th. 140588498282048 -
|
|
||||||
Trace /volatile/salome/jenkins/workspace/Salome_master_CO7/SALOME-9.6.0-CO7/SOURCES/SMESH/src/SMESH/SMESH_subMesh.cxx [2005] :
|
|
||||||
NETGEN_2D3D failed on sub-shape #47 with error COMPERR_WARNING
|
|
||||||
"Thickness 0.001 of viscous layers not reached, average reached thickness is 0.000928207"
|
|
||||||
|
|
||||||
th. 139986338838080 -
|
|
||||||
Trace /volatile/salome/jenkins/workspace/Salome_master_CO7/SALOME-9.6.0-CO7/SOURCES/SMESH/src/SMESH/SMESH_subMesh.cxx [2005] :
|
|
||||||
NETGEN_2D3D failed on sub-shape #1 with error COMPERR_BAD_INPUT_MESH
|
|
||||||
"NgException at Volume meshing: Stop meshing since boundary mesh is overlapping Intersecting triangles"
|
|
||||||
|
|
||||||
|
|
||||||
## 1.03.21
|
|
||||||
- [x] boundary type (wall or symetryPlane)
|
|
||||||
- [x] restruct for ways
|
|
||||||
- [x] build alpha = 0.01 .. 0.13
|
|
||||||
- [x] ! symetryPlane -> cyclicAMI
|
|
||||||
|
|
||||||
## 3.03.21
|
|
||||||
- [x] configure salome server, ports, etc.
|
|
||||||
- [ ] less processes for salome, optimization.
|
|
||||||
|
|
||||||
## 4.03.21
|
|
||||||
- [x] 3rd direction
|
|
||||||
- [x] createPatch(Dict)
|
|
||||||
- [ ] views (mesh, ..)
|
|
||||||
- [x] alpha for simpleCubic [0.01 .. 0.28]
|
|
||||||
- [x] translation vector (cyclicAMI)
|
|
||||||
- [ ] BUG: angle between the direction vector and the normal to inlet is ~1.4e-14
|
|
||||||
- [x] Another solution
|
|
||||||
- [ ] BUG: ideasUnvToFoam not working with param '-case PATH'
|
|
||||||
- [x] Temporary sulution via os.chdir(PATH)
|
|
||||||
|
|
||||||
## 6.03.21
|
|
||||||
- [ ] ERROR: MakeFuseList with alpha > 0.2
|
|
||||||
|
|
||||||
## 7.03.21
|
|
||||||
- [x] Split the symetryPlane to 4 faces
|
|
||||||
|
|
||||||
## 11.03.21
|
|
||||||
- [x] Dual test for cyclicAMI
|
|
4
anisotropy.sh
Executable file
4
anisotropy.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
python ${DIR}/anisotropy/anisotropy.py
|
@ -68,24 +68,6 @@ def main():
|
|||||||
logger.info(f"Warnings: {logger.warnings}\tErrors: {logger.errors}")
|
logger.info(f"Warnings: {logger.warnings}\tErrors: {logger.errors}")
|
||||||
|
|
||||||
|
|
||||||
def checkEnv():
|
|
||||||
missed = False
|
|
||||||
|
|
||||||
try:
|
|
||||||
pythonVersion = "Python {}".format(sys.version.split(" ")[0])
|
|
||||||
salomeVersion = salome_utils.salomeVersion()
|
|
||||||
foamVersion = foam_utils.foamVersion()
|
|
||||||
|
|
||||||
except Exception:
|
|
||||||
logger.critical("Missed environment")
|
|
||||||
missed = True
|
|
||||||
|
|
||||||
else:
|
|
||||||
logger.info(f"environment:\n\t{pythonVersion}\n\t{salomeVersion}\n\t{foamVersion}")
|
|
||||||
|
|
||||||
finally:
|
|
||||||
return missed
|
|
||||||
|
|
||||||
|
|
||||||
class Task:
|
class Task:
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
@ -223,4 +205,3 @@ def postprocessing(tasks):
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
163
anisotropy/utils.py
Normal file
163
anisotropy/utils.py
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
from multiprocessing import Queue, Process, cpu_count
|
||||||
|
import socket
|
||||||
|
|
||||||
|
|
||||||
|
class struct:
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
for (k, v) in kwargs.items():
|
||||||
|
setattr(self, k, v)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
members = []
|
||||||
|
|
||||||
|
for key in self.__dict__.keys():
|
||||||
|
members.append(f"{ key } = ")
|
||||||
|
|
||||||
|
if type(self.__dict__[key]) == str:
|
||||||
|
members[len(members) - 1] += f"\"{ self.__dict__[key] }\""
|
||||||
|
|
||||||
|
else:
|
||||||
|
members[len(members) - 1] += f"{ self.__dict__[key] }"
|
||||||
|
|
||||||
|
return f"struct({', '.join(members)})"
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return str(self)
|
||||||
|
|
||||||
|
|
||||||
|
class Logger:
|
||||||
|
def __init__(self, name, logpath):
|
||||||
|
logging.basicConfig(
|
||||||
|
level = logging.INFO,
|
||||||
|
format = "%(levelname)s: %(message)s",
|
||||||
|
handlers = [
|
||||||
|
logging.StreamHandler(),
|
||||||
|
logging.FileHandler(logpath)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
self.logger = logging.getLogger(name)
|
||||||
|
self.warnings = 0
|
||||||
|
self.errors = 0
|
||||||
|
self.criticals = 0
|
||||||
|
self.exceptions = 0
|
||||||
|
|
||||||
|
def info(self, *args):
|
||||||
|
self.logger.info(*args)
|
||||||
|
|
||||||
|
def warning(self, *args):
|
||||||
|
self.warnings += 1
|
||||||
|
self.logger.warning(*args)
|
||||||
|
|
||||||
|
def error(self, *args):
|
||||||
|
self.errors += 1
|
||||||
|
self.logger.error(*args)
|
||||||
|
|
||||||
|
def critical(self, *args):
|
||||||
|
self.criticals += 1
|
||||||
|
self.logger.critical(*args)
|
||||||
|
|
||||||
|
def exception(self, *args):
|
||||||
|
self.exceptions += 1
|
||||||
|
self.logger.exception(*args)
|
||||||
|
|
||||||
|
def fancyline(self):
|
||||||
|
self.logger.info("-" * 80)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def queue(cmd, qin, qout, *args):
|
||||||
|
|
||||||
|
while True:
|
||||||
|
# Get item from the queue
|
||||||
|
pos, var = qin.get()
|
||||||
|
|
||||||
|
# Exit point
|
||||||
|
if pos is None:
|
||||||
|
break
|
||||||
|
|
||||||
|
# Execute command
|
||||||
|
res = cmd(*var, *args)
|
||||||
|
|
||||||
|
# Put results to the queue
|
||||||
|
qout.put((pos, res))
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def parallel(np, var, cmd):
|
||||||
|
|
||||||
|
varcount = len(var)
|
||||||
|
|
||||||
|
processes = []
|
||||||
|
nprocs = np if np <= cpu_count() else cpu_count()
|
||||||
|
|
||||||
|
qin = Queue(1)
|
||||||
|
qout = Queue()
|
||||||
|
|
||||||
|
logging.info("cpu count: {}".format(np))
|
||||||
|
logging.info("var: {}".format(var))
|
||||||
|
logging.info("cmd: {}".format(cmd))
|
||||||
|
|
||||||
|
# Create processes
|
||||||
|
for n in range(nprocs):
|
||||||
|
pargs = [cmd, qin, qout]
|
||||||
|
|
||||||
|
p = Process(target = queue, args = tuple(pargs))
|
||||||
|
|
||||||
|
processes.append(p)
|
||||||
|
|
||||||
|
# Start processes
|
||||||
|
for p in processes:
|
||||||
|
p.daemon = True
|
||||||
|
p.start()
|
||||||
|
|
||||||
|
# Fill queue
|
||||||
|
for n in range(varcount):
|
||||||
|
qin.put((n, var[n]))
|
||||||
|
|
||||||
|
for _ in range(nprocs):
|
||||||
|
qin.put((None, None))
|
||||||
|
|
||||||
|
# Get results
|
||||||
|
results = [[] for n in range(varcount)]
|
||||||
|
|
||||||
|
for n in range(varcount):
|
||||||
|
index, res = qout.get()
|
||||||
|
|
||||||
|
results[index] = res
|
||||||
|
|
||||||
|
# Wait until each processor has finished
|
||||||
|
for p in processes:
|
||||||
|
p.join()
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
def portIsFree(address, port):
|
||||||
|
|
||||||
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||||
|
return s.connect_ex((address, port)) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def checkEnv():
|
||||||
|
missed = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
pythonVersion = "Python {}".format(sys.version.split(" ")[0])
|
||||||
|
salomeVersion = salome_utils.salomeVersion()
|
||||||
|
foamVersion = foam_utils.foamVersion()
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
logger.critical("Missed environment")
|
||||||
|
missed = True
|
||||||
|
|
||||||
|
else:
|
||||||
|
logger.info(f"environment:\n\t{pythonVersion}\n\t{salomeVersion}\n\t{foamVersion}")
|
||||||
|
|
||||||
|
finally:
|
||||||
|
return missed
|
||||||
|
|
||||||
|
|
@ -163,4 +163,3 @@ class faceCentered:
|
|||||||
facesToIgnore = None,
|
facesToIgnore = None,
|
||||||
extrusionMethod = None
|
extrusionMethod = None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
34
notes.md
34
notes.md
@ -1,30 +1,8 @@
|
|||||||
## relaxationFactors
|
|
||||||
|
|
||||||
| p | Iterations | U |
|
- createPatch
|
||||||
| --- | --- | --- |
|
- polyDualMesh
|
||||||
| 0.05 | 830 | 0.2 |
|
- fvSolution: cellLimited
|
||||||
| 0.1 | 678 | 0.2 |
|
- collapseDict: collapseEdges
|
||||||
| 0.2 | 505 | 0.2 |
|
- renumberMesh
|
||||||
| 0.3 | 305 | 0.3 |
|
- processorField
|
||||||
| 0.3 | 236 | 0.4 |
|
|
||||||
| 0.3 | 181 | 0.5 |
|
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
## SIMPLE.residualControl
|
|
||||||
|
|
||||||
| p | U | Iterations |
|
|
||||||
| --- | --- | --- |
|
|
||||||
| 1e-4 | 1e-4 | 338 |
|
|
||||||
| 1e-5 | 1e-5 | 499 |
|
|
||||||
|
|
||||||
##
|
|
||||||
|
|
||||||
```math
|
|
||||||
U = \frac{\Delta p L}{mu} \frac{9}{256} (\sqrt 2 - \frac{1}{1 - \alpha})^2
|
|
||||||
L = 2 R_0
|
|
||||||
R_0 = 1
|
|
||||||
scale = 1e-5
|
|
||||||
mu = 1e-3
|
|
||||||
\Delta p = 1
|
|
||||||
```
|
|
||||||
|
4
openfoam/meshConversion.py
Normal file
4
openfoam/meshConversion.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
def ideasUnvToFoam(mesh: str, case: str = None) -> (str, int):
|
||||||
|
return application("ideasUnvToFoam", mesh, case = case, stderr = True)
|
||||||
|
|
32
openfoam/meshManipulation.py
Normal file
32
openfoam/meshManipulation.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
def createPatch(dictfile: str = None, case: str = None):
|
||||||
|
args = ["-overwrite"]
|
||||||
|
|
||||||
|
if dictfile:
|
||||||
|
args.extend(["-dict", dictfile])
|
||||||
|
|
||||||
|
application("createPatch", *args, case = case, stderr = True)
|
||||||
|
|
||||||
|
|
||||||
|
def transformPoints(scale: tuple, case: str = None):
|
||||||
|
scale_ = "{}".format(scale).replace(",", "")
|
||||||
|
|
||||||
|
application("transformPoints", "-scale", scale_, case = case, stderr = True)
|
||||||
|
|
||||||
|
|
||||||
|
def checkMesh(case: str = None):
|
||||||
|
application("checkMesh", "-allGeometry", "-allTopology", case = case, stderr = True)
|
||||||
|
|
||||||
|
with open("checkMesh.log", "r") as io:
|
||||||
|
warnings = []
|
||||||
|
for line in io:
|
||||||
|
if re.search("\*\*\*", line):
|
||||||
|
warnings.append(line.replace("***", "").strip())
|
||||||
|
|
||||||
|
if warnings:
|
||||||
|
logger.warning("checkMesh:\n\t{}".format("\n\t".join(warnings)))
|
||||||
|
|
||||||
|
|
||||||
|
def renumberMesh(case: str = None):
|
||||||
|
application("renumberMesh", "-parallel", "-overwrite", useMPI = True, case = case, stderr = True)
|
||||||
|
|
9
openfoam/miscellaneous.py
Normal file
9
openfoam/miscellaneous.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
def foamDictionary(filepath: str, entry: str, value: str = None, case: str = None):
|
||||||
|
args = [filepath, "-entry", entry]
|
||||||
|
|
||||||
|
if value:
|
||||||
|
args.extend(["-set", value])
|
||||||
|
|
||||||
|
application("foamDictionary", *args, case = case, stderr = False)
|
||||||
|
|
@ -123,4 +123,3 @@ def simpleFoam(case: str = None):
|
|||||||
|
|
||||||
return returncode
|
return returncode
|
||||||
|
|
||||||
|
|
4
openfoam/parallelProcessing.py
Normal file
4
openfoam/parallelProcessing.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
def decomposePar(case: str = None):
|
||||||
|
application("decomposePar", case = case, stderr = True)
|
||||||
|
|
15
openfoam/solvers.py
Normal file
15
openfoam/solvers.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
def potentialFoam(case: str = None):
|
||||||
|
application("potentialFoam", "-parallel", useMPI = True, case = case, stderr = True)
|
||||||
|
|
||||||
|
|
||||||
|
def simpleFoam(case: str = None):
|
||||||
|
_, returncode = application("simpleFoam", "-parallel", useMPI = True, case = case, stderr = True)
|
||||||
|
|
||||||
|
with open("simpleFoam.log", "r") as io:
|
||||||
|
for line in io:
|
||||||
|
if re.search("solution converged", line):
|
||||||
|
logger.info("simpleFoam:\n\t{}".format(line.strip()))
|
||||||
|
|
||||||
|
return returncode
|
||||||
|
|
14
openfoam/utils.py
Normal file
14
openfoam/utils.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
def foamVersion() -> str:
|
||||||
|
return "OpenFOAM-{}".format(os.environ["WM_PROJECT_VERSION"])
|
||||||
|
|
||||||
|
|
||||||
|
def foamClean(case: str = None):
|
||||||
|
rmDirs = ["0", "constant", "system", "postProcessing", "logs"]
|
||||||
|
rmDirs.extend([ "processor{}".format(n) for n in range(os.cpu_count()) ])
|
||||||
|
path = case if case else ""
|
||||||
|
|
||||||
|
for d in rmDirs:
|
||||||
|
if os.path.exists(os.path.join(path, d)):
|
||||||
|
shutil.rmtree(os.path.join(path, d))
|
||||||
|
|
0
postProcessing/__init__.py
Normal file
0
postProcessing/__init__.py
Normal file
0
requirements.txt
Normal file
0
requirements.txt
Normal file
0
salome/__init__.py
Normal file
0
salome/__init__.py
Normal file
@ -1,5 +1,5 @@
|
|||||||
import salome
|
#import salome
|
||||||
salome.salome_init()
|
#salome.salome_init()
|
||||||
|
|
||||||
import GEOM
|
import GEOM
|
||||||
from salome.geom import geomBuilder
|
from salome.geom import geomBuilder
|
||||||
@ -284,4 +284,3 @@ def bodyCenteredHexagonalPrism(theta = 0.01, fillet = False, direction = [1, 1,
|
|||||||
groups.append(wall)
|
groups.append(wall)
|
||||||
|
|
||||||
return shape, groups
|
return shape, groups
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
import salome
|
#import salome
|
||||||
salome.salome_init()
|
#salome.salome_init()
|
||||||
|
|
||||||
import GEOM
|
import GEOM
|
||||||
from salome.geom import geomBuilder
|
from salome.geom import geomBuilder
|
||||||
@ -281,4 +281,3 @@ def faceCenteredHexagonalPrism(theta = 0.01, fillet = False, direction = [1, 1,
|
|||||||
groups.append(wall)
|
groups.append(wall)
|
||||||
|
|
||||||
return shape, groups
|
return shape, groups
|
||||||
|
|
@ -1,3 +1,6 @@
|
|||||||
|
###
|
||||||
|
# This file executes inside salome environment
|
||||||
|
##
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
import os, sys
|
import os, sys
|
||||||
import logging
|
import logging
|
@ -236,4 +236,3 @@ def boundaryCreate(gobj, dvec, grains):
|
|||||||
|
|
||||||
return boundary
|
return boundary
|
||||||
|
|
||||||
|
|
@ -189,4 +189,3 @@ def meshExport(mobj, path):
|
|||||||
except:
|
except:
|
||||||
logger.error("""meshExport: Cannot export.""")
|
logger.error("""meshExport: Cannot export.""")
|
||||||
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
import salome
|
#import salome
|
||||||
salome.salome_init()
|
#salome.salome_init()
|
||||||
|
|
||||||
import GEOM
|
import GEOM
|
||||||
from salome.geom import geomBuilder
|
from salome.geom import geomBuilder
|
||||||
@ -261,4 +261,3 @@ def simpleHexagonalPrism(theta = 0.01, fillet = False, direction = [1, 1, 1]):
|
|||||||
groups.append(wall)
|
groups.append(wall)
|
||||||
|
|
||||||
return shape, groups
|
return shape, groups
|
||||||
|
|
@ -80,4 +80,3 @@ def remote(port, cmd):
|
|||||||
stderr = subprocess.PIPE)
|
stderr = subprocess.PIPE)
|
||||||
|
|
||||||
return p
|
return p
|
||||||
|
|
@ -1,103 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
import math
|
|
||||||
from . import geometry_utils
|
|
||||||
|
|
||||||
import GEOM
|
|
||||||
geompy = geometry_utils.getGeom()
|
|
||||||
|
|
||||||
class StructuredGrains:
|
|
||||||
def __init__(self, radius, stackAngle, theta, layers):
|
|
||||||
self.pos = [0, 0, 0]
|
|
||||||
self.angle = [0, 0, 0]
|
|
||||||
self.radius = radius
|
|
||||||
self.theta = theta
|
|
||||||
self.layers = layers
|
|
||||||
|
|
||||||
# Parameters and dependencies
|
|
||||||
R = self.radius / (1 - self.theta)
|
|
||||||
|
|
||||||
C1 = 0.8 #fillet[0]
|
|
||||||
C2 = 0.4 #fillet[1]
|
|
||||||
self.theta1 = 0.01
|
|
||||||
self.theta2 = 0.28
|
|
||||||
|
|
||||||
Cf = C1 + (C2 - C1) / (self.theta2 - self.theta1) * (self.theta - self.theta1)
|
|
||||||
R_fillet = Cf * (self.radius * math.sqrt(2) - R)
|
|
||||||
|
|
||||||
###
|
|
||||||
stackang = [
|
|
||||||
0.5 * math.pi - stackAngle[0],
|
|
||||||
0.5 * math.pi - stackAngle[1],
|
|
||||||
0.5 * math.pi - stackAngle[2]
|
|
||||||
]
|
|
||||||
|
|
||||||
xvec = geompy.MakeVector(
|
|
||||||
geompy.MakeVertex(0, 0, 0),
|
|
||||||
geompy.MakeVertex(1, 0, 0))
|
|
||||||
yvec = geometry_utils.rotate(xvec, [0.5 * math.pi, 0, 0])
|
|
||||||
zvec = geometry_utils.rotate(xvec, [0, 0.5 * math.pi, 0])
|
|
||||||
|
|
||||||
grain = geompy.MakeSpherePntR(geompy.MakeVertex(pos[0], pos[1], pos[2]), R)
|
|
||||||
|
|
||||||
xstack = geompy.MakeMultiTranslation1D(grain, xvec, 2 * self.radius, self.layers[0])
|
|
||||||
ystack = geompy.MakeMultiTranslation1D(xgrain, yvec, 2 * self.radius, self.layers[1])
|
|
||||||
zstack = geompy.MakeMultiTranslation1D(ygrain, zvec, 2 * self.radius, self.layers[2])
|
|
||||||
|
|
||||||
# Correct position to zero
|
|
||||||
stack = geompy.MakeTranslation(zstack, -2 * self.radius, 0, 0)
|
|
||||||
|
|
||||||
self.geometry = geompy.ExtractShapes(stack, geompy.ShapeType["SOLID"], True)
|
|
||||||
self.geometry = geompy.MakeFuseList(self.geometry, False, False)
|
|
||||||
|
|
||||||
if not R_fillet == 0:
|
|
||||||
self.geometry = geompy.MakeFilletAll(self.geometry, R_fillet)
|
|
||||||
|
|
||||||
|
|
||||||
class AnisotropeCubic:
|
|
||||||
def __init__(self, scale, grains, style):
|
|
||||||
self.pos = [0, 0, 0]
|
|
||||||
self.angle = [0, 0, 0]
|
|
||||||
self.scale = scale
|
|
||||||
self.grains = grains
|
|
||||||
|
|
||||||
# Bounding box
|
|
||||||
if style == 0:
|
|
||||||
# Square
|
|
||||||
profile = (
|
|
||||||
geompy.Sketcher3D()
|
|
||||||
.addPointAbsolute(0, 0, 0)
|
|
||||||
.addPointAbsolute(0, 0, self.scale[2])
|
|
||||||
.addPointAbsolute(0, self.scale[1], self.scale[2])
|
|
||||||
.addPointAbsolute(0, self.scale[1], 0)
|
|
||||||
.addPointAbsolute(0, 0, 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
face = geompy.MakeFaceWires([profile.wire()], 1)
|
|
||||||
|
|
||||||
elif style == 1:
|
|
||||||
# Rombus
|
|
||||||
profile = (
|
|
||||||
geompy.Sketcher3D()
|
|
||||||
.addPointAbsolute(self.scale[0], 0.5 * self.scale[1], 0)
|
|
||||||
.addPointAbsolute(0.5 * self.scale[0], 0, 0.5 * self.scale[2])
|
|
||||||
.addPointAbsolute(0, 0.5 * self.scale[1], self.scale[2])
|
|
||||||
.addPointAbsolute(0.5 * self.scale[0], self.scale[1], 0.5 * self.scale[2])
|
|
||||||
.addPointAbsolute(self.scale[0], 0.5 * self.scale[1], 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
face = geompy.MakeFaceWires([profile.wire()], 1)
|
|
||||||
face = geompy.MakeTranslation(face,
|
|
||||||
0.5 * self.scale[1], 0, 0)
|
|
||||||
|
|
||||||
self.boundingbox = geompy.MakePrismVecH(face,
|
|
||||||
geompy.MakeVectorDXDYDZ(1, 0, 0),
|
|
||||||
self.scale[0])
|
|
||||||
|
|
||||||
# Geometry
|
|
||||||
self.geometry = geompy.MakeCutList(box, [self.grains], True)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
|||||||
import logging
|
|
||||||
import config
|
|
||||||
|
|
||||||
class Logger():
|
|
||||||
def __init__(self):
|
|
||||||
logging.basicConfig(
|
|
||||||
level = logging.INFO,
|
|
||||||
format = "%(levelname)s: %(message)s",
|
|
||||||
handlers = [
|
|
||||||
logging.StreamHandler(),
|
|
||||||
logging.FileHandler(f"{config.LOG}/anisotrope.log")
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
self.logger = logging.getLogger("anisotrope")
|
|
||||||
self.warnings = 0
|
|
||||||
self.errors = 0
|
|
||||||
self.criticals = 0
|
|
||||||
self.exceptions = 0
|
|
||||||
|
|
||||||
def info(self, *args):
|
|
||||||
self.logger.info(*args)
|
|
||||||
|
|
||||||
def warning(self, *args):
|
|
||||||
self.warnings += 1
|
|
||||||
self.logger.warning(*args)
|
|
||||||
|
|
||||||
def error(self, *args):
|
|
||||||
self.errors += 1
|
|
||||||
self.logger.error(*args)
|
|
||||||
|
|
||||||
def critical(self, *args):
|
|
||||||
self.criticals += 1
|
|
||||||
self.logger.critical(*args)
|
|
||||||
|
|
||||||
def exception(self, *args):
|
|
||||||
self.exceptions += 1
|
|
||||||
self.logger.exception(*args)
|
|
||||||
|
|
||||||
def fancyline(self):
|
|
||||||
self.logger.info("-" * 80)
|
|
77
src/utils.py
77
src/utils.py
@ -1,77 +0,0 @@
|
|||||||
from multiprocessing import Queue, Process, cpu_count
|
|
||||||
import socket
|
|
||||||
import logging
|
|
||||||
|
|
||||||
def queue(cmd, qin, qout, *args):
|
|
||||||
|
|
||||||
while True:
|
|
||||||
# Get item from the queue
|
|
||||||
pos, var = qin.get()
|
|
||||||
|
|
||||||
# Exit point
|
|
||||||
if pos is None:
|
|
||||||
break
|
|
||||||
|
|
||||||
# Execute command
|
|
||||||
res = cmd(*var, *args)
|
|
||||||
|
|
||||||
# Put results to the queue
|
|
||||||
qout.put((pos, res))
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def parallel(np, var, cmd):
|
|
||||||
|
|
||||||
varcount = len(var)
|
|
||||||
|
|
||||||
processes = []
|
|
||||||
nprocs = np if np <= cpu_count() else cpu_count()
|
|
||||||
|
|
||||||
qin = Queue(1)
|
|
||||||
qout = Queue()
|
|
||||||
|
|
||||||
logging.info("cpu count: {}".format(np))
|
|
||||||
logging.info("var: {}".format(var))
|
|
||||||
logging.info("cmd: {}".format(cmd))
|
|
||||||
|
|
||||||
# Create processes
|
|
||||||
for n in range(nprocs):
|
|
||||||
pargs = [cmd, qin, qout]
|
|
||||||
|
|
||||||
p = Process(target = queue, args = tuple(pargs))
|
|
||||||
|
|
||||||
processes.append(p)
|
|
||||||
|
|
||||||
# Start processes
|
|
||||||
for p in processes:
|
|
||||||
p.daemon = True
|
|
||||||
p.start()
|
|
||||||
|
|
||||||
# Fill queue
|
|
||||||
for n in range(varcount):
|
|
||||||
qin.put((n, var[n]))
|
|
||||||
|
|
||||||
for _ in range(nprocs):
|
|
||||||
qin.put((None, None))
|
|
||||||
|
|
||||||
# Get results
|
|
||||||
results = [[] for n in range(varcount)]
|
|
||||||
|
|
||||||
for n in range(varcount):
|
|
||||||
index, res = qout.get()
|
|
||||||
|
|
||||||
results[index] = res
|
|
||||||
|
|
||||||
# Wait until each processor has finished
|
|
||||||
for p in processes:
|
|
||||||
p.join()
|
|
||||||
|
|
||||||
return results
|
|
||||||
|
|
||||||
|
|
||||||
def portIsFree(address, port):
|
|
||||||
|
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
||||||
return s.connect_ex((address, port)) == 0
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user