Bläddra i källkod

initial near field auto-refine

Konstantin Ladutenko 3 år sedan
förälder
incheckning
68cf98c056

+ 9 - 6
guiapp/src/components/nearfield/GetNearFieldSettings.vue

@@ -76,7 +76,7 @@
 </template>
 
 <script lang="ts">
-import { defineComponent, computed, watch } from 'vue';
+import { defineComponent, computed } from 'vue';
 import { useStore } from 'src/store';
 import InputWithUnits from 'components/InputWithUnits.vue';
 import { flexRowTitleStyle } from 'components/config';
@@ -124,11 +124,14 @@ export default defineComponent({
         ),
     });
 
-    watch(plotXSideResolution, () => {
-      $store.commit(
-        'simulationSetup/setNearFieldPlotYSideResolution',
-        plotXSideResolution.value
-      );
+    const plotYSideResolution = computed({
+      get: () =>
+        $store.state.simulationSetup.gui.nearFieldSetup.plotYSideResolution,
+      set: (val) =>
+        $store.commit(
+          'simulationSetup/setNearFieldPlotYSideResolution',
+          Math.floor(val)
+        ),
     });
 
     return {

+ 10 - 4
guiapp/src/components/nearfield/PlotNearField.vue

@@ -18,6 +18,8 @@ import {
   toUnits,
   getMaxFromHeatmap,
   getMinFromHeatmap,
+  arrayMin,
+  arrayMax,
   limitMap,
   fromUnits,
 } from 'components/utils';
@@ -159,8 +161,14 @@ export default defineComponent({
       };
       nearFieldPlot.data.push({ ...xy.value, ...heatMapSettings });
 
-      if (nearFieldPlot.layout.shapes) {
-        nearFieldPlot.layout.shapes.length = 0;
+      const isPlotShapes =
+        arrayMin(xy.value.x) < -totalR.value &&
+        arrayMax(xy.value.x) > totalR.value &&
+        arrayMin(xy.value.y) < -totalR.value &&
+        arrayMax(xy.value.y) > totalR.value;
+
+      if (nearFieldPlot.layout.shapes) nearFieldPlot.layout.shapes.length = 0;
+      if (nearFieldPlot.layout.shapes && isPlotShapes) {
         let r = 0;
         for (let widthLayer of layerWidths.value) {
           r += widthLayer;
@@ -215,8 +223,6 @@ export default defineComponent({
             toY: 0,
           });
         }
-        console.log(data['xaxis.range[0]']);
-        console.log($store.state.guiRuntime.nearFieldZoom);
       });
     }
 

+ 137 - 3
guiapp/src/components/nearfield/RunSimulationNearField.vue

@@ -38,13 +38,41 @@
       </div>
     </div>
   </div>
+  <div class="row items-baseline">
+    <div
+      class="col-xs-12 col-sm-auto text-weight-bold text-center q-px-md q-py-sm"
+    >
+      <q-btn
+        :loading="isRunning"
+        :disable="isRunning || !isNmieLoaded"
+        color="primary"
+        no-caps
+        :label="isNmieLoaded ? 'Refine on zoom' : 'Loading...'"
+        @click="refineOnZoom"
+      >
+        <template #loading>
+          <q-spinner-gears />
+        </template>
+      </q-btn>
+    </div>
+    <div class="col-xs-grow col-sm q-px-xs">
+      <div class="row justify-xs-center justify-sm-start items-baseline">
+        <div class="col-auto">
+          <q-checkbox v-model="isAutoRefineNearField" size="sm">
+            auto refine
+          </q-checkbox>
+        </div>
+      </div>
+    </div>
+  </div>
 </template>
 
 <script lang="ts">
-import { computed, defineComponent, nextTick } from 'vue';
+import { computed, defineComponent, nextTick, watch } from 'vue';
 import { useStore } from 'src/store';
-import { cloneDeep } from 'lodash';
+import { cloneDeep, floor } from 'lodash';
 import SaveSimulationNearField from 'components/nearfield/SaveSimulationNearField.vue';
+import { nearFieldPlane } from 'src/store/simulation-setup/state';
 
 export default defineComponent({
   name: 'RunSimulationNearField',
@@ -52,6 +80,11 @@ export default defineComponent({
   setup() {
     const $store = useStore();
 
+    const isAutoRefineNearField = computed({
+      get: () => $store.state.guiRuntime.isAutoRefineNearField,
+      set: (val) => $store.commit('guiRuntime/setIsAutoRefineNearField', val),
+    });
+
     const isRunning = computed({
       get: () => $store.state.simulationSetup.nmies.nearField.isNmieRunning,
       set: (val) => {
@@ -72,6 +105,11 @@ export default defineComponent({
     //---------------------  Main  --------------------------------------------//
     //-------------------------------------------------------------------------//
     function runNearFieldSimulation() {
+      if (!isNmieLoaded.value) {
+        console.log('Nmie was not loaded yet');
+        return;
+      }
+
       if (isRunning.value) {
         console.log('Some Nmie is already running!');
         return;
@@ -154,7 +192,103 @@ export default defineComponent({
 
     runNearFieldSimulation();
 
-    return { isRunning, isNmieLoaded, runNearFieldSimulation };
+    const layerWidths = computed(() =>
+      $store.state.simulationSetup.current.layers.map((x) => x.layerWidth)
+    );
+    const totalR = computed(() => layerWidths.value.reduce((a, b) => a + b, 0));
+    const nearFieldZoom = computed(() => $store.state.guiRuntime.nearFieldZoom);
+
+    const crossSection = computed(
+      () => $store.state.simulationSetup.current.nearFieldSetup.crossSection
+    );
+    const atX = computed(
+      () =>
+        (nearFieldZoom.value.fromX + nearFieldZoom.value.toX) /
+        2.0 /
+        totalR.value
+    );
+    const atY = computed(
+      () =>
+        (nearFieldZoom.value.fromY + nearFieldZoom.value.toY) /
+        2.0 /
+        totalR.value
+    );
+    const sideX = computed(
+      () => (nearFieldZoom.value.toX - nearFieldZoom.value.fromX) / totalR.value
+    );
+    const sideY = computed(
+      () => (nearFieldZoom.value.toY - nearFieldZoom.value.fromY) / totalR.value
+    );
+
+    const plotXSideResolutionGUI = computed(
+      () => $store.state.simulationSetup.gui.nearFieldSetup.plotXSideResolution
+    );
+    const plotYSideResolutionGUI = computed(
+      () => $store.state.simulationSetup.gui.nearFieldSetup.plotYSideResolution
+    );
+    const totalPoints = computed(
+      () => plotXSideResolutionGUI.value * plotYSideResolutionGUI.value
+    );
+
+    function refineOnZoom() {
+      if (sideX.value == 0 || sideY.value == 0) return;
+      $store.commit(
+        'simulationSetup/setNearFieldRelativePlotSize',
+        sideX.value / 2.0
+      );
+      $store.commit(
+        'simulationSetup/setNearFieldPlotXSideResolution',
+        floor(Math.sqrt((totalPoints.value * sideX.value) / sideY.value))
+      );
+      $store.commit(
+        'simulationSetup/setNearFieldPlotYSideResolution',
+        floor(Math.sqrt((totalPoints.value * sideY.value) / sideX.value))
+      );
+      console.log(
+        floor(Math.sqrt((totalPoints.value * sideX.value) / sideY.value)),
+        floor(Math.sqrt((totalPoints.value * sideY.value) / sideX.value))
+      );
+      if (crossSection.value == nearFieldPlane.Ek) {
+        $store.commit('simulationSetup/setNearFieldAtRelativeZ0', atX.value);
+        $store.commit('simulationSetup/setNearFieldAtRelativeX0', atY.value);
+      }
+      if (crossSection.value == nearFieldPlane.Hk) {
+        $store.commit('simulationSetup/setNearFieldAtRelativeZ0', atX.value);
+        $store.commit('simulationSetup/setNearFieldAtRelativeY0', atY.value);
+      }
+      if (crossSection.value == nearFieldPlane.EH) {
+        $store.commit('simulationSetup/setNearFieldAtRelativeY0', atX.value);
+        $store.commit('simulationSetup/setNearFieldAtRelativeX0', atY.value);
+      }
+      runNearFieldSimulation();
+    }
+
+    watch([atX, atY, sideX, sideY], () => {
+      if (!isAutoRefineNearField.value) return;
+      console.log(nearFieldZoom.value);
+      refineOnZoom();
+    });
+
+    let count = 0;
+    watch([plotXSideResolutionGUI, plotYSideResolutionGUI], () => {
+      console.log(plotXSideResolutionGUI.value, plotYSideResolutionGUI.value);
+      if (
+        plotYSideResolutionGUI.value * plotXSideResolutionGUI.value >
+          150 * 150 &&
+        count == 0
+      ) {
+        isAutoRefineNearField.value = false;
+        count = 1;
+      }
+    });
+
+    return {
+      isRunning,
+      isNmieLoaded,
+      runNearFieldSimulation,
+      refineOnZoom,
+      isAutoRefineNearField,
+    };
   },
 });
 </script>

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

@@ -6,6 +6,28 @@ export function limitMap(arr: Float64Array, minVal: number, maxVal: number) {
 
 // According to https://stackoverflow.com/questions/1669190/find-the-min-max-element-of-an-array-in-javascript
 // getting max and min element is non trivial for large arrays (e.g. 512x512 points heatmap)
+export function arrayMin(arr: number[]) {
+  let len = arr.length,
+    min = Infinity;
+  while (len--) {
+    if (arr[len] < min) {
+      min = arr[len];
+    }
+  }
+  return min;
+}
+
+export function arrayMax(arr: number[]) {
+  let len = arr.length,
+    max = -Infinity;
+  while (len--) {
+    if (arr[len] > max) {
+      max = arr[len];
+    }
+  }
+  return max;
+}
+
 export function getMaxFromHeatmap(val: Float64Array | undefined) {
   let max = -Infinity;
   if (!val) return max;

+ 3 - 0
guiapp/src/store/gui-runtime/mutations.ts

@@ -18,6 +18,9 @@ const mutation: MutationTree<grsi> = {
   setIsSaveWithPythonScript(state: grsi, val: boolean) {
     state.isSaveWithPythonScript = val;
   },
+  setIsAutoRefineNearField(state: grsi, val: boolean) {
+    state.isAutoRefineNearField = val;
+  },
   setIsShowingHelpForInputWithUnits(state: grsi, val: boolean) {
     state.isShowingHelpForInputWithUnits = val;
   },

+ 2 - 0
guiapp/src/store/gui-runtime/state.ts

@@ -11,6 +11,7 @@ export interface guiRuntimeStateInterface {
   safeFromWL: number;
   safeToWL: number;
   isSaveWithPythonScript: boolean;
+  isAutoRefineNearField: boolean;
   nearFieldZoom: { fromX: number; toX: number; fromY: number; toY: number };
 }
 
@@ -24,6 +25,7 @@ function state(): guiRuntimeStateInterface {
     safeToWL: 1e300,
     isSaveWithPythonScript: true,
     nearFieldZoom: { fromX: 0, toX: 1, fromY: 0, toY: 1 },
+    isAutoRefineNearField: true,
     activatedMaterials: [
       // 'PEC',
       {