Pārlūkot izejas kodu

measure and output of spectrum simulation time

Konstantin Ladutenko 3 gadi atpakaļ
vecāks
revīzija
4cbd80faa1

+ 1 - 1
guiapp/src/App.vue

@@ -9,7 +9,7 @@ export default defineComponent({
   name: 'App',
   setup(){
     const $store = useStore()
-    $store.dispatch('simulationSetup/loadScattnlay')
+    void (async () => $store.dispatch('simulationSetup/loadScattnlay'))()
 
   }
 })

+ 23 - 24
guiapp/src/components/RunSimulationSpectrum.vue

@@ -6,7 +6,7 @@
                color="primary"
                no-caps
                :label="isNmieLoaded ? 'Run simulation' : 'Loading...'"
-               @click="runSimulation"
+               @click="runSpectrumSimulation"
       />
     </div>
     <div class="col-xs-grow col-sm q-px-xs">
@@ -27,7 +27,7 @@ import {
   computed,
   } from 'vue'
 import { useStore } from 'src/store'
-import { flexRowTitleStyle } from 'components/utils'
+import { range, rangeInt } from 'components/utils'
 
 export default defineComponent({
   name: 'RunSimulationSpectrum',
@@ -35,37 +35,36 @@ export default defineComponent({
   setup() {
     const $store = useStore()
 
-
-    const numberOfModesToPlot = computed({
-      get: () => $store.state.simulationSetup.gui.numberOfModesToPlot,
-      set: val => {
-        const intVal = parseInt(val.toString())
-        if (!isNaN(intVal)) $store.commit('simulationSetup/setNumberOfModesToPlot', intVal)
-      }
-    })
-
-    const isNmieLoaded = computed(()=>{ return $store.state.simulationSetup.isNmieLoaded })
     const isRunning = computed({
       get: ()=> $store.state.simulationSetup.isNmieRunning,
       set: val => {
-        val ? $store.commit('simulationSetup/markNmieAsRunning') : $store.commit('simulationSetup/markNmieAsFinished')
+        val ? $store.commit('simulationSetup/markNmieAsStarted') : $store.commit('simulationSetup/markNmieAsFinished')
       }
     })
 
+    const isNmieLoaded = computed(()=>{ return $store.state.simulationSetup.isNmieLoaded })
+
+    return { isRunning, isNmieLoaded,
+      //-----------------------------------------------------------------------//
+      //-------------------  Main  --------------------------------------------//
+      //-----------------------------------------------------------------------//
+      runSpectrumSimulation() {
+        isRunning.value = true
+        $store.commit('simulationSetup/copySetupFromGuiToCurrent')
 
-    function runSimulation() {
-      isRunning.value = true
-// simulate a delay
-      setTimeout(() => {
-        // we're done, we reset loading state
-        isRunning.value = false
-      }, 3000)
-    }
+        const host = $store.state.simulationSetup.current.hostIndex
+
+        const fromWL = $store.state.simulationSetup.current.fromWL
+        const toWL = $store.state.simulationSetup.current.toWL
+        const pointsWL = $store.state.simulationSetup.current.pointsWL
+        const stepWL = (toWL-fromWL)/(pointsWL-1)
+        let WLs = range(fromWL, toWL, stepWL);
 
-    return { flexRowTitleStyle,
-      numberOfModesToPlot, runSimulation,
-      isRunning, isNmieLoaded
+        const total_mode_n = $store.state.simulationSetup.current.numberOfModesToPlot
+
+        isRunning.value = false
       }
+    }
   },
 })
 </script>

+ 9 - 0
guiapp/src/components/utils.ts

@@ -1,4 +1,13 @@
 export const flexRowTitleStyle='width:10em; margin: auto;'
+
+export function range(start:number, stop:number, step = 1) {
+    return Array(Math.ceil((stop - start) / step)).fill(start).map((x:number, y:number) => x + y * step)
+}
+
+export function rangeInt(size:number, startAt = 0) {
+    return [...Array(size).keys()].map(i => i + startAt)
+}
+
 // convert value to nm from some units
 export function fromUnits(fromU:string, val:number):number {
     if (fromU === 'nm') return val

+ 5 - 56
guiapp/src/layouts/MainLayout.vue

@@ -56,18 +56,13 @@
           <q-item-section> <q-item-label>Support</q-item-label>
             <q-item-label caption> Requires a GitHub account</q-item-label></q-item-section>
         </q-item>
-<!--        <q-item-label-->
-<!--          header-->
-<!--        >-->
-<!--          Essential Links-->
-<!--        </q-item-label>-->
+        <q-separator inset spaced/>
 
-<!--        <EssentialLink-->
-<!--          v-for="link in essentialLinks"-->
-<!--          :key="link.title"-->
-<!--          v-bind="link"-->
-<!--        />-->
+        <q-item class="q-mt-auto">
+          Last simulation took {{$store.state.simulationSetup.nmieTotalRunTime.toFixed(2)}} s.
+        </q-item>
       </q-list>
+
     </q-drawer>
 
     <q-page-container>
@@ -77,52 +72,6 @@
 </template>
 
 <script lang="ts">
-// import EssentialLink from 'components/EssentialLink.vue'
-
-// const linksList = [
-//   {
-//     title: 'Docs',
-//     caption: 'quasar.dev',
-//     icon: 'school',
-//     link: 'https://quasar.dev'
-//   },
-//   {
-//     title: 'Github',
-//     caption: 'github.com/quasarframework',
-//     icon: 'code',
-//     link: 'https://github.com/quasarframework'
-//   },
-//   {
-//     title: 'Discord Chat Channel',
-//     caption: 'chat.quasar.dev',
-//     icon: 'chat',
-//     link: 'https://chat.quasar.dev'
-//   },
-//   {
-//     title: 'Forum',
-//     caption: 'forum.quasar.dev',
-//     icon: 'record_voice_over',
-//     link: 'https://forum.quasar.dev'
-//   },
-//   {
-//     title: 'Twitter',
-//     caption: '@quasarframework',
-//     icon: 'rss_feed',
-//     link: 'https://twitter.quasar.dev'
-//   },
-//   {
-//     title: 'Facebook',
-//     caption: '@QuasarFramework',
-//     icon: 'public',
-//     link: 'https://facebook.quasar.dev'
-//   },
-//   {
-//     title: 'Quasar Awesome',
-//     caption: 'Community Quasar projects',
-//     icon: 'favorite',
-//     link: 'https://awesome.quasar.dev'
-//   }
-// ];
 
 import { defineComponent, ref } from 'vue'
 

+ 1 - 1
guiapp/src/store/simulation-setup/actions.ts

@@ -16,7 +16,7 @@ const actions: ActionTree<simulationSetupStateInterface, StateInterface> = {
       // },3000)
     }
     if (state.nmie && !state.isNmieRunning) {
-      commit('markNmieAsRunning')
+      commit('markNmieAsStarted')
       state.nmie.ClearTarget()
       const R = 100.0
       const reN = 4.0

+ 13 - 2
guiapp/src/store/simulation-setup/mutations.ts

@@ -9,14 +9,24 @@ const mutation: MutationTree<sssi> = {
     state.nmie = markRaw(newVal)
   },
   markNmieAsLoaded  (state: sssi) {state.isNmieLoaded  = true },
-  markNmieAsRunning (state: sssi) {state.isNmieRunning = true },
-  markNmieAsFinished(state: sssi) {state.isNmieRunning = false},
+  markNmieAsStarted (state: sssi) {
+    state.isNmieRunning = true
+    state.nmieStartedTime = performance.now()
+  },
+  markNmieAsFinished(state: sssi) {
+    state.isNmieRunning = false
+    state.nmieTotalRunTime = (performance.now()-state.nmieStartedTime)/1000
+  },
 
   setCurrentState (state: sssi,
                    newVal: simulationSetup) {
     state.current = cloneDeep(newVal)
   },
 
+  copySetupFromGuiToCurrent (state: sssi) {
+    state.current = cloneDeep(state.gui)
+  },
+
   // Mutations for simulation setup as represented\set in GUI
   setGuiState (state: sssi,
                newVal: simulationSetup) {
@@ -30,6 +40,7 @@ const mutation: MutationTree<sssi> = {
   setFromWL    (state: sssi, val: number) {state.gui.fromWL    = val},
   setToWL      (state: sssi, val: number) {state.gui.toWL      = val},
   setPointsWL  (state: sssi, val: number) {state.gui.pointsWL  = val},
+  setCurrentWL (state: sssi, val: number) {state.gui.currentWL = val},
   setNumberOfModesToPlot  (state: sssi, val: number) {state.gui.numberOfModesToPlot  = val},
 
 };

+ 9 - 3
guiapp/src/store/simulation-setup/state.ts

@@ -12,7 +12,7 @@ export interface layer {
 
 export interface simulationSetup {
   hostIndex: number
-  fromWL: number; toWL:number; pointsWL:number
+  fromWL: number; toWL:number; pointsWL:number; currentWL:number
   layers: layer[]
   numberOfModesToPlot: number
 }
@@ -24,10 +24,12 @@ export interface simulationSetupStateInterface {
   nmie: import('src/nmiejs').nmie_class|undefined
   isNmieLoaded: boolean
   isNmieRunning: boolean
+  nmieStartedTime: number
+  nmieTotalRunTime: number
 }
 
 function setupFactory(hostIndex = 1,
-                      fromWL = 300, toWL=1000, pointsWL=101,
+                      fromWL = 300, toWL=1000, pointsWL=101, currentWL = 300,
                       layers = [
                         {layerWidth:100, n:4, k:0.01,
                           materialName:'nk-constant',
@@ -38,6 +40,7 @@ function setupFactory(hostIndex = 1,
                      ):simulationSetup {
   return {hostIndex:hostIndex,
     fromWL:fromWL, toWL:toWL, pointsWL:pointsWL,
+    currentWL:currentWL,
     layers: cloneDeep(layers),
     numberOfModesToPlot: numberOfModesToPlot,
   }
@@ -52,12 +55,15 @@ function state(): simulationSetupStateInterface {
   const nmie = undefined
   const isNmieLoaded = false
   const isNmieRunning = false
+  const nmieStartedTime = 0
+  const nmieTotalRunTime = 0
+
   return {
     library,
     gui, // simulation setup config as shown in GUI
     current, // simulation setup used for the latest simulation
     nmie,
-    isNmieLoaded, isNmieRunning
+    isNmieLoaded, isNmieRunning, nmieStartedTime, nmieTotalRunTime
   }
 };