App.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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 ReactiveChart from "./components/ReactiveChart.vue";
  99. // You should put *.wasm to public and *.js to src folder
  100. // To compile fibbonacci example use
  101. // 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
  102. // for and example from https://gist.github.com/ashleygwilliams/32c31a3f5b8c87bf2894108b3534ee4f
  103. // import fibonacci from './fibonacci.js';
  104. // const module = fibonacci({
  105. // locateFile(path) {
  106. // console.log(path);
  107. // return path;
  108. // }
  109. // });
  110. // module.onRuntimeInitialized = () => {
  111. // console.log(module._fib(12));
  112. // };
  113. // // Test the size of wasm file
  114. // fetch('fibonacci.wasm'
  115. // ).then(response =>
  116. // response.arrayBuffer()
  117. // ).then(bytes =>
  118. // console.log(bytes)
  119. // );
  120. import nmiejs from './nmiejs.js';
  121. const module = nmiejs({
  122. locateFile(path) {
  123. console.log(path);
  124. return path;
  125. }
  126. });
  127. // Test nmiejs if working
  128. module.onRuntimeInitialized = () => {
  129. const nmie = new module.nmie();
  130. nmie.ClearTarget();
  131. let R = 100.0;
  132. let reN = 4.0;
  133. let imN = 0.01;
  134. nmie.AddTargetLayerReIm(R, reN, imN)
  135. nmie.SetModeNmaxAndType(-1, -1);
  136. let WL = 800;
  137. nmie.SetWavelength(WL);
  138. nmie.RunMieCalculation();
  139. console.log(nmie.GetQsca());
  140. }
  141. const range = (start, stop, step = 1) =>
  142. Array(Math.ceil((stop - start) / step)).fill(start).map((x, y) => x + y * step);
  143. export default {
  144. name: 'app',
  145. components: {
  146. InputWithUnits,
  147. // ReactiveChart
  148. // HelloWorld
  149. },
  150. data() {
  151. return {
  152. window: {
  153. width: 0,
  154. height: 0
  155. },
  156. // on change of initial value for __ units __
  157. // remember to update this.chart.layout.xaxis.title
  158. units: 'nm',
  159. simulationRuntime: {
  160. mode_n : [],
  161. mode_types: range(0,2),
  162. mode_names: ['E','H'],
  163. WLs: [],
  164. Qsca: [],
  165. Qabs: [],
  166. Qsca_n: [[],[]],
  167. Qabs_n: [[],[]],
  168. layout: {},
  169. trace1: {},
  170. trace2: {}
  171. },
  172. simulationSetup: {
  173. stepWL: 0.5,
  174. fromWL: 300.0,
  175. toWL: 1000.0,
  176. R: 100.0,
  177. reN: 4.0,
  178. imN: 0.01,
  179. total_mode_n:4
  180. },
  181. changes: 0,
  182. isShowInfo: false,
  183. chart: {
  184. uuid: "123",
  185. traces: [
  186. {
  187. y: [],
  188. line: {
  189. color: "#5e9e7e",
  190. width: 4,
  191. shape: "line"
  192. }
  193. }
  194. ],
  195. layout: {
  196. title:'reactive charts',
  197. xaxis: {
  198. // initial value should be same as in units
  199. title: 'Wavelength, nm'
  200. },
  201. yaxis: {
  202. title: 'yaxis title'
  203. }
  204. }
  205. }
  206. };
  207. },
  208. created() {
  209. window.addEventListener('resize', this.handleResize)
  210. this.handleResize();
  211. },
  212. destroyed() {
  213. window.removeEventListener('resize', this.handleResize)
  214. },
  215. mounted(){ this.runMie();},
  216. watch: {
  217. simulationSetup: {
  218. handler: function () {
  219. this.runMie();
  220. },
  221. deep: true
  222. },
  223. units:{
  224. handler: function () {
  225. this.chart.layout.xaxis.title = "Wavelength, "+this.units;
  226. }
  227. }
  228. },
  229. methods: {
  230. handleResize() {
  231. this.window.width = window.innerWidth;
  232. this.window.height = window.innerHeight;
  233. },
  234. runMie(){
  235. // let t0 = performance.now();
  236. // let fromWL = parseFloat(this.simulationSetup.fromWL);
  237. // let toWL = parseFloat(this.simulationSetup.toWL);
  238. // let stepWL = parseFloat(this.simulationSetup.stepWL);
  239. // let R = parseFloat(this.simulationSetup.R);
  240. // let reN = parseFloat(this.simulationSetup.reN);
  241. // let imN = parseFloat(this.simulationSetup.imN);
  242. // this.simulationRuntime.Qsca = [], this.simulationRuntime.Qabs = [];
  243. // this.simulationRuntime.Qsca_n = [[],[]], this.simulationRuntime.Qabs_n = [[],[]];
  244. // nmie.ClearTarget();
  245. // nmie.AddTargetLayerReIm(R, reN, imN)
  246. this.changes++;
  247. }
  248. },
  249. }
  250. </script>
  251. <style>
  252. #app {
  253. font-family: 'Avenir', Helvetica, Arial, sans-serif;
  254. -webkit-font-smoothing: antialiased;
  255. -moz-osx-font-smoothing: grayscale;
  256. /*text-align: center;*/
  257. /*color: #2c3e50;*/
  258. /*margin-top: 60px;*/
  259. }
  260. </style>