Skip to content

Commit

Permalink
fix: Bug with AWG display and electron velocity
Browse files Browse the repository at this point in the history
  • Loading branch information
ElrohirGT committed Nov 9, 2023
1 parent d95be9b commit ea9a84b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
diameterUnits
} from './lib/WireMaterials'
import { SimulationEngine } from './lib/SimulationEngine'
import { AWG_TO_METERS } from './lib/Utils'
import { AWGToMeters } from './lib/Utils'
import NoneLogo from './assets/none.jpg'
import AluminumLogo from './assets/aluminumLogo.png'
import CopperLogo from './assets/copperLogo.png'
Expand Down Expand Up @@ -202,10 +202,10 @@ const flickWalkingSimulation = (value) => {
}}{{ context.length.unit }}, Diameter:
{{
(context.diameter.unit === diameterUnits.AWG
? context.diameter.value * AWG_TO_METERS
? AWGToMeters(context.diameter.value)
: context.diameter.value
).toExponential(3)
}}m
}}mm²
</p>
<simulation-display
:sim-info="engine"
Expand Down
16 changes: 8 additions & 8 deletions src/components/organisms/simulationDisplay.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<template>
<div>
<svg class="oval" viewBox="0 0 30 90" width="8%" height="100%">
<ellipse cx="15" cy="45" rx="14" ry="63" stroke-width="1"/>
</svg>
<ellipse cx="15" cy="45" rx="14" ry="63" stroke-width="1" />
</svg>
<canvas v-bind:id="ELEMENT_ID"></canvas>
<svg class="oval" viewBox="0 0 30 90" width="8%" height="100%">
<ellipse cx="15" cy="45" rx="14" ry="63" stroke-width="1"/>
</svg>
<ellipse cx="15" cy="45" rx="14" ry="63" stroke-width="1" />
</svg>
</div>
</template>

Expand All @@ -23,7 +23,8 @@ import { WIRE_MATERIALS } from '../../lib/WireMaterials'
const ELEMENT_ID = 'simulationContainer'
const ELECTRON_RADIUS = 5
const VELOCITY_FACTOR = 1e12
const VELOCITY_FACTOR = 1e10
const ELECTRON_COUNT_FACTOR = 1e-21
const props = defineProps({
simInfo: {
Expand Down Expand Up @@ -94,7 +95,7 @@ const setupMultipleElectronsSimulation = () => {
const CANVAS_WIDTH = elem.clientWidth
const CANVAS_HEIGHT = elem.clientHeight
const ELECTRONS_COUNT = props.simInfo.totalElectrons * 1e-28
const ELECTRONS_COUNT = props.simInfo.totalElectrons * ELECTRON_COUNT_FACTOR
console.log('Electrons count', ELECTRONS_COUNT, props.simInfo.totalElectrons)
let electrons = []
Expand Down Expand Up @@ -280,7 +281,6 @@ const setupInitialConditions = () => {
</script>

<style scoped>
.oval {
position: absolute;
transform: translateX(-50%);
Expand All @@ -291,7 +291,7 @@ ellipse {
stroke: white;
}
div{
div {
width: 100%;
position: relative;
}
Expand Down
12 changes: 4 additions & 8 deletions src/lib/SimulationEngine.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SimulationContext } from './SimulationContext'
import { WIRE_MATERIALS, diameterUnits } from './WireMaterials'
import { AWG_TO_METERS, ELECTRON_CHARGE } from '../lib/Utils'
import { ELECTRON_CHARGE, AWGToArea } from '../lib/Utils'

export const SIMULATION_TYPES = {
MULTIPLE_ELECTRONS: false,
Expand Down Expand Up @@ -52,7 +52,7 @@ export class SimulationEngine {

calculateResistence(context) {
let wireTransversalArea = this.calculateTransversalArea(context)
console.log(wireTransversalArea )
console.log(wireTransversalArea)
return (
(context.material.resistivity.value * context.length.value) /
wireTransversalArea
Expand Down Expand Up @@ -90,17 +90,13 @@ export class SimulationEngine {
const MILI_TO_METERS = 1 / 1000
let wireUnit = context.diameter.unit
let wireValue = context.diameter.value
console.log("Wire diameter" + wireValue);
console.log('Wire diameter' + wireValue)
switch (wireUnit) {
case diameterUnits.MILIMETERS:
let diameter = wireValue * MILI_TO_METERS
return (Math.PI * Math.pow(diameter, 2)) / 4
case diameterUnits.AWG:
return (
0.012668 *
Math.pow(92, (36 - wireValue) / 19.5) *
Math(MILI_TO_METERS, 2)
)
return AWGToArea(wireValue)
}
}
}
15 changes: 15 additions & 0 deletions src/lib/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,18 @@ export const getRandomElement = (list) =>
*/
export const isInBetween = (n, min, max, exclusive = false) =>
exclusive ? n > min && n < max : n >= min && n <= max

/**
* Calculates the area that the given AWG measurement represents.
* @param {Number} awg The diameter of the cable in AWG
* @returns {Number} The AWG measurement in meters^2.
*/
export const AWGToArea = (awg) =>
0.012668 * Math.pow(92, (36 - awg) / 19.5) * Math.pow(1e-3, 2)

/**
* Calculates the meters that the given AWG measurement represents.
* @param {Number} awg The diameter of the cable in AWG
* @returns {Number} The AWG measurement in meters.
*/
export const AWGToMeters = (awg) => 0.127 * Math.pow(92, (36 - awg) / 39) * 1e-3

0 comments on commit ea9a84b

Please sign in to comment.