Samples
This commit is contained in:
parent
fbb3849ad6
commit
f8c35fa369
@ -1,56 +1,64 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os, shutil
|
|
||||||
import subprocess
|
|
||||||
import logging
|
|
||||||
import time
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
def application(name, case, log=False, args=[], parallel=False):
|
|
||||||
logging.info("Running '{}'.".format(name))
|
|
||||||
|
|
||||||
if log:
|
|
||||||
logfile = open("{}/{}.log".format(case, name), "a")
|
|
||||||
|
|
||||||
mpirun = []
|
|
||||||
if parallel:
|
|
||||||
mpirun = ["mpirun", "-np", "4", "--oversubscribe"]
|
|
||||||
|
|
||||||
subprocess.run(mpirun + [name, "-case", case] + args,
|
|
||||||
stdout=logfile if log else subprocess.STDOUT,
|
|
||||||
stderr=logfile if log else subprocess.STDOUT)
|
|
||||||
|
|
||||||
if log:
|
|
||||||
logfile.close()
|
|
||||||
|
|
||||||
def ideasUnvToFoam(case, mesh):
|
|
||||||
application("ideasUnvToFoam", case, True, [mesh])
|
|
||||||
|
|
||||||
def createPatch(case):
|
|
||||||
application("createPatch", case, True, ["-overwrite"])
|
|
||||||
|
|
||||||
def transformPoints(case, vector):
|
|
||||||
application("transformPoints", case, True, ["-scale", vector])
|
|
||||||
|
|
||||||
def checkMesh(case):
|
|
||||||
application("checkMesh", case, True, ["-allGeometry", "-allTopology"])
|
|
||||||
|
|
||||||
def foamDictionaryGet(case, foamFile, entry):
|
|
||||||
application("foamDictionary", case, True, [foamFile, "-entry", entry])
|
|
||||||
|
|
||||||
def foamDictionarySet(case, foamFile, entry, value):
|
|
||||||
application("foamDictionary", case, True, [foamFile, "-entry", entry, "-set", value])
|
|
||||||
|
|
||||||
def decomposePar(case):
|
|
||||||
application("decomposePar", case, True)
|
|
||||||
|
|
||||||
def potentialFoam(case):
|
|
||||||
application("potentialFoam", case, True, ["-parallel"], True)
|
|
||||||
|
|
||||||
def simpleFoam(case):
|
|
||||||
application("simpleFoam", case, True, ["-parallel"], True)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
###
|
||||||
|
# SALOME
|
||||||
|
#
|
||||||
|
# Get main paths
|
||||||
|
project = os.getcwd()
|
||||||
|
src = os.path.join(project, "src")
|
||||||
|
build = os.path.join(project, "build")
|
||||||
|
|
||||||
|
if not os.path.exists(build):
|
||||||
|
os.makedirs(build)
|
||||||
|
|
||||||
|
# Logger
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.INFO,
|
||||||
|
format="%(levelname)s: %(message)s",
|
||||||
|
handlers = [
|
||||||
|
logging.StreamHandler(),
|
||||||
|
logging.FileHandler("{}/genmesh.log".format(build))
|
||||||
|
])
|
||||||
|
start_time = time.monotonic()
|
||||||
|
|
||||||
|
# Start in parallel
|
||||||
|
processes = []
|
||||||
|
structures = ["simpleCubic", "faceCenteredCubic", "bodyCenteredCubic"]
|
||||||
|
directions = ["001"] #, "100", "111"]
|
||||||
|
coefficients = [0.1] #[ alpha * 0.01 for alpha in range(1, 13 + 1) ]
|
||||||
|
port = 2810
|
||||||
|
|
||||||
|
for structure in structures:
|
||||||
|
for direction in directions:
|
||||||
|
for coefficient in coefficients:
|
||||||
|
src_path = os.path.join(src, "{}.py".format(structure))
|
||||||
|
build_path = os.path.join(build,
|
||||||
|
structure,
|
||||||
|
"direction-{}".format(direction),
|
||||||
|
"alpha-{}".format(coefficient))
|
||||||
|
|
||||||
|
if not os.path.exists(build_path):
|
||||||
|
os.makedirs(build_path)
|
||||||
|
|
||||||
|
p = multiprocessing.Process(target = salome,
|
||||||
|
args = (port, src_path, build_path, coefficient, direction))
|
||||||
|
processes.append(p)
|
||||||
|
p.start()
|
||||||
|
logging.info("{} on port {}.".format(p, port))
|
||||||
|
port += 1
|
||||||
|
|
||||||
|
for process in processes:
|
||||||
|
process.join()
|
||||||
|
|
||||||
|
end_time = time.monotonic()
|
||||||
|
logging.info("Elapsed time: {}".format(timedelta(seconds=end_time - start_time)))
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
# FOAM
|
||||||
|
#
|
||||||
# Get main paths
|
# Get main paths
|
||||||
project = os.getcwd()
|
project = os.getcwd()
|
||||||
src = os.path.join(project, "src")
|
src = os.path.join(project, "src")
|
53
src/foam_utils.py
Normal file
53
src/foam_utils.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import os, shutil
|
||||||
|
import subprocess
|
||||||
|
import logging
|
||||||
|
import time
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
def application(name, case, log=False, args=[], parallel=False):
|
||||||
|
logging.info("Running '{}'.".format(name))
|
||||||
|
|
||||||
|
if log:
|
||||||
|
logfile = open("{}/{}.log".format(case, name), "a")
|
||||||
|
|
||||||
|
mpirun = []
|
||||||
|
if parallel:
|
||||||
|
mpirun = ["mpirun", "-np", "4", "--oversubscribe"]
|
||||||
|
|
||||||
|
subprocess.run(mpirun + [name, "-case", case] + args,
|
||||||
|
stdout=logfile if log else subprocess.STDOUT,
|
||||||
|
stderr=logfile if log else subprocess.STDOUT)
|
||||||
|
|
||||||
|
if log:
|
||||||
|
logfile.close()
|
||||||
|
|
||||||
|
def ideasUnvToFoam(case, mesh):
|
||||||
|
application("ideasUnvToFoam", case, True, [mesh])
|
||||||
|
|
||||||
|
def createPatch(case):
|
||||||
|
application("createPatch", case, True, ["-overwrite"])
|
||||||
|
|
||||||
|
def transformPoints(case, vector):
|
||||||
|
application("transformPoints", case, True, ["-scale", vector])
|
||||||
|
|
||||||
|
def checkMesh(case):
|
||||||
|
application("checkMesh", case, True, ["-allGeometry", "-allTopology"])
|
||||||
|
|
||||||
|
def foamDictionaryGet(case, foamFile, entry):
|
||||||
|
application("foamDictionary", case, True, [foamFile, "-entry", entry])
|
||||||
|
|
||||||
|
def foamDictionarySet(case, foamFile, entry, value):
|
||||||
|
application("foamDictionary", case, True, [foamFile, "-entry", entry, "-set", value])
|
||||||
|
|
||||||
|
def decomposePar(case):
|
||||||
|
application("decomposePar", case, True)
|
||||||
|
|
||||||
|
def potentialFoam(case):
|
||||||
|
application("potentialFoam", case, True, ["-parallel"], True)
|
||||||
|
|
||||||
|
def simpleFoam(case):
|
||||||
|
application("simpleFoam", case, True, ["-parallel"], True)
|
||||||
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import salome
|
import salome
|
||||||
|
import subprocess
|
||||||
|
import logging
|
||||||
|
|
||||||
def hasDesktop() -> bool:
|
def hasDesktop() -> bool:
|
||||||
return salome.sg.hasDesktop()
|
return salome.sg.hasDesktop()
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from . import geometry_utils
|
from . import geometry_utils
|
||||||
import GEOM
|
import GEOM
|
||||||
|
|
||||||
@ -8,6 +5,8 @@ from . import mesh_utils
|
|||||||
import SMESH
|
import SMESH
|
||||||
|
|
||||||
from . import anisotropeCubic
|
from . import anisotropeCubic
|
||||||
|
import salome
|
||||||
|
import math
|
||||||
|
|
||||||
def simpleCubic(theta, flowdirection):
|
def simpleCubic(theta, flowdirection):
|
||||||
radius = 1
|
radius = 1
|
||||||
@ -16,7 +15,7 @@ def simpleCubic(theta, flowdirection):
|
|||||||
layers = [3, 3, 3]
|
layers = [3, 3, 3]
|
||||||
grains = anisotropeCubic.StructuredGrains(radius, stackAngle, theta, layers)
|
grains = anisotropeCubic.StructuredGrains(radius, stackAngle, theta, layers)
|
||||||
|
|
||||||
scale = [1, 1, 1]
|
scale = [2 * math.sqrt(2), 2 * math.sqrt(2), 2]
|
||||||
flowdirection = flowdirection if flowdirection else [1, 0, 0]
|
flowdirection = flowdirection if flowdirection else [1, 0, 0]
|
||||||
style = 0
|
style = 0
|
||||||
cubic = anisotropeCubic.AnisotropeCubic(scale, grains, style)
|
cubic = anisotropeCubic.AnisotropeCubic(scale, grains, style)
|
||||||
@ -34,7 +33,7 @@ def bodyCenteredCubic(theta, flowdirection):
|
|||||||
layers = [3, 3, 3]
|
layers = [3, 3, 3]
|
||||||
grains = anisotropeCubic.StructuredGrains(radius, stackAngle, theta, layers)
|
grains = anisotropeCubic.StructuredGrains(radius, stackAngle, theta, layers)
|
||||||
|
|
||||||
scale = [1, 1, 1]
|
scale = [2 / math.sqrt(2), 2 / math.sqrt(2), 1]
|
||||||
flowdirection = flowdirection if flowdirection else [1, 0, 0]
|
flowdirection = flowdirection if flowdirection else [1, 0, 0]
|
||||||
style = 0
|
style = 0
|
||||||
cubic = anisotropeCubic.AnisotropeCubic(scale, grains, style)
|
cubic = anisotropeCubic.AnisotropeCubic(scale, grains, style)
|
||||||
@ -52,7 +51,7 @@ def faceCenteredCubic(theta, flowdirection):
|
|||||||
layers = [3, 3, 3]
|
layers = [3, 3, 3]
|
||||||
grains = anisotropeCubic.StructuredGrains(radius, stackAngle, theta, layers)
|
grains = anisotropeCubic.StructuredGrains(radius, stackAngle, theta, layers)
|
||||||
|
|
||||||
scale = [1, 1, 1]
|
scale = [1 / math.sqrt(2), 1 / math.sqrt(2), 1]
|
||||||
flowdirection = flowdirection if flowdirection else [1, 0, 0]
|
flowdirection = flowdirection if flowdirection else [1, 0, 0]
|
||||||
style = 0
|
style = 0
|
||||||
cubic = anisotropeCubic.AnisotropeCubic(scale, grains, style)
|
cubic = anisotropeCubic.AnisotropeCubic(scale, grains, style)
|
||||||
@ -63,5 +62,8 @@ def faceCenteredCubic(theta, flowdirection):
|
|||||||
mesh_utils.meshCompute(mesh)
|
mesh_utils.meshCompute(mesh)
|
||||||
|
|
||||||
|
|
||||||
def genMesh():
|
def genMesh(ctype, theta, flowdirection):
|
||||||
pass
|
salome.salome_init()
|
||||||
|
|
||||||
|
|
||||||
|
salome.salome_close()
|
||||||
|
@ -6,7 +6,7 @@ def queue(cmd, qin, qout, *args):
|
|||||||
# Get item from the queue
|
# Get item from the queue
|
||||||
pos, var = qin.get()
|
pos, var = qin.get()
|
||||||
|
|
||||||
# Exit if last item is None
|
# Exit point
|
||||||
if pos is None:
|
if pos is None:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user