Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
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
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sebastian Bindgen
pystencils
Commits
e4874494
Commit
e4874494
authored
4 years ago
by
Stephan Seitz
Browse files
Options
Downloads
Patches
Plain Diff
Fix Dirichlet boundary condition for scalar case
parent
04eb30b6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pystencils/boundaries/boundaryconditions.py
+2
-2
2 additions, 2 deletions
pystencils/boundaries/boundaryconditions.py
pystencils_tests/test_boundary.py
+25
-2
25 additions, 2 deletions
pystencils_tests/test_boundary.py
with
27 additions
and
4 deletions
pystencils/boundaries/boundaryconditions.py
+
2
−
2
View file @
e4874494
...
...
@@ -84,7 +84,7 @@ class Dirichlet(Boundary):
inner_or_boundary
=
False
single_link
=
True
def
__init__
(
self
,
value
,
name
=
"
Dirchlet
"
):
def
__init__
(
self
,
value
,
name
=
None
):
super
().
__init__
(
name
)
self
.
_value
=
value
...
...
@@ -103,7 +103,7 @@ class Dirichlet(Boundary):
def
__call__
(
self
,
field
,
direction_symbol
,
index_field
,
**
kwargs
):
if
field
.
index_dimensions
==
0
:
return
[
Assignment
(
field
,
index_field
(
"
value
"
)
if
self
.
additional_data
else
self
.
_value
)]
return
[
Assignment
(
field
.
center
,
index_field
(
"
value
"
)
if
self
.
additional_data
else
self
.
_value
)]
elif
field
.
index_dimensions
==
1
:
assert
not
self
.
additional_data
if
not
field
.
has_fixed_index_shape
:
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_boundary.py
+
25
−
2
View file @
e4874494
...
...
@@ -2,11 +2,10 @@ import os
from
tempfile
import
TemporaryDirectory
import
numpy
as
np
import
pytest
from
pystencils
import
Assignment
,
create_kernel
from
pystencils.boundaries
import
BoundaryHandling
,
Neumann
,
add_neumann_boundary
from
pystencils.boundaries
import
BoundaryHandling
,
Dirichlet
,
Neumann
,
add_neumann_boundary
from
pystencils.datahandling
import
SerialDataHandling
from
pystencils.slicing
import
slice_from_direction
...
...
@@ -88,3 +87,27 @@ def test_kernel_vs_copy_boundary():
pytest
.
importorskip
(
'
pyevtk
'
)
boundary_handling
.
geometry_to_vtk
(
file_name
=
os
.
path
.
join
(
tmp_dir
,
'
test_output1
'
),
ghost_layers
=
False
)
boundary_handling
.
geometry_to_vtk
(
file_name
=
os
.
path
.
join
(
tmp_dir
,
'
test_output2
'
),
ghost_layers
=
True
)
@pytest.mark.parametrize
(
'
with_indices
'
,
(
'
with_indices
'
,
False
))
def
test_dirichlet
(
with_indices
):
value
=
(
1
,
20
,
3
)
if
with_indices
else
1
dh
=
SerialDataHandling
(
domain_size
=
(
7
,
7
))
src
=
dh
.
add_array
(
'
src
'
,
values_per_cell
=
3
if
with_indices
else
1
)
dh
.
cpu_arrays
.
src
[...]
=
np
.
random
.
rand
(
*
src
.
shape
)
boundary_stencil
=
[(
1
,
0
),
(
-
1
,
0
),
(
0
,
1
),
(
0
,
-
1
)]
boundary_handling
=
BoundaryHandling
(
dh
,
src
.
name
,
boundary_stencil
)
dirichlet
=
Dirichlet
(
value
)
assert
dirichlet
.
name
==
'
Dirichlet
'
dirichlet
.
name
=
"
wall
"
assert
dirichlet
.
name
==
'
wall
'
for
d
in
(
'
N
'
,
'
S
'
,
'
W
'
,
'
E
'
):
boundary_handling
.
set_boundary
(
dirichlet
,
slice_from_direction
(
d
,
dim
=
2
))
boundary_handling
()
assert
all
([
np
.
allclose
(
a
,
np
.
array
(
value
))
for
a
in
dh
.
cpu_arrays
.
src
[
1
:
-
2
,
0
]])
assert
all
([
np
.
allclose
(
a
,
np
.
array
(
value
))
for
a
in
dh
.
cpu_arrays
.
src
[
1
:
-
2
,
-
1
]])
assert
all
([
np
.
allclose
(
a
,
np
.
array
(
value
))
for
a
in
dh
.
cpu_arrays
.
src
[
0
,
1
:
-
2
]])
assert
all
([
np
.
allclose
(
a
,
np
.
array
(
value
))
for
a
in
dh
.
cpu_arrays
.
src
[
-
1
,
1
:
-
2
]])
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