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
7b60bb58
Commit
7b60bb58
authored
3 years ago
by
Laura Christine Kühle
Browse files
Options
Downloads
Patches
Plain Diff
Improved docstring for Basis class.
parent
46b1f8f1
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
Basis_Function.py
+64
-38
64 additions, 38 deletions
Basis_Function.py
with
64 additions
and
38 deletions
Basis_Function.py
+
64
−
38
View file @
7b60bb58
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
"""
"""
Module for polynomial basis.
@author: Laura C. Kühle
@author: Laura C. Kühle
"""
"""
from
functools
import
cache
import
numpy
as
np
import
numpy
as
np
from
sympy
import
Symbol
,
integrate
from
sympy
import
Symbol
,
integrate
from
functools
import
cache
from
projection_utils
import
calculate_approximate_solution
from
projection_utils
import
calculate_approximate_solution
...
@@ -26,7 +27,14 @@ class Basis:
...
@@ -26,7 +27,14 @@ class Basis:
Array of wavelet.
Array of wavelet.
inv_mass : ndarray
inv_mass : ndarray
Inverse mass matrix.
Inverse mass matrix.
basis_projection: ndarray
basis_projection : Tuple[ndarray, ndarray]
Two arrays containing integrals of all basis vector
combinations evaluated on the left and right cell boundary,
respectively.
wavelet_projection : Tuple[ndarray, ndarray]
Two arrays containing integrals of all basis vector/
wavelet vector combinations evaluated on the left and right cell
boundary, respectively.
Methods
Methods
...
@@ -35,8 +43,9 @@ class Basis:
...
@@ -35,8 +43,9 @@ class Basis:
Calculate cell averages for a given projection.
Calculate cell averages for a given projection.
"""
"""
def
__init__
(
self
,
polynomial_degree
):
def
__init__
(
self
,
polynomial_degree
):
"""
Initialize
s Vector
.
"""
Initialize
Basis
.
Parameters
Parameters
----------
----------
...
@@ -58,7 +67,7 @@ class Basis:
...
@@ -58,7 +67,7 @@ class Basis:
return
self
.
_build_basis_vector
(
x
)
return
self
.
_build_basis_vector
(
x
)
def
_build_basis_vector
(
self
,
eval_point
):
def
_build_basis_vector
(
self
,
eval_point
):
"""
Construct
s
basis vector.
"""
Construct basis vector.
Parameters
Parameters
----------
----------
...
@@ -76,11 +85,11 @@ class Basis:
...
@@ -76,11 +85,11 @@ class Basis:
@property
@property
@cache
@cache
def
wavelet
(
self
):
def
wavelet
(
self
):
"""
Return
basis
vector.
"""
"""
Return
wavelet
vector.
"""
return
self
.
_build_wavelet_vector
(
z
)
return
self
.
_build_wavelet_vector
(
z
)
def
_build_wavelet_vector
(
self
,
eval_point
):
def
_build_wavelet_vector
(
self
,
eval_point
):
"""
Construct
s
wavelet vector.
"""
Construct wavelet vector.
Parameters
Parameters
----------
----------
...
@@ -102,7 +111,7 @@ class Basis:
...
@@ -102,7 +111,7 @@ class Basis:
return
self
.
_build_inverse_mass_matrix
()
return
self
.
_build_inverse_mass_matrix
()
def
_build_inverse_mass_matrix
(
self
):
def
_build_inverse_mass_matrix
(
self
):
"""
Construct
s
inverse mass matrix.
"""
Construct inverse mass matrix.
Returns
Returns
-------
-------
...
@@ -192,8 +201,9 @@ class Basis:
...
@@ -192,8 +201,9 @@ class Basis:
class
Legendre
(
Basis
):
class
Legendre
(
Basis
):
"""
Class for Legendre basis.
"""
"""
Class for Legendre basis.
"""
def
_build_basis_vector
(
self
,
eval_point
):
def
_build_basis_vector
(
self
,
eval_point
):
"""
Construct
s
basis vector.
"""
Construct basis vector.
Parameters
Parameters
----------
----------
...
@@ -209,7 +219,7 @@ class Legendre(Basis):
...
@@ -209,7 +219,7 @@ class Legendre(Basis):
return
self
.
_calculate_legendre_vector
(
eval_point
)
return
self
.
_calculate_legendre_vector
(
eval_point
)
def
_calculate_legendre_vector
(
self
,
eval_point
):
def
_calculate_legendre_vector
(
self
,
eval_point
):
"""
Construct
s
Legendre vector.
"""
Construct Legendre vector.
Parameters
Parameters
----------
----------
...
@@ -239,8 +249,9 @@ class Legendre(Basis):
...
@@ -239,8 +249,9 @@ class Legendre(Basis):
class
OrthonormalLegendre
(
Legendre
):
class
OrthonormalLegendre
(
Legendre
):
"""
Class for orthonormal Legendre basis.
"""
"""
Class for orthonormal Legendre basis.
"""
def
_build_basis_vector
(
self
,
eval_point
):
def
_build_basis_vector
(
self
,
eval_point
):
"""
Construct
s
basis vector.
"""
Construct basis vector.
Parameters
Parameters
----------
----------
...
@@ -258,7 +269,7 @@ class OrthonormalLegendre(Legendre):
...
@@ -258,7 +269,7 @@ class OrthonormalLegendre(Legendre):
for
degree
in
range
(
self
.
_polynomial_degree
+
1
)]
for
degree
in
range
(
self
.
_polynomial_degree
+
1
)]
def
_build_wavelet_vector
(
self
,
eval_point
):
def
_build_wavelet_vector
(
self
,
eval_point
):
"""
Construct
s
wavelet vector.
"""
Construct wavelet vector.
Parameters
Parameters
----------
----------
...
@@ -323,6 +334,14 @@ class OrthonormalLegendre(Legendre):
...
@@ -323,6 +334,14 @@ class OrthonormalLegendre(Legendre):
up to degree 4 for this application
'
)
up to degree 4 for this application
'
)
def
_build_inverse_mass_matrix
(
self
):
def
_build_inverse_mass_matrix
(
self
):
"""
Construct inverse mass matrix.
Returns
-------
ndarray
Inverse mass matrix.
"""
mass_matrix
=
[]
mass_matrix
=
[]
for
i
in
range
(
self
.
_polynomial_degree
+
1
):
for
i
in
range
(
self
.
_polynomial_degree
+
1
):
new_row
=
[]
new_row
=
[]
...
@@ -337,21 +356,26 @@ class OrthonormalLegendre(Legendre):
...
@@ -337,21 +356,26 @@ class OrthonormalLegendre(Legendre):
@property
@property
@cache
@cache
def
basis_projections
(
self
):
def
basis_projections
(
self
):
"""
Returns basis projection.
"""
Return basis projection.
Construct matrices containing the integrals of the
product of two basis vectors for every degree combination evaluated
at the left and right cell boundary.
Returns
Returns
-------
-------
ndarray
left_basis_projection : ndarray
Array containing the basis projection based on the integrals of
Array containing the left basis projection.
the product of two basis vectors for each degree combination.
right_basis_projection : ndarray
Array containing the right basis projection.
"""
"""
basis_projection
_left
=
self
.
_build_basis_matrix
(
z
,
0.5
*
(
z
-
1
))
left_
basis_projection
=
self
.
_build_basis_matrix
(
z
,
0.5
*
(
z
-
1
))
basis_projection
_right
=
self
.
_build_basis_matrix
(
z
,
0.5
*
(
z
+
1
))
right_
basis_projection
=
self
.
_build_basis_matrix
(
z
,
0.5
*
(
z
+
1
))
return
basis_projection
_left
,
basis_projection
_right
return
left_
basis_projection
,
right_
basis_projection
def
_build_basis_matrix
(
self
,
first_param
,
second_param
):
def
_build_basis_matrix
(
self
,
first_param
,
second_param
):
"""
Construct
s
a basis matrix.
"""
Construct a basis matrix.
Parameters
Parameters
----------
----------
...
@@ -380,25 +404,29 @@ class OrthonormalLegendre(Legendre):
...
@@ -380,25 +404,29 @@ class OrthonormalLegendre(Legendre):
@property
@property
@cache
@cache
def
multiwavelet_projections
(
self
):
def
multiwavelet_projections
(
self
):
"""
Returns wavelet projection.
"""
Return wavelet projection.
Construct matrices containing the integrals of the
product of a basis vector and a wavelet vector for every degree
combination evaluated at the left and right cell boundary.
Returns
Returns
-------
-------
ndarray
left_wavelet_projection :
ndarray
Array containing the multiwavelet projection
based on the integrals
Array containing the
left
multiwavelet projection
.
of the product of a basis vector and a wavelet vector for each
right_wavelet_projection : ndarray
degree combina
tion.
Array containing the right multiwavelet projec
tion.
"""
"""
wavelet_projection
_left
=
self
.
_build_multiwavelet_matrix
(
left_
wavelet_projection
=
self
.
_build_multiwavelet_matrix
(
z
,
-
0.5
*
(
z
-
1
),
True
)
z
,
-
0.5
*
(
z
-
1
),
True
)
wavelet_projection
_right
=
self
.
_build_multiwavelet_matrix
(
right_
wavelet_projection
=
self
.
_build_multiwavelet_matrix
(
z
,
0.5
*
(
z
+
1
),
False
)
z
,
0.5
*
(
z
+
1
),
False
)
return
wavelet_projection
_left
,
wavelet_projection
_right
return
left_
wavelet_projection
,
right_
wavelet_projection
def
_build_multiwavelet_matrix
(
self
,
first_param
,
second_param
,
def
_build_multiwavelet_matrix
(
self
,
first_param
,
second_param
,
is_left_matrix
):
is_left_matrix
):
"""
Construct
s
a multiwavelet matrix.
"""
Construct a multiwavelet matrix.
Parameters
Parameters
----------
----------
...
@@ -439,7 +467,7 @@ class OrthonormalLegendre(Legendre):
...
@@ -439,7 +467,7 @@ class OrthonormalLegendre(Legendre):
Notes
Notes
-----
-----
To increase speed
.
this function uses a simplified calculation
To increase speed
,
this function uses a simplified calculation
specific to the orthonormal Legendre polynomial basis.
specific to the orthonormal Legendre polynomial basis.
Parameters
Parameters
...
@@ -459,7 +487,6 @@ class OrthonormalLegendre(Legendre):
...
@@ -459,7 +487,6 @@ class OrthonormalLegendre(Legendre):
projection.
projection.
"""
"""
cell_averages
=
np
.
array
([
projection
[
0
]
/
np
.
sqrt
(
2
)])
cell_averages
=
np
.
array
([
projection
[
0
]
/
np
.
sqrt
(
2
)])
if
add_reconstructions
:
if
add_reconstructions
:
...
@@ -478,11 +505,6 @@ class OrthonormalLegendre(Legendre):
...
@@ -478,11 +505,6 @@ class OrthonormalLegendre(Legendre):
def
_calculate_reconstructions
(
self
,
projection
):
def
_calculate_reconstructions
(
self
,
projection
):
"""
Calculate left and right reconstructions for a given projection.
"""
Calculate left and right reconstructions for a given projection.
Notes
-----
To increase speed. this function uses a simplified calculation
specific to the orthonormal Legendre polynomial basis.
Parameters
Parameters
----------
----------
projection : ndarray
projection : ndarray
...
@@ -495,8 +517,12 @@ class OrthonormalLegendre(Legendre):
...
@@ -495,8 +517,12 @@ class OrthonormalLegendre(Legendre):
right_reconstruction : list
right_reconstruction : list
List containing right reconstructions for given projection.
List containing right reconstructions for given projection.
"""
Notes
-----
To increase speed. this function uses a simplified calculation
specific to the orthonormal Legendre polynomial basis.
"""
left_reconstructions
=
[
left_reconstructions
=
[
sum
(
projection
[
degree
][
cell
]
*
(
-
1
)
**
degree
sum
(
projection
[
degree
][
cell
]
*
(
-
1
)
**
degree
*
np
.
sqrt
(
degree
+
0.5
)
*
np
.
sqrt
(
degree
+
0.5
)
...
...
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