Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Troubled Cell Detection
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Laura Christine Kühle
Troubled Cell Detection
Commits
8d1035fa
Commit
8d1035fa
authored
2 years ago
by
Laura Christine Kühle
Browse files
Options
Downloads
Patches
Plain Diff
Vectorized '_determine_modification()' in MinMod limiter.
parent
f8f2061e
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/tcd/Limiter.py
+27
-26
27 additions, 26 deletions
scripts/tcd/Limiter.py
with
27 additions
and
26 deletions
scripts/tcd/Limiter.py
+
27
−
26
View file @
8d1035fa
...
@@ -134,20 +134,20 @@ class MinMod(Limiter):
...
@@ -134,20 +134,20 @@ class MinMod(Limiter):
"""
"""
new_projection
=
projection
.
copy
()
new_projection
=
projection
.
copy
()
cell_slopes
=
self
.
_set_cell_slope
(
projection
)
for
cell
in
cells
:
for
cell
in
cells
:
cell_slope
=
self
.
_set_cell_slope
(
projection
,
cell
)
is_good_cell
=
self
.
_determine_modification
(
projection
,
cell
,
is_good_cell
=
self
.
_determine_modification
(
projection
,
cell
,
cell_slope
)
cell_slope
s
)
if
not
is_good_cell
:
if
not
is_good_cell
:
adapted_projection
=
projection
[:,
cell
].
copy
()
adapted_projection
=
projection
[:,
cell
+
1
].
copy
()
for
i
in
range
(
len
(
adapted_projection
)):
for
i
in
range
(
len
(
adapted_projection
)):
if
i
>
self
.
_erase_degree
:
if
i
>
self
.
_erase_degree
:
adapted_projection
[
i
]
=
0
adapted_projection
[
i
]
=
0
new_projection
[:,
cell
]
=
adapted_projection
new_projection
[:,
cell
+
1
]
=
adapted_projection
return
new_projection
return
new_projection
def
_determine_modification
(
self
,
projection
,
cell
,
cell_
slope
):
def
_determine_modification
(
self
,
projection
,
cell
,
slope
s
):
"""
Determines whether limiting is applied.
"""
Determines whether limiting is applied.
Parameters
Parameters
...
@@ -156,8 +156,8 @@ class MinMod(Limiter):
...
@@ -156,8 +156,8 @@ class MinMod(Limiter):
Matrix of projection for each polynomial degree.
Matrix of projection for each polynomial degree.
cell : int
cell : int
Index of cell.
Index of cell.
cell_
slope :
float
slope
s
:
ndarray
S
lope of
the give
n cell.
Vector of s
lope
s
of
projectio
n cell
s
.
Returns
Returns
-------
-------
...
@@ -165,36 +165,37 @@ class MinMod(Limiter):
...
@@ -165,36 +165,37 @@ class MinMod(Limiter):
Flag whether cell should be adjusted.
Flag whether cell should be adjusted.
"""
"""
forward_slope
=
(
projection
[
0
][
cell
+
1
]
forward_slopes
=
(
projection
[
0
,
2
:]
-
projection
[
0
,
1
:
-
1
])
*
(
0.5
**
0.5
)
-
projection
[
0
][
cell
])
*
(
0.5
**
0.5
)
backward_slopes
=
(
projection
[
0
,
1
:
-
1
]
-
projection
[
0
,
:
-
2
])
*
(
0.5
**
0.5
)
backward_slope
=
(
projection
[
0
][
cell
]
pos_mask
=
np
.
logical_and
(
slopes
>=
0
,
-
projection
[
0
][
cell
-
1
])
*
(
0.5
**
0.5
)
np
.
logical_and
(
forward_slopes
>=
0
,
backward_slopes
>=
0
))
return
(
forward_slope
<=
0
)
&
(
backward_slope
<=
0
)
\
neg_mask
=
np
.
logical_and
(
slopes
<=
0
,
&
(
cell_slope
<=
0
)
\
np
.
logical_and
(
forward_slopes
<=
0
,
|
(
forward_slope
>=
0
)
&
(
backward_slope
>=
0
)
&
(
cell_slope
>=
0
)
backward_slopes
<=
0
))
slope_mask
=
np
.
logical_or
(
pos_mask
,
neg_mask
)
return
slope_mask
[
cell
]
@staticmethod
@staticmethod
def
_set_cell_slope
(
projection
,
cell
):
def
_set_cell_slope
(
projection
):
"""
Calculates the slope of the cell.
"""
Calculates the slope of the cell.
Parameters
Parameters
----------
----------
projection : ndarray
projection : ndarray
Matrix of projection for each polynomial degree.
Matrix of projection for each polynomial degree.
cell : int
Index of cell.
Returns
Returns
-------
-------
float
ndarray
S
lope of
the give
n cell.
Vector of s
lope
s
of
projectio
n cell
s
.
"""
"""
root_vector
=
np
.
array
([
np
.
sqrt
(
degree
+
0.5
)
root_vector
=
np
.
array
([
np
.
sqrt
(
degree
+
0.5
)
for
degree
in
range
(
len
(
projection
))])
for
degree
in
range
(
len
(
projection
))])
slope
=
root_vector
[
1
:]
@
projection
[
1
:]
slope
=
root_vector
[
1
:]
@
projection
[
1
:]
return
slope
[
cell
]
return
slope
[
1
:
-
1
]
class
ModifiedMinMod
(
MinMod
):
class
ModifiedMinMod
(
MinMod
):
...
@@ -239,7 +240,7 @@ class ModifiedMinMod(MinMod):
...
@@ -239,7 +240,7 @@ class ModifiedMinMod(MinMod):
"""
Returns string of class name concatenated with the erase-degree.
"""
"""
Returns string of class name concatenated with the erase-degree.
"""
return
self
.
__class__
.
__name__
+
str
(
self
.
_erase_degree
)
return
self
.
__class__
.
__name__
+
str
(
self
.
_erase_degree
)
def
_determine_modification
(
self
,
projection
,
cell
,
cell_
slope
):
def
_determine_modification
(
self
,
projection
,
cell
,
slope
s
):
"""
Determines whether limiting is applied.
"""
Determines whether limiting is applied.
Parameters
Parameters
...
@@ -248,8 +249,8 @@ class ModifiedMinMod(MinMod):
...
@@ -248,8 +249,8 @@ class ModifiedMinMod(MinMod):
Matrix of projection for each polynomial degree.
Matrix of projection for each polynomial degree.
cell : int
cell : int
Index of cell.
Index of cell.
cell_
slope :
float
slope
s
:
ndarray
S
lope of
the give
n cell.
Vector of s
lope
s
of
projectio
n cell
s
.
Returns
Returns
-------
-------
...
@@ -257,7 +258,7 @@ class ModifiedMinMod(MinMod):
...
@@ -257,7 +258,7 @@ class ModifiedMinMod(MinMod):
Flag whether cell should be adjusted.
Flag whether cell should be adjusted.
"""
"""
if
abs
(
cell_
slope
)
<=
self
.
_threshold
:
if
abs
(
slope
s
[
cell
]
)
<=
self
.
_threshold
:
return
True
return
True
return
super
().
_determine_modification
(
projection
,
cell
,
cell_
slope
)
return
super
().
_determine_modification
(
projection
,
cell
,
slope
s
)
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