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
# -*- 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.QtGui import *
from PyQt5.QtWidgets import *
from ui_fossils import Ui_Form
import sys
import os
class Window(QWidget, Ui_Form):
"""Minimal GUI asking for a file and running it
......@@ -70,23 +60,69 @@ class Window(QWidget, Ui_Form):
event.accept()
def run_simulation(testname):
"""Runs a python file
"""
if __name__ == "__main__":
import sys
import os
# adds "." to the pythonpath
exec(open(testname, encoding='utf-8').read(),
{'__file__': testname, '__name__':'__main__'})
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.normcase(thisdir)
print(f'adding {thisdir} to pythonpath')
sys.path.append(thisdir)
add_folder2path(thisdir)
# add binary dir to PYTHONPATH
pyexe = os.path.basename(sys.executable)
print(f'pyexe={pyexe}')
sys.path.append(os.path.join(thisdir, 'cxxfem',
print(f'pyexe = {pyexe}')
add_folder2path(os.path.join(thisdir, 'cxxfem',
'build', 'bin')) # gcc/mingw
sys.path.append(os.path.join(thisdir, 'cxxfem',
'build', 'bin', 'Release')) # msvc
add_folder2path(os.path.join(thisdir, 'cxxfem',
'build', 'bin', 'Release')) # msvc
if __name__ == "__main__":
# add main program folder and binaries dir to the PYTHONPATH
setup_pythonpath()
# redirect C++ streams to Python
import cxxfem
......@@ -97,17 +133,6 @@ if __name__ == "__main__":
os.environ['OMP_NUM_THREADS'] = str(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
try:
print(f"OMP_NUM_THREADS={os.environ['OMP_NUM_THREADS']}")
......@@ -126,6 +151,7 @@ if __name__ == "__main__":
win.show()
app.lastWindowClosed.connect(app.quit)
app.exec_()
workspace = win.wrkspLineEdit.text()
action = win.action
testname = win.inpFileLineEdit.text()
......@@ -134,9 +160,9 @@ if __name__ == "__main__":
action = 'run'
testname = os.path.abspath(args.file)
# run the simulation
print(f'action={action}')
# run the simulation or display results
print(f'action = {action}')
if action=='run' or action=='post':
testname = os.path.normcase(testname) # F:/ => f:/ on Windows
print(f'testname = {testname}')
......@@ -152,7 +178,7 @@ if __name__ == "__main__":
resdir = testname[len(common):].replace(os.sep, "_")
resdir, ext = os.path.splitext(resdir)
wdir = os.path.join('workspace', resdir)
print('workspace=', wdir)
print('workspace =', wdir)
if not os.path.isdir(wdir):
os.makedirs(wdir)
......@@ -161,31 +187,6 @@ if __name__ == "__main__":
tee = cxxfem.Tee('stdout.txt') # split streams
if action == 'run':
if ext == '.py':
# run python script
__file__ = testname
exec(open(testname, encoding='utf-8').read())
run_simulation(testname)
elif action == 'post':
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()
view_results()
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