Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
grudge
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Andreas Klöckner
grudge
Commits
cd04017a
Commit
cd04017a
authored
3 years ago
by
Thomas Gibson
Browse files
Options
Downloads
Patches
Plain Diff
Add op.h_max_from_volume
parent
a098ca9c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
grudge/op.py
+27
-0
27 additions, 0 deletions
grudge/op.py
test/test_grudge.py
+5
-15
5 additions, 15 deletions
test/test_grudge.py
with
32 additions
and
15 deletions
grudge/op.py
+
27
−
0
View file @
cd04017a
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
.. autofunction:: nodes
.. autofunction:: nodes
.. autofunction:: normal
.. autofunction:: normal
.. autofunction:: h_max_from_volume
.. autofunction:: local_grad
.. autofunction:: local_grad
.. autofunction:: local_d_dx
.. autofunction:: local_d_dx
...
@@ -153,6 +154,32 @@ def normal(dcoll, dd):
...
@@ -153,6 +154,32 @@ def normal(dcoll, dd):
actx
=
dcoll
.
discr_from_dd
(
dd
).
_setup_actx
actx
=
dcoll
.
discr_from_dd
(
dd
).
_setup_actx
return
freeze
(
normal
(
actx
,
dcoll
,
dd
))
return
freeze
(
normal
(
actx
,
dcoll
,
dd
))
@memoize_on_first_arg
def
h_max_from_volume
(
dcoll
,
dim
=
None
,
dd
=
None
):
"""
Returns a characteristic length based on the volume of the elements.
This length may not be representative if the elements have very high
aspect ratios.
:arg dcoll: a :class:`grudge.discretization.DiscretizationCollection`.
:arg dim: an integer denoting topological dimension. If *None*, the
spatial dimension specified by :attr:`dcoll.dim` is used.
:arg dd: a :class:`~grudge.dof_desc.DOFDesc`, or a value convertible to one.
Defaults to the base volume discretization if not provided.
:returns: an integer denoting the characteristic length.
"""
if
dd
is
None
:
dd
=
dof_desc
.
DD_VOLUME
dd
=
dof_desc
.
as_dofdesc
(
dd
)
if
dim
is
None
:
dim
=
dcoll
.
dim
ones_volm
=
dcoll
.
_volume_discr
.
zeros
(
dcoll
.
_setup_actx
)
+
1.0
return
nodal_max
(
dcoll
,
dd
,
elementwise_sum
(
dcoll
,
mass
(
dcoll
,
dd
,
ones_volm
))
)
**
(
1.0
/
dim
)
# }}}
# }}}
...
...
This diff is collapsed.
Click to expand it.
test/test_grudge.py
+
5
−
15
View file @
cd04017a
...
@@ -249,11 +249,8 @@ def test_mass_surface_area(actx_factory, name):
...
@@ -249,11 +249,8 @@ def test_mass_surface_area(actx_factory, name):
# }}}
# }}}
# {{{ compute h_max using mass weights
# compute max element size
h_max
=
op
.
h_max_from_volume
(
dcoll
)
h_max
=
actx
.
np
.
max
(
flattened_mass_weights
)
**
(
1
/
dcoll
.
dim
)
# }}}
eoc
.
add_data_point
(
h_max
,
area_error
)
eoc
.
add_data_point
(
h_max
,
area_error
)
...
@@ -315,13 +312,8 @@ def test_surface_mass_operator_inverse(actx_factory, name):
...
@@ -315,13 +312,8 @@ def test_surface_mass_operator_inverse(actx_factory, name):
# }}}
# }}}
# {{{ compute h_max from mass weights
# compute max element size
h_max
=
op
.
h_max_from_volume
(
dcoll
)
ones_volm
=
volume_discr
.
zeros
(
actx
)
+
1
flattened_mass_weights
=
flatten
(
op
.
mass
(
dcoll
,
dd
,
ones_volm
))
h_max
=
actx
.
np
.
max
(
flattened_mass_weights
)
**
(
1
/
dcoll
.
dim
)
# }}}
eoc
.
add_data_point
(
h_max
,
inv_error
)
eoc
.
add_data_point
(
h_max
,
inv_error
)
...
@@ -630,9 +622,7 @@ def test_surface_divergence_theorem(actx_factory, mesh_name, visualize=False):
...
@@ -630,9 +622,7 @@ def test_surface_divergence_theorem(actx_factory, mesh_name, visualize=False):
logger
.
info
(
"
errors: global %.5e local %.5e
"
,
err_global
,
err_local
)
logger
.
info
(
"
errors: global %.5e local %.5e
"
,
err_global
,
err_local
)
# compute max element size
# compute max element size
ones_volm
=
volume
.
zeros
(
actx
)
+
1
h_max
=
op
.
h_max_from_volume
(
dcoll
)
sum_mass_weights
=
op
.
elementwise_sum
(
dcoll
,
op
.
mass
(
dcoll
,
dd
,
ones_volm
))
h_max
=
op
.
nodal_max
(
dcoll
,
dd
,
sum_mass_weights
)
**
(
1
/
dcoll
.
dim
)
eoc_global
.
add_data_point
(
h_max
,
err_global
)
eoc_global
.
add_data_point
(
h_max
,
err_global
)
eoc_local
.
add_data_point
(
h_max
,
err_local
)
eoc_local
.
add_data_point
(
h_max
,
err_local
)
...
...
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