Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pySDC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
atml-ati
pySDC
Commits
76cfa155
Unverified
Commit
76cfa155
authored
5 months ago
by
Thomas Baumann
Committed by
GitHub
5 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Added separate function to apply Dirichlet BCs to any solution in RBC (#508)
parent
0518f267
No related branches found
No related tags found
No related merge requests found
Pipeline
#241369
passed
5 months ago
Stage: benchmark
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pySDC/implementations/problem_classes/RayleighBenard.py
+40
-1
40 additions, 1 deletion
pySDC/implementations/problem_classes/RayleighBenard.py
pySDC/tests/test_problems/test_RayleighBenard.py
+27
-1
27 additions, 1 deletion
pySDC/tests/test_problems/test_RayleighBenard.py
with
67 additions
and
2 deletions
pySDC/implementations/problem_classes/RayleighBenard.py
+
40
−
1
View file @
76cfa155
...
...
@@ -152,7 +152,7 @@ class RayleighBenard(GenericSpectralLinear):
)
self
.
add_BC
(
component
=
'
T
'
,
equation
=
'
T
'
,
axis
=
1
,
x
=-
1
,
v
=
self
.
BCs
[
'
T_bottom
'
],
kind
=
'
Dirichlet
'
,
line
=-
1
)
self
.
add_BC
(
component
=
'
T
'
,
equation
=
'
T
'
,
axis
=
1
,
x
=
1
,
v
=
self
.
BCs
[
'
T_top
'
],
kind
=
'
Dirichlet
'
,
line
=-
2
)
self
.
add_BC
(
component
=
'
v
'
,
equation
=
'
v
'
,
axis
=
1
,
x
=
1
,
v
=
self
.
BCs
[
'
v_
bot
to
m
'
],
kind
=
'
Dirichlet
'
,
line
=-
1
)
self
.
add_BC
(
component
=
'
v
'
,
equation
=
'
v
'
,
axis
=
1
,
x
=
1
,
v
=
self
.
BCs
[
'
v_to
p
'
],
kind
=
'
Dirichlet
'
,
line
=-
1
)
self
.
add_BC
(
component
=
'
v
'
,
equation
=
'
v
'
,
axis
=
1
,
x
=-
1
,
v
=
self
.
BCs
[
'
v_bottom
'
],
kind
=
'
Dirichlet
'
,
line
=-
2
)
self
.
remove_BC
(
component
=
'
v
'
,
equation
=
'
v
'
,
axis
=
1
,
x
=-
1
,
kind
=
'
Dirichlet
'
,
line
=-
2
,
scalar
=
True
)
self
.
add_BC
(
component
=
'
u
'
,
equation
=
'
u
'
,
axis
=
1
,
v
=
self
.
BCs
[
'
u_top
'
],
x
=
1
,
kind
=
'
Dirichlet
'
,
line
=-
2
)
...
...
@@ -257,6 +257,45 @@ class RayleighBenard(GenericSpectralLinear):
else
:
return
me
def
apply_BCs
(
self
,
sol
):
"""
Enforce the Dirichlet BCs at the top and bottom for arbitrary solution.
The function modifies the last two modes of u, v, and T in order to achieve this.
Note that the pressure is not modified here and the Nyquist mode is not altered either.
Args:
sol: Some solution that does not need to enforce boundary conditions
Returns:
Modified version of the solution that satisfies Dirichlet BCs.
"""
ultraspherical
=
self
.
spectral
.
axes
[
-
1
]
if
self
.
spectral_space
:
sol_half_hat
=
self
.
itransform
(
sol
,
axes
=
(
-
2
,))
else
:
sol_half_hat
=
self
.
transform
(
sol
,
axes
=
(
-
1
,))
BC_bottom
=
ultraspherical
.
get_BC
(
x
=-
1
,
kind
=
'
dirichlet
'
)
BC_top
=
ultraspherical
.
get_BC
(
x
=
1
,
kind
=
'
dirichlet
'
)
M
=
np
.
array
([
BC_top
[
-
2
:],
BC_bottom
[
-
2
:]])
M_I
=
np
.
linalg
.
inv
(
M
)
rhs
=
np
.
empty
((
2
,
self
.
nx
),
dtype
=
complex
)
for
component
in
[
'
u
'
,
'
v
'
,
'
T
'
]:
i
=
self
.
index
(
component
)
rhs
[
0
]
=
self
.
BCs
[
f
'
{
component
}
_top
'
]
-
self
.
xp
.
sum
(
sol_half_hat
[
i
,
:,
:
-
2
]
*
BC_top
[:
-
2
],
axis
=
1
)
rhs
[
1
]
=
self
.
BCs
[
f
'
{
component
}
_bottom
'
]
-
self
.
xp
.
sum
(
sol_half_hat
[
i
,
:,
:
-
2
]
*
BC_bottom
[:
-
2
],
axis
=
1
)
BC_vals
=
M_I
@
rhs
sol_half_hat
[
i
,
:,
-
2
:]
=
BC_vals
.
T
if
self
.
spectral_space
:
return
self
.
transform
(
sol_half_hat
,
axes
=
(
-
2
,))
else
:
return
self
.
itransform
(
sol_half_hat
,
axes
=
(
-
1
,))
def
get_fig
(
self
):
# pragma: no cover
"""
Get a figure suitable to plot the solution of this problem
...
...
This diff is collapsed.
Click to expand it.
pySDC/tests/test_problems/test_RayleighBenard.py
+
27
−
1
View file @
76cfa155
...
...
@@ -286,10 +286,36 @@ def test_Nyquist_mode_elimination():
assert
np
.
allclose
(
u
[:,
Nyquist_mode_index
,
:],
0
)
@pytest.mark.mpi4py
def
test_apply_BCs
():
from
pySDC.implementations.problem_classes.RayleighBenard
import
RayleighBenard
import
numpy
as
np
BCs
=
{
'
u_top
'
:
np
.
random
.
rand
(),
'
u_bottom
'
:
np
.
random
.
rand
(),
'
v_top
'
:
np
.
random
.
rand
(),
'
v_bottom
'
:
np
.
random
.
rand
(),
'
T_top
'
:
np
.
random
.
rand
(),
'
T_bottom
'
:
np
.
random
.
rand
(),
}
P
=
RayleighBenard
(
nx
=
5
,
nz
=
2
**
2
,
BCs
=
BCs
)
u_in
=
P
.
u_init
u_in
[...]
=
np
.
random
.
rand
(
*
u_in
.
shape
)
u_in_hat
=
P
.
transform
(
u_in
)
u_hat
=
P
.
apply_BCs
(
u_in_hat
)
u
=
P
.
itransform
(
u_hat
)
P
.
check_BCs
(
u
)
if
__name__
==
'
__main__
'
:
# test_eval_f(2**0, 2**2, 'z', True)
# test_Poisson_problem(1, 'T')
test_Poisson_problem_v
()
# test_Poisson_problem_v()
test_apply_BCs
()
# test_Nusselt_numbers(1)
# test_buoyancy_computation()
# test_viscous_dissipation()
...
...
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