Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fluidsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
This instance will be upgraded to Heptapod 17.11.0rc1 on 2025-04-24 between 17:00 and 18:00 UTC+2
Show more breadcrumbs
fluiddyn
fluidsim
Commits
e5067f49
Commit
e5067f49
authored
6 years ago
by
Ashwin Vishnu
Browse files
Options
Downloads
Patches
Plain Diff
Extensible magics and util functions: package argument
parent
56f703d7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
fluidsim/magic.py
+8
-3
8 additions, 3 deletions
fluidsim/magic.py
fluidsim/util/util.py
+20
-15
20 additions, 15 deletions
fluidsim/util/util.py
with
28 additions
and
18 deletions
fluidsim/magic.py
+
8
−
3
View file @
e5067f49
...
...
@@ -77,6 +77,10 @@
"""
def
__init__
(
self
,
shell
,
package_solvers
):
super
(
FluidsimMagics
,
self
).
__init__
(
shell
)
self
.
package
=
package_solvers
def
is_defined
(
self
,
varname
):
user_ns
=
self
.
shell
.
user_ns
return
varname
in
user_ns
and
user_ns
[
varname
]
is
not
None
...
...
@@ -90,7 +94,7 @@
if
args
.
solver
==
""
:
print
(
"
Available solvers:
"
)
pprint
(
available_solver_keys
(),
indent
=
4
,
compact
=
True
)
pprint
(
available_solver_keys
(
self
.
package
),
indent
=
4
,
compact
=
True
)
if
self
.
is_defined
(
"
params
"
)
and
self
.
is_defined
(
"
sim
"
):
print
(
"
\n
Initialized:
"
)
...
...
@@ -114,7 +118,7 @@
return
user_ns
=
self
.
shell
.
user_ns
Simul
=
import_simul_class_from_key
(
args
.
solver
)
Simul
=
import_simul_class_from_key
(
args
.
solver
,
self
.
package
)
params
=
Simul
.
create_default_params
()
print
(
"
Created Simul class and default parameters for
"
,
...
...
@@ -163,4 +167,5 @@
def
load_ipython_extension
(
ipython
):
"""
Load the extension in IPython.
"""
ipython
.
register_magics
(
FluidsimMagics
)
fluidsim_magics
=
FluidsimMagics
(
ipython
,
"
fluidsim.solvers
"
)
ipython
.
register_magics
(
fluidsim_magics
)
This diff is collapsed.
Click to expand it.
fluidsim/util/util.py
+
20
−
15
View file @
e5067f49
...
...
@@ -39,8 +39,9 @@
)
def
available_solver_keys
():
"""
Inspects the subpackage `fluidsim.solvers` for all available
def
available_solver_keys
(
package
=
solvers
):
"""
Inspects a package or a subpackage for all available
solvers.
Returns
...
...
@@ -48,7 +49,10 @@
list
"""
top
=
_os
.
path
.
split
(
inspect
.
getfile
(
solvers
))[
0
]
if
isinstance
(
package
,
str
):
package
=
import_module
(
package
)
top
=
_os
.
path
.
split
(
inspect
.
getfile
(
package
))[
0
]
top
=
_os
.
path
.
abspath
(
top
)
+
_os
.
sep
keys
=
list
()
for
dirpath
,
dirname
,
filenames
in
_os
.
walk
(
top
):
...
...
@@ -61,6 +65,6 @@
return
sorted
(
keys
)
def
module_solver_from_key
(
key
=
None
):
def
module_solver_from_key
(
key
=
None
,
package
=
"
fluidsim.solvers
"
):
"""
Return the string corresponding to a module solver.
"""
key
=
key
.
lower
()
...
...
@@ -65,8 +69,8 @@
"""
Return the string corresponding to a module solver.
"""
key
=
key
.
lower
()
keys
=
available_solver_keys
()
keys
=
available_solver_keys
(
package
)
if
key
in
keys
:
part_path
=
key
else
:
raise
ValueError
(
...
...
@@ -68,8 +72,9 @@
if
key
in
keys
:
part_path
=
key
else
:
raise
ValueError
(
"
You have to give a proper solver key, name solver given:
"
+
key
"
You have to give a proper solver key, name solver given:
"
"
{}. Expected one of: {}
"
.
format
(
key
,
keys
)
)
...
...
@@ -74,8 +79,8 @@
)
base_solvers
=
"
fluidsim.solvers
"
base_solvers
=
package
module_solver
=
base_solvers
+
"
.
"
+
part_path
+
"
.solver
"
return
module_solver
...
...
@@ -77,9 +82,9 @@
module_solver
=
base_solvers
+
"
.
"
+
part_path
+
"
.solver
"
return
module_solver
def
import_module_solver_from_key
(
key
=
None
):
def
import_module_solver_from_key
(
key
=
None
,
package
=
"
fluidsim.solvers
"
):
"""
Import and reload the solver.
Parameters
...
...
@@ -89,6 +94,6 @@
The short name of a solver.
"""
return
import_module
(
module_solver_from_key
(
key
))
return
import_module
(
module_solver_from_key
(
key
,
package
))
...
...
@@ -93,6 +98,6 @@
def
get_dim_from_solver_key
(
key
):
def
get_dim_from_solver_key
(
key
,
package
=
"
fluidsim.solvers
"
):
"""
Try to guess the dimension from the solver key (via the operator name).
"""
...
...
@@ -96,7 +101,7 @@
"""
Try to guess the dimension from the solver key (via the operator name).
"""
cls
=
import_simul_class_from_key
(
key
)
cls
=
import_simul_class_from_key
(
key
,
package
)
info
=
cls
.
InfoSolver
()
for
dim
in
range
(
4
):
if
str
(
dim
)
in
info
.
classes
.
Operators
.
class_name
:
...
...
@@ -108,7 +113,7 @@
)
def
import_simul_class_from_key
(
key
):
def
import_simul_class_from_key
(
key
,
package
=
"
fluidsim.solvers
"
):
"""
Import and reload a simul class.
Parameters
...
...
@@ -118,7 +123,7 @@
The short name of a solver.
"""
solver
=
import_module
(
module_solver_from_key
(
key
))
solver
=
import_module
(
module_solver_from_key
(
key
,
package
))
return
solver
.
Simul
...
...
@@ -135,5 +140,5 @@
class
ModulesSolvers
(
dict
):
"""
Dictionary to gather imported solvers.
"""
def
__init__
(
self
,
names_solvers
):
def
__init__
(
self
,
names_solvers
,
package
=
"
fluidsim.solvers
"
):
for
key
in
names_solvers
:
...
...
@@ -139,5 +144,5 @@
for
key
in
names_solvers
:
self
[
key
]
=
import_module_solver_from_key
(
key
)
self
[
key
]
=
import_module_solver_from_key
(
key
,
package
)
def
name_file_from_time_approx
(
path_dir
,
t_approx
=
None
):
...
...
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