anisotropy/src/genmesh.py

73 lines
2.4 KiB
Python
Raw Normal View History

2021-02-17 21:41:19 +05:00
import os
import subprocess
import multiprocessing
2021-03-03 16:24:47 +05:00
import logging
import time
from datetime import timedelta
2021-02-17 21:41:19 +05:00
2021-03-03 16:24:47 +05:00
def salome(port, src_path, build_path, coefficient, direction):
"""
Run salome and terminate after.
Parameters:
port (int): Port for the process.
src_path (str): Path to the execution script.
build_path (str): Output path.
"""
logging.info("Starting SALOME on port {} for {}".format(port, build_path))
subprocess.run(["salome", "start",
"--port", str(port),
"-t", src_path,
"args:{},{},{}".format(build_path, coefficient, direction)])
logging.info("Terminating SALOME on port {} for {}".format(port, build_path))
subprocess.run(["salome", "kill", str(port)])
2021-03-03 13:00:28 +05:00
if __name__ == "__main__":
# Get main paths
project = os.getcwd()
src = os.path.join(project, "src")
build = os.path.join(project, "build")
2021-03-03 16:24:47 +05:00
2021-03-03 13:00:28 +05:00
if not os.path.exists(build):
2021-03-03 16:24:47 +05:00
os.makedirs(build)
2021-03-03 13:00:28 +05:00
2021-03-03 16:24:47 +05:00
# Logger
logging.basicConfig(filename="{}/genmesh.log".format(build),
level=logging.INFO, format="%(levelname)s: %(name)s: %(message)s")
start_time = time.monotonic()
# Start in parallel
2021-03-03 13:00:28 +05:00
processes = []
2021-03-03 16:24:47 +05:00
structures = ["simpleCubic"] #, "bc-cubic", "fc-cubic"]
2021-03-03 13:00:28 +05:00
directions = ["001", "100"]
coefficients = [ alpha * 0.01 for alpha in range(1, 13 + 1) ]
2021-03-03 16:24:47 +05:00
port = 2810
2021-03-03 13:00:28 +05:00
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)
2021-03-03 16:24:47 +05:00
logging.info("{} created.".format(build_path))
2021-03-03 13:00:28 +05:00
2021-03-03 16:24:47 +05:00
p = multiprocessing.Process(target = salome,
args = (port, src_path, build_path, coefficient, direction))
2021-03-03 13:00:28 +05:00
processes.append(p)
p.start()
2021-03-03 16:24:47 +05:00
logging.info("{} on port {}.".format(p, port))
port += 1
2021-03-03 13:00:28 +05:00
for process in processes:
process.join()
2021-03-03 16:24:47 +05:00
end_time = time.monotonic()
logging.info("Elapsed time: {}".format(timedelta(seconds=end_time - start_time)))