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.
|
|
|
|
"""
|
2021-03-03 22:16:36 +05:00
|
|
|
logging.info("Starting SALOME on port {}.".format(port))
|
|
|
|
salomelog = open("{}/salome.log".format(build_path), "a")
|
|
|
|
|
|
|
|
subprocess.run([
|
|
|
|
"salome", "start",
|
|
|
|
"--port", str(port),
|
|
|
|
"-t", src_path,
|
|
|
|
"args:{},{},{}".format(build_path, coefficient, direction)
|
|
|
|
],
|
|
|
|
stdout=salomelog,
|
|
|
|
stderr=salomelog)
|
|
|
|
|
|
|
|
logging.info("Terminating SALOME on port {}.".format(port))
|
2021-03-03 16:24:47 +05:00
|
|
|
|
2021-03-03 22:16:36 +05:00
|
|
|
subprocess.run([
|
|
|
|
"salome", "kill",
|
|
|
|
str(port)
|
|
|
|
],
|
|
|
|
stdout=salomelog,
|
|
|
|
stderr=salomelog)
|
|
|
|
|
|
|
|
salomelog.close()
|
|
|
|
|
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
|
2021-03-03 22:16:36 +05:00
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.INFO,
|
|
|
|
format="%(levelname)s: %(message)s",
|
|
|
|
handlers = [
|
|
|
|
logging.StreamHandler(),
|
|
|
|
logging.FileHandler("{}/genmesh.log".format(build))
|
|
|
|
])
|
2021-03-03 16:24:47 +05:00
|
|
|
start_time = time.monotonic()
|
|
|
|
|
|
|
|
# Start in parallel
|
2021-03-03 13:00:28 +05:00
|
|
|
processes = []
|
2021-03-09 13:13:31 +05:00
|
|
|
structures = ["simpleCubic", "faceCenteredCubic"] #, "bodyCenteredCubic"]
|
2021-03-06 19:19:43 +05:00
|
|
|
directions = ["001"] #, "100", "111"]
|
|
|
|
coefficients = [0.1] #[ 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
|
|
|
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)))
|
|
|
|
|