كود لا ينسى

جذب قسم من الكود اهتمامي عندما كنت أقوم بمراجعة كود البرنامج بعد الانتهاء من محاكاة التأثير الكهروضوئي، فوقفت عليه لبعض الوقت وتأملت فيه. توقفت عن التفكير كمبرمج في تلك المرحلة وعدت إلى التفكير كفيزيائي. لقد أذهلني كيف يمكننا محاكاة الظواهر الفيزيائية ببضعة أسطر من التعليمات البرمجية. تُصوِّر هذه السطور قصة خلق وانعدام، حيث تصف إنشاء الفوتون، واختفائه اللاحق عندما يمتصه الإلكترون على سطح لوحة الكاثود، والمغادرة اللاحقة للإلكترون من الكاثود، وأخيرًا اختفاء الإلكترون عندما يصل إلى اللوحة الأخرى ويتم التقاطه.

إذا كانت لديك بعض مهارات البرمجة، يمكنك قراءة هذه القصة من خلال أسطر التعليمات البرمجية المبينة أدناه، أو يمكنك قراءتها في سطور التعليق (الأسطر المسبوقة بـ //).

function movePhotons(){
    i++;
    if (laserONFlag){
        var productionFactor = Math.ceil(1.5/ sim.calculation.getIntensity());
        if (i % productionFactor === 0){
            photon[++p] = new sim.lib.photon();
            // new photon is created
            photon[p].x = 40;
            photon[p].y = getRndInteger(-31, 31);
            // this is where the photon is created
            photons.addChild(photon[p]);
            // now the photon is ejected
            if (p > 10){p = 0;}
            Kmax = sim.calculation.getKmax(sim.currentElement) * 1.6e-19;
            // this is the maximum possible kinetic energy that the electron
            // that absorbs the photon may possess
            // and it depends on parameters contained in the class "Calculation"
            V0 = tubeLength * Math.sqrt(2 * Kmax / me) * 
            // this is the maximum possible initial velocity that an ejected electron can possess
            (sim.calculation.getLambda() < sim.calculation.getMaxLambda(sim.currentElement));
            // this is a condition: if the wavelength of the incident light beam is below the
            // threshold wavelength of the irradiated element, then an electron may be ejected,
            // otherwise, the energy of the incident photon is not enough for the electron to be
            // released 
            if (sim.calculation.calculateVoltageCoeff(sim.currentElement) === 1){
                v0 = V0;
                // this is when the photocurrent reaches a maximum value, called the saturation current
                // this happens when the potential of the anode plate is high enough
                // to pull all the released electrons and capture them
            } else {
                v0 = getRndNumber(0.7 * V0 , 1.01 * V0);
                // this allows for the fact that the electrons which absorb photons will be ejected
                // with kinetic energy of maximum value V0 that is calculated above (here the randomization
                // between 0.7 * V0 and 1.01 * V0 is not realistic but to allow an adequate visualization
                // for educational purpose only)
                // So probability plays a role here.
            }
            i = 0;
        }
    }
    for (p in photon){
        photon[p].x += 5;
        if (photon[p].x > (380 + photon[p].y * Math.tan(beamAngle))){
            // if a photon reaches the plate
            if (getRndNumber(0,1) > 0.5){
                // Another probabilistic factor here allows for the fact not all the photons hitting
                // the plate get caught and cause the ejection of electrons
                // So probability plays a role here too
                // Note that the speed of photons and electrons in the tube in this simulation and the
                // number of photons that cause ejection of electrons are not accurate but tuned to be
                // clearly visualized so that the learners understand the concept visually.
                electron[++m] = new sim.lib.electron();
                // the electron that absorbed the incident photon and
                // gained enough energy and got lucky to escape from the
                // surface of the plate..
                electron[m].x = -8;
                electron[m].y = photon[p].y / Math.cos(beamAngle);
                // ..starts from the surface of the plate..
                electron[m].alpha = 0.6;
                electron[m].v = v0;
                // ..with an initial speed previously calculated..
                electron[m].v0 = v0;
                electrons.addChild(electron[m]);
                // ..and hence flies away!
            }
            photons.removeChild(photon[p]);
            delete photon[p];
            // .. and don't forget that the incident photon vanished
            // since it is absorbed by the electron!
            if (p > 4){p = 0;}
        }
    }
}

function moveElectrons(){
    // Now the electron is flying
    for (m in electron){
        // for every electron which was released from the platee..
        a = (voltageONFlag) * e * sim.calculation.getVoltage() / (me * tubeLength);
        // ..this is its acceleration due to electrostatic force on it
        // caused by the potential difference between the cathode and the anode.
        // notice that when the power supply is off, the flag "voltageONFlag" is
        // false (false is equivalent to 0), so a = 0 (since there is no potential 
        // difference anymore), and hence, the electron is not accelerating 
        electron[m].v += 0.5 * a;
        // this is how much the speed of the electron is increasing (depending on a, the 
        // acceleration)
        // note that if a is zero, then the speed of the electron becomes constant
        electron[m].x -= 2.0e-9 * electron[m].v;
        // this is how fast the electron is moving (depending on the speed)
        // if the speed is constant, then the motion of the electron is uniform,
        // while if the speed is increasing, then the electron is accelerating
        // (remember that this happens when a potential difference is applied between the plates)
        if (electron[m].x < -440 || electron[m].x > -8){
            // if the electron reaches the anode plate
            electrons.removeChild(electron[m]);
            delete electron[m];
            // the electron disappears since it is being absorbed by the anode plate!
            if (m > 4){m = 0;}
        }
    }
}

Similar Posts

  • |

    انحفاظ الزخم الخطي

    لو تم إجراء هذه التجربة في ظروف يكون فيها صافي القوى الخارجية صفرًا على المدفع المُحمّل قبل وبعد إطلاق النار مباشرة (على سبيل المثال، عندما يكون وزن المدفع متوازناً مع رد الفعل العمودي للأرض)، فإن حسبنا عندئذٍ حاصل ضرب كتلة القذيفة بسرعتها المتجهة وحاصل ضرب كتلة المدفع بسرعته المتجهة قبل وبعد الإطلاق مباشرة، سنجد أنه قبل إطلاق النار كان كلاهما في حالة سكون، وبالتالي يكون الناتج صفرًا لكليهما، بينما نجد أن الناتجين، بعد إطلاق النار ذوا مقدار متساوٍ، ولكن باتجاهين متعاكسين.

  • |

    Free fall experiment

    This experiment demonstrates that in the absence of air resistance, two freely falling bodies released from the same height reach the ground simultaneously. Both objects gain the same speed during their fall, proving they experience the same acceleration – the acceleration due to gravity. The demonstration explains why we typically observe heavy objects falling faster than light objects due to air resistance effects.

  • |

    مبدأ ارخميدس

    توضح هذه التجربة مبدأ أرخميدس والطفو. عند وضع جسم في سائل، يزيح كمية من السائل تساوي كتلتها كتلة الجسم نفسه. كما أن حجم السائل المُزاح يساوي حجم الجزء المغمور من الجسم. عرض أساسي لمبادئ ميكانيكا الموائع والإزاحة.

  • |

    عزم الدوران

    يوضح هذا الدرس مفهوم عزم الدوران (عزم القوة) والتوازن الدوراني. تُحدث القوة تأثيراً دورانياً يعتمد على مقدار القوة والمسافة العمودية من نقطة المحور. عند التوازن، يساوي عزم الدوران في اتجاه عقارب الساعة عزم الدوران عكس عقارب الساعة. يتضمن المنشور معادلات حساب عزم الدوران للقوى العمودية والمائلة.

  • |

    Course: Crafting Effective Learning Assessments

    I created this course and published it on my Moodle platform. Each module is comprised of SCORM package and a quiz, with an unofficial completion certificate as a template that can be costumed to the specifications of your organization. The course is tracked, and you must successfully complete each chapter to unlock the next one. The course is fully learner-centered.

  • فكرة الأكوان اللامتناهية وما وراءها وفساد معاداة العقل السليم

    تحليل نقدي لفكرة الأكوان اللامتناهية المتوازية وما تستخدم له من محاولات لإنكار الحاجة إلى خالق. يناقش المقال فساد معاداة العقل السليم والأسس العقلية المنطقية التي بُني عليها علم الرياضيات والفيزياء. يوضح كيف تُستخدم فرضيات فيزيائية غير مثبتة كملجأ فكري، ويرد على من يخلط بين معنى “العالمين” في القرآن وفكرة تعدد الأكوان.

Leave a Reply

Your email address will not be published. Required fields are marked *