Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sumpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
sumpy
Commits
c0e9bc69
Commit
c0e9bc69
authored
12 years ago
by
Andreas Klöckner
Browse files
Options
Downloads
Patches
Plain Diff
Tweak curve pot toy, make it build matrices.
parent
4c06e0e1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/curve-pot.py
+77
-9
77 additions, 9 deletions
examples/curve-pot.py
with
77 additions
and
9 deletions
examples/curve-pot.py
+
77
−
9
View file @
c0e9bc69
from
__future__
import
division
from
__future__
import
division
import
pyopencl
as
cl
import
pyopencl
as
cl
import
numpy
as
np
import
numpy
as
np
import
numpy.linalg
as
la
import
matplotlib.pyplot
as
pt
import
matplotlib.pyplot
as
pt
from
pytools
import
Record
from
pytools
import
Record
...
@@ -31,7 +32,8 @@ def draw_pot_figure(aspect_ratio,
...
@@ -31,7 +32,8 @@ def draw_pot_figure(aspect_ratio,
what_operator
=
"
S
"
,
what_operator
=
"
S
"
,
what_operator_lpot
=
None
,
what_operator_lpot
=
None
,
order
=
5
,
order
=
5
,
ovsmp_center_exp
=
0.66
):
ovsmp_center_exp
=
0.66
,
force_center_side
=
None
):
if
novsmp
is
None
:
if
novsmp
is
None
:
novsmp
=
4
*
nsrc
novsmp
=
4
*
nsrc
...
@@ -112,9 +114,13 @@ def draw_pot_figure(aspect_ratio,
...
@@ -112,9 +114,13 @@ def draw_pot_figure(aspect_ratio,
curve_len
=
np
.
sum
(
ovsmp_weights
*
ovsmp_curve
.
speed
)
curve_len
=
np
.
sum
(
ovsmp_weights
*
ovsmp_curve
.
speed
)
hovsmp
=
curve_len
/
novsmp
hovsmp
=
curve_len
/
novsmp
hnative
=
curve_len
/
nsrc
hnative
=
curve_len
/
nsrc
center_dist
=
5
*
hnative
*
(
hovsmp
/
hnative
)
**
ovsmp_center_exp
center_dist
=
5
*
hovsmp
if
force_center_side
is
not
None
:
center_side
=
force_center_side
*
np
.
ones
(
len
(
native_curve
))
else
:
center_side
=
-
np
.
sign
(
native_curve
.
mean_curvature
)
center_side
=
-
np
.
sign
(
native_curve
.
mean_curvature
)
centers
=
(
native_curve
.
pos
centers
=
(
native_curve
.
pos
+
center_side
[:,
np
.
newaxis
]
+
center_side
[:,
np
.
newaxis
]
*
center_dist
*
native_curve
.
normal
)
*
center_dist
*
native_curve
.
normal
)
...
@@ -126,7 +132,7 @@ def draw_pot_figure(aspect_ratio,
...
@@ -126,7 +132,7 @@ def draw_pot_figure(aspect_ratio,
lpot_kwargs
=
knl_kwargs
.
copy
()
lpot_kwargs
=
knl_kwargs
.
copy
()
if
what_operator
==
"
D
"
:
if
what_operator
==
"
D
"
:
lpot_kwargs
[
"
src_derivative_dir
"
]
=
ovsmp
_curve
.
normal
vo
lpot_kwargs
[
"
src_derivative_dir
"
]
=
native
_curve
.
normal
if
what_operator_lpot
==
"
D
"
:
if
what_operator_lpot
==
"
D
"
:
lpot_kwargs
[
"
src_derivative_dir
"
]
=
ovsmp_curve
.
normal
lpot_kwargs
[
"
src_derivative_dir
"
]
=
ovsmp_curve
.
normal
...
@@ -136,7 +142,41 @@ def draw_pot_figure(aspect_ratio,
...
@@ -136,7 +142,41 @@ def draw_pot_figure(aspect_ratio,
# }}}
# }}}
len
(
native_curve
)
if
1
:
# {{{ build matrix
from
fourier
import
make_fourier_interp_matrix
fim
=
make_fourier_interp_matrix
(
novsmp
,
nsrc
)
from
sumpy.tools
import
build_matrix
from
scipy.sparse.linalg
import
LinearOperator
def
apply_lpot
(
x
):
xovsmp
=
np
.
dot
(
fim
,
x
)
evt
,
(
y
,)
=
lpot
(
queue
,
native_curve
.
pos
,
ovsmp_curve
.
pos
,
centers
,
[
xovsmp
],
ovsmp_curve
.
speed
,
ovsmp_weights
,
**
lpot_kwargs
)
if
0
:
class
JumpTermArgs
(
Record
):
pass
evt
,
(
y
,)
=
jt
(
queue
,
[
y
],
JumpTermArgs
(
src_derivative_dir
=
native_curve
.
normal
,
tgt_derivative_dir
=
native_curve
.
normal
,
density_0
=
x
,
side
=
center_side
,
normal
=
native_curve
.
normal
,
))
return
y
op
=
LinearOperator
((
nsrc
,
nsrc
),
apply_lpot
)
mat
=
build_matrix
(
op
,
dtype
=
np
.
complex128
)
w
,
v
=
la
.
eig
(
mat
)
pt
.
plot
(
w
.
real
,
"
o-
"
)
#import sys; sys.exit(0)
return
# }}}
# {{{ compute potentials
density
=
np
.
cos
(
3
*
2
*
np
.
pi
*
native_t
).
astype
(
np
.
complex128
)
density
=
np
.
cos
(
3
*
2
*
np
.
pi
*
native_t
).
astype
(
np
.
complex128
)
ovsmp_density
=
np
.
cos
(
3
*
2
*
np
.
pi
*
ovsmp_t
).
astype
(
np
.
complex128
)
ovsmp_density
=
np
.
cos
(
3
*
2
*
np
.
pi
*
ovsmp_t
).
astype
(
np
.
complex128
)
evt
,
(
vol_pot
,)
=
p2p
(
queue
,
fp
.
points
,
native_curve
.
pos
,
evt
,
(
vol_pot
,)
=
p2p
(
queue
,
fp
.
points
,
native_curve
.
pos
,
...
@@ -146,7 +186,11 @@ def draw_pot_figure(aspect_ratio,
...
@@ -146,7 +186,11 @@ def draw_pot_figure(aspect_ratio,
[
ovsmp_density
],
ovsmp_curve
.
speed
,
ovsmp_weights
,
[
ovsmp_density
],
ovsmp_curve
.
speed
,
ovsmp_weights
,
**
lpot_kwargs
)
**
lpot_kwargs
)
# }}}
if
1
:
if
1
:
# {{{ apply jump terms
class
JumpTermArgs
(
Record
):
class
JumpTermArgs
(
Record
):
pass
pass
evt
,
(
curve_pot
,)
=
jt
(
queue
,
[
curve_pot
],
JumpTermArgs
(
evt
,
(
curve_pot
,)
=
jt
(
queue
,
[
curve_pot
],
JumpTermArgs
(
...
@@ -156,13 +200,22 @@ def draw_pot_figure(aspect_ratio,
...
@@ -156,13 +200,22 @@ def draw_pot_figure(aspect_ratio,
side
=
center_side
,
side
=
center_side
,
normal
=
native_curve
.
normal
,
normal
=
native_curve
.
normal
,
))
))
# }}}
if
0
:
if
0
:
# {{{ plot on-surface potential in 2D
pt
.
plot
(
curve_pot
,
label
=
"
pot
"
)
pt
.
plot
(
curve_pot
,
label
=
"
pot
"
)
pt
.
plot
(
density
,
label
=
"
dens
"
)
pt
.
plot
(
density
,
label
=
"
dens
"
)
pt
.
legend
()
pt
.
legend
()
pt
.
show
()
pt
.
show
()
# }}}
if
0
:
if
0
:
# {{{ 2D false-color plot
pt
.
clf
()
pt
.
clf
()
plotval
=
np
.
log10
(
1e-20
+
np
.
abs
(
vol_pot
))
plotval
=
np
.
log10
(
1e-20
+
np
.
abs
(
vol_pot
))
im
=
fp
.
show_scalar_in_matplotlib
(
plotval
.
real
)
im
=
fp
.
show_scalar_in_matplotlib
(
plotval
.
real
)
...
@@ -181,7 +234,11 @@ def draw_pot_figure(aspect_ratio,
...
@@ -181,7 +234,11 @@ def draw_pot_figure(aspect_ratio,
#pt.gca().xaxis.set_major_formatter(NullFormatter())
#pt.gca().xaxis.set_major_formatter(NullFormatter())
#pt.gca().yaxis.set_major_formatter(NullFormatter())
#pt.gca().yaxis.set_major_formatter(NullFormatter())
fp
.
set_matplotlib_limits
()
fp
.
set_matplotlib_limits
()
# }}}
else
:
else
:
# {{{ 3D plots
plotval_vol
=
vol_pot
.
real
plotval_vol
=
vol_pot
.
real
plotval_c
=
curve_pot
.
real
plotval_c
=
curve_pot
.
real
...
@@ -210,11 +267,22 @@ def draw_pot_figure(aspect_ratio,
...
@@ -210,11 +267,22 @@ def draw_pot_figure(aspect_ratio,
scale
*
plotval_c
,
scale_factor
=
0.02
)
scale
*
plotval_c
,
scale_factor
=
0.02
)
mlab
.
show
()
mlab
.
show
()
# }}}
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
draw_pot_figure
(
aspect_ratio
=
1
,
nsrc
=
1000
,
helmholtz_k
=
0
,
draw_pot_figure
(
aspect_ratio
=
1
,
nsrc
=
100
,
novsmp
=
100
,
helmholtz_k
=
0
,
what_operator
=
"
S
"
,
what_operator
=
"
D
"
,
what_operator_lpot
=
"
D
"
,
force_center_side
=
1
)
what_operator_lpot
=
"
S
'"
)
pt
.
savefig
(
"
eigvals-ext-nsrc100-novsmp100.pdf
"
)
pt
.
show
()
pt
.
clf
()
draw_pot_figure
(
aspect_ratio
=
1
,
nsrc
=
100
,
novsmp
=
100
,
helmholtz_k
=
0
,
what_operator
=
"
D
"
,
what_operator_lpot
=
"
D
"
,
force_center_side
=-
1
)
pt
.
savefig
(
"
eigvals-int-nsrc100-novsmp100.pdf
"
)
pt
.
clf
()
draw_pot_figure
(
aspect_ratio
=
1
,
nsrc
=
100
,
novsmp
=
200
,
helmholtz_k
=
0
,
what_operator
=
"
D
"
,
what_operator_lpot
=
"
D
"
,
force_center_side
=-
1
)
pt
.
savefig
(
"
eigvals-int-nsrc100-novsmp200.pdf
"
)
# vim: fdm=marker
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