App.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. <template>
  2. <div id="app">
  3. <b-loading :active.sync="isLoading" :can-cancel="isLoading"/>
  4. <ShowInfo/>
  5. <section class="add_padding">
  6. <GetUnits v-bind:units="units"
  7. v-bind:source_units="source_units"
  8. v-bind:isSourceOtherUnits="isSourceOtherUnits"
  9. @unitsData="units=$event"
  10. @source_unitsData="source_units=$event"
  11. @isSourceOtherUnitsData="isSourceOtherUnits=$event"
  12. />
  13. <GetHostIndex v-bind:hostIndex="simulationSetup.hostIndex"
  14. @hostIndexData="simulationSetup.hostIndex=$event" />
  15. <GetSourceParameters v-bind:fromWL="simulationSetup.fromWL"
  16. v-bind:toWL="simulationSetup.toWL"
  17. v-bind:stepWL="simulationSetup.stepWL"
  18. v-bind:source_units="source_units"
  19. @fromWLData="simulationSetup.fromWL=$event"
  20. @toWLData="simulationSetup.toWL=$event"
  21. @stepWLData="simulationSetup.stepWL=$event"
  22. @source_unitsData="source_units=$event"
  23. />
  24. <GetMaterials v-bind:materials="materials"
  25. v-bind:plot_width="chart.layout.width"
  26. v-bind:plot_height="chart.layout.height"
  27. />
  28. <GetParticleParameters v-bind:layers="simulationSetup.layers"
  29. v-bind:units="units"
  30. v-bind:materials="materials"
  31. />
  32. <div class="field is-horizontal">
  33. <div class="field-label is-normal">
  34. <label class="label">Modes to plot</label>
  35. </div>
  36. <div class="field-body" >
  37. <b-field label="">
  38. <b-input v-model="simulationSetup.total_mode_n" type='number' min=1 style="width:7rem"/>
  39. </b-field>
  40. </div>
  41. </div>
  42. <div class="add_padding">
  43. <b-button class="is-primary is-medium" @click="runSimulation();">
  44. Run simulation
  45. </b-button><br>
  46. It took {{ ttime }} s.
  47. </div>
  48. <div class="field is-grouped is-grouped-multiline add_padding">
  49. <b-switch v-model="plotSelector.isPlotQsca">
  50. Qsca
  51. </b-switch>
  52. <b-switch v-model="plotSelector.isPlotQabs">
  53. Qabs
  54. </b-switch>
  55. <b-switch v-model="plotSelector.isPlotQext">
  56. Qext
  57. </b-switch>
  58. </div>
  59. <!-- <b-table :data="plotSelectorData" :columns="plotSelectorColumns" :mobile-cards="isShowInfo"></b-table>-->
  60. <table class="table is-narrow add_padding">
  61. <thead>
  62. <tr>
  63. <th v-for="mode_name in simulationRuntime.mode_n_names" v-bind:key="mode_name.name">
  64. {{ mode_name.name == 'type' ? '': mode_name.name}}
  65. </th>
  66. </tr>
  67. </thead>
  68. <tbody>
  69. <tr>
  70. <th>E</th>
  71. <td v-for="(mode,index) in plotSelector.isPlotModeE" v-bind:key="index">
  72. <template v-if="(simulationRuntime.total_mode_n_evaluated - 1) < index">
  73. <b-checkbox v-model="plotSelector.isPlotModeE[index]" disabled> </b-checkbox>
  74. </template>
  75. <template v-else>
  76. <b-checkbox v-model="plotSelector.isPlotModeE[index]"> </b-checkbox>
  77. </template>
  78. </td>
  79. </tr>
  80. <tr>
  81. <th>H</th>
  82. <td v-for="(mode,index) in plotSelector.isPlotModeH" v-bind:key="index">
  83. <template v-if="(simulationRuntime.total_mode_n_evaluated - 1) < index">
  84. <b-checkbox v-model="plotSelector.isPlotModeH[index]" disabled> </b-checkbox>
  85. </template>
  86. <template v-else>
  87. <b-checkbox v-model="plotSelector.isPlotModeH[index]"> </b-checkbox>
  88. </template>
  89. </td>
  90. </tr>
  91. </tbody>
  92. </table>
  93. </section>
  94. <div class="chart-container">
  95. <reactive-chart :chart="chart"/>
  96. </div>
  97. </div>
  98. </template>
  99. <script>
  100. // You should put *.wasm to public/ and *.js to src/ folder
  101. // To compile fibbonacci example use
  102. // emcc -O3 -s WASM=1 -s EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap"]' -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 -s 'EXPORT_NAME="fibonacci"' -o ./fibonacci.js fibonacci.c
  103. // for and example from https://gist.github.com/ashleygwilliams/32c31a3f5b8c87bf2894108b3534ee4f
  104. // import fibonacci from './fibonacci.js';
  105. // const module = fibonacci({
  106. // locateFile(path) {
  107. // console.log(path);
  108. // return path;
  109. // }
  110. // });
  111. // module.onRuntimeInitialized = () => {
  112. // console.log(module._fib(12));
  113. // };
  114. // // Test the size of wasm file
  115. // fetch('nmiejs.wasm'
  116. // ).then(response =>
  117. // response.arrayBuffer()
  118. // ).then(bytes =>
  119. // console.log(bytes)
  120. // );
  121. import nmiejs from './nmiejs.js';
  122. // // Test nmiejs if working
  123. // (async () => {
  124. // const module = await nmiejs({
  125. // locateFile(path) {
  126. // let deploy_path = process.env.BASE_URL;
  127. // // '/themes/custom/physics/mie/';
  128. // // console.log();
  129. // // // let deploy_path = '';
  130. // console.log(deploy_path + path);
  131. // return deploy_path + path;
  132. // }
  133. // })
  134. // const nmie = new module.nmie();
  135. // nmie.ClearTarget();
  136. // let R = 100.0;
  137. // let reN = 4.0;
  138. // let imN = 0.01;
  139. // nmie.AddTargetLayerReIm(R, reN, imN)
  140. // nmie.SetModeNmaxAndType(-1, -1);
  141. // let WL = 800;
  142. // nmie.SetWavelength(WL);
  143. // nmie.RunMieCalculation();
  144. // console.log(nmie.GetQsca());
  145. //
  146. // })();
  147. const range = (start, stop, step = 1) => Array(Math.ceil((stop - start) / step)).fill(start).map((x, y) => x + y * step);
  148. function rangeInt(size, startAt = 0) {
  149. return [...Array(size).keys()].map(i => i + startAt);
  150. }
  151. import ReactiveChart from "./components/ReactiveChart.vue";
  152. import ShowInfo from "./components/ShowInfo.vue";
  153. import GetMaterials from "./components/GetMaterials.vue";
  154. import GetHostIndex from "./components/GetHostIndex.vue";
  155. import GetUnits from "./components/GetUnits.vue";
  156. import GetSourceParameters from "./components/GetSourceParameters.vue";
  157. import GetParticleParameters from "./components/GetParticleParameters.vue";
  158. export default {
  159. name: 'app',
  160. components: {
  161. GetHostIndex,
  162. GetMaterials,
  163. GetSourceParameters,
  164. GetParticleParameters,
  165. GetUnits,
  166. ReactiveChart,
  167. ShowInfo
  168. },
  169. data() {
  170. return {
  171. nmie: undefined,
  172. ttime: "",
  173. window: {
  174. width: 0,
  175. height: 0
  176. },
  177. units: 'nm',
  178. units_prev: 'nm',
  179. source_units: 'nm',
  180. source_units_prev: 'nm',
  181. materials: [],
  182. isSourceOtherUnits: false,
  183. simulationSetup: {
  184. hostIndex: 1,
  185. stepWL: 2,
  186. fromWL: 300.0,
  187. toWL: 1000.0,
  188. layers: [
  189. {
  190. R: 100.0,
  191. material: 'nk',
  192. isMaterialLoaded:true,
  193. reN: 4.0,
  194. imN: 0.01,
  195. index: 0
  196. }
  197. ],
  198. total_mode_n: 4
  199. },
  200. simulationRuntime: {
  201. r_units: 'nm',
  202. r_source_units: 'nm',
  203. stepWL: 2,
  204. fromWL: 300.0,
  205. toWL: 1000.0,
  206. layers: [
  207. {
  208. R: 100.0,
  209. material: 'nk',
  210. reN: 4.0,
  211. imN: 0.01,
  212. index:0
  213. }
  214. ],
  215. mode_n: [],
  216. mode_n_names: [],
  217. mode_types: range(0, 2),
  218. mode_names: ['E', 'H'],
  219. WLs: [],
  220. Qsca: [],
  221. Qabs: [],
  222. Qext: [],
  223. Qsca_n: [[], []],
  224. Qabs_n: [[], []],
  225. layout: {},
  226. trace1: {},
  227. trace2: {},
  228. total_mode_n_evaluated: 4,
  229. },
  230. plotData: {
  231. pWLs: [],
  232. pQsca: [],
  233. pQabs: [],
  234. pQext: [],
  235. pQsca_n: [[], []],
  236. pQabs_n: [[], []],
  237. },
  238. changes: 0,
  239. isShowInfo: false,
  240. isLoading: true,
  241. isRunning: false,
  242. plotSelector: {
  243. isPlotModeE: [],
  244. isPlotModeH: [],
  245. isPlotQabs: true,
  246. isPlotQsca: true,
  247. isPlotQext: false,
  248. },
  249. // plotSelectorData: undefined,
  250. // plotSelectorColumns: undefined,
  251. // plotSelectorNames: undefined,
  252. chart: {
  253. uuid: "spectra",
  254. traces: [
  255. {
  256. y: [],
  257. line: {
  258. color: "#5e9e7e",
  259. width: 4,
  260. shape: "line"
  261. }
  262. }
  263. ],
  264. layout: {
  265. margin: {
  266. l:0,
  267. r:40,
  268. b:50,
  269. t:0
  270. },
  271. // paper_bgcolor: '#7f7f7f',
  272. // plot_bgcolor: '#c7c7c7',
  273. // title: 'reactive charts',
  274. xaxis: {
  275. // will be set on mount
  276. title: ''
  277. },
  278. yaxis: {
  279. title: 'Normalized cross-sections'
  280. },
  281. showlegend: true,
  282. legend: {
  283. orientation:"h",
  284. x: -.1,
  285. y: 1.05
  286. },
  287. // width: 100,
  288. height: 100
  289. }
  290. }
  291. };
  292. },
  293. created() {
  294. window.addEventListener('resize', this.handleResize);
  295. this.handleResize();
  296. },
  297. destroyed() {
  298. window.removeEventListener('resize', this.handleResize)
  299. },
  300. mounted() {
  301. this.setXaxisTitle();
  302. (async () => {
  303. const module = await nmiejs({
  304. locateFile(path) {
  305. let deploy_path = process.env.BASE_URL;
  306. // '/themes/custom/physics/mie/';
  307. // console.log();
  308. // // let deploy_path = '';
  309. console.log(deploy_path + path);
  310. return deploy_path + path;
  311. }
  312. })
  313. this.nmie = new module.nmie();
  314. this.isLoading = false;
  315. this.runMie();
  316. this.setIsPlotMode();
  317. this.setModeNNames();
  318. this.plotResults();
  319. })();
  320. },
  321. watch: {
  322. plotSelector: {
  323. handler: function () {
  324. this.plotResults();
  325. },
  326. deep: true
  327. },
  328. 'simulationSetup.total_mode_n': function () {
  329. this.setIsPlotMode();
  330. this.setModeNNames();
  331. },
  332. units: {
  333. handler: function () {
  334. if (!this.isSourceOtherUnits) {
  335. this.source_units = this.units;
  336. }
  337. let u = this.units;
  338. let u_prev = this.units_prev;
  339. let layers = this.simulationSetup.layers;
  340. for (let i=0; i<layers.length; i++) {
  341. layers[i].R = this.convertUnits(u_prev, u, layers[i].R);
  342. }
  343. this.units_prev = this.units;
  344. }
  345. },
  346. source_units: {
  347. handler: function () {
  348. // this.$buefy.notification.open({
  349. // duration: 4000,
  350. // message: 'Source parameters were restored from last simulation for correct plotting.',
  351. // type: 'is-info',
  352. // position: 'is-top',
  353. // });
  354. this.setXaxisTitle();
  355. let u = this.source_units;
  356. let u_prev = this.source_units_prev;
  357. for (let i=0; i<this.plotData.pWLs.length; i++) {
  358. this.plotData.pWLs[i] = this.convertUnits(u_prev, u,
  359. this.plotData.pWLs[i]);
  360. }
  361. this.simulationSetup.fromWL = this.convertUnits(u_prev, u,
  362. this.simulationSetup.fromWL);
  363. this.simulationSetup.toWL = this.convertUnits(u_prev, u,
  364. this.simulationSetup.toWL);
  365. if (this.simulationSetup.fromWL > this.simulationSetup.toWL) {
  366. let tmp = this.simulationSetup.fromWL;
  367. this.simulationSetup.fromWL = this.simulationSetup.toWL;
  368. this.simulationSetup.toWL = tmp;
  369. }
  370. this.simulationSetup.stepWL = (this.simulationSetup.toWL-this.simulationSetup.fromWL)
  371. /this.plotData.pWLs.length;
  372. this.source_units_prev = this.source_units;
  373. // Update plotting
  374. this.plotSelector.isPlotQsca = !this.plotSelector.isPlotQsca
  375. setTimeout(
  376. () => {
  377. this.plotSelector.isPlotQsca = !this.plotSelector.isPlotQsca
  378. }, 2);
  379. }
  380. },
  381. isSourceOtherUnits: {
  382. handler: function () {
  383. // this.setEmptyChart();
  384. this.setXaxisTitle();
  385. if (!this.isSourceOtherUnits) {
  386. this.source_units = this.units;
  387. } else {
  388. this.source_units = 'THz'
  389. }
  390. }
  391. },
  392. window: {
  393. handler: function () {
  394. // this.chart.layout.width = this.window.width * 0.92;
  395. this.chart.layout.height = this.window.height * 0.95;
  396. // if (this.window.width < 600) this.chart.layout.width = this.window.width;
  397. if (this.window.height < 600) this.chart.layout.height = this.window.height;
  398. },
  399. deep: true
  400. }
  401. },
  402. methods: {
  403. handleResize() {
  404. this.window.width = window.innerWidth;
  405. this.window.height = window.innerHeight*0.8;
  406. },
  407. convertUnits2nm(fromU, val) {
  408. if (fromU === 'nm') return val;
  409. if (fromU === 'mkm') return val*1e3;
  410. if (fromU === 'mm') return val*1e6;
  411. if (fromU === 'cm') return val*1e7;
  412. if (fromU === 'm') return val*1e9;
  413. if (fromU === 'km') return val*1e12;
  414. let c = 299792458; // m/s
  415. let hc = 1239841930.092394328e-15; // m*eV
  416. if (fromU === 'THz') return c/(val*1e12)*1e9;
  417. if (fromU === 'GHz') return c/(val*1e9)*1e9;
  418. if (fromU === 'MHz') return c/(val*1e6)*1e9;
  419. if (fromU === 'kHz') return c/(val*1e3)*1e9;
  420. if (fromU === 'Hz') return c/(val*1e0)*1e9;
  421. if (fromU === 'eV') return hc/(val*1e0)*1e9;
  422. if (fromU === 'meV') return hc/(val/1e3)*1e9;
  423. if (fromU === 'fs') return (val/1e12)/c*1e9;
  424. if (fromU === 'ps') return (val/1e15)/c*1e9;
  425. return undefined;
  426. },
  427. convertUnitsFrom_nm(toU, val) {
  428. if (toU === 'nm') return val;
  429. if (toU === 'mkm') return val/1e3;
  430. if (toU === 'mm') return val/1e6;
  431. if (toU === 'cm') return val/1e7;
  432. if (toU === 'm') return val/1e9;
  433. if (toU === 'km') return val/1e12;
  434. let c = 299792458; // m/s
  435. let hc = 1239841930.092394328e-15; // m*eV
  436. if (toU === 'THz') return c/(val/1e9)/1e12;
  437. if (toU === 'GHz') return c/(val/1e9)/1e9;
  438. if (toU === 'MHz') return c/(val/1e9)/1e6;
  439. if (toU === 'kHz') return c/(val/1e9)/1e3;
  440. if (toU === 'Hz') return c/(val/1e9)/1e0;
  441. if (toU === 'eV') return hc/(val/1e9);
  442. if (toU === 'meV') return hc/(val/1e9)*1e3;
  443. if (toU === 'fs') return (val/1e9)/c*1e12;
  444. if (toU === 'ps') return (val/1e9)/c*1e15;
  445. return undefined;
  446. },
  447. convertUnits(fromU,toU, val) {
  448. if (fromU === toU) return val;
  449. return this.convertUnitsFrom_nm(toU, this.convertUnits2nm(fromU, val));
  450. },
  451. notifyDanger: function(message) {
  452. this.$buefy.notification.open({
  453. duration: 3000,
  454. message: message,
  455. type: 'is-danger',
  456. position: 'is-bottom-left',
  457. });
  458. },
  459. runSimulation: function() {
  460. this.$buefy.notification.open({
  461. duration: 200,
  462. message: 'Simulation was started!',
  463. type: 'is-danger',
  464. position: 'is-bottom-left',
  465. });
  466. setTimeout(
  467. () => {
  468. this.runMie();
  469. this.plotResults();
  470. this.$buefy.notification.open({
  471. duration: 3000,
  472. message: 'Finished! '+"It took " + this.ttime + " s.",
  473. type: 'is-success',
  474. position: 'is-bottom-left',
  475. })
  476. ;
  477. }, 20);
  478. },
  479. runMie: function () {
  480. this.simulationRuntime.r_units = this.units;
  481. this.simulationRuntime.r_source_units = this.source_units;
  482. this.simulationRuntime.fromWL = this.simulationSetup.fromWL;
  483. this.simulationRuntime.toWL = this.simulationSetup.toWL;
  484. this.simulationRuntime.stepWL = this.simulationSetup.stepWL;
  485. this.simulationRuntime.layers =this.simulationSetup.layers; // TODO: not a copy, but we need spline_n.at() method in every layer.
  486. let t0 = performance.now();
  487. let fromWL = parseFloat(this.simulationSetup.fromWL);
  488. let toWL = parseFloat(this.simulationSetup.toWL);
  489. let stepWL = parseFloat(this.simulationSetup.stepWL);
  490. let host = parseFloat(this.simulationSetup.hostIndex);
  491. let Qsca = [], Qabs = [], Qext = [];
  492. let Qsca_n = [[], []], Qabs_n = [[], []];
  493. let WLs = range(fromWL, toWL, stepWL);
  494. this.simulationRuntime.WLs = WLs;
  495. let total_mode_n = this.simulationSetup.total_mode_n;
  496. let mode_n = [];
  497. mode_n = rangeInt(Number(total_mode_n), 1);
  498. this.simulationRuntime.total_mode_n_evaluated = total_mode_n;
  499. let mode_types = range(0, 2);
  500. this.simulationSetup.mode_n = mode_n;
  501. this.simulationSetup.mode_types = mode_types;
  502. mode_types.forEach(function (mode_type) {
  503. mode_n.forEach(function () {
  504. Qsca_n[mode_type].push([]);
  505. Qabs_n[mode_type].push([]);
  506. });
  507. });
  508. // Provide all sizes (germetry and wavelengths) to nmie in same units [nm]
  509. const nmie = this.nmie;
  510. // nmie.ClearTarget();
  511. // nmie.AddTargetLayerReIm( this.convertUnits2nm(this.units, R)*host,
  512. // reN/host, imN/host);
  513. let WLs_nm = range(fromWL, toWL, stepWL);
  514. let WL_points = WLs_nm.length;
  515. for (let i = 0; i < WL_points; i++) {
  516. let WL = this.convertUnits2nm(this.source_units, WLs[i]);
  517. nmie.ClearTarget();
  518. for (let num_layer = 0;
  519. num_layer < this.simulationRuntime.layers.length;
  520. num_layer++) {
  521. let layer = this.simulationRuntime.layers[num_layer];
  522. let R = parseFloat(layer.R);
  523. if (layer.material === 'PEC') {
  524. // TODO: set PEC layer
  525. continue;
  526. }
  527. if (layer.material !== 'nk') {
  528. if ( layer.spline_n === undefined ) {
  529. this.notifyDanger('Failed to load material!');
  530. return;
  531. }
  532. if (layer.spline_n.xs[0] > WL
  533. || layer.spline_n.xs[layer.spline_n.xs.length-1] < WL) {
  534. this.notifyDanger('ERROR!!! Source parameters are out of material spectral range!');
  535. return;
  536. }
  537. layer.reN = layer.spline_n.at(WL);
  538. layer.imN = layer.spline_k.at(WL);
  539. }
  540. let reN = parseFloat(layer.reN);
  541. let imN = parseFloat(layer.imN);
  542. nmie.AddTargetLayerReIm( this.convertUnits2nm(this.units, R)*host,
  543. reN/host, imN/host);
  544. }
  545. nmie.SetModeNmaxAndType(-1, -1);
  546. nmie.SetWavelength(WL);
  547. nmie.RunMieCalculation();
  548. Qsca.push(nmie.GetQsca());
  549. Qabs.push(nmie.GetQabs());
  550. Qext.push(nmie.GetQsca()+nmie.GetQabs());
  551. mode_types.forEach(function (mode_type) {
  552. mode_n.forEach(function (n) {
  553. nmie.SetModeNmaxAndType(n, mode_type);
  554. nmie.RunMieCalculation();
  555. Qsca_n[mode_type][n - 1].push(nmie.GetQsca());
  556. Qabs_n[mode_type][n - 1].push(nmie.GetQabs());
  557. });
  558. });
  559. }
  560. this.simulationRuntime.Qsca = Qsca;
  561. this.simulationRuntime.Qabs = Qabs;
  562. this.simulationRuntime.Qext = Qext;
  563. this.simulationRuntime.Qsca_n = Qsca_n;
  564. this.simulationRuntime.Qabs_n = Qabs_n;
  565. let t1 = performance.now();
  566. this.ttime = ((t1 - t0) / 1000).toFixed(2);
  567. // console.log("It took " + this.ttime + " s.");
  568. this.plotData.pWLs = WLs.slice();
  569. this.plotData.pQsca = Qsca;
  570. this.plotData.pQabs = Qabs;
  571. this.plotData.pQext = Qext;
  572. this.plotData.pQsca_n = Qsca_n;
  573. this.plotData.pQabs_n = Qabs_n;
  574. this.changes++;
  575. },
  576. filterBug: function () {
  577. let Qsca = this.simulationRuntime.Qsca;
  578. let Qabs = this.simulationRuntime.Qabs;
  579. let Qext = this.simulationRuntime.Qext;
  580. let Qsca_n = this.simulationRuntime.Qsca_n;
  581. let Qabs_n = this.simulationRuntime.Qabs_n;
  582. let total_mode_n = this.simulationSetup.total_mode_n;
  583. for (let mode_type = 0; mode_type < 2; mode_type++) {
  584. for (let n = 0; n < total_mode_n; n++){
  585. this.filterMedian(Qsca_n[mode_type][n]);
  586. this.filterMedian(Qabs_n[mode_type][n]);
  587. }
  588. }
  589. this.filterMedian(Qsca);
  590. this.filterMedian(Qabs);
  591. for (let i = 0; i < Qsca.length; i++) {
  592. Qext[i] = Qsca[i] + Qabs[i];
  593. }
  594. // this.filterMedian(Qext);
  595. this.simulationRuntime.Qsca = Qsca;
  596. this.simulationRuntime.Qabs = Qabs;
  597. this.simulationRuntime.Qext = Qext;
  598. this.simulationRuntime.Qsca_n = Qsca_n;
  599. this.simulationRuntime.Qabs_n = Qabs_n;
  600. },
  601. filterMedian: function(spectra) {
  602. let l = spectra.length;
  603. let i;
  604. for (i = 1; i < l-1; i++) {
  605. let prev = spectra[i-1];
  606. let curr = spectra[i];
  607. let next = spectra[i+1];
  608. let diff1 = Math.abs((prev-curr)/curr);
  609. let diff2 = Math.abs((next-curr)/curr);
  610. if (diff1 > 0.3 && diff2 > 0.3) {
  611. spectra[i] = (prev+next)/2.0;
  612. }
  613. // console.log(spectra(i));
  614. }
  615. // return spectra;
  616. },
  617. setIsPlotMode: function () {
  618. let total_mode_n = this.simulationSetup.total_mode_n;
  619. total_mode_n++;
  620. let np1 = Number(total_mode_n);
  621. let mode_n = rangeInt(Number(np1), 0);
  622. let modeE = [];
  623. let modeH = [];
  624. mode_n.forEach(function (n) {
  625. if (n !== 0) {
  626. modeE.push(false);
  627. modeH.push(false);
  628. }
  629. });
  630. let saved_modes = this.simulationSetup.total_mode_n > this.simulationRuntime.total_mode_n_evaluated ?
  631. this.simulationRuntime.total_mode_n_evaluated : this.simulationSetup.total_mode_n;
  632. this.simulationRuntime.total_mode_n_evaluated = saved_modes;
  633. let oldModeE = this.plotSelector.isPlotModeE;
  634. let oldModeH = this.plotSelector.isPlotModeH;
  635. let ii;
  636. for (ii = 0; ii < saved_modes; ++ii) {
  637. if (ii < oldModeE.length) {
  638. modeE[ii] = oldModeE[ii];
  639. modeH[ii] = oldModeH[ii];
  640. }
  641. }
  642. this.plotSelector.isPlotModeE = modeE;
  643. this.plotSelector.isPlotModeH = modeH;
  644. },
  645. setXaxisTitle: function () {
  646. if (this.source_units.endsWith('Hz')) {
  647. this.chart.layout.xaxis.title = "Frequency, " + this.source_units;
  648. } else if (this.source_units.endsWith('eV')) {
  649. this.chart.layout.xaxis.title = "Energy, " + this.source_units;
  650. } else if (this.source_units.endsWith('s')) {
  651. this.chart.layout.xaxis.title = "Period, " + this.source_units;
  652. } else {
  653. this.chart.layout.xaxis.title = "Wavelength, " + this.source_units;
  654. }
  655. },
  656. setModeNNames: function () {
  657. let total_mode_n = this.simulationSetup.total_mode_n;
  658. total_mode_n++;
  659. let np1 = Number(total_mode_n);
  660. let mode_n = rangeInt(Number(np1), 0);
  661. let mode_n_names = [];
  662. mode_n.forEach(function (n) {
  663. if (n === 0) mode_n_names.push({id: 0, name: 'type'});
  664. else if (n === 1) mode_n_names.push({id: 1, name: 'dipole'});
  665. else if (n === 2) mode_n_names.push({id: 2, name: 'quadrupole'});
  666. else if (n === 3) mode_n_names.push({id: 3, name: 'octupole'});
  667. else mode_n_names.push({id: n, name: (Math.pow(2, n)).toString()});
  668. });
  669. this.simulationRuntime.mode_n_names = mode_n_names;
  670. },
  671. setQtotalChart: function () {
  672. let traceQsca, traceQabs, traceQext;
  673. traceQsca = {
  674. x: this.plotData.pWLs,
  675. y: this.plotData.pQsca,
  676. type: 'scatter',
  677. name: 'Qsca'
  678. };
  679. traceQabs = {
  680. x: this.plotData.pWLs,
  681. y: this.plotData.pQabs,
  682. type: 'scatter',
  683. name: 'Qabs'
  684. };
  685. traceQext = {
  686. x: this.plotData.pWLs,
  687. y: this.plotData.pQext,
  688. type: 'scatter',
  689. name: 'Qext'
  690. };
  691. this.chart.traces = [];
  692. if (this.plotSelector.isPlotQsca === true) this.chart.traces.push(traceQsca);
  693. if (this.plotSelector.isPlotQabs === true) this.chart.traces.push(traceQabs);
  694. if (this.plotSelector.isPlotQext === true) this.chart.traces.push(traceQext);
  695. },
  696. plotResults: function () {
  697. this.setQtotalChart();
  698. let mode_type, mode_n;
  699. let mode_n_names = this.simulationRuntime.mode_n_names;
  700. let mode_names = this.simulationRuntime.mode_names;
  701. for (mode_type = 0; mode_type < 2; ++mode_type) {
  702. for (mode_n = 0; mode_n < this.simulationRuntime.total_mode_n_evaluated; ++mode_n) {
  703. let is_mode_plot = mode_type === 0 ? this.plotSelector.isPlotModeE : this.plotSelector.isPlotModeH;
  704. if (is_mode_plot[mode_n] === false) continue;
  705. if (this.plotSelector.isPlotQsca === true) {
  706. let trace_sca = {
  707. x: this.plotData.pWLs,
  708. y: this.plotData.pQsca_n[mode_type][mode_n],
  709. type: 'scatter',
  710. name: 'Qsca ' + mode_names[mode_type] + ' ' + mode_n_names[mode_n + 1].name
  711. };
  712. this.chart.traces.push(trace_sca);
  713. }
  714. if (this.plotSelector.isPlotQabs === true) {
  715. let trace_abs = {
  716. x: this.plotData.pWLs,
  717. y: this.plotData.pQabs_n[mode_type][mode_n],
  718. type: 'scatter',
  719. name: 'Qabs ' + mode_names[mode_type] + ' ' + mode_n_names[mode_n + 1].name
  720. };
  721. this.chart.traces.push(trace_abs);
  722. }
  723. }
  724. }
  725. }
  726. },
  727. };
  728. </script>
  729. <style lang="scss">
  730. // Import Bulma's core
  731. @import "~bulma/sass/utilities/_all";
  732. // https://bulma.io/documentation/customize/variables/
  733. // $body-background-color: $green;
  734. // Set your colors
  735. $primary: #7957d5;
  736. $twitter: #4099FF;
  737. $twitter-invert: findColorInvert($twitter);
  738. // Setup $colors to use as bulma classes (e.g. 'is-twitter')
  739. $colors: (
  740. "white": ($white, $black),
  741. "black": ($black, $white),
  742. "light": ($light, $light-invert),
  743. "dark": ($dark, $dark-invert),
  744. "primary": ($primary, $primary-invert),
  745. "info": ($info, $info-invert),
  746. "success": ($success, $success-invert),
  747. "warning": ($warning, $warning-invert),
  748. "danger": ($danger, $danger-invert),
  749. "twitter": ($twitter, $twitter-invert)
  750. );
  751. // Links
  752. // $link: $primary;
  753. // $link-invert: $primary-invert;
  754. // $link-focus-border: $primary;
  755. // Import Bulma and Buefy styles
  756. @charset "utf-8";
  757. /*! bulma.io v0.7.5 | MIT License | github.com/jgthms/bulma */
  758. @import "~bulma/sass/utilities/_all";
  759. @import "~bulma/sass/base/_all";
  760. /*@import "~bulma/sass/elements/_all";*/
  761. @import "~bulma/sass/elements/box.sass";
  762. @import "~bulma/sass/elements/button.sass";
  763. @import "~bulma/sass/elements/container.sass";
  764. @import "~bulma/sass/elements/content.sass";
  765. /*@import "~bulma/sass/elements/icon.sass";*/
  766. @import "~bulma/sass/elements/image.sass";
  767. @import "~bulma/sass/elements/notification.sass";
  768. @import "~bulma/sass/elements/progress.sass";
  769. @import "~bulma/sass/elements/table.sass";
  770. @import "~bulma/sass/elements/tag.sass";
  771. @import "~bulma/sass/elements/title.sass";
  772. @import "~bulma/sass/elements/other.sass";
  773. @import "~bulma/sass/form/_all";
  774. /*@import "~bulma/sass/components/_all";*/
  775. @import "~bulma/sass/components/dropdown";
  776. @import "~bulma/sass/components/tabs";
  777. @import "~bulma/sass/components/modal";
  778. @import "~bulma/sass/components/message";
  779. @import "~bulma/sass/grid/_all";
  780. /*@import "~bulma/sass/layout/_all";*/
  781. // @import "~bulma";
  782. @import "~buefy/src/scss/buefy";
  783. .add_padding {
  784. padding: 1rem;
  785. }
  786. // Custom styles to build into the design of physics.ifmo.ru
  787. // npm run build && ./deploy.sh && xclip -sel c < dist/index.html
  788. .content table {
  789. width: auto;
  790. }
  791. ul {
  792. padding-left: 1.5em;
  793. }
  794. body {
  795. line-height: 1.42857;
  796. }
  797. /*.container {*/
  798. /* width: 750px;*/
  799. /*}*/
  800. h1 {
  801. font-size: 34px;
  802. font-weight: bold;
  803. }
  804. .block-views-blockmessages-header-message-block {
  805. top: 25px;
  806. }
  807. </style>