Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pykat
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
finesse
pykat
Commits
3a418d7c
Commit
3a418d7c
authored
10 years ago
by
Daniel Brown
Browse files
Options
Downloads
Patches
Plain Diff
more romhom and map fixes
parent
16c0700e
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
bin/test_romhom.py
+14
-11
14 additions, 11 deletions
bin/test_romhom.py
pykat/utilities/knm.py
+58
-41
58 additions, 41 deletions
pykat/utilities/knm.py
pykat/utilities/maps.py
+34
-25
34 additions, 25 deletions
pykat/utilities/maps.py
with
106 additions
and
77 deletions
bin/test_romhom.py
+
14
−
11
View file @
3a418d7c
from
pykat.utilities.maps
import
read_map
from
pykat.utilities.maps
import
read_map
,
tiltmap
,
surfacemap
from
pykat.utilities.knm
import
*
from
pykat.utilities.optics.gaussian_beams
import
beam_param
import
time
...
...
@@ -7,20 +7,23 @@ couplings = np.array([[[0,0,0,0], [0,0,1,0], [0,0,0,1]],
[[
1
,
0
,
0
,
0
],
[
1
,
0
,
1
,
0
],
[
1
,
0
,
0
,
1
]],
[[
0
,
1
,
0
,
0
],
[
0
,
1
,
1
,
0
],
[
0
,
1
,
0
,
1
]]])
q1
=
beam_param
(
w0
=
4
e-2
,
z
=
0
)
q2
=
beam_param
(
w0
=
4
e-2
,
z
=
0
)
q1
=
beam_param
(
w0
=
3
e-2
,
z
=
0
)
q2
=
beam_param
(
w0
=
3
e-2
,
z
=
0
)
m
=
read_map
(
'
etm08_virtual.txt
'
)
size
=
np
.
array
([
200
,
200
])
stepsize
=
0.2
/
(
size
-
1
)
m
.
data
=
np
.
zeros
((
100
,
100
))
m
.
x
=
np
.
linspace
(
-
0.15
,
0.15
,
m
.
size
[
0
])
m
.
y
=
np
.
linspace
(
-
0.15
,
0.15
,
m
.
size
[
1
])
m
.
center
=
np
.
array
(
m
.
size
)
/
2
m
.
step_size
=
(
m
.
x
[
1
]
-
m
.
x
[
0
],
m
.
y
[
1
]
-
m
.
y
[
0
])
# This map has points evenly spaced about the axes
m
=
tiltmap
(
"
tilt
"
,
size
,
stepsize
,
(
1e-6
,
0
))
# Shifting the central point changes the results slightly
# but this is about a 1e-7 change, probably due to extra
# clipping
m
.
center
+=
20
print
"
g
enerating weights...
"
print
"
G
enerating weights...
"
t0
=
time
.
time
()
w
,
EI
=
m
.
generateROMWeights
(
isModeMatched
=
True
)
#w.writeToFile("testWeights.rom")
print
"
Completed in
"
,
time
.
time
()
-
t0
print
"
computing Riemann knm...
"
...
...
@@ -39,7 +42,7 @@ print np.abs(K2)
print
"
Speed up
"
,
tr
/
tt
#w.writeToFile("testWeights.rom")
...
...
This diff is collapsed.
Click to expand it.
pykat/utilities/knm.py
+
58
−
41
View file @
3a418d7c
...
...
@@ -94,43 +94,60 @@ def ROM_HG_knm(weights, mode_in, mode_out, q1, q2, q1y=None, q2y=None, cache=Non
npr
=
mode_in
[
1
]
mpr
=
mode_out
[
1
]
# if cache == None:
u_xm_nodes
=
u_star_u
(
q1
.
z
,
q2
.
z
,
q1
.
w0
,
q2
.
w0
,
n
,
m
,
weights
.
EI
[
"
xm
"
].
nodes
-
0.1e-2
)
u_xp_nodes
=
u_star_u
(
q1
.
z
,
q2
.
z
,
q1
.
w0
,
q2
.
w0
,
n
,
m
,
weights
.
EI
[
"
xp
"
].
nodes
-
0.1e-2
)
u_ym_nodes
=
u_star_u
(
q1y
.
z
,
q2y
.
z
,
q1y
.
w0
,
q2y
.
w0
,
npr
,
mpr
,
weights
.
EI
[
"
ym
"
].
nodes
-
0.1e-2
)
u_yp_nodes
=
u_star_u
(
q1y
.
z
,
q2y
.
z
,
q1y
.
w0
,
q2y
.
w0
,
npr
,
mpr
,
weights
.
EI
[
"
yp
"
].
nodes
-
0.1e-2
)
# else:
# strx = "x[%i,%i]" % (mode_in[0], mode_out[0])
# stry = "y[%i,%i]" % (mode_in[1], mode_out[1])
#
# u_x_nodes = cache[strx]
# u_y_nodes = cache[stry]
foundSymmetry
=
np
.
all
(
weights
.
EI
[
"
xp
"
].
nodes
==
-
weights
.
EI
[
"
xm
"
].
nodes
)
and
np
.
all
(
weights
.
EI
[
"
yp
"
].
nodes
==
-
weights
.
EI
[
"
ym
"
].
nodes
)
if
foundSymmetry
:
if
cache
==
None
:
u_x_nodes
=
u_star_u
(
q1
.
z
,
q2
.
z
,
q1
.
w0
,
q2
.
w0
,
n
,
m
,
weights
.
EI
[
"
xm
"
].
nodes
)
u_y_nodes
=
u_star_u
(
q1
.
z
,
q2
.
z
,
q1
.
w0
,
q2
.
w0
,
n
,
m
,
weights
.
EI
[
"
ym
"
].
nodes
)
w_ij_Q1Q3
=
weights
.
w_ij_Q1
+
weights
.
w_ij_Q3
w_ij_Q2Q4
=
weights
.
w_ij_Q2
+
weights
.
w_ij_Q4
w_ij_Q1Q2
=
weights
.
w_ij_Q1
+
weights
.
w_ij_Q2
w_ij_Q1Q4
=
weights
.
w_ij_Q1
+
weights
.
w_ij_Q4
w_ij_Q2Q3
=
weights
.
w_ij_Q2
+
weights
.
w_ij_Q3
w_ij_Q3Q4
=
weights
.
w_ij_Q3
+
weights
.
w_ij_Q4
w_ij_Q1Q2Q3Q4
=
weights
.
w_ij_Q1
+
weights
.
w_ij_Q2
+
weights
.
w_ij_Q3
+
weights
.
w_ij_Q4
else
:
strx
=
"
x[%i,%i]
"
%
(
mode_in
[
0
],
mode_out
[
0
])
stry
=
"
y[%i,%i]
"
%
(
mode_in
[
1
],
mode_out
[
1
])
u_x_nodes
=
cache
[
strx
]
u_y_nodes
=
cache
[
stry
]
u_xy_nodes
=
np
.
outer
(
u_x_nodes
,
u_y_nodes
)
n_mod_2
=
n
%
2
m_mod_2
=
m
%
2
npr_mod_2
=
npr
%
2
mpr_mod_2
=
mpr
%
2
if
n_mod_2
==
m_mod_2
and
npr_mod_2
==
mpr_mod_2
:
k_ROQ
=
np
.
einsum
(
'
ij,ij
'
,
u_xy_nodes
,
w_ij_Q1Q2Q3Q4
)
elif
n_mod_2
!=
m_mod_2
:
if
npr_mod_2
==
mpr_mod_2
:
k_ROQ
=
np
.
einsum
(
'
ij,ij
'
,
u_xy_nodes
,
w_ij_Q1Q4
)
+
np
.
einsum
(
'
ij,ij
'
,
-
u_xy_nodes
,
w_ij_Q2Q3
)
else
:
k_ROQ
=
np
.
einsum
(
'
ij,ij
'
,
u_xy_nodes
,
w_ij_Q2Q4
)
+
np
.
einsum
(
'
ij,ij
'
,
-
u_xy_nodes
,
w_ij_Q1Q3
)
elif
npr_mod_2
!=
mpr_mod_2
:
if
n_mod_2
==
m_mod_2
:
k_ROQ
=
np
.
einsum
(
'
ij,ij
'
,
u_xy_nodes
,
w_ij_Q3Q4
)
+
np
.
einsum
(
'
ij,ij
'
,
-
u_xy_nodes
,
w_ij_Q1Q2
)
else
:
k_ROQ
=
np
.
einsum
(
'
ij,ij
'
,
u_xy_nodes
,
w_ij_Q2Q4
)
+
np
.
einsum
(
'
ij,ij
'
,
-
u_xy_nodes
,
w_ij_Q1Q3
)
else
:
# If there is no symmetry about the axes then each quadrant is different
u_xm_nodes
=
u_star_u
(
q1
.
z
,
q2
.
z
,
q1
.
w0
,
q2
.
w0
,
n
,
m
,
weights
.
EI
[
"
xm
"
].
nodes
)
u_xp_nodes
=
u_star_u
(
q1
.
z
,
q2
.
z
,
q1
.
w0
,
q2
.
w0
,
n
,
m
,
weights
.
EI
[
"
xp
"
].
nodes
)
u_ym_nodes
=
u_star_u
(
q1y
.
z
,
q2y
.
z
,
q1y
.
w0
,
q2y
.
w0
,
npr
,
mpr
,
weights
.
EI
[
"
ym
"
].
nodes
)
u_yp_nodes
=
u_star_u
(
q1y
.
z
,
q2y
.
z
,
q1y
.
w0
,
q2y
.
w0
,
npr
,
mpr
,
weights
.
EI
[
"
yp
"
].
nodes
)
u_xy_Q1
=
np
.
outer
(
u_xm_nodes
,
u_yp_nodes
)
u_xy_Q2
=
np
.
outer
(
u_xp_nodes
,
u_yp_nodes
)
u_xy_Q3
=
np
.
outer
(
u_xp_nodes
,
u_ym_nodes
)
u_xy_Q4
=
np
.
outer
(
u_xm_nodes
,
u_ym_nodes
)
# n_mod_2 = n % 2
# m_mod_2 = m % 2
# npr_mod_2 = npr % 2
# mpr_mod_2 = mpr % 2
#
# if n_mod_2 == m_mod_2 and npr_mod_2 == mpr_mod_2:
# k_ROQ = np.einsum('ij,ij', u_xy_nodes, w_ij_Q1Q2Q3Q4)
#
# elif n_mod_2 != m_mod_2:
# if npr_mod_2 == mpr_mod_2:
# k_ROQ = np.einsum('ij,ij', u_xy_nodes, w_ij_Q1Q4) + np.einsum('ij,ij', -u_xy_nodes, w_ij_Q2Q3)
# else:
# k_ROQ = np.einsum('ij,ij', u_xy_nodes, w_ij_Q2Q4) + np.einsum('ij,ij', -u_xy_nodes, w_ij_Q1Q3)
#
# elif npr_mod_2 != mpr_mod_2:
# if n_mod_2 == m_mod_2:
# k_ROQ = np.einsum('ij,ij', u_xy_nodes, w_ij_Q3Q4) + np.einsum('ij,ij', -u_xy_nodes, w_ij_Q1Q2)
# else:
# k_ROQ = np.einsum('ij,ij', u_xy_nodes, w_ij_Q2Q4) + np.einsum('ij,ij', -u_xy_nodes, w_ij_Q1Q3)
k_ROQ
=
np
.
einsum
(
'
ij,ij
'
,
u_xy_Q1
,
weights
.
w_ij_Q1
)
k_ROQ
+=
np
.
einsum
(
'
ij,ij
'
,
u_xy_Q2
,
weights
.
w_ij_Q2
)
k_ROQ
+=
np
.
einsum
(
'
ij,ij
'
,
u_xy_Q3
,
weights
.
w_ij_Q3
)
...
...
This diff is collapsed.
Click to expand it.
pykat/utilities/maps.py
+
34
−
25
View file @
3a418d7c
from
pykat.utilities.romhom
import
makeReducedBasis
,
makeEmpiricalInterpolant
,
makeWeights
import
numpy
import
numpy
as
np
import
math
class
tiltmap
(
surfacemap
):
def
__init__
(
self
,
name
,
size
,
step_size
,
tilt
,
center
=
(
0
,
0
)
):
surfacemap
.
__init__
(
name
,
"
phase
"
,
size
,
center
,
step_sizes
)
self
.
tilt
=
tilt
@property
def
tilt
(
self
):
return
self
.
__tilt
@tilt.setter
def
tilt
(
self
,
value
):
self
.
__tilt
=
value
class
surfacemap
:
class
surfacemap
(
object
):
def
__init__
(
self
,
name
,
maptype
,
size
,
center
,
step_size
,
scaling
,
data
=
None
):
self
.
name
=
name
...
...
@@ -26,7 +11,12 @@ class surfacemap:
self
.
center
=
center
self
.
step_size
=
step_size
self
.
scaling
=
scaling
if
data
==
None
:
self
.
data
=
np
.
zeros
(
size
)
else
:
self
.
data
=
data
self
.
_rom_weights
=
None
def
write_map
(
self
,
filename
):
...
...
@@ -48,11 +38,11 @@ class surfacemap:
@property
def
x
(
self
):
return
self
.
step_size
[
0
]
*
(
n
umpy
.
array
(
range
(
1
,
self
.
data
.
shape
[
0
]
+
1
))
-
self
.
center
[
0
])
return
self
.
step_size
[
0
]
*
(
n
p
.
array
(
range
(
1
,
self
.
data
.
shape
[
0
]
+
1
))
-
self
.
center
[
0
])
@property
def
y
(
self
):
return
self
.
step_size
[
1
]
*
(
n
umpy
.
array
(
range
(
1
,
self
.
data
.
shape
[
1
]
+
1
))
-
self
.
center
[
1
])
return
self
.
step_size
[
1
]
*
(
n
p
.
array
(
range
(
1
,
self
.
data
.
shape
[
1
]
+
1
))
-
self
.
center
[
1
])
@property
def
size
(
self
):
...
...
@@ -60,7 +50,7 @@ class surfacemap:
@property
def
offset
(
self
):
return
n
umpy
.
array
(
self
.
step_size
)
*
(
self
.
center
-
n
umpy
.
array
(
self
.
size
)
/
2
)
return
n
p
.
array
(
self
.
step_size
)
*
(
self
.
center
-
n
p
.
array
(
self
.
size
)
/
2
)
@property
def
ROMWeights
(
self
):
...
...
@@ -70,7 +60,7 @@ class surfacemap:
if
"
phase
"
in
self
.
type
:
k
=
math
.
pi
*
2
/
wavelength
return
n
umpy
.
exp
(
2j
*
k
*
self
.
scaling
*
self
.
data
)
return
n
p
.
exp
(
2j
*
k
*
self
.
scaling
*
self
.
data
)
else
:
raise
BasePyKatException
(
"
Map type needs handling
"
)
...
...
@@ -123,6 +113,25 @@ class surfacemap:
return
fig
class
tiltmap
(
surfacemap
):
def
__init__
(
self
,
name
,
size
,
step_size
,
tilt
):
surfacemap
.
__init__
(
self
,
name
,
"
phase
"
,
size
,
(
np
.
array
(
size
)
+
1
)
/
2.0
,
step_size
,
1
)
self
.
tilt
=
tilt
@property
def
tilt
(
self
):
return
self
.
__tilt
@tilt.setter
def
tilt
(
self
,
value
):
self
.
__tilt
=
value
xx
,
yy
=
np
.
meshgrid
(
self
.
x
,
self
.
y
)
self
.
data
=
xx
*
self
.
tilt
[
0
]
+
yy
*
self
.
tilt
[
1
]
def
read_map
(
filename
):
with
open
(
filename
,
'
r
'
)
as
f
:
...
...
@@ -137,7 +146,7 @@ def read_map(filename):
data
=
n
umpy
.
loadtxt
(
filename
,
dtype
=
n
umpy
.
float64
,
ndmin
=
2
,
comments
=
'
%
'
)
data
=
n
p
.
loadtxt
(
filename
,
dtype
=
n
p
.
float64
,
ndmin
=
2
,
comments
=
'
%
'
)
return
surfacemap
(
name
,
maptype
,
size
,
center
,
step
,
scaling
,
data
)
...
...
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