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
8193066b
Commit
8193066b
authored
3 years ago
by
Timo Koch
Browse files
Options
Downloads
Patches
Plain Diff
[python][cleanup] Use fstring in properties for better readability
parent
d98fb09c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2834
[python][cleanup] Use fstring in properties for better readability
Pipeline
#8963
failed
3 years ago
Stage: trigger
Stage: downstream modules
+1
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/dumux/common/properties.py
+19
-18
19 additions, 18 deletions
python/dumux/common/properties.py
with
19 additions
and
18 deletions
python/dumux/common/properties.py
+
19
−
18
View file @
8193066b
...
...
@@ -62,29 +62,30 @@ def typePropertyToString(propertyName, typeTagName, typeArg):
"""
Converts a Type Property to a string
"""
propertyString
=
"
template<class TypeTag>
\n
"
propertyString
+=
"
struct {}<TypeTag, TTag::{
}>
\n
{{
\n
"
.
format
(
propertyName
,
typeTagName
)
propertyString
+=
f
"
struct
{
propertyName
}
<TypeTag, TTag::
{
typeTagName
}
>
\n
{{
\n
"
if
isinstance
(
typeArg
,
(
float
)):
propertyString
+=
"
using type =
{};
\n
"
.
format
(
"
double
"
)
propertyString
+=
"
using type = double
;
\n
"
elif
isinstance
(
typeArg
,
(
int
)):
propertyString
+=
"
using type =
{}
;
\n
"
.
format
(
"
int
"
)
propertyString
+=
"
using type =
int
;
\n
"
elif
isinstance
(
typeArg
,
Property
):
if
typeArg
.
requiredPropertyTypes
or
typeArg
.
requiredPropertyValues
:
propertyString
+=
"
private:
\n
"
if
typeArg
.
requiredPropertyTypes
is
not
None
:
for
reqProp
in
typeArg
.
requiredPropertyTypes
:
propertyString
+=
"
using {} = {};
\n
"
.
format
(
reqProp
,
"
GetPropType<TypeTag, Properties::{
}>
"
.
format
(
reqProp
)
propertyString
+=
(
f
"
using
{
reqProp
}
=
"
f
"
GetPropType<TypeTag, Properties::
{
reqProp
}
>;
\n
"
)
if
typeArg
.
requiredPropertyValues
is
not
None
:
for
reqProp
in
typeArg
.
requiredPropertyValues
:
reqPropLowerCase
=
reqProp
[
0
].
lower
()
+
reqProp
[
1
:]
propertyString
+=
"
static constexpr auto {} = {};
\n
"
.
format
(
reqPropLowerCase
,
"
getPropValue<TypeTag, Properties::{}>()
"
.
format
(
reqProp
)
propertyString
+=
(
f
"
static constexpr auto
{
reqPropLowerCase
}
=
"
f
"
getPropValue<TypeTag, Properties::
{
reqProp
}
>();
\n
"
)
propertyString
+=
"
public:
\n
"
propertyString
+=
"
using type = {
};
\n
"
.
format
(
typeArg
.
cppType
)
propertyString
+=
f
"
using type =
{
typeArg
.
cppType
}
;
\n
"
propertyString
+=
"
};
"
...
...
@@ -95,7 +96,7 @@ def valuePropertyToString(propertyName, typeTagName, value):
"""
Converts a Value Property to a string
"""
propertyString
=
"
template<class TypeTag>
\n
"
propertyString
+=
"
struct {}<TypeTag, TTag::{
}>
\n
{{
"
.
format
(
propertyName
,
typeTagName
)
propertyString
+=
f
"
struct
{
propertyName
}
<TypeTag, TTag::
{
typeTagName
}
>
\n
{{
"
# make sure to get the correct C++ types and values
if
isinstance
(
value
,
bool
):
...
...
@@ -189,15 +190,15 @@ class TypeTag:
if
not
isinstance
(
parentTypeTag
,
TypeTag
):
if
not
isinstance
(
parentTypeTag
,
str
):
raise
ValueError
(
"
Unknown parent TypeTag {}. Use either argument of type TypeTag
"
f
"
Unknown parent TypeTag
{
parentTypeTag
}
.
"
"
Use either argument of type TypeTag
"
"
or a string for an existing TypeTag.
"
"
List of existing TypeTags: {
}
"
.
format
(
parentTypeTag
,
_typeTags
.
keys
()
)
f
"
List of existing TypeTags:
{
_typeTags
.
keys
()
}
"
)
if
parentTypeTag
not
in
_typeTags
.
keys
():
raise
ValueError
(
"
Unknown TypeTag {}. List of existing TypeTags: {}
"
.
format
(
parentTypeTag
,
_typeTags
.
keys
()
)
f
"
Unknown TypeTag
{
parentTypeTag
}
.
"
f
"
List of existing TypeTags:
{
_typeTags
.
keys
()
}
"
)
self
.
inheritsFrom
[
idx
]
=
TypeTag
(
parentTypeTag
)
...
...
@@ -237,14 +238,14 @@ class TypeTag:
def
cppHeader
(
self
):
"""
creates a string resembling a properties.hh file
"""
file
=
"
#ifndef DUMUX_{}_PROPERTIES_HH
\n
"
.
format
(
self
.
name
.
upper
())
file
+=
"
#define DUMUX_{}_PROPERTIES_HH
\n\n
"
.
format
(
self
.
name
.
upper
())
file
=
f
"
#ifndef DUMUX_
{
self
.
name
.
upper
()
}
_PROPERTIES_HH
\n
"
file
+=
f
"
#define DUMUX_
{
self
.
name
.
upper
()
}
_PROPERTIES_HH
\n\n
"
file
+=
"
#include <dumux/common/properties.hh>
\n
"
for
include
in
self
.
includes
:
assert
"
<
"
not
in
include
file
+=
"
#include <{
}>
\n
"
.
format
(
include
)
file
+=
f
"
#include <
{
include
}
>
\n
"
file
+=
"
\n
"
...
...
@@ -254,7 +255,7 @@ class TypeTag:
if
self
.
inheritsFrom
is
not
None
:
for
otherTypeTag
in
self
.
inheritsFrom
:
if
not
otherTypeTag
.
isExistingTypeTag
:
file
+=
"
struct {
}{{}};
\n
"
.
format
(
otherTypeTag
.
name
)
file
+=
f
"
struct
{
otherTypeTag
.
name
}
{{}};
\n
"
args
=
"
,
"
.
join
(
x
.
name
for
x
in
self
.
inheritsFrom
)
else
:
...
...
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