App.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <div id="app">
  3. <section style="padding: 1rem">
  4. <button class="button is-primary is-medium"
  5. @click="isShowInfo = true">
  6. Show info
  7. </button>
  8. <b-modal :active.sync="isShowInfo">
  9. <div class="message" style="padding: 2rem">
  10. <span style="text-decoration: underline;text-emphasis: before;font-weight: bold;">Usage:</span>
  11. <br><br>
  12. Feel free to use provided software, however, use it at your own risk. We made our best effort to verify
  13. it is correct, however, we do not provide any warranty.
  14. <br><br>
  15. If it was usefull for your project, please, cite in your related paper the following reference:
  16. <br><br>
  17. <article style="margin-left: 1rem">
  18. <div style="font-style: italic; padding-bottom: 0.5rem">"Mie calculation of electromagnetic near-field
  19. for a multilayered sphere"</div>
  20. Konstantin Ladutenko, Umapada Pal, Antonio Rivera, Ovidio Peña-Rodríguez<br>
  21. <span style="font-weight: bold">Comp. Phys. Comm., vol. 214, pp. 225–230, 2017</span>
  22. </article>
  23. </div>
  24. </b-modal>
  25. </section>
  26. <section>
  27. <div class="field is-horizontal">
  28. <div class="field-label is-normal">
  29. <label class="label">Units</label>
  30. </div>
  31. <div class="field-body">
  32. <b-select v-model="units">
  33. <option units="nm">nm</option>
  34. <option units="mkm">mkm</option>
  35. <option units="mm">mm</option>
  36. <option units="cm">cm</option>
  37. <option units="m">m</option>
  38. <option units="km">km</option>
  39. </b-select>
  40. </div>
  41. </div>
  42. <div class="field is-horizontal">
  43. <div class="field-label is-normal">
  44. <label class="label">Wavelength</label>
  45. </div>
  46. <div class="field-body">
  47. <div class="field is-grouped is-grouped-multiline">
  48. <input-with-units title="from" v-bind:units="units"
  49. v-bind:value="simulationSetup.fromWL"
  50. @newdata="simulationSetup.fromWL=$event"></input-with-units>
  51. <input-with-units title="to" v-bind:units="units"
  52. v-bind:value="simulationSetup.toWL"
  53. @newdata="simulationSetup.toWL=$event"></input-with-units>
  54. <input-with-units title="step" v-bind:units="units"
  55. v-bind:value="simulationSetup.stepWL"
  56. @newdata="simulationSetup.stepWL=$event"></input-with-units>
  57. </div>
  58. </div>
  59. </div>
  60. <div class="field is-horizontal">
  61. <div class="field-label is-normal">
  62. <label class="label">Spherical particle</label>
  63. </div>
  64. <div class="field-body">
  65. <div class="field is-grouped is-grouped-multiline">
  66. <input-with-units title="R" v-bind:units="units"
  67. v-bind:value="simulationSetup.R"
  68. @newdata="simulationSetup.R=$event"></input-with-units>
  69. <input-with-units title="Re(n)" units=""
  70. v-bind:value="simulationSetup.reN"
  71. @newdata="simulationSetup.reN=$event"></input-with-units>
  72. <input-with-units title="Im(n)" units=""
  73. v-bind:value="simulationSetup.imN"
  74. @newdata="simulationSetup.imN=$event"></input-with-units>
  75. </div>
  76. </div>
  77. </div>
  78. <div class="field is-horizontal">
  79. <div class="field-label is-normal">
  80. <label class="label">Modes to plot</label>
  81. </div>
  82. <div class="field-body">
  83. <b-input v-model="simulationSetup.total_mode_n" type='number' min=1 style="width:7rem"></b-input>
  84. </div>
  85. </div>
  86. <div>From {{simulationSetup.fromWL}} to {{simulationSetup.toWL}} {{ units }}
  87. <br>
  88. Changes:{{ changes }}
  89. </div>
  90. <!-- <div class="chart-container">-->
  91. <!-- <reactive-chart :chart="chart"></reactive-chart>-->
  92. <!-- </div>-->
  93. </section>
  94. </div>
  95. </template>
  96. <script>
  97. import InputWithUnits from "./components/InputWithUnits.vue";
  98. import fibonacci from './fibonacci.js';
  99. const module = fibonacci({
  100. locateFile(path) {
  101. console.log(path);
  102. return path;
  103. }
  104. });
  105. module.onRuntimeInitialized = () => {
  106. console.log(module._fib(12));
  107. };
  108. // // const moduleFib =
  109. // fetch('fibonacci.wasm').then(response =>
  110. // response.arrayBuffer()
  111. // ).then(bytes =>
  112. // WebAssembly.instantiate(bytes)
  113. //
  114. // ).then(obj => {
  115. // console.log(obj._fib(12));
  116. // // return obj
  117. // }
  118. // );
  119. // alert("test")
  120. // moduleFib.onRuntimeInitialized = () => {
  121. // alert(moduleFib._fib(12));
  122. // };
  123. // // TODO: uncomment
  124. // import nmiejs from './nmiejs.js';
  125. // import nmiejsModule from './nmiejs.wasm';
  126. // const module = nmiejs({
  127. // locateFile(path) {
  128. // if(path.endsWith('.wasm')) {
  129. // return nmiejsModule;
  130. // }
  131. // return path;
  132. // }
  133. // });
  134. //
  135. // nmiejs().then(function(module) {
  136. // // this is reached when everything is ready, and you can call methods on Module
  137. // });
  138. // let getMethods = (obj) => Object.getOwnPropertyNames(obj);
  139. // // TODO: end uncomment block
  140. //
  141. // const nmie = new module.nmie();
  142. // module.onRuntimeInitialized = () => {
  143. // nmie.ClearTarget();
  144. // let R = 100.0;
  145. // let reN = 4.0;
  146. // let imN = 0.01;
  147. // nmie.AddTargetLayerReIm(R, reN, imN)
  148. // nmie.SetModeNmaxAndType(-1, -1);
  149. // let WL = 800;
  150. // nmie.SetWavelength(WL);
  151. // nmie.RunMieCalculation();
  152. // // Qsca.push();
  153. // // Qabs.push(nmie.GetQabs());
  154. //
  155. // console.log(nmie.GetQsca());
  156. // };
  157. // console.log(Object.keys(nmie));
  158. //import ReactiveChart from "./components/ReactiveChart.vue";
  159. // import VueWasm from 'vue-wasm';
  160. // import nmie from './assets/nmie.wasm';
  161. // VueWasm(Vue, { modules: { arithmetic: arithmeticModule } });
  162. const range = (start, stop, step = 1) =>
  163. Array(Math.ceil((stop - start) / step)).fill(start).map((x, y) => x + y * step);
  164. export default {
  165. name: 'app',
  166. components: {
  167. InputWithUnits,
  168. // ReactiveChart
  169. // HelloWorld
  170. },
  171. data() {
  172. return {
  173. window: {
  174. width: 0,
  175. height: 0
  176. },
  177. // on change of initial value for __ units __
  178. // remember to update this.chart.layout.xaxis.title
  179. units: 'nm',
  180. simulationRuntime: {
  181. mode_n : [],
  182. mode_types: range(0,2),
  183. mode_names: ['E','H'],
  184. WLs: [],
  185. Qsca: [],
  186. Qabs: [],
  187. Qsca_n: [[],[]],
  188. Qabs_n: [[],[]],
  189. layout: {},
  190. trace1: {},
  191. trace2: {}
  192. },
  193. simulationSetup: {
  194. stepWL: 0.5,
  195. fromWL: 300.0,
  196. toWL: 1000.0,
  197. R: 100.0,
  198. reN: 4.0,
  199. imN: 0.01,
  200. total_mode_n:4
  201. },
  202. changes: 0,
  203. isShowInfo: false,
  204. chart: {
  205. uuid: "123",
  206. traces: [
  207. {
  208. y: [],
  209. line: {
  210. color: "#5e9e7e",
  211. width: 4,
  212. shape: "line"
  213. }
  214. }
  215. ],
  216. layout: {
  217. title:'reactive charts',
  218. xaxis: {
  219. // initial value should be same as in units
  220. title: 'Wavelength, nm'
  221. },
  222. yaxis: {
  223. title: 'yaxis title'
  224. }
  225. }
  226. }
  227. };
  228. },
  229. created() {
  230. window.addEventListener('resize', this.handleResize)
  231. this.handleResize();
  232. },
  233. destroyed() {
  234. window.removeEventListener('resize', this.handleResize)
  235. },
  236. mounted(){ this.runMie();},
  237. watch: {
  238. simulationSetup: {
  239. handler: function () {
  240. this.runMie();
  241. },
  242. deep: true
  243. },
  244. units:{
  245. handler: function () {
  246. this.chart.layout.xaxis.title = "Wavelength, "+this.units;
  247. }
  248. }
  249. },
  250. methods: {
  251. handleResize() {
  252. this.window.width = window.innerWidth;
  253. this.window.height = window.innerHeight;
  254. },
  255. runMie(){
  256. // let t0 = performance.now();
  257. // let fromWL = parseFloat(this.simulationSetup.fromWL);
  258. // let toWL = parseFloat(this.simulationSetup.toWL);
  259. // let stepWL = parseFloat(this.simulationSetup.stepWL);
  260. // let R = parseFloat(this.simulationSetup.R);
  261. // let reN = parseFloat(this.simulationSetup.reN);
  262. // let imN = parseFloat(this.simulationSetup.imN);
  263. // this.simulationRuntime.Qsca = [], this.simulationRuntime.Qabs = [];
  264. // this.simulationRuntime.Qsca_n = [[],[]], this.simulationRuntime.Qabs_n = [[],[]];
  265. // nmie.ClearTarget();
  266. // nmie.AddTargetLayerReIm(R, reN, imN)
  267. this.changes++;
  268. }
  269. },
  270. }
  271. </script>
  272. <style>
  273. #app {
  274. font-family: 'Avenir', Helvetica, Arial, sans-serif;
  275. -webkit-font-smoothing: antialiased;
  276. -moz-osx-font-smoothing: grayscale;
  277. /*text-align: center;*/
  278. /*color: #2c3e50;*/
  279. /*margin-top: 60px;*/
  280. }
  281. </style>