Changeset 349:b855b51c22f4


Ignore:
Timestamp:
Dec 11, 2013, 7:42:19 PM (11 years ago)
Author:
Evgeny Stambulchik <Evgeny.Stambulchik@…>
Branch:
default
Phase:
public
Message:

Rewrote evaluateEntityValue with Function.call() instead of eval().

Location:
source
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • source/class/pf/Application.js

    r341 r349  
    530530        evaluateEntityValue : function(entity, s1, s2)
    531531        {
    532             var formula;
    533             switch (entity.nspecies) {
    534             case 1:
    535                 var s1_str = "this.plasma." + s1.id;
    536                 formula = entity.formula.replace(/\%s1/g, s1_str);
    537                 break;
    538             case 2:
    539                 var s1_str = "this.plasma." + s1.id;
    540                 var s2_str = "this.plasma." + s2.id;
    541                 formula = entity.formula.replace(/\%s1/g, s1_str);
    542                 formula = formula.replace(/\%s2/g, s2_str);
    543                 break;
    544             default:
    545                 formula = entity.formula;
    546                 break;
    547             }
    548             var v = eval(formula);
    549            
    550             return v;
     532            var F = new Function("s1", "s2", entity.formula);
     533
     534            return F.call(this, s1, s2);
    551535        },
    552536       
  • source/entities.js

    r318 r349  
    66        nspecies  : 1,
    77        section   : "waves",
    8         formula   : "%s1.getPlasmaFrequency()",
     8        formula   : "return s1.getPlasmaFrequency()",
    99        wikiLink  : "Plasma_frequency"
    1010    },
     
    1515        nspecies  : 1,
    1616        section   : "fundamental",
    17         formula   : "%s1.getGyroFrequency(this.plasma.B)",
     17        formula   : "return s1.getGyroFrequency(this.plasma.B)",
    1818        wikiLink  : "Gyrofrequency"
    1919    },
     
    2525        nspecies  : 1,
    2626        section   : "fundamental",
    27         formula   : "%s1.getTypicalDistance()",
     27        formula   : "return s1.getTypicalDistance()",
    2828        wikiLink  : "Wigner-Seitz_radius"
    2929    },
     
    3434        nspecies  : 1,
    3535        section   : "fundamental",
    36         formula   : "%s1.getDebyeLength()",
     36        formula   : "return s1.getDebyeLength()",
    3737        wikiLink  : "Debye_length"
    3838    },
     
    4343        nspecies  : 1,
    4444        section   : "fundamental",
    45         formula   : "this.plasma.getFullDebyeLength(%s1)",
     45        formula   : "return this.plasma.getFullDebyeLength(s1)",
    4646        wikiLink  : "Debye_length"
    4747    },
     
    5252        nspecies  : 1,
    5353        section   : "fundamental",
    54         formula   : "%s1.getGyroRadius(this.plasma.B)",
     54        formula   : "return s1.getGyroRadius(this.plasma.B)",
    5555        wikiLink  : "Gyroradius"
    5656    },
     
    6161        nspecies  : 1,
    6262        section   : "fundamental",
    63         formula   : "%s1.getMinApproachDistance()"
     63        formula   : "return s1.getMinApproachDistance()"
    6464    },
    6565    {
     
    6969        nspecies  : 1,
    7070        section   : "waves",
    71         formula   : "%s1.getInertialLength()",
     71        formula   : "return s1.getInertialLength()",
    7272        wikiLink  : "Inertial_length"
    7373    },
     
    7878        nspecies  : 1,
    7979        section   : "fundamental",
    80         formula   : "%s1.getDeBroglieLength()",
     80        formula   : "return s1.getDeBroglieLength()",
    8181        wikiLink  : "DeBroglie_wavelength"
    8282    },
     
    8888        nspecies  : 1,
    8989        section   : "fundamental",
    90         formula   : "%s1.getThermalVelocity()",
     90        formula   : "return s1.getThermalVelocity()",
    9191        wikiLink  : "Thermal_velocity"
    9292    },
     
    9797        nspecies  : 0,
    9898        section   : "waves",
    99         formula   : "this.plasma.getAlfvenVelocity(this.plasma.B)",
     99        formula   : "return this.plasma.getAlfvenVelocity(this.plasma.B)",
    100100        wikiLink  : "Alfven_velocity"
    101101    },
     
    107107        nspecies  : 1,
    108108        section   : "fundamental",
    109         formula   : "%s1.getCoupling()"
     109        formula   : "return s1.getCoupling()"
    110110    },
    111111    {
     
    115115        nspecies  : 1,
    116116        section   : "spectroscopy",
    117         formula   : "var r = %s1.getTypicalDistance()/%s1.getDebyeLength(); \
    118                      (1 + r)*Math.exp(-r)"
     117        formula   : "var r = s1.getTypicalDistance()/s1.getDebyeLength(); \
     118                     return (1 + r)*Math.exp(-r)"
    119119    },
    120120
     
    125125        nspecies  : 0,
    126126        section   : "spectroscopy",
    127         formula   : "this.plasma.r.getTransitionEnergy()"
     127        formula   : "return this.plasma.r.getTransitionEnergy()"
    128128    },
    129129    {
     
    133133        nspecies  : 0,
    134134        section   : "spectroscopy",
    135         formula   : "this.plasma.r.getNaturalWidth()"
     135        formula   : "return this.plasma.r.getNaturalWidth()"
    136136    },
    137137    {
     
    141141        nspecies  : 0,
    142142        section   : "spectroscopy",
    143         formula   : "this.plasma.dE2dWl(this.plasma.r.getNaturalWidth())"
     143        formula   : "return this.plasma.dE2dWl(this.plasma.r.getNaturalWidth())"
    144144    },
    145145    {
     
    149149        nspecies  : 0,
    150150        section   : "spectroscopy",
    151         formula   : "this.plasma.r.getFineStructure()",
     151        formula   : "return this.plasma.r.getFineStructure()",
    152152        wikiLink  : "Fine_structure"
    153153    },
     
    158158        nspecies  : 0,
    159159        section   : "spectroscopy",
    160         formula   : "this.plasma.dE2dWl(this.plasma.r.getFineStructure())",
     160        formula   : "return this.plasma.dE2dWl(this.plasma.r.getFineStructure())",
    161161        wikiLink  : "Fine_structure"
    162162    },
     
    167167        nspecies  : 0,
    168168        section   : "spectroscopy",
    169         formula   : "2*this.plasma.r.getDopplerHwhm()",
     169        formula   : "return 2*this.plasma.r.getDopplerHwhm()",
    170170        wikiLink  : "Doppler_broadening"
    171171    },
     
    176176        nspecies  : 0,
    177177        section   : "spectroscopy",
    178         formula   : "this.plasma.dE2dWl(2*this.plasma.r.getDopplerHwhm())",
     178        formula   : "return this.plasma.dE2dWl(2*this.plasma.r.getDopplerHwhm())",
    179179        wikiLink  : "Doppler_broadening"
    180180    },
     
    185185        nspecies  : 0,
    186186        section   : "spectroscopy",
    187         formula   : "2*this.plasma.getZeemanSplitting()"
     187        formula   : "return 2*this.plasma.getZeemanSplitting()"
    188188    },
    189189    {
     
    193193        nspecies  : 0,
    194194        section   : "spectroscopy",
    195         formula   : "this.plasma.dE2dWl(2*this.plasma.getZeemanSplitting())"
     195        formula   : "return this.plasma.dE2dWl(2*this.plasma.getZeemanSplitting())"
    196196    },
    197197    {
     
    201201        nspecies  : 0,
    202202        section   : "spectroscopy",
    203         formula   : "2*this.plasma.getStarkHwhm()"
     203        formula   : "return 2*this.plasma.getStarkHwhm()"
    204204    },
    205205    {
     
    209209        nspecies  : 0,
    210210        section   : "spectroscopy",
    211         formula   : "this.plasma.dE2dWl(2*this.plasma.getStarkHwhm())"
     211        formula   : "return this.plasma.dE2dWl(2*this.plasma.getStarkHwhm())"
    212212    },
    213213    {
     
    218218        prepos    : "due to",
    219219        section   : "spectroscopy",
    220         formula   : "2*this.plasma.getQsHwhm(%s1)*this.plasma.getStarkQuasistaticity(%s1)"
     220        formula   : "return 2*this.plasma.getQsHwhm(s1)*this.plasma.getStarkQuasistaticity(s1)"
    221221    },
    222222
     
    228228        prepos    : "due to",
    229229        section   : "spectroscopy",
    230         formula   : "2*this.plasma.getQsHwhm(%s1)"
     230        formula   : "return 2*this.plasma.getQsHwhm(s1)"
    231231    },
    232232
     
    237237        nspecies  : 1,
    238238        section   : "spectroscopy",
    239         formula   : "this.plasma.getMicrofieldFrequency(%s1)"
     239        formula   : "return this.plasma.getMicrofieldFrequency(s1)"
    240240    },
    241241
     
    246246        nspecies  : 0,
    247247        section   : "spectroscopy",
    248         formula   : "this.plasma.r.getMinEnergyDistance()"
     248        formula   : "return this.plasma.r.getMinEnergyDistance()"
    249249    },
    250250    {
     
    254254        nspecies  : 0,
    255255        section   : "spectroscopy",
    256         formula   : "this.plasma.e.getPlasmaFrequencyW()",
     256        formula   : "return this.plasma.e.getPlasmaFrequencyW()",
    257257        wikiLink  : "Plasmon"
    258258    },
     
    263263        nspecies  : 0,
    264264        section   : "fundamental",
    265         formula   : "this.plasma.getFermiEnergy()",
     265        formula   : "return this.plasma.getFermiEnergy()",
    266266        wikiLink  : "Fermi_energy"
    267267    },
     
    272272        nspecies  : 0,
    273273        section   : "fundamental",
    274         formula   : "this.plasma.getFermiVelocity()",
     274        formula   : "return this.plasma.getFermiVelocity()",
    275275        wikiLink  : "Fermi_velocity"
    276276    },
     
    281281        nspecies  : 0,
    282282        section   : "fundamental",
    283         formula   : "this.plasma.getFermiLength()",
     283        formula   : "return this.plasma.getFermiLength()",
    284284        wikiLink  : "Electric-field_screening"
    285285    },
     
    290290        nspecies  : 1,
    291291        section   : "fundamental",
    292         formula   : "%s1.getChemicalPotential()",
     292        formula   : "return s1.getChemicalPotential()",
    293293        wikiLink  : "Chemical_potential"
    294294    },
     
    300300        nspecies  : 1,
    301301        section   : "fundamental",
    302         formula   : "%s1.getMassDensity()",
     302        formula   : "return s1.getMassDensity()",
    303303        wikiLink  : "Density"
    304304    },
     
    309309        nspecies  : 0,
    310310        section   : "fundamental",
    311         formula   : "this.plasma.getMassDensity()",
     311        formula   : "return this.plasma.getMassDensity()",
    312312        wikiLink  : "Density"
    313313    },
     
    319319        nspecies  : 0,
    320320        section   : "fundamental",
    321         formula   : "this.plasma.getBeta()",
     321        formula   : "return this.plasma.getBeta()",
    322322        wikiLink  : "Beta_(plasma_physics)"
    323323    },
     
    329329        nspecies  : 0,
    330330        section   : "spectroscopy",
    331         formula   : "pf.base.Bohr.c/this.plasma.r.getTransitionEnergy()*(2*Math.PI)"
     331        formula   : "return pf.base.Bohr.c/this.plasma.r.getTransitionEnergy()*(2*Math.PI)"
    332332    },
    333333    {
     
    337337        nspecies  : 0,
    338338        section   : "spectroscopy",
    339         formula   : "this.plasma.r.getTransitionEnergy()/(2*Math.PI)"
     339        formula   : "return this.plasma.r.getTransitionEnergy()/(2*Math.PI)"
    340340    },
    341341
     
    346346        nspecies  : 0,
    347347        section   : "spectroscopy",
    348         formula   : "this.plasma.r.getOscillatorStrength()",
     348        formula   : "return this.plasma.r.getOscillatorStrength()",
    349349        wikiLink  : "Oscillator_strength"
    350350    },
     
    355355        nspecies  : 0,
    356356        section   : "spectroscopy",
    357         formula   : "this.plasma.r.getEinsteinA()",
     357        formula   : "return this.plasma.r.getEinsteinA()",
    358358        wikiLink  : "Einstein_coefficients"
    359359    },
     
    365365        nspecies  : 0,
    366366        section   : "spectroscopy",
    367         formula   : "this.plasma.e.getN()/this.plasma.getLteNe()",
     367        formula   : "return this.plasma.e.getN()/this.plasma.getLteNe()",
    368368        wikiLink  : "Einstein_coefficients"
    369369    },
     
    375375        nspecies  : 1,
    376376        section   : "spectroscopy",
    377         formula   : "this.plasma.getStarkQuasistaticity(%s1)"
     377        formula   : "return this.plasma.getStarkQuasistaticity(s1)"
    378378    },
    379379    {
     
    383383        nspecies  : 1,
    384384        section   : "spectroscopy",
    385         formula   : "this.plasma.getStarkRatio(%s1)"
     385        formula   : "return this.plasma.getStarkRatio(s1)"
    386386    },
    387387
     
    392392        nspecies  : 1,
    393393        section   : "spectroscopy",
    394         formula   : "%s1.getHoltsmarkField()"
     394        formula   : "return s1.getHoltsmarkField()"
    395395    },
    396396
     
    401401        nspecies  : 1,
    402402        section   : "spectroscopy",
    403         formula   : "this.plasma.getMicrofieldFrequency(%s1)"
     403        formula   : "return this.plasma.getMicrofieldFrequency(s1)"
    404404    },
    405405   
     
    410410        nspecies  : 1,
    411411        section   : "radiation",
    412         formula   : "%s1.getCyclotronLosses(this.plasma.B)",
     412        formula   : "return s1.getCyclotronLosses(this.plasma.B)",
    413413        wikiLink  : "Cyclotron_radiation"
    414414    },
     
    420420        nspecies  : 0,
    421421        section   : "radiation",
    422         formula   : "this.plasma.getBremsstrahlungLosses()",
     422        formula   : "return this.plasma.getBremsstrahlungLosses()",
    423423        wikiLink  : "Bremsstrahlung"
    424424    },
     
    430430        nspecies  : 0,
    431431        section   : "radiation",
    432         formula   : "this.plasma.getBremsstrahlungSpectralDensity()",
     432        formula   : "return this.plasma.getBremsstrahlungSpectralDensity()",
    433433        wikiLink  : "Bremsstrahlung"
    434434    },
     
    440440        nspecies  : 0,
    441441        section   : "radiation",
    442         formula   : "this.plasma.getFreeBoundLosses()"
     442        formula   : "return this.plasma.getFreeBoundLosses()"
    443443    },
    444444   
     
    449449        nspecies  : 0,
    450450        section   : "radiation",
    451         formula   : "this.plasma.getFreeBoundSpectralDensity()"
     451        formula   : "return this.plasma.getFreeBoundSpectralDensity()"
    452452    },
    453453   
     
    458458        nspecies  : 1,
    459459        section   : "fundamental",
    460         formula   : "%s1.getPressure()",
     460        formula   : "return s1.getPressure()",
    461461        wikiLink  : "Ideal_gas"
    462462    },
     
    468468        nspecies  : 0,
    469469        section   : "fundamental",
    470         formula   : "this.plasma.getPressure()"
     470        formula   : "return this.plasma.getPressure()"
    471471    },
    472472   
     
    477477        nspecies  : 0,
    478478        section   : "fundamental",
    479         formula   : "this.plasma.getMagneticFieldPressure()",
     479        formula   : "return this.plasma.getMagneticFieldPressure()",
    480480        wikiLink  : "Magnetic_pressure"
    481481    },
     
    487487        nspecies  : 2,
    488488        section   : "collisions",
    489         formula   : "this.plasma.getCoulombLog(%s1, %s2)",
     489        formula   : "return this.plasma.getCoulombLog(s1, s2)",
    490490        wikiLink  : "Coulomb_collision"
    491491    },
     
    497497        nspecies  : 2,
    498498        section   : "collisions",
    499         formula   : "this.plasma.getRelaxationRate(%s1, %s2)"
     499        formula   : "return this.plasma.getRelaxationRate(s1, s2)"
    500500    },
    501501
     
    506506        nspecies  : 1,
    507507        section   : "collisions",
    508         formula   : "%s1.getThomsonXsTotal()",
     508        formula   : "return s1.getThomsonXsTotal()",
    509509        wikiLink  : "Thomson_cross_section"
    510510    },
     
    516516        nspecies  : 0,
    517517        section   : "spectroscopy",
    518         formula   : "this.plasma.r.getClassicalIonizationField()"
     518        formula   : "return this.plasma.r.getClassicalIonizationField()"
    519519    },
    520520    {
     
    524524        nspecies  : 0,
    525525        section   : "spectroscopy",
    526         formula   : "this.plasma.r.getInglisTellerField()",
     526        formula   : "return this.plasma.r.getInglisTellerField()",
    527527        wikiLink  : "Inglis-Teller_equation"
    528528    },
     
    533533        nspecies  : 0,
    534534        section   : "collisions",
    535         formula   : "this.plasma.getDreicerField()"
     535        formula   : "return this.plasma.getDreicerField()"
    536536    }
    537537);
Note: See TracChangeset for help on using the changeset viewer.