Performing globalization
This commit is contained in:
parent
f8c35fa369
commit
d13ff1bc7d
63
run.py
63
run.py
@ -1,5 +1,64 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import os, sys
|
||||
from collections import namedtuple
|
||||
|
||||
ROOT = os.getcwd()
|
||||
sys.path.append(ROOT)
|
||||
|
||||
import src.utils
|
||||
import src.salome_utils
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
nprocs = os.cpu_count()
|
||||
port = 2810
|
||||
salomeServers = []
|
||||
salomeServer = namedtuple("salomeServer", ["process", "port"])
|
||||
|
||||
for n in range(nprocs):
|
||||
while not utils.portIsFree:
|
||||
port += 1
|
||||
|
||||
s = salomeServer(salome_utils.startServer(port), port)
|
||||
salomeServers.append(s)
|
||||
|
||||
var = []
|
||||
cmd = "python "
|
||||
|
||||
# TODO: pass it to samples in namedtuples
|
||||
# get sample.directions and etc ..
|
||||
structures = [
|
||||
"simpleCubic",
|
||||
"bodyCenteredCubic",
|
||||
"faceCenteredCubic"
|
||||
]
|
||||
directions = [
|
||||
[1, 0, 0],
|
||||
[0, 0, 1],
|
||||
[1, 1, 1]
|
||||
]
|
||||
|
||||
cmd += "-m "
|
||||
var.append((salomeServer[n].port, cmd))
|
||||
|
||||
utils.parallel(nprocs, var, salome_utils.execute)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
###
|
||||
|
@ -1,13 +1,28 @@
|
||||
from . import geometry_utils
|
||||
from .src import geometry_utils
|
||||
import GEOM
|
||||
|
||||
from . import mesh_utils
|
||||
from .src import mesh_utils
|
||||
import SMESH
|
||||
|
||||
from . import anisotropeCubic
|
||||
from .src import anisotropeCubic
|
||||
import salome
|
||||
import math
|
||||
|
||||
def genMesh(ctype, theta, flowdirection):
|
||||
_G = globals()
|
||||
|
||||
for g in _G:
|
||||
func = g.get(ctype)
|
||||
|
||||
if func:
|
||||
salome.salome_init()
|
||||
func(theta, flowdirection)
|
||||
salome.salome_close()
|
||||
|
||||
else:
|
||||
raise Exception("Unknown type of the sample function")
|
||||
|
||||
|
||||
def simpleCubic(theta, flowdirection):
|
||||
radius = 1
|
||||
stackAngle = [0.5 * math.pi, 0.5 * math.pi, 0.5 * math.pi]
|
||||
@ -62,8 +77,3 @@ def faceCenteredCubic(theta, flowdirection):
|
||||
mesh_utils.meshCompute(mesh)
|
||||
|
||||
|
||||
def genMesh(ctype, theta, flowdirection):
|
||||
salome.salome_init()
|
||||
|
||||
|
||||
salome.salome_close()
|
0
src/__init__.py
Normal file
0
src/__init__.py
Normal file
@ -1,6 +1,3 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import salome
|
||||
import subprocess
|
||||
import logging
|
||||
@ -8,45 +5,37 @@ import logging
|
||||
def hasDesktop() -> bool:
|
||||
return salome.sg.hasDesktop()
|
||||
|
||||
def startServer(port, logPath):
|
||||
def startServer(port):
|
||||
|
||||
log = open("{}/salome.log".format(logPath), "a")
|
||||
logging.info("Starting SALOME on port {} ...".format(port))
|
||||
|
||||
p = subprocess.Popen(["salome", "start", "--port", str(port), "-t"],
|
||||
shell = True,
|
||||
stdout = log,
|
||||
stderr = log)
|
||||
|
||||
log.close()
|
||||
shell = False,
|
||||
stdout = subprocess.PIPE,
|
||||
stderr = subprocess.PIPE)
|
||||
|
||||
return p
|
||||
|
||||
def killServer(port, logPath):
|
||||
def killServer(port):
|
||||
|
||||
log = open("{}/salome.log".format(logPath), "a")
|
||||
logging.info("Terminating SALOME on port {} ...".format(port))
|
||||
|
||||
p = subprocess.Popen(["salome", "kill", str(port)],
|
||||
shell = True,
|
||||
stdout = log,
|
||||
stderr = log)
|
||||
|
||||
log.close()
|
||||
stdout = subprocess.PIPE,
|
||||
stderr = subprocess.PIPE)
|
||||
|
||||
return p
|
||||
|
||||
def execute(port, cmd, logPath):
|
||||
def execute(port, cmd):
|
||||
|
||||
log = open("{}/salome.log".format(logPath), "a")
|
||||
logging.info("Executing command in the SALOME on port {} ...".format(port))
|
||||
|
||||
p = subprocess.Popen(["salome", "connect", "-p", str(port), str(cmd)],
|
||||
|
||||
# cmd = "python -m"; = "python -c"
|
||||
p = subprocess.Popen(["salome", "remote", "-p", str(port), "--", str(cmd)],
|
||||
shell = True,
|
||||
stdout = log,
|
||||
stderr = log)
|
||||
|
||||
log.close()
|
||||
stdout = subprocess.PIPE,
|
||||
stderr = subprocess.PIPE)
|
||||
|
||||
return p
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
from multiprocessing import Queue, Process, cpu_count
|
||||
import socket
|
||||
|
||||
def queue(cmd, qin, qout, *args):
|
||||
|
||||
@ -64,4 +65,8 @@ def parallel(np, var, cmd):
|
||||
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