Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dumux-course
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dumux-repositories
dumux-course
Commits
c85d2372
Commit
c85d2372
authored
1 year ago
by
Timo Koch
Browse files
Options
Downloads
Patches
Plain Diff
[slides] Add some Python slides
parent
e10cf3e7
No related branches found
No related tags found
No related merge requests found
Pipeline
#30543
passed
1 year ago
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
slides/python.md
+61
-0
61 additions, 0 deletions
slides/python.md
with
61 additions
and
0 deletions
slides/python.md
0 → 100644
+
61
−
0
View file @
c85d2372
---
title
:
Python bindings
---
# DuMu^x^ Python bindings
## Using DuMu^x^ from Python
*
Based on just-in-time (JIT) compilation of Python binding code
*
Experimental feature: only a small subset of functionality is available
*
See
[
Python test apps
](
https://git.iws.uni-stuttgart.de/dumux-repositories/dumux/-/tree/master/test/python
)
## Configuration
*
Enabled and built by default!
*
`dune-common`
configures a
[
Python virtual environment
](
https://docs.python.org/3/library/venv.html
)
(
`dune-common/build-cmake/dune-env`
)
*
Automatically created and set up when running
`dunecontrol`
*
To activate:
`source dune-common/build-cmake/dune-env/bin/activate`
## Configuration
For more control, follow
```
./dune-common/bin/dunecontrol bexec rm -r CMakeFiles CMakeCache.txt
python3 -m venv venv
source venv/bin/activate
./dune-common/bin/dunecontrol --opts=dumux.opts configure
./dune-common/bin/dunecontrol --opts=dumux.opts make -j
```
which installs Python bindings into the activated virtual environment.
## Example Python code
*
See
[
dumux/test/python/test_1p.py
](
https://git.iws.uni-stuttgart.de/dumux-repositories/dumux/-/blob/master/test/python/test_1p.py
)
*
With virtual environment activated, run
```
python3 test_1p.py
```
*
First time takes very long, due to a lot of JIT
*
Second run is much faster
## Small exercise
*
Increase the number of grid cells to $100
\t
imes 100$
*
Add a constant source term of $10.0$
*
Note that you don't have to recompile
*
Visualization:
`pip install pyvista`
and append
```
py
import
pyvista
as
pv
mesh
=
pv
.
read
(
"
test_1p_box_numeric-00000.vtu
"
)
mesh
.
plot
(
show_edges
=
True
,
full_screen
=
True
)
```
## Further resources
*
[
DuMu^x^ documentation
](
https://dumux.org/docs/doxygen/master/python-bindings.html
)
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