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
9bd121e6
Commit
9bd121e6
authored
3 years ago
by
Kilian Weishaupt
Committed by
Timo Koch
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[python] Add params
parent
153040b7
No related branches found
No related tags found
1 merge request
!2681
Feature/python main file
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dumux/python/common/parameters.hh
+76
-0
76 additions, 0 deletions
dumux/python/common/parameters.hh
python/dumux/common/__init__.py
+23
-1
23 additions, 1 deletion
python/dumux/common/__init__.py
with
99 additions
and
1 deletion
dumux/python/common/parameters.hh
0 → 100644
+
76
−
0
View file @
9bd121e6
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/****************************************************************************
* See the file COPYING for full copying permissions. *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
/*!
* \file
* \brief TODO: docme!
*/
#ifndef DUMUX_PYTHON_COMMON_PARAMETERS_HH
#define DUMUX_PYTHON_COMMON_PARAMETERS_HH
#include
<dumux/common/parameters.hh>
#include
<dune/python/pybind11/pybind11.h>
#include
<dune/python/pybind11/stl.h>
namespace
Dumux
::
Python
{
template
<
class
...
options
>
void
registerParameters
(
pybind11
::
handle
scope
,
pybind11
::
class_
<
Parameters
,
options
...
>
cls
)
{
auto
setParams
=
[](
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
params
)
{
return
[
&
](
Dune
::
ParameterTree
&
tree
)
{
for
(
const
auto
&
p
:
params
)
tree
[
p
.
first
]
=
p
.
second
;
};
};
cls
.
def
(
pybind11
::
init
([
setParams
](
const
std
::
string
&
parameterFileName
,
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
params
,
bool
inputFileOverwritesParams
)
{
auto
p
=
new
Parameters
();
p
->
init
(
parameterFileName
,
setParams
(
params
),
inputFileOverwritesParams
);
return
p
;
}),
pybind11
::
arg
(
"parameterFileName"
),
pybind11
::
arg
(
"params"
)
=
std
::
unordered_map
<
std
::
string
,
std
::
string
>
{},
pybind11
::
arg
(
"inputFileOverwritesParams"
)
=
false
);
cls
.
def
(
pybind11
::
init
([
setParams
](
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
params
)
{
auto
p
=
new
Parameters
();
p
->
init
(
setParams
(
params
));
return
p
;
}));
}
template
<
class
Scalar
>
void
registerParameters
(
pybind11
::
handle
scope
,
const
char
*
clsName
=
"Parameters"
)
{
pybind11
::
class_
<
Parameters
>
cls
(
scope
,
clsName
);
registerParameters
(
scope
,
cls
);
}
}
// namespace Dumux::Python
#endif
This diff is collapsed.
Click to expand it.
python/dumux/common/__init__.py
+
23
−
1
View file @
9bd121e6
from
._common
import
*
from
dumux.common.properties
import
Model
,
Property
from
dune.generator.generator
import
SimpleGenerator
from
dune.common.hashit
import
hashIt
# A problem decorator generator for Python problems
#
# from dumux.common import FVProblem
...
...
@@ -25,6 +28,7 @@ def FVProblem(gridGeometry):
def
FVProblemDecorator
(
Cls
):
module
=
createModule
(
Cls
.
numEq
)
def
createFVProblem
():
return
module
.
FVProblem
(
gridGeometry
,
Cls
())
return
createFVProblem
...
...
@@ -34,7 +38,7 @@ def FVProblem(gridGeometry):
# Function for JIT copmilation of Dumux::BoundaryTypes
def
BoundaryTypes
(
numEq
=
1
):
# only co
p
mile this once per numEq
# only com
p
ile this once per numEq
cacheKey
=
"
BoundaryTypes_{}
"
.
format
(
numEq
)
try
:
return
globals
()[
cacheKey
]()
...
...
@@ -46,3 +50,21 @@ def BoundaryTypes(numEq=1):
module
=
generator
.
load
(
includes
,
typeName
,
moduleName
)
globals
().
update
({
cacheKey
:
module
.
BoundaryTypes
})
return
globals
()[
cacheKey
]()
def
Parameters
(
*
,
file
=
None
,
dict
=
{}):
parametersType
=
"
Dumux::Parameters
"
includes
=
[
"
dumux/common/parameters.hh
"
,
"
dumux/python/common/parameters.hh
"
]
moduleName
=
"
parameters_
"
+
hashIt
(
parametersType
)
generator
=
SimpleGenerator
(
"
Parameters
"
,
"
Dumux::Python
"
)
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
)
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