Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dumux
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
Commits
8437f927
Commit
8437f927
authored
3 years ago
by
Timo Koch
Browse files
Options
Downloads
Patches
Plain Diff
[python][common] Improve style, add some, use wrapper helpers
parent
499669cf
No related branches found
No related tags found
1 merge request
!2681
Feature/python main file
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/dumux/common/__init__.py
+70
-26
70 additions, 26 deletions
python/dumux/common/__init__.py
with
70 additions
and
26 deletions
python/dumux/common/__init__.py
+
70
−
26
View file @
8437f927
from
._common
import
*
from
dumux.common.properties
import
Model
,
Property
"""
The DuMux common module
containing classes and functions needed for most simulations
"""
from
dune.generator.generator
import
SimpleGenerator
from
dune.common.hashit
import
hashIt
from
dumux.common.properties
import
Model
,
Property
from
dumux.wrapping
import
cppWrapperCreator
,
cppWrapperClassAlias
from
._common
import
*
@cppWrapperCreator
def
_createFVProblemDecorator
(
gridGeometry
,
enableInternalDirichletConstraints
=
False
):
"""
A problem decorator generator for Python problems
from dumux.common import FVProblem
@FVProblem(gridGeometry)
class MyProblem:
...
"""
# A problem decorator generator for Python problems
#
# from dumux.common import FVProblem
# @FVProblem(gridGeometry)
# class MyProblem:
# ...
#
def
FVProblem
(
gridGeometry
,
enableInternalDirichletConstraints
=
False
):
def
createModule
(
numEq
):
priVarType
=
"
Dune::FieldVector<double, {}>
"
.
format
(
numEq
)
ggType
=
gridGeometry
.
_typeName
...
...
@@ -28,19 +36,26 @@ def FVProblem(gridGeometry, enableInternalDirichletConstraints=False):
module
=
generator
.
load
(
includes
,
problemType
,
moduleName
,
options
=
[
holderType
])
return
module
def
FVProblem
Decorator
(
C
ls
):
module
=
createModule
(
C
ls
.
numEq
)
def
decorate
FVProblem
(
c
ls
):
module
=
createModule
(
c
ls
.
numEq
)
def
createFVProblem
():
return
module
.
FVProblem
(
gridGeometry
,
C
ls
())
return
module
.
FVProblem
(
gridGeometry
,
c
ls
())
return
createFVProblem
return
FVProblemDecorator
return
decorateFVProblem
@cppWrapperClassAlias
(
creator
=
_createFVProblemDecorator
)
class
FVProblem
:
"""
Class alias used to decorate a Python finite volume problem
"""
# Function for JIT copmilation of Dumux::BoundaryTypes
def
BoundaryTypes
(
numEq
=
1
):
@cppWrapperCreator
def
_createBoundaryTypes
(
numEq
=
1
):
"""
Create BoundaryTypes instances
"""
# only compile this once per numEq
cacheKey
=
"
BoundaryTypes_{}
"
.
format
(
numEq
)
try
:
...
...
@@ -55,7 +70,30 @@ def BoundaryTypes(numEq=1):
return
globals
()[
cacheKey
]()
def
Parameters
(
dict
=
{},
file
=
None
):
@cppWrapperClassAlias
(
creator
=
_createBoundaryTypes
)
class
BoundaryTypes
:
"""
Class alias used to create a BoundaryTypes instance
"""
@cppWrapperCreator
def
_createParameters
(
params
:
dict
=
None
,
fileName
:
str
=
None
):
"""
Create Parameters
Args:
params (dict): A dictionary of parameter key-value pairs
fileName (str): Optionally a file to read parameters from
Usage:
parameters = Parameters(
{
"
Problem.EnableGravity
"
: True,
"
SpatialParams.Porosity
"
: 0.3,
"
SpatialParams.Permeability
"
: 1e-8,
"
Vtk.AddVelocity
"
: False,
"
Assembly.NumericDifference.PriVarMagnitude
"
: 1e5,
}
)
"""
parametersType
=
"
Dumux::Parameters
"
includes
=
[
"
dumux/common/parameters.hh
"
,
"
dumux/python/common/parameters.hh
"
]
moduleName
=
"
parameters_
"
+
hashIt
(
parametersType
)
...
...
@@ -63,11 +101,17 @@ def Parameters(dict={}, file=None):
module
=
generator
.
load
(
includes
,
parametersType
,
moduleName
)
# make sure all dict keys are strings
for
key
in
dict
:
if
not
isinstance
(
dict
[
key
],
str
):
dict
[
key
]
=
str
(
dict
[
key
])
if
file
is
not
None
:
return
module
.
Parameters
(
file
,
dict
)
else
:
return
module
.
Parameters
(
dict
)
if
params
is
None
:
params
=
{}
for
key
,
value
in
params
.
items
():
params
[
key
]
=
str
(
value
)
if
fileName
is
not
None
:
return
module
.
Parameters
(
fileName
,
params
)
return
module
.
Parameters
(
params
)
@cppWrapperClassAlias
(
creator
=
_createParameters
)
class
Parameters
:
"""
Class alias used to create a Parameters instance
"""
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