Beispiel #1
0
        private readonly double _airFrictionConstant; //a constant of air friction applied to masses

        public RopeSimulation(                        //a long long constructor with 11 parameters starts here
            int numOfMasses,                          //1. the number of masses
            double m,                                 //2. weight of each mass
            double springConstant,                    //3. how stiff the springs are
            double springLength,                      //4. the length that a spring does not exert any force
            double springFrictionConstant,            //5. inner friction constant of spring
            Vector gravitation,                       //6. gravitational acceleration
            double airFrictionConstant,               //11. height of the ground (y position)
            Vector position
            )
        {
            _gravitation         = gravitation;
            _airFrictionConstant = airFrictionConstant;

            for (int i = 0; i < numOfMasses; i++)
            {
                Masses.Add(new Mass(m)
                {
                    Pos = position
                });
            }

            _ropeConnectionPos1 = position;
            _ropeConnectionPos2 = position;

            var index = 1;

            while (index < Masses.Count)
            {
                _springs.Add(new Spring(Masses[index - 1], Masses[index], springConstant, springLength, springFrictionConstant));

                index++;
            }
        }
        public IsotopicDistribution(ChemicalFormula formula, double fineResolution, double minProbability, double molecularWeightResolution)
        {
            ValidateFormulaForIsotopologueComputation(formula);
            double monoisotopicMass = formula.MonoisotopicMass;
            var    a = GetNewFineAndMergeResolutions(monoisotopicMass, fineResolution);

            fineResolution = a.Item1;
            double _mergeFineResolution = a.Item2;
            List <List <Composition> > elementalComposition = new List <List <Composition> >();

            // Get all the unique elements that might have isotopes
            foreach (var elementAndCount in formula.elements)
            {
                int count = elementAndCount.Value;
                List <Composition> isotopeComposition = new List <Composition>();
                foreach (Isotope isotope in elementAndCount.Key.Isotopes.OrderBy(iso => iso.AtomicMass))
                {
                    Composition c = new Composition
                    {
                        Atoms           = count,
                        MolecularWeight = isotope.AtomicMass,
                        Power           = isotope.AtomicMass,
                        Probability     = isotope.RelativeAbundance
                    };

                    isotopeComposition.Add(c);
                }
                elementalComposition.Add(isotopeComposition);
            }

            foreach (List <Composition> compositions in elementalComposition)
            {
                double sumProb = compositions.Sum(t => t.Probability);
                foreach (Composition composition in compositions)
                {
                    composition.Probability   /= sumProb;
                    composition.LogProbability = Math.Log(composition.Probability);
                    composition.Power          = Math.Floor(composition.MolecularWeight / molecularWeightResolution + 0.5);
                }
            }
            CalculateFineGrain(elementalComposition, molecularWeightResolution, _mergeFineResolution, fineResolution, minProbability);

            double additionalMass = 0;

            foreach (var isotopeAndCount in formula.isotopes)
            {
                additionalMass += isotopeAndCount.Key.AtomicMass * isotopeAndCount.Value;
            }

            for (int i = 0; i < Masses.Count(); i++)
            {
                masses[i] += additionalMass;
            }
        }
        private void ImportDataFromFile()
        {
            var data = File.ReadAllLines(dataFilePath);

            Masses.AddRange(data.Select(int.Parse).ToArray());
        }