Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PAnTHer
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
puma
client
PAnTHer
Commits
740eda7e
Commit
740eda7e
authored
4 months ago
by
Lucio Zambon
Browse files
Options
Downloads
Patches
Plain Diff
Add new file
parent
e265e021
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
simulator2d.js
+192
-0
192 additions, 0 deletions
simulator2d.js
with
192 additions
and
0 deletions
simulator2d.js
0 → 100644
+
192
−
0
View file @
740eda7e
// jshint esversion: 6
const
factorsHor
=
{
""
:
1000
,
"
position
"
:
5000
,
'
beta
'
:
0.5
,
'
eta
'
:
20
,
'
mu
'
:
0.2
,
'
sigma
'
:
5000000
};
const
factorsVer
=
{
""
:
1000
,
"
position
"
:
5000
,
'
beta
'
:
0.5
,
'
eta
'
:
200
,
'
mu
'
:
0.2
,
'
sigma
'
:
5000000
};
const
simulator
=
document
.
location
.
search
.
indexOf
(
'
simulator=
'
)
>-
1
?
document
.
location
.
search
.
split
(
'
simulator=
'
)[
1
].
split
(
'
&
'
)[
0
]:
''
;
const
visibility
=
simulator
==
''
?
'
hidden
'
:
'
visible
'
;
let
simulatorBuffer
=
false
;
let
logScaleHor
=
false
;
let
logScaleVer
=
false
;
let
simulatorFactorHor
=
document
.
location
.
search
.
indexOf
(
'
simulatorFactorHor=
'
)
>-
1
?
document
.
location
.
search
.
split
(
'
simulatorFactorHor=
'
)[
1
].
split
(
'
&
'
)[
0
]
*
1000
*
(
simulator
==
'
sigma
'
?
1000000
:
1
):
factorsHor
[
simulator
]
*
1000
;
let
simulatorFactorVer
=
document
.
location
.
search
.
indexOf
(
'
simulatorFactorVer=
'
)
>-
1
?
document
.
location
.
search
.
split
(
'
simulatorFactorVer=
'
)[
1
].
split
(
'
&
'
)[
0
]
*
1000
*
(
simulator
==
'
sigma
'
?
1000000
:
1
):
factorsVer
[
simulator
]
*
1000
;
function
factorHor
(
v
)
{
console
.
log
(
'
factorHor()
'
,
v
);
simulatorFactorHor
=
v
*
1000
;
}
function
factorVer
(
v
)
{
console
.
log
(
'
factorVer()
'
,
v
);
simulatorFactorVer
=
v
*
1000
;
}
function
logscale
(
dirNum
)
{
if
(
dirNum
==
0
)
logScaleHor
=
$
(
'
#logHor
'
).
attr
(
'
checked
'
)
==
'
checked
'
;
else
logScaleVer
=
$
(
'
#logVer
'
).
attr
(
'
checked
'
)
==
'
checked
'
;
}
function
simulatorMenu
(
lattice
,
facilities
,
params
)
{
console
.
log
(
'
simulatorMenu
'
,
lattice
,
facilities
,
params
);
// params.simulator = false;
$
(
'
.simulatorhor
'
).
css
(
'
display
'
,
'
none
'
);
$
(
'
.simulatorver
'
).
css
(
'
display
'
,
'
none
'
);
params
.
simulator
=
document
.
location
.
search
.
indexOf
(
'
simulator
'
)
>-
1
&&
document
.
location
.
search
.
indexOf
(
'
=simulator
'
)
==-
1
?
'
position
'
:
''
;
if
(
document
.
location
.
search
.
indexOf
(
'
simulator=
'
)
>-
1
)
params
.
simulator
=
document
.
location
.
search
.
split
(
'
simulator=
'
)[
1
].
split
(
'
&
'
)[
0
];
const
options
=
[
''
,
'
position
'
,
'
beta
'
,
'
eta
'
,
'
mu
'
,
'
sigma
'
];
if
(
options
.
indexOf
(
params
.
simulator
)
==-
1
)
params
.
simulator
=
'
position
'
;
gui
.
add
(
params
,
'
simulator
'
,
options
).
name
(
'
simulator H <img id="h" src="red.svg" style="margin-bottom: -4px;"> V <img id="v" src="green.svg" style="margin-bottom: -4px;">
'
).
onChange
(
function
()
{
simulatorSwitch
(
compData
,
params
);});
const
controllerOption
=
$
(
'
.controller.option
'
);
for
(
let
i
=
0
;
i
<
controllerOption
.
length
;
i
++
)
{
if
(
controllerOption
.
eq
(
i
).
children
()[
0
].
innerText
.
indexOf
(
"
simulator H
"
)
>
-
1
)
{
const
maxVer
=
Math
.
pow
(
10
,
Math
.
floor
(
Math
.
log10
(
simulatorFactorVer
/
1000
))
+
2
);
$
(
'
<div class="simulatorgauge"><iframe id="vergauge" style="width: 100%;height:250px;" src="../misc/gauge.html?dark&r=115&ringwidth=30&max=
'
+
maxVer
+
'
&throttlingPeriod=50&apply=factorVer&extbackground=green&exthighlight=darkgreen&intbackground=green&inthighlight=darkgreen&val=
'
+
simulatorFactorVer
/
1000
+
'
"></iframe></div>
'
).
insertAfter
(
controllerOption
.
eq
(
i
));
const
maxHor
=
Math
.
pow
(
10
,
Math
.
floor
(
Math
.
log10
(
simulatorFactorHor
/
1000
))
+
2
);
$
(
'
<div class="simulatorgauge"><iframe id="horgauge" style="width: 100%;height:250px;" src="../misc/gauge.html?dark&r=115&ringwidth=30&max=
'
+
maxHor
+
'
&throttlingPeriod=50&apply=factorHor&extbackground=red&exthighlight=darkred&intbackground=red&inthighlight=darkred&val=
'
+
simulatorFactorHor
/
1000
+
'
"></iframe></div>
'
).
insertAfter
(
controllerOption
.
eq
(
i
));
$
(
'
<div style="padding: 8px;" class="simulatorgauge">log scale H <img id="h" src="red.svg" style="margin-bottom: -2px;"> <input type="checkbox" id="logHor" onChange="logscale(0)"> log V <img id="h" src="green.svg" style="margin-bottom: -2px;"> <input type="checkbox" id="logVer" onChange="logscale(1)"></div>
'
).
insertAfter
(
controllerOption
.
eq
(
i
));
if
(
simulator
==
''
)
$
(
'
.simulatorgauge
'
).
hide
();
}
}
for
(
let
f
in
facilities
)
{
const
b
=
facilities
[
f
];
if
(
b
!=
'
sr
'
)
continue
;
console
.
log
(
'
simulatorMenu() -
'
,
b
,
lattice
[
b
],
conf
.
simulatorSrcUrl
);
compData
[
b
].
map
=
[];
fetch
(
conf
.
simulatorSrcUrl
)
.
then
((
response
)
=>
{
return
response
.
json
();})
.
then
((
simulatorNaming
)
=>
{
console
.
log
(
'
simulatorNaming
'
,
simulatorNaming
);
for
(
let
i
in
simulatorNaming
)
{
const
name
=
simulatorNaming
[
i
];
if
(
name
==
'
SCRPH_S11
'
||
name
==
'
SCRPV_S11
'
)
continue
;
for
(
let
bl
in
compData
[
b
].
obj
)
{
if
(
name
==
compData
[
b
].
obj
[
bl
].
replace
(
'
CHV
'
,
'
CH
'
))
{
compData
[
b
].
map
[
i
]
=
bl
;}
}
}
console
.
log
(
'
simulatorMenu(), name
'
,
b
,
compData
[
b
],
lattice
[
b
]);
for
(
let
fi
in
facilities
)
{
const
facility
=
facilities
[
fi
];
if
(
facility
!=
'
sr
'
)
continue
;
console
.
log
(
fi
,
facility
,
compData
);
if
(
facility
.
length
>
0
&&
typeof
compData
[
facility
]
!=
'
undefined
'
&&
compData
[
facility
].
obj
&&
compData
[
facility
].
obj
.
length
>
0
)
{
console
.
log
(
'
simulatorInit
'
,
facility
,
compData
[
facility
]);
const
dhor
=
[];
const
dver
=
[];
for
(
i
=
0
;
i
<
compData
[
facility
].
pos
.
length
;
i
++
)
{
// if (i>threshold) break;
const
dir
=
compData
[
facility
].
dir
[
i
];
const
beta
=
Math
.
PI
*
dir
/
180
;
if
(
threshold
<
1000
)
console
.
log
(
'
i
'
,
i
,
'
pos
'
,
compData
[
facility
].
pos
[
i
],
'
dir
'
,
dir
,
beta
,
Math
.
cos
(
beta
),
Math
.
sin
(
beta
));
dhor
.
push
((
i
==
0
?
'
M
'
:
'
L
'
)
+
Math
.
round
(
compData
[
facility
].
pos
[
i
][
0
]
-
f
*
Math
.
sin
(
beta
))
+
'
'
+
Math
.
round
(
compData
[
facility
].
pos
[
i
][
1
]
+
f
*
Math
.
cos
(
beta
))
);
dver
.
push
((
i
==
0
?
'
M
'
:
'
L
'
)
+
Math
.
round
(
compData
[
facility
].
pos
[
i
][
0
]
-
f
*
1.05
*
Math
.
sin
(
beta
))
+
'
'
+
Math
.
round
(
compData
[
facility
].
pos
[
i
][
1
]
+
f
*
1.05
*
Math
.
cos
(
beta
))
);
}
appendSvg
(
"
path
"
,
{
id
:
facility
+
"
_simulatorhor
"
,
class
:
"
simulatorhor
"
+
facility
,
visibility
:
visibility
,
name
:
"
simulatorhor
"
,
fill
:
"
none
"
,
"
stroke-width
"
:
"
150
"
,
"
stroke
"
:
"
red
"
,
"
stroke-opacity
"
:
"
0.8
"
,
d
:
dhor
.
join
(
'
'
)
+
(
lattice
[
facility
].
sections
[
0
].
chamber
?
'
Z
'
:
''
)},
false
,
false
,
false
,
'
.svg-pan-zoom_viewport
'
);
appendSvg
(
"
path
"
,
{
id
:
facility
+
"
_simulatorver
"
,
class
:
"
simulatorver
"
+
facility
,
visibility
:
visibility
,
name
:
"
simulatorver
"
,
fill
:
"
none
"
,
"
stroke-width
"
:
"
150
"
,
"
stroke
"
:
"
green
"
,
"
stroke-opacity
"
:
"
0.8
"
,
d
:
dver
.
join
(
'
'
)
+
(
lattice
[
facility
].
sections
[
0
].
chamber
?
'
Z
'
:
''
)},
false
,
false
,
false
,
'
.svg-pan-zoom_viewport
'
);
// console.log("path", {id:facility+"_simulatorhor", name:"simulatorhor", d: dver.join(' ')+' Z'});
}
}
});
}
if
(
document
.
location
.
search
.
indexOf
(
'
simulator
'
)
>-
1
)
{
/*params.simulator=true;*/
setTimeout
(
simulatorSwitch
,
500
,
compData
,
params
);}
}
// const threshold = document.location.search.indexOf('threshold=')>-1? document.location.search.split('threshold=')[1].split('&')[0]: 1000;
// const f = document.location.search.indexOf('factor=')>-1? document.location.search.split('factor=')[1].split('&')[0]: 3000;
function
simulator2d
(
lattice
,
params
)
{
console
.
log
(
'
simulator2d
'
);
const
facilities
=
[];
for
(
let
i
in
lattice
)
{
if
(
i
!=
'
conf
'
)
facilities
.
push
(
i
);}
simulatorMenu
(
lattice
,
facilities
,
params
);
}
function
simulatorSwitch
(
simulatorData
,
params
)
{
console
.
log
(
'
simulatorSwitch()
'
,
simulatorData
,
params
,
params
.
simulator
);
if
(
simulatorData
.
reader
!==
false
)
{
clearInterval
(
simulatorData
.
reader
);
}
simulatorData
.
reader
=
false
;
if
(
params
.
simulator
==
''
)
{
for
(
let
facility
in
simulatorData
)
{
if
(
typeof
$
(
'
#
'
+
facility
+
"
_simulatorhor
"
).
attr
(
'
visibility
'
)
!=
'
undefined
'
)
{
$
(
'
#
'
+
facility
+
"
_simulatorhor
"
).
attr
(
'
visibility
'
,
"
hidden
"
);
$
(
'
#
'
+
facility
+
"
_simulatorver
"
).
attr
(
'
visibility
'
,
"
hidden
"
);
}
}
$
(
'
#application
'
).
hide
();
$
(
'
#applicationFrame
'
).
removeAttr
(
"
src
"
);
$
(
'
.simulatorgauge
'
).
hide
();
}
else
{
for
(
let
facility
in
simulatorData
)
{
if
(
typeof
$
(
'
#
'
+
facility
+
"
_simulatorhor
"
).
attr
(
'
visibility
'
)
!=
'
undefined
'
)
{
$
(
'
#
'
+
facility
+
"
_simulatorhor
"
).
attr
(
'
visibility
'
,
"
visible
"
);
$
(
'
#
'
+
facility
+
"
_simulatorver
"
).
attr
(
'
visibility
'
,
"
visible
"
);
}
// console.log('#'+facility+"_simulatorhor", $('#'+facility+"_simulatorhor").attr('visibility'), typeof simulatorData[facility]);
if
(
typeof
simulatorData
[
facility
]
==
'
undefined
'
||
typeof
simulatorData
[
facility
].
map
==
'
undefined
'
)
continue
;
simulatorData
.
oldIndex
=
facility
;
simulatorRead
(
simulatorData
,
params
);
}
displayer
=
setInterval
(
simulatorDisplay
,
200
,
params
);
simulatorData
.
reader
=
setInterval
(
simulatorRead
,
1000
,
simulatorData
,
params
);
$
(
'
#application
'
).
show
();
$
(
'
.simulatorhor
'
).
css
(
'
display
'
,
'
block
'
);
$
(
'
.simulatorver
'
).
css
(
'
display
'
,
'
block
'
);
simulatorFactorHor
=
factorsHor
[
params
.
simulator
]
*
1000
;
document
.
getElementById
(
"
horgauge
"
).
contentWindow
.
maxval
=
Math
.
pow
(
10
,
Math
.
floor
(
Math
.
log10
(
factorsHor
[
params
.
simulator
]))
+
2
);
document
.
getElementById
(
"
horgauge
"
).
contentWindow
.
reset
();
document
.
getElementById
(
"
horgauge
"
).
contentWindow
.
setVal
(
factorsHor
[
params
.
simulator
]);
simulatorFactorVer
=
factorsVer
[
params
.
simulator
]
*
1000
;
document
.
getElementById
(
"
vergauge
"
).
contentWindow
.
maxval
=
Math
.
pow
(
10
,
Math
.
floor
(
Math
.
log10
(
factorsVer
[
params
.
simulator
]))
+
2
);
document
.
getElementById
(
"
vergauge
"
).
contentWindow
.
reset
();
document
.
getElementById
(
"
vergauge
"
).
contentWindow
.
setVal
(
factorsVer
[
params
.
simulator
]);
$
(
'
.simulatorgauge
'
).
show
();
// $('#applicationFrame').attr("src", "/spa/index.html?s=simulator&src="+params.simulator+(document.location.search.indexOf('demo')>-1? '&demo': ''));
// $("#applicationFrame").height(window.innerHeight);
}
}
const
logConst
=
ln
(
10
)
function
simulatorRender
(
facility
,
val
,
simulator
)
{
// console.log('simulatorRender(), val', val, simulatorFactorHor);
const
dhor
=
[];
const
dver
=
[];
if
(
val
.
Hor
)
{
for
(
i
=
0
;
i
<
val
.
Hor
.
length
;
i
++
)
{
if
(
typeof
compData
[
facility
].
map
[
i
]
==
'
undefined
'
)
continue
;
const
j
=
compData
[
facility
].
map
[
i
];
if
(
document
.
location
.
search
.
indexOf
(
'
pulse=
'
)
>-
1
&&
i
!=
document
.
location
.
search
.
split
(
'
pulse=
'
)[
1
].
split
(
'
&
'
)[
0
])
{
val
.
Hor
[
i
]
=
0
;}
const
pos
=
compData
[
facility
].
pos
[
j
];
if
(
pos
==
null
)
continue
;
const
beta
=
Math
.
PI
*
compData
[
facility
].
dir
[
j
]
/
180
;
// https://en.wikipedia.org/wiki/Logarithmic_scale#Extensions
const
valHor
=
logScaleHor
?
Math
.
sign
(
val
.
Hor
[
i
])
*
Math
.
log10
(
1
+
Math
.
abs
(
val
.
Hor
[
i
]
*
Math
.
LN10
)):
val
.
Hor
[
i
];
const
valVer
=
logScaleVer
?
Math
.
sign
(
val
.
Ver
[
i
])
*
Math
.
log10
(
1
+
Math
.
abs
(
val
.
Ver
[
i
]
*
Math
.
LN10
)):
val
.
Ver
[
i
];
// if (i<20) console.log('i', i, 'pos',pos, 'dir', compData[facility].dir[i], 'facility', facility, beta, Math.cos(beta), Math.sin(beta));
dhor
.
push
((
dhor
.
length
==
0
?
'
M
'
:
'
L
'
)
+
Math
.
round
(
pos
[
0
]
-
valHor
*
simulatorFactorHor
*
Math
.
sin
(
beta
))
+
'
'
+
Math
.
round
(
pos
[
1
]
+
valHor
*
simulatorFactorHor
*
Math
.
cos
(
beta
))
);
dver
.
push
((
dver
.
length
==
0
?
'
M
'
:
'
L
'
)
+
Math
.
round
(
pos
[
0
]
-
valVer
*
simulatorFactorVer
*
Math
.
sin
(
beta
))
+
'
'
+
Math
.
round
(
pos
[
1
]
+
valVer
*
simulatorFactorVer
*
Math
.
cos
(
beta
))
);
}
// console.log('Hor', dhor.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
$
(
'
#
'
+
facility
+
"
_simulatorhor
"
).
attr
(
'
d
'
,
dhor
.
join
(
'
'
)
+
(
lattice
[
facility
].
sections
[
0
].
chamber
?
'
Z
'
:
''
));
$
(
'
#
'
+
facility
+
"
_simulatorver
"
).
attr
(
'
d
'
,
dver
.
join
(
'
'
)
+
(
lattice
[
facility
].
sections
[
0
].
chamber
?
'
Z
'
:
''
));
}
}
function
simulatorDisplay
(
params
)
{
if
(
simulatorBuffer
==
false
)
return
;
simulatorRender
(
'
sr
'
,
simulatorBuffer
,
params
.
simulator
);
}
function
simulatorRead
(
simulatorData
,
params
)
{
// console.log('fetch()',conf.simulatorUrl+'¶m='+params.simulator);
fetch
(
conf
.
simulatorUrl
+
'
¶m=
'
+
params
.
simulator
,
{
cache
:
"
no-store
"
})
.
then
((
response
)
=>
{
return
response
.
json
();})
.
then
((
eventData
)
=>
{
simulatorBuffer
=
eventData
.
sr
;
// simulatorRender('sr', eventData['sr'], params.simulator);
/*for (let i in eventData) {
simulatorRender(i, eventData[i]);
}*/
});
}
This diff is collapsed.
Click to expand it.
Preview
0%
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