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
b7dcadcf
Commit
b7dcadcf
authored
Oct 21, 2022
by
Laura Christine Kühle
Browse files
Options
Downloads
Patches
Plain Diff
Reworked UpdateScheme to limit over array instead of cell.
parent
d6837143
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Snakefile
+8
-1
8 additions, 1 deletion
Snakefile
scripts/tcd/Limiter.py
+46
-30
46 additions, 30 deletions
scripts/tcd/Limiter.py
scripts/tcd/Update_Scheme.py
+2
-5
2 additions, 5 deletions
scripts/tcd/Update_Scheme.py
with
56 additions
and
36 deletions
Snakefile
+
8
−
1
View file @
b7dcadcf
...
...
@@ -21,9 +21,16 @@ TODO: Discuss descriptions (matrices, cfl number, right-hand side,
TODO: Discuss referencing info on SSPRK3
TODO: Discuss name for quadrature mesh (now: grid)
TODO: Contemplate using lambdify for basis
TODO: Ask why MinMod slope is only calculated from degree 1, not 0
Urgent:
TODO: Vectorize '_calculate_reconstructions()' in OrthonormalLegendre
TODO: Vectorize '_calculate_reconstructions()' in OrthonormalLegendre -> Done
TODO: Vectorize 'do_initial_projection()' -> Done
TODO: Rework UpdateScheme to limit over array instead of cell -> Done
TODO: Vectorize '_determine_modification()' in ModifiedMinMod
TODO: Vectorize '_set_cell_slope()' in MinMod
TODO: Vectorize '_determine_modification()' in MinMod
TODO: Vectorize 'apply()' in MinMod
TODO: Replace loops/list comprehension with vectorization if feasible
TODO: Replace loops with list comprehension if feasible
TODO: Rework ICs to allow vector input
...
...
This diff is collapsed.
Click to expand it.
scripts/tcd/Limiter.py
+
46
−
30
View file @
b7dcadcf
...
...
@@ -4,6 +4,7 @@
"""
from
abc
import
ABC
,
abstractmethod
import
numpy
as
np
class
Limiter
(
ABC
):
...
...
@@ -13,8 +14,8 @@ class Limiter(ABC):
-------
get_name()
Returns string of class name.
apply(projection, cell)
Applies limiting to cell.
apply(projection, cell
s
)
Applies limiting to cell
s
.
"""
def
__init__
(
self
,
config
):
...
...
@@ -45,15 +46,15 @@ class Limiter(ABC):
return
self
.
__class__
.
__name__
@abstractmethod
def
apply
(
self
,
projection
,
cell
):
"""
Applies limiting to cell.
def
apply
(
self
,
projection
,
cell
s
):
"""
Applies limiting to cell
s
.
Parameters
----------
projection : ndarray
Matrix of projection for each polynomial degree.
cell
: in
t
Index of cell.
cell
s : lis
t
Index of cell
s to limit
.
Returns
-------
...
...
@@ -71,13 +72,13 @@ class NoLimiter(Limiter):
-------
get_name()
Returns string of class name.
apply(projection, cell)
Applies no limiting to cell.
apply(projection, cell
s
)
Applies no limiting to cell
s
.
"""
def
apply
(
self
,
projection
,
cell
):
"""
Returns projection
of cell
without limiting.
"""
return
projection
[:,
cell
]
def
apply
(
self
,
projection
,
cell
s
):
"""
Returns projection without limiting.
"""
return
projection
class
MinMod
(
Limiter
):
...
...
@@ -96,8 +97,8 @@ class MinMod(Limiter):
-------
get_name()
Returns string of class name.
apply(projection, cell)
Applies limiting to cell.
apply(projection, cell
s
)
Applies limiting to cell
s
.
"""
def
_reset
(
self
,
config
):
...
...
@@ -116,34 +117,35 @@ class MinMod(Limiter):
"""
Returns string of class name concatenated with the erase-degree.
"""
return
self
.
__class__
.
__name__
+
str
(
self
.
_erase_degree
)
def
apply
(
self
,
projection
,
cell
):
"""
Applies limiting to cell.
def
apply
(
self
,
projection
,
cell
s
):
"""
Applies limiting to cell
s
.
Parameters
----------
projection : ndarray
Matrix of projection for each polynomial degree.
cell :
in
t
Index of cell.
cell
s
:
lis
t
Index of cell
s to limit
.
Returns
-------
adapted
_projection : ndarray
new
_projection : ndarray
Matrix of updated projection for each polynomial degree.
"""
new_projection
=
projection
.
copy
()
for
cell
in
cells
:
cell_slope
=
self
.
_set_cell_slope
(
projection
,
cell
)
is_good_cell
=
self
.
_determine_modification
(
projection
,
cell
,
cell_slope
)
if
is_good_cell
:
return
projection
[:,
cell
]
if
not
is_good_cell
:
adapted_projection
=
projection
[:,
cell
].
copy
()
for
i
in
range
(
len
(
adapted_projection
)):
if
i
>
self
.
_erase_degree
:
adapted_projection
[
i
]
=
0
return
adapted_projection
new_projection
[:,
cell
]
=
adapted_projection
return
new_projection
def
_determine_modification
(
self
,
projection
,
cell
,
cell_slope
):
"""
Determines whether limiting is applied.
...
...
@@ -197,6 +199,16 @@ class MinMod(Limiter):
slope
.
append
(
new_entry
)
return
slope
[
cell
]
# # print(np.array(slope).shape)
# # print(slope)
# root_vector = np.array([np.sqrt(degree+0.5)
# for degree in range(len(projection))])
# test = root_vector[1:] @ projection[1:]
# # print(test.shape)
# # print(np.isclose(test, slope, rtol=1e-16))
#
# return test[cell]
class
ModifiedMinMod
(
MinMod
):
"""
Class for modified minmod limiting function.
...
...
@@ -235,6 +247,9 @@ class ModifiedMinMod(MinMod):
super
().
_reset
(
config
)
# Unpack necessary configurations
# cell_len = config.pop('cell_len')
# mod_factor = config.pop('mod_factor', 0)
# self._threshold = mod_factor * cell_len**2
self
.
_cell_len
=
config
.
pop
(
'
cell_len
'
)
self
.
_mod_factor
=
config
.
pop
(
'
mod_factor
'
,
0
)
...
...
@@ -260,6 +275,7 @@ class ModifiedMinMod(MinMod):
Flag whether cell should be adjusted.
"""
# if abs(cell_slope) <= self._threshold:
if
abs
(
cell_slope
)
<=
self
.
_mod_factor
*
self
.
_cell_len
**
2
:
return
True
...
...
This diff is collapsed.
Click to expand it.
scripts/tcd/Update_Scheme.py
+
2
−
5
View file @
b7dcadcf
...
...
@@ -154,11 +154,8 @@ class UpdateScheme(ABC):
"""
troubled_cells
=
self
.
_detector
.
get_cells
(
current_projection
)
new_projection
=
current_projection
.
copy
()
for
cell
in
troubled_cells
:
new_projection
[:,
cell
]
=
self
.
_limiter
.
apply
(
current_projection
,
cell
)
new_projection
=
self
.
_limiter
.
apply
(
current_projection
,
troubled_cells
)
return
new_projection
,
troubled_cells
...
...
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