Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
fossils
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Boman Romain
fossils
Commits
5d04649d
Commit
5d04649d
authored
2 years ago
by
Boman Romain
Browse files
Options
Downloads
Patches
Plain Diff
make functions
parent
60220c3f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#7085
passed
2 years ago
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fossils.py
+65
-64
65 additions, 64 deletions
fossils.py
with
65 additions
and
64 deletions
fossils.py
+
65
−
64
View file @
5d04649d
#!/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
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment