Skip to content
Snippets Groups Projects
Commit 5d04649d authored by Boman Romain's avatar Boman Romain
Browse files

make functions

parent 60220c3f
No related branches found
No related tags found
No related merge requests found
Pipeline #7085 passed
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# runs a test as if it was installed
# import os
# import platform
# if 'Windows' in platform.uname():
# # remove tbb from the PATH
# # otherwise: "Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll"
# paths = os.environ['PATH'].split(';')
# corr_path = [ p for p in paths if not 'tbb' in p]
# os.environ['PATH'] = ';'.join(corr_path)
# for p in corr_path:
# print(p)
from PyQt5.QtCore import * from PyQt5.QtCore import *
from PyQt5.QtGui import * from PyQt5.QtGui import *
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
from ui_fossils import Ui_Form from ui_fossils import Ui_Form
import sys
import os
class Window(QWidget, Ui_Form): class Window(QWidget, Ui_Form):
"""Minimal GUI asking for a file and running it """Minimal GUI asking for a file and running it
...@@ -70,23 +60,69 @@ class Window(QWidget, Ui_Form): ...@@ -70,23 +60,69 @@ class Window(QWidget, Ui_Form):
event.accept() event.accept()
def run_simulation(testname):
"""Runs a python file
"""
if __name__ == "__main__": exec(open(testname, encoding='utf-8').read(),
import sys {'__file__': testname, '__name__':'__main__'})
import os
# adds "." to the pythonpath
def view_results():
"""Load/display results in the current folder
"""
import gmsh
if not gmsh.isInitialized():
gmsh.initialize()
# load empty mesh
gmsh.merge('mesh.msh')
gmsh.option.setNumber("General.Verbosity", 3)
# load views from the option file
views = []
with open('mesh.opt') as f:
import re
viewregex = re.compile('View\[(.+)\].FileName = "(.+)";')
for l in f.readlines():
match = viewregex.search(l)
if match:
g = match.groups()
views.append(g)
for v in views:
print(f'loading "{v[1]}"')
gmsh.merge(v[1])
print('loading options...')
gmsh.merge('mesh.opt')
print('starting Gmsh GUI, please wait...')
gmsh.fltk.run()
def add_folder2path(folder):
if os.path.isdir(folder):
print(f'{folder} added to pythonpath')
sys.path.append(folder)
def setup_pythonpath():
"""setup PYTHONPATH
"""
# adds script folder to the pythonpath
thisdir = os.path.split(os.path.abspath(__file__))[0] thisdir = os.path.split(os.path.abspath(__file__))[0]
thisdir = os.path.normcase(thisdir) thisdir = os.path.normcase(thisdir)
print(f'adding {thisdir} to pythonpath') add_folder2path(thisdir)
sys.path.append(thisdir)
# add binary dir to PYTHONPATH # add binary dir to PYTHONPATH
pyexe = os.path.basename(sys.executable) pyexe = os.path.basename(sys.executable)
print(f'pyexe={pyexe}') print(f'pyexe = {pyexe}')
sys.path.append(os.path.join(thisdir, 'cxxfem', add_folder2path(os.path.join(thisdir, 'cxxfem',
'build', 'bin')) # gcc/mingw 'build', 'bin')) # gcc/mingw
sys.path.append(os.path.join(thisdir, 'cxxfem', add_folder2path(os.path.join(thisdir, 'cxxfem',
'build', 'bin', 'Release')) # msvc 'build', 'bin', 'Release')) # msvc
if __name__ == "__main__":
# add main program folder and binaries dir to the PYTHONPATH
setup_pythonpath()
# redirect C++ streams to Python # redirect C++ streams to Python
import cxxfem import cxxfem
...@@ -97,17 +133,6 @@ if __name__ == "__main__": ...@@ -97,17 +133,6 @@ if __name__ == "__main__":
os.environ['OMP_NUM_THREADS'] = str(args.k) os.environ['OMP_NUM_THREADS'] = str(args.k)
cxxfem.set_num_threads(args.k) cxxfem.set_num_threads(args.k)
# try:
# ncpus1 = int(os.environ['NUMBER_OF_PROCESSORS'])
# print(f'{ncpus1} CPUs detected')
# import multiprocessing
# ncpus2 = multiprocessing.cpu_count()
# print(f'{ncpus2} CPUs detected')
# ncpus3 = os.cpu_count()
# print(f'{ncpus3} CPUs detected')
# except:
# pass
# display env variables # display env variables
try: try:
print(f"OMP_NUM_THREADS={os.environ['OMP_NUM_THREADS']}") print(f"OMP_NUM_THREADS={os.environ['OMP_NUM_THREADS']}")
...@@ -126,6 +151,7 @@ if __name__ == "__main__": ...@@ -126,6 +151,7 @@ if __name__ == "__main__":
win.show() win.show()
app.lastWindowClosed.connect(app.quit) app.lastWindowClosed.connect(app.quit)
app.exec_() app.exec_()
workspace = win.wrkspLineEdit.text() workspace = win.wrkspLineEdit.text()
action = win.action action = win.action
testname = win.inpFileLineEdit.text() testname = win.inpFileLineEdit.text()
...@@ -134,9 +160,9 @@ if __name__ == "__main__": ...@@ -134,9 +160,9 @@ if __name__ == "__main__":
action = 'run' action = 'run'
testname = os.path.abspath(args.file) testname = os.path.abspath(args.file)
# run the simulation or display results
# run the simulation
print(f'action={action}') print(f'action = {action}')
if action=='run' or action=='post': if action=='run' or action=='post':
testname = os.path.normcase(testname) # F:/ => f:/ on Windows testname = os.path.normcase(testname) # F:/ => f:/ on Windows
print(f'testname = {testname}') print(f'testname = {testname}')
...@@ -152,7 +178,7 @@ if __name__ == "__main__": ...@@ -152,7 +178,7 @@ if __name__ == "__main__":
resdir = testname[len(common):].replace(os.sep, "_") resdir = testname[len(common):].replace(os.sep, "_")
resdir, ext = os.path.splitext(resdir) resdir, ext = os.path.splitext(resdir)
wdir = os.path.join('workspace', resdir) wdir = os.path.join('workspace', resdir)
print('workspace=', wdir) print('workspace =', wdir)
if not os.path.isdir(wdir): if not os.path.isdir(wdir):
os.makedirs(wdir) os.makedirs(wdir)
...@@ -161,31 +187,6 @@ if __name__ == "__main__": ...@@ -161,31 +187,6 @@ if __name__ == "__main__":
tee = cxxfem.Tee('stdout.txt') # split streams tee = cxxfem.Tee('stdout.txt') # split streams
if action == 'run': if action == 'run':
if ext == '.py': run_simulation(testname)
# run python script
__file__ = testname
exec(open(testname, encoding='utf-8').read())
elif action == 'post': elif action == 'post':
import gmsh view_results()
if not gmsh.isInitialized():
gmsh.initialize()
# load empty mesh
gmsh.merge('mesh.msh')
gmsh.option.setNumber("General.Verbosity", 3)
# load views from the option file
views = []
with open('mesh.opt') as f:
import re
viewregex = re.compile('View\[(.+)\].FileName = "(.+)";')
for l in f.readlines():
match = viewregex.search(l)
if match:
g = match.groups()
views.append(g)
for v in views:
print(f'loading "{v[1]}"')
gmsh.merge(v[1])
print('loading options...')
gmsh.merge('mesh.opt')
print('starting Gmsh GUI, please wait...')
gmsh.fltk.run()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment